This workshop handles the concept of using Object Relational Mapping features from ColdFusion 9 in AIR to synchronise your local database with a remote server without writing any SQL code.
2. Who Am I ?
Steven Peeters
Instructor / consultant at multimediacollege™
Adobe Flex & AIR Certified Instructor
ColdFusion User Group Manager
10+ years development experience
Author for Friends of ED
Email: steven@multimediacollege.be
LinkedIn: www.linkedin.com/in/stevenpeeters
Blog: www.multimediacollege.be/blog
Twitter: @aikisteve
Personal site: www.flexpert.be
3. What will I be talking about?
SQLite basics
Synchronous vs asynchronous access
Encryption
ORM
Hands-on exercise
12. SQLite: advantages
Resides on client
Can be encrypted to protect data inside
13. SQLite: advantages
Resides on client
Can be encrypted to protect data inside
Cross-platform
14. SQLite: advantages
Resides on client
Can be encrypted to protect data inside
Cross-platform
Easy to use
15. SQLite: advantages
Resides on client
Can be encrypted to protect data inside
Cross-platform
Easy to use
Both synchronous and asynchronous access
19. SQLite: disadvantages
Limited SQL statements
No full ANSI-92 SQL support
No ALTER TABLE <table> ALTER COLUMN
20. SQLite: disadvantages
Limited SQL statements
No full ANSI-92 SQL support
No ALTER TABLE <table> ALTER COLUMN
Limited data types
21. SQLite: disadvantages
Limited SQL statements
No full ANSI-92 SQL support
No ALTER TABLE <table> ALTER COLUMN
Limited data types
INTEGER
22. SQLite: disadvantages
Limited SQL statements
No full ANSI-92 SQL support
No ALTER TABLE <table> ALTER COLUMN
Limited data types
INTEGER
REAL
23. SQLite: disadvantages
Limited SQL statements
No full ANSI-92 SQL support
No ALTER TABLE <table> ALTER COLUMN
Limited data types
INTEGER
REAL
TEXT
24. SQLite: disadvantages
Limited SQL statements
No full ANSI-92 SQL support
No ALTER TABLE <table> ALTER COLUMN
Limited data types
INTEGER
REAL
TEXT
BLOB
25. SQLite: disadvantages
Limited SQL statements
No full ANSI-92 SQL support
No ALTER TABLE <table> ALTER COLUMN
Limited data types
INTEGER
REAL
TEXT
BLOB
DATE
26. SQLite: disadvantages
Limited SQL statements
No full ANSI-92 SQL support
No ALTER TABLE <table> ALTER COLUMN
Limited data types
INTEGER
REAL
TEXT
BLOB
DATE
Mapping remote DB can be troublesome
29. SQLite: encryption
Need password before accessing the database
Use EncryptionKeyGenerator to validate the
strength of the password
30. SQLite: encryption
Need password before accessing the database
Use EncryptionKeyGenerator to validate the
strength of the password
as3corelib project on code.google.com
31. SQLite: encryption
Need password before accessing the database
Use EncryptionKeyGenerator to validate the
strength of the password
as3corelib project on code.google.com
Re-encryption possible
32. SQLite: encryption
Need password before accessing the database
Use EncryptionKeyGenerator to validate the
strength of the password
as3corelib project on code.google.com
Re-encryption possible
connection.open(dbFile, SQLMode, autoCompact, pageSize, encryptionKey);
connection.openAsync(dbFile, SQLMode, autoCompact, pageSize, encryptionKey);
34. Password as encryption key
Login procedure used for obtaining encryption
password at runtime
35. Password as encryption key
Login procedure used for obtaining encryption
password at runtime
Password doesn’t have to be stored
36. Password as encryption key
Login procedure used for obtaining encryption
password at runtime
Password doesn’t have to be stored
Need to re-encrypt DB when user changes
password
38. Password as encryption key
What if user changes password on another
machine?
2 passwords for same application
39. Password as encryption key
What if user changes password on another
machine?
2 passwords for same application
synchronise with remote server
40. Password as encryption key
What if user changes password on another
machine?
2 passwords for same application
synchronise with remote server
store current password in ELS
41. Password as encryption key
What if user changes password on another
machine?
2 passwords for same application
synchronise with remote server
store current password in ELS
Log in procedure:
42. Password as encryption key
What if user changes password on another
machine?
2 passwords for same application
synchronise with remote server
store current password in ELS
Log in procedure:
- Online: attempt login with new password
43. Password as encryption key
What if user changes password on another
machine?
2 passwords for same application
synchronise with remote server
store current password in ELS
Log in procedure:
- Online: attempt login with new password
• Success: re-encrypt and update ELS
44. Password as encryption key
What if user changes password on another
machine?
2 passwords for same application
synchronise with remote server
store current password in ELS
Log in procedure:
- Online: attempt login with new password
• Success: re-encrypt and update ELS
• Fail: attempt login with ELS password
45. Password as encryption key
What if user changes password on another
machine?
2 passwords for same application
synchronise with remote server
store current password in ELS
Log in procedure:
- Online: attempt login with new password
• Success: re-encrypt and update ELS
• Fail: attempt login with ELS password
- Offline: attempt login with ELS password
48. Synchronous access
Similar to executing an ActionScript method
pauses application
49. Synchronous access
Similar to executing an ActionScript method
pauses application
immediate result
50. Synchronous access
Similar to executing an ActionScript method
pauses application
immediate result
Very easy to understand
51. Synchronous access
Similar to executing an ActionScript method
pauses application
immediate result
Very easy to understand
Very easy to use
52. Synchronous access
Similar to executing an ActionScript method
pauses application
immediate result
Very easy to understand
Very easy to use
Not always user friendly with batch operations
53. Synchronous access
public function insertRecord(firstname:String, lastname:String):void {
_dbConnection.open(_dbFile);
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = _dbConnection;
stmt.text = “INSERT INTO person(firstname, lastname) “
+ “VALUES (‘Steven’, ‘Peeters’)”;
stmt.execute();
_dbConnection.close();
}
57. Asynchronous access
Fire and forget
does not pause application
don’t know when result is available
58. Asynchronous access
Fire and forget
does not pause application
don’t know when result is available
Needs event handler to capture result
59. Asynchronous access
Fire and forget
does not pause application
don’t know when result is available
Needs event handler to capture result
More complex
60. Asynchronous access
Fire and forget
does not pause application
don’t know when result is available
Needs event handler to capture result
More complex
Especially useful with batch operations
61. Asynchronous access
public function openDB():void {
_dbConnection.openAsync(_dbFile);
_dbConnection.addEventListener(SQLEvent.OPEN, insertRecord);
}
public function insertRecord(event:SQLEvent):void {
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = _dbConnection;
stmt.text = “INSERT INTO person(firstname, lastname) “
+ “VALUES (‘Steven’, ‘Peeters’)”;
stmt.addEventListener(SQLEvent.RESULT, recordInserted);
stmt.execute();
}
public function recordInserted(event:SQLEvent):void {
_dbConnection.close();
}
66. ORM
What the <bleep> is ORM?
Object Relational Mapping
Hibernate framework
Server technology
67. ORM
What the <bleep> is ORM?
Object Relational Mapping
Hibernate framework
Server technology
Database independent
68. ORM
What the <bleep> is ORM?
Object Relational Mapping
Hibernate framework
Server technology
Database independent
No more SQL
69. ORM
What the <bleep> is ORM?
Object Relational Mapping
Hibernate framework
Server technology
Database independent
No more SQL
Implicit getters/setters in ColdFusion
70. ORM
What the <bleep> is ORM?
Object Relational Mapping
Hibernate framework
Server technology
Database independent
No more SQL
Implicit getters/setters in ColdFusion
71. ORM
What the <bleep> is ORM?
Object Relational Mapping
Hibernate framework
Server technology
Database independent
No more SQL
Implicit getters/setters in ColdFusion
Let’s look at the code...
74. ORM in AIR
Server technology on client?
cfair.swc
75. ORM in AIR
Server technology on client?
cfair.swc
To be found in CFIDE/Scripts/AIR on server
76. ORM in AIR
Server technology on client?
cfair.swc
To be found in CFIDE/Scripts/AIR on server
Works with local SQLite database
77. ORM in AIR
Server technology on client?
cfair.swc
To be found in CFIDE/Scripts/AIR on server
Works with local SQLite database
Need to adjust DTOs with metadata
78. ORM in AIR
Server technology on client?
cfair.swc
To be found in CFIDE/Scripts/AIR on server
Works with local SQLite database
Need to adjust DTOs with metadata
Use SyncManager class
79. ORM in AIR
Server technology on client?
cfair.swc
To be found in CFIDE/Scripts/AIR on server
Works with local SQLite database
Need to adjust DTOs with metadata
Use SyncManager class
No BLOB possible :-(
80. ORM in AIR
Server technology on client?
cfair.swc
To be found in CFIDE/Scripts/AIR on server
Works with local SQLite database
Need to adjust DTOs with metadata
Use SyncManager class
No BLOB possible :-(
81. ORM in AIR
Server technology on client?
cfair.swc
To be found in CFIDE/Scripts/AIR on server
Works with local SQLite database
Need to adjust DTOs with metadata
Use SyncManager class
No BLOB possible :-(
Let’s look at the code...