use of example.entity.Emp in project doma by domaframework.
the class EntityProviderTest method testGetEntity.
@Test
public void testGetEntity() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("id"));
metaData.columns.add(new ColumnMetaData("name"));
metaData.columns.add(new ColumnMetaData("salary"));
metaData.columns.add(new ColumnMetaData("version"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData(1, "aaa", new BigDecimal(10), 100));
resultSet.next();
_Emp entityType = _Emp.getSingletonInternal();
EntityProvider<Emp> provider = new EntityProvider<>(entityType, new MySelectQuery(new MockConfig()), false);
Emp emp = provider.get(resultSet);
assertEquals(1, emp.getId());
assertEquals("aaa", emp.getName());
assertEquals(new BigDecimal(10), emp.getSalary());
assertEquals(100, emp.getVersion());
}
use of example.entity.Emp in project doma by domaframework.
the class EntityProviderTest method testGetEntity_UnknownColumnException.
@Test
public void testGetEntity_UnknownColumnException() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("id"));
metaData.columns.add(new ColumnMetaData("name"));
metaData.columns.add(new ColumnMetaData("salary"));
metaData.columns.add(new ColumnMetaData("version"));
metaData.columns.add(new ColumnMetaData("unknown"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData(1, "aaa", new BigDecimal(10), 100, "bbb"));
resultSet.next();
_Emp entityType = _Emp.getSingletonInternal();
EntityProvider<Emp> provider = new EntityProvider<>(entityType, new MySelectQuery(new MockConfig()), false);
try {
provider.get(resultSet);
fail();
} catch (UnknownColumnException expected) {
}
}
use of example.entity.Emp in project doma by domaframework.
the class EntitySingleResultHandlerTest method testHandle.
@Test
public void testHandle() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("id"));
metaData.columns.add(new ColumnMetaData("name"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData(1, "aaa"));
SqlFileSelectQuery query = new SqlFileSelectQuery();
query.setConfig(runtimeConfig);
query.setSqlFilePath(SqlFileUtil.buildPath(getClass().getName(), method.getName()));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setMethod(method);
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
EntitySingleResultHandler<Emp> handler = new EntitySingleResultHandler<>(_Emp.getSingletonInternal());
Emp emp = handler.handle(resultSet, query, (i, next) -> {
}).get();
assertEquals(1, emp.getId());
assertEquals("aaa", emp.getName());
}
use of example.entity.Emp in project doma by domaframework.
the class BatchInsertCommandTest method testExecute.
@Test
public void testExecute(TestInfo testInfo) {
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);
AutoBatchInsertQuery<Emp> query = new AutoBatchInsertQuery<>(_Emp.getSingletonInternal());
query.setMethod(testInfo.getTestMethod().get());
query.setConfig(runtimeConfig);
query.setEntities(Arrays.asList(emp1, emp2));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
int[] rows = new BatchInsertCommand(query).execute();
query.complete();
assertEquals(2, rows.length);
String sql = runtimeConfig.dataSource.connection.preparedStatement.sql;
assertEquals("insert into EMP (ID, NAME, SALARY, VERSION) values (?, ?, ?, ?)", sql);
}
use of example.entity.Emp 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();
}
Aggregations