@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { List<SQLiteUpdateTask> task = findTask(oldVersion, newVersion); for (SQLiteUpdateTask item : task) { item.execute(db, oldVersion, oldVersion + 1); oldVersion++; } }
/** * Allow to update database version to <i>version</i>. This method allows to specify the destination version schema and compare it with schema resulting by version update * applied. * * @param version * the version * @param context * the context * @param schemaDefinitionRawResourceId * the schema definition raw resource id * @return the SQ lite update test database */ public SQLiteTestDatabase updateAndVerify(int version, final Context context, final int schemaDefinitionRawResourceId) { updateAndVerify(version, context.getResources().openRawResource(schemaDefinitionRawResourceId)); return this; }
/** * build and create test database. * * @return the SQ lite update test database */ public SQLiteTestDatabase build() { Collections.sort(updateTasks, new Comparator<Pair<Integer, ? extends SQLiteUpdateTask>>() { @Override public int compare(Pair<Integer, ? extends SQLiteUpdateTask> entry0, Pair<Integer, ? extends SQLiteUpdateTask> entry1) { return entry0.value0 - entry1.value0; } }); SQLiteTestDatabase helper = new SQLiteTestDatabase(KriptonLibrary.getContext(), null, version, null, initialSchemaInputStream, initialSchemaResourceRawId, populator, updateTasks); return helper.create(); }