Search in sources :

Example 16 with CompositeType

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

the class JoinWalker method walkEntityTree.

/**
	 * Walk the association tree for an entity, adding associations which should
	 * be join fetched to the {@link #associations} inst var.  This form is the
	 * entry point into the walking for a given entity, starting the recursive
	 * calls into {@link #walkEntityTree(org.hibernate.persister.entity.OuterJoinLoadable, String, PropertyPath, int)}.
	 *
	 * @param persister The persister representing the entity to be walked.
	 * @param alias The (root) alias to use for this entity/persister.
	 * @param path The property path to the entity being walked
	 * @param currentDepth The current join depth
	 *
	 * @throws org.hibernate.MappingException ???
	 */
private void walkEntityTree(final OuterJoinLoadable persister, final String alias, final PropertyPath path, final int currentDepth) throws MappingException {
    int n = persister.countSubclassProperties();
    for (int i = 0; i < n; i++) {
        Type type = persister.getSubclassPropertyType(i);
        if (type.isAssociationType()) {
            walkEntityAssociationTree((AssociationType) type, persister, i, alias, path, persister.isSubclassPropertyNullable(i), currentDepth);
        } else if (type.isComponentType()) {
            walkComponentTree((CompositeType) type, i, 0, persister, alias, path.append(persister.getSubclassPropertyName(i)), currentDepth);
        }
    }
    // if the entity has a composite identifier, see if we need to handle
    // its sub-properties separately
    final Type idType = persister.getIdentifierType();
    if (idType.isComponentType()) {
        final CompositeType cidType = (CompositeType) idType;
        if (cidType.isEmbedded()) {
            // explicitly at odds with the notion of "embedded composite".  So we use that for now
            if (persister.getEntityMetamodel().getIdentifierProperty().isEmbedded()) {
                walkComponentTree(cidType, -1, 0, persister, alias, path, currentDepth);
            }
        }
    }
}
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) CompositeType(org.hibernate.type.CompositeType)

Example 17 with CompositeType

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

the class HibernateTraversableResolver method addAssociationsToTheSetForOneProperty.

private void addAssociationsToTheSetForOneProperty(String name, Type type, String prefix, SessionFactoryImplementor factory) {
    if (type.isCollectionType()) {
        CollectionType collType = (CollectionType) type;
        Type assocType = collType.getElementType(factory);
        addAssociationsToTheSetForOneProperty(name, assocType, prefix, factory);
    } else //ToOne association
    if (type.isEntityType() || type.isAnyType()) {
        associations.add(prefix + name);
    } else if (type.isComponentType()) {
        CompositeType componentType = (CompositeType) type;
        addAssociationsToTheSetForAllProperties(componentType.getPropertyNames(), componentType.getSubtypes(), (prefix.equals("") ? name : prefix + name) + ".", factory);
    }
}
Also used : CollectionType(org.hibernate.type.CollectionType) ElementType(java.lang.annotation.ElementType) CompositeType(org.hibernate.type.CompositeType) Type(org.hibernate.type.Type) CollectionType(org.hibernate.type.CollectionType) CompositeType(org.hibernate.type.CompositeType)

Example 18 with CompositeType

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

the class InExpression method getTypedValues.

@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
    final ArrayList<TypedValue> list = new ArrayList<TypedValue>();
    final Type type = criteriaQuery.getTypeUsingProjection(criteria, propertyName);
    if (type.isComponentType()) {
        final CompositeType compositeType = (CompositeType) type;
        final Type[] subTypes = compositeType.getSubtypes();
        for (Object value : values) {
            for (int i = 0; i < subTypes.length; i++) {
                final Object subValue = value == null ? null : compositeType.getPropertyValues(value, EntityMode.POJO)[i];
                list.add(new TypedValue(subTypes[i], subValue));
            }
        }
    } else {
        for (Object value : values) {
            list.add(criteriaQuery.getTypedValue(criteria, propertyName, value));
        }
    }
    return list.toArray(new TypedValue[list.size()]);
}
Also used : CompositeType(org.hibernate.type.CompositeType) Type(org.hibernate.type.Type) ArrayList(java.util.ArrayList) TypedValue(org.hibernate.engine.spi.TypedValue) CompositeType(org.hibernate.type.CompositeType)

