Example usage for org.hibernate.tuple.entity EntityMetamodel getPropertyIndexOrNull

List of usage examples for org.hibernate.tuple.entity EntityMetamodel getPropertyIndexOrNull

Introduction

In this page you can find the example usage for org.hibernate.tuple.entity EntityMetamodel getPropertyIndexOrNull.

Prototype

public Integer getPropertyIndexOrNull(String propertyName) 

Source Link

Usage

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

License:Apache License

@Override
public boolean isOrphanRemoval(ManagedType<?> ownerType, String attributeName) {
    AbstractEntityPersister entityPersister = getEntityPersister(ownerType);
    if (entityPersister != null) {
        EntityMetamodel entityMetamodel = entityPersister.getEntityMetamodel();
        Integer index = entityMetamodel.getPropertyIndexOrNull(attributeName);
        if (index != null) {
            try {
                return (boolean) HAS_ORPHAN_DELETE_METHOD.invoke(entityMetamodel.getCascadeStyles()[index]);
            } 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  ww w .j  a v  a  2s . com
            }
        }
    }

    return false;
}

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

License:Apache License

@Override
public boolean isDeleteCascaded(ManagedType<?> ownerType, String attributeName) {
    AbstractEntityPersister entityPersister = getEntityPersister(ownerType);
    if (entityPersister != null) {
        EntityMetamodel entityMetamodel = entityPersister.getEntityMetamodel();
        Integer index = entityMetamodel.getPropertyIndexOrNull(attributeName);
        if (index != null) {
            try {
                return (boolean) DO_CASCADE_METHOD.invoke(entityMetamodel.getCascadeStyles()[index],
                        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);//w  w w . j  a va 2  s  .  co m
            }
        }
    }

    return false;
}

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

License:Apache License

@Override
public boolean isOrphanRemoval(ManagedType<?> ownerType, String attributeName) {
    AbstractEntityPersister entityPersister = getEntityPersister(ownerType);
    if (entityPersister != null) {
        EntityMetamodel entityMetamodel = entityPersister.getEntityMetamodel();
        Integer index = entityMetamodel.getPropertyIndexOrNull(attributeName);
        if (index != null) {
            return entityMetamodel.getCascadeStyles()[index].hasOrphanDelete();
        }//  www  .  j a v a 2 s .  c  o  m
    }

    return false;
}

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

License:Apache License

@Override
public boolean isDeleteCascaded(ManagedType<?> ownerType, String attributeName) {
    AbstractEntityPersister entityPersister = getEntityPersister(ownerType);
    if (entityPersister != null) {
        EntityMetamodel entityMetamodel = entityPersister.getEntityMetamodel();
        Integer index = entityMetamodel.getPropertyIndexOrNull(attributeName);
        if (index != null) {
            return entityMetamodel.getCascadeStyles()[index].doCascade(CascadingAction.DELETE);
        }/*from  w  w  w.  ja v a2 s.c  o m*/
    }

    return false;
}

From source file:org.jboss.tools.hibernate3_5.console.EntityPropertySource.java

License:Open Source License

public Object getPropertyValue(Object id) {
    Object propertyValue;/*  w ww  . j a v  a 2 s . c o m*/

    if (id.equals(classMetadata.getIdentifierPropertyName())) {
        propertyValue = classMetadata.getIdentifier(reflectedObject, EntityMode.POJO);
    } else {
        try {
            propertyValue = classMetadata.getPropertyValue(reflectedObject, (String) id, EntityMode.POJO);
        } catch (HibernateException he) {
            propertyValue = HibernateConsoleMessages.EntityPropertySource_unable_to_resolve_property;
            if (classMetadata instanceof AbstractEntityPersister) {
                AbstractEntityPersister aep = (AbstractEntityPersister) classMetadata;
                EntityMetamodel emm = aep.getEntityMetamodel();
                if (emm != null) {
                    Integer idx = emm.getPropertyIndexOrNull((String) id);
                    if (idx != null) {
                        propertyValue = emm.getTuplizer(EntityMode.POJO).getPropertyValue(reflectedObject, idx);
                    }
                }
            }
        }
    }

    if (propertyValue instanceof Collection<?>) {
        CollectionMetadata collectionMetadata = currentSession.getSessionFactory()
                .getCollectionMetadata(classMetadata.getEntityName() + "." + id); //$NON-NLS-1$
        if (collectionMetadata != null) {
            propertyValue = new CollectionPropertySource((Collection<?>) propertyValue);
        }
    }
    return propertyValue;
}

From source file:org.jboss.tools.hibernate4_0.console.EntityPropertySource.java

License:Open Source License

public Object getPropertyValue(Object id) {
    Object propertyValue;/*from   w  ww .  j  a v  a 2s .  co m*/

    if (id.equals(classMetadata.getIdentifierPropertyName())) {
        propertyValue = classMetadata.getIdentifier(reflectedObject, (SessionImplementor) currentSession);
    } else {
        try {
            propertyValue = classMetadata.getPropertyValue(reflectedObject, (String) id);
        } catch (HibernateException he) {
            propertyValue = HibernateConsoleMessages.EntityPropertySource_unable_to_resolve_property;
            if (classMetadata instanceof AbstractEntityPersister) {
                AbstractEntityPersister aep = (AbstractEntityPersister) classMetadata;
                EntityMetamodel emm = aep.getEntityMetamodel();
                if (emm != null) {
                    Integer idx = emm.getPropertyIndexOrNull((String) id);
                    if (idx != null) {
                        propertyValue = emm.getTuplizer().getPropertyValue(reflectedObject, idx);
                    }
                }
            }
        }
    }

    if (propertyValue instanceof Collection<?>) {
        CollectionMetadata collectionMetadata = currentSession.getSessionFactory()
                .getCollectionMetadata(classMetadata.getEntityName() + "." + id); //$NON-NLS-1$
        if (collectionMetadata != null) {
            propertyValue = new CollectionPropertySource((Collection<?>) propertyValue);
        }
    }
    return propertyValue;
}