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;
}
});
}
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");
}
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");
}
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;
}
});
}
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;
}
});
}
Aggregations