640 likes | 787 Views
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. Painter. Add controls from palette
E N D
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
Painter • Add controls from palette • Set properties from dialog label text box button status line common specific font and color size and position events 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; form.show( ); load - paint - activate - gotFocus self.unloadForm( ); queryUnload - unload 53
Lifecycle of a Form 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(); deleteself; 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) MDI Frame • 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 Child MDI Child 59
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
caption Customer Details caption LastName: caption FirstNames: caption name statusLine caption Address: name btnOK caption OK maxLength 15 name txtLastName name btnCancel maxLength 25 caption Cancel name txtAddress maxLength 25 name txtFirstNames Challenge #9 • Add a BankingViewSchema • Paint a CustomerDetails form • Code a CustomerDetails::createCustomer method • Code the click method for btnOK • Code the click method for btnCancel 63
caption Main Menu name mnuCustomer mdiFrame True caption &Customer name mnuCustomerAdd caption &Add Challenge #10 • 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 64
app process aForm global transient transient Application-Related Objects Form Objecttransient copy of persistent object designed in Painter Application Objecttransient instance of Application subclass Process Objectpersistent object represents thread of execution Global Objectpersistent object that can validate application logon 65
aCustomer aCustomer aBank process global aCollection aCollection aSavingsAcct aSavingsAcct app aChequeAcct aChequeAcct transient aForm transient aButton aButton aTextBox aTextBox transient transient transient transient Objects in an Application • two objects representing an application 66
Application Type • Four types • GUI • GUI, No forms • Non-GUI • Web-Enabled • Specified on Define Application dialog 67
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
3000.1 Bank Customer Collection allBankAccounts BankAccount Collection allCustomers // accessing collections app.myBank.allCustomers app.myBank.allBankAccounts Root Object • Persistent object (singleton) that represents the business • Has ‘complete’ collections of model objects • Accessed from the app object Application Subclass (app) myBank transient initialize () updating; begin // set reference to root object self.myBank := Bank.firstInstance(); end; 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'; ifnot 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
Challenge #11 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 74
mdiChild Not MDI form caption Enter the password Challenge #12 • Paint a Logon form • Code the btnOK_click method • Code the getAndValidateUser method • Test the logon security name txtPassword passwordField True name btnOK caption OK default True 75
Manage the Database Server Client Client Run the Application Distributed Processing 76
JADE Application JADE Database JADE Database 77
JADE Database JADE Database ‘specification’ objects classes methods forms reports ‘data’ objects branches accounts deposits withdrawals 78
JADE Database JADE Database Persistent Cache automatic storage automatic retrieval 79
Database Server Application Server Fat Client Fat Client Fat Client (Web-Enabled Application) Internet Server (Microsoft IIS) HTML Client (Browser) Thin Client Thin Client HTML Client (Browser) Development and Runtime Systems Runtime Systems Only Architecture 80
Persistent Cache Transient Cache TransientDatabase Node Node Background Process Process Process 81
Transient Cache Remote Transient Cache TransientDatabase PersistentDatabase Server Node Server Node Persistent Cache Background Process Server Application Process Server Method Process 82
Persistent Cache Transient Cache Background Process Development Process Client Application Process Debugger Process Painter Process User Interface TransientDatabase Read-OnlySchema Client Node Client Node 83
Persistent Cache Transient Cache Background Process AppServer Application Process Thin Client Process Thin Client Process Thin Client Thin Client Process User Interface CachedForms AppServer Node AppServer Node Read-OnlySchema TransientDatabase 84
Server Node Persistent Database edition=4 Node Node Node Persistent Cache Persistent Cache Persistent Cache edition=5 edition=2 edition=4 Object Editions modified but not committed latest edition obsolete 85
Cache Synchronisation cust.edition(); // returns edition of customer in cache cust.latestEdition(); // returns edition of customer on server Obtaining edition information Locking to obtain the latest edition then checking editions self.exclusiveLock(cust); // any lock ensures latest edition if previousCustomerEdition <> cust.edition() then // compare a previous edition number Resynching to obtain the latest edition cust.resynch(); // customer resynchs itself self.resynchObject(cust); // 'self' resynchs the customer Customer.resynchInstances(); // resynchs all Customer instances 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
Challenge #13 • 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 88
Challenge #14 Run the default application in the Architecture schema 89
Challenge #15 • Extract your schemas • Remove your schemas • Run the JADE loader program 90
“The process . . . . . . . . . . has a lock on . . . . . . . . the object” Lock Diagrams Who owns the lock? object1.exclusiveLock (object2); self.exclusiveLock (object2); 91
Lock Combinations exclusive Exclusive process A shared shared process A process B Shared shared shared process D process C reserve shared process A process B Reserve shared shared process D process C 92
Lock Durations • Session • released when process ceases • Transaction • released when abortTransaction or commitTransaction 93
Database Server Persistent Cache successful lock edition check cache updated edition=3 edition=2 edition=3 Latest Edition resynchObject(object); // object marked as obsolete write object.name; // edition checked so // latest object now in cache 94
process start process end beginTransaction beginLoad (beginLock) endLoad (endLock) commitTransaction (abortTransaction) read transaction update transaction session Transactions 95
Read Transactions • Locks not required but must guarantee correct result. Has logical start and end. • beginLock/endLock or beginLoad/endLoad 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 beginLoad; sharedLock(account); // account is locked trial := trial + account.getBalance(); endLoad; // account is unlocked 96
Database Server Persistent Cache failed transaction ‘dirty’ object discarded edition=4 edition=3 Database Server Persistent Cache successful transaction database updated edition=4 edition=3 edition=4 Updating Transactions 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); 98
Lock Queue ServerTimeout=10000 (10 sec) LockQueueCheckInterval=1000 (1 sec) Lock Queue If lock cannot be obtained immediately If lock has not been obtained Lock Exception 99