@Override protected Type resolveType(QueryableCollection collectionPersister) { return collectionPersister.getElementType(); } }
public boolean isCollectionOfValuesOrComponents() { return persister == null && queryableCollection != null && !queryableCollection.getElementType().isEntityType(); }
@Override @SuppressWarnings("unchecked") protected Type resolveType(QueryableCollection collectionPersister) { final Type keyType = collectionPersister.getIndexType(); final Type valueType = collectionPersister.getElementType(); types.add( keyType ); types.add( valueType ); mapEntryBuilder = new MapEntryBuilder(); // an entry (as an aggregated select expression) does not have a type... return null; }
ComponentCollectionCriteriaInfoProvider(QueryableCollection persister) { this.persister = persister; if ( !persister.getElementType().isComponentType() ) { throw new IllegalArgumentException( "persister for role " + persister.getRole() + " is not a collection-of-component" ); } CompositeType componentType = (CompositeType) persister.getElementType(); String[] names = componentType.getPropertyNames(); Type[] types = componentType.getSubtypes(); for ( int i = 0; i < names.length; i++ ) { subTypes.put( names[i], types[i] ); } }
public Type toType(String propertyName) throws QueryException { if ( propertyName.equals(CollectionPropertyNames.COLLECTION_ELEMENTS) ) { return memberPersister.getElementType(); } else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_INDICES) ) { if ( !memberPersister.hasIndex() ) { throw new QueryException("unindexed collection before indices()"); } return memberPersister.getIndexType(); } else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_SIZE) ) { return StandardBasicTypes.INTEGER; } else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_MAX_INDEX) ) { return memberPersister.getIndexType(); } else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_MIN_INDEX) ) { return memberPersister.getIndexType(); } else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_MAX_ELEMENT) ) { return memberPersister.getElementType(); } else if ( propertyName.equals(CollectionPropertyNames.COLLECTION_MIN_ELEMENT) ) { return memberPersister.getElementType(); } else { //return memberPersister.getPropertyType(propertyName); throw new QueryException("illegal syntax near collection: " + propertyName); } }
public boolean isManyToManyWith(OuterJoinableAssociation other) { if ( joinable.isCollection() ) { QueryableCollection persister = (QueryableCollection) joinable; if ( persister.isManyToMany() ) { return persister.getElementType() == other.getJoinableType(); } } return false; }
void setCollectionToFetch(String role, String name, String ownerName, String entityName) throws QueryException { fetchName = name; collectionPersister = getCollectionPersister( role ); collectionOwnerName = ownerName; if ( collectionPersister.getElementType().isEntityType() ) { addEntityToFetch( entityName ); } }
if ( queryableCollection.getElementType().isAnyType() ) { if ( queryableCollection.getElementType().isComponentType() ) {
/** * Get sub-attribute definitions for a composite collection element. * @param compositionElementDefinition - composite collection element definition. * @return sub-attribute definitions for a composite collection element. */ public static Iterable<AttributeDefinition> getCompositeCollectionElementSubAttributes( CompositeCollectionElementDefinition compositionElementDefinition) { final QueryableCollection collectionPersister = (QueryableCollection) compositionElementDefinition.getCollectionDefinition().getCollectionPersister(); return getSingularSubAttributes( compositionElementDefinition.getSource(), (OuterJoinLoadable) collectionPersister.getOwnerEntityPersister(), (CompositeType) collectionPersister.getElementType(), collectionPersister.getTableName(), collectionPersister.getElementColumnNames() ); }
@Override public String getAssociatedEntityName(SessionFactoryImplementor factory) throws MappingException { try { QueryableCollection collectionPersister = (QueryableCollection) factory .getCollectionPersister( role ); if ( !collectionPersister.getElementType().isEntityType() ) { throw new MappingException( "collection was not an association: " + collectionPersister.getRole() ); } return collectionPersister.getElementPersister().getEntityName(); } catch (ClassCastException cce) { throw new MappingException( "collection role is not queryable " + role ); } }
roleAlias, joinSequence, (EntityType) queryableCollection.getElementType(), false ); elem = createManyToMany( role, associatedEntityName, roleAlias, entityPersister, (EntityType) queryableCollection.getElementType(), joinType ); fromClause.getWalker().addQuerySpaces( queryableCollection.getCollectionSpaces() );
private TypeDiscriminatorMetadata buildTypeDiscriminatorMetadata() { final String aliasToUse = getTableAlias(); Queryable queryable = getQueryable(); if ( queryable == null ) { QueryableCollection collection = getQueryableCollection(); if ( ! collection.getElementType().isEntityType() ) { throw new QueryException( "type discrimination cannot be applied to value collection [" + collection.getRole() + "]" ); } queryable = (Queryable) collection.getElementPersister(); } handlePropertyBeingDereferenced( getDataType(), DISCRIMINATOR_PROPERTY_NAME ); return new TypeDiscriminatorMetadataImpl( queryable.getTypeDiscriminatorMetadata(), aliasToUse ); }
private void handleElements(FromReferenceNode collectionNode, String propertyName) { FromElement collectionFromElement = collectionNode.getFromElement(); QueryableCollection queryableCollection = collectionFromElement.getQueryableCollection(); String path = collectionNode.getPath() + "[]." + propertyName; LOG.debugf( "Creating elements for %s", path ); fromElement = collectionFromElement; if ( !collectionFromElement.isCollectionOfValuesOrComponents() ) { getWalker().addQuerySpaces( queryableCollection.getElementPersister().getQuerySpaces() ); } setDataType( queryableCollection.getElementType() ); selectColumns = collectionFromElement.toColumns( fromElement.getTableAlias(), propertyName, inSelect ); }
public void setScalarColumnText(int i) throws SemanticException { if (nakedPropertyRef) { // do *not* over-write the column text, as that has already been // "rendered" during resolve ColumnHelper.generateSingleScalarColumn(this, i); } else { FromElement fe = getFromElement(); if (fe != null) { if ( fe.getQueryableCollection() != null && fe.getQueryableCollection().getElementType().isComponentType() ) { ColumnHelper.generateScalarColumns( this, getColumns(), i ); } else { setText(fe.renderScalarIdentifierSelect(i)); } } else { ColumnHelper.generateSingleScalarColumn(this, i); } } }
private void determineValueSelectExpressions(QueryableCollection collectionPersister, List selections) { AliasGenerator aliasGenerator = new LocalAliasGenerator( 1 ); appendSelectExpressions( collectionPersister.getElementColumnNames(), selections, aliasGenerator ); Type valueType = collectionPersister.getElementType(); if ( valueType.isAssociationType() ) { EntityType valueEntityType = (EntityType) valueType; Queryable valueEntityPersister = (Queryable) sfi().getEntityPersister( valueEntityType.getAssociatedEntityName( sfi() ) ); SelectFragment fragment = valueEntityPersister.propertySelectFragmentFragment( elementTableAlias(), null, false ); appendSelectExpressions( fragment, selections, aliasGenerator ); } }
Type collectionElementType = persister.getElementType(); if ( !collectionElementType.isEntityType() ) { throw new QueryException( "collection of values in filter: " + elementName ); try { join.addJoin( (AssociationType) persister.getElementType(), elementName, JoinType.INNER_JOIN,
Type elementType = queryableCollection.getElementType(); if ( !elementType.isEntityType() ) { throw new IllegalArgumentException( "Cannot create element join for a collection of non-entities!" ); classAlias, targetEntityPersister, (EntityType) queryableCollection.getElementType(), tableAlias );
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 ); }
private FromElement createCollectionJoin(JoinSequence collectionJoinSequence, String tableAlias) throws SemanticException { String text = queryableCollection.getTableName(); AST ast = createFromElement( text ); FromElement destination = (FromElement) ast; Type elementType = queryableCollection.getElementType(); if ( elementType.isCollectionType() ) { throw new SemanticException( "Collections of collections are not supported!" ); } destination.initializeCollection( fromClause, classAlias, tableAlias ); destination.setType( JOIN_FRAGMENT ); // Tag this node as a JOIN. destination.setIncludeSubclasses( false ); // Don't include subclasses in the join. destination.setCollectionJoin( true ); // This is a clollection join. destination.setJoinSequence( collectionJoinSequence ); destination.setOrigin( origin, false ); destination.setCollectionTableAlias( tableAlias ); // origin.addDestination( destination ); // This was the cause of HHH-242 // origin.setType( FROM_FRAGMENT ); // Set the parent node type so that the AST is properly formed. origin.setText( "" ); // The destination node will have all the FROM text. origin.setCollectionJoin( true ); // The parent node is a collection join too (voodoo - see JoinProcessor) fromClause.addCollectionJoinFromElementByPath( path, destination ); fromClause.getWalker().addQuerySpaces( queryableCollection.getCollectionSpaces() ); return destination; }
@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; }