Company

Products

Services

Partners

Media

 

 

 

Home

Empress Markets

News & Events


Presentations

Press Releases

Product Profile

Success Stories

Technical News


White Papers

Join Mailing List

For More Info

           

    Empress Technical News – May 2012

    Empress SDK for Android
    Now with Empress SQLite Interface

    Introduction
    The latest Empress SDK for Android offers Android application developers new ways to develop advanced database applications requiring robustness, reliability, security, high performance, large data sets, multi-tasking control and much more.

    Since Android comes with SQLite support, most Android application developers use SQLite for their database data driven applications. In many cases, application developers find that SQLite based applications will outgrow SQLite capabilities and these developers will find themselves scratching their heads and looking for an alternate solution.

    Empress SDK for Android with Empress SQLite Interface is a nice alternate solution.

    Empress for Android supports the following APIs:

    1.      Empress JDBC API (JDBC)
    2.      Empress Android SQLite Compatibility API (sqlite API)
    3.      Empress Database Administration API (dbadmin API)
    4.      Empress Set-Up API (setup API)

    Empress SDK for Android supports the database access standard API, JDBC. The JDBC API can help developers create new database applications or migrate existing database applications to Android. The JDBC API can access databases on the local Android device (Figure 1).
     
    Empress Android JDBC API
    Figure 1: Empress Android JDBC API

    In addition, Empress JDBC Android application developers can create applications where data is stored outside of the local device such as on a local LAN, an Internet location or even in a Cloud (Figure 2).

    It is even possible to mix and match local, LAN, Internet and Cloud database storage from the same Android device.
     
      Different Ways JDBC API
    Figure 2: Different Ways to Use Empress Android JDBC Applications

    In addition to JDBC, SDK for Android supports the Empress Sqlite database interface (see Figure 3) as defined in the Android package android.database.sqlite. Android application developers can utilize the Empress Sqlite API to convert an existing Android sqlite application or create a new application.

    This Empress Sqlite API helps developers migrate existing database applications to Android or create new ones quickly and with low conversion effort.

      Empress Android SQLite API
    Figure 3: Empress Android SQLite Compatibility API (sqlite API)

    Empress SDK for Android also supports the usage of callable administration functions (e.g. creating and removing databases, exporting and importing data, checking and repairing databases) and setting Empress System variables in the Android environment.


    Empress SQLite versus SQLite on Android Devices
    Empress SDK for Android offers many advantages compared to SQLite on Android devices. To mention a few:

    Robustness and Reliability

    Empress database engine has a long history of over 30 years of usage in embedded applications. Bringing the same database engine to Android devices allows developers to experience the same kind of reliability and robustness that many production systems have experienced for decades.
    Additional Features
    With Empress, database developers are offered a full-fledged database development environment comparable to enterprise environments. Many features, such as encryption, allow application developers to enhance their Android applications.
    Large data set solution
    Empress allows application developers to build applications that can go way beyond just contacts and address book data
    Multi-access solution
    Empress APIs for Android supports concurrent access that allows applications to run multiple tasks at the same time. 
    Database degradation over time
    Since SQLite has a single file to contain all the data, there is a greater likelihood of the database file being fragmented compared to Empress where the database data is spread over multiple files.
    Performance
    Performance of Android devices (phones, tablets, special devices, …) depends on factors such as: the location of the data storage, memory, CPU, Android version, etc. Benchmarks have shown that Empress APIs beat SQLite on Android devices with larger data sets.


    Develop Empress Applications Using sqlite API

    Since Android defines classes and methods in its package android.database.sqlite.

    The following classes are supported:

    Classes
    SQLiteClosable
    SQLiteCursor
    SQLiteDatabase
    SQLiteOpenHelper
    SQLiteProgram
    SQLiteQuery
    SQLiteQueryBuilder
    SQLiteStatement

    android.database.sqlite classes are referenced in:
    http://developer.android.com/reference/android/database/sqlite/package-summary.html


    Converting SQLite Applications to Empress
    When converting SQLite Android application to work with Empress SQLite, here are the major areas that application developers need to be aware of:


    Import Lines

    import database.sqlite.*

    Import lines related to SQLite should be changed in the following way:

    import com.empress.database.sqlite.*

    Set up Empress Temporary Directory on the Android Target
    At runtime, the Empress Database engine needs a temporary directory to store temporary files when necessary. This task is optional if your default temporary directory is writeable. On Android devices, the typical default is: /sdcard which is usually writeable, so you don’t need to do anything.

    Set License Key
    In order to enable Empress applications to be used in Android environment, a valid license key must be set in the application before using Empress methods. An Empress license key will be provided to you by Empress Software Inc. The key could be an evaluation key that expires after a certain time or a runtime key that does not expire for production purpose.

    For example:

    lic_str = " 18a94c3c3a2d4a9f3c0b0a225bae78398561c30476be1ad3"
    if (SetUp.getLicenceKey() == null)
                SetUp.setLicenceKey (lic_str)




    Example
    The Empress sample project EmpressEmpSQLiteSample included in the Empress SDK for Android zip file has all the Empress components pre-configured so that users can try it and run it in their Android emulator or a real device. 4 shows the EmpressEmpSQLiteSample directory structure:

      EMPSQLiteSample Directory
    Figure 4: EmpressEmpSQLiteSample Directory Structure



    To demonstrate the minimal need for modification when converting a SQLite application to Empress, an example is given in the following text (part of the source code included in the sample project EmpressEmpSQLiteSample).

    package com.empress.EmpressSQLiteSample


    import com.empress.database.sqlite.SQLiteDatabase
    import com.empress.util.EmpressException

    import com.empress.database.sqlite.SQLiteStatement
    import com.empress.util.SetUp

    import android.app.Activity
    import android.database.Cursor
    import android.graphics.Color
    import android.os.Bundle
    import android.view.View
    import android.widget.ScrollView
    import android.widget.TextView

    public class EmpressSQLiteSample extends Activity
    {

          TextView tv = null
          ScrollView sv = null
          String output = " "

          String dbLocation = " "
         

          public void onCreate(Bundle savedInstanceState)
          {
                super.onCreate(savedInstanceState)

                sv = new ScrollView(this)
                sv.setBackgroundColor(Color.WHITE)

                tv = new TextView(this)
                tv.setTextColor(Color.BLACK)

                sv.addView(tv)
                setContentView(sv)
                       
                //dbLocation = " /sdcard"
                dbLocation = this.getApplicationInfo().dataDir
               
               
                runSampleInThread()

          }

          private void runSampleInThread()
          {
                Thread runner = new Thread()
                {
                      public void run()
                      {
                            DoEmpSQLite()
                      }
         
                }

                runner.start()
          }

          private void DoEmpSQLite()
          {
                Cursor             rs
                SQLiteDatabase       db1
                SQLiteStatement      stmt
                EmpressOpenHelp DbHelp
                String            sql
                String            first_name
                String            last_name
                String            ColumnNames[]
                String            DBString
                long            manager_id
                long            k

                rs = null
                DbHelp = null
                db1 = null
                stmt = null

                String appdatadir = this.getApplicationInfo().dataDir
                String tmpdir = System.getProperty(" java.io.tmpdir" )
                //By default java.io.tmpdir is set to " /sdcard" . 
                //If your /sdcard is not writable, you need to reset it
                //to a writable location. In this example, the application
                          //data directory is chosen.
                if (!dbLocation.equals (tmpdir))
                {
                      postText (" DoEmpSQLite:Resetting javio.io.tmpdir '"
                            + tmpdir + " ' to '" + appdatadir + " '" )
                      System.setProperty(" java.io.tmpdir" , appdatadir)
                }

                // We need to set the license
                try
                {
                      String      lic_str
                      //Note:
                      //This key has expired as of
                      //Wednesday April 11 17:03:23 EDT 2012
                      lic_str =
                                      " 18a94c3c3a2e5a9f3c0b0a225bae78398561b20476be1ad3"
                      if (SetUp.getLicenceKey() == null)
                            SetUp.setLicenceKey (lic_str)
                      postText(" DoEmpSQLite:setLicenceKey success" )
                      postText(" Expiry Date:" +
                            SetUp.getLicenceExpiryDateString())
                }
                catch (EmpressException e)
                {
                      postText(" DoEmpSQLite:setLicenceKey failure e:" +
                            e.toString())
                      return
                }

                DBString = dbLocation + " /emp_db"
                postText (" DoEmpSQLite:Working with database:" + DBString)

                try
                {
                      DbHelp = new EmpressOpenHelp (this,
                            DBString, null, 1)
                      db1 = DbHelp.getWritableDatabase ()
                      // Insert 3 records into the table employee
                      sql = " INSERT INTO employee " +
                            " (employee_id, first_name, " +
                            " last_name, hire_date, manager_id) VALUES (" +
                            " NULL, ?, ?, now(), ?)"
                      stmt = db1.compileStatement (sql)
                      first_name = " Dan"
                      for (manager_id = 0 manager_id < 3 manager_id++)
                      {
                            last_name = " Smitters_0" + manager_id
                            stmt.bindString (1, first_name)
                            stmt.bindString (2, last_name)
                            stmt.bindLong (3, manager_id)
                            k = stmt.executeInsert ()
                            if (k != 1)
                            {
                                  postText(" Unable to insert record " +
                                        manager_id)
                                  break
                            }
                      }
                      stmt.close ()
                      stmt = null

                      // Retrieve the records back
                      rs = db1.rawQuery (" SELECT * FROM employee" , null)
                      // Get the Column Names
                      ColumnNames= rs.getColumnNames ()
                      while (rs.moveToNext ())
                      {
                            postText (" ================" )
                            for (int i = 0 i < ColumnNames.length i++)
                            {
                                  postText (ColumnNames[i] + " :" +
                                        rs.getString (i))
                            }
                            postText (" ================\n" )
                      }
                      rs.close ()
                      rs = null


                      db1.close ()
                      db1 = null

                      DbHelp.close ()
                      DbHelp = null

                      postText(" \nExample is done" )
                }
                catch (Exception e)
                {
                      if (stmt != null)
                            stmt.close ()
                      if (rs != null)
                            rs.close ()
                      if (db1 != null)
                            db1.close()
                      if (DbHelp != null)
                            DbHelp.close ()
                      postText (" Exception caught e:" + e)
                      postText (" " )
                }
                     
          }

          private void postText(String t)
          {
                final String txt = t
                sv.post(new Runnable() {
                     
                      public void run() {
                            tv.append(txt + " \n" )
                            sv.fullScroll(View.FOCUS_DOWN)

                      }
                })
          }
         
    }


    Instead of Summary
    Empress SDK for Android with Empress SQLite Interface addresses the growing need for more secure, complex, reliable and efficient database data driven Android applications that fall short when using the Android SQLite solution. In addition to the standard JDBC API, Empress SDK for Android supports Empress Android SQLite Compatibility API which helps developers migrate existing database applications to Android quickly and with the least effort. Furthermore, Empress also provides robustness, reliability, additional features, large data set handling, multi-access solutions, increased performance and much more.



    Empress Software Inc.

                       
                             
                         

Company
Information
GSA Contracts
Careers
Privacy Policy 
Contact US

Products
Empress RDBMS
Empress Servers
Empress API
Free Trial 
Empress iPad Apps
 

Services
Consulting
Mobile Apps Development
Technical Support

Training Courses
Empress Extreme  

Partners
Distributors
Business Alliances
Partner Programs  
GSA Program
Distributors Program

Media 
Empress Markets
News and Events
Press releases
Technical News
Success Stories

        USA: 301-220-1919                 Canada & International:       905-513-8888         
Copyright © 2014           Empress Software Inc.           info@empress.com           Join Empress Mailing List