public interface

CreateDatabaseCallback

com.sap.cloud.mobile.foundation.securestore.CreateDatabaseCallback

Class Overview

This interface is used to provide callback methods to create or update database objects when instantiating Secure Database Store via SecureDatabaseStore(Context, String, int, CreateDatabaseCallback).

1. Initial database creation-- use database version 1, and create database objects in
   onCreate method.

   For example,

static final int DATABASE_VERSION = 1;
    ...
    SecureDatabaseStore store = new SecureDatabaseStore(androidContext, storeName,
        DATABASE_VERSION,
        new CreateDatabaseCallback(){
            public void onCreate(SecureDatabaseStore store){
                // Executes the create table SQL statement when the database is created the first
                // time.
                store.executeUpdate(<create table SQL statement(s)>);
                ...
            }

            public void onUpdate(SecureDatabaseStore store, int oldVersion, int newVersion) {
                // No need to to anything if newVersion == oldVersion.
                // For example, when DATABASE_VERSION == 1, this method will not be called.
                    ...
            }
        });


2. When database table(s) changed-- use a higher database version for each such change, and
   implements onUpdate to alter the table(s) or migrate existing table data to
   the new table.

   For example, when a SecureDatabaseStore has evolved to version 3,

static final int DATABASE_VERSION = 3;
    ...
    SecureDatabaseStore store = new SecureDatabaseStore(androidContext, storeName,
        DATABASE_VERSION,
        new CreateDatabaseCallback(){
            public void onCreate(SecureDatabaseStore store){
                // Executes the create table SQL statement when the database is created the first
                // time.
                store.executeUpdate(<create table SQL statement(s) for the version 3 table(s)>);
                ...
            }

            public void onUpdate(SecureDatabaseStore store, int oldVersion, int newVersion) {
                // Modify the existing table or migrate the original table data based on the
                // differences across each version.
                if (oldVersion < 2) {
                    ...
                }

                if (oldVersion < 3) {
                    ...
                }
                ...
                // Now the app will iterate over the update statements and run any that are needed.
                // No matter what previous version was and regardless of what more recent version
                // they upgrade to, the app will run the proper statements to take the app from the
                // older schema to the properly upgraded one.
            }
        });

Summary

Public Methods
abstract void onCreate(SecureDatabaseStore store)
This method is invoked after a database has been created but before any table is created.
abstract void onUpgrade(SecureDatabaseStore store, int oldVersion, int newVersion)
This method is invoked when a new database version is introduced and the new version is different from the version of the existing database on device.

Public Methods

public abstract void onCreate (SecureDatabaseStore store)

This method is invoked after a database has been created but before any table is created. Usually, the user should call executeUpdate(String) to create one or more tables the very first time the database is used.

Parameters
store the SecureDatabaseStore instance

public abstract void onUpgrade (SecureDatabaseStore store, int oldVersion, int newVersion)

This method is invoked when a new database version is introduced and the new version is different from the version of the existing database on device.

Typically, the application can alter the table or migrate the existing table contents to the new table inside this method to ensure no data loss.

Parameters
store the SecureDatabaseStore instance
oldVersion the version of the existing database
newVersion the version of the changed database