use of example.entity.Emp in project doma by domaframework.
the class AutoUpdateQueryTest method testOption_excludeNull.
@Test
public void testOption_excludeNull() {
Emp emp = new Emp();
emp.setId(10);
emp.setVersion(100);
AutoUpdateQuery<Emp> query = new AutoUpdateQuery<>(_Emp.getSingletonInternal());
query.setMethod(method);
query.setConfig(runtimeConfig);
query.setEntity(emp);
query.setNullExcluded(true);
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
PreparedSql sql = query.getSql();
assertEquals("update EMP set VERSION = ? + 1 where ID = ? and VERSION = ?", sql.getRawSql());
List<InParameter<?>> parameters = sql.getParameters();
assertEquals(3, parameters.size());
assertEquals(100, parameters.get(0).getWrapper().get());
assertEquals(10, parameters.get(1).getWrapper().get());
assertEquals(100, parameters.get(2).getWrapper().get());
}
use of example.entity.Emp in project doma by domaframework.
the class AutoUpdateQueryTest method testIsExecutable.
@Test
public void testIsExecutable() {
Emp emp = new Emp();
emp.originalStates = new Emp();
AutoUpdateQuery<Emp> query = new AutoUpdateQuery<>(_Emp.getSingletonInternal());
query.setMethod(method);
query.setConfig(runtimeConfig);
query.setEntity(emp);
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
assertFalse(query.isExecutable());
}
use of example.entity.Emp in project doma by domaframework.
the class SqlFileBatchDeleteQueryTest method testOption_default.
@Test
public void testOption_default() {
Emp emp1 = new Emp();
emp1.setName("aaa");
Emp emp2 = new Emp();
emp2.setName("bbb");
SqlFileBatchDeleteQuery<Emp> query = new SqlFileBatchDeleteQuery<>(Emp.class);
query.setMethod(method);
query.setConfig(runtimeConfig);
query.setSqlFilePath(SqlFileUtil.buildPath(getClass().getName(), method.getName()));
query.setParameterName("e");
query.setElements(Arrays.asList(emp1, emp2));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
PreparedSql sql = query.getSqls().get(0);
assertEquals("delete from emp where name = ?", sql.getRawSql());
List<InParameter<?>> parameters = sql.getParameters();
assertEquals(1, parameters.size());
assertEquals("aaa", parameters.get(0).getWrapper().get());
sql = query.getSqls().get(1);
assertEquals("delete from emp where name = ?", sql.getRawSql());
parameters = sql.getParameters();
assertEquals(1, parameters.size());
assertEquals("bbb", parameters.get(0).getWrapper().get());
}
use of example.entity.Emp in project doma by domaframework.
the class AutoBatchDeleteQueryTest method testOption_default.
@Test
public void testOption_default() {
Emp emp1 = new Emp();
emp1.setId(10);
emp1.setName("aaa");
Emp emp2 = new Emp();
emp2.setId(20);
emp2.setSalary(new BigDecimal(2000));
emp2.setVersion(10);
AutoBatchDeleteQuery<Emp> query = new AutoBatchDeleteQuery<>(_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("delete from EMP where ID = ? and VERSION = ?", sql.getRawSql());
List<InParameter<?>> parameters = sql.getParameters();
assertEquals(2, parameters.size());
assertEquals(10, parameters.get(0).getWrapper().get());
assertNull(parameters.get(1).getWrapper().get());
sql = query.getSqls().get(1);
assertEquals("delete from EMP where ID = ? and VERSION = ?", sql.getRawSql());
parameters = sql.getParameters();
assertEquals(2, parameters.size());
assertEquals(20, parameters.get(0).getWrapper().get());
assertEquals(10, parameters.get(1).getWrapper().get());
}
use of example.entity.Emp in project doma by domaframework.
the class AutoBatchInsertQueryTest method testPrepare.
@Test
public void testPrepare() {
Emp emp1 = new Emp();
emp1.setId(10);
emp1.setName("aaa");
Emp emp2 = new Emp();
emp2.setId(20);
emp2.setName("bbb");
AutoBatchInsertQuery<Emp> query = new AutoBatchInsertQuery<>(_Emp.getSingletonInternal());
query.setMethod(method);
query.setConfig(runtimeConfig);
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setEntities(Arrays.asList(emp1, emp2));
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
assertTrue(((BatchInsertQuery) query).isBatchSupported());
assertEquals(2, ((BatchInsertQuery) query).getSqls().size());
}
Aggregations