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);
}
}
}
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());
}
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);
}
}
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);
}
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);
}
}
Aggregations