Search in sources :

Example 1 with SemanticException

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

the class FromElementType method applyTreatAsDeclarations.

public void applyTreatAsDeclarations(Set<String> treatAsDeclarations) {
    if (treatAsDeclarations != null && !treatAsDeclarations.isEmpty()) {
        if (this.treatAsDeclarations == null) {
            this.treatAsDeclarations = new HashSet<String>();
        }
        for (String treatAsSubclassName : treatAsDeclarations) {
            try {
                EntityPersister subclassPersister = fromElement.getSessionFactoryHelper().requireClassPersister(treatAsSubclassName);
                this.treatAsDeclarations.add(subclassPersister.getEntityName());
            } catch (SemanticException e) {
                throw new QueryException("Unable to locate persister for subclass named in TREAT-AS : " + treatAsSubclassName);
            }
        }
        if (joinSequence != null) {
            joinSequence.applyTreatAsDeclarations(this.treatAsDeclarations);
        }
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) QueryException(org.hibernate.QueryException) SemanticException(antlr.SemanticException)

Example 2 with SemanticException

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

the class IdentNode method resolveIndex.

public void resolveIndex(AST parent) throws SemanticException {
    //      currently un-needed overhead.
    if (!(isResolved() && nakedPropertyRef)) {
        throw new UnsupportedOperationException();
    }
    String propertyName = getOriginalText();
    if (!getDataType().isCollectionType()) {
        throw new SemanticException("Collection expected; [" + propertyName + "] does not refer to a collection property");
    }
    // TODO : most of below was taken verbatim from DotNode; should either delegate this logic or super-type it
    CollectionType type = (CollectionType) getDataType();
    String role = type.getRole();
    QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection(role);
    // DotNode uses null here...
    String alias = null;
    String columnTableAlias = getFromElement().getTableAlias();
    JoinType joinType = JoinType.INNER_JOIN;
    boolean fetch = false;
    FromElementFactory factory = new FromElementFactory(getWalker().getCurrentFromClause(), getFromElement(), propertyName, alias, getFromElement().toColumns(columnTableAlias, propertyName, false), true);
    FromElement elem = factory.createCollection(queryableCollection, role, joinType, fetch, true);
    setFromElement(elem);
    // Always add the collection's query spaces.
    getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces());
}
Also used : CollectionType(org.hibernate.type.CollectionType) QueryableCollection(org.hibernate.persister.collection.QueryableCollection) JoinType(org.hibernate.sql.JoinType) SemanticException(antlr.SemanticException)

Example 3 with SemanticException

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

the class InLogicOperatorNode method initialize.

@Override
public void initialize() throws SemanticException {
    final Node lhs = getLeftHandOperand();
    if (lhs == null) {
        throw new SemanticException("left-hand operand of in operator was null");
    }
    final Node inList = getInList();
    if (inList == null) {
        throw new SemanticException("right-hand operand of in operator was null");
    }
    // one-or-more params.
    if (SqlNode.class.isAssignableFrom(lhs.getClass())) {
        Type lhsType = ((SqlNode) lhs).getDataType();
        AST inListChild = inList.getFirstChild();
        while (inListChild != null) {
            if (ExpectedTypeAwareNode.class.isAssignableFrom(inListChild.getClass())) {
                ((ExpectedTypeAwareNode) inListChild).setExpectedType(lhsType);
            }
            // fix for HHH-9605
            if (CollectionFunction.class.isInstance(inListChild) && ExpectedTypeAwareNode.class.isInstance(lhs)) {
                final Type rhsType = ((CollectionFunction) inListChild).getDataType();
                ((ExpectedTypeAwareNode) lhs).setExpectedType(rhsType);
            }
            inListChild = inListChild.getNextSibling();
        }
    }
    final SessionFactoryImplementor sessionFactory = getSessionFactoryHelper().getFactory();
    if (sessionFactory.getDialect().supportsRowValueConstructorSyntaxInInList()) {
        return;
    }
    final Type lhsType = extractDataType(lhs);
    if (lhsType == null) {
        return;
    }
    final int lhsColumnSpan = lhsType.getColumnSpan(sessionFactory);
    final Node rhsNode = (Node) inList.getFirstChild();
    if (!isNodeAcceptable(rhsNode)) {
        return;
    }
    int rhsColumnSpan;
    if (rhsNode == null) {
        // early exit for empty IN list
        return;
    } else if (rhsNode.getType() == HqlTokenTypes.VECTOR_EXPR) {
        rhsColumnSpan = rhsNode.getNumberOfChildren();
    } else {
        final Type rhsType = extractDataType(rhsNode);
        if (rhsType == null) {
            return;
        }
        rhsColumnSpan = rhsType.getColumnSpan(sessionFactory);
    }
    if (lhsColumnSpan > 1 && rhsColumnSpan > 1) {
        mutateRowValueConstructorSyntaxInInListSyntax(lhsColumnSpan, rhsColumnSpan);
    }
}
Also used : Type(org.hibernate.type.Type) AST(antlr.collections.AST) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SemanticException(antlr.SemanticException)

Example 4 with SemanticException

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

the class CollectionFunction method resolve.

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);
}
Also used : AST(antlr.collections.AST) SemanticException(antlr.SemanticException)

Example 5 with SemanticException

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

the class ConstructorNode method resolveConstructor.

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) {
        // locate an appropriate constructor
        throw new DetailedSemanticException(formatMissingContructorExceptionMessage(className), e);
    }
}
Also used : PropertyNotFoundException(org.hibernate.PropertyNotFoundException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) DetailedSemanticException(org.hibernate.hql.internal.ast.DetailedSemanticException) SemanticException(antlr.SemanticException) DetailedSemanticException(org.hibernate.hql.internal.ast.DetailedSemanticException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

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