Example usage for org.hibernate.type ComponentType getCascadeStyle

List of usage examples for org.hibernate.type ComponentType getCascadeStyle

Introduction

In this page you can find the example usage for org.hibernate.type ComponentType getCascadeStyle.

Prototype

@Override
    public CascadeStyle getCascadeStyle(int i) 

Source Link

Usage

From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpa21Provider.java

License:Apache License

@Override
public boolean isOrphanRemoval(ManagedType<?> ownerType, String elementCollectionPath, String attributeName) {
    Type elementType = getCollectionPersister(ownerType, elementCollectionPath).getElementType();
    if (!(elementType instanceof ComponentType)) {
        // This can only happen for collection/join table target attributes, where it is irrelevant
        return false;
    }//from  w  w w  .jav  a2 s. c  om
    ComponentType componentType = (ComponentType) elementType;
    String subAttribute = attributeName.substring(elementCollectionPath.length() + 1);
    // Component types only store direct properties, so we have to go deeper
    String[] propertyParts = subAttribute.split("\\.");
    int propertyIndex = 0;
    for (; propertyIndex < propertyParts.length - 1; propertyIndex++) {
        int index = componentType.getPropertyIndex(propertyParts[propertyIndex]);
        Type propertyType = componentType.getSubtypes()[index];
        if (propertyType instanceof ComponentType) {
            componentType = (ComponentType) propertyType;
        } else {
            // The association property is just as good as the id property of the association for our purposes
            // So we stop here and query the association property instead
            break;
        }
    }

    try {
        return (boolean) HAS_ORPHAN_DELETE_METHOD.invoke(componentType.getCascadeStyle(propertyIndex));
    } catch (Exception ex) {
        throw new RuntimeException(
                "Could not access orphan removal information. Please report your version of hibernate so we can provide support for it!",
                ex);
    }
}

From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpa21Provider.java

License:Apache License

@Override
public boolean isDeleteCascaded(ManagedType<?> ownerType, String elementCollectionPath, String attributeName) {
    Type elementType = getCollectionPersister(ownerType, elementCollectionPath).getElementType();
    if (!(elementType instanceof ComponentType)) {
        // This can only happen for collection/join table target attributes, where it is irrelevant
        return false;
    }//from  w ww. j a v  a  2s. c o m
    ComponentType componentType = (ComponentType) elementType;
    String subAttribute = attributeName.substring(elementCollectionPath.length() + 1);
    // Component types only store direct properties, so we have to go deeper
    String[] propertyParts = subAttribute.split("\\.");
    int propertyIndex = 0;
    for (; propertyIndex < propertyParts.length - 1; propertyIndex++) {
        int index = componentType.getPropertyIndex(propertyParts[propertyIndex]);
        Type propertyType = componentType.getSubtypes()[index];
        if (propertyType instanceof ComponentType) {
            componentType = (ComponentType) propertyType;
        } else {
            // The association property is just as good as the id property of the association for our purposes
            // So we stop here and query the association property instead
            break;
        }
    }
    try {
        return (boolean) DO_CASCADE_METHOD.invoke(componentType.getCascadeStyle(propertyIndex), DELETE_CASCADE);
    } catch (Exception ex) {
        throw new RuntimeException(
                "Could not access orphan removal information. Please report your version of hibernate so we can provide support for it!",
                ex);
    }
}

From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java

License:Apache License

@Override
public boolean isOrphanRemoval(ManagedType<?> ownerType, String elementCollectionPath, String attributeName) {
    Type elementType = getCollectionPersister(ownerType, elementCollectionPath).getElementType();
    if (!(elementType instanceof ComponentType)) {
        // This can only happen for collection/join table target attributes, where it is irrelevant
        return false;
    }//from  ww w . j a v a2s . co m
    ComponentType componentType = (ComponentType) elementType;
    String subAttribute = attributeName.substring(elementCollectionPath.length() + 1);
    // Component types only store direct properties, so we have to go deeper
    String[] propertyParts = subAttribute.split("\\.");
    int propertyIndex = 0;
    for (; propertyIndex < propertyParts.length - 1; propertyIndex++) {
        int index = componentType.getPropertyIndex(propertyParts[propertyIndex]);
        Type propertyType = componentType.getSubtypes()[index];
        if (propertyType instanceof ComponentType) {
            componentType = (ComponentType) propertyType;
        } else {
            // The association property is just as good as the id property of the association for our purposes
            // So we stop here and query the association property instead
            break;
        }
    }
    return componentType.getCascadeStyle(propertyIndex).hasOrphanDelete();
}

From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java

License:Apache License

@Override
public boolean isDeleteCascaded(ManagedType<?> ownerType, String elementCollectionPath, String attributeName) {
    Type elementType = getCollectionPersister(ownerType, elementCollectionPath).getElementType();
    if (!(elementType instanceof ComponentType)) {
        // This can only happen for collection/join table target attributes, where it is irrelevant
        return false;
    }/*from w  ww .  java2s.  c  o m*/
    ComponentType componentType = (ComponentType) elementType;
    String subAttribute = attributeName.substring(elementCollectionPath.length() + 1);
    // Component types only store direct properties, so we have to go deeper
    String[] propertyParts = subAttribute.split("\\.");
    int propertyIndex = 0;
    for (; propertyIndex < propertyParts.length - 1; propertyIndex++) {
        int index = componentType.getPropertyIndex(propertyParts[propertyIndex]);
        Type propertyType = componentType.getSubtypes()[index];
        if (propertyType instanceof ComponentType) {
            componentType = (ComponentType) propertyType;
        } else {
            // The association property is just as good as the id property of the association for our purposes
            // So we stop here and query the association property instead
            break;
        }
    }
    return componentType.getCascadeStyle(propertyIndex).doCascade(CascadingAction.DELETE);
}