Search in sources :

Example 1 with TransactionResult

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

the class Test209Model2Runtime method testRunSqlite1.

@Test
public void testRunSqlite1() {
    BindApp2DataSource ds = BindApp2DataSource.instance();
    ds.execute(new Transaction() {

        @Override
        public TransactionResult onExecute(BindApp2DaoFactory daoFactory) {
            Device device = new Device();
            device.name = "device-test";
            daoFactory.getDeviceDao().insert(device);
            User user = new User();
            user.userName = "user-test";
            daoFactory.getUserDao().insert(user);
            UserDevice userDevice = new UserDevice();
            userDevice.deviceId = device.id;
            userDevice.userId = user.id;
            daoFactory.getUserDeviceDao().insert(userDevice);
            List<Device> devices = daoFactory.getDeviceDao().getUserDevices(user.id);
            Assert.assertTrue(devices.size() == 1);
            return TransactionResult.ROLLBACK;
        }
    });
}
Also used : BindApp2DaoFactory(sqlite.kripton209.model2.BindApp2DaoFactory) TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) User(sqlite.kripton209.model2.User) Transaction(sqlite.kripton209.model2.BindApp2DataSource.Transaction) UserDevice(sqlite.kripton209.model2.UserDevice) Device(sqlite.kripton209.model2.Device) BindApp2DataSource(sqlite.kripton209.model2.BindApp2DataSource) List(java.util.List) UserDevice(sqlite.kripton209.model2.UserDevice) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 2 with TransactionResult

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

the class TestSpeedRuntime method testInsertBatch.

@Test
public void testInsertBatch() {
    final int ITEM_COUNTER = 10000;
    final One<Long> start = new One<>();
    final One<Long> end = new One<>();
    final One<Integer> index = new One<>();
    final int COUNTER = 100;
    final BindPersonDataSource ds = BindPersonDataSource.instance();
    ds.openWritableDatabase();
    final List<Person> list = new ArrayList<Person>();
    for (int i = 0; i < ITEM_COUNTER; i++) {
        Person bean = new Person();
        bean.name = "name" + index.value0;
        bean.surname = "surname" + index.value0;
        list.add(bean);
    }
    start.value0 = System.currentTimeMillis();
    for (int i = 0; i < COUNTER; i++) {
        index.value0 = i;
        ds.execute(new Transaction() {

            @Override
            public TransactionResult onExecute(BindPersonDaoFactory daoFactory) {
                PersonDaoImpl dao = daoFactory.getPersonDao();
                for (int i = 0; i < list.size(); i++) {
                    dao.insert(list.get(i));
                }
                return TransactionResult.COMMIT;
            }
        });
    }
    end.value0 = System.currentTimeMillis();
    ds.close();
    // 3100
    System.out.println("Average time to insert " + ITEM_COUNTER + " items: " + ((end.value0 - start.value0) * 1.0 / COUNTER) + " ms");
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) One(com.abubusoft.kripton.common.One) BindPersonDaoFactory(sqlite.feature.speed.persistence.BindPersonDaoFactory) ArrayList(java.util.ArrayList) PersonDaoImpl(sqlite.feature.speed.persistence.PersonDaoImpl) Transaction(sqlite.feature.speed.persistence.BindPersonDataSource.Transaction) BindPersonDataSource(sqlite.feature.speed.persistence.BindPersonDataSource) Person(sqlite.feature.speed.model.Person) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 3 with TransactionResult

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

the class TestSpeedRuntime method testTransaction.

@Test
public void testTransaction() {
    final One<Long> start = new One<>();
    final One<Long> end = new One<>();
    final One<Integer> index = new One<>();
    final int COUNTER = 2000;
    final BindPersonDataSource ds = BindPersonDataSource.instance();
    ds.openWritableDatabase();
    start.value0 = System.currentTimeMillis();
    for (int i = 0; i < COUNTER; i++) {
        index.value0 = i;
        ds.execute(new Transaction() {

            @Override
            public TransactionResult onExecute(BindPersonDaoFactory daoFactory) {
                PersonDaoImpl dao = daoFactory.getPersonDao();
                Person bean = new Person();
                bean.name = "name" + index.value0;
                bean.surname = "surname" + index.value0;
                // Object bean = new
                dao.insert(bean);
                return TransactionResult.COMMIT;
            }
        });
    }
    end.value0 = System.currentTimeMillis();
    ds.close();
    // 3100
    System.out.println("Esecuzione terminata in " + (end.value0 - start.value0) + " ms");
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) One(com.abubusoft.kripton.common.One) BindPersonDaoFactory(sqlite.feature.speed.persistence.BindPersonDaoFactory) PersonDaoImpl(sqlite.feature.speed.persistence.PersonDaoImpl) Transaction(sqlite.feature.speed.persistence.BindPersonDataSource.Transaction) BindPersonDataSource(sqlite.feature.speed.persistence.BindPersonDataSource) Person(sqlite.feature.speed.model.Person) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 4 with TransactionResult

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

