SlideShare una empresa de Scribd logo
1 de 37
Descargar para leer sin conexión
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.

Más contenido relacionado

Similar a 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 a 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
 

Último

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Último (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

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.