SlideShare a Scribd company logo
1 of 37
Download to read offline
ME: SEAN VOISEN
               THIS: SYNC IT UP
               Synchronizing Desktop Data with AIR and SQLite
               @ FITC, Toronto on April 21, 2008




Sean 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 EASILY

Sean 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 FORGET
Sean 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 CLIENT


Sean 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 a
little 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, BLOB

Sean 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, NONE




Sean 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 QUERY

Sean 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 QUEUED




Sean 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 VULNERABILITY
Sean 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();


                         • SocketMonitor
Sean 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 ERRORS

Sean 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 PROFILER
Sean Voisen 2008.
Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
DEMO: Librarian
Free 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.com
Sean Voisen 2008.
Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
QUESTIONS?
               Web: http://voisen.org
               E-mail: sean@voisen.org




Sean Voisen 2008.
Licensed under Creative Commons Attribution No-Derivatives 3.0 license.

More Related Content

Similar to Sync It Up

Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers Tom Eston
 
OpenStack Technology Overview
OpenStack Technology OverviewOpenStack Technology Overview
OpenStack Technology OverviewOpen Stack
 
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...Amazon Web Services
 
Enterprise Node - Securing Your Environment
Enterprise Node - Securing Your EnvironmentEnterprise Node - Securing Your Environment
Enterprise Node - Securing Your EnvironmentKurtis Kemple
 
NoSQL - No Security?
NoSQL - No Security?NoSQL - No Security?
NoSQL - No Security?Gavin Holt
 
Securing Servers in Public and Hybrid Clouds
Securing Servers in Public and Hybrid CloudsSecuring Servers in Public and Hybrid Clouds
Securing Servers in Public and Hybrid CloudsRightScale
 
(DVO312) Sony: Building At-Scale Services with AWS Elastic Beanstalk
(DVO312) Sony: Building At-Scale Services with AWS Elastic Beanstalk(DVO312) Sony: Building At-Scale Services with AWS Elastic Beanstalk
(DVO312) Sony: Building At-Scale Services with AWS Elastic BeanstalkAmazon Web Services
 
Introduction to AWS Organizations
Introduction to AWS OrganizationsIntroduction to AWS Organizations
Introduction to AWS OrganizationsAmazon Web Services
 
You Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing It
You Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing ItYou Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing It
You Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing ItAleksandr Yampolskiy
 
Simple Principles for Website Security
Simple Principles for Website SecuritySimple Principles for Website Security
Simple Principles for Website SecurityLauren Wood
 
Secure Keystone Deployment
Secure Keystone DeploymentSecure Keystone Deployment
Secure Keystone DeploymentPriti Desai
 
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015Stuart
 
Hack-Proof Your Cloud: Responding to 2016 Threats
Hack-Proof Your Cloud: Responding to 2016 ThreatsHack-Proof Your Cloud: Responding to 2016 Threats
Hack-Proof Your Cloud: Responding to 2016 ThreatsAmazon Web Services
 
vlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets Presentationvlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets PresentationVolodymyr Lavrynovych
 
React Fast by Processing Streaming Data - AWS Summit Tel Aviv 2017
React Fast by Processing Streaming Data - AWS Summit Tel Aviv 2017React Fast by Processing Streaming Data - AWS Summit Tel Aviv 2017
React Fast by Processing Streaming Data - AWS Summit Tel Aviv 2017Amazon Web Services
 
Hack proof your aws cloud cloudcheckr_040416
Hack proof your aws cloud cloudcheckr_040416Hack proof your aws cloud cloudcheckr_040416
Hack proof your aws cloud cloudcheckr_040416Jarrett Plante
 
(ATS4-APP01) Tips and Tricks for a Successful Installation of Accelrys Electr...
(ATS4-APP01) Tips and Tricks for a Successful Installation of Accelrys Electr...(ATS4-APP01) Tips and Tricks for a Successful Installation of Accelrys Electr...
(ATS4-APP01) Tips and Tricks for a Successful Installation of Accelrys Electr...BIOVIA
 
Developing and deploying windows azure applications
Developing and deploying windows azure applicationsDeveloping and deploying windows azure applications
Developing and deploying windows azure applicationsManish Corriea
 

Similar to Sync It Up (20)

Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
 
Spa Secure Coding Guide
Spa Secure Coding GuideSpa Secure Coding Guide
Spa Secure Coding Guide
 
Getting Started with AWS IoT
Getting Started with AWS IoTGetting Started with AWS IoT
Getting Started with AWS IoT
 
OpenStack Technology Overview
OpenStack Technology OverviewOpenStack Technology Overview
OpenStack Technology Overview
 
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
AWS re:Invent 2016: Amazon CloudFront Flash Talks: Best Practices on Configur...
 
Enterprise Node - Securing Your Environment
Enterprise Node - Securing Your EnvironmentEnterprise Node - Securing Your Environment
Enterprise Node - Securing Your Environment
 
NoSQL - No Security?
NoSQL - No Security?NoSQL - No Security?
NoSQL - No Security?
 
Securing Servers in Public and Hybrid Clouds
Securing Servers in Public and Hybrid CloudsSecuring Servers in Public and Hybrid Clouds
Securing Servers in Public and Hybrid Clouds
 
(DVO312) Sony: Building At-Scale Services with AWS Elastic Beanstalk
(DVO312) Sony: Building At-Scale Services with AWS Elastic Beanstalk(DVO312) Sony: Building At-Scale Services with AWS Elastic Beanstalk
(DVO312) Sony: Building At-Scale Services with AWS Elastic Beanstalk
 
