public FromElement findFromElementBySqlAlias(String sqlAlias) { FromElement fromElement = fromElementByTableAlias.get( sqlAlias ); if ( fromElement == null && parentFromClause != null ) { fromElement = parentFromClause.getFromElement( sqlAlias ); } return fromElement; }
public List<FromElement> toFromElements(FromClause fromClause, HqlSqlWalker walker) { // If a role already has an explicit fetch in the query, skip it in the graph. Map<String, FromElement> explicitFetches = new HashMap<String, FromElement>(); for ( Object o : fromClause.getFromElements() ) { final FromElement fromElement = (FromElement) o; if ( fromElement.getRole() != null && ! (fromElement instanceof ImpliedFromElement) ) { explicitFetches.put( fromElement.getRole(), fromElement ); } } return getFromElements( fromClause.getLevel() == FromClause.ROOT_LEVEL ? graph.getAttributeNodes(): Collections.emptyList(), fromClause.getFromElement(), fromClause, walker, explicitFetches ); }
public FromElement findFromElementByUserOrSqlAlias(String userAlias, String sqlAlias) { FromElement fromElement = null; if ( userAlias != null ) { fromElement = getFromElement( userAlias ); } if ( fromElement == null ) { fromElement = findFromElementBySqlAlias( sqlAlias ); } return fromElement; }
/** * Retrieve the from-element represented by the given alias. * * @param aliasOrClassName The alias by which to locate the from-element. * * @return The from-element assigned the given alias, or null if none. */ public FromElement getFromElement(String aliasOrClassName) { FromElement fromElement = fromElementByClassAlias.get( aliasOrClassName ); if ( fromElement == null && getSessionFactoryHelper().isStrictJPAQLComplianceEnabled() ) { fromElement = findIntendedAliasedFromElementBasedOnCrazyJPARequirements( aliasOrClassName ); } if ( fromElement == null && parentFromClause != null ) { fromElement = parentFromClause.getFromElement( aliasOrClassName ); } return fromElement; }
FromElement addFromElement() throws SemanticException { final FromClause parentFromClause = fromClause.getParentFromClause(); if ( parentFromClause != null ) { // Look up class name using the first identifier in the path. final String pathAlias = PathHelper.getAlias( path ); final FromElement parentFromElement = parentFromClause.getFromElement( pathAlias ); if ( parentFromElement != null ) { return createFromElementInSubselect( path, pathAlias, parentFromElement, classAlias ); } } final EntityPersister entityPersister = fromClause.getSessionFactoryHelper().requireClassPersister( path ); final FromElement elem = createAndAddFromElement( path, classAlias, entityPersister, (EntityType) ( (Queryable) entityPersister ).getType(), null ); // Add to the query spaces. fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() ); return elem; }
SessionFactoryHelper sfh = fromClause.getSessionFactoryHelper(); FromElement destination = null; String tableAlias = null; EntityPersister entityPersister = queryableCollection.getElementPersister(); tableAlias = fromClause.getAliasGenerator().createName( entityPersister.getEntityName() ); String associatedEntityName = entityPersister.getEntityName(); EntityPersister targetEntityPersister = sfh.requireClassPersister( associatedEntityName ); destination.setIncludeSubclasses( false ); fromClause.addCollectionJoinFromElementByPath( path, destination ); fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );
this.queryableCollection = queryableCollection; collectionType = queryableCollection.getCollectionType(); String roleAlias = fromClause.getAliasGenerator().createName( role ); boolean explicitSubqueryFromElement = fromClause.isSubQuery() && !implied; if ( explicitSubqueryFromElement ) { String pathRoot = StringHelper.root( path ); FromElement origin = fromClause.getFromElement( pathRoot ); if ( origin == null || origin.getFromClause() != fromClause ) { implied = true;
public FromElement getFromElement() { // TODO: not sure about this one // List fromElements = getFromElements(); // if ( fromElements == null || fromElements.isEmpty() ) { // throw new QueryException( "Unable to locate from element" ); // } return (FromElement) getFromElements().get( 0 ); }
public void resolve(boolean generateJoin, boolean implicitJoin, String classAlias, AST parent, AST parentPredicate) { if (!isResolved()) { if ( getWalker().getCurrentFromClause().isFromElementAlias( getText() ) ) { FromElement fromElement = getWalker().getCurrentFromClause().getFromElement( getText() ); if ( fromElement.getQueryableCollection() != null && fromElement.getQueryableCollection().getElementType().isComponentType() ) { if ( getWalker().isInSelect() ) { getColumns() != null && ( getWalker().getAST() instanceof AbstractMapComponentNode || getWalker().getAST() instanceof IndexNode ) && getWalker().getCurrentFromClause().isFromElementAlias( getOriginalText() ) ) {
protected void postProcessDML(RestrictableStatement statement) throws SemanticException { statement.getFromClause().resolve(); FromElement fromElement = (FromElement) statement.getFromClause().getFromElements().get( 0 ); Queryable persister = fromElement.getQueryable(); // Make #@%$^#^&# sure no alias is applied to the table name fromElement.setText( persister.getTableName() ); // // append any filter fragments; the EMPTY_MAP is used under the assumption that // // currently enabled filters should not affect this process // if ( persister.getDiscriminatorType() != null ) { // new SyntheticAndFactory( getASTFactory() ).addDiscriminatorWhereFragment( // statement, // persister, // java.util.Collections.EMPTY_MAP, // fromElement.getTableAlias() // ); // } if ( persister.getDiscriminatorType() != null || !queryTranslatorImpl.getEnabledFilters().isEmpty() ) { new SyntheticAndFactory( this ).addDiscriminatorWhereFragment( statement, persister, queryTranslatorImpl.getEnabledFilters(), fromElement.getTableAlias() ); } }
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; }
FromElement elem = currentFromClause.findJoinByPath( joinPath ); currentFromClause.addDuplicateAlias( classAlias, elem );
try { inEntityGraph = true; qn.getFromClause().getFromElements().addAll( queryTranslatorImpl.getEntityGraphQueryHint().toFromElements( qn.getFromClause(), this ) ); Iterator itr = qn.getFromClause().getProjectionList().iterator(); while ( itr.hasNext() ) { final FromElement fromElement = (FromElement) itr.next();
public ComponentJoin( FromClause fromClause, FromElement origin, String alias, String componentPath, CompositeType componentType) { super( fromClause, origin, alias ); this.componentPath = componentPath; this.componentType = componentType; this.componentProperty = StringHelper.unqualify( componentPath ); fromClause.addJoinByPathMap( componentPath, this ); initializeComponentJoin( new ComponentFromElementType( this ) ); this.columns = origin.getPropertyMapping( "" ).toColumns( getTableAlias(), componentProperty ); StringBuilder buf = new StringBuilder(); for ( int j = 0; j < columns.length; j++ ) { final String column = columns[j]; if ( j > 0 ) { buf.append( ", " ); } buf.append( column ); } this.columnsFragment = buf.toString(); }
@Override protected AST createFromElement(String path, AST alias, AST propertyFetch) throws SemanticException { FromElement fromElement = currentFromClause.addFromElement( path, alias ); fromElement.setAllPropertyFetch( propertyFetch != null ); return fromElement; }
/** * Adds a new from element to the from node. * * @param path The reference to the class. * @param alias The alias AST. * * @return FromElement - The new FROM element. */ public FromElement addFromElement(String path, AST alias) throws SemanticException { // The path may be a reference to an alias defined in the parent query. String classAlias = ( alias == null ) ? null : alias.getText(); checkForDuplicateClassAlias( classAlias ); FromElementFactory factory = new FromElementFactory( this, null, path, classAlias, null, false ); return factory.addFromElement(); }
public void setOrigin(FromElement origin, boolean manyToMany) { this.origin = origin; this.manyToMany = manyToMany; origin.addDestination( this ); if ( origin.getFromClause() == this.getFromClause() ) { // TODO: Figure out a better way to get the FROM elements in a proper tree structure. // If this is not the destination of a many-to-many, add it as a child of the origin. if ( manyToMany ) { ASTUtil.appendSibling( origin, this ); } else { if ( !getWalker().isInFrom() && !getWalker().isInSelect() && !getWalker().isInEntityGraph() ) { getFromClause().addChild( this ); } else { origin.addChild( this ); } } } else if ( !getWalker().isInFrom() ) { // HHH-276 : implied joins in a subselect where clause - The destination needs to be added // to the destination's from clause. getFromClause().addChild( this ); // Not sure if this is will fix everything, but it works. } else { // Otherwise, the destination node was implied by the FROM clause and the FROM clause processor // will automatically add it in the right place. } }
FromElement addFromElement() throws SemanticException { FromClause parentFromClause = fromClause.getParentFromClause(); if ( parentFromClause != null ) { // Look up class name using the first identifier in the path. String pathAlias = PathHelper.getAlias( path ); FromElement parentFromElement = parentFromClause.getFromElement( pathAlias ); if ( parentFromElement != null ) { return createFromElementInSubselect( path, pathAlias, parentFromElement, classAlias ); } } EntityPersister entityPersister = fromClause.getSessionFactoryHelper().requireClassPersister( path ); FromElement elem = createAndAddFromElement( path, classAlias, entityPersister, ( EntityType ) ( ( Queryable ) entityPersister ).getType(), null ); // Add to the query spaces. fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() ); return elem; }