42
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 1 Implementing Data Caching and Data Syncing using Oracle Mobile Application Framework (MAF) Steven Davelaar Oracle Mobile A-Team Oracle Corporation @stevendavelaar

Implementing Data Caching and Data Synching Using Oracle MAF

Embed Size (px)

Citation preview

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.1

Implementing Data Caching and Data Syncing using Oracle Mobile Application Framework (MAF)

Steven Davelaar

Oracle Mobile A-Team

Oracle Corporation

@stevendavelaar

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.2

Agenda

� Quick Intro to Oracle MAF

� Designing a Mobile-Optimized API

– On-demand loading versus data caching

� Using A-Team Mobile Persistence Accelerator

– Implementing Data Caching

– Implementing Data Syncing

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.3

Oracle Mobile Application Framework

Productivity boosting mobile development framework

� Build Once, Run on Multiple-Platforms

� Simpler UI development

� Java, JavaScript, and HTML5-based

application development

� Choice of development tools

� Offline-capable: SQLite with Encryption

� Full Access to Native Device Features

� Modular, Reusable Components

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.4

Business Logic Development

Access and Process Application Data

� Code logic with Java

� Lightweight JVM

� Native library on device

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.5

UI Implementation Options in Oracle MAF

� Component based page definition

– AMX Components

� Programmatic HTML5

– with any third-party HTML5 frameworks

� Remote URL

– Any server-side HTML

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.6

Extend and Expand

Add capabilities to the framework

�Cordova Plug-in Support

– Add functionality such as barcode scanning,

NFC, geo-fencing, etc.

– Cross platform

�Custom AMX Component Support

– Allows developer to add custom UI

components to the framework

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.7

Oracle MAF Architecture

Device

Services

PhoneGap/

Cordova

Device Native Container

Web

View

Server

HTML

ADF Mobile

AMX View

Third Party

Web Sites

Third Party

Web Sites

Server or Cloud

backend

Server or Cloud

backend

Oracle IDM

Oracle IAM

Oracle IDM

Oracle IAM

Mobile

Device

Local

HTML

HTML5 & JavaScript Presentation

Configuration

Server

Configuration

Server

ADF Controller

Credential M

anagement,

SSO & Access Contro

l

Credential M

anagement,

SSO & Access Contro

l

App

Config

App

Config

Server

SOAP & REST

Web Services

SOAP & REST

Web Services

Java VM

Business

Logic

ADF Model

Encrypted

SQLite DB

JDBC

SQLite

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.8

Oracle MAF Architecture

Device

Services

PhoneGap/

Cordova

Device Native Container

Web

View

Server

HTML

ADF Mobile

AMX View

Third Party

Web Sites

Third Party

Web Sites

Server or Cloud

backend

Server or Cloud

backend

Oracle IDM

Oracle IAM

Oracle IDM

Oracle IAM

Mobile

Device

Local

HTML

HTML5 & JavaScript Presentation

Configuration

Server

Configuration

Server

ADF Controller

Credential M

anagement,

SSO & Access Contro

l

Credential M

anagement,

SSO & Access Contro

l

App

Config

App

Config

Server

SOAP & REST

Web Services

SOAP & REST

Web Services

Java VM

Business

Logic

ADF Model

Encrypted

SQLite DB

JDBC

SQLite

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.9

Agenda

� Quick Intro to Oracle MAF

� Designing a Mobile-Optimized API

– On-demand loading versus data caching

� Using A-Team Mobile Persistence Accelerator

– Implementing Data Caching

– Implementing Data Syncing

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.10

What is a Mobile API?

� API = Application Programming Interface

� The API is typically hosted on a remote server (on-premise) or in the

cloud

� The mobile app typically accesses the API over HTTP using SOAP or

RESTful web services

1

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.11

What is a Mobile-Optimized API?

� A mobile-optimized API uses RESTful services with JSON payload

– Easy, flexible, performant, de facto standard

– SOAP-XML creates larger payloads and is slower to process

� A mobile-optimized API is designed with mobile app in mind

– Returns clean payloads that are fit for purpose

– Supports required data caching and offline use case scenarios

� Existing back-end system API’s are typically NOT mobile-optimized

1

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.12

Designing a Mobile-Optimized HR API

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.13

Designing a Mobile-Optimized HR API

� Design optimized for on-demand data loading

– Get list of departments with only id and name

– Get details of one department with summary list of employees

– Get details of one employee

� Design optimized for data caching / offline usage

– Get list of departments and its employees with all attributes

� Mobile-optimized API needs to be flexible to support both scenarios!

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.14

Designing a Mobile-Optimized API

� The mobile developer should drive API design

– knows the supported form factors and which data is needed for which

screen.

– knows the requirements for offline mode, and how mobile development tool

set supports and implements this.

