use of example.entity.Emp in project doma by domaframework.
the class SqlFileUpdateQueryTest method testOriginalStates_unchanged.
@Test
public void testOriginalStates_unchanged() {
Emp emp = new Emp();
emp.setId(10);
emp.setName("aaa");
emp.setSalary(BigDecimal.ZERO);
emp.setVersion(100);
emp.originalStates = new Emp();
emp.originalStates.setId(emp.getId());
emp.originalStates.setName(emp.getName());
emp.originalStates.setSalary(emp.getSalary());
emp.originalStates.setVersion(emp.getVersion());
SqlFileUpdateQuery query = new SqlFileUpdateQuery();
query.setMethod(method);
query.setSqlFilePath("META-INF/org/seasar/doma/jdbc/query/SqlFileUpdateQueryTest/testOriginalStates.sql");
query.setConfig(runtimeConfig);
query.setEntityAndEntityType("emp", emp, _Emp.getSingletonInternal());
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setSqlLogType(SqlLogType.FORMATTED);
query.addParameter("emp", Emp.class, emp);
query.prepare();
PreparedSql sql = ((UpdateQuery) query).getSql();
assertEquals("update aaa set VERSION = ? + 1 where id = ?", sql.getRawSql());
assertEquals("update aaa set VERSION = 100 + 1 where id = 10", sql.getFormattedSql());
List<? extends InParameter<?>> parameters = sql.getParameters();
assertEquals(2, parameters.size());
assertEquals(100, parameters.get(0).getWrapper().get());
assertEquals(10, parameters.get(1).getWrapper().get());
assertFalse(query.isExecutable());
}
use of example.entity.Emp in project doma by domaframework.
the class SqlFileUpdateQueryTest method testPopulate_exclude.
@Test
public void testPopulate_exclude() {
Emp emp = new Emp();
emp.setId(10);
emp.setName("aaa");
emp.setSalary(new BigDecimal(200));
emp.setVersion(100);
SqlFileUpdateQuery query = new SqlFileUpdateQuery();
query.setMethod(method);
query.setSqlFilePath("META-INF/org/seasar/doma/jdbc/query/SqlFileUpdateQueryTest/testPopulate.sql");
query.setConfig(runtimeConfig);
query.setEntityAndEntityType("emp", emp, _Emp.getSingletonInternal());
query.setExcludedPropertyNames("name");
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setSqlLogType(SqlLogType.FORMATTED);
query.addParameter("emp", Emp.class, emp);
query.prepare();
PreparedSql sql = query.getSql();
assertEquals("update aaa set SALARY = ?, VERSION = ? + 1 where id = ?", sql.getRawSql());
List<InParameter<?>> parameters = sql.getParameters();
assertEquals(3, parameters.size());
assertEquals(new BigDecimal(200), parameters.get(0).getWrapper().get());
assertEquals(100, parameters.get(1).getWrapper().get());
assertEquals(10, parameters.get(2).getWrapper().get());
assertEquals(100, parameters.get(1).getWrapper().get());
assertTrue(query.isExecutable());
}
use of example.entity.Emp in project doma by domaframework.
the class SqlFileUpdateQueryTest method testPopulate_include.
@Test
public void testPopulate_include() {
Emp emp = new Emp();
emp.setId(10);
emp.setName("aaa");
emp.setSalary(new BigDecimal(200));
emp.setVersion(100);
SqlFileUpdateQuery query = new SqlFileUpdateQuery();
query.setMethod(method);
query.setSqlFilePath("META-INF/org/seasar/doma/jdbc/query/SqlFileUpdateQueryTest/testPopulate.sql");
query.setConfig(runtimeConfig);
query.setEntityAndEntityType("emp", emp, _Emp.getSingletonInternal());
query.setIncludedPropertyNames("name");
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setSqlLogType(SqlLogType.FORMATTED);
query.addParameter("emp", Emp.class, emp);
query.prepare();
PreparedSql sql = query.getSql();
assertEquals("update aaa set NAME = ?, VERSION = ? + 1 where id = ?", sql.getRawSql());
List<InParameter<?>> parameters = sql.getParameters();
assertEquals(3, parameters.size());
assertEquals("aaa", parameters.get(0).getWrapper().get());
assertEquals(100, parameters.get(1).getWrapper().get());
assertEquals(10, parameters.get(2).getWrapper().get());
assertTrue(query.isExecutable());
}
use of example.entity.Emp in project doma by domaframework.
the class EntityIterationHandlerTest 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"));
resultSet.rows.add(new RowData(2, "bbb"));
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();
EntityIterationHandler<Emp, Integer> handler = new EntityIterationHandler<>(_Emp.getSingletonInternal(), new IterationCallback<Emp, Integer>() {
private int count;
@Override
public Integer iterate(Emp target, IterationContext iterationContext) {
count++;
return count;
}
});
Integer result = handler.handle(resultSet, query, (i, next) -> {
}).get();
assertEquals(new Integer(2), result);
}
use of example.entity.Emp in project doma by domaframework.
the class EntityIterationHandlerTest method testHandle_exits.
@Test
public void testHandle_exits() 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"));
resultSet.rows.add(new RowData(2, "bbb"));
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();
EntityIterationHandler<Emp, Integer> handler = new EntityIterationHandler<>(_Emp.getSingletonInternal(), new IterationCallback<Emp, Integer>() {
private int count;
@Override
public Integer iterate(Emp target, IterationContext iterationContext) {
iterationContext.exit();
count++;
return count;
}
});
Integer result = handler.handle(resultSet, query, (i, next) -> {
}).get();
assertEquals(new Integer(1), result);
}
Aggregations