Interface CreateDatabaseCallback

  • All Implemented Interfaces:

    
    public interface CreateDatabaseCallback
    
                        

    This interface is used to provide callback methods to create or update database objects when instantiating Secure Database Store via SecureDatabaseStore.

    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.
                }
            });
    
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract void onCreate(@NonNull() SecureDatabaseStore store) This method is invoked after a database has been created but before any table is created.
      abstract void onUpgrade(@NonNull() 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • onCreate

         abstract void onCreate(@NonNull() SecureDatabaseStore store)

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

        Parameters:
        store - the SecureDatabaseStore instance
      • onUpgrade

         abstract void onUpgrade(@NonNull() 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