use of example.entity.Emp in project doma by domaframework.
the class AutoBatchUpdateQueryTest method testPrepare.
@Test
public void testPrepare() {
Emp emp1 = new Emp();
emp1.setId(10);
emp1.setName("aaa");
emp1.setVersion(100);
Emp emp2 = new Emp();
emp2.setId(20);
emp2.setName("bbb");
emp2.setVersion(200);
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();
assertEquals(2, ((BatchUpdateQuery) query).getSqls().size());
}
use of example.entity.Emp in project doma by domaframework.
the class AutoBatchUpdateQueryTest method testOption_exclude.
@Test
public void testOption_exclude() {
Emp emp1 = new Emp();
emp1.setId(10);
emp1.setName("aaa");
emp1.setSalary(new BigDecimal(200));
emp1.setVersion(100);
Emp emp2 = new Emp();
emp2.setId(20);
emp2.setVersion(200);
AutoBatchUpdateQuery<Emp> query = new AutoBatchUpdateQuery<>(_Emp.getSingletonInternal());
query.setMethod(method);
query.setConfig(runtimeConfig);
query.setEntities(Arrays.asList(emp1, emp2));
query.setExcludedPropertyNames("name");
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
PreparedSql sql = query.getSqls().get(0);
assertEquals("update EMP set SALARY = ?, VERSION = ? + 1 where ID = ? and VERSION = ?", sql.getRawSql());
List<InParameter<?>> parameters = sql.getParameters();
assertEquals(4, 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(3).getWrapper().get());
sql = query.getSqls().get(1);
assertEquals("update EMP set SALARY = ?, VERSION = ? + 1 where ID = ? and VERSION = ?", sql.getRawSql());
parameters = sql.getParameters();
assertEquals(4, parameters.size());
assertNull(parameters.get(0).getWrapper().get());
assertEquals(200, parameters.get(1).getWrapper().get());
assertEquals(20, parameters.get(2).getWrapper().get());
assertEquals(200, parameters.get(3).getWrapper().get());
}
use of example.entity.Emp in project doma by domaframework.
the class AutoBatchUpdateQueryTest method testOption_default.
@Test
public void testOption_default() {
Emp emp1 = new Emp();
emp1.setId(10);
emp1.setName("aaa");
emp1.setVersion(100);
Emp emp2 = new Emp();
emp2.setId(20);
emp2.setSalary(new BigDecimal(2000));
emp2.setVersion(200);
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();
PreparedSql sql = query.getSqls().get(0);
assertEquals("update EMP set NAME = ?, SALARY = ?, VERSION = ? + 1 where ID = ? and VERSION = ?", sql.getRawSql());
List<InParameter<?>> parameters = sql.getParameters();
assertEquals(5, parameters.size());
assertEquals("aaa", parameters.get(0).getWrapper().get());
assertNull(parameters.get(1).getWrapper().get());
assertEquals(100, parameters.get(2).getWrapper().get());
assertEquals(10, parameters.get(3).getWrapper().get());
assertEquals(100, parameters.get(4).getWrapper().get());
sql = query.getSqls().get(1);
assertEquals("update EMP set NAME = ?, SALARY = ?, VERSION = ? + 1 where ID = ? and VERSION = ?", sql.getRawSql());
parameters = sql.getParameters();
assertEquals(5, parameters.size());
assertNull(parameters.get(0).getWrapper().get());
assertEquals(new BigDecimal(2000), parameters.get(1).getWrapper().get());
assertEquals(200, parameters.get(2).getWrapper().get());
assertEquals(20, parameters.get(3).getWrapper().get());
assertEquals(200, parameters.get(4).getWrapper().get());
}
use of example.entity.Emp in project doma by domaframework.
the class SqlFileUpdateQueryTest method testPopulate_excludeNull_updateNullableInPreUpdate.
@Test
public void testPopulate_excludeNull_updateNullableInPreUpdate() {
Emp emp = new Emp();
emp.setId(10);
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, new PreUpdate(_Emp.getSingletonInternal()));
query.setNullExcluded(true);
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("hoge", 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 SqlFileUpdateQueryTest method testPopulate_states.
@Test
public void testPopulate_states() {
Emp emp = new Emp();
emp.setId(10);
emp.setName("aaa");
emp.setVersion(100);
emp.originalStates = new Emp();
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.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());
}
Aggregations