Docstoc

Databases for Mobile Devices

Document Sample
Databases for Mobile Devices Powered By Docstoc
					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

                  http://cmer.cis.uoguelph.ca   2
         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.


                        http://cmer.cis.uoguelph.ca                3
      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.




                    http://cmer.cis.uoguelph.ca            4
        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.
                  http://cmer.cis.uoguelph.ca   5
        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



                    http://cmer.cis.uoguelph.ca     6
        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.

                    http://cmer.cis.uoguelph.ca       7
      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




                   http://cmer.cis.uoguelph.ca          8
        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.


                   http://cmer.cis.uoguelph.ca     9
        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


                    http://cmer.cis.uoguelph.ca    10
        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.


                   http://cmer.cis.uoguelph.ca   11
        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.


                  http://cmer.cis.uoguelph.ca   12
         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.




                   http://cmer.cis.uoguelph.ca       13
           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) {
      this.name = name;
  }
  public String getName(){
      return this.name;
  }
                          http://cmer.cis.uoguelph.ca   14
        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.



                  http://cmer.cis.uoguelph.ca   15
          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.


                     http://cmer.cis.uoguelph.ca    16
        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.


                  http://cmer.cis.uoguelph.ca   17
        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.




                   http://cmer.cis.uoguelph.ca      18
           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();
 }
                         http://cmer.cis.uoguelph.ca       19
          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, javax.microedition.io.file, is
  used.
• The package specification is in JSR 75, File
  Connection API.



                    http://cmer.cis.uoguelph.ca   20
         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.

                       http://cmer.cis.uoguelph.ca              21
         Storing Data on MicroSD
         (Cont.)
• The FileConnection API provides:
  – Interfaces:
     • FileConnection
     • FileSystemListener
  – Classes:
     • FileSystemRegistry
     • ConnectionClosedException
     • IllegalModeException




                      http://cmer.cis.uoguelph.ca   22
          Storing Data on MicroSD
          (Cont.)
• File Connection API provides access to files or
  directories resided on either
  – MicroSD card
     • FileConnection fc = (FileConnection)
            Connector.open(“file:///SDCard”);
  - Or –
  – File systems on BlackBerry devices
     • FileConnection fc = (FileConnection)
            Connector.open(“file:///Store”);




                         http://cmer.cis.uoguelph.ca   23
               Example- FileConnection
               API
 public void readFile(String filename) throws IOException         {
   //Open a connection to the file
   FileConnection fc = (FileConnection)Connector.open(
          "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 = is.read(data)))              {
                    System.out.println(“The content is ”+
                           new String(data, 0, length);
          }
   }
                                  http://cmer.cis.uoguelph.ca         24
}
         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.
•




                   http://cmer.cis.uoguelph.ca       25
        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.
                  http://cmer.cis.uoguelph.ca    26
        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.




                   http://cmer.cis.uoguelph.ca   27
        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.


                    http://cmer.cis.uoguelph.ca      28
         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




                        http://cmer.cis.uoguelph.ca   29
         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




                       http://cmer.cis.uoguelph.ca           30
          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.
                      http://cmer.cis.uoguelph.ca       31
          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)
{
}

                         http://cmer.cis.uoguelph.ca          32
          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.



                     http://cmer.cis.uoguelph.ca   33
        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

                   http://cmer.cis.uoguelph.ca   34
         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.



                       http://cmer.cis.uoguelph.ca            35
       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



                     http://cmer.cis.uoguelph.ca                36
         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




                      http://cmer.cis.uoguelph.ca   37
         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


                    http://cmer.cis.uoguelph.ca      38
        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.
                     http://cmer.cis.uoguelph.ca      39
                     4-Tier Architecture
                     (Cont.)

                            HTTP
          Wireless          Connection
          Network




                                                                       Databases

Client Tier           Business Tier                 Data Access Tier   Databases



                                      http://cmer.cis.uoguelph.ca                  40
         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.




                        http://cmer.cis.uoguelph.ca               41
              Remote Access to Data
              Sources (Cont.)

                    Server
                    Application




                     Web Service




Client-tier           Server-tier                 Database
                    http://cmer.cis.uoguelph.ca              42
        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.




                 http://cmer.cis.uoguelph.ca   43
        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



                    http://cmer.cis.uoguelph.ca      44
        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.




                  http://cmer.cis.uoguelph.ca   45
Remote Data Access using
BES with MDS service




  Source:http://na.blackberry.com/eng/services/mobile.jsp




                   http://cmer.cis.uoguelph.ca              46
        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.


                   http://cmer.cis.uoguelph.ca   47
       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.




                   http://cmer.cis.uoguelph.ca   48
          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)




                         http://cmer.cis.uoguelph.ca                49
        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.



                 http://cmer.cis.uoguelph.ca    50

				
DOCUMENT INFO