databases for mobile devices n.
Skip this Video
Loading SlideShow in 5 Seconds..
Databases for Mobile Devices PowerPoint Presentation
Download Presentation
Databases for Mobile Devices

Databases for Mobile Devices

106 Vues Download Presentation
Télécharger la présentation

Databases for Mobile Devices

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Databases for Mobile Devices Introduction

  2. 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

  3. Different Types of Data Storage in BlackBerry • There are two types of built-in memory in BlackBerry devices: • Flash • Operating 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. • SRAM • In Static RAM, data persists as long as the device is on. It is used in runtime process, loading applications and objects. It is fast.

  4. Extendable Memory • microSD expandable memory card • You 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. • 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.

  5. 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.

  6. Garbage Collection • Garbage 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 available • The device is idle • The allocated heap size is exhausted

  7. Optimizing the memory usage • As 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.

  8. Optimizing the memory usage (Cont.) • Use primitive types such as int rather than objects like Vector, Integer • Reduce object handles. Try to group objects. It reduces the number of object handles

  9. Database Techniques • Databases 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.

  10. Local Database Techniques • Persistence storages techniques in BlackBerry devices: • BlackBerry Persistent Store Model • MIDP RMS (Record Store Model) • Storing data on the expanable microSD card using File Connection APIs • Relational Model • Access to PIM data

  11. BlackBerry Persistent Store Model • BlackBerry 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.

  12. 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.

  13. 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.

  14. Example- Persistent Storage API //This object can be added to PersistentStore class 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; }

  15. MIDP RMS Model • It 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.

  16. 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.

  17. 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.

  18. 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.

  19. Example- Record Store API String name="Smith"; try{ // To open a record store RecordStore rs = RecordStore.openRecordStore("phone_book", true); // To add a new record to a record store byte[] rec = name.getBytes(); rs.addRecord(rec, 0, rec.length); }catch(RecordStoreException rse) { System.out.println(rse); rse.printStackTrace(); }

  20. Storing Data on MicroSD • MicroSD 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.

  21. 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 devices • PIM API: • A J2ME optional package that give access to PIM (Personal Information Management) data • Both APIs are supported in BlackBerry devices as well.

  22. Storing Data on MicroSD (Cont.) • The FileConnection API provides: • Interfaces: • FileConnection • FileSystemListener • Classes: • FileSystemRegistry • ConnectionClosedException • IllegalModeException

  23. Storing Data on MicroSD (Cont.) • File Connection API provides access to files or directories resided on either • MicroSD card • FileConnection fc = (FileConnection)“file:///SDCard”); • Or – • File systems on BlackBerry devices • FileConnection fc = (FileConnection)“file:///Store”);

  24. 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() && 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); } } }

  25. Relational Model • Relational 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.

  26. Access to PIM Data • BlackBerry 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.

  27. 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.

  28. PIM Class • It provides methods for accessing PIM databases on the BlackBerry devices. • Invoke PIM.getInstance() to retrieve a PIM object. • PIM List • PIM 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.

  29. PIM Class (Cont.) • There are three types of PIM lists: • CONTACT_LIST: • Represents the contact list type • EVENT_LIST: • Represents the event list type • TODO_LIST: • Represents the ToDo list type

  30. PIM Class (Cont.) • Invoke PIM. openPIMList() to open the specified PIM list. • PIMList openPIMList(int pimListType, int mode, String name) • mode indicates that the list is either READ_ONLY or READ_WRITE or WRITE_ONLY

  31. 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 list • Create a contact on a contact list • Add contact information to the contact object • Commit the contact object to the BlackBerry PIM database.

  32. Example- PIM Class // Open a contact list and create a contact import 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) { }

  33. Data Integrity in persistent storage model • Data 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.

  34. 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

  35. Security Techniques in Persistent storage • Security 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.

  36. 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. • 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

  37. Remote database techniques • You can access remote data sources from the BlackBerry devices. • The following presents different ways to access remote databases : • N-tier applications • MDS Applications • Web Services

  38. Remote database techniques (Cont.) • In order to access data remotely, a distributed (n-tier) architecture is required. • There are several ways to implement a n-tier architecture. • In the following slide, a 4-tier architecture is described

  39. 4-Tier Architecture • A 4-tier architecture provides 4 separate layers for each of the following tiers: • Client-tier: mobile devices are considered as client-tier • Server-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.

  40. 4-Tier Architecture (Cont.) HTTP Connection Wireless Network Databases Client Tier Business Tier Data Access Tier Databases

  41. Remote Access to Data Sources • The 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 Service • It implements SOA (Service-Oriented Architecture) concepts. A client-tier application invokes the web service interfaces, in order to access the Web Service methods.

  42. Remote Access to Data Sources (Cont.) Server Application Web Service Database Client-tier Server-tier

  43. BlackBerry Gateways • BlackBerry 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.

  44. 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 gateway • BlackBerry Internet Service as an Internet gateway • Wireless Service Provider’s Internet gateway

  45. BlackBerry Enterprise Server (BES) Gateway • BES 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.

  46. Remote Data Access using BES with MDS service Source:

  47. MDS Applications • The 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 separated wireless applications from email.

  48. MDS Applications (Cont.) • It enables mobile access to applications only. • In other words, BES for MDS applications provides you a choice to deploy both wireless email and applications or wireless applications only.

  49. MDS Applications (Cont.) • BES for MDS applications offers the following features: • Security: • IT Policy: It controls the application accesses. • End-to-end authenticated connection: It encrypts all data. • Push service to provide real-time data • Centralized administration console • Deploy over-the-air (OTA)

  50. BlackBerry Internet Service (BIS) Gateway • BIS is an Internet and email service for BlackBerry devices • Allows to automatic delivery of email messages, and convenient access to Internet content. • This service uses RIM push technology allowing real-time access of email.