Search in sources :

Example 1 with InputParameter

use of org.eclipse.persistence.jpa.jpql.parser.InputParameter in project eclipselink by eclipse-ee4j.

the class HermesParser method addArguments.

/**
 * Registers the input parameters derived from the JPQL expression with the {@link DatabaseQuery}.
 *
 * @param queryContext The {@link JPQLQueryContext} containing the information about the JPQL query
 * @param databaseQuery The EclipseLink {@link DatabaseQuery} where the input parameter types are added
 */
private void addArguments(JPQLQueryContext queryContext, DatabaseQuery databaseQuery) {
    if (queryContext.inputParameters != null) {
        for (Map.Entry<InputParameter, Expression> entry : queryContext.inputParameters.entrySet()) {
            ParameterExpression parameter = (ParameterExpression) entry.getValue();
            databaseQuery.addArgument(parameter.getField().getName(), (Class<?>) parameter.getType(), entry.getKey().isPositional() ? ParameterType.POSITIONAL : ParameterType.NAMED);
        }
    }
}
Also used : ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression) Expression(org.eclipse.persistence.expressions.Expression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) ParameterExpression(org.eclipse.persistence.internal.expressions.ParameterExpression) Map(java.util.Map) InputParameter(org.eclipse.persistence.jpa.jpql.parser.InputParameter)

Example 2 with InputParameter

use of org.eclipse.persistence.jpa.jpql.parser.InputParameter in project eclipselink by eclipse-ee4j.

the class AbstractGrammarValidator method validateInputParameters.

protected void validateInputParameters(JPQLExpression expression) {
    int positionalCount = 0;
    int namedCount = 0;
    for (InputParameter inputParameter : inputParameters) {
        if (inputParameter.isNamed()) {
            namedCount++;
        } else if (inputParameter.isPositional()) {
            positionalCount++;
        }
    }
    if ((positionalCount > 0) && (namedCount > 0)) {
        for (InputParameter parameter : inputParameters) {
            addProblem(parameter, InputParameter_Mixture);
        }
    }
}
Also used : InputParameter(org.eclipse.persistence.jpa.jpql.parser.InputParameter)

Example 3 with InputParameter

use of org.eclipse.persistence.jpa.jpql.parser.InputParameter in project eclipselink by eclipse-ee4j.

the class AbstractJPQLQueryHelper method getParameterType.

/**
 * Retrieves, if it can be determined, the type of the given input parameter with the given name.
 * The type will be guessed based on its location within expression.
 * <p>
 * Note: Both named and positional input parameter can be used.
 *
 * @param parameterName The name of the input parameter to retrieve its type, which needs to be
 * prepended by ':' or '?'
 * @return Either the closest type of the input parameter or <code>null</code> if the type
 * couldn't be determined
 */
public IType getParameterType(String parameterName) {
    // Retrieve the input parameter's qualifier (':' or '?')
    char character = parameterName.length() > 0 ? parameterName.charAt(0) : '\0';
    // Does not begin with either ':' or '?'
    if ((character != ':') && (character != '?')) {
        return getTypeHelper().objectType();
    }
    // Find the InputParameters with the given parameter name
    Collection<InputParameter> inputParameters = getQueryContext().findInputParameters(parameterName);
    // No InputParameter was found
    if (inputParameters.isEmpty()) {
        return getTypeHelper().objectType();
    }
    // Now find the closest type for each location
    TreeSet<IType> types = new TreeSet<>(buildNumericTypeComparator());
    for (InputParameter inputParameter : inputParameters) {
        IType type = queryContext.getParameterType(inputParameter);
        // The first :name cannot be used to calculate the type
        if (type.isResolvable()) {
            types.add(type);
        }
    }
    return types.isEmpty() ? getTypeHelper().objectType() : types.first();
}
Also used : TreeSet(java.util.TreeSet) InputParameter(org.eclipse.persistence.jpa.jpql.parser.InputParameter) IType(org.eclipse.persistence.jpa.jpql.tools.spi.IType)

Aggregations

InputParameter (org.eclipse.persistence.jpa.jpql.parser.InputParameter)3 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 Expression (org.eclipse.persistence.expressions.Expression)1 ParameterExpression (org.eclipse.persistence.internal.expressions.ParameterExpression)1 JPQLExpression (org.eclipse.persistence.jpa.jpql.parser.JPQLExpression)1 IType (org.eclipse.persistence.jpa.jpql.tools.spi.IType)1