List of usage examples for org.hibernate.type ComponentType getPropertyIndex
@Override
public int getPropertyIndex(String name)
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; }//w w w .j av 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 ww w . ja v a 2 s . 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; }// ww w .j a v a 2s . 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; } } 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; }// ww w . j av a2 s . 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).doCascade(CascadingAction.DELETE); }
From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java
License:Apache License
@Override public List<String> getIdentifierOrUniqueKeyEmbeddedPropertyNames(EntityType<?> owner, String elementCollectionPath, String attributeName) { QueryableCollection persister = getCollectionPersister(owner, elementCollectionPath); ComponentType componentType = (ComponentType) persister.getElementType(); String subAttribute = attributeName.substring(elementCollectionPath.length() + 1); // Component types only store direct properties, so we have to go deeper String[] propertyParts = subAttribute.split("\\."); Type propertyType;//from www . ja v a 2s. c o m for (int i = 0; i < propertyParts.length - 1; i++) { int index = componentType.getPropertyIndex(propertyParts[i]); propertyType = componentType.getSubtypes()[index]; if (propertyType instanceof ComponentType) { componentType = (ComponentType) propertyType; } else { // A path expression shouldn't navigate over an association.. throw new IllegalStateException("Can't get the id properties for: " + attributeName); } } propertyType = componentType.getSubtypes()[componentType .getPropertyIndex(propertyParts[propertyParts.length - 1])]; List<String> identifierOrUniqueKeyPropertyNames = new ArrayList<>(); collectPropertyNames(identifierOrUniqueKeyPropertyNames, null, propertyType, persister.getFactory()); return identifierOrUniqueKeyPropertyNames; }
From source file:com.blazebit.persistence.integration.hibernate.base.HibernateJpaProvider.java
License:Apache License
private void collectPropertyNames(Collection<String> propertyNames, String prefix, Type propertyType, Mapping factory) {/*from w w w . ja va2 s . com*/ if (propertyType instanceof ComponentType) { ComponentType componentType = (ComponentType) propertyType; for (String propertyName : componentType.getPropertyNames()) { Type subtype = componentType.getSubtypes()[componentType.getPropertyIndex(propertyName)]; collectPropertyNames(propertyNames, prefix == null ? propertyName : prefix + "." + propertyName, subtype, factory); } } else if (propertyType instanceof org.hibernate.type.EntityType) { org.hibernate.type.EntityType entityType = (org.hibernate.type.EntityType) propertyType; Type identifierOrUniqueKeyType = entityType.getIdentifierOrUniqueKeyType(factory); if (identifierOrUniqueKeyType instanceof EmbeddedComponentType) { EmbeddedComponentType embeddedComponentType = (EmbeddedComponentType) identifierOrUniqueKeyType; for (String propertyName : embeddedComponentType.getPropertyNames()) { propertyNames.add(prefix == null ? propertyName : prefix + "." + propertyName); } } else { String identifierOrUniqueKeyPropertyName = entityType.getIdentifierOrUniqueKeyPropertyName(factory); propertyNames.add(prefix == null ? identifierOrUniqueKeyPropertyName : prefix + "." + identifierOrUniqueKeyPropertyName); } } else if (!(propertyType instanceof CollectionType) && prefix != null) { propertyNames.add(prefix); } }
From source file:cz.jirutka.rsql.visitor.hibernate.HibernateCriterionVisitor.java
License:Apache License
private Type getPropertyType(ComponentType componentType, String property) { property = propertyResolver.getPropertyName(componentType.getReturnedClass(), property); int propertyIndex = componentType.getPropertyIndex(property); return componentType.getSubtypes()[propertyIndex]; }