use of com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask in project kripton by xcesco.
the class BindDummy02DataSource 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", Bean02Table.CREATE_TABLE_SQL);
}
// log section END
database.execSQL(Bean02Table.CREATE_TABLE_SQL);
}
if (options.databaseLifecycleHandler != null) {
options.databaseLifecycleHandler.onUpdate(database, previousVersion, currentVersion, true);
}
}
use of com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask in project kripton by xcesco.
the class BindShortDataSource 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", ShortBeanTable.CREATE_TABLE_SQL);
}
// log section END
database.execSQL(ShortBeanTable.CREATE_TABLE_SQL);
}
if (options.databaseLifecycleHandler != null) {
options.databaseLifecycleHandler.onUpdate(database, previousVersion, currentVersion, true);
}
}
use of com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask in project kripton by xcesco.
the class BindBeanDataSource 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", BeanTable.CREATE_TABLE_SQL);
}
// log section END
database.execSQL(BeanTable.CREATE_TABLE_SQL);
}
if (options.databaseLifecycleHandler != null) {
options.databaseLifecycleHandler.onUpdate(database, previousVersion, currentVersion, true);
}
}
use of com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask in project kripton by xcesco.
the class SQLiteUpdateTestDatabase method findTask.
List<SQLiteUpdateTask> findTask(int previousVersion, int currentVersion) {
List<SQLiteUpdateTask> result = new ArrayList<>();
final One<Integer> ref = new One<>(null);
for (int i = previousVersion; i < currentVersion; i++) {
ref.value0 = i;
SQLiteUpdateTask t = null;
for (Pair<Integer, ? extends SQLiteUpdateTask> item : updateTasks) {
if (item.value0 - 1 == ref.value0) {
t = item.value1;
break;
}
}
if (t != null) {
result.add(t);
}
}
return result;
}
use of com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask in project kripton by xcesco.
the class TestSchemaUpdater method testUpdateWithHelper.
@Test
public void testUpdateWithHelper() throws FileNotFoundException {
final FileInputStream stream = new FileInputStream("schemas/school_schema_2.sql");
SQLiteUpdateTestDatabase.builder(1, new FileInputStream("schemas/school_schema_1.sql")).addVersionUpdateTask(2, new SQLiteUpdateTask() {
@Override
public void execute(SQLiteDatabase database, int previousVersion, int currentVersion) {
SQLiteSchemaVerifierHelper.renameAllTablesWithPrefix(database, "tmp_");
SQLiteSchemaVerifierHelper.executeSQL(database, stream);
SQLiteSchemaVerifierHelper.dropTablesWithPrefix(database, "tmp_");
}
}).build().updateAndVerify(2, new FileInputStream("schemas/school_schema_2.sql"));
log("finish");
}
Aggregations