private void validateLhs(FromReferenceNode lhs) { // make sure the lhs is "assignable"... if ( !lhs.isResolved() ) { throw new UnsupportedOperationException( "cannot validate assignablity of unresolved node" ); } if ( lhs.getDataType().isCollectionType() ) { throw new QueryException( "collections not assignable in update statements" ); } else if ( lhs.getDataType().isComponentType() ) { throw new QueryException( "Components currently not assignable in update statements" ); } else if ( lhs.getDataType().isEntityType() ) { // currently allowed... } // TODO : why aren't these the same? if ( lhs.getImpliedJoin() != null || lhs.getFromElement().isImplied() ) { throw new QueryException( "Implied join paths are not assignable in update statements" ); } } }
public void recursiveResolve(int level, boolean impliedAtRoot, String classAlias, AST parent) throws SemanticException { AST lhs = getFirstChild(); int nextLevel = level + 1; if ( lhs != null ) { FromReferenceNode n = (FromReferenceNode) lhs; n.recursiveResolve( nextLevel, impliedAtRoot, null, this ); } resolveFirstChild(); boolean impliedJoin = true; if ( level == ROOT_LEVEL && !impliedAtRoot ) { impliedJoin = false; } resolve( true, impliedJoin, classAlias, parent ); }
DotNode dotNode = (DotNode) dot; FromReferenceNode lhs = dotNode.getLhs(); AST rhs = lhs.getNextSibling(); if ( lhs.getDataType() != null && lhs.getDataType().isCollectionType() ) { if ( CollectionProperties.isCollectionProperty( rhs.getText() ) ) { DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfCollectionPropertiesInHql( rhs.getText(), lhs.getPath() ); dotNode.getPath(), rhs.getText(), lhs.getPath() ); lhs.setNextSibling( null ); dotNode.setFirstChild( f );
private boolean checkSubclassOrSuperclassPropertyReference(FromReferenceNode lhs, String propertyName) { if ( lhs != null && !( lhs instanceof IndexNode ) ) { final FromElement source = lhs.getFromElement(); if ( source != null ) { source.handlePropertyBeingDereferenced( lhs.getDataType(), propertyName ); } } return false; } }
private FromElement evaluateFromElementPath(String path, String classAlias) throws SemanticException { ASTFactory factory = fromClause.getASTFactory(); FromReferenceNode pathNode = (FromReferenceNode) PathHelper.parsePath( path, factory ); pathNode.recursiveResolve( // This is the root level node. FromReferenceNode.ROOT_LEVEL, // Generate an explicit from clause at the root. false, classAlias, null ); if ( pathNode.getImpliedJoin() != null ) { return pathNode.getImpliedJoin(); } return pathNode.getFromElement(); }
collectionNode.resolveIndex( this ); // Fully resolve the map reference, create implicit joins. Type type = collectionNode.getDataType(); if ( !type.isCollectionType() ) { throw new SemanticException( "The [] operator cannot be applied to type " + type.toString() ); QueryableCollection queryableCollection = sessionFactoryHelper.requireQueryableCollection( collectionRole ); if ( !queryableCollection.hasIndex() ) { throw new QueryException( "unindexed fromElement before []: " + collectionNode.getPath() ); FromElement fromElement = collectionNode.getFromElement(); String elementTable = fromElement.getTableAlias(); FromClause fromClause = fromElement.getFromClause(); String path = collectionNode.getPath(); AST selector = collectionNode.getNextSibling(); if ( selector == null ) { throw new QueryException( "No index value!" ); String[] indexCols = queryableCollection.getIndexColumnNames(); if ( indexCols.length != 1 ) { throw new QueryException( "composite-index appears in []: " + collectionNode.getPath() );
@Override public Type getDataType() { if ( super.getDataType() == null ) { FromElement fromElement = getLhs().getFromElement(); if ( fromElement == null ) { return null; } // If the lhs is a collection, use CollectionPropertyMapping Type propertyType = fromElement.getPropertyType( propertyPath, propertyPath ); LOG.debugf( "getDataType() : %s -> %s", propertyPath, propertyType ); super.setDataType( propertyType ); } return super.getDataType(); }
if ( mapFromElement == null ) { final FromReferenceNode mapReference = getMapReference(); mapReference.resolve( true, true ); final QueryableCollection collectionPersister = mapReference.getFromElement().getQueryableCollection(); if ( Map.class.isAssignableFrom( collectionPersister.getCollectionType().getReturnedClass() ) ) { sourceFromElement = mapReference.getFromElement(); if ( mapReference.getDataType().isCollectionType() ) { final CollectionType collectionType = (CollectionType) mapReference.getDataType(); if ( Map.class.isAssignableFrom( collectionType.getReturnedClass() ) ) { sourceFromElement = mapReference.getFromElement();
private String[] getColumns() throws QueryException { if ( columns == null ) { // Use the table fromElement and the property name to get the array of column names. String tableAlias = getLhs().getFromElement().getTableAlias(); columns = getFromElement().toColumns( tableAlias, propertyPath, false ); } return columns; }
/** * Resolves the left hand side of the DOT. * * @throws SemanticException */ @Override public void resolveFirstChild() throws SemanticException { FromReferenceNode lhs = (FromReferenceNode) getFirstChild(); SqlNode property = (SqlNode) lhs.getNextSibling(); // Set the attributes of the property reference expression. String propName = property.getText(); propertyName = propName; // If the uresolved property path isn't set yet, just use the property name. if ( propertyPath == null ) { propertyPath = propName; } // Resolve the LHS fully, generate implicit joins. Pass in the property name so that the resolver can // discover foreign key (id) properties. lhs.resolve( true, true, null, this ); setFromElement( lhs.getFromElement() ); // The 'from element' that the property is in. checkSubclassOrSuperclassPropertyReference( lhs, propName ); }
@Override protected AST lookupProperty(AST dot, boolean root, boolean inSelect) throws SemanticException { DotNode dotNode = ( DotNode ) dot; FromReferenceNode lhs = dotNode.getLhs(); AST rhs = lhs.getNextSibling(); switch ( rhs.getType() ) { case SqlTokenTypes.ELEMENTS: case SqlTokenTypes.INDICES: if (LOG.isDebugEnabled()) LOG.debugf("lookupProperty() %s => %s(%s)", dotNode.getPath(), rhs.getText(), lhs.getPath()); CollectionFunction f = ( CollectionFunction ) rhs; // Re-arrange the tree so that the collection function is the root and the lhs is the path. f.setFirstChild( lhs ); lhs.setNextSibling( null ); dotNode.setFirstChild( f ); resolve( lhs ); // Don't forget to resolve the argument! f.resolve( inSelect ); // Resolve the collection function now. return f; default: // Resolve everything up to this dot, but don't resolve the placeholders yet. dotNode.resolveFirstChild(); return dotNode; } }
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 ); }
@Override protected void resolveSelectExpression(AST node) throws SemanticException { // This is called when it's time to fully resolve a path expression. int type = node.getType(); switch ( type ) { case DOT: { DotNode dot = (DotNode) node; dot.resolveSelectExpression(); break; } case ALIAS_REF: { // Notify the FROM element that it is being referenced by the select. FromReferenceNode aliasRefNode = (FromReferenceNode) node; //aliasRefNode.resolve( false, false, aliasRefNode.getText() ); //TODO: is it kosher to do it here? aliasRefNode.resolve( false, false ); //TODO: is it kosher to do it here? FromElement fromElement = aliasRefNode.getFromElement(); if ( fromElement != null ) { fromElement.setIncludeSubclasses( true ); } break; } default: { break; } } }
private void checkLhsIsNotCollection() throws SemanticException { if ( getLhs().getDataType() != null && getLhs().getDataType().isCollectionType() ) { throw ILLEGAL_COLL_DEREF_EXCP_BUILDER.buildIllegalCollectionDereferenceException( propertyName, getLhs() ); } }
/** * Returns the full path of the node. * * @return the full path of the node. */ @Override public String getPath() { if ( path == null ) { FromReferenceNode lhs = getLhs(); if ( lhs == null ) { path = getText(); } else { SqlNode rhs = (SqlNode) lhs.getNextSibling(); path = lhs.getPath() + "." + rhs.getOriginalText(); } } return path; }
private boolean resolveAsNakedComponentPropertyRefRHS(DotNode parent) { FromElement fromElement = locateSingleFromElement(); if (fromElement == null) { return false; } Type propertyType; String propertyPath = parent.getLhs().getText() + "." + getText(); try { // check to see if our "propPath" actually // represents a property on the persister propertyType = fromElement.getPropertyType(getText(), propertyPath); } catch (Throwable t) { // assume we do *not* refer to a property on the given persister return false; } setFromElement(fromElement); // this piece is needed for usage in select clause super.setDataType(propertyType); nakedPropertyRef = true; return true; }
checkSubclassOrSuperclassPropertyReference( lhs, lhs.getNextSibling().getText() ); lhs = (FromReferenceNode) lhs.getFirstChild();
@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 ); } }
); ( (FromReferenceNode) path ).setFromElement( join ); dot.getLhs().getFromElement(), dot.getPropertyPath(), alias == null ? null : alias.getText(),