use of org.seasar.doma.jdbc.command.BatchDeleteCommand in project doma by domaframework.
the class EntityqlBatchDeleteStatement method createCommand.
@Override
protected Command<BatchResult<ENTITY>> createCommand() {
EntityType<ENTITY> entityType = entityMetamodel.asType();
AutoBatchDeleteQuery<ENTITY> query = config.getQueryImplementors().createAutoBatchDeleteQuery(EXECUTE_METHOD, entityType);
query.setMethod(EXECUTE_METHOD);
query.setConfig(config);
query.setEntities(entities);
query.setCallerClassName(getClass().getName());
query.setCallerMethodName(EXECUTE_METHOD_NAME);
query.setQueryTimeout(settings.getQueryTimeout());
query.setBatchSize(settings.getBatchSize());
query.setSqlLogType(settings.getSqlLogType());
query.setVersionIgnored(settings.getIgnoreVersion());
query.setOptimisticLockExceptionSuppressed(settings.getSuppressOptimisticLockException());
query.setMessage(settings.getComment());
query.prepare();
BatchDeleteCommand command = config.getCommandImplementors().createBatchDeleteCommand(EXECUTE_METHOD, query);
return new Command<BatchResult<ENTITY>>() {
@Override
public Query getQuery() {
return query;
}
@Override
public BatchResult<ENTITY> execute() {
int[] counts = command.execute();
query.complete();
return new BatchResult<>(counts, query.getEntities());
}
};
}
use of org.seasar.doma.jdbc.command.BatchDeleteCommand in project doma by domaframework.
the class BatchDeleteExecutor method execute.
/**
* Executes SQL DELETE statements.
*
* @param <P> the parameter type
* @param params the parameters
* @param buildConsumer the code block that builds SQL statements
* @return the array whose each element contains affected rows count. The array length is equal to
* the {@code parameter} size.
* @throws DomaNullPointerException if {@code params} or {@code buildConsumer} is {@code null}
* @throws JdbcException if a JDBC related error occurs
*/
public <P> int[] execute(Iterable<P> params, BiConsumer<P, BatchBuilder> buildConsumer) {
if (params == null) {
throw new DomaNullPointerException("params");
}
if (buildConsumer == null) {
throw new DomaNullPointerException("buildConsumer");
}
if (query.getMethodName() == null) {
query.setCallerMethodName("execute");
}
BatchBuilder builder = BatchBuilder.newInstance(query);
for (P p : params) {
buildConsumer.accept(p, builder);
builder = builder.fixSql();
}
return builder.execute(() -> new BatchDeleteCommand(query));
}
use of org.seasar.doma.jdbc.command.BatchDeleteCommand 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();
}
use of org.seasar.doma.jdbc.command.BatchDeleteCommand in project doma by domaframework.
the class BatchDeleteExecutorTest method testBuilder.
@Test
public void testBuilder() {
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.sql("salary = ").param(BigDecimal.class, new BigDecimal("2000"));
builder = builder.fixSql();
builder.execute(() -> new BatchDeleteCommand(query));
}
Aggregations