Search in sources :

Example 26 with EntityType

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

the class QueryLoader method initialize.

private void initialize(SelectClause selectClause) {
    List fromElementList = selectClause.getFromElementsForLoad();
    hasScalars = selectClause.isScalarSelect();
    scalarColumnNames = selectClause.getColumnNames();
    //sqlResultTypes = selectClause.getSqlResultTypes();
    queryReturnTypes = selectClause.getQueryReturnTypes();
    aggregatedSelectExpression = selectClause.getAggregatedSelectExpression();
    queryReturnAliases = selectClause.getQueryReturnAliases();
    List collectionFromElements = selectClause.getCollectionFromElements();
    if (collectionFromElements != null && collectionFromElements.size() != 0) {
        int length = collectionFromElements.size();
        collectionPersisters = new QueryableCollection[length];
        collectionOwners = new int[length];
        collectionSuffixes = new String[length];
        for (int i = 0; i < length; i++) {
            FromElement collectionFromElement = (FromElement) collectionFromElements.get(i);
            collectionPersisters[i] = collectionFromElement.getQueryableCollection();
            collectionOwners[i] = fromElementList.indexOf(collectionFromElement.getOrigin());
            //				collectionSuffixes[i] = collectionFromElement.getColumnAliasSuffix();
            //				collectionSuffixes[i] = Integer.toString( i ) + "_";
            collectionSuffixes[i] = collectionFromElement.getCollectionSuffix();
        }
    }
    int size = fromElementList.size();
    entityPersisters = new Queryable[size];
    entityEagerPropertyFetches = new boolean[size];
    entityAliases = new String[size];
    sqlAliases = new String[size];
    sqlAliasSuffixes = new String[size];
    includeInSelect = new boolean[size];
    owners = new int[size];
    ownerAssociationTypes = new EntityType[size];
    for (int i = 0; i < size; i++) {
        final FromElement element = (FromElement) fromElementList.get(i);
        entityPersisters[i] = (Queryable) element.getEntityPersister();
        if (entityPersisters[i] == null) {
            throw new IllegalStateException("No entity persister for " + element.toString());
        }
        entityEagerPropertyFetches[i] = element.isAllPropertyFetch();
        sqlAliases[i] = element.getTableAlias();
        entityAliases[i] = element.getClassAlias();
        sqlAliasByEntityAlias.put(entityAliases[i], sqlAliases[i]);
        // TODO should we just collect these like with the collections above?
        sqlAliasSuffixes[i] = (size == 1) ? "" : Integer.toString(i) + "_";
        //			sqlAliasSuffixes[i] = element.getColumnAliasSuffix();
        includeInSelect[i] = !element.isFetch();
        if (includeInSelect[i]) {
            selectLength++;
        }
        //by default
        owners[i] = -1;
        if (element.isFetch()) {
            //noinspection StatementWithEmptyBody
            if (element.isCollectionJoin() || element.getQueryableCollection() != null) {
            // This is now handled earlier in this method.
            } else if (element.getDataType().isEntityType()) {
                EntityType entityType = (EntityType) element.getDataType();
                if (entityType.isOneToOne()) {
                    owners[i] = fromElementList.indexOf(element.getOrigin());
                }
                ownerAssociationTypes[i] = entityType;
            }
        }
    }
    //NONE, because its the requested lock mode, not the actual! 
    defaultLockModes = ArrayHelper.fillArray(LockMode.NONE, size);
}
Also used : EntityType(org.hibernate.type.EntityType) FromElement(org.hibernate.hql.internal.ast.tree.FromElement) List(java.util.List)

Example 27 with EntityType

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

the class ForeignKeys method collectNonNullableTransientEntities.

