use of org.hibernate.param.ParameterSpecification 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 org.hibernate.param.ParameterSpecification in project hibernate-orm by hibernate.
the class BinaryLogicOperatorNode method mutateRowValueConstructorSyntax.
/**
* Mutate the subtree relating to a row-value-constructor to instead use
* a series of ANDed predicates. This allows multi-column type comparisons
* and explicit row-value-constructor syntax even on databases which do
* not support row-value-constructor.
* <p/>
* For example, here we'd mutate "... where (col1, col2) = ('val1', 'val2) ..." to
* "... where col1 = 'val1' and col2 = 'val2' ..."
*
* @param valueElements The number of elements in the row value constructor list.
*/
private void mutateRowValueConstructorSyntax(int valueElements) {
// mutation depends on the types of nodes involved...
int comparisonType = getType();
String comparisonText = getText();
switch(comparisonType) {
case HqlSqlTokenTypes.EQ:
setType(HqlSqlTokenTypes.AND);
setText("AND");
break;
case HqlSqlTokenTypes.NE:
setType(HqlSqlTokenTypes.OR);
setText("OR");
break;
default:
throw new QuerySyntaxException(comparisonText + " operator not supported on composite types.");
}
String[] lhsElementTexts = extractMutationTexts(getLeftHandOperand(), valueElements);
String[] rhsElementTexts = extractMutationTexts(getRightHandOperand(), valueElements);
ParameterSpecification lhsEmbeddedCompositeParameterSpecification = getLeftHandOperand() == null || (!ParameterNode.class.isInstance(getLeftHandOperand())) ? null : ((ParameterNode) getLeftHandOperand()).getHqlParameterSpecification();
ParameterSpecification rhsEmbeddedCompositeParameterSpecification = getRightHandOperand() == null || (!ParameterNode.class.isInstance(getRightHandOperand())) ? null : ((ParameterNode) getRightHandOperand()).getHqlParameterSpecification();
translate(valueElements, comparisonType, comparisonText, lhsElementTexts, rhsElementTexts, lhsEmbeddedCompositeParameterSpecification, rhsEmbeddedCompositeParameterSpecification, this);
}
Aggregations