use of org.hibernate.sql.Delete in project hibernate-orm by hibernate.
the class AbstractEntityPersister method generateSQLDeletStrings.
private String[] generateSQLDeletStrings(Object[] loadedState) {
int span = getTableSpan();
String[] deleteStrings = new String[span];
for (int j = span - 1; j >= 0; j--) {
Delete delete = new Delete().setTableName(getTableName(j)).addPrimaryKeyColumns(getKeyColumns(j));
if (getFactory().getSessionFactoryOptions().isCommentsEnabled()) {
delete.setComment("delete " + getEntityName() + " [" + j + "]");
}
boolean[] versionability = getPropertyVersionability();
Type[] types = getPropertyTypes();
for (int i = 0; i < entityMetamodel.getPropertySpan(); i++) {
if (isPropertyOfTable(i, j) && versionability[i]) {
// this property belongs to the table and it is not specifically
// excluded from optimistic locking by optimistic-lock="false"
String[] propertyColumnNames = getPropertyColumnNames(i);
boolean[] propertyNullness = types[i].toColumnNullness(loadedState[i], getFactory());
for (int k = 0; k < propertyNullness.length; k++) {
if (propertyNullness[k]) {
delete.addWhereFragment(propertyColumnNames[k] + " = ?");
} else {
delete.addWhereFragment(propertyColumnNames[k] + " is null");
}
}
}
}
deleteStrings[j] = delete.toStatementString();
}
return deleteStrings;
}
Aggregations