Java Code Examples for org.hibernate.sql.JoinType#LEFT_OUTER_JOIN
The following examples show how to use
org.hibernate.sql.JoinType#LEFT_OUTER_JOIN .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OuterJoinableAssociation.java From lams with GNU General Public License v2.0 | 6 votes |
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 ); }
Example 2
Source File: JoinProcessor.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Translates an AST join type (i.e., the token type) into a JoinFragment.XXX join type. * * @param astJoinType The AST join type (from HqlSqlTokenTypes or SqlTokenTypes) * * @return a JoinFragment.XXX join type. * * @see JoinFragment * @see SqlTokenTypes */ public static JoinType toHibernateJoinType(int astJoinType) { switch ( astJoinType ) { case LEFT_OUTER: { return JoinType.LEFT_OUTER_JOIN; } case INNER: { return JoinType.INNER_JOIN; } case RIGHT_OUTER: { return JoinType.RIGHT_OUTER_JOIN; } case FULL: { return JoinType.FULL_JOIN; } default: { throw new AssertionFailure( "undefined join type " + astJoinType ); } } }
Example 3
Source File: JoinWalker.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Use an inner join if it is a non-null association and this * is the "first" join in a series */ protected JoinType getJoinType(boolean nullable, int currentDepth) { //TODO: this is too conservative; if all preceding joins were // also inner joins, we could use an inner join here // // IMPL NOTE : currentDepth might be less-than zero if this is the // root of a many-to-many collection initializer return !nullable && currentDepth <= 0 ? JoinType.INNER_JOIN : JoinType.LEFT_OUTER_JOIN; }
Example 4
Source File: JoinWalker.java From lams with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 5
Source File: BasicCollectionJoinWalker.java From lams with GNU General Public License v2.0 | 5 votes |
protected JoinType getJoinType( OuterJoinLoadable persister, PropertyPath path, int propertyNumber, AssociationType associationType, FetchMode metadataFetchMode, CascadeStyle metadataCascadeStyle, String lhsTable, String[] lhsColumns, boolean nullable, int currentDepth) throws MappingException { JoinType joinType = super.getJoinType( persister, path, propertyNumber, associationType, metadataFetchMode, metadataCascadeStyle, lhsTable, lhsColumns, nullable, currentDepth ); //we can use an inner join for the many-to-many if ( joinType==JoinType.LEFT_OUTER_JOIN && path.isRoot() ) { joinType=JoinType.INNER_JOIN; } return joinType; }
Example 6
Source File: AbstractEntityPersister.java From lams with GNU General Public License v2.0 | 5 votes |
protected JoinType determineSubclassTableJoinType( int subclassTableNumber, boolean canInnerJoin, boolean includeSubclasses, Set<String> treatAsDeclarations) { if ( isClassOrSuperclassTable( subclassTableNumber ) ) { final boolean shouldInnerJoin = canInnerJoin && !isInverseTable( subclassTableNumber ) && !isNullableTable( subclassTableNumber ); // the table is either this persister's driving table or (one of) its super class persister's driving // tables which can be inner joined as long as the `shouldInnerJoin` condition resolves to true return shouldInnerJoin ? JoinType.INNER_JOIN : JoinType.LEFT_OUTER_JOIN; } // otherwise we have a subclass table and need to look a little deeper... // IMPL NOTE : By default includeSubclasses indicates that all subclasses should be joined and that each // subclass ought to be joined by outer-join. However, TREAT-AS always requires that an inner-join be used // so we give TREAT-AS higher precedence... if ( isSubclassTableIndicatedByTreatAsDeclarations( subclassTableNumber, treatAsDeclarations ) ) { return JoinType.INNER_JOIN; } if ( includeSubclasses && !isSubclassTableSequentialSelect( subclassTableNumber ) && !isSubclassTableLazy( subclassTableNumber ) ) { return JoinType.LEFT_OUTER_JOIN; } return JoinType.NONE; }
Example 7
Source File: JoinWalker.java From lams with GNU General Public License v2.0 | 4 votes |
protected void initPersisters( final List associations, final LockOptions lockOptions, final AssociationInitCallback callback) throws MappingException { final int joins = countEntityPersisters( associations ); final int collections = countCollectionPersisters( associations ); collectionOwners = collections == 0 ? null : new int[collections]; collectionPersisters = collections == 0 ? null : new CollectionPersister[collections]; collectionSuffixes = BasicLoader.generateSuffixes( joins + 1, collections ); this.lockOptions = lockOptions; persisters = new Loadable[joins]; aliases = new String[joins]; owners = new int[joins]; ownerAssociationTypes = new EntityType[joins]; lockModeArray = ArrayHelper.fillArray( lockOptions.getLockMode(), joins ); int i = 0; int j = 0; 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++; } else { QueryableCollection collPersister = (QueryableCollection) oj.getJoinable(); if ( oj.getJoinType() == JoinType.LEFT_OUTER_JOIN && !oj.hasRestriction() ) { //it must be a collection fetch collectionPersisters[j] = collPersister; collectionOwners[j] = oj.getOwner( associations ); j++; } if ( collPersister.isOneToMany() ) { persisters[i] = (Loadable) collPersister.getElementPersister(); aliases[i] = oj.getRHSAlias(); callback.associationProcessed( oj, i ); i++; } } } if ( ArrayHelper.isAllNegative( owners ) ) { owners = null; } if ( collectionOwners != null && ArrayHelper.isAllNegative( collectionOwners ) ) { collectionOwners = null; } }
Example 8
Source File: JoinWalker.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Generate a select list of columns containing all properties of the entity classes */ protected final String selectString(List associations) throws MappingException { if ( associations.size() == 0 ) { return ""; } else { StringBuilder buf = new StringBuilder( associations.size() * 100 ); int entityAliasCount = 0; int collectionAliasCount = 0; for ( int i = 0; i < associations.size(); i++ ) { OuterJoinableAssociation join = (OuterJoinableAssociation) associations.get( i ); OuterJoinableAssociation next = ( i == associations.size() - 1 ) ? null : (OuterJoinableAssociation) associations.get( i + 1 ); final Joinable joinable = join.getJoinable(); final String entitySuffix = ( suffixes == null || entityAliasCount >= suffixes.length ) ? null : suffixes[entityAliasCount]; final String collectionSuffix = ( collectionSuffixes == null || collectionAliasCount >= collectionSuffixes.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 ) { buf.append( ", " ).append( selectFragment ); } if ( joinable.consumesEntityAlias() ) { entityAliasCount++; } if ( joinable.consumesCollectionAlias() && join.getJoinType() == JoinType.LEFT_OUTER_JOIN && !join.hasRestriction() ) { collectionAliasCount++; } } return buf.toString(); } }