Search in sources :

Example 1 with DatabaseLifecycleHandler

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

the class TestKripton234Runtime method testRunSqlite2.

@Test
public void testRunSqlite2() throws IOException, InstantiationException, IllegalAccessException {
    DataSourceOptions.Builder optionsBuilder = DataSourceOptions.builder();
    optionsBuilder.inMemory(false);
    optionsBuilder.databaseLifecycleHandler(new DatabaseLifecycleHandler() {

        @Override
        public void onUpdate(SQLiteDatabase database, int oldVersion, int newVersion, boolean upgrade) {
            log("databaseLifecycleHandler - onUpdate");
        }

        @Override
        public void onCreate(SQLiteDatabase database) {
            log("databaseLifecycleHandler - onCreate " + database.getVersion());
        }

        @Override
        public void onConfigure(SQLiteDatabase database) {
            log("databaseLifecycleHandler - onConfigure");
        }
    });
    optionsBuilder.addUpdateTask(1, new SQLiteUpdateTask() {

        @Override
        public void execute(SQLiteDatabase database, int previousVersion, int currentVersion) {
            log("aaaaaaaaa");
        }
    });
    BindAppWithConfigDataSource ds = BindAppWithConfigDataSource.build(optionsBuilder.build());
}
Also used : DatabaseLifecycleHandler(com.abubusoft.kripton.android.sqlite.DatabaseLifecycleHandler) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) DataSourceOptions(com.abubusoft.kripton.android.sqlite.DataSourceOptions) SQLiteUpdateTask(com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 2 with DatabaseLifecycleHandler

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

the class TestSchemaRuntime method testRun.

@Test
public void testRun() {
    BindSchoolDataSource.build(DataSourceOptions.builder().databaseLifecycleHandler(new DatabaseLifecycleHandler() {

        @Override
        public void onUpdate(SQLiteDatabase db, int oldVersion, int newVersion, boolean upgrade) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onCreate(SQLiteDatabase database) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onConfigure(SQLiteDatabase database) {
        // TODO Auto-generated method stub
        }
    }).build());
    try (BindSchoolDataSource dataSource = BindSchoolDataSource.open();
        DaoProfessorImpl dao = dataSource.getDaoProfessor()) {
        // dataSource.execute(transaction);
        for (int i = 0; i < 10; i++) {
            Professor professor = new Professor();
            professor.name = String.format("professor%03d", i);
            professor.surname = "surname" + i;
            professor.birthDate = new Date();
            dao.insert(professor);
        }
    }
    try (BindSchoolDataSource dataSource = BindSchoolDataSource.open();
        DaoStudentImpl dao = dataSource.getDaoStudent()) {
        // dataSource.execute(transaction);
        for (int i = 0; i < 100; i++) {
            Student student = new Student();
            student.name = String.format("professor%03d", i);
            student.location = String.format("location%03d", i);
            dao.insert(student);
        }
    }
}
Also used : DaoProfessorImpl(sqlite.feature.schema.version2.DaoProfessorImpl) Professor(sqlite.feature.schema.version2.Professor) DatabaseLifecycleHandler(com.abubusoft.kripton.android.sqlite.DatabaseLifecycleHandler) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) BindSchoolDataSource(sqlite.feature.schema.version2.BindSchoolDataSource) DaoStudentImpl(sqlite.feature.schema.version2.DaoStudentImpl) Student(sqlite.feature.schema.version2.Student) Date(java.util.Date) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 BaseAndroidTest (base.BaseAndroidTest)2 DatabaseLifecycleHandler (com.abubusoft.kripton.android.sqlite.DatabaseLifecycleHandler)2 Test (org.junit.Test)2 DataSourceOptions (com.abubusoft.kripton.android.sqlite.DataSourceOptions)1 SQLiteUpdateTask (com.abubusoft.kripton.android.sqlite.SQLiteUpdateTask)1 Date (java.util.Date)1 BindSchoolDataSource (sqlite.feature.schema.version2.BindSchoolDataSource)1 DaoProfessorImpl (sqlite.feature.schema.version2.DaoProfessorImpl)1 DaoStudentImpl (sqlite.feature.schema.version2.DaoStudentImpl)1 Professor (sqlite.feature.schema.version2.Professor)1 Student (sqlite.feature.schema.version2.Student)1