@Override public Member resolveMember(AttributeContext attributeContext) { final EmbeddedTypeDescriptor embeddableType = (EmbeddedTypeDescriptor<?>) attributeContext.getOwnerType(); final String attributeName = attributeContext.getPropertyMapping().getName(); final Getter getter = embeddableType.getHibernateType() .getComponentTuplizer() .getGetter( embeddableType.getHibernateType().getPropertyIndex( attributeName ) ); return PropertyAccessMapImpl.GetterImpl.class.isInstance( getter ) ? new MapMember( attributeName, attributeContext.getPropertyMapping().getType().getReturnedClass() ) : getter.getMember(); } };
public CompositeIdOrder(String componentPath, ComponentType componentType) { super(); this.componentType = componentType; // Initialize with relative paths, but prepend a prefix below this.propertyPaths = new ArrayList<>( Arrays.asList( componentType.getPropertyNames() ) ); this.propertyPaths.sort( Comparator.naturalOrder() ); String pathPrefix = componentPath == null ? "" : componentPath + "."; this.propertyIndices = CollectionHelper.newArrayList( propertyPaths.size() ); ListIterator<String> iterator = this.propertyPaths.listIterator(); while ( iterator.hasNext() ) { String propertyName = iterator.next(); // We need the relative path of the property here propertyIndices.add( componentType.getPropertyIndex( propertyName ) ); // Prepend the path prefix to each property; we will only use absolute path from now on iterator.set( pathPrefix + propertyName ); } }
@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; 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; }
private Type associationPropertyType(Type type, String property) { if ( type instanceof ComponentType ) { ComponentType componentType = (ComponentType) type; return componentType.getSubtypes()[componentType.getPropertyIndex( property )]; } else if ( type instanceof EntityType ) { OgmEntityPersister persister = getPersister( type.getName() ); return persister.getPropertyType( property ); } throw new UnsupportedOperationException( "Unrecognized property type: " + type ); }
@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; } 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); } }
/** * {@inheritDoc} */ @Override public Type getPropertyType(String propertyName, String propertyPath) { int index = getComponentType().getPropertyIndex( propertyName ); return getComponentType().getSubtypes()[index]; }
/** * {@inheritDoc} */ @Override public Type getPropertyType(String propertyName, String propertyPath) { int index = getComponentType().getPropertyIndex( propertyName ); return getComponentType().getSubtypes()[index]; }
@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; } 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); } }
private void collectEmbeddedCollectionColumns(ComponentType componentType, String dotName, List<String> embeddedCollections) { for ( String propertyName : componentType.getPropertyNames() ) { Type type = componentType.getSubtypes()[componentType.getPropertyIndex( propertyName )]; if ( type.isCollectionType() ) { embeddedCollections.add( dotName + "." + propertyName ); } else if ( type.isComponentType() ) { collectEmbeddedCollectionColumns( (ComponentType) type, dotName + "." + propertyName, embeddedCollections ); } } }
@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; } 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(); }
@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; } 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); }
private void collectPropertyNames(Collection<String> propertyNames, String prefix, Type propertyType, Mapping factory) { 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); } }
/** * {@inheritDoc} */ public Member resolveMember(AttributeContext attributeContext) { final EmbeddableTypeImpl embeddableType = ( EmbeddableTypeImpl<?> ) attributeContext.getOwnerType(); final String attributeName = attributeContext.getPropertyMapping().getName(); return embeddableType.getHibernateType() .getComponentTuplizer() .getGetter( embeddableType.getHibernateType().getPropertyIndex( attributeName ) ) .getMember(); } };