private void checkForDuplicateClassAlias(String classAlias) throws SemanticException { if ( classAlias != null && fromElementByClassAlias.containsKey( classAlias ) ) { throw new SemanticException( "Duplicate definition of alias '" + classAlias + "'" ); } }
/** * Set the select expression that defines the result variable. * * @param selectExpression the select expression; * selectExpression.getAlias() must be non-null * @throws SemanticException if selectExpression or * selectExpression.getAlias() is null. */ public void setSelectExpression(SelectExpression selectExpression) throws SemanticException { if ( selectExpression == null || selectExpression.getAlias() == null ) { throw new SemanticException( "A ResultVariableRefNode must refer to a non-null alias." ); } this.selectExpression = selectExpression; }
protected SemanticException nonMap() { return new SemanticException( expressionDescription() + " expression did not reference map property" ); }
@Override public void resolve( boolean generateJoin, boolean implicitJoin, String classAlias, AST parent, AST parentPredicate) throws SemanticException { if (parent != null) { throw new SemanticException( expressionDescription() + " expression cannot be further de-referenced" ); } super.resolve(generateJoin, implicitJoin, classAlias, parent, parentPredicate); }
@Override protected void validateMapPropertyExpression(AST node) throws SemanticException { try { FromReferenceNode fromReferenceNode = (FromReferenceNode) node; QueryableCollection collectionPersister = fromReferenceNode.getFromElement().getQueryableCollection(); if ( !Map.class.isAssignableFrom( collectionPersister.getCollectionType().getReturnedClass() ) ) { throw new SemanticException( "node did not reference a map" ); } } catch (SemanticException se) { throw se; } catch (Throwable t) { throw new SemanticException( "node did not reference a map" ); } }
@Override protected void handleResultVariableRef(AST resultVariableRef) throws SemanticException { if ( isSubQuery() ) { throw new SemanticException( "References to result variables in subqueries are not supported." ); } ( (ResultVariableRefNode) resultVariableRef ).setSelectExpression( selectExpressionsByResultVariable.get( resultVariableRef.getText() ) ); }
private void error(String msg) throws TokenStreamException, SemanticException { Token token = LT(0); throw new SemanticException( msg, token.getFilename(), token.getLine(), token.getColumn() ); }
public void resolve(boolean inSelect) throws SemanticException { initializeMethodNode( this, inSelect ); if ( !isCollectionPropertyMethod() ) { throw new SemanticException( this.getText() + " is not a collection property name!" ); } AST expr = getFirstChild(); if ( expr == null ) { throw new SemanticException( this.getText() + " requires a path!" ); } resolveCollectionProperty( expr ); }
/** * Performs the operator node initialization by seeking out any parameter * nodes and setting their expected type, if possible. */ @Override public void initialize() throws SemanticException { final Node lhs = getLeftHandOperand(); if ( lhs == null ) { throw new SemanticException( "left-hand operand of a binary operator was null" ); } final Node rhs = getRightHandOperand(); if ( rhs == null ) { throw new SemanticException( "right-hand operand of a binary operator was null" ); } Type lhsType = extractDataType( lhs ); Type rhsType = extractDataType( rhs ); if ( lhsType == null ) { lhsType = rhsType; } if ( rhsType == null ) { rhsType = lhsType; } if ( ExpectedTypeAwareNode.class.isAssignableFrom( lhs.getClass() ) ) { ( (ExpectedTypeAwareNode) lhs ).setExpectedType( rhsType ); } if ( ExpectedTypeAwareNode.class.isAssignableFrom( rhs.getClass() ) ) { ( (ExpectedTypeAwareNode) rhs ).setExpectedType( lhsType ); } mutateRowValueConstructorSyntaxesIfNecessary( lhsType, rhsType ); }
private void collectionProperty(AST path, AST name) throws SemanticException { if ( path == null ) { throw new SemanticException( "Collection function " + name.getText() + " has no path!" ); } SqlNode expr = (SqlNode) path; Type type = expr.getDataType(); LOG.debugf( "collectionProperty() : name=%s type=%s", name, type ); resolveCollectionProperty( expr ); }
public void initialize() throws SemanticException { final Node fixture = getFixtureOperand(); if ( fixture == null ) { throw new SemanticException( "fixture operand of a between operator was null" ); throw new SemanticException( "low operand of a between operator was null" ); throw new SemanticException( "high operand of a between operator was null" );
private void typeDiscriminator(AST path) throws SemanticException { if ( path == null ) { throw new SemanticException( "type() discriminator reference has no path!" ); } FromReferenceNode pathAsFromReferenceNode = (FromReferenceNode) path; FromElement fromElement = pathAsFromReferenceNode.getFromElement(); TypeDiscriminatorMetadata typeDiscriminatorMetadata = fromElement.getTypeDiscriminatorMetadata(); setDataType( typeDiscriminatorMetadata.getResolutionType() ); setText( typeDiscriminatorMetadata.getSqlFragment() ); setType( SqlTokenTypes.SQL_TOKEN ); }
throw new SemanticException( "Expecting 'first' or 'last', but found '" + nullPrecedence_AST.getText() + "' as null ordering precedence." );
@Override protected AST generateNamedParameter(AST delimiterNode, AST nameNode) throws SemanticException { if ( getSessionFactoryHelper().isStrictJPAQLComplianceEnabled() && positionalParameters != null ) { throw new SemanticException( "Cannot mix positional and named parameters: " + queryTranslatorImpl.getQueryString() ); } final String name = nameNode.getText(); trackNamedParameterPositions( name ); // create the node initially with the param name so that it shows // appropriately in the "original text" attribute final ParameterNode parameter = (ParameterNode) astFactory.create( NAMED_PARAM, name ); parameter.setText( "?" ); final NamedParameterSpecification paramSpec = new NamedParameterSpecification( delimiterNode.getLine(), delimiterNode.getColumn(), name ); parameter.setHqlParameterSpecification( paramSpec ); parameterSpecs.add( paramSpec ); return parameter; }
throw new SemanticException( "Expecting 'first' or 'last', but found '" + nullPrecedence_AST.getText() + "' as null ordering precedence." );
match(CLOSE); if (!( i.getText().equalsIgnoreCase("treat") )) throw new SemanticException(" i.getText().equalsIgnoreCase(\"treat\") ");
private void handleWithFragment(FromElement fromElement, AST hqlWithNode) throws SemanticException { try { withClause( hqlWithNode ); AST hqlSqlWithNode = returnAST; if ( LOG.isDebugEnabled() ) { LOG.debug( "handleWithFragment() : " + getASTPrinter().showAsString( hqlSqlWithNode, "-- with clause --" ) ); } WithClauseVisitor visitor = new WithClauseVisitor( fromElement, queryTranslatorImpl ); NodeTraverser traverser = new NodeTraverser( visitor ); traverser.traverseDepthFirst( hqlSqlWithNode ); SqlGenerator sql = new SqlGenerator( getSessionFactoryHelper().getFactory() ); sql.whereExpr( hqlSqlWithNode.getFirstChild() ); fromElement.setWithClauseFragment( "(" + sql.getSQL() + ")" ); } catch (SemanticException e) { throw e; } catch (InvalidWithClauseException e) { throw e; } catch (Exception e) { throw new SemanticException( e.getMessage() ); } }
private Constructor resolveConstructor(String path) throws SemanticException { String importedClassName = getSessionFactoryHelper().getImportedClassName( path ); String className = StringHelper.isEmpty( importedClassName ) ? path : importedClassName; if ( className == null ) { throw new SemanticException( "Unable to locate class [" + path + "]" ); } try { final Class holderClass = getSessionFactoryHelper().getFactory() .getServiceRegistry() .getService( ClassLoaderService.class ) .classForName( className ); return ReflectHelper.getConstructor( holderClass, constructorArgumentTypes ); } catch (ClassLoadingException e) { throw new DetailedSemanticException( "Unable to locate class [" + className + "]", e ); } catch (PropertyNotFoundException e) { // this is the exception returned by ReflectHelper.getConstructor() if it cannot // locate an appropriate constructor throw new DetailedSemanticException( formatMissingContructorExceptionMessage( className ), e ); } }
throw new SemanticException("Collection expected; [" + propertyName + "] does not refer to a collection property");
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; }