Search in sources :

Example 41 with SQLiteUpdateTask

use of com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask in project kripton by xcesco.

the class BindDeleteBeanPersonDataSource method onUpgrade.

/**
 * onUpgrade
 */
@Override
public void onUpgrade(SQLiteDatabase database, int previousVersion, int currentVersion) {
    // log section BEGIN
    if (this.logEnabled) {
        Logger.info("Update database '%s' from version %s to version %s", this.name, previousVersion, currentVersion);
    }
    // if we have a list of update task, try to execute them
    if (options.updateTasks != null) {
        List<SQLiteUpdateTask> tasks = buildTaskList(previousVersion, currentVersion);
        for (SQLiteUpdateTask task : tasks) {
            // log section BEGIN
            if (this.logEnabled) {
                Logger.info("Begin update database from version %s to %s", previousVersion, previousVersion + 1);
            }
            // log section END
            task.execute(database, previousVersion, previousVersion + 1);
            // log section BEGIN
            if (this.logEnabled) {
                Logger.info("End update database from version %s to %s", previousVersion, previousVersion + 1);
            }
            // log section END
            previousVersion++;
        }
    } else {
        // drop all tables
        SQLiteUpdateTaskHelper.dropTablesAndIndices(database);
        // log section BEGIN
        if (this.logEnabled) {
            Logger.info("DDL: %s", PersonTable.CREATE_TABLE_SQL);
        }
        // log section END
        database.execSQL(PersonTable.CREATE_TABLE_SQL);
    }
    if (options.databaseLifecycleHandler != null) {
        options.databaseLifecycleHandler.onUpdate(database, previousVersion, currentVersion, true);
    }
}
Also used : SQLiteUpdateTask(com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask)

Example 42 with SQLiteUpdateTask

use of com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask in project kripton by xcesco.

the class BindAppDataSource method onUpgrade.

/**
 * onUpgrade
 */
@Override
public void onUpgrade(SQLiteDatabase database, int previousVersion, int currentVersion) {
    // log section BEGIN
    if (this.logEnabled) {
        Logger.info("Update database '%s' from version %s to version %s", this.name, previousVersion, currentVersion);
    }
    // if we have a list of update task, try to execute them
    if (options.updateTasks != null) {
        List<SQLiteUpdateTask> tasks = buildTaskList(previousVersion, currentVersion);
        for (SQLiteUpdateTask task : tasks) {
            // log section BEGIN
            if (this.logEnabled) {
                Logger.info("Begin update database from version %s to %s", previousVersion, previousVersion + 1);
            }
            // log section END
            task.execute(database, previousVersion, previousVersion + 1);
            // log section BEGIN
            if (this.logEnabled) {
                Logger.info("End update database from version %s to %s", previousVersion, previousVersion + 1);
            }
            // log section END
            previousVersion++;
        }
    } else {
        // drop all tables
        SQLiteUpdateTaskHelper.dropTablesAndIndices(database);
        // log section BEGIN
        if (this.logEnabled) {
            Logger.info("DDL: %s", UserTable.CREATE_TABLE_SQL);
        }
        // log section END
        database.execSQL(UserTable.CREATE_TABLE_SQL);
        // log section BEGIN
        if (this.logEnabled) {
            Logger.info("DDL: %s", BookTable.CREATE_TABLE_SQL);
        }
        // log section END
        database.execSQL(BookTable.CREATE_TABLE_SQL);
        // log section BEGIN
        if (this.logEnabled) {
            Logger.info("DDL: %s", LoanTable.CREATE_TABLE_SQL);
        }
        // log section END
        database.execSQL(LoanTable.CREATE_TABLE_SQL);
    }
    if (options.databaseLifecycleHandler != null) {
        options.databaseLifecycleHandler.onUpdate(database, previousVersion, currentVersion, true);
    }
}
Also used : SQLiteUpdateTask(com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask)

Example 43 with SQLiteUpdateTask

use of com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask in project kripton by xcesco.

the class BindCollegeStudentsDataSource method onUpgrade.

/**
 * onUpgrade
 */
@Override
public void onUpgrade(SQLiteDatabase database, int previousVersion, int currentVersion) {
    // log section BEGIN
    if (this.logEnabled) {
        Logger.info("Update database '%s' from version %s to version %s", this.name, previousVersion, currentVersion);
    }
    // if we have a list of update task, try to execute them
    if (options.updateTasks != null) {
        List<SQLiteUpdateTask> tasks = buildTaskList(previousVersion, currentVersion);
        for (SQLiteUpdateTask task : tasks) {
            // log section BEGIN
            if (this.logEnabled) {
                Logger.info("Begin update database from version %s to %s", previousVersion, previousVersion + 1);
            }
            // log section END
            task.execute(database, previousVersion, previousVersion + 1);
            // log section BEGIN
            if (this.logEnabled) {
                Logger.info("End update database from version %s to %s", previousVersion, previousVersion + 1);
            }
            // log section END
            previousVersion++;
        }
    } else {
        // drop all tables
        SQLiteUpdateTaskHelper.dropTablesAndIndices(database);
        // log section BEGIN
        if (this.logEnabled) {
            Logger.info("DDL: %s", CollegeStudentTable.CREATE_TABLE_SQL);
        }
        // log section END
        database.execSQL(CollegeStudentTable.CREATE_TABLE_SQL);
    }
    if (options.databaseLifecycleHandler != null) {
        options.databaseLifecycleHandler.onUpdate(database, previousVersion, currentVersion, true);
    }
}
Also used : SQLiteUpdateTask(com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask)

