OuterJoinableAssociation assoc = new OuterJoinableAssociation( path, type, loadQueryInfluencers.getEnabledFilters() ); assoc.validateJoin( path.getFullPath() ); associations.add( assoc );
/** * Generate a sequence of <tt>LEFT OUTER JOIN</tt> clauses for the given associations. */ protected final JoinFragment mergeOuterJoins(List associations) throws MappingException { JoinFragment outerjoin = getDialect().createOuterJoinFragment(); Iterator iter = associations.iterator(); OuterJoinableAssociation last = null; while ( iter.hasNext() ) { final OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next(); if ( last != null && last.isManyToManyWith( oj ) ) { oj.addManyToManyJoin( outerjoin, (QueryableCollection) last.getJoinable() ); } else { oj.addJoins( outerjoin ); } last = oj; } last = null; return outerjoin; }
for ( Object association : associations ) { final OuterJoinableAssociation oj = (OuterJoinableAssociation) association; if ( !oj.isCollection() ) { persisters[i] = (Loadable) oj.getJoinable(); aliases[i] = oj.getRHSAlias(); owners[i] = oj.getOwner( associations ); ownerAssociationTypes[i] = (EntityType) oj.getJoinableType(); callback.associationProcessed( oj, i ); i++; QueryableCollection collPersister = (QueryableCollection) oj.getJoinable(); if ( oj.getJoinType() == JoinType.LEFT_OUTER_JOIN && !oj.hasRestriction() ) { collectionOwners[j] = oj.getOwner( associations ); j++; aliases[i] = oj.getRHSAlias(); callback.associationProcessed( oj, i ); i++;
public int getOwner(final List associations) { if ( isOneToOne() || isCollection() ) { return getPosition( lhsAlias, associations ); } else { return -1; } }
/** * Count the number of instances of Joinable which are actually * also instances of PersistentCollection which are being fetched * by outer join */ protected static int countCollectionPersisters(List associations) throws MappingException { int result = 0; for ( Object association : associations ) { final OuterJoinableAssociation oj = (OuterJoinableAssociation) association; if ( oj.getJoinType() == JoinType.LEFT_OUTER_JOIN && oj.getJoinable().isCollection() && !oj.hasRestriction() ) { result++; } } return result; }
private Integer locateKeyManyToOneTargetIndex(OuterJoinableAssociation joinWithCompositeId, EntityType keyManyToOneType) { // the lhs (if one) is a likely candidate if ( joinWithCompositeId.getLhsAlias() != null ) { final OuterJoinableAssociation lhs = associationsByAlias.get( joinWithCompositeId.getLhsAlias() ); if ( keyManyToOneType.getAssociatedEntityName( factory ).equals( lhs.getJoinableType().getAssociatedEntityName( factory ) ) ) { return positionsByAlias.get( lhs.getRhsAlias() ); } } // otherwise, seek out OuterJoinableAssociation which are RHS of given OuterJoinableAssociation // (joinWithCompositeId) for ( OuterJoinableAssociation oja : associationsByAlias.values() ) { if ( oja.getLhsAlias() != null && oja.getLhsAlias().equals( joinWithCompositeId.getRhsAlias() ) ) { if ( keyManyToOneType.equals( oja.getJoinableType() ) ) { return positionsByAlias.get( oja.getLhsAlias() ); } } } return null; } }
while ( iter.hasNext() ) { OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next(); if ( oj.getJoinType() == JoinType.LEFT_OUTER_JOIN ) { // why does this matter? if ( oj.getJoinable().isCollection() ) { final QueryableCollection queryableCollection = (QueryableCollection) oj.getJoinable(); if ( queryableCollection.hasOrdering() ) { final String orderByString = queryableCollection.getSQLOrderByString( oj.getRHSAlias() ); buf.append( orderByString ).append( ", " ); if ( last != null && last.getJoinable().isCollection() ) { final QueryableCollection queryableCollection = (QueryableCollection) last.getJoinable(); if ( queryableCollection.isManyToMany() && last.isManyToManyWith( oj ) ) { if ( queryableCollection.hasManyToManyOrdering() ) { final String orderByString = queryableCollection.getManyToManyOrderByString( oj.getRHSAlias() ); buf.append( orderByString ).append( ", " );
/** * Get the order by string required for collection fetching */ protected static final String orderBy(List associations) throws MappingException { StringBuffer buf = new StringBuffer(); Iterator iter = associations.iterator(); while ( iter.hasNext() ) { OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next(); if ( oj.getJoinType()==JoinFragment.LEFT_OUTER_JOIN && oj.getJoinable().isCollection() ) { final QueryableCollection queryableCollection = (QueryableCollection) oj.getJoinable(); if ( queryableCollection.hasOrdering() ) { final String orderByString = queryableCollection.getSQLOrderByString( oj.getRHSAlias() ); buf.append( orderByString ).append(", "); } } } if ( buf.length()>0 ) buf.setLength( buf.length()-2 ); return buf.toString(); }
? null : (OuterJoinableAssociation) associations.get( i + 1 ); final Joinable joinable = join.getJoinable(); final String entitySuffix = ( suffixes == null || entityAliasCount >= suffixes.length ) ? null : collectionSuffixes[collectionAliasCount]; final String selectFragment = joinable.selectFragment( next == null ? null : next.getJoinable(), next == null ? null : next.getRHSAlias(), join.getRHSAlias(), entitySuffix, collectionSuffix, join.getJoinType() == JoinType.LEFT_OUTER_JOIN ); if ( selectFragment.trim().length() > 0 ) { join.getJoinType() == JoinType.LEFT_OUTER_JOIN && !join.hasRestriction() ) { collectionAliasCount++;
public void associationProcessed(OuterJoinableAssociation oja, int position) { associationsByAlias.put( oja.getRhsAlias(), oja ); positionsByAlias.put( oja.getRhsAlias(), position ); EntityPersister entityPersister = null; if ( oja.getJoinableType().isCollectionType() ) { entityPersister = ( ( QueryableCollection) oja.getJoinable() ).getElementPersister(); } else if ( oja.getJoinableType().isEntityType() ) { entityPersister = ( EntityPersister ) oja.getJoinable(); } if ( entityPersister != null && entityPersister.getIdentifierType().isComponentType() && ! entityPersister.getEntityMetamodel().getIdentifierProperty().isEmbedded() && hasAssociation( (CompositeType) entityPersister.getIdentifierType() ) ) { aliasesForAssociationsWithCompositesIds.add( oja.getRhsAlias() ); } }
while ( itr.hasNext() ) { OuterJoinableAssociation oja = ( OuterJoinableAssociation ) itr.next(); if ( oja.getJoinableType() == associationType ) { oja.getRHSAlias(), getLoadQueryInfluencers().getEnabledFilters() ); manyToManyOrderBy += collectionPersister.getManyToManyOrderByString( oja.getRHSAlias() );
if ( joinWithCompositeId.getJoinableType().isCollectionType() ) { entityPersister = ( ( QueryableCollection) joinWithCompositeId.getJoinable() ).getElementPersister(); else if ( joinWithCompositeId.getJoinableType().isEntityType() ) { entityPersister = ( EntityPersister ) joinWithCompositeId.getJoinable();
/** * Count the number of instances of Joinable which are actually * also instances of Loadable, or are one-to-many associations */ protected static int countEntityPersisters(List associations) throws MappingException { int result = 0; for ( Object association : associations ) { final OuterJoinableAssociation oj = (OuterJoinableAssociation) association; if ( oj.getJoinable().consumesEntityAlias() ) { result++; } } return result; }
public static OuterJoinableAssociation createRoot( AssociationType joinableType, String alias, SessionFactoryImplementor factory) { return new OuterJoinableAssociation( new PropertyPath(), joinableType, null, null, alias, JoinType.LEFT_OUTER_JOIN, null, false, factory, Collections.EMPTY_MAP ); }
/** * Count the number of instances of Joinable which are actually * also instances of PersistentCollection which are being fetched * by outer join */ protected static final int countCollectionPersisters(List associations) throws MappingException { int result = 0; Iterator iter = associations.iterator(); while ( iter.hasNext() ) { OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next(); if ( oj.getJoinType()==JoinFragment.LEFT_OUTER_JOIN && oj.getJoinable().isCollection() ) { result++; } } return result; }
public boolean isManyToManyWith(OuterJoinableAssociation other) { if ( joinable.isCollection() ) { QueryableCollection persister = (QueryableCollection) joinable; if ( persister.isManyToMany() ) { return persister.getElementType() == other.getJoinableType(); } } return false; }
while ( iter.hasNext() ) { OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next(); if ( oj.getJoinType() == JoinType.LEFT_OUTER_JOIN ) { // why does this matter? if ( oj.getJoinable().isCollection() ) { final QueryableCollection queryableCollection = (QueryableCollection) oj.getJoinable(); if ( queryableCollection.hasOrdering() ) { final String orderByString = queryableCollection.getSQLOrderByString( oj.getRHSAlias() ); buf.append( orderByString ).append(", "); if ( last != null && last.getJoinable().isCollection() ) { final QueryableCollection queryableCollection = (QueryableCollection) last.getJoinable(); if ( queryableCollection.isManyToMany() && last.isManyToManyWith( oj ) ) { if ( queryableCollection.hasManyToManyOrdering() ) { final String orderByString = queryableCollection.getManyToManyOrderByString( oj.getRHSAlias() ); buf.append( orderByString ).append(", ");
public int getOwner(final List associations) { if ( isOneToOne() || isCollection() ) { return getPosition(lhsAlias, associations); } else { return -1; } }
? null : ( OuterJoinableAssociation ) associations.get( i + 1 ); final Joinable joinable = join.getJoinable(); final String entitySuffix = ( suffixes == null || entityAliasCount >= suffixes.length ) ? null : collectionSuffixes[collectionAliasCount]; final String selectFragment = joinable.selectFragment( next == null ? null : next.getJoinable(), next == null ? null : next.getRHSAlias(), join.getRHSAlias(), entitySuffix, collectionSuffix, join.getJoinType()==JoinType.LEFT_OUTER_JOIN ); if (selectFragment.trim().length() > 0) { if ( joinable.consumesCollectionAlias() && join.getJoinType()==JoinType.LEFT_OUTER_JOIN ) collectionAliasCount++;
public void associationProcessed(OuterJoinableAssociation oja, int position) { associationsByAlias.put( oja.getRhsAlias(), oja ); positionsByAlias.put( oja.getRhsAlias(), position ); EntityPersister entityPersister = null; if ( oja.getJoinableType().isCollectionType() ) { entityPersister = ( ( QueryableCollection) oja.getJoinable() ).getElementPersister(); } else if ( oja.getJoinableType().isEntityType() ) { entityPersister = ( EntityPersister ) oja.getJoinable(); } if ( entityPersister != null && entityPersister.getIdentifierType().isComponentType() && ! entityPersister.getEntityMetamodel().getIdentifierProperty().isEmbedded() && hasAssociation( (CompositeType) entityPersister.getIdentifierType() ) ) { aliasesForAssociationsWithCompositesIds.add( oja.getRhsAlias() ); } }