Search in sources :

Example 1 with PositionalParameterSpecification

use of org.hibernate.param.PositionalParameterSpecification in project hibernate-orm by hibernate.

the class HqlSqlWalker method generatePositionalParameter.

@Override
protected AST generatePositionalParameter(AST delimiterNode, AST numberNode) throws SemanticException {
    // todo : we check this multiple times
    if (getSessionFactoryHelper().isStrictJPAQLComplianceEnabled() && namedParameters != null) {
        throw new SemanticException("Cannot mix positional and named parameters: " + queryTranslatorImpl.getQueryString());
    }
    if (numberNode == null) {
        throw new QueryException(String.format(Locale.ROOT, ERROR_LEGACY_ORDINAL_PARAMS_NO_LONGER_SUPPORTED, queryTranslatorImpl.getQueryString()));
    }
    final String positionString = numberNode.getText();
    final int label = Integer.parseInt(positionString);
    trackPositionalParameterPositions(label);
    final ParameterNode parameter = (ParameterNode) astFactory.create(PARAM, positionString);
    parameter.setText("?");
    final int queryParamtersPosition = isFilter() ? label : label - 1;
    final PositionalParameterSpecification paramSpec = new PositionalParameterSpecification(delimiterNode.getLine(), delimiterNode.getColumn(), label, queryParamtersPosition);
    parameter.setHqlParameterSpecification(paramSpec);
    parameterSpecs.add(paramSpec);
    return parameter;
}
Also used : QueryException(org.hibernate.QueryException) ParameterNode(org.hibernate.hql.internal.ast.tree.ParameterNode) PositionalParameterSpecification(org.hibernate.param.PositionalParameterSpecification) SemanticException(antlr.SemanticException)

Aggregations

SemanticException (antlr.SemanticException)1 QueryException (org.hibernate.QueryException)1 ParameterNode (org.hibernate.hql.internal.ast.tree.ParameterNode)1 PositionalParameterSpecification (org.hibernate.param.PositionalParameterSpecification)1