use of org.apache.cayenne.access.translator.DbAttributeBinding in project cayenne by apache.
the class BatchAction method runAsBatch.
protected void runAsBatch(Connection con, BatchTranslator translator, OperationObserver delegate) throws SQLException, Exception {
String sql = translator.getSql();
JdbcEventLogger logger = dataNode.getJdbcEventLogger();
boolean isLoggable = logger.isLoggable();
// log batch SQL execution
logger.log(sql);
// run batch
DbAdapter adapter = dataNode.getAdapter();
try (PreparedStatement statement = con.prepareStatement(sql)) {
for (BatchQueryRow row : query.getRows()) {
DbAttributeBinding[] bindings = translator.updateBindings(row);
logger.logQueryParameters("batch bind", bindings);
bind(adapter, statement, bindings);
statement.addBatch();
}
// execute the whole batch
int[] results = statement.executeBatch();
delegate.nextBatchCount(query, results);
if (isLoggable) {
int totalUpdateCount = 0;
for (int result : results) {
// Statement.EXECUTE_FAILED
if (result < 0) {
totalUpdateCount = Statement.SUCCESS_NO_INFO;
break;
}
totalUpdateCount += result;
}
logger.logUpdateCount(totalUpdateCount);
}
}
}
use of org.apache.cayenne.access.translator.DbAttributeBinding in project cayenne by apache.
the class DeleteBatchTranslator method createBindings.
@Override
protected DbAttributeBinding[] createBindings() {
DeleteBatchQuery deleteBatch = (DeleteBatchQuery) query;
List<DbAttribute> attributes = deleteBatch.getDbAttributes();
int len = attributes.size();
DbAttributeBinding[] bindings = new DbAttributeBinding[len];
for (int i = 0; i < len; i++) {
bindings[i] = new DbAttributeBinding(attributes.get(i));
}
return bindings;
}
use of org.apache.cayenne.access.translator.DbAttributeBinding in project cayenne by apache.
the class DeleteBatchTranslator method doUpdateBindings.
@Override
protected DbAttributeBinding[] doUpdateBindings(BatchQueryRow row) {
int len = bindings.length;
DeleteBatchQuery deleteBatch = (DeleteBatchQuery) query;
for (int i = 0, j = 1; i < len; i++) {
DbAttributeBinding b = bindings[i];
// skip null attributes... they are translated as "IS NULL"
if (deleteBatch.isNull(b.getAttribute())) {
b.exclude();
} else {
Object value = row.getValue(i);
ExtendedType extendedType = value != null ? adapter.getExtendedTypes().getRegisteredType(value.getClass()) : adapter.getExtendedTypes().getDefaultType();
b.include(j++, value, extendedType);
}
}
return bindings;
}
use of org.apache.cayenne.access.translator.DbAttributeBinding in project cayenne by apache.
the class InsertBatchTranslator method doUpdateBindings.
@Override
protected DbAttributeBinding[] doUpdateBindings(BatchQueryRow row) {
int len = bindings.length;
for (int i = 0, j = 1; i < len; i++) {
DbAttributeBinding b = bindings[i];
// exclusions are permanent
if (!b.isExcluded()) {
Object value = row.getValue(i);
ExtendedType extendedType = value != null ? adapter.getExtendedTypes().getRegisteredType(value.getClass()) : adapter.getExtendedTypes().getDefaultType();
b.include(j++, value, extendedType);
}
}
return bindings;
}
use of org.apache.cayenne.access.translator.DbAttributeBinding in project cayenne by apache.
the class SoftDeleteBatchTranslator method doUpdateBindings.
@Override
protected DbAttributeBinding[] doUpdateBindings(BatchQueryRow row) {
int len = bindings.length;
DeleteBatchQuery deleteBatch = (DeleteBatchQuery) query;
// skip position 0... Otherwise follow super algorithm
for (int i = 1, j = 2; i < len; i++) {
DbAttributeBinding b = bindings[i];
// skip null attributes... they are translated as "IS NULL"
if (deleteBatch.isNull(b.getAttribute())) {
b.exclude();
} else {
Object value = row.getValue(i - 1);
ExtendedType extendedType = value != null ? adapter.getExtendedTypes().getRegisteredType(value.getClass()) : adapter.getExtendedTypes().getDefaultType();
b.include(j++, value, extendedType);
}
}
return bindings;
}
Aggregations