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