Search in sources :

Example 1 with JoinType

use of org.hibernate.sql.JoinType 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)

Example 2 with JoinType

use of org.hibernate.sql.JoinType 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 3 with JoinType

use of org.hibernate.sql.JoinType 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 4 with JoinType

use of org.hibernate.sql.JoinType in project hibernate-orm by hibernate.

the class JoinWalker method walkEntityAssociationTree.

/**
	 * Process a particular association owned by the entity
	 *
	 * @param associationType The type representing the association to be
	 * processed.
	 * @param persister The owner of the association to be processed.
	 * @param propertyNumber The property number for the association
	 * (relative to the persister).
	 * @param alias The entity alias
	 * @param path The path to the association
	 * @param nullable is the association nullable (which I think is supposed
	 * to indicate inner/outer join semantics).
	 * @param currentDepth The current join depth
	 *
	 * @throws org.hibernate.MappingException ???
	 */
private void walkEntityAssociationTree(final AssociationType associationType, final OuterJoinLoadable persister, final int propertyNumber, final String alias, final PropertyPath path, final boolean nullable, final int currentDepth) throws MappingException {
    String[] aliasedLhsColumns = JoinHelper.getAliasedLHSColumnNames(associationType, alias, propertyNumber, persister, getFactory());
    String[] lhsColumns = JoinHelper.getLHSColumnNames(associationType, propertyNumber, persister, getFactory());
    String lhsTable = JoinHelper.getLHSTableName(associationType, propertyNumber, persister);
    PropertyPath subPath = path.append(persister.getSubclassPropertyName(propertyNumber));
    JoinType joinType = getJoinType(persister, subPath, propertyNumber, associationType, persister.getFetchMode(propertyNumber), persister.getCascadeStyle(propertyNumber), lhsTable, lhsColumns, nullable, currentDepth);
    addAssociationToJoinTreeIfNecessary(associationType, aliasedLhsColumns, alias, subPath, currentDepth, joinType);
}
Also used : JoinType(org.hibernate.sql.JoinType)

Example 5 with JoinType

use of org.hibernate.sql.JoinType in project hibernate-orm by hibernate.

the class CriteriaJoinWalker method getJoinType.

@Override
protected JoinType getJoinType(OuterJoinLoadable persister, final PropertyPath path, int propertyNumber, AssociationType associationType, FetchMode metadataFetchMode, CascadeStyle metadataCascadeStyle, String lhsTable, String[] lhsColumns, final boolean nullable, final int currentDepth) throws MappingException {
    final JoinType resolvedJoinType;
    if (translator.isJoin(path.getFullPath())) {
        resolvedJoinType = translator.getJoinType(path.getFullPath());
    } else {
        if (translator.hasProjection()) {
            resolvedJoinType = JoinType.NONE;
        } else {
            FetchMode fetchMode = translator.getRootCriteria().getFetchMode(path.getFullPath());
            if (isDefaultFetchMode(fetchMode)) {
                if (persister != null) {
                    if (isJoinFetchEnabledByProfile(persister, path, propertyNumber)) {
                        if (isDuplicateAssociation(lhsTable, lhsColumns, associationType)) {
                            resolvedJoinType = JoinType.NONE;
                        } else if (isTooDeep(currentDepth) || (associationType.isCollectionType() && isTooManyCollections())) {
                            resolvedJoinType = JoinType.NONE;
                        } else {
                            resolvedJoinType = getJoinType(nullable, currentDepth);
                        }
                    } else {
                        resolvedJoinType = super.getJoinType(persister, path, propertyNumber, associationType, metadataFetchMode, metadataCascadeStyle, lhsTable, lhsColumns, nullable, currentDepth);
                    }
                } else {
                    resolvedJoinType = super.getJoinType(associationType, metadataFetchMode, path, lhsTable, lhsColumns, nullable, currentDepth, metadataCascadeStyle);
                }
            } else {
                if (fetchMode == FetchMode.JOIN) {
                    isDuplicateAssociation(lhsTable, lhsColumns, associationType);
                    //deliberately ignore return value!
                    resolvedJoinType = getJoinType(nullable, currentDepth);
                } else {
                    resolvedJoinType = JoinType.NONE;
                }
            }
        }
    }
    return resolvedJoinType;
}
Also used : FetchMode(org.hibernate.FetchMode) JoinType(org.hibernate.sql.JoinType)

Aggregations

JoinType (org.hibernate.sql.JoinType)11 CompositeType (org.hibernate.type.CompositeType)6 AssociationType (org.hibernate.type.AssociationType)5 EntityType (org.hibernate.type.EntityType)5 Type (org.hibernate.type.Type)5 CollectionType (org.hibernate.type.CollectionType)3 SemanticException (antlr.SemanticException)2 QueryException (org.hibernate.QueryException)2 JoinSequence (org.hibernate.engine.internal.JoinSequence)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 FetchMode (org.hibernate.FetchMode)1 DotNode (org.hibernate.hql.internal.ast.tree.DotNode)1 EntityJoinFromElement (org.hibernate.hql.internal.ast.tree.EntityJoinFromElement)1 FromElement (org.hibernate.hql.internal.ast.tree.FromElement)1 FromElementFactory (org.hibernate.hql.internal.ast.tree.FromElementFactory)1 FromReferenceNode (org.hibernate.hql.internal.ast.tree.FromReferenceNode)1 SessionFactoryHelper (org.hibernate.hql.internal.ast.util.SessionFactoryHelper)1 CriteriaImpl (org.hibernate.internal.CriteriaImpl)1 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)1 JoinFragment (org.hibernate.sql.JoinFragment)1