1
ADF Mobile The Data Layer 2
Mobile Device Device Services ADF Mobile Architecture Device Native Container HTML5 & JavaScript Presentation Phone Gap Native View ADF Mobile XML View ADF Controller Local HTML Java VM ADF Model Java Business Logic Web View Server HTML App Config Encrypted SQLite DB Credential Management, SSO & Access Control Configuration Server Oracle IDM Oracle IAM Third Party Web Sites Server or Cloud backend SOAP & REST Web Services Servers 3
Back-end Data Service Scenarios Online Read/Write Needs to be continuously connected. No sync required Cached Reads, Online Write Caches data as it is accessed. Updates are via direct web service calls. No sync required Cached Reads, Offline Writes Caches data as it is accessed. Requires offline writes be saved locally as transactions and uploaded/replayed at the server Full Synchronization All data is synchronized to the device. Offline writes saved locally as transactions and uploaded/replayed at the server 4
Data Sources for ADF Mobile Applications Remote - Web service SOAP REST XML REST JSON Local Java Classes SQLite DB 5
ADF Mobile Web Services Backend SOAP Created using the Web Service Data Control wizard - Must specify a WSDL file Allows declarative invocation of WS methods REST-XML Created using the URL Data Control wizard - Must specify an XSD Allows declarative invocation of WS methods REST-JSON Connection created using the URL Data Control wizard Must be invoked programmatically and results parsed by the developer restserviceadapter and JSON parsers classes provided as a helper utilities 6
ADF Mobile Local Data Service Object Java class for CRUD operations Wrapped with a Data Control interface Returns arrays of Data Objects in the get methods Should not access bindings on a page Data Object Java class to hold attributes of an object Represents a single row of a collection Can contain sub-collections of other Data Objects for form complex object hierarchies Should not access bindings on a page 7
Data Control Data Control AMX Service Object Architecture Java VM ADF Model Service Object Data Object JDBC Encrypted SQLite DB restserviceadapter AdfmfJavaUtilities invokedatacontrolmethod REST-JSON SOAP/REST-XML SOAP/REST-XML Web Services 8
ADF Mobile Data Controls Declarative Binding Data abstraction layer Contains all references to data objects for the project Allows easy drag & drop binding of data Controls to UI Can represent Java Beans and SOAP/REST Web Services Managed in datacontrols.dcx file 9
Data Control Data Control Data Control AMX Architecture Web View Java VM Page Definition ADF Model AMX Page Bindings Service Object Data Object Data EL Bindings Web Services Device Feature s Bindings Device and Application Services Data Event EL Managed Beans Backing Beans 10
SOAP Web Service Data Control Declarative Creation 11
XML REST Services Create URL data control Enter authentication details for a secured REST service Select a HTTP method (Get/Post/Delete) for the REST service Specify the path to the complete URL and parameters in the source field Import/Point to an XSD as needed 12
JSON REST Service Create a URL Connection that points to the JSON data host This URL should be based on the root of all JSON services For example, for a JSON service that returns employees and departments (http://server:port/service/employees and http://server:port/service/departments), the URL Data Control should point to http://server:port/service/. Use RestServiceAdaptor to invoke service 13
RestServiceAdaptor Example public void loaddata() { RestServiceAdapter restserviceadapter = Model.createRestServiceAdapter(); restserviceadapter.clearrequestproperties(); restserviceadapter.setconnectionname("geoip"); restserviceadapter.setrequesttype(restserviceadapter.request_type_get); restserviceadapter.setretrylimit(0); restserviceadapter.setrequesturi("/json/" + getsearchip()); setjsonresponse(""); try { setjsonresponse(restserviceadapter.send("")); RESTJSONResponse res = new RESTJSONResponse(); res = (RESTJSONResponse)JSONBeanSerializationHelper.fromJSON(RESTJSONResponse.class, getjs setresponse(res); } catch (Exception e) { e.printstacktrace(); } } 14
Storing Data - SQLite Designed for use as an embedded database system Typically used by a single user Embedded within the application itself It is contained in a small library optimized for mobile SQLite libraries and JDBC drivers are embedded in ADF Mobile container Encryption for the SQLite Database File is provided with ADF Mobile 15
Initialize the Database LifeCycleListenerImpl.java call Start() Application starts up Note: Need to add LifeCycleListenerImpl.java to the LifeCycleEvent Listener Field of the adfmf-application.xml file. Start() 1. Creates Connection 2. Connects 3. Creates the DB 4. Populates DB 16
Access Local SQLite Data Simple Java Classes Use JDBC Exposed as Data Controls 17
JDBC Example Get Departments public void retrivedepartments() { try { Connection conn = DBConnectionFactory.getConnection(); s_departments.clear(); conn.setautocommit(false); PreparedStatement stat = conn.preparestatement("select * from DEPARTMENTS"); ResultSet rs = stat.executequery(); while (rs.next()) { int id = rs.getint("department_id"); String deptname = rs.getstring("department_name"); int mgrid = rs.getint("manager_id"); int locid = rs.getint("location_id"); Department d = new Department(id, deptname, mgrid, locid); s_departments.add(d); } rs.close(); 18
PRODUCT DEMONSTRATION Working with data sources 19
Summary Access remote data through Web services Data controls simplify data access Declarative or programmatic approach Local data accessed using Java Local data storage with SQLite 20
21