void addFlattenedDelete(DbEntity flattenedEntity, FlattenedArcKey flattenedDeleteInfo) { DeleteBatchQuery relationDeleteQuery = (DeleteBatchQuery) flattenedDeleteQueries .get(flattenedEntity); if (relationDeleteQuery == null) { boolean optimisticLocking = false; relationDeleteQuery = new DeleteBatchQuery(flattenedEntity, 50); relationDeleteQuery.setUsingOptimisticLocking(optimisticLocking); flattenedDeleteQueries.put(flattenedEntity, relationDeleteQuery); } DataNode node = parent.getDomain().lookupDataNode(flattenedEntity.getDataMap()); List flattenedSnapshots = flattenedDeleteInfo.buildJoinSnapshotsForDelete(node); if (!flattenedSnapshots.isEmpty()) { Iterator snapsIt = flattenedSnapshots.iterator(); while (snapsIt.hasNext()) { relationDeleteQuery.add((Map) snapsIt.next()); } } }
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(); }
public Object getValue(int dbAttributeIndex) { DbAttribute attribute = (DbAttribute) dbAttributes.get(dbAttributeIndex); return getCurrentQualifier().get(attribute.getName()); }
/** * 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 "); } } }
@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[] 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; }
@Override protected BatchTranslator deleteTranslator(DeleteBatchQuery query, DbAdapter adapter, String trimFunction) { DbAttribute attr = query.getDbEntity().getAttribute(deletedFieldName); boolean needsSoftDelete = attr != null && attr.getType() == Types.BOOLEAN; return needsSoftDelete ? new SoftDeleteBatchTranslator(query, adapter, trimFunction, deletedFieldName) : super .deleteTranslator(query, adapter, trimFunction); }
@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; } }
void addFlattenedDelete(DbEntity flattenedEntity, FlattenedArcKey flattenedDeleteInfo) { DeleteBatchQuery relationDeleteQuery = flattenedDeleteQueries.get(flattenedEntity); if (relationDeleteQuery == null) { Collection<DbAttribute> pk = flattenedEntity.getPrimaryKeys(); List<DbAttribute> pkList = pk instanceof List ? (List<DbAttribute>) pk : new ArrayList<>(pk); relationDeleteQuery = new DeleteBatchQuery(flattenedEntity, pkList, Collections.<String> emptySet(), 50); relationDeleteQuery.setUsingOptimisticLocking(false); flattenedDeleteQueries.put(flattenedEntity, relationDeleteQuery); } DataNode node = parent.getDomain().lookupDataNode(flattenedEntity.getDataMap()); List<Map<String, Object>> flattenedSnapshots = flattenedDeleteInfo.buildJoinSnapshotsForDelete(node); if (!flattenedSnapshots.isEmpty()) { for (Map<String, Object> flattenedSnapshot : flattenedSnapshots) { relationDeleteQuery.add(flattenedSnapshot); } } }
/** * 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()); } } }
snapshot = ((DeleteBatchQuery) query).getCurrentQualifier();
batch = new DeleteBatchQuery(dbEntity, qualifierBuilder .getAttributes(), nullQualifierNames, 27); batch.setUsingOptimisticLocking(qualifierBuilder .isUsingOptimisticLocking()); batches.put(batchKey, batch); batch.add(qualifierSnapshot);
batch = new DeleteBatchQuery(dbEntity, qualifierBuilder .getAttributes(), nullQualifierNames, 27); batch.setUsingOptimisticLocking(qualifierBuilder .isUsingOptimisticLocking()); batches.put(batchKey, batch); batch.add(qualifierSnapshot);