the class TestKripton180BeanInsertSelectRuntime method testRun.

@Test
public void testRun() {
    final Employee bean = new Employee();
    bean.birthDate = new java.sql.Date((new java.util.Date()).getTime());
    bean.fieldBoolean = "true";
    bean.fieldByte = "42";
    bean.fieldByteArray = "42";
    bean.fieldCharacter = "a";
    bean.fieldDouble = "120";
    bean.fieldFloat = "120";
    bean.fieldInteger = "11";
    bean.fieldLong = "13";
    bean.fieldShort = "2";
    bean.fieldString = "a";
    bean.hireDate = new java.sql.Date((new java.util.Date()).getTime());
    BindKripton180BeanInsertSelectDataSource dataSource = BindKripton180BeanInsertSelectDataSource.instance();
    dataSource.execute(new BindKripton180BeanInsertSelectDataSource.Transaction() {

        @Override
        public TransactionResult onExecute(BindKripton180BeanInsertSelectDaoFactory daoFactory) {
            EmployeeBeanInsertSelectDaoImpl dao = daoFactory.getEmployeeBeanInsertSelectDao();
            dao.insertJQL(bean);
            Assert.assertTrue(bean.id > 0);
            return TransactionResult.ROLLBACK;
        }
    });
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) EmployeeBeanInsertSelectDaoImpl(sqlite.feature.typeadapter.kripton180.bean.insertselect.EmployeeBeanInsertSelectDaoImpl) BindKripton180BeanInsertSelectDataSource(sqlite.feature.typeadapter.kripton180.bean.insertselect.BindKripton180BeanInsertSelectDataSource) BindKripton180BeanInsertSelectDaoFactory(sqlite.feature.typeadapter.kripton180.bean.insertselect.BindKripton180BeanInsertSelectDaoFactory) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 5 with TransactionResult

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

the class Test58Runtime method testRunSqlite1.

@Test
public void testRunSqlite1() {
    BindLongDataSource dataSource = BindLongDataSource.instance();
    dataSource.execute(new Transaction() {

        @Override
        public TransactionResult onExecute(BindLongDaoFactory daoFactory) {
            LongDaoImpl dao = daoFactory.getLongDao();
            ArrayList<Long> value = new ArrayList<Long>();
            value.add(45L);
            LongBean bean = new LongBean();
            bean.value = value;
            dao.insert(bean);
            // retrieve same value
            List<LongBean> result = dao.selectList(value);
            assertTrue(result.size() == 1);
            return TransactionResult.COMMIT;
        }
    });
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) Transaction(sqlite.kripton58.list.BindLongDataSource.Transaction) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Aggregations

TransactionResult (com.abubusoft.kripton.android.sqlite.TransactionResult)28 BaseAndroidTest (base.BaseAndroidTest)27 Test (org.junit.Test)27 List (java.util.List)13 Transaction (sqlite.feature.foreignKey.BindDummyDataSource.Transaction)4 One (com.abubusoft.kripton.common.One)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Country (sqlite.feature.rx.model.Country)3 BindXenoDaoFactory (sqlite.feature.rx.persistence.BindXenoDaoFactory)3 BindXenoDataSource (sqlite.feature.rx.persistence.BindXenoDataSource)3 CountryDaoImpl (sqlite.feature.rx.persistence.CountryDaoImpl)3 Person (sqlite.feature.speed.model.Person)3 BindPersonDaoFactory (sqlite.feature.speed.persistence.BindPersonDaoFactory)3 BindPersonDataSource (sqlite.feature.speed.persistence.BindPersonDataSource)3 Transaction (sqlite.feature.speed.persistence.BindPersonDataSource.Transaction)3 PersonDaoImpl (sqlite.feature.speed.persistence.PersonDaoImpl)3 ArrayList (java.util.ArrayList)2 BindKripton180BeanDaoFactory (sqlite.feature.typeadapter.kripton180.bean.BindKripton180BeanDaoFactory)2 BindKripton180BeanDataSource (sqlite.feature.typeadapter.kripton180.bean.BindKripton180BeanDataSource)2