Part 5 Searching in databases
No edit summary
No edit summary
Line 73: Line 73:
for (var i = 0; i < IMG.length; i++) {
for (var i = 0; i < IMG.length; i++) {
   IMG[i].onclick = function() {
   IMG[i].onclick = function() {
     IFRAME.src = 'http://www.youtube.com/embed/' + this.dataset.video + '?rel=0&autoplay=1';
     IFRAME.src = 'https://www.youtube.com/embed/' + this.dataset.video + '?rel=0&autoplay=1';
     if(this.dataset.end) IFRAME.src = IFRAME.src.replace(/([\s\S]*)/g, '$1&end=' + this.dataset.end);
     if(this.dataset.end) IFRAME.src = IFRAME.src.replace(/([\s\S]*)/g, '$1&end=' + this.dataset.end);
     if(this.dataset.start) IFRAME.src = IFRAME.src.replace(/([\s\S]*)/g, '$1&start=' + this.dataset.start);
     if(this.dataset.start) IFRAME.src = IFRAME.src.replace(/([\s\S]*)/g, '$1&start=' + this.dataset.start);

Revision as of 12:15, 3 April 2017

We create a seeker that translates ocl to sql for searching in databases of any size. We look at derivations, constraints and validation rules.

To make your experience more comfortable, we set the main tags mentioned in the video to the right bar menu of this mini player. Choose the interesting subtitle on the list and immediately get to the exact theme timeplace in the video. Now you can pick any topic to be instructed without watching the whole video.


View Model Editor: Search expressions Variables and Validations Derivation Attribute Visible expressions Test data: Tab separated data import Constraints Validation Rules Saving despite error warnings

Raw subtitles text

Hi and welcome back to MDriven designer overview

and this will be session five, so we

ended off the last session with the

creating a modal dialog that were

allowed us to pick tenants to our house

so we could pick persons that would

create lease contract and when we used

this dialogue "all persons" to to pick

the tenants from and as you can

imagine this strategy simply will not

hold, if we have a million persons and

this is good, when we have a hundred

maybe, but we can't really trust on all

instances to come to the rescue for

every scenario, we really desperately

need some way to vSeek the database

without instanciating the objects in

memory in their client during the

prototyper, so how do we go about that in

the view model pattern that we have

we don't like this, we right click and among the nesting

choices we have add add search expression

and such expressions are expression step

are supposed to be executed in

persistent storage, so that will be a

database if your back and is connected

to it, to one or it will be the xml file

in our case, where we prototype against

the xml file and if we are in turn

key will be the persistence mapper that

in turn will question the backing database

alright, so let's just go ahead and add

a search expression or maybe better

yet, we will do a new view model to keep

the searching and we will column this

"person search" and we type it to be "person"

right click and in the nested view models

add search expression and what happened

here, was that three columns were

added to the root and one of the

columns was a variable called the

vSeek result, this variable was created

and added to the viewmodel well it

wasn't because it's implicit, but it

should be in the newer versions, it will

be and so variables are just as they sound

something that we can define in

the view model and is only available

in the viewmodel scope, so this one

should be of collection person this is

where our result is going to end up from

a search and that one we connect to a

search result grid, so we have another

variable vSeekParam that is

defined as a string, so we have a column

in the UI that lets the user enter

a criteria and we have his search button

and the search button as the ocl

expression "selfvm.search", "selfvm" is

a special instance that is available in

view models only from OCL, let's see

what it contains, "selfvm." and from

here we can do things as

refresh, save, search, and a few other

things, like PSexpression_refresh, we can

come back to these in later sessions, but

for now we just going to use the vm

search, what the search operator does is

it looks for search expressions in the

view model and this is a search

expression, it's just another view model

nesting, but what separates this from the

other nestings is that it is not

connected to anything it's judt sits here

in the middle, doesn't need to be in the

middle because I said so I can right

click this and move this one up, so as

such expression is typed and it has

criterias right here it's just columns you

can have many criteria per search expression

the criterias are merged

together with the ocl operator

intersection, so what if these criteria

is true and we had another or this

criteria returned five persons 12345 and

we had another one that return two

persons 45, the intersection will take

what's equal between the two domains

so 4 and 5, but the search expression

the criteria is just another ocl, but

what's different about this is that is

the persistent storage subset of SQL Ocl-PS

it sets up here in the edge

when we entry and then we don't have access to every single

operator, we can't concatenate

strings etc. in this language

its main purpose is to be easily

transformed to SQL and executed as an

SQL query to the database and the

database will return a number of

identities, that we will in turn

interpret as persons and load personal

objects, so what we do is select and we

have a loop variable called A then

the mechanism to create the search

expression and all this for us it just

took the first string attribute of the

class that we had set person and that

was first name and set, well it's not

unlikely that is what you as a

developer want to limit search of,

this attribute as SqlLike(vSeekParam) and ends with a +% just like in

Sql operator like, so if you want to find

both and start, if you want to find

values that equals in the middle

that you would go something like this,

so this will be a resulting string that's

add into the SqlLike, that of course

will be translated into a like operator

in sequel, but as we are running against

an xml file, it will do something similar

just execute operator on that

so is this really what we want

well, we want to also check if it's the

last name maybe, so I use "or" and I use "LastName", like that

what should I show for a result I can show the things I have

first name and last name

so let's do one thing more in this view

and if you don't find what you expect

you might want to have somewhere where

you can create a new person, so let's

totally action definitions for this

dialogue and let's do a viewmodel action

and say that we should show it on the

root and say new person and the

execute expression on this one

should be PersonCreate, having done that

we can see, if we have, we can save this

push the play button, start system, Run Model

and continue, we never created an

action to actually show the seeker

view model, so person search

I right click on this and say add a

global action for show

okay then it's shown here, but we

probably want to sort into as menu group

a double click it

find it here set menu group-seekers

maybe, so this is might be where I want

to put all my search dialogues and who

knows

having done that and I head back to this one

model refresh, seekers, show per person,

search and I can search, but I only want those

that has an "a" in them

that's the only one, okay but

what if someone's missing

I can create a new person and call that

Andersson Anders, now if I search for a

I should find Anderson, but since

my xml file is, I guess it is case sensitive

it is case sensitive, so if we don't

like that we should have used operator

called .sqlLikeCaseInSensitive, where like

so now we have the searcher

let's go back to the house view

where we added the pic tenants action

so the pick tenant action and let's do

a copy of this, where did he go

let's do a copy of this, just going to do

a copy and paste, and "pick tenants by search"

and that one should bring up the

person search instead and if it does

it cannot call "check this" because that

variable doesn't exist in that UI like

instead it calls "SearchResultGrid" if that is empty

ok and this expression won't go either

because the same problem, like that

and it adds the tenants if I have selected any

so if we head back here we see that we have

another action pick tenants by search

of course in the end, I only want one of these

and our most likely it's the "BySearch"

that will survive and then maybe

I will change its name, model refresh,

houses and pick one here,

this doesn't have any tenants, I'm going to pick

tenants by search, I'm going to search on

find this one and I add that one, so I find it

rather disturbing that I don't see the name here

this is what I talked about

before, in session 2 or something

first, when we do the UI

and watch the information together

that it's obvious that, of course, we need to see

the name here as a new requirement, but

it's obvious now that we see the result and that's not a problem

this is the grid, which is this one, which

points to this one and let's add the columns

and add a generic column and in

that generic column sets an expression

that follow the role to tenant and the

first name that's the ocl editor acting up

when you don't have a separator

first name and you might have noticed that

I quite a lot of times had a need

to concatenate first and the last name

because that's simply how we

refer to persons, so this

sort of this pattern comes back

again and again and we're going to solve

this in just a minute, just going to save

the fact that we did a new column

and we call that "tenant name" and

we might want to give that a little more

space like three columns and we might

want to drag this one to the end

here and over there, and this one and we

added in summary session it's just we want

so if I save and refresh and look at all

the houses, was it this one and there's

Andersson, but I don't want it there

I want it first and let's show the

gridlines, like that, refresh like

that and that's pretty obvious and

how come this isn't even showing, well

it's too tight to show with this

style, so how would you solve that

well as you can see we are cramming

everything into one grid cell here

so we're gonna insert column and

give this one more space for the presentation

let's give it 2 and just to make things

look straight you're going to get the

rest of them 2 as well, head back,

refresh, views, all houses, when I click it

would still crap but you get the

general idea I will just insert yet another column

let's judt do that one for and refresh, like that

so this is important how quickly

we can go from feedback with our eyes

that this isn't good back to design how should be instead

back to verification, okay it's fine it

really saves everyboy's time

ok enough about that, and I said that

this pattern is repeated again and again

yes it is the first name and last name

it's a really common scenario that we

want to refer to persons by their full

name, so what we probably would want

to do is add an attribute, that is called

full name, but that wouldn't be very

normalized to store the first name and

the last name and full name, so let's

make that one right, that's another

attribute mode, it's not persistent as it

is not stored in the database, it's

derived as it's calculated from other

values that we do have, so I can paste in

that one and now that was for the

tenants and I don't want that

because now we are in the scope of a person,

so first name and last name

this makes up the full name and now we

have done this and we can make use of it

in our view models or wherever we access

model information, so instead of doing

this we can just as well do the full

name, like that and now it's grey I was

expecting it to be pink, because it is

derived I wonder why that was it's derived

don't have an answer, but going to save

what do you say? self is not...

that was just wrong, save and head back and

model refresh, and there's really

no difference, but like here now that we have it

let's use it, so tenance last name

and tenance full name is full name we got refresh

if I were to change the name

the right attributes were like this

there are always subscribed, so let's head

back to this view and add it as well

just to prove a point all persons add column

full name,  give it some space when it's in grid too

maybe we refresh, views, show all persons

as soon as I change one of their values

that build up the derivation, the

derivation will kick in and invalidate

as the UI looks at this value

it will force it to refresh, getting the

parts of the value and re-evaluate it,

so when I write Hans it will be updated

and if I were to change anything

it will be updated and that might be

Dick Smith, right, so derivation is also

available for associations

so what we could do, if we want to know

where the person lives is of course to

follow to see the rented apart and

look up the street for that house

but if that is a common operation

that we want to do we could

also add a association straight from

person to streets and since

I can rent many apartments, I potentially

have many addresses, so if I want to

derive this from available information,

I was saying that the association is derived

and I will take this end, will

have no value so I will say that there

it is non navigable, is navigable

false, because if I would want to go from

street to persons that would be another

derivations that would have another

expression, but this one should have

a derivation expression, that it starts

in person and it goes to

here is the one that is derived it

goes to owned house,

no, to lease contract, and from lease contract

rented apartments, and from rented

apartments - the street

I really must fix that, the street

so this will be a collection of

streets and if we were to show this in

our UI, I guess we could add column and

add generic column, and I follow the

relation to streets and that has a name,

but since this is a collection of

strings, we need some way to display it

in a single cell that we will do here in

the grid and done an operator that's

real handy for these cases as CommaList

so it will take all the strings in

the collection and append them as they

with the comma in between, so lives at, so heading

back to refresh, views or persons, so

here we see the address is swelling

ok, so good we have covered in a lot of

ground we have mentioned derivations

for attributes like the full night

servations for associations like the

street even if it was kind of silly,

because we would probably would like

the street number to get the precise

address and that's not possible this way

we have covered the idea of being able

to vSeek in a lost database and then

we also mentioned variables that are

available in view models, so I'm going to

show you another thing and what if we

are in a situation where we actually

need some test data, we need a lot of

persons to verify that our idea to search in

larger amount is valid and of course

we could run the prototype print

and press, we added the new person action

here and we could press that a thousand

times to enter the first and last name

but is there a better way, you ask

and since I talking about it you have

probably guessed that there is and I go

into the the Run button again because

I need a context that we are in the

XML persistence, we're going to start

the system and we're going to go into

the legacy debugger and in here we have

a tab over here

"import tab separated", so tab separated

data import via named view model, so what it

says he's given tab-separated data and

the view model name assumes row 1 in data

to be viewmodel column and creates

instances of view model class

so basically, if we have some data that

we paste in here, we should be able to

create objects of certain class, but it

also says, that we need a view model,

so let's create one, as you see the view

models are used over and over for different purposes

ImportPersons and type Person and let's assume

the first name is the first value and

the last name is the second value so

that's about it and given that I should be able to say

that this is the view model I want to

use or maybe I need to reread this, I do

start, lazy debugger,

input tap separated and view model and

get header from view model,and first-name

lastname alright, where can I get that, I found this site

as google for a list of names and find

anything on google list of random names

let's do 50 and male and female and well

no alliteration when you start the same ok

now I want to grab these on listing text

area, that's great, I wonder if this is

tab separate it probably isn't and going to

start notepad, alright so is that a tab

no, I copy tab and I want to

do is search and replace here, look

for space and paste in my tab and

replace it all and copy those and head

back to my importer and paste those, and

go, so that means I got a lot of dirty

objects here that I will save like that and

head back to my this one is going to

restart, person search and I have some

test data to work on

oh let's see everyone that starts either

their first loss name with "t" or has a "t"

really because that was what we said in the criteria

ok, so that means that when we do houses

and we want to assign tenance by search

and we do everyone with the "T"

because it is case sensitive as we

found out and select them and press ok

then we have those as tenants

alright moving ON as we see the

tenants here, but they haven't got

an apartment number...they

haven't got a rent figure, but they

really should this is important information

it's so important, that we might want to

add constraint on our class lease

contract to make sure that

the user of the system is made aware of

the importance of these values

so I select the class and I select

constraints and I get a little dialogue

where I can add constraints this

constraint I give a name "must have

apartment number" that's the name of my

constraint so that I can refer to it and

and I want to have a description as well

and I'm going to make easy to myself is

to do something like this, that's right

the expression is more or

less self.apartmentnumber and well it

should be not null, right

shouldn't be null and then now we got

that symbol that says that this has one

constraint, so when we look at our

diagrams we will see that this is

constrained in some way

ok, so if we were to head back to our

prototyper and show the house

we see, must have apartment number

must have apartment number, but there's

really no information on who is missing

the apartment number and let's head back

to the constraint and in the description we can actually

access attributes, so and we can

go like this as string within the

larger than and smaller than, greater than and

tags to say that we want to describe

the default presentation here, can you

please inject that and what is the

default presentation, default string

representation on lease contract is none

okay, but we might follow the link to the

person and use the full name again we

made use of the derived full name

like that and save, and head back, refresh, view

all houses, so Hans Karlsen must have an

apartment number and Dick Smith must

have apartment number and as I give our

Hans Karlsen apartment number one

that is removed and as I give  Dick's one 2

that one removed as well, so that's a

good way to feedback information to the

user about what needs to be filled in

but it might not be enough for us, we

might need to stress these even harder depending on use case

so there's more ways to signal the

user that something needs to be done

if we check the house view here and we had

the variables that we don't use in this

view we use them in the seeker, but we

also have the the constraints, so these

are the constraints that we found in the

classes that are used here that is just

one and depending on use case we might

not want to show it because who knows

the view might not even contain

their apartment number, so no need to

stress the user about entering it if it

isn't really possible, so that we could

just opt it out, but we want to have it

opt-in because it's good for us, but what

we could do is something more precise as a validation rule

let's right-click up in the top and add

a validation rule, so we got rule one and

then the rule one is that

let's say it's the fact that the selected, what

what I want to do is to highlight something here

apartment number to make the user see this

so what is this, this is here

the lease contract, so what I want to do in

my validation rule is to find a

variable the current

the lease contract and check that one

that particular one that sunscreen and

or selected at the moment, and check that

for apartment number and verify that

isn't null, and then I can write something

please supply number

like that, but we still haven't been able

to say that this rule

is supposed to show up for this field

that I can select the field it's over

here and I'm supposed to find it and

validation rules, my menus really turn

out the wrong end all the time,

validation rules, rule one, please supply number

ok, so that would be one way to

further gearsteer our user to see

something, but how does it look

refresh, view, houses

it doesn't show anything, but if I null

that out first I get this one and I also

get the red information here

actually depending on what style you use

it really renders differently, so that

you can control

this and we have examples, where you just

have an "!" that was when you point that

it states what's wrong with it

so this is another important thing I

should mention that,when you have errors

and there's some something and updated

in  the information and you try to

save then it will ask you, there are

errors in the information, do you really

want to save anyway? "Hans Karlsen must

have apartment number" and the system

won't stop you from saving and this is

an important principle I think, that you

shouldn't stop the user from entering

information, even if it isn't correct

then it's better to to monitor all the

information that is in incorrect, so that

they can come back to it then and update

it don't stop users from entering data

and make a UI very clear, what you expect

but you should always

always honor the users' request to

save and maybe you should work with

the quality attributes like states that

you can't go into approved, before you

have apartment number or the rent in

dollars, but you shouldn't stop them from saving

ok, that's just my very clear view on this

ok, so I'm going to save it anyway, but run

nice wouldn't you say

just having the area information this

way, so whenever I enter something the

error goes away and of course I don't

get the warning, when I save, but that was

not a very good side for this example, so

switch back, so let's add

another constraint and we make that

not to error constraint, but rather look at

the other types of constraints, so we

have a constraint the "rent" and

the description and we do as we before "<as

string> lives free" and

we don't do an error just the information

expression would be self.rent->not null

because when the expression

is true then the constraint is

fulfilled and we don't shoe anything, but

as soon as the constraint is not true

then it's broken and then we show warning signs etc.

in this case information

refresh and now it's a little white

thing is Hans Karlsen lives free

shouldn't be the case that let them say alright

I wonder if we will have time to

cramming reports in this, so that we

could do rents and rents slips for these guys

I think maybe we'll come back to

that in the next session so we will

round this off and thank you very much

for following along with these tutorials and I'll be back

This page was edited 80 days ago on 02/10/2024. What links here