Search in sources :

Example 1 with CollectionType

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

the class AuditMetadataGenerator method addValueInSecondPass.

private void addValueInSecondPass(Element parent, Value value, CompositeMapperBuilder currentMapper, String entityName, EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData, boolean insertable, boolean processModifiedFlag) {
    final Type type = value.getType();
    if (type instanceof ComponentType) {
        componentMetadataGenerator.addComponent(parent, propertyAuditingData, value, currentMapper, entityName, xmlMappingData, false);
        // mod flag field has been already generated in first pass
        return;
    } else if (type instanceof ManyToOneType) {
        toOneRelationMetadataGenerator.addToOne(parent, propertyAuditingData, value, currentMapper, entityName, insertable);
    } else if (type instanceof OneToOneType) {
        final OneToOne oneToOne = (OneToOne) value;
        if (oneToOne.getReferencedPropertyName() != null) {
            toOneRelationMetadataGenerator.addOneToOneNotOwning(propertyAuditingData, value, currentMapper, entityName);
        } else {
            // @OneToOne relation marked with @PrimaryKeyJoinColumn
            toOneRelationMetadataGenerator.addOneToOnePrimaryKeyJoinColumn(propertyAuditingData, value, currentMapper, entityName, insertable);
        }
    } else if (type instanceof CollectionType) {
        final CollectionMetadataGenerator collectionMetadataGenerator = new CollectionMetadataGenerator(this, (Collection) value, currentMapper, entityName, xmlMappingData, propertyAuditingData);
        collectionMetadataGenerator.addCollection();
    } else {
        return;
    }
    addModifiedFlagIfNeeded(parent, propertyAuditingData, processModifiedFlag);
}
Also used : CollectionType(org.hibernate.type.CollectionType) ManyToOneType(org.hibernate.type.ManyToOneType) ComponentType(org.hibernate.type.ComponentType) OneToOneType(org.hibernate.type.OneToOneType) TimestampType(org.hibernate.type.TimestampType) Type(org.hibernate.type.Type) ComponentType(org.hibernate.type.ComponentType) OneToOne(org.hibernate.mapping.OneToOne) ManyToOneType(org.hibernate.type.ManyToOneType) CollectionType(org.hibernate.type.CollectionType) Collection(org.hibernate.mapping.Collection) OneToOneType(org.hibernate.type.OneToOneType)

Example 2 with CollectionType

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

the class AbstractEmptinessExpression method getQueryableCollection.

protected QueryableCollection getQueryableCollection(String entityName, String propertyName, SessionFactoryImplementor factory) throws HibernateException {
    final PropertyMapping ownerMapping = (PropertyMapping) factory.getEntityPersister(entityName);
    final Type type = ownerMapping.toType(propertyName);
    if (!type.isCollectionType()) {
        throw new MappingException("Property path [" + entityName + "." + propertyName + "] does not reference a collection");
    }
    final String role = ((CollectionType) type).getRole();
    try {
        return (QueryableCollection) factory.getCollectionPersister(role);
    } catch (ClassCastException cce) {
        throw new QueryException("collection role is not queryable: " + role);
    } catch (Exception e) {
        throw new QueryException("collection role not found: " + role);
    }
}
Also used : CollectionType(org.hibernate.type.CollectionType) Type(org.hibernate.type.Type) QueryException(org.hibernate.QueryException) CollectionType(org.hibernate.type.CollectionType) PropertyMapping(org.hibernate.persister.entity.PropertyMapping) QueryableCollection(org.hibernate.persister.collection.QueryableCollection) MappingException(org.hibernate.MappingException) HibernateException(org.hibernate.HibernateException) QueryException(org.hibernate.QueryException) MappingException(org.hibernate.MappingException)

Example 3 with CollectionType

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

the class Nullability method checkSubElementsNullability.

/**
	 * check sub elements-nullability. Returns property path that break
	 * nullability or null if none
	 *
	 * @param propertyType type to check
	 * @param value value to check
	 *
	 * @return property path
	 * @throws HibernateException error while getting subcomponent values
	 */
