Post on 17-Jan-2016
Model–View Separation
A subschema for ‘view’ classes (forms) enforces• ModelSchema knows nothing of the view• ViewSchema knows of the model through inheritance
Separate teams of developers can work in• Object model• User interface
49
Add controls from palette
Set properties from dialog
Painter
eventssize and positionfont and color
commonspecific
labeltext boxbuttonstatus line
50
Form Class
• Can have properties and methods (like a ‘model’ class)• Has references to controls and menu items on the form• Inherits from the Form and Window classes• Can be the superclass of other forms
51
Event Method
• Automatically invoked when an event (in right pane) happens to a control or the <form> (in middle pane)
• Is a method of the form (So ‘self’ is the form)
52
Lifecycle of a Form
create form;
load - paint - activate - gotFocus
form.show( );
self.unloadForm( );
queryUnload - unload53
Lifecycle of a Form
mnuCustomerAdd_click(menuItem : MenuItem input) updating;
vars
form : CustomerDetails;
begin
create form transient;
form.show();
end;
mnuCustomerAdd_click(menuItem : MenuItem input) updating;
vars
form : CustomerDetails;
begin
create form transient;
form.show();
end;
btnCancel_click(btn : Button input) updating;
begin
self.unloadForm();
delete self;
end;
btnCancel_click(btn : Button input) updating;
begin
self.unloadForm();
delete self;
end;
54
Create a Customer (1)
An event method is executed whenthe Windows event occurs.
55
Create a Customer (2)
A form captures information enteredby a user about a new customer
56
Create a Customer (3)
A model class sets (and possibly)validates information about an instance
58
MDI (Multiple Document Interface)
• A form that contains other forms is an ‘MDI frame’
• An MDI frame has the menu for the application
• A form inside an MDI frame is an ‘MDI child’
MDI Frame
MDI ChildMDI Child
59
Adding a Menu
60
Form load Event
• Occurs before a form is displayed• Can be used, for example, to put text into text boxes• In this example, sets MDI Frame for application
61
Demonstration
Paint a form Add controls Set properties Size and align controls Test a form Code a button click event Add a menu Code a menu click event Build an MDI application
Your instructor will demonstrate how to
62
• Add a BankingViewSchema
• Paint a CustomerDetails form
• Code a CustomerDetails::createCustomer method
• Code the click method for btnOK
• Code the click method for btnCancel
Challenge #9
name btnOK
caption OK
maxLength 25
name txtAddress
caption FirstNames:
caption Address:
caption LastName:
maxLength 25
name txtFirstNames
maxLength 15
name txtLastName
name btnCancel
caption Cancel
caption
name statusLine
caption Customer Details
63
• Paint a MainMenu form
• Use the menu designer
• Code the click method for mnuCustomerAdd
• Code the load method for the form
• Run the form from Painter and add a customer
Challenge #10
name mnuCustomer
caption &Customer
name mnuCustomerAdd
caption &Add
caption Main Menu
mdiFrame True
64
Application-Related Objects
Form Objecttransient copy of persistent object designed in Painter
process
global
aForm
transient
app
transient
Global Objectpersistent object that can validate application logon
Process Objectpersistent object represents thread of execution
Application Objecttransient instance of Application subclass
65
aCustomer
Objects in an Application
transient
aForm
transient
aButton
aBank
transient
app process
aCustomer
aChequeAcct
transient
aTextBox
transient
aTextBoxaSavingsAcct
aChequeAcct
aCollectionaCollection
transient
aButton aSavingsAcct
global
two objects representing an application
66
Application Type
• Four types– GUI– GUI, No forms– Non-GUI– Web-Enabled
• Specified on Define Application dialog67
Initialize and Finalize Methods
• Methods run at startup and closedown for each process• Methods in the Application class or sub class• Can use other names• Specified on Define Application dialog
68
Root Object
• Persistent object (singleton) that represents the business• Has ‘complete’ collections of model objects• Accessed from the app object
transient
ApplicationSubclass (app)
myBank
initialize () updating;
begin
// set reference to root object
self.myBank := Bank.firstInstance();
end;
initialize () updating;
begin
// set reference to root object
self.myBank := Bank.firstInstance();
end;
3000.1
Bank
allCustomers
// accessing collections
app.myBank.allCustomers
app.myBank.allBankAccounts
// accessing collections
app.myBank.allCustomers
app.myBank.allBankAccounts
CustomerCollection
BankAccountCollection
allBankAccounts
69
Security Methods
• Global class methods– getAndValidateUser– isUserValid
• Application class property– userSecurityLevel
• Form and Controls– securityLevelEnabled– securityLevelVisible
70
Logon Validation
getAndValidateUser(usercode : String output; password : String output): Boolean;
vars
form : Logon;
accept : Boolean;
begin
create form transient;
form.showModal();
accept := form.txtPassword.text.toLower() = 'secret';
if not accept then
app.msgBox('Please enter your password again',
'Access Denied',
MsgBox_OK_Only);
endif;
return accept;
end;
getAndValidateUser(usercode : String output; password : String output): Boolean;
vars
form : Logon;
accept : Boolean;
begin
create form transient;
form.showModal();
accept := form.txtPassword.text.toLower() = 'secret';
if not accept then
app.msgBox('Please enter your password again',
'Access Denied',
MsgBox_OK_Only);
endif;
return accept;
end;
71
Shortcut
c:\jadecourse\bin\jade.exe path=c:\jadecourse\system
app=BankingViewSchema
schema=BankingViewSchema
host=localhost
port=6005
server=multiuser
72
Demonstration
Define an application Display a message box Provide logon validation Run application from development Create an application shortcut
Your instructor will demonstrate how to
73
In the BankingModelSchema
• Add a Bank class (no properties or methods yet)
• Code and execute a JadeScript::createBank method
• Add a myBank reference to BankingModelSchema
• Code a BankingModelSchema::initialize method
In the BankingViewSchema
• Modify the definition of the application to startwith MainMenu and run initialize
On the desktop
• Create a shortcut to run the application
Challenge #11
74
• Paint a Logon form
• Code the btnOK_click method
• Code the getAndValidateUser method
• Test the logon security
Challenge #12
name btnOK
caption OK
caption Enter the passwordname txtPassword
passwordField True
mdiChild Not MDI form
default True
75
Distributed Processing
Server
Run the Application
Manage the Database
ClientClient
76
JADE Database
JADE DatabaseJADE Application
77
JADE Database
‘data’ objects
branches
accounts
deposits
withdrawals
‘specification’ objects
classes
methods
forms
reports
JADE Database
78
JADE Database
Persistent Cache automatic storage
automatic retrieval
JADE Database
79
Architecture
Database Server
Internet Server(Microsoft IIS)
Fat Client(Web-Enabled Application)
HTML Client(Browser)
HTML Client(Browser)
Application ServerFat Client Fat Client
Thin Client Thin Client
Runtime Systems OnlyDevelopment and Runtime Systems
80
Node
Persistent Cache Transient Cache
TransientDatabase
Background Process
Process
Process
Node
81
Server Node
Server Node
TransientDatabase
PersistentDatabase
Background Process
Server Application Process
Server Method Process
Persistent Cache Transient Cache
Remote Transient Cache
82
Client Node
Client Node
TransientDatabase
Background Process
Development Process
Client Application Process
Painter Process
Debugger Process
Read-OnlySchema
User Interface
Persistent Cache Transient Cache
83
AppServer Node
AppServer Node
Background Process
AppServer Application Process
Thin Client Process
Thin Client Process
Thin Client Process
TransientDatabase
Read-OnlySchema Thin Client
User Interface
CachedForms
Persistent Cache Transient Cache
84
Object Editions
Server Node
Persistent Database
edition=4
Node
Persistent Cache
edition=5
Node
Persistent Cache
edition=4
Node
Persistent Cache
edition=2
modified but not committed latest edition obsolete
85
Cache Synchronisation
Obtaining edition information
cust.edition(); // returns edition of customer in cache
cust.latestEdition(); // returns edition of customer on server
cust.edition(); // returns edition of customer in cache
cust.latestEdition(); // returns edition of customer on server
self.exclusiveLock(cust); // any lock ensures latest edition
if previousCustomerEdition <> cust.edition() then
// compare a previous edition number
self.exclusiveLock(cust); // any lock ensures latest edition
if previousCustomerEdition <> cust.edition() then
// compare a previous edition number
cust.resynch(); // customer resynchs itself
self.resynchObject(cust); // 'self' resynchs the customer
Customer.resynchInstances(); // resynchs all Customer instances
cust.resynch(); // customer resynchs itself
self.resynchObject(cust); // 'self' resynchs the customer
Customer.resynchInstances(); // resynchs all Customer instances
Locking to obtain the latest edition then checking editions
Resynching to obtain the latest edition
86
Demonstration
Run the JADE monitor program Run a JADE application server Run a JADE thin client Extract your schema Run the JADE loader program
Your instructor will demonstrate how to
87
• Run the JADE monitor program
• Monitor ‘Users’ – processes and nodes
• Run your application from a shortcut
• Run a JADE application server
• Run JADE development in thin client
• Run a second development thin client
• Identify processes and nodes
Challenge #13
88
Challenge #14
Run the default application in the Architecture schema89
Challenge #15
• Extract your schemas
• Remove your schemas
• Run the JADE loader program
90
Lock Diagrams
“The process . . . . . . . . . . has a lock on . . . . . . . . the object”
Who owns the lock?
object1.exclusiveLock (object2);object1.exclusiveLock (object2);
self.exclusiveLock (object2);self.exclusiveLock (object2);
91
Lock Combinations
shared
shared
shared
shared
process A process B
process Cprocess D
Shared
shared
shared
reserve
shared
process A
process D
process B
process C
Reserve
exclusive
process AExclusive
92
Lock Durations
• Session– released when process ceases
• Transaction– released when abortTransaction or commitTransaction
93
Latest Edition
edition=2
Persistent CacheDatabase Server
edition=3
edition=3
successful lock edition check cache updated
resynchObject(object); // object marked as obsolete
write object.name; // edition checked so
// latest object now in cache
resynchObject(object); // object marked as obsolete
write object.name; // edition checked so
// latest object now in cache
94
Transactions
session
process start
beginLoad
(beginLock)
endLoad
(endLock)
read
transaction
beginTransaction
update
transaction
process end
commitTransaction
(abortTransaction)
95
Read Transactions
• Locks not required but must guarantee correct result. Has logical start and end.
• beginLock/endLock or beginLoad/endLoadbeginLock;
trial := trial + account.balance; // balance is a property, account is locked
endLock; // account is unlocked
beginLock;
trial := trial + account.balance; // balance is a property, account is locked
endLock; // account is unlocked
beginLock;
trial := trial + account.getBalance(); // getbalance is a method, account is locked
endLock; // account is unlocked
beginLock;
trial := trial + account.getBalance(); // getbalance is a method, account is locked
endLock; // account is unlocked
beginLoad;
sharedLock(account); // account is locked
trial := trial + account.getBalance();
endLoad; // account is unlocked
beginLoad;
sharedLock(account); // account is locked
trial := trial + account.getBalance();
endLoad; // account is unlocked96
Updating Transactions
edition=4
Persistent CacheDatabase Server
edition=3
edition=4
successful transaction database updated
edition=4
Persistent CacheDatabase Server
edition=3
failed transaction ‘dirty’ object discarded
97
Locking an Object
lock (object, type, duration, timeout);
sharedLock (object);lock (object, Share_Lock, Transaction_Duration, LockTimeout_Server_Defined);
reserveLock(object);lock(object, Reserve_Lock, Transaction_Duration, LockTimeout_Server_Defined);
exclusiveLock(object);lock(object, Exclusive_Lock,Transaction_Duration, LockTimeout_Server_Defined);
tryLock (object, type, duration, timeout);
lock (object, type, duration, timeout);
sharedLock (object);lock (object, Share_Lock, Transaction_Duration, LockTimeout_Server_Defined);
reserveLock(object);lock(object, Reserve_Lock, Transaction_Duration, LockTimeout_Server_Defined);
exclusiveLock(object);lock(object, Exclusive_Lock,Transaction_Duration, LockTimeout_Server_Defined);
tryLock (object, type, duration, timeout);
98
Lock Queue
Lock
Exception
ServerTimeout=10000 (10 sec)
LockQueueCheckInterval=1000 (1 sec)
Lock Queue
If lock has not been obtained
If lock cannot be obtained
immediately
99
Monitoring Locks
100
Changing a Lock
• Duration• Type
Lock could attempt to change
Guidelines Duration upgrade Duration downgrade Type upgrade
(if object is locked with a session lock, a transaction duration upgrade inside a transaction is reversed when the transaction ends)
Type downgrade outside a transaction Type downgrade in a transaction
(if object is locked with a session lock, a session duration downgrade inside a transaction is delayed until the transaction ends)
101
Collections and Locking
while i < collection.size() do // collection is locked
if collection.includes(object) then // collection is locked
while i < collection.size() do // collection is locked
if collection.includes(object) then // collection is locked
foreach object in collection do // collection is locked
. . .
endforeach; // collection is unlocked
iter := collection.createIterator();
while iter.next(object) do // collection is not locked
. . .
endwhile;
foreach object in collection do // collection is locked
. . .
endforeach; // collection is unlocked
iter := collection.createIterator();
while iter.next(object) do // collection is not locked
. . .
endwhile;
foreach object in collection do // collection is locked
beginTransaction;
object.update();
commitTransaction; // all locks released so collection is unlocked
endforeach;
foreach object in collection do // collection is locked
beginTransaction;
object.update();
commitTransaction; // all locks released so collection is unlocked
endforeach;102
Lock Exceptions
“The process . . . . . . . . tries but cannot lock . . . . . . the object”
process A process B
process A
process B
process C103
Lock Exception Object
LockException
lockDurationlockTimeoutlockTyperetryCounttargetLockedBy
lockTargetretryLock
initialize() updating;
begin
on LockException do app.globalLockException (exception) global;
end;
initialize() updating;
begin
on LockException do app.globalLockException (exception) global;
end;
104
Deadlocks
process A process B
shared
process Bprocess A
shared
exclusive
exclusive
105
Deadlocks Many Processes
process A process B
process D process C
106
Dirty Reads
Client or AppServer Node
Persistent Cacheedition=4
cache overflow partial commit ‘dirty’ object
Client or AppServer Node
Persistent Cache
Server Node
Transaction Log File Persistent Database
edition=3
edition=4
107
Node
Persistent Cache Transient Cache
TransientDatabase
Background Process
Process
Process
Node
108
getLockStatus (object, lockType, lockDuration, lockedBy);
isLockedByMe (obj);
create lockArray transient;
system.getLocks (lockArray, max);
getLockStatus (object, lockType, lockDuration, lockedBy);
isLockedByMe (obj);
create lockArray transient;
system.getLocks (lockArray, max);
Information on Locks
109
Shared Transient Objects
beginTransaction;
create object persistent; // persistent
commitTransaction;
create object transient; // process transient
beginTransientTransaction;
create object sharedTransient; // shared transient
commitTransientTransaction;
beginTransaction;
create object persistent; // persistent
commitTransaction;
create object transient; // process transient
beginTransientTransaction;
create object sharedTransient; // shared transient
commitTransientTransaction;
110
Demonstration
Lock and unlock an object Create a lock exception Carry out a read transaction Carry out an update transaction Monitor locks Monitor queued locks Execute code and observe locking Create transient and shared transient objects Cause a deadlock exception
Your instructor will demonstrate how to
111
Run the default application in the TransactionAndLocking schema
Challenge #16
112
Code a CustomerDetails::isInputOK method
Challenge #17
• Return true if all text boxes contain textand false otherwise
• If a text box is empty – display a message on the statusLine – set the focus to the text box
Code a CustomerDetails::clearTextBoxes method
Modify the btnOK_click method
• Call isInputOK and return if input is not OK• If input is okay
– create the customer as before – clear text boxes – display a message on the statusLine – set focus to txtLastName
113