use of org.seasar.doma.jdbc.query.SqlBatchDeleteQuery in project doma by domaframework.
the class BatchDeleteExecutorTest method testParamToLiteral.
@Test
public void testParamToLiteral() {
SqlBatchDeleteQuery query = mockQuery();
BatchBuilder builder = BatchBuilder.newInstance(query);
builder.sql("delete from Emp");
builder.sql("where");
builder.sql("name = ").param(String.class, "SMITH");
builder.sql("and");
builder.sql("salary = ").param(BigDecimal.class, new BigDecimal("1000"));
builder = builder.fixSql();
builder.sql("delete from Emp");
builder.sql("where");
builder = builder.sql("name = ");
try {
builder.literal(String.class, "ALLEN");
} catch (JdbcException e) {
assertEquals(Message.DOMA2230, e.getMessageResource());
return;
}
fail();
}
use of org.seasar.doma.jdbc.query.SqlBatchDeleteQuery in project doma by domaframework.
the class BatchDeleteExecutorTest method testLiteral.
@Test
public void testLiteral() {
SqlBatchDeleteQuery query = mockQuery();
BatchBuilder builder = BatchBuilder.newInstance(query);
builder.sql("delete from Emp");
builder.sql("where");
builder.sql("name = ").literal(String.class, "SMITH");
builder.sql("and");
builder.sql("salary = ").literal(BigDecimal.class, new BigDecimal("1000"));
builder = builder.fixSql();
builder.sql("delete from Emp");
builder.sql("where");
builder.sql("name = ").literal(String.class, "ALLEN");
builder.sql("and");
builder.sql("salary = ").literal(BigDecimal.class, new BigDecimal("2000"));
builder = builder.fixSql();
List<? extends Sql<?>> sqls = builder.getSqls();
assertEquals(2, sqls.size());
Sql<?> sql0 = sqls.get(0);
assertEquals(String.format("delete from Emp%n" + "where%n" + "name = 'SMITH'%n" + "and%n" + "salary = 1000"), sql0.getRawSql());
List<? extends SqlParameter> parameters0 = sql0.getParameters();
assertEquals(0, parameters0.size());
Sql<?> sql1 = sqls.get(1);
assertEquals(String.format("delete from Emp%n" + "where%n" + "name = 'ALLEN'%n" + "and%n" + "salary = 2000"), sql1.getRawSql());
List<? extends SqlParameter> parameters1 = sql1.getParameters();
assertEquals(0, parameters1.size());
}
use of org.seasar.doma.jdbc.query.SqlBatchDeleteQuery in project doma by domaframework.
the class BatchDeleteExecutorTest method mockQuery.
private SqlBatchDeleteQuery mockQuery() {
final SqlBatchDeleteQuery query = new SqlBatchDeleteQuery();
query.setConfig(new MockConfig());
query.setSqlLogType(SqlLogType.FORMATTED);
return query;
}
use of org.seasar.doma.jdbc.query.SqlBatchDeleteQuery in project doma by domaframework.
the class BatchDeleteExecutorTest method testChangeType.
@Test
public void testChangeType() {
SqlBatchDeleteQuery query = mockQuery();
BatchBuilder builder = BatchBuilder.newInstance(query);
builder.sql("delete from Emp");
builder.sql("where");
builder.sql("name = ").param(String.class, "SMITH");
builder.sql("and");
builder.sql("salary = ").param(BigDecimal.class, new BigDecimal("1000"));
builder = builder.fixSql();
builder.sql("delete from Emp");
builder.sql("where");
builder.sql("name = ").param(String.class, "ALLEN");
builder.sql("and");
builder = builder.sql("salary = ");
try {
builder.param(int.class, 2000);
} catch (JdbcException e) {
assertEquals(Message.DOMA2229, e.getMessageResource());
return;
}
fail();
}
use of org.seasar.doma.jdbc.query.SqlBatchDeleteQuery in project doma by domaframework.
the class BatchDeleteExecutorTest method testNotEqualParamCall.
@Test
public void testNotEqualParamCall() {
SqlBatchDeleteQuery query = mockQuery();
BatchBuilder builder = BatchBuilder.newInstance(query);
builder.sql("delete from Emp");
builder.sql("where");
builder.sql("name = ").param(String.class, "SMITH");
builder.sql("and");
builder.sql("salary = ").param(BigDecimal.class, new BigDecimal("1000"));
builder = builder.fixSql();
builder.sql("delete from Emp");
builder.sql("where");
builder.sql("name = ").param(String.class, "ALLEN");
builder = builder.fixSql();
try {
builder.execute(() -> new BatchDeleteCommand(query));
} catch (AssertionError e) {
return;
}
fail();
}
Aggregations