use of org.apache.cayenne.query.DeleteBatchQuery in project cayenne by apache.
the class DataDomainFlattenedBucket method addFlattenedDelete.
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);
}
}
}
use of org.apache.cayenne.query.DeleteBatchQuery 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.query.DeleteBatchQuery in project cayenne by apache.
the class DeleteBatchTranslator method applyQualifier.
/**
* 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 ");
}
}
}
use of org.apache.cayenne.query.DeleteBatchQuery 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.query.DeleteBatchQuery 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