private static void collectNonNullableTransientEntities(Nullifier nullifier, Object value, String propertyName, Type type, boolean isNullable, SharedSessionContractImplementor session, NonNullableTransientDependencies nonNullableTransientEntities) {
    if (value == null) {
        return;
    }
    if (type.isEntityType()) {
        final EntityType entityType = (EntityType) type;
        if (!isNullable && !entityType.isOneToOne() && nullifier.isNullifiable(entityType.getAssociatedEntityName(), value)) {
            nonNullableTransientEntities.add(propertyName, value);
        }
    } else if (type.isAnyType()) {
        if (!isNullable && nullifier.isNullifiable(null, value)) {
            nonNullableTransientEntities.add(propertyName, value);
        }
    } else if (type.isComponentType()) {
        final CompositeType actype = (CompositeType) type;
        final boolean[] subValueNullability = actype.getPropertyNullability();
        if (subValueNullability != null) {
            final String[] subPropertyNames = actype.getPropertyNames();
            final Object[] subvalues = actype.getPropertyValues(value, session);
            final Type[] subtypes = actype.getSubtypes();
            for (int j = 0; j < subvalues.length; j++) {
                collectNonNullableTransientEntities(nullifier, subvalues[j], subPropertyNames[j], subtypes[j], subValueNullability[j], session, nonNullableTransientEntities);
            }
        }
    }
}
Also used : EntityType(org.hibernate.type.EntityType) EntityType(org.hibernate.type.EntityType) CompositeType(org.hibernate.type.CompositeType) Type(org.hibernate.type.Type) CompositeType(org.hibernate.type.CompositeType)

Example 28 with EntityType

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

the class AbstractPropertyMapping method initPropertyPaths.

/*protected void initPropertyPaths(
			final String path,
			final Type type,
			final String[] columns,
			final String[] formulaTemplates,
			final Mapping factory)
	throws MappingException {
		//addFormulaPropertyPath(path, type, formulaTemplates);
		initPropertyPaths(path, type, columns, formulaTemplates, factory);
	}*/
protected void initPropertyPaths(final String path, final Type type, String[] columns, String[] columnReaders, String[] columnReaderTemplates, final String[] formulaTemplates, final Mapping factory) throws MappingException {
    assert columns != null : "Incoming columns should not be null : " + path;
    assert type != null : "Incoming type should not be null : " + path;
    if (columns.length != type.getColumnSpan(factory)) {
        throw new MappingException("broken column mapping for: " + path + " of: " + getEntityName());
    }
    if (type.isAssociationType()) {
        AssociationType actype = (AssociationType) type;
        if (actype.useLHSPrimaryKey()) {
            columns = getIdentifierColumnNames();
            columnReaders = getIdentifierColumnReaders();
            columnReaderTemplates = getIdentifierColumnReaderTemplates();
        } else {
            String foreignKeyProperty = actype.getLHSPropertyName();
            if (foreignKeyProperty != null && !path.equals(foreignKeyProperty)) {
                //TODO: this requires that the collection is defined afterQuery the
                //      referenced property in the mapping file (ok?)
                columns = columnsByPropertyPath.get(foreignKeyProperty);
                if (columns == null) {
                    //get em on the second pass!
                    return;
                }
                columnReaders = columnReadersByPropertyPath.get(foreignKeyProperty);
                columnReaderTemplates = columnReaderTemplatesByPropertyPath.get(foreignKeyProperty);
            }
        }
    }
    if (path != null) {
        addPropertyPath(path, type, columns, columnReaders, columnReaderTemplates, formulaTemplates);
    }
    if (type.isComponentType()) {
        CompositeType actype = (CompositeType) type;
        initComponentPropertyPaths(path, actype, columns, columnReaders, columnReaderTemplates, formulaTemplates, factory);
        if (actype.isEmbedded()) {
            initComponentPropertyPaths(path == null ? null : StringHelper.qualifier(path), actype, columns, columnReaders, columnReaderTemplates, formulaTemplates, factory);
        }
    } else if (type.isEntityType()) {
        initIdentifierPropertyPaths(path, (EntityType) type, columns, columnReaders, columnReaderTemplates, factory);
    }
}
Also used : EntityType(org.hibernate.type.EntityType) AssociationType(org.hibernate.type.AssociationType) MappingException(org.hibernate.MappingException) CompositeType(org.hibernate.type.CompositeType)

Aggregations

EntityType (org.hibernate.type.EntityType)28 Type (org.hibernate.type.Type)18 EntityPersister (org.hibernate.persister.entity.EntityPersister)9 JoinSequence (org.hibernate.engine.internal.JoinSequence)6 JoinType (org.hibernate.sql.JoinType)6 CompositeType (org.hibernate.type.CompositeType)6 AssociationType (org.hibernate.type.AssociationType)5 CollectionType (org.hibernate.type.CollectionType)5 QueryException (org.hibernate.QueryException)4 Queryable (org.hibernate.persister.entity.Queryable)4 MappingException (org.hibernate.MappingException)3 EntityKey (org.hibernate.engine.spi.EntityKey)3 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)3 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)3 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 HibernateException (org.hibernate.HibernateException)2 Session (org.hibernate.Session)2