Search in sources :

Example 6 with CompositeType

use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.

the class JoinWalker method walkCompositeElementTree.

/**
	 * For a composite element, add to a list of associations to be fetched by outerjoin
	 */
private void walkCompositeElementTree(final CompositeType compositeType, final String[] cols, final QueryableCollection persister, final String alias, final PropertyPath path, final int currentDepth) throws MappingException {
    Type[] types = compositeType.getSubtypes();
    String[] propertyNames = compositeType.getPropertyNames();
    int begin = 0;
    for (int i = 0; i < types.length; i++) {
        int length = types[i].getColumnSpan(getFactory());
        String[] lhsColumns = ArrayHelper.slice(cols, begin, length);
        if (types[i].isAssociationType()) {
            AssociationType associationType = (AssociationType) types[i];
            // simple, because we can't have a one-to-one or a collection 
            // (or even a property-ref) in a composite-element:
            String[] aliasedLhsColumns = StringHelper.qualify(alias, lhsColumns);
            final PropertyPath subPath = path.append(propertyNames[i]);
            final boolean[] propertyNullability = compositeType.getPropertyNullability();
            final JoinType joinType = getJoinType(associationType, compositeType.getFetchMode(i), subPath, persister.getTableName(), lhsColumns, propertyNullability == null || propertyNullability[i], currentDepth, compositeType.getCascadeStyle(i));
            addAssociationToJoinTreeIfNecessary(associationType, aliasedLhsColumns, alias, subPath, currentDepth, joinType);
        } else if (types[i].isComponentType()) {
            final PropertyPath subPath = path.append(propertyNames[i]);
            walkCompositeElementTree((CompositeType) types[i], lhsColumns, persister, alias, subPath, currentDepth);
        }
        begin += length;
    }
}
Also used : EntityType(org.hibernate.type.EntityType) CompositeType(org.hibernate.type.CompositeType) JoinType(org.hibernate.sql.JoinType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) AssociationType(org.hibernate.type.AssociationType) JoinType(org.hibernate.sql.JoinType) CompositeType(org.hibernate.type.CompositeType)

Example 7 with CompositeType

use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.

the class JoinWalker method walkComponentTree.

/**
	 * For a component, add to a list of associations to be fetched by outerjoin
	 *
	 * @param componentType The component type to be walked.
	 * @param propertyNumber The property number for the component property (relative to
	 * persister).
	 * @param begin todo unknowm
	 * @param persister The owner of the component property
	 * @param alias The root alias
	 * @param path The property access path
	 * @param currentDepth The current join depth
	 *
	 * @throws org.hibernate.MappingException ???
	 */
private void walkComponentTree(final CompositeType componentType, final int propertyNumber, int begin, final OuterJoinLoadable persister, final String alias, final PropertyPath path, final int currentDepth) throws MappingException {
    Type[] types = componentType.getSubtypes();
    String[] propertyNames = componentType.getPropertyNames();
    for (int i = 0; i < types.length; i++) {
        if (types[i].isAssociationType()) {
            AssociationType associationType = (AssociationType) types[i];
            String[] aliasedLhsColumns = JoinHelper.getAliasedLHSColumnNames(associationType, alias, propertyNumber, begin, persister, getFactory());
            String[] lhsColumns = JoinHelper.getLHSColumnNames(associationType, propertyNumber, begin, persister, getFactory());
            String lhsTable = JoinHelper.getLHSTableName(associationType, propertyNumber, persister);
            final PropertyPath subPath = path.append(propertyNames[i]);
            final boolean[] propertyNullability = componentType.getPropertyNullability();
            final JoinType joinType = getJoinType(persister, subPath, propertyNumber, associationType, componentType.getFetchMode(i), componentType.getCascadeStyle(i), lhsTable, lhsColumns, propertyNullability == null || propertyNullability[i], currentDepth);
            addAssociationToJoinTreeIfNecessary(associationType, aliasedLhsColumns, alias, subPath, currentDepth, joinType);
        } else if (types[i].isComponentType()) {
            final PropertyPath subPath = path.append(propertyNames[i]);
            walkComponentTree((CompositeType) types[i], propertyNumber, begin, persister, alias, subPath, currentDepth);
        }
        begin += types[i].getColumnSpan(getFactory());
    }
}
Also used : EntityType(org.hibernate.type.EntityType) CompositeType(org.hibernate.type.CompositeType) JoinType(org.hibernate.sql.JoinType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) AssociationType(org.hibernate.type.AssociationType) JoinType(org.hibernate.sql.JoinType) CompositeType(org.hibernate.type.CompositeType)

Example 8 with CompositeType

use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.

the class AbstractCollectionReference method buildElementGraph.

