/** * Appends WHERE clause to SQL string */ protected void applyQualifier(StringBuilder buffer) { buffer.append(" WHERE "); DeleteBatchQuery deleteBatch = (DeleteBatchQuery) query; Iterator<DbAttribute> i = deleteBatch.getDbAttributes().iterator(); while (i.hasNext()) { DbAttribute attribute = i.next(); appendDbAttribute(buffer, attribute); buffer.append(deleteBatch.isNull(attribute) ? " IS NULL" : " = ?"); if (i.hasNext()) { buffer.append(" AND "); } } }
public String createSqlString(BatchQuery batch) { DeleteBatchQuery deleteBatch = (DeleteBatchQuery) batch; String table = batch.getDbEntity().getFullyQualifiedName(); List qualifierAttributes = deleteBatch.getQualifierAttributes(); StringBuffer query = new StringBuffer("DELETE FROM "); query.append(table).append(" WHERE "); Iterator i = qualifierAttributes.iterator(); while (i.hasNext()) { DbAttribute attribute = (DbAttribute) i.next(); appendDbAttribute(query, attribute); query.append(deleteBatch.isNull(attribute) ? " IS NULL" : " = ?"); if (i.hasNext()) { query.append(" AND "); } } return query.toString(); }
/** * Binds BatchQuery parameters to the PreparedStatement. */ public void bindParameters(PreparedStatement statement, BatchQuery query) throws SQLException, Exception { DeleteBatchQuery deleteBatch = (DeleteBatchQuery) query; List qualifierAttributes = deleteBatch.getQualifierAttributes(); int parameterIndex = 1; for (int i = 0; i < qualifierAttributes.size(); i++) { Object value = query.getValue(i); DbAttribute attribute = (DbAttribute) qualifierAttributes.get(i); // skip null attributes... they are translated as "IS NULL" if (deleteBatch.isNull(attribute)) { continue; } adapter.bindParameter( statement, value, parameterIndex++, attribute.getType(), attribute.getPrecision()); } } }
@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; } }
@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; } }