Search in sources :

Example 1 with SqlBatchDeleteQuery

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();
}
Also used : SqlBatchDeleteQuery(org.seasar.doma.jdbc.query.SqlBatchDeleteQuery) JdbcException(org.seasar.doma.jdbc.JdbcException) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 2 with SqlBatchDeleteQuery

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());
}
Also used : SqlBatchDeleteQuery(org.seasar.doma.jdbc.query.SqlBatchDeleteQuery) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 3 with SqlBatchDeleteQuery

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;
}
Also used : SqlBatchDeleteQuery(org.seasar.doma.jdbc.query.SqlBatchDeleteQuery) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig)

Example 4 with SqlBatchDeleteQuery

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();
}
Also used : SqlBatchDeleteQuery(org.seasar.doma.jdbc.query.SqlBatchDeleteQuery) JdbcException(org.seasar.doma.jdbc.JdbcException) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 5 with SqlBatchDeleteQuery

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();
}
Also used : BatchDeleteCommand(org.seasar.doma.jdbc.command.BatchDeleteCommand) SqlBatchDeleteQuery(org.seasar.doma.jdbc.query.SqlBatchDeleteQuery) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Aggregations

SqlBatchDeleteQuery (org.seasar.doma.jdbc.query.SqlBatchDeleteQuery)7 BigDecimal (java.math.BigDecimal)6 Test (org.junit.jupiter.api.Test)6 JdbcException (org.seasar.doma.jdbc.JdbcException)2 BatchDeleteCommand (org.seasar.doma.jdbc.command.BatchDeleteCommand)2 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)1