use of org.seasar.doma.jdbc.query.AutoBatchUpdateQuery in project doma by domaframework.
the class BatchUpdateCommandTest method testExecute_suppressesOptimisticLockException.
@Test
public void testExecute_suppressesOptimisticLockException() {
Emp emp = new Emp();
emp.setId(1);
emp.setName("hoge");
emp.setVersion(10);
runtimeConfig.dataSource.connection.preparedStatement.updatedRows = 0;
AutoBatchUpdateQuery<Emp> query = new AutoBatchUpdateQuery<>(_Emp.getSingletonInternal());
query.setMethod(method);
query.setConfig(runtimeConfig);
query.setEntities(Collections.singletonList(emp));
query.setOptimisticLockExceptionSuppressed(true);
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
new BatchUpdateCommand(query).execute();
query.complete();
}
use of org.seasar.doma.jdbc.query.AutoBatchUpdateQuery in project doma by domaframework.
the class BatchUpdateCommandTest method testExecute.
@Test
public void testExecute() {
Emp emp1 = new Emp();
emp1.setId(1);
emp1.setName("hoge");
emp1.setVersion(10);
Emp emp2 = new Emp();
emp2.setId(2);
emp2.setName("foo");
emp2.setVersion(20);
AutoBatchUpdateQuery<Emp> query = new AutoBatchUpdateQuery<>(_Emp.getSingletonInternal());
query.setMethod(method);
query.setConfig(runtimeConfig);
query.setEntities(Arrays.asList(emp1, emp2));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
int[] rows = new BatchUpdateCommand(query).execute();
query.complete();
assertEquals(2, rows.length);
String sql = runtimeConfig.dataSource.connection.preparedStatement.sql;
assertEquals("update EMP set NAME = ?, SALARY = ?, VERSION = ? + 1 where ID = ? and VERSION = ?", sql);
assertEquals(new Integer(11), emp1.getVersion());
assertEquals(new Integer(21), emp2.getVersion());
}
use of org.seasar.doma.jdbc.query.AutoBatchUpdateQuery in project doma by domaframework.
the class BatchUpdateCommandTest method testExecute_throwsOptimisticLockException.
@Test
public void testExecute_throwsOptimisticLockException() {
Emp emp = new Emp();
emp.setId(1);
emp.setName("hoge");
emp.setVersion(10);
runtimeConfig.dataSource.connection.preparedStatement.updatedRows = 0;
AutoBatchUpdateQuery<Emp> query = new AutoBatchUpdateQuery<>(_Emp.getSingletonInternal());
query.setMethod(method);
query.setConfig(runtimeConfig);
query.setEntities(Collections.singletonList(emp));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
BatchUpdateCommand command = new BatchUpdateCommand(query);
try {
command.execute();
fail();
} catch (OptimisticLockException expected) {
}
}
Aggregations