Flash And The City 2010

1,104 views

Published on

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.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,104
On SlideShare
0
From Embeds
0
Number of Embeds
100
Actions
Shares
0
Downloads
31
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
































































































  • Flash And The City 2010

    1. 1. Working With Data SYNCHRONISING DATABASES WITHOUT SQL STATEMENTS
    2. 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. 3. What will I be talking about?  SQLite basics  Synchronous vs asynchronous access  Encryption  ORM  Hands-on exercise
    4. 4. SQLite
    5. 5. SQLite  Lightweight database
    6. 6. SQLite  Lightweight database  No configuration necessary
    7. 7. SQLite  Lightweight database  No configuration necessary  No tablespaces
    8. 8. SQLite  Lightweight database  No configuration necessary  No tablespaces  No user rights
    9. 9. SQLite  Lightweight database  No configuration necessary  No tablespaces  No user rights  Single database file
    10. 10. SQLite: advantages
    11. 11. SQLite: advantages  Resides on client
    12. 12. SQLite: advantages  Resides on client  Can be encrypted to protect data inside
    13. 13. SQLite: advantages  Resides on client  Can be encrypted to protect data inside  Cross-platform
    14. 14. SQLite: advantages  Resides on client  Can be encrypted to protect data inside  Cross-platform  Easy to use
    15. 15. SQLite: advantages  Resides on client  Can be encrypted to protect data inside  Cross-platform  Easy to use  Both synchronous and asynchronous access
    16. 16. SQLite: disadvantages
    17. 17. SQLite: disadvantages  Limited SQL statements
    18. 18. SQLite: disadvantages  Limited SQL statements  No full ANSI-92 SQL support
    19. 19. SQLite: disadvantages  Limited SQL statements  No full ANSI-92 SQL support  No ALTER TABLE <table> ALTER COLUMN
    20. 20. SQLite: disadvantages  Limited SQL statements  No full ANSI-92 SQL support  No ALTER TABLE <table> ALTER COLUMN  Limited data types
    21. 21. SQLite: disadvantages  Limited SQL statements  No full ANSI-92 SQL support  No ALTER TABLE <table> ALTER COLUMN  Limited data types  INTEGER
    22. 22. SQLite: disadvantages  Limited SQL statements  No full ANSI-92 SQL support  No ALTER TABLE <table> ALTER COLUMN  Limited data types  INTEGER  REAL
    23. 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. 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. 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. 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
    27. 27. SQLite: encryption
    28. 28. SQLite: encryption  Need password before accessing the database
    29. 29. SQLite: encryption  Need password before accessing the database  Use EncryptionKeyGenerator to validate the strength of the password
    30. 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. 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. 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);
    33. 33. Password as encryption key
    34. 34. Password as encryption key  Login procedure used for obtaining encryption password at runtime
    35. 35. Password as encryption key  Login procedure used for obtaining encryption password at runtime  Password doesn’t have to be stored
    36. 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
    37. 37. Password as encryption key  What if user changes password on another machine?
    38. 38. Password as encryption key  What if user changes password on another machine?  2 passwords for same application
    39. 39. Password as encryption key  What if user changes password on another machine?  2 passwords for same application  synchronise with remote server
    40. 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. 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. 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. 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. 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. 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
    46. 46. Synchronous access
    47. 47. Synchronous access  Similar to executing an ActionScript method
    48. 48. Synchronous access  Similar to executing an ActionScript method  pauses application
    49. 49. Synchronous access  Similar to executing an ActionScript method  pauses application  immediate result
    50. 50. Synchronous access  Similar to executing an ActionScript method  pauses application  immediate result  Very easy to understand
    51. 51. Synchronous access  Similar to executing an ActionScript method  pauses application  immediate result  Very easy to understand  Very easy to use
    52. 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. 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(); }
    54. 54. Asynchronous access
    55. 55. Asynchronous access  Fire and forget
    56. 56. Asynchronous access  Fire and forget  does not pause application
    57. 57. Asynchronous access  Fire and forget  does not pause application  don’t know when result is available
    58. 58. Asynchronous access  Fire and forget  does not pause application  don’t know when result is available  Needs event handler to capture result
    59. 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. 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. 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(); }
    62. 62. ORM
    63. 63. ORM What the <bleep> is ORM?
    64. 64. ORM What the <bleep> is ORM?  Object Relational Mapping
    65. 65. ORM What the <bleep> is ORM?  Object Relational Mapping  Hibernate framework
    66. 66. ORM What the <bleep> is ORM?  Object Relational Mapping  Hibernate framework  Server technology
    67. 67. ORM What the <bleep> is ORM?  Object Relational Mapping  Hibernate framework  Server technology  Database independent
    68. 68. ORM What the <bleep> is ORM?  Object Relational Mapping  Hibernate framework  Server technology  Database independent  No more SQL
    69. 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. 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. 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...
    72. 72. ORM in AIR
    73. 73. ORM in AIR  Server technology on client?
    74. 74. ORM in AIR  Server technology on client?  cfair.swc
    75. 75. ORM in AIR  Server technology on client?  cfair.swc  To be found in CFIDE/Scripts/AIR on server
    76. 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. 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. 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. 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. 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. 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...
    82. 82. ORM metadata
    83. 83. ORM metadata  [Entity]
    84. 84. ORM metadata  [Entity]  [Table(name=”name”)]
    85. 85. ORM metadata  [Entity]  [Table(name=”name”)]  [Id]
    86. 86. ORM metadata  [Entity]  [Table(name=”name”)]  [Id]  [Transient]
    87. 87. ORM metadata  [Entity]  [Table(name=”name”)]  [Id]  [Transient]  [Column(name=”name”, columnDefinition=”TEXT| INTEGER|REAL|DATE”, nullable=true|false, unique=true|false)]
    88. 88. ORM metadata  [Entity]  [Table(name=”name”)]  [Id]  [Transient]  [Column(name=”name”, columnDefinition=”TEXT| INTEGER|REAL|DATE”, nullable=true|false, unique=true|false)]  [RemoteClass]
    89. 89. ORM relationship metadata
    90. 90. ORM relationship metadata  [OneToOne(targetEntity=”entity”, fetchType=”EAGER(default)|LAZY”)]
    91. 91. ORM relationship metadata  [OneToOne(targetEntity=”entity”, fetchType=”EAGER(default)|LAZY”)]  [OneToMany(targetEntity=”entity”, mappedBy=”entity”, fetchType=”EAGER(default)| LAZY”)]
    92. 92. ORM relationship metadata  [OneToOne(targetEntity=”entity”, fetchType=”EAGER(default)|LAZY”)]  [OneToMany(targetEntity=”entity”, mappedBy=”entity”, fetchType=”EAGER(default)| LAZY”)]  [ManyToOne(targetEntity=”entity”, fetchType=”EAGER(default)|LAZY”)]
    93. 93. ORM relationship metadata  [OneToOne(targetEntity=”entity”, fetchType=”EAGER(default)|LAZY”)]  [OneToMany(targetEntity=”entity”, mappedBy=”entity”, fetchType=”EAGER(default)| LAZY”)]  [ManyToOne(targetEntity=”entity”, fetchType=”EAGER(default)|LAZY”)]
    94. 94. ORM relationship metadata  [OneToOne(targetEntity=”entity”, fetchType=”EAGER(default)|LAZY”)]  [OneToMany(targetEntity=”entity”, mappedBy=”entity”, fetchType=”EAGER(default)| LAZY”)]  [ManyToOne(targetEntity=”entity”, fetchType=”EAGER(default)|LAZY”)]  [JoinColumn(name=”name”, referencedColumnName=”name”)]
    95. 95. ORM relationship metadata
    96. 96. ORM relationship metadata  [ManyToMany(targetEntity=”entity”, fetchType=”EAGER|LAZY(default)”)]
    97. 97. ORM relationship metadata  [ManyToMany(targetEntity=”entity”, fetchType=”EAGER|LAZY(default)”)]
    98. 98. ORM relationship metadata  [ManyToMany(targetEntity=”entity”, fetchType=”EAGER|LAZY(default)”)]  [JoinTable(name=”name”)]
    99. 99. ORM relationship metadata  [ManyToMany(targetEntity=”entity”, fetchType=”EAGER|LAZY(default)”)]  [JoinTable(name=”name”)]  [JoinColumn(name=”name”, referencedColumnName=”name”)]
    100. 100. ORM relationship metadata  [ManyToMany(targetEntity=”entity”, fetchType=”EAGER|LAZY(default)”)]  [JoinTable(name=”name”)]  [JoinColumn(name=”name”, referencedColumnName=”name”)]  [InverseJoinColumn(name=”name”, referencedColumnName=”name”)]
    101. 101. What can you do with it?
    102. 102. What can you do with it?  Offline applications
    103. 103. What can you do with it?  Offline applications  Use DB as temporary storage
    104. 104. What can you do with it?  Offline applications  Use DB as temporary storage  Online/offline synchronisation
    105. 105. What can you do with it?  Offline applications  Use DB as temporary storage  Online/offline synchronisation  Protect private data
    106. 106. Flexpert Photo
    107. 107. Enough technical blabber Let’s just do it !!!
    108. 108. Thank You... Twitter: @aikisteve Email: steven@multimediacollege.be Blog: www.multimediacollege.be/blog Personal site: www.flexpert.be

    ×