Mapping Existing Globals To Objects and SQL: Mike Larocca Intersystems Corporation
Mapping Existing Globals To Objects and SQL: Mike Larocca Intersystems Corporation
CacheStorage
CacheSQLStorage
CustomStorage
CacheSQLStorage Example
Storage Strategy Comparisons
SQL
Objects
CacheStorage
CacheSQLStorage
CustomStorage
CacheSQLStorage Example
CacheStorage Overview
Application
Globals
CacheStorage Notes
CacheStorage
CacheSQLStorage
CustomStorage
CacheSQLStorage Example
CacheSQLStorage Overview
Application
SELECT
INSERT /
DELETE
SQL
UPDATE
Implementation
Globals
CacheSQLStorage Mapping –
A Bird’s Eye View
• Create a Persistent Class
• Add properties to your new class
• Figure out which property (or properties) will be your
unique identifier (IDKey / Primary Key) for the class
• Create a storage strategy, mapping your class properties to
your global data
CacheSQLStorage Maps
CacheStorage
CacheSQLStorage
CustomStorage
CacheSQLStorage Example
CustomStorage Overview
Application
? ? ?
Custom
Implementation
Globals
CustomStorage Mapping –
A Bird’s Eye View
• Create a Persistent Class
• Add properties to your new class
• Figure out which property (or properties) will be your
unique identifier (IDKey / Primary Key) for the class
• Create a storage strategy, mapping your class properties to
your global data
• Implement the Object access code, namely: %LoadData,
%SaveData, %DeleteData
CustomStorage and SQL
Quit $$$OK
}
%SaveData
• Code implemented by %SaveData() will be executed each time an
object is saved by calling the %Save() method
• %SaveData Example:
Method %SaveData(id As %Library.String) As %Library.Status
{
Lock ^P(id):5 If '$Test Quit $$$ERROR($$$LockFailedToAcquireExclusive)
Set id = i%SSN
Do ..%IdSet(id)
Quit $$$OK
}
%DeleteData
• Code implemented by %DeleteData will be executed each time an
object is deleted, by calling %Delete() or %DeleteId()
• %DeleteData example:
Method %DeleteData(id As %String, concurrency as %Integer) As %Status
{
Lock ^P(id):5 If '$Test Quit $$$ERROR($$$LockFailedToAcquireExclusive)
Kill ^P(id)
Quit $$$OK
}
Agenda
Storage Strategy Overview
CacheStorage
CacheSQLStorage
CustomStorage
CacheSQLStorage Example
Example Data Model
Patient
Address
Phone
Doctor Visits
Numbers
• Deleting a patient should delete all related phone numbers & visits
Example Data Global Structure
^P(SSN) = “Name^DOB^Phone1~Phone2~...~PhoneN^Company”
^P(SSN,“Address”) = “City^PostalCode^Country”
^P(SSN,“Visits”,VisitDate,VisitTime) = “Symptom^Payment”
^P(“211-22-1222”) = “Smith,John^39873^718-317-3312~917-225-2213^AT&T”
^P(“211-22-1222”,“Address”) = “New York^10312^USA”
^P(“211-22-1222”,“Visits”,58809,43200) = “Cough^15.00”
^P(“211-22-1222”,“Visits”,58820,57900) = “Sore Throat^50.00”
Example Index Global Structure
^PI(Name,SSN) = “”
^PI(“Smith,John”,“211-22-1222”) = “”
Create a Persistent Class
Add Properties
Choose a Unique Identifier
• In addition to naming the property in this class (PatientRef here), you must
also specify the inverse side of the relationship (Visits here)
Add Additional Properties
Choose a Unique Identifier
• This time, our identifier will be based on 2 fields: VisitDate and VisitTime
Declare an ID / Primary Key Index