Databases for Mobile Devices

  • Published on

  • View

  • Download

Embed Size (px)


Databases for Mobile Devices. Introduction. Overview. Different types of data storages Memory management Local database techniques in BlackBerry devices Data Integrity in persistent storage model Security Techniques in Persistent storage Remote database techniques BlackBerry Gateways. - PowerPoint PPT Presentation


<ul><li><p>Databases for Mobile DevicesIntroduction</p><p></p><p>OverviewDifferent types of data storagesMemory managementLocal database techniques in BlackBerry devicesData Integrity in persistent storage modelSecurity Techniques in Persistent storageRemote database techniquesBlackBerry Gateways</p><p></p><p>Different Types of Data Storage in BlackBerryThere are two types of built-in memory in BlackBerry devices:FlashOperating system, deployed applications and all persistent data such as PIM data, SMS/MMS messages and emails are stored in flash memory persistently. The size of flash memory depends on the device.SRAMIn Static RAM, data persists as long as the device is on. It is used in runtime process, loading applications and objects. It is fast.</p><p></p><p>Extendable MemorymicroSD expandable memory cardYou can extend the memory of your phone with a microSD card. MicroSD cards are persistent storages in which you can store documents, pictures, music and other media.</p><p>In order to use microSD card, the device must support expandable memory functionality. The size of card your BlackBerry can support depends on the version of handheld OS software running on your device.</p><p></p><p>Memory Management The BlackBerry JVM performs memory allocation, garbage collection, memory management and swapping data between memories.Persistent data is stored in flash memory. When you load, execute or update application/ data, it is copied in RAM. Then, it is written back to flash memory.Hence, data is swapped continuously between flash and RAM. </p><p></p><p>Garbage CollectionGarbage collection is handled by JVM. It removes unreferenced objects from RAM.It is only operated when: JVM faces with a lack of space in RAM and can not allocate objects. Objects handles are not availableThe device is idleThe allocated heap size is exhausted</p><p></p><p>Optimizing the memory usageAs mobile devices are limited in resources such as memory and battery consumption, it is recommended to minimize the memory use by performing the following guidelines:Help Garbage collector with release resources after use. Set their reference to null after use.Avoid creating many objects and global variables. Try to reuse objects as much as possible. Having too many objects can cause you run out of memory.</p><p></p><p>Optimizing the memory usage (Cont.)Use primitive types such as int rather than objects like Vector, IntegerReduce object handles. Try to group objects. It reduces the number of object handles</p><p></p><p>Database TechniquesDatabases can be accessed either locally or remotely.In local access, persistent storage is located in the mobile devices meaning that data can be stored locally on the device.In remote access, databases are located in the server. They can be access using data access tier or web services.</p><p></p><p>Local Database TechniquesPersistence storages techniques in BlackBerry devices:</p><p>BlackBerry Persistent Store ModelMIDP RMS (Record Store Model)Storing data on the expanable microSD card using File Connection APIsRelational ModelAccess to PIM data</p><p></p><p>BlackBerry Persistent Store ModelBlackBerry Persistent Store Model provides a set of APIs for storing data permanently to flash memory in the BlackBerry device.Using the APIs, you are able to store, retrieve and manipulate data to/from the persistent storage.You are also able to save an entire Java object to memory without doing serialization.</p><p></p><p>BlackBerry Persistent Store Model (Cont.)The BlackBerry API for persistent store model is in net.rim.device.api.system package.In this model, data is stored as instances of PersistentObject.PersistentObject can be any object that implements the Persistable interface. PersistentStore is a store of persistent objects.</p><p></p><p>BlackBerry Persistent Store Model (Cont.)There is not a size limit exists on a persistent store.In Week 2, you will learn more details about this model.</p><p></p><p>Example- Persistent Storage API//This object can be added to PersistentStoreclass Student implements Persistable private int studentID;private String name;private String address;private String phone;public void setName(String name){ = name;}public String getName(){return;}</p><p></p><p>MIDP RMS ModelIt provides a mechanism for MIDlets to persistently store, then retrieve and manipulate data.It is a Java ME package supported in the BlackBerry device as well. RMS library package is javax.microedition.rms Data is stored in a Record Store.</p><p></p><p>MIDP RMS Model (Cont.)A Record Store is a collection of persistent records.A record is an array of bytes (byte[]) that can have a different length and type.Each record has a unique identifier called RecordID. It is automatically assigned by an increasing-by-one algorithm.The size limit for a Record Store is 64KB.</p><p></p><p>MIDP RMS Model (Cont.)Each Record Store maintains a version, an integer number, which is incremented every time that the content of a record store is modified.The device platform is responsible to maintain the integrity of the record stores throughout the platform operations such as reboots, battery change and so on.</p><p></p><p>MIDP RMS Model (Cont.)All record store operations are atomic and synchronous. So, there will be no data corruption during multiple access to record stores.However, if you develop multi-threads to access record stores, it is your responsibility to synchronize these accesses.</p><p></p><p>Example- Record Store APIString name="Smith"; try{// To open a record storeRecordStore rs = RecordStore.openRecordStore("phone_book", true);// To add a new record to a record storebyte[] rec = name.getBytes();rs.addRecord(rec, 0, rec.length);</p><p> }catch(RecordStoreException rse) { System.out.println(rse); rse.printStackTrace(); }</p><p></p><p>Storing Data on MicroSDMicroSD cards are expandable memory storages in which data can be stored permanently.In order to store /access data on the SD card, the Java Me package,, is used. The package specification is in JSR 75, File Connection API.</p><p></p><p>Storing Data on MicroSD (Cont.)JSR 75 provides detailed information on the following package:FileConnection API: A J2ME optional package that give Java-enabled devices access to file systems located on mobile devicesPIM API:A J2ME optional package that give access to PIM (Personal Information Management) dataBoth APIs are supported in BlackBerry devices as well.</p><p></p><p>Storing Data on MicroSD (Cont.)The FileConnection API provides:Interfaces:FileConnectionFileSystemListenerClasses:FileSystemRegistryConnectionClosedExceptionIllegalModeException</p><p></p><p>Storing Data on MicroSD (Cont.)File Connection API provides access to files or directories resided on eitherMicroSD cardFileConnection fc = (FileConnection);Or File systems on BlackBerry devicesFileConnection fc = (FileConnection);</p><p></p><p>Example- FileConnection API public void readFile(String filename) throws IOException {//Open a connection to the file FileConnection fc = (FileConnection) "file:///SDCard/BlackBerry/ + filename);if (fc.exists() &amp;&amp; fc.fileSize() != 0) {InputStream is = fc.openInputStream(); // Read data from the input stream byte[] data = new byte[256]; int length = 0; while (-1 != (length = { System.out.println(The content is +new String(data, 0, length); } }}</p><p></p><p>Relational ModelRelational model is not supported in the BlackBerry Persistent models either Persistent Store APIs or RMS.It is the responsibility of developers to create an effective relational object model. </p><p></p><p>Access to PIM DataBlackBerry device Applications can access PIM (or PDAP) data such as contacts, tasks, and calendar.The package net.rim.blackberry.api.pdap supports the required interfaces and classes to access to the PDAP (Personal Digital Assistant Profile) data on the BlackBerry device.Java ME package, javax.microedition.pim, supports PIM data. </p><p></p><p>Access to PIM Data (Cont.)The APIs in the BlackBerry package, net.rim.blackberry.api.pdap, are controlled API. When you use controlled APIs in your application, your application must be signed using a signature key before deploying the application onto the BlackBerry device.</p><p></p><p>PIM ClassIt provides methods for accessing PIM databases on the BlackBerry devices.Invoke PIM.getInstance() to retrieve a PIM object.PIM ListPIM list Provides a list of PIM Items. A PIM item represents a collection of data for PIM data such as a calendar appointment, a contact, a task and so on.A PIM item stores data in fields.</p><p></p><p>PIM Class (Cont.)There are three types of PIM lists:CONTACT_LIST: Represents the contact list typeEVENT_LIST:Represents the event list typeTODO_LIST: Represents the ToDo list type</p><p></p><p>PIM Class (Cont.)Invoke PIM. openPIMList() to open the specified PIM list.PIMList openPIMList(intpimListType, intmode, String name)mode indicates that the list is either READ_ONLY or READ_WRITE or WRITE_ONLY </p><p></p><p>PIM Class (Cont.)The next example demonstrates how to invoke this method. In order to create a contact, you must first create a contact list, then create contacts and add the information to it:Open a contact listCreate a contact on a contact listAdd contact information to the contact objectCommit the contact object to the BlackBerry PIM database.</p><p></p><p>Example- PIM Class// Open a contact list and create a contactimport javax.microedition.pim.*;import net.rim.blackberry.api.pdap.*;try {ContactList contactList =(ContactList)PIM.getInstance().openPIMList (PIM.CONTACT_LIST, PIM.WRITE_ONLY);Contact contact = contactList.createContact();} catch(Exception ex){}</p><p></p><p>Data Integrity in persistent storage modelData Integrity is one of the important features in persistent models.It means that data should have consistency in terms of both creating and manipulating data all the time.To maintain the data integrity, partial updates are not done if an error occurs during commit.</p><p></p><p>Data Integrity in persistent storage model (Cont.)Partial updates occurs when one part of transaction is rolled back without rolling back the other parts.To maintain data integrity, Persistent Store model in BlackBerry supports both commit and rollback.Data Integrity can be compromised when JVM in BlackBerry devices invokes garbage collector due to low memory</p><p></p><p>Security Techniques in Persistent storageSecurity techniques in BlackBerry devices are summarized as follows:Security in application layer:Controlled APIs: Persistent Storage APIs are controlled API. Applications on the BlackBerry which use these APIs must be digitally signed by RIM.You can run BlackBerry application that use controlled APIs in the BlackBerry simulators without signing the code.</p><p></p><p>Security Techniques in Persistent storage (Cont.)Security in data layer:BlackBerry core applications: user data stored in BlackBerry core applications can be encrypted locally in flash memory by setting IT policy by administrator.</p><p>Third party applications: They should register their data with this encryption service using cryptography APIs. So, before a third party application data commits to flash memory, the encryption service encrypts it with the same key</p><p></p><p>Remote database techniquesYou can access remote data sources from the BlackBerry devices. </p><p>The following presents different ways to access remote databases :N-tier applicationsMDS ApplicationsWeb Services</p><p></p><p>Remote database techniques (Cont.)In order to access data remotely, a distributed (n-tier) architecture is required.</p><p>There are several ways to implement a n-tier architecture. </p><p>In the following slide, a 4-tier architecture is described</p><p></p><p>4-Tier ArchitectureA 4-tier architecture provides 4 separate layers for each of the following tiers:Client-tier: mobile devices are considered as client-tierServer-tier: known as business tier. Business objects, rules and data transformation can be designed in this tier.Data access tier: Interfaces to access data storages, handling data I/O are designed in this layer.Data-tier: Databases and data storages are in this tier.</p><p></p><p>4-Tier Architecture (Cont.)DatabasesBusiness TierClient TierData Access TierDatabasesHTTP ConnectionWireless Network</p><p></p><p>Remote Access to Data SourcesThe Server tier in this architecture can be:An application server :It is a server-side application deployed into the server. It provides the business logic, handles requests, processes and send the response back to the client.A Web ServiceIt implements SOA (Service-Oriented Architecture) concepts. A client-tier application invokes the web service interfaces, in order to access the Web Service methods.</p><p></p><p>Remote Access to Data Sources (Cont.)Client-tierServer-tierDatabaseServer ApplicationWeb Service</p><p></p><p>BlackBerry GatewaysBlackBerry applications can use HTTP, HTTPS or TCP socket to make a connection over the wireless network.In order to minimize the network connection issues, it is recommended to use one of the three wireless gateways to proxy the connection to the Internet or Intranet.</p><p></p><p>BlackBerry Gateways (Cont.)In addition to reduce the network connection issues, they let applications have a consistent connectivity.The Gateways are:BlackBerry Enterprise Server as an Intranet gatewayBlackBerry Internet Service as an Internet gatewayWireless Service Providers Internet gateway</p><p></p><p>BlackBerry Enterprise Server (BES) GatewayBES is a link between BlackBerry devices, wireless network, and application servers enabling access from BlackBerry devices to the corporate data resided on the corporate intranet. The next slide describes the architecture.</p><p></p><p>Remote Data Access using BES with MDS serviceSource:</p><p></p><p>MDS ApplicationsThe BlackBerry Mobile Data System (MDS) is a framework which provides tools to build and deploy BlackBerry Enterprise applications.Before, in order to use corporate applications, customers have to be tied to the corporate email server.Now, BES for MDS has separa...</p></li></ul>