private CollectionFetchableElement buildElementGraph() {
    final CollectionPersister persister = collectionQuerySpace.getCollectionPersister();
    final Type type = persister.getElementType();
    if (type.isAssociationType()) {
        if (type.isEntityType()) {
            final EntityPersister elementPersister = persister.getFactory().getEntityPersister(((EntityType) type).getAssociatedEntityName());
            final ExpandingEntityQuerySpace entityQuerySpace = QuerySpaceHelper.INSTANCE.makeEntityQuerySpace(collectionQuerySpace, elementPersister, CollectionPropertyNames.COLLECTION_ELEMENTS, (EntityType) persister.getElementType(), collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(), collectionQuerySpace.canJoinsBeRequired(), allowElementJoin);
            return new CollectionFetchableElementEntityGraph(this, entityQuerySpace);
        } else if (type.isAnyType()) {
            return new CollectionFetchableElementAnyGraph(this);
        }
    } else if (type.isComponentType()) {
        final ExpandingCompositeQuerySpace compositeQuerySpace = QuerySpaceHelper.INSTANCE.makeCompositeQuerySpace(collectionQuerySpace, new CompositePropertyMapping((CompositeType) persister.getElementType(), (PropertyMapping) persister, ""), CollectionPropertyNames.COLLECTION_ELEMENTS, (CompositeType) persister.getElementType(), collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(), collectionQuerySpace.canJoinsBeRequired(), allowElementJoin);
        return new CollectionFetchableElementCompositeGraph(this, compositeQuerySpace);
    }
    return null;
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) ExpandingCompositeQuerySpace(org.hibernate.loader.plan.build.spi.ExpandingCompositeQuerySpace) EntityType(org.hibernate.type.EntityType) CompositeType(org.hibernate.type.CompositeType) Type(org.hibernate.type.Type) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) CompositePropertyMapping(org.hibernate.loader.plan.build.internal.spaces.CompositePropertyMapping) ExpandingEntityQuerySpace(org.hibernate.loader.plan.build.spi.ExpandingEntityQuerySpace) CompositeType(org.hibernate.type.CompositeType)

Example 9 with CompositeType

use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.

the class EntityQuerySpaceImpl method makeCompositeIdentifierQuerySpace.

@Override
public ExpandingCompositeQuerySpace makeCompositeIdentifierQuerySpace() {
    final String compositeQuerySpaceUid = getUid() + "-id";
    final ExpandingCompositeQuerySpace rhs = getExpandingQuerySpaces().makeCompositeQuerySpace(compositeQuerySpaceUid, new CompositePropertyMapping((CompositeType) getEntityPersister().getIdentifierType(), (PropertyMapping) getEntityPersister(), getEntityPersister().getIdentifierPropertyName()), canJoinsBeRequired());
    final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCompositeJoin(this, EntityPersister.ENTITY_ID, rhs, canJoinsBeRequired(), (CompositeType) persister.getIdentifierType());
    internalGetJoins().add(join);
    return rhs;
}
Also used : ExpandingCompositeQuerySpace(org.hibernate.loader.plan.build.spi.ExpandingCompositeQuerySpace) PropertyMapping(org.hibernate.persister.entity.PropertyMapping) JoinDefinedByMetadata(org.hibernate.loader.plan.spi.JoinDefinedByMetadata) CompositeType(org.hibernate.type.CompositeType)

Example 10 with CompositeType

use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.

the class AbstractCollectionPersister method initCollectionPropertyMap.

private void initCollectionPropertyMap(String aliasName, Type type, String[] columnAliases, String[] columnNames) {
    collectionPropertyColumnAliases.put(aliasName, columnAliases);
    collectionPropertyColumnNames.put(aliasName, columnNames);
    if (type.isComponentType()) {
        CompositeType ct = (CompositeType) type;
        String[] propertyNames = ct.getPropertyNames();
        for (int i = 0; i < propertyNames.length; i++) {
            String name = propertyNames[i];
            collectionPropertyColumnAliases.put(aliasName + "." + name, columnAliases[i]);
            collectionPropertyColumnNames.put(aliasName + "." + name, columnNames[i]);
        }
    }
}
Also used : CompositeType(org.hibernate.type.CompositeType)

Aggregations

CompositeType (org.hibernate.type.CompositeType)32 Type (org.hibernate.type.Type)22 AssociationType (org.hibernate.type.AssociationType)12 EntityType (org.hibernate.type.EntityType)11 EntityPersister (org.hibernate.persister.entity.EntityPersister)7 JoinType (org.hibernate.sql.JoinType)6 CollectionType (org.hibernate.type.CollectionType)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 MappingException (org.hibernate.MappingException)3 QueryException (org.hibernate.QueryException)3 ExpandingCompositeQuerySpace (org.hibernate.loader.plan.build.spi.ExpandingCompositeQuerySpace)3 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)3 HashSet (java.util.HashSet)2 HibernateException (org.hibernate.HibernateException)2 TypedValue (org.hibernate.engine.spi.TypedValue)2 CompositePropertyMapping (org.hibernate.loader.plan.build.internal.spaces.CompositePropertyMapping)2 ExpandingEntityQuerySpace (org.hibernate.loader.plan.build.spi.ExpandingEntityQuerySpace)2 AssociationKey (org.hibernate.persister.walking.spi.AssociationKey)2 AttributeDefinition (org.hibernate.persister.walking.spi.AttributeDefinition)2