Java Code Examples for org.hibernate.persister.collection.QueryableCollection#isOneToMany()
The following examples show how to use
org.hibernate.persister.collection.QueryableCollection#isOneToMany() .
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: ReactiveDynamicBatchingCollectionDelegator.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 6 votes |
public ReactiveDynamicBatchingCollectionDelegator( QueryableCollection collectionPersister, int maxBatchSize, SessionFactoryImplementor factory, LoadQueryInfluencers influencers) { super( collectionPersister, factory, influencers ); this.maxBatchSize = maxBatchSize; if ( collectionPersister.isOneToMany() ) { this.singleKeyLoader = new ReactiveOneToManyLoader( collectionPersister, 1, factory, influencers ); } else { throw new UnsupportedOperationException(); // this.singleKeyLoader = new ReactiveBasicCollectionLoader( collectionPersister, 1, factory, influencers ); } this.batchLoader = new ReactiveDynamicBatchingCollectionInitializer( collectionPersister, factory, influencers ); }
Example 2
Source File: DynamicBatchingCollectionInitializerBuilder.java From lams with GNU General Public License v2.0 | 6 votes |
public DynamicBatchingCollectionInitializer( QueryableCollection collectionPersister, int maxBatchSize, SessionFactoryImplementor factory, LoadQueryInfluencers influencers) { super( collectionPersister ); this.maxBatchSize = maxBatchSize; if ( collectionPersister.isOneToMany() ) { this.singleKeyLoader = new OneToManyLoader( collectionPersister, 1, factory, influencers ); } else { this.singleKeyLoader = new BasicCollectionLoader( collectionPersister, 1, factory, influencers ); } this.batchLoader = new DynamicBatchingCollectionLoader( collectionPersister, factory, influencers ); }
Example 3
Source File: IndexNode.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void prepareForDot(String propertyName) throws SemanticException { FromElement fromElement = getFromElement(); if ( fromElement == null ) { throw new IllegalStateException( "No FROM element for index operator!" ); } final QueryableCollection queryableCollection = fromElement.getQueryableCollection(); if ( queryableCollection != null && !queryableCollection.isOneToMany() ) { final FromReferenceNode collectionNode = (FromReferenceNode) getFirstChild(); final String path = collectionNode.getPath() + "[]." + propertyName; LOG.debugf( "Creating join for many-to-many elements for %s", path ); final FromElementFactory factory = new FromElementFactory( fromElement.getFromClause(), fromElement, path ); // This will add the new from element to the origin. final FromElement elementJoin = factory.createElementJoin( queryableCollection ); setFromElement( elementJoin ); } }
Example 4
Source File: HqlSqlWalker.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
protected AST createFromFilterElement(AST filterEntity, AST alias) throws SemanticException { FromElement fromElement = currentFromClause.addFromElement( filterEntity.getText(), alias ); FromClause fromClause = fromElement.getFromClause(); QueryableCollection persister = sessionFactoryHelper.getCollectionPersister( collectionFilterRole ); // Get the names of the columns used to link between the collection // owner and the collection elements. String[] keyColumnNames = persister.getKeyColumnNames(); String fkTableAlias = persister.isOneToMany() ? fromElement.getTableAlias() : fromClause.getAliasGenerator().createName( collectionFilterRole ); JoinSequence join = sessionFactoryHelper.createJoinSequence(); join.setRoot( persister, fkTableAlias ); if ( !persister.isOneToMany() ) { join.addJoin( ( AssociationType ) persister.getElementType(), fromElement.getTableAlias(), JoinFragment.INNER_JOIN, persister.getElementColumnNames( fkTableAlias ) ); } join.addCondition( fkTableAlias, keyColumnNames, " = ?" ); fromElement.setJoinSequence( join ); fromElement.setFilter( true ); if ( log.isDebugEnabled() ) { log.debug( "createFromFilterElement() : processed filter FROM element." ); } return fromElement; }
Example 5
Source File: IndexNode.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public void prepareForDot(String propertyName) throws SemanticException { FromElement fromElement = getFromElement(); if ( fromElement == null ) { throw new IllegalStateException( "No FROM element for index operator!" ); } QueryableCollection queryableCollection = fromElement.getQueryableCollection(); if ( queryableCollection != null && !queryableCollection.isOneToMany() ) { FromReferenceNode collectionNode = ( FromReferenceNode ) getFirstChild(); String path = collectionNode.getPath() + "[]." + propertyName; if ( log.isDebugEnabled() ) { log.debug( "Creating join for many-to-many elements for " + path ); } FromElementFactory factory = new FromElementFactory( fromElement.getFromClause(), fromElement, path ); // This will add the new from element to the origin. FromElement elementJoin = factory.createElementJoin( queryableCollection ); setFromElement( elementJoin ); } }
Example 6
Source File: QueryTranslatorImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Used for collection filters */ private void addFromAssociation(final String elementName, final String collectionRole) throws QueryException { //q.addCollection(collectionName, collectionRole); QueryableCollection persister = getCollectionPersister( collectionRole ); Type collectionElementType = persister.getElementType(); if ( !collectionElementType.isEntityType() ) { throw new QueryException( "collection of values in filter: " + elementName ); } String[] keyColumnNames = persister.getKeyColumnNames(); //if (keyColumnNames.length!=1) throw new QueryException("composite-key collection in filter: " + collectionRole); String collectionName; JoinSequence join = new JoinSequence( getFactory() ); collectionName = persister.isOneToMany() ? elementName : createNameForCollection( collectionRole ); join.setRoot( persister, collectionName ); if ( !persister.isOneToMany() ) { //many-to-many addCollection( collectionName, collectionRole ); try { join.addJoin( ( AssociationType ) persister.getElementType(), elementName, JoinFragment.INNER_JOIN, persister.getElementColumnNames(collectionName) ); } catch ( MappingException me ) { throw new QueryException( me ); } } join.addCondition( collectionName, keyColumnNames, " = ?" ); //if ( persister.hasWhere() ) join.addCondition( persister.getSQLWhereString(collectionName) ); EntityType elemType = ( EntityType ) collectionElementType; addFrom( elementName, elemType.getAssociatedEntityName(), join ); }
Example 7
Source File: ReactiveBatchingCollectionInitializerBuilder.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 5 votes |
protected ReactiveCollectionLoader buildNonBatchingLoader( QueryableCollection persister, SessionFactoryImplementor factory, LoadQueryInfluencers influencers) { if (persister.isOneToMany()) { return new ReactiveOneToManyLoader(persister, factory, influencers); } throw new UnsupportedOperationException(); // return new ReactiveBasicCollectionLoader(persister, factory, influencers); }
Example 8
Source File: PathExpressionParser.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public String addFromCollection(QueryTranslatorImpl q) throws QueryException { Type collectionElementType = getPropertyType(); if ( collectionElementType == null ) { throw new QueryException( "must specify 'elements' for collection valued property in from clause: " + path ); } if ( collectionElementType.isEntityType() ) { // an association QueryableCollection collectionPersister = q.getCollectionPersister( collectionRole ); Queryable entityPersister = ( Queryable ) collectionPersister.getElementPersister(); String clazz = entityPersister.getEntityName(); final String elementName; if ( collectionPersister.isOneToMany() ) { elementName = collectionName; //allow index() function: q.decoratePropertyMapping( elementName, collectionPersister ); } else { //many-to-many q.addCollection( collectionName, collectionRole ); elementName = q.createNameFor( clazz ); addJoin( elementName, ( AssociationType ) collectionElementType ); } q.addFrom( elementName, clazz, joinSequence ); currentPropertyMapping = new CollectionPropertyMapping( collectionPersister ); return elementName; } else { // collections of values q.addFromCollection( collectionName, collectionRole, joinSequence ); return collectionName; } }
Example 9
Source File: PathExpressionParser.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private void prepareForIndex(QueryTranslatorImpl q) throws QueryException { QueryableCollection collPersister = q.getCollectionPersister( collectionRole ); if ( !collPersister.hasIndex() ) throw new QueryException( "unindexed collection before []: " + path ); String[] indexCols = collPersister.getIndexColumnNames(); if ( indexCols.length != 1 ) throw new QueryException( "composite-index appears in []: " + path ); //String[] keyCols = collPersister.getKeyColumnNames(); JoinSequence fromJoins = new JoinSequence( q.getFactory() ) .setUseThetaStyle( useThetaStyleJoin ) .setRoot( collPersister, collectionName ) .setNext( joinSequence.copy() ); if ( !continuation ) addJoin( collectionName, collPersister.getCollectionType() ); joinSequence.addCondition( collectionName + '.' + indexCols[0] + " = " ); //TODO: get SQL rendering out of here CollectionElement elem = new CollectionElement(); elem.elementColumns = collPersister.getElementColumnNames(collectionName); elem.elementType = collPersister.getElementType(); elem.isOneToMany = collPersister.isOneToMany(); elem.alias = collectionName; elem.joinSequence = joinSequence; collectionElements.addLast( elem ); setExpectingCollectionIndex(); q.addCollection( collectionName, collectionRole ); q.addFromJoinOnly( collectionName, fromJoins ); }
Example 10
Source File: FromElementType.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void setQueryableCollection(QueryableCollection queryableCollection) { if ( this.queryableCollection != null ) { throw new IllegalStateException( "QueryableCollection is already defined for " + this + "!" ); } this.queryableCollection = queryableCollection; if ( !queryableCollection.isOneToMany() ) { // For many-to-many joins, use the tablename from the queryable collection for the default text. fromElement.setText( queryableCollection.getTableName() + " " + getTableAlias() ); } }
Example 11
Source File: QueryTranslatorImpl.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Used for collection filters */ private void addFromAssociation(final String elementName, final String collectionRole) throws QueryException { //q.addCollection(collectionName, collectionRole); QueryableCollection persister = getCollectionPersister( collectionRole ); Type collectionElementType = persister.getElementType(); if ( !collectionElementType.isEntityType() ) { throw new QueryException( "collection of values in filter: " + elementName ); } String[] keyColumnNames = persister.getKeyColumnNames(); //if (keyColumnNames.length!=1) throw new QueryException("composite-key collection in filter: " + collectionRole); String collectionName; JoinSequence join = new JoinSequence( getFactory() ); collectionName = persister.isOneToMany() ? elementName : createNameForCollection( collectionRole ); join.setRoot( persister, collectionName ); if ( !persister.isOneToMany() ) { //many-to-many addCollection( collectionName, collectionRole ); try { join.addJoin( (AssociationType) persister.getElementType(), elementName, JoinType.INNER_JOIN, persister.getElementColumnNames( collectionName ) ); } catch (MappingException me) { throw new QueryException( me ); } } join.addCondition( collectionName, keyColumnNames, " = ?" ); //if ( persister.hasWhere() ) join.addCondition( persister.getSQLWhereString(collectionName) ); EntityType elemType = (EntityType) collectionElementType; addFrom( elementName, elemType.getAssociatedEntityName(), join ); }
Example 12
Source File: PathExpressionParser.java From lams with GNU General Public License v2.0 | 5 votes |
public String addFromCollection(QueryTranslatorImpl q) throws QueryException { Type collectionElementType = getPropertyType(); if ( collectionElementType == null ) { throw new QueryException( "must specify 'elements' for collection valued property in from clause: " + path ); } if ( collectionElementType.isEntityType() ) { // an association QueryableCollection collectionPersister = q.getCollectionPersister( collectionRole ); Queryable entityPersister = ( Queryable ) collectionPersister.getElementPersister(); String clazz = entityPersister.getEntityName(); final String elementName; if ( collectionPersister.isOneToMany() ) { elementName = collectionName; //allow index() function: q.decoratePropertyMapping( elementName, collectionPersister ); } else { //many-to-many q.addCollection( collectionName, collectionRole ); elementName = q.createNameFor( clazz ); addJoin( elementName, ( AssociationType ) collectionElementType ); } q.addFrom( elementName, clazz, joinSequence ); currentPropertyMapping = new CollectionPropertyMapping( collectionPersister ); return elementName; } else { // collections of values q.addFromCollection( collectionName, collectionRole, joinSequence ); return collectionName; } }
Example 13
Source File: PathExpressionParser.java From lams with GNU General Public License v2.0 | 5 votes |
private void prepareForIndex(QueryTranslatorImpl q) throws QueryException { QueryableCollection collPersister = q.getCollectionPersister( collectionRole ); if ( !collPersister.hasIndex() ) { throw new QueryException( "unindexed collection before []: " + path ); } String[] indexCols = collPersister.getIndexColumnNames(); if ( indexCols.length != 1 ) { throw new QueryException( "composite-index appears in []: " + path ); } //String[] keyCols = collPersister.getKeyColumnNames(); JoinSequence fromJoins = new JoinSequence( q.getFactory() ) .setUseThetaStyle( useThetaStyleJoin ) .setRoot( collPersister, collectionName ) .setNext( joinSequence.copy() ); if ( !continuation ) { addJoin( collectionName, collPersister.getCollectionType() ); } joinSequence.addCondition( collectionName + '.' + indexCols[0] + " = " ); //TODO: get SQL rendering out of here CollectionElement elem = new CollectionElement(); elem.elementColumns = collPersister.getElementColumnNames(collectionName); elem.elementType = collPersister.getElementType(); elem.isOneToMany = collPersister.isOneToMany(); elem.alias = collectionName; elem.joinSequence = joinSequence; collectionElements.addLast( elem ); setExpectingCollectionIndex(); q.addCollection( collectionName, collectionRole ); q.addFromJoinOnly( collectionName, fromJoins ); }
Example 14
Source File: HqlSqlWalker.java From lams with GNU General Public License v2.0 | 5 votes |
@Override protected AST createFromFilterElement(AST filterEntity, AST alias) throws SemanticException { FromElement fromElement = currentFromClause.addFromElement( filterEntity.getText(), alias ); FromClause fromClause = fromElement.getFromClause(); QueryableCollection persister = sessionFactoryHelper.getCollectionPersister( collectionFilterRole ); // Get the names of the columns used to link between the collection // owner and the collection elements. String[] keyColumnNames = persister.getKeyColumnNames(); String fkTableAlias = persister.isOneToMany() ? fromElement.getTableAlias() : fromClause.getAliasGenerator().createName( collectionFilterRole ); JoinSequence join = sessionFactoryHelper.createJoinSequence(); join.setRoot( persister, fkTableAlias ); if ( !persister.isOneToMany() ) { join.addJoin( (AssociationType) persister.getElementType(), fromElement.getTableAlias(), JoinType.INNER_JOIN, persister.getElementColumnNames( fkTableAlias ) ); } join.addCondition( fkTableAlias, keyColumnNames, " = ?" ); fromElement.setJoinSequence( join ); fromElement.setFilter( true ); LOG.debug( "createFromFilterElement() : processed filter FROM element." ); return fromElement; }
Example 15
Source File: FromElementType.java From lams with GNU General Public License v2.0 | 5 votes |
public void setQueryableCollection(QueryableCollection queryableCollection) { if ( this.queryableCollection != null ) { throw new IllegalStateException( "QueryableCollection is already defined for " + this + "!" ); } this.queryableCollection = queryableCollection; if ( !queryableCollection.isOneToMany() ) { // For many-to-many joins, use the tablename from the queryable collection for the default text. fromElement.setText( queryableCollection.getTableName() + " " + getTableAlias() ); } }
Example 16
Source File: BatchingCollectionInitializerBuilder.java From lams with GNU General Public License v2.0 | 5 votes |
protected CollectionInitializer buildNonBatchingLoader( QueryableCollection persister, SessionFactoryImplementor factory, LoadQueryInfluencers influencers) { return persister.isOneToMany() ? new OneToManyLoader( persister, factory, influencers ) : new BasicCollectionLoader( persister, factory, influencers ); }
Example 17
Source File: JoinWalker.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * For a collection role, return a list of associations to be fetched by outerjoin */ private void walkCollectionTree( final QueryableCollection persister, final String alias, final String path, final int currentDepth) throws MappingException { if ( persister.isOneToMany() ) { walkEntityTree( (OuterJoinLoadable) persister.getElementPersister(), alias, path, currentDepth ); } else { Type type = persister.getElementType(); if ( type.isAssociationType() ) { // a many-to-many; // decrement currentDepth here to allow join across the association table // without exceeding MAX_FETCH_DEPTH (i.e. the "currentDepth - 1" bit) AssociationType associationType = (AssociationType) type; String[] aliasedLhsColumns = persister.getElementColumnNames(alias); String[] lhsColumns = persister.getElementColumnNames(); // if the current depth is 0, the root thing being loaded is the // many-to-many collection itself. Here, it is alright to use // an inner join... boolean useInnerJoin = currentDepth == 0; final int joinType = getJoinType( associationType, persister.getFetchMode(), path, persister.getTableName(), lhsColumns, !useInnerJoin, currentDepth - 1, null //operations which cascade as far as the collection also cascade to collection elements ); addAssociationToJoinTreeIfNecessary( associationType, aliasedLhsColumns, alias, path, currentDepth - 1, joinType ); } else if ( type.isComponentType() ) { walkCompositeElementTree( (AbstractComponentType) type, persister.getElementColumnNames(), persister, alias, path, currentDepth ); } } }
Example 18
Source File: JoinWalker.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
protected void initPersisters(final List associations, final LockMode lockMode) 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 ); persisters = new Loadable[joins]; aliases = new String[joins]; owners = new int[joins]; ownerAssociationTypes = new EntityType[joins]; lockModeArray = ArrayHelper.fillArray(lockMode, joins); int i=0; int j=0; Iterator iter = associations.iterator(); while ( iter.hasNext() ) { final OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next(); if ( !oj.isCollection() ) { persisters[i] = (Loadable) oj.getJoinable(); aliases[i] = oj.getRHSAlias(); owners[i] = oj.getOwner(associations); ownerAssociationTypes[i] = (EntityType) oj.getJoinableType(); i++; } else { QueryableCollection collPersister = (QueryableCollection) oj.getJoinable(); if ( oj.getJoinType()==JoinFragment.LEFT_OUTER_JOIN ) { //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(); i++; } } } if ( ArrayHelper.isAllNegative(owners) ) owners = null; if ( collectionOwners!=null && ArrayHelper.isAllNegative(collectionOwners) ) { collectionOwners = null; } }
Example 19
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 20
Source File: JoinWalker.java From lams with GNU General Public License v2.0 | 4 votes |
/** * For a collection role, return a list of associations to be fetched by outerjoin */ private void walkCollectionTree( final QueryableCollection persister, final String alias, final PropertyPath path, final int currentDepth) throws MappingException { if ( persister.isOneToMany() ) { walkEntityTree( (OuterJoinLoadable) persister.getElementPersister(), alias, path, currentDepth ); } else { Type type = persister.getElementType(); if ( type.isAssociationType() ) { // a many-to-many; // decrement currentDepth here to allow join across the association table // without exceeding MAX_FETCH_DEPTH (i.e. the "currentDepth - 1" bit) AssociationType associationType = (AssociationType) type; String[] aliasedLhsColumns = persister.getElementColumnNames( alias ); String[] lhsColumns = persister.getElementColumnNames(); // if the current depth is 0, the root thing being loaded is the // many-to-many collection itself. Here, it is alright to use // an inner join... boolean useInnerJoin = currentDepth == 0; final JoinType joinType = getJoinType( associationType, persister.getFetchMode(), path, persister.getTableName(), lhsColumns, !useInnerJoin, currentDepth - 1, null //operations which cascade as far as the collection also cascade to collection elements ); addAssociationToJoinTreeIfNecessary( associationType, aliasedLhsColumns, alias, path, currentDepth - 1, joinType ); } else if ( type.isComponentType() ) { walkCompositeElementTree( (CompositeType) type, persister.getElementColumnNames(), persister, alias, path, currentDepth ); } } }