– designs data caching strategies for performance optimizations

– decides which read and write actions can be performed in background

thread not impacting user-perceived performance.

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.15

Implementing a Mobile-Optimized API

� Use OSB to transform backend (SOAP) services to mobile API

� Use mock-up API to enable parallel development

– Easy and fast with tools like MongoDB, Node.js, Express

� A-Team article series “Creating a Mobile-Optimized REST API Using

Oracle Service Bus”

– http://www.ateam-oracle.com/?cat=151

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.16

Agenda

� Quick Intro to Oracle MAF

� Designing a Mobile-Optimized API

– On-demand loading versus data caching

� Using A-Team Mobile Persistence Accelerator

– Implementing Data Caching

– Implementing Data Syncing

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.17

A-Team Mobile Persistence Accelerator (AMPA)

� Lightweight persistence framework that works on top of MAF

� Declarative consumption of REST-JSON services

� Significantly speeds up implementation of data caching and data

synching

� Available as open source framework hosted on GitHub

� Provided “as-is”, no support, no updates from Oracle

� Ideas and features from this project will be included in the MAF

product over time.

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.18

AMPA – Project mobile-persistence on GitHub

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.21

MAF Model

Runtime Persistence Architecture

DepartmentService

Data Control

EntityCRUDServiceextends

SQLite

DepartmentService

uses

Department

Persistence

Mapping XML

DEPARTMENTS

table

references

DBPersistence

Manager

JDBC

Statements

REST(JSON/XML)

REST-JSON

PersistenceManager

HTTP

Requests

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.22

AMPA - JDeveloper Wizards

� Three wizard are provided to create the artefacts needed for this

runtime persistence architecture:

– Mobile Business Objects From Web Service Data Control Wizard

– Mobile Business Objects From REST Web Service Wizard

– Mobile Business Objects From Database Tables (Local persistence only)

� Another wizard is provided to generate a default CRUD user interface

on top of the business layer created by one of the above wizards.

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.23

Rest Wizard Demo - Toplink Data ServicesM/ToplinkRest/persistence/v1.0/Model1/query/Department.findAll

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |

Demo: Building Mobile Application – Model layerIncluding data caching, offline usage and data synchronization

Oracle 2

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.63

Configured InitDBLifecycleListener

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.64

Create Data Control For Service Classes

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.65

Creating the Mobile User Interface

� Build Using Drag and Drop

from DataControl Palette

� Generate Using MAF User

Interface Generator

Wizard

Two Options

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.66

Building the User Interface

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.67

Building the User Interface

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.68

Building the User Interface

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |

Demo: Building Mobile Application – UI layerIncluding data caching, offline usage and data synchronization

6

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.70

Using the MAF User Interface Generator

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.71

Using the MAF User Interface Generator

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.72

Generated User Interface Artefacts

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.73

AMPA - Offline Writes and Data Syncing

� If a remote persistence manager is configured, and CUD service call

fails, the service call is registered as “pending” data synch action

– Failure reason registered (device offline, service not available, etc)

� On next service call, the pending synch actions are processed first in

order of creation

– When failing again, the still pending synch action is updated with date of

last synch attempt and last error message

� Out-of-the-box feature: NO Java coding required

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.74

Viewing Pending Data Sync Actions

� A reusable “DataSync” feature is provided that can be added to your

mobile application

� Register the feature in adfmf-application.xml

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.75

Viewing Pending Data Sync Actions

� Add a button that navigates to the data sync feature

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |

Demo: Offline transactions and data syncing

7

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.77

Viewing Pending Data Synch Actions

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.78

Notes on Data Sync Functionality

� Pending changes can become obsolete because of updates in server

data by other clients

– The server–side code should identify this and throw an error when the data

sync action sends stale data

– Stale data detection can be done by including a data revision number or

‘last-modified” timestamp in payload. This number or timestamp should

match with server-side data record

� Data sync actions that keep failing need to be removed manually

– Local database might be out-of-sync, app needs to offer reconcile action

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.79

Other Runtime Persistence Features

� Encryption of database

� Auto-cleaning of unused database segments

� Lazy loading of child collections (a.k.a “Indirection”)

� Entity caching to minimize object creation

� Supports server-derived primary keys

� FindEntityByKey

– Checks cache first, then database

� Designed for customization

– Easy to override and extend default behavior

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.80

AMPA - More Info

� A-Team Chronicles: http://www.ateam-oracle.com/?p=29192

� Includes download links to

– Source code on GitHub

– Videos

– Demo applications

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.81

Summary

� Start with designing and implementing a mobile-optimized REST API

� Use AMPA to declaratively consume the REST/JSON web services

� Use AMPA to implement data caching and syncing using the on-device

SQLite database

� Think about how your end users should handle failed data sync

actions, and how to prevent updates based on stale data

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.82