Example 44 with SQLiteUpdateTask

use of com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask in project kripton by xcesco.

the class BindCollegeStudentsDataSource method onUpgrade.

/**
 * onUpgrade
 */
@Override
public void onUpgrade(SQLiteDatabase database, int previousVersion, int currentVersion) {
    // log section BEGIN
    if (this.logEnabled) {
        Logger.info("Update database '%s' from version %s to version %s", this.name, previousVersion, currentVersion);
    }
    // if we have a list of update task, try to execute them
    if (options.updateTasks != null) {
        List<SQLiteUpdateTask> tasks = buildTaskList(previousVersion, currentVersion);
        for (SQLiteUpdateTask task : tasks) {
            // log section BEGIN
            if (this.logEnabled) {
                Logger.info("Begin update database from version %s to %s", previousVersion, previousVersion + 1);
            }
            // log section END
            task.execute(database, previousVersion, previousVersion + 1);
            // log section BEGIN
            if (this.logEnabled) {
                Logger.info("End update database from version %s to %s", previousVersion, previousVersion + 1);
            }
            // log section END
            previousVersion++;
        }
    } else {
        // drop all tables
        SQLiteUpdateTaskHelper.dropTablesAndIndices(database);
        // log section BEGIN
        if (this.logEnabled) {
            Logger.info("DDL: %s", CollegeStudentTable.CREATE_TABLE_SQL);
        }
        // log section END
        database.execSQL(CollegeStudentTable.CREATE_TABLE_SQL);
    }
    if (options.databaseLifecycleHandler != null) {
        options.databaseLifecycleHandler.onUpdate(database, previousVersion, currentVersion, true);
    }
}
Also used : SQLiteUpdateTask(com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask)

Example 45 with SQLiteUpdateTask

use of com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask in project kripton by xcesco.

the class BindPersonCirtyDataSource method onUpgrade.

/**
 * onUpgrade
 */
@Override
public void onUpgrade(SQLiteDatabase database, int previousVersion, int currentVersion) {
    // log section BEGIN
    if (this.logEnabled) {
        Logger.info("Update database '%s' from version %s to version %s", this.name, previousVersion, currentVersion);
    }
    // if we have a list of update task, try to execute them
    if (options.updateTasks != null) {
        List<SQLiteUpdateTask> tasks = buildTaskList(previousVersion, currentVersion);
        for (SQLiteUpdateTask task : tasks) {
            // log section BEGIN
            if (this.logEnabled) {
                Logger.info("Begin update database from version %s to %s", previousVersion, previousVersion + 1);
            }
            // log section END
            task.execute(database, previousVersion, previousVersion + 1);
            // log section BEGIN
            if (this.logEnabled) {
                Logger.info("End update database from version %s to %s", previousVersion, previousVersion + 1);
            }
            // log section END
            previousVersion++;
        }
    } else {
        // drop all tables
        SQLiteUpdateTaskHelper.dropTablesAndIndices(database);
        // log section BEGIN
        if (this.logEnabled) {
            Logger.info("DDL: %s", CityTable.CREATE_TABLE_SQL);
        }
        // log section END
        database.execSQL(CityTable.CREATE_TABLE_SQL);
        // log section BEGIN
        if (this.logEnabled) {
            Logger.info("DDL: %s", PersonTable.CREATE_TABLE_SQL);
        }
        // log section END
        database.execSQL(PersonTable.CREATE_TABLE_SQL);
        // log section BEGIN
        if (this.logEnabled) {
            Logger.info("DDL: %s", PersonCityTable.CREATE_TABLE_SQL);
        }
        // log section END
        database.execSQL(PersonCityTable.CREATE_TABLE_SQL);
    }
    if (options.databaseLifecycleHandler != null) {
        options.databaseLifecycleHandler.onUpdate(database, previousVersion, currentVersion, true);
    }
}
Also used : SQLiteUpdateTask(com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask)

Aggregations

SQLiteUpdateTask (com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask)123 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 BaseAndroidTest (base.BaseAndroidTest)3 Test (org.junit.Test)3 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)1 DataSourceOptions (com.abubusoft.kripton.android.sqlite.DataSourceOptions)1 DatabaseLifecycleHandler (com.abubusoft.kripton.android.sqlite.DatabaseLifecycleHandler)1 One (com.abubusoft.kripton.common.One)1 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)1 List (java.util.List)1