Introduction to AWS Organizations
Introduction to AWS OrganizationsIntroduction to AWS Organizations
Introduction to AWS Organizations
 
You Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing It
You Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing ItYou Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing It
You Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing It
 
Simple Principles for Website Security
Simple Principles for Website SecuritySimple Principles for Website Security
Simple Principles for Website Security
 
Secure Keystone Deployment
Secure Keystone DeploymentSecure Keystone Deployment
Secure Keystone Deployment
 
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
 
Hack-Proof Your Cloud: Responding to 2016 Threats
Hack-Proof Your Cloud: Responding to 2016 ThreatsHack-Proof Your Cloud: Responding to 2016 Threats
Hack-Proof Your Cloud: Responding to 2016 Threats
 
vlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets Presentationvlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets Presentation
 
React Fast by Processing Streaming Data - AWS Summit Tel Aviv 2017
React Fast by Processing Streaming Data - AWS Summit Tel Aviv 2017React Fast by Processing Streaming Data - AWS Summit Tel Aviv 2017
React Fast by Processing Streaming Data - AWS Summit Tel Aviv 2017
 
Hack proof your aws cloud cloudcheckr_040416
Hack proof your aws cloud cloudcheckr_040416Hack proof your aws cloud cloudcheckr_040416
Hack proof your aws cloud cloudcheckr_040416
 
(ATS4-APP01) Tips and Tricks for a Successful Installation of Accelrys Electr...
(ATS4-APP01) Tips and Tricks for a Successful Installation of Accelrys Electr...(ATS4-APP01) Tips and Tricks for a Successful Installation of Accelrys Electr...
(ATS4-APP01) Tips and Tricks for a Successful Installation of Accelrys Electr...
 
Developing and deploying windows azure applications
Developing and deploying windows azure applicationsDeveloping and deploying windows azure applications
Developing and deploying windows azure applications
 

Recently uploaded

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Sync It Up

  • 1. ME: SEAN VOISEN THIS: SYNC IT UP Synchronizing Desktop Data with AIR and SQLite @ FITC, Toronto on April 21, 2008 Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 2. A FEW ASSUMPTIONS ... •YOU KNOW SOME AS3 •YOU’VE TRIED AIR DEVELOPMENT •YOU KNOW A LITTLE SQL
  • 3. 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.
  • 4. 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.
  • 5. •OFFLINE DATA ACCESS •LARGE DATA SETS •FASTER START UP TIME •STORE EPHEMERAL DATA •EXPORT DATA EASILY Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 6. SYNCHRONIZATION STRATEGIES. Keeping your data fresh. Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 7. •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.
  • 8. MANUAL SYNC •REQUIRES USER TO PUSH A BUTTON •GOOD FOR SHORT SYNC TIMES OR SMALL AMOUNTS OF DATA •EASIEST TO IMPLEMENT •BUT ... USER MAY FORGET Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 9. 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.
  • 10. WHAT TO SYNC •TIMESTAMPS •“DIRTY” BITS •DIRECT DATA COMPARISON •COLLISIONS: CLIENT OVERRIDES SERVER, SERVER OVERRIDES CLIENT Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 11. DESIGN PATTERNS Make it beautiful and usable. Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 12. •PATTERN: AN APPROPRIATE AND SUCCESSFUL APPROACH TO A PROBLEM. Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 14. •ACCOMODATES BOTH MANUAL AND BACKGROUND SYNCHRONIZATION •UNOBTRUSIVE •CONNECTION AVAILABILITY AND SYNC ARE VISUALLY LINKED
  • 15. DEMO: PAYPAL DESKTOP. A combined project of Adobe XD and PayPal, with a little help from yours truly.
  • 16. 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.
  • 17. •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.
  • 18. DATA TYPES in SQLite •SQLite USES TYPE AFFINITIES •TYPE “AFFINITY” = RECOMMENDED, BUT NOT REQUIRED •THE NORMAL SQLite AFFINITIES: • NULL, INTEGER, REAL, TEXT, BLOB Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 19. •ADDITIONAL TYPE AFFINITIES AVAILABLE FOR AIR: • TEXT, NUMERIC, INTEGER, REAL, BOOLEAN, DATE, XML, XMLList, OBJECT, NONE Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 20. 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 QUERY Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 21. 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();
  • 22. •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 QUEUED Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 23. 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 VULNERABILITY Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 24. 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.
  • 25. 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.
  • 26. CONNECTION DETECTION in AIR. Is this thing on? Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 27. •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(); • SocketMonitor Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 28. AS3 PROGRAMMING STRATEGIES A few tips to make your life easier. Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 29. CREATE DAOs •DAO = DATA ACCESS OBJECT •SINGLETON or STATIC CLASS •ABSTRACTS SQL MANIPULATION, HANDLES CRUD OPERATIONS •ONE PLACE FOR DB ACCESS and HANDLING DB ERRORS Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 30. 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 ) ); } }
  • 31. 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.
  • 32. 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 PROFILER Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 33. DEMO: Librarian Free sample code to be posted on voisen.org
  • 34. 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.
  • 35. DEMO: SQLite Admin. By Christophe Coenraets.
  • 36. 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.com Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.
  • 37. QUESTIONS? Web: http://voisen.org E-mail: sean@voisen.org Sean Voisen 2008. Licensed under Creative Commons Attribution No-Derivatives 3.0 license.