Search in sources :

Example 11 with SemanticException

use of antlr.SemanticException in project hibernate-orm by hibernate.

the class HqlSqlWalker method validateMapPropertyExpression.

@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");
    }
}
Also used : FromReferenceNode(org.hibernate.hql.internal.ast.tree.FromReferenceNode) QueryableCollection(org.hibernate.persister.collection.QueryableCollection) Map(java.util.Map) HashMap(java.util.HashMap) SemanticException(antlr.SemanticException)

Example 12 with SemanticException

use of antlr.SemanticException in project hibernate-orm by hibernate.

the class HqlSqlWalker method prepareVersioned.

@Override
protected void prepareVersioned(AST updateNode, AST versioned) throws SemanticException {
    UpdateStatement updateStatement = (UpdateStatement) updateNode;
    FromClause fromClause = updateStatement.getFromClause();
    if (versioned != null) {
        // Make sure that the persister is versioned
        Queryable persister = fromClause.getFromElement().getQueryable();
        if (!persister.isVersioned()) {
            throw new SemanticException("increment option specified for update of non-versioned entity");
        }
        VersionType versionType = persister.getVersionType();
        if (versionType instanceof UserVersionType) {
            throw new SemanticException("user-defined version types not supported for increment option");
        }
        AST eq = getASTFactory().create(HqlSqlTokenTypes.EQ, "=");
        AST versionPropertyNode = generateVersionPropertyNode(persister);
        eq.setFirstChild(versionPropertyNode);
        AST versionIncrementNode = null;
        if (isTimestampBasedVersion(versionType)) {
            versionIncrementNode = getASTFactory().create(HqlSqlTokenTypes.PARAM, "?");
            ParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification(versionType);
            ((ParameterNode) versionIncrementNode).setHqlParameterSpecification(paramSpec);
            parameters.add(0, paramSpec);
        } else {
            // Not possible to simply re-use the versionPropertyNode here as it causes
            // OOM errors due to circularity :(
            versionIncrementNode = getASTFactory().create(HqlSqlTokenTypes.PLUS, "+");
            versionIncrementNode.setFirstChild(generateVersionPropertyNode(persister));
            versionIncrementNode.addChild(getASTFactory().create(HqlSqlTokenTypes.IDENT, "1"));
        }
        eq.addChild(versionIncrementNode);
        evaluateAssignment(eq, persister, 0);
        AST setClause = updateStatement.getSetClause();
        AST currentFirstSetElement = setClause.getFirstChild();
        setClause.setFirstChild(eq);
        eq.setNextSibling(currentFirstSetElement);
    }
}
Also used : UpdateStatement(org.hibernate.hql.internal.ast.tree.UpdateStatement) UserVersionType(org.hibernate.usertype.UserVersionType) AST(antlr.collections.AST) CollectionFilterKeyParameterSpecification(org.hibernate.param.CollectionFilterKeyParameterSpecification) ParameterSpecification(org.hibernate.param.ParameterSpecification) PositionalParameterSpecification(org.hibernate.param.PositionalParameterSpecification) VersionTypeSeedParameterSpecification(org.hibernate.param.VersionTypeSeedParameterSpecification) NamedParameterSpecification(org.hibernate.param.NamedParameterSpecification) VersionTypeSeedParameterSpecification(org.hibernate.param.VersionTypeSeedParameterSpecification) ParameterNode(org.hibernate.hql.internal.ast.tree.ParameterNode) FromClause(org.hibernate.hql.internal.ast.tree.FromClause) Queryable(org.hibernate.persister.entity.Queryable) UserVersionType(org.hibernate.usertype.UserVersionType) VersionType(org.hibernate.type.VersionType) SemanticException(antlr.SemanticException)

Example 13 with SemanticException

use of antlr.SemanticException in project hibernate-orm by hibernate.

the class BetweenOperatorNode method initialize.

public void initialize() throws SemanticException {
    final Node fixture = getFixtureOperand();
    if (fixture == null) {
        throw new SemanticException("fixture operand of a between operator was null");
    }
    final Node low = getLowOperand();
    if (low == null) {
        throw new SemanticException("low operand of a between operator was null");
    }
    final Node high = getHighOperand();
    if (high == null) {
        throw new SemanticException("high operand of a between operator was null");
    }
    Type expectedType = null;
    if (fixture instanceof SqlNode) {
        expectedType = ((SqlNode) fixture).getDataType();
    }
    if (expectedType == null && low instanceof SqlNode) {
        expectedType = ((SqlNode) low).getDataType();
    }
    if (expectedType == null && high instanceof SqlNode) {
        expectedType = ((SqlNode) high).getDataType();
    }
    if (fixture instanceof ExpectedTypeAwareNode) {
        ((ExpectedTypeAwareNode) fixture).setExpectedType(expectedType);
    }
    if (low instanceof ExpectedTypeAwareNode) {
        ((ExpectedTypeAwareNode) low).setExpectedType(expectedType);
    }
    if (high instanceof ExpectedTypeAwareNode) {
        ((ExpectedTypeAwareNode) high).setExpectedType(expectedType);
    }
}
Also used : Type(org.hibernate.type.Type) SemanticException(antlr.SemanticException)

Example 14 with SemanticException

use of antlr.SemanticException in project hibernate-orm by hibernate.

the class BinaryLogicOperatorNode method initialize.

/**
	 * 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);
}
Also used : OneToOneType(org.hibernate.type.OneToOneType) Type(org.hibernate.type.Type) SemanticException(antlr.SemanticException)

Example 15 with SemanticException

use of antlr.SemanticException in project hibernate-orm by hibernate.

the class HqlSqlWalker method handleWithFragment.

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());
    }
}
Also used : AST(antlr.collections.AST) NodeTraverser(org.hibernate.hql.internal.ast.util.NodeTraverser) RecognitionException(antlr.RecognitionException) QueryException(org.hibernate.QueryException) SemanticException(antlr.SemanticException) SemanticException(antlr.SemanticException)

Aggregations

SemanticException (antlr.SemanticException)17 Type (org.hibernate.type.Type)7 AST (antlr.collections.AST)6 QueryException (org.hibernate.QueryException)4 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)3 JoinType (org.hibernate.sql.JoinType)3 CollectionType (org.hibernate.type.CollectionType)3 RecognitionException (antlr.RecognitionException)2 FromReferenceNode (org.hibernate.hql.internal.ast.tree.FromReferenceNode)2 ParameterNode (org.hibernate.hql.internal.ast.tree.ParameterNode)2 ParameterSpecification (org.hibernate.param.ParameterSpecification)2 PositionalParameterSpecification (org.hibernate.param.PositionalParameterSpecification)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 CompositeType (org.hibernate.type.CompositeType)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PropertyNotFoundException (org.hibernate.PropertyNotFoundException)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1 JoinSequence (org.hibernate.engine.internal.JoinSequence)1