private String checkSubElementsNullability(Type propertyType, Object value) throws HibernateException {
    if (propertyType.isComponentType()) {
        return checkComponentNullability(value, (CompositeType) propertyType);
    }
    if (propertyType.isCollectionType()) {
        // persistent collections may have components
        final CollectionType collectionType = (CollectionType) propertyType;
        final Type collectionElementType = collectionType.getElementType(session.getFactory());
        if (collectionElementType.isComponentType()) {
            // check for all components values in the collection
            final CompositeType componentType = (CompositeType) collectionElementType;
            final Iterator itr = CascadingActions.getLoadedElementsIterator(session, collectionType, value);
            while (itr.hasNext()) {
                final Object compositeElement = itr.next();
                if (compositeElement != null) {
                    return checkComponentNullability(compositeElement, componentType);
                }
            }
        }
    }
    return null;
}
Also used : CompositeType(org.hibernate.type.CompositeType) CollectionType(org.hibernate.type.CollectionType) Type(org.hibernate.type.Type) CollectionType(org.hibernate.type.CollectionType) Iterator(java.util.Iterator) CompositeType(org.hibernate.type.CompositeType)

Example 4 with CollectionType

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

the class Cascade method cascadeCollection.

/**
	 * Cascade an action to a collection
	 */
private static void cascadeCollection(final CascadingAction action, final CascadePoint cascadePoint, final EventSource eventSource, final int componentPathStackDepth, final Object parent, final Object child, final CascadeStyle style, final Object anything, final CollectionType type) {
    final CollectionPersister persister = eventSource.getFactory().getCollectionPersister(type.getRole());
    final Type elemType = persister.getElementType();
    CascadePoint elementsCascadePoint = cascadePoint;
    if (cascadePoint == CascadePoint.AFTER_INSERT_BEFORE_DELETE) {
        elementsCascadePoint = CascadePoint.AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION;
    }
    //cascade to current collection elements
    if (elemType.isEntityType() || elemType.isAnyType() || elemType.isComponentType()) {
        cascadeCollectionElements(action, elementsCascadePoint, eventSource, componentPathStackDepth, parent, child, type, style, elemType, anything, persister.isCascadeDeleteEnabled());
    }
}
Also used : CollectionType(org.hibernate.type.CollectionType) EntityType(org.hibernate.type.EntityType) CompositeType(org.hibernate.type.CompositeType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) CollectionPersister(org.hibernate.persister.collection.CollectionPersister)

Example 5 with CollectionType

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

the class IdentNode method resolveIndex.

public void resolveIndex(AST parent) throws SemanticException {
    //      currently un-needed overhead.
    if (!(isResolved() && nakedPropertyRef)) {
        throw new UnsupportedOperationException();
    }
    String propertyName = getOriginalText();
    if (!getDataType().isCollectionType()) {
        throw new SemanticException("Collection expected; [" + propertyName + "] does not refer to a collection property");
    }
    // TODO : most of below was taken verbatim from DotNode; should either delegate this logic or super-type it
    CollectionType type = (CollectionType) getDataType();
    String role = type.getRole();
    QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection(role);
    // DotNode uses null here...
    String alias = null;
    String columnTableAlias = getFromElement().getTableAlias();
    JoinType joinType = JoinType.INNER_JOIN;
    boolean fetch = false;
    FromElementFactory factory = new FromElementFactory(getWalker().getCurrentFromClause(), getFromElement(), propertyName, alias, getFromElement().toColumns(columnTableAlias, propertyName, false), true);
    FromElement elem = factory.createCollection(queryableCollection, role, joinType, fetch, true);
    setFromElement(elem);
    // Always add the collection's query spaces.
    getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces());
}
Also used : CollectionType(org.hibernate.type.CollectionType) QueryableCollection(org.hibernate.persister.collection.QueryableCollection) JoinType(org.hibernate.sql.JoinType) SemanticException(antlr.SemanticException)

Aggregations

CollectionType (org.hibernate.type.CollectionType)26 Type (org.hibernate.type.Type)21 JoinType (org.hibernate.sql.JoinType)10 EntityType (org.hibernate.type.EntityType)10 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)7 AssociationType (org.hibernate.type.AssociationType)7 CompositeType (org.hibernate.type.CompositeType)7 QueryException (org.hibernate.QueryException)5 JoinSequence (org.hibernate.engine.internal.JoinSequence)5 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)5 HibernateException (org.hibernate.HibernateException)3 ComponentType (org.hibernate.type.ComponentType)3 SemanticException (antlr.SemanticException)2 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 MappingException (org.hibernate.MappingException)2 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 SessionFactoryHelper (org.hibernate.hql.internal.ast.util.SessionFactoryHelper)2 ClassMetadata (org.hibernate.metadata.ClassMetadata)2