Example 19 with CompositeType

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

the class IdsClauseBuilder method quoteIdentifier.

protected String quoteIdentifier(Object... value) {
    if (value.length == 1) {
        return quoteIdentifier(value[0], identifierType);
    } else {
        if (identifierType instanceof CompositeType) {
            CompositeType compositeType = (CompositeType) identifierType;
            List<String> quotedIdentifiers = new ArrayList<>();
            for (int i = 0; i < value.length; i++) {
                quotedIdentifiers.add(quoteIdentifier(value[i], compositeType.getSubtypes()[i]));
            }
            return String.join(",", quotedIdentifiers);
        } else {
            throw new IllegalArgumentException("Composite identifier does not implement CompositeType");
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CompositeType(org.hibernate.type.CompositeType)

Example 20 with CompositeType

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

the class AbstractEntityPersister method initSubclassPropertyAliasesMap.

//This is really ugly, but necessary:
/**
	 * Must be called by subclasses, at the end of their constructors
	 */
protected void initSubclassPropertyAliasesMap(PersistentClass model) throws MappingException {
    // ALIASES
    internalInitSubclassPropertyAliasesMap(null, model.getSubclassPropertyClosureIterator());
    // aliases for identifier ( alias.id ); skip if the entity defines a non-id property named 'id'
    if (!entityMetamodel.hasNonIdentifierPropertyNamedId()) {
        subclassPropertyAliases.put(ENTITY_ID, getIdentifierAliases());
        subclassPropertyColumnNames.put(ENTITY_ID, getIdentifierColumnNames());
    }
    // aliases named identifier ( alias.idname )
    if (hasIdentifierProperty()) {
        subclassPropertyAliases.put(getIdentifierPropertyName(), getIdentifierAliases());
        subclassPropertyColumnNames.put(getIdentifierPropertyName(), getIdentifierColumnNames());
    }
    // aliases for composite-id's
    if (getIdentifierType().isComponentType()) {
        // Fetch embedded identifiers propertynames from the "virtual" identifier component
        CompositeType componentId = (CompositeType) getIdentifierType();
        String[] idPropertyNames = componentId.getPropertyNames();
        String[] idAliases = getIdentifierAliases();
        String[] idColumnNames = getIdentifierColumnNames();
        for (int i = 0; i < idPropertyNames.length; i++) {
            if (entityMetamodel.hasNonIdentifierPropertyNamedId()) {
                subclassPropertyAliases.put(ENTITY_ID + "." + idPropertyNames[i], new String[] { idAliases[i] });
                subclassPropertyColumnNames.put(ENTITY_ID + "." + getIdentifierPropertyName() + "." + idPropertyNames[i], new String[] { idColumnNames[i] });
            }
            //				if (hasIdentifierProperty() && !ENTITY_ID.equals( getIdentifierPropertyName() ) ) {
            if (hasIdentifierProperty()) {
                subclassPropertyAliases.put(getIdentifierPropertyName() + "." + idPropertyNames[i], new String[] { idAliases[i] });
                subclassPropertyColumnNames.put(getIdentifierPropertyName() + "." + idPropertyNames[i], new String[] { idColumnNames[i] });
            } else {
                // embedded composite ids ( alias.idname1, alias.idname2 )
                subclassPropertyAliases.put(idPropertyNames[i], new String[] { idAliases[i] });
                subclassPropertyColumnNames.put(idPropertyNames[i], new String[] { idColumnNames[i] });
            }
        }
    }
    if (entityMetamodel.isPolymorphic()) {
        subclassPropertyAliases.put(ENTITY_CLASS, new String[] { getDiscriminatorAlias() });
        subclassPropertyColumnNames.put(ENTITY_CLASS, new String[] { getDiscriminatorColumnName() });
    }
}
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