Search in sources :

Example 1 with Delete

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;
}
Also used : Delete(org.hibernate.sql.Delete) AssociationType(org.hibernate.type.AssociationType) JoinType(org.hibernate.sql.JoinType) CollectionType(org.hibernate.type.CollectionType) EntityType(org.hibernate.type.EntityType) ComponentType(org.hibernate.type.ComponentType) CompositeType(org.hibernate.type.CompositeType) VersionType(org.hibernate.type.VersionType) Type(org.hibernate.type.Type)

Aggregations

Delete (org.hibernate.sql.Delete)1 JoinType (org.hibernate.sql.JoinType)1 AssociationType (org.hibernate.type.AssociationType)1 CollectionType (org.hibernate.type.CollectionType)1 ComponentType (org.hibernate.type.ComponentType)1 CompositeType (org.hibernate.type.CompositeType)1 EntityType (org.hibernate.type.EntityType)1 Type (org.hibernate.type.Type)1 VersionType (org.hibernate.type.VersionType)1