• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Sync It Up
 

Sync It Up

on

  • 2,075 views

Sync It Up: Synchronize Your Desktop Data with AIR and SQLite @ FITC Toronto, 2008

Sync It Up: Synchronize Your Desktop Data with AIR and SQLite @ FITC Toronto, 2008

Statistics

Views

Total Views
2,075
Views on SlideShare
1,773
Embed Views
302

Actions

Likes
0
Downloads
19
Comments
0

5 Embeds 302

http://eismann-sf.com 184
http://voisen.org 115
http://72.14.235.104 1
http://192.168.10.100 1
http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Sync It Up Sync It Up Presentation Transcript

    • ME: SEAN VOISEN THIS: SYNC IT UP Synchronizing Desktop Data with AIR and SQLite @ FITC, Toronto on April 21, 2008Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • A FEW ASSUMPTIONS ...•YOU KNOW SOME AS3•YOU’VE TRIED AIR DEVELOPMENT•YOU KNOW A LITTLE SQL
    • 1. WHY SYNCHRONIZE? 2. SYNCHRONIZATION STRATEGIES. 3. DESIGN PATTERNS. 4. SQLITE IN AIR. 5. CONNECTION DETECTION IN AIR. 6. AS3 PROGRAMMING STRATEGIES.Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • WHY SYNCHRONIZE? When it’s not always good to have your head in the “cloud.”Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • •OFFLINE DATA ACCESS •LARGE DATA SETS •FASTER START UP TIME •STORE EPHEMERAL DATA •EXPORT DATA EASILYSean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • SYNCHRONIZATION STRATEGIES. Keeping your data fresh.Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • •USER MAKES CHANGES WHILE OFFLINE •DATA IS CHANGED ON SERVER BY THIRD PARTIES •DATA IS CHANGED LOCALLY BY THIRD PARTIES (RSS FEEDS)Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • MANUAL SYNC •REQUIRES USER TO PUSH A BUTTON •GOOD FOR SHORT SYNC TIMES OR SMALL AMOUNTS OF DATA •EASIEST TO IMPLEMENT •BUT ... USER MAY FORGETSean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • BACKGROUND SYNC •WORKS “BEHIND THE SCENES” WITHOUT INTERVENTION •USE TIMER OR TRIGGERING EVENTS (PROBABLY BOTH) •SERVER CAN PUSH DATA (LIVECYCLE DATA SERVICES)Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • WHAT TO SYNC •TIMESTAMPS •“DIRTY” BITS •DIRECT DATA COMPARISON •COLLISIONS: CLIENT OVERRIDES SERVER, SERVER OVERRIDES CLIENTSean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • DESIGN PATTERNS Make it beautiful and usable.Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • •PATTERN: AN APPROPRIATE AND SUCCESSFUL APPROACH TO A PROBLEM.Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • BRETT RAMPATA
    • •ACCOMODATES BOTH MANUAL AND BACKGROUND SYNCHRONIZATION•UNOBTRUSIVE•CONNECTION AVAILABILITY AND SYNC ARE VISUALLY LINKED
    • DEMO: PAYPAL DESKTOP.A combined project of Adobe XD and PayPal, with alittle help from yours truly.
    • SQLite in AIR. What you need to know to get your feet wet.Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • •EMBEDDED SQL DATABASE ENGINE •NO SETUP, NO SERVER •DATABASE IS STORED AS A SINGLE FILE •MOST OF SQL92 SUPPORTED • INCLUDING THE ADVANCED STUFF LIKE VIEWS, TRANSACTIONS AND TRIGGERS!Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • DATA TYPES in SQLite •SQLite USES TYPE AFFINITIES •TYPE “AFFINITY” = RECOMMENDED, BUT NOT REQUIRED •THE NORMAL SQLite AFFINITIES: • NULL, INTEGER, REAL, TEXT, BLOBSean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • •ADDITIONAL TYPE AFFINITIES AVAILABLE FOR AIR: • TEXT, NUMERIC, INTEGER, REAL, BOOLEAN, DATE, XML, XMLList, OBJECT, NONESean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • THE BASICS 1. CREATE A File REFERENCE FOR THE DB 2. CREATE A SQLConnection INSTANCE 3. OPEN SQLConnection ON FILE 4. CREATE A QUERY USING SQLStatement 5. EXECUTE THE QUERYSean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • var db:File = File.applicationStorageDirectory.resolvePath( "filename.db");var connection:SQLConnection = new SQLConnection();connection.openAsync(db, SQLMode.CREATE);var stmt:SQLStatement = new SQLStatement();stmt.sqlConnection = connection;stmt.text = "SELECT * FROM mytable";stmt.addEventListener( SQLEvent.RESULT, onResult );stmt.execute();
    • •SQLConnection SUPPORTS BOTH SYNCHRONOUS AND ASYNCHRONOUS CONNECTIONS • SYNC: APP INTERACTIVITY BLOCKED UNTIL COMPLETE (LIKE FILE I/O API) • ASYNC: USES EVENT LISTENERS AND QUERIES ARE QUEUEDSean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • ABOUT PARAMETERS var stmt:SQLStatement = new SQLStatement(); stmt.text = "SELECT * FROM mytable WHERE id = :id"; stmt.parameters[":id"] = 5; stmt.execute(); •CACHES QUERY FOR FASTER EXECUTION •PREVENTS INJECTION VULNERABILITYSean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • ABOUT RESULT PAGING •SQLStatement SUPPORTS PAGING •LIMITS NUMBER OF ROWS RETURNED var statement:SQLStatement = new SQLStatement(); statement.sqlConnection = mySQLConnection; statement.text = "SELECT * FROM contacts"; statement.execute( 10 ); statement.next();Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • ABOUT TRANSACTIONS •MULTIPLE STATEMENTS (USING LOOPS) IN ONE WRITE OPERATION •ALLOWS ROLLBACKS ON ERROR var stmt:SQLStatement = new SQLStatement(); stmt.sqlConnection = connection; stmt.text = "INSERT INTO tasks VALUES(:task)"; connection.begin(); for each( var task:String in tasks ) { stmt.parameters[":task"] = task; stmt.execute(); } connection.commit();Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • CONNECTION DETECTION in AIR. Is this thing on?Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • •NATIVE NativeApplication.nativeApplication.addEventListener( Event.NETWORK_CHANGE, onNetworkChange ); • ONLY DETECTS A CHANGE! •SERVICE MONITOR FRAMEWORK • URLMonitor var m:URLMonitor = new URLMonitor( new URLRequest(http://myurl.com) ); m.addEventListener( StatusEvent.STATUS, onStatus ); m.start(); • SocketMonitorSean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • AS3 PROGRAMMING STRATEGIES A few tips to make your life easier.Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • CREATE DAOs •DAO = DATA ACCESS OBJECT •SINGLETON or STATIC CLASS •ABSTRACTS SQL MANIPULATION, HANDLES CRUD OPERATIONS •ONE PLACE FOR DB ACCESS and HANDLING DB ERRORSSean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • public class ContactsDAO { private static var instance:ContactsDAO; public function ContactsDAO() { if( ContactsDAO.instance != null ) { throw new Error("Singleton!"); } } public static function getInstance():ContactsDAO { if( ContactsDAO.instance == null ) { ContactsDAO.instance = new ContactsDAO(); } return ContactsDAO.instance; } public function getAllContacts( resultHandler:Function, faultHandler:Function ):void { var statement:SQLStatement = new SQLStatement(); statement.sqlConnection = mySQLConnection; statement.text = "SELECT * FROM contacts"; statement.execute( -1, new Responder( function( result:SQLResult ):void { resultHandler.call( this, result.data ); }, faultHandler ) ); }}
    • USE “IF NOT EXISTS” •CREATE TABLES WHEN DB IS OPENED IF THEY DON’T EXIST var statement:SQLStatement = new SQLStatement(); statement.sqlConnection = mySQLConnection; statement.text = "CREATE TABLE IF NOT EXISTS mytable (" + "id INTEGER PRIMARY KEY AUTOINCREMENT," + "first_name TEXT," + "last_name TEXT)"; statement.addEventListener( SQLEvent.RESULT, onResult ); statement.execute();Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • WATCH FOR MEMORY LEAKS •DATA QUERIED FROM SQL STORED IN Array/ArrayCollection • DATA CAN’T BE USED DIRECTLY FROM DB IN GRIDS, CHARTS, ETC. • RELOAD ALL DATA IN ARRAYS? OR INDIVIDUAL ITEMS? •USE FLEX 3 PROFILERSean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • DEMO: LibrarianFree sample code to be posted on voisen.org
    • USE SQLiteAdmin •USED TO HANDY TOOLS LIKE PHPMyAdmin? Try: http://coenraets.org/blog/2008/02/ sqlite-admin-for-air-10/Sean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • DEMO: SQLite Admin.By Christophe Coenraets.
    • RESOURCES •CHRISTOPHE COENRAETS: coenraets.org - SQLite Admin for AIR •PETER ELST: peterelst.com - SQLite Wrapper Classes •PAUL ROBERTSON: probertson.com - Insider info on AIR SQLite •ADOBE XD: xd.adobe.comSean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
    • QUESTIONS? Web: http://voisen.org E-mail: sean@voisen.orgSean Voisen 2008.Licensed under Creative Commons Attribution No-Derivatives 3.0 license.