Search in sources :

Example 46 with InvokeExpression

use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.

the class StringExpressionImpl method indexOf.

/* (non-Javadoc)
     * @see org.datanucleus.query.typesafe.StringExpression#indexOf(java.lang.String, int)
     */
public NumericExpression indexOf(String str, int pos) {
    List<org.datanucleus.query.expression.Expression> args = new ArrayList();
    args.add(new Literal(str));
    args.add(new Literal(pos));
    org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(queryExpr, "indexOf", args);
    return new NumericExpressionImpl<Integer>(invokeExpr);
}
Also used : InvokeExpression(org.datanucleus.query.expression.InvokeExpression) DyadicExpression(org.datanucleus.query.expression.DyadicExpression) NumericExpression(javax.jdo.query.NumericExpression) CharacterExpression(javax.jdo.query.CharacterExpression) InvokeExpression(org.datanucleus.query.expression.InvokeExpression) StringExpression(javax.jdo.query.StringExpression) PersistableExpression(javax.jdo.query.PersistableExpression) BooleanExpression(javax.jdo.query.BooleanExpression) Expression(javax.jdo.query.Expression) Literal(org.datanucleus.query.expression.Literal) ArrayList(java.util.ArrayList)

Example 47 with InvokeExpression

use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.

the class StringExpressionImpl method startsWith.

/* (non-Javadoc)
     * @see org.datanucleus.query.typesafe.StringExpression#startsWith(java.lang.String)
     */
public BooleanExpression startsWith(String str) {
    List<org.datanucleus.query.expression.Expression> args = new ArrayList();
    args.add(new Literal(str));
    org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(queryExpr, "startsWith", args);
    return new BooleanExpressionImpl(invokeExpr);
}
Also used : InvokeExpression(org.datanucleus.query.expression.InvokeExpression) DyadicExpression(org.datanucleus.query.expression.DyadicExpression) NumericExpression(javax.jdo.query.NumericExpression) CharacterExpression(javax.jdo.query.CharacterExpression) InvokeExpression(org.datanucleus.query.expression.InvokeExpression) StringExpression(javax.jdo.query.StringExpression) PersistableExpression(javax.jdo.query.PersistableExpression) BooleanExpression(javax.jdo.query.BooleanExpression) Expression(javax.jdo.query.Expression) Literal(org.datanucleus.query.expression.Literal) ArrayList(java.util.ArrayList)

Example 48 with InvokeExpression

use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.

the class StringExpressionImpl method equalsIgnoreCase.

/* (non-Javadoc)
     * @see org.datanucleus.query.typesafe.StringExpression#equalsIgnoreCase(java.lang.String)
     */
public BooleanExpression equalsIgnoreCase(String str) {
    List<org.datanucleus.query.expression.Expression> args = new ArrayList();
    args.add(new Literal(str));
    org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(queryExpr, "equalsIgnoreCase", args);
    return new BooleanExpressionImpl(invokeExpr);
}
Also used : InvokeExpression(org.datanucleus.query.expression.InvokeExpression) DyadicExpression(org.datanucleus.query.expression.DyadicExpression) NumericExpression(javax.jdo.query.NumericExpression) CharacterExpression(javax.jdo.query.CharacterExpression) InvokeExpression(org.datanucleus.query.expression.InvokeExpression) StringExpression(javax.jdo.query.StringExpression) PersistableExpression(javax.jdo.query.PersistableExpression) BooleanExpression(javax.jdo.query.BooleanExpression) Expression(javax.jdo.query.Expression) Literal(org.datanucleus.query.expression.Literal) ArrayList(java.util.ArrayList)

Example 49 with InvokeExpression

use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.

the class StringExpressionImpl method indexOf.

/* (non-Javadoc)
     * @see org.datanucleus.query.typesafe.StringExpression#indexOf(java.lang.String)
     */
public NumericExpression<Integer> indexOf(String str) {
    List<org.datanucleus.query.expression.Expression> args = new ArrayList();
    args.add(new Literal(str));
    org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(queryExpr, "indexOf", args);
    return new NumericExpressionImpl<Integer>(invokeExpr);
}
Also used : InvokeExpression(org.datanucleus.query.expression.InvokeExpression) DyadicExpression(org.datanucleus.query.expression.DyadicExpression) NumericExpression(javax.jdo.query.NumericExpression) CharacterExpression(javax.jdo.query.CharacterExpression) InvokeExpression(org.datanucleus.query.expression.InvokeExpression) StringExpression(javax.jdo.query.StringExpression) PersistableExpression(javax.jdo.query.PersistableExpression) BooleanExpression(javax.jdo.query.BooleanExpression) Expression(javax.jdo.query.Expression) Literal(org.datanucleus.query.expression.Literal) ArrayList(java.util.ArrayList)

Example 50 with InvokeExpression

use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-core by datanucleus.

the class TemporalSecondMethod method evaluate.

/* (non-Javadoc)
     * @see org.datanucleus.query.evaluator.memory.InvocationEvaluator#evaluate(org.datanucleus.query.expression.InvokeExpression, org.datanucleus.query.evaluator.memory.InMemoryExpressionEvaluator)
     */
public Object evaluate(InvokeExpression expr, Object invokedValue, InMemoryExpressionEvaluator eval) {
    if (invokedValue == null && expr.getArguments() != null) {
        // Specified as static function, so use argument of InvokeExpression
        List<Expression> argExprs = expr.getArguments();
        if (argExprs.size() > 1) {
            throw new NucleusUserException("Incorrect number of arguments to SECOND");
        }
        Expression argExpr = argExprs.get(0);
        invokedValue = eval.getValueForExpression(argExpr);
    }
    if (invokedValue == null) {
        return Boolean.FALSE;
    }
    if (!(invokedValue instanceof Date)) {
        throw new NucleusException(Localiser.msg("021011", expr.getOperation(), invokedValue.getClass().getName()));
    }
    if (invokedValue instanceof Date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime((Date) invokedValue);
        return Integer.valueOf(cal.get(Calendar.SECOND));
    } else if (invokedValue instanceof Calendar) {
        return Integer.valueOf(((Calendar) invokedValue).get(Calendar.SECOND));
    } else if (invokedValue instanceof LocalTime) {
        return ((LocalTime) invokedValue).getSecond();
    } else if (invokedValue instanceof LocalDateTime) {
        return ((LocalDateTime) invokedValue).getSecond();
    } else {
        throw new NucleusUserException("We do not currently support SECOND() with argument of type " + invokedValue.getClass().getName());
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) Expression(org.datanucleus.query.expression.Expression) InvokeExpression(org.datanucleus.query.expression.InvokeExpression) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) Calendar(java.util.Calendar) NucleusException(org.datanucleus.exceptions.NucleusException) Date(java.util.Date)

Aggregations

InvokeExpression (org.datanucleus.query.expression.InvokeExpression)65 Literal (org.datanucleus.query.expression.Literal)42 DyadicExpression (org.datanucleus.query.expression.DyadicExpression)40 Expression (org.datanucleus.query.expression.Expression)39 PrimaryExpression (org.datanucleus.query.expression.PrimaryExpression)38 ParameterExpression (org.datanucleus.query.expression.ParameterExpression)37 NucleusException (org.datanucleus.exceptions.NucleusException)32 ArrayList (java.util.ArrayList)25 VariableExpression (org.datanucleus.query.expression.VariableExpression)21 BooleanExpression (javax.jdo.query.BooleanExpression)17 NumericExpression (javax.jdo.query.NumericExpression)17 PersistableExpression (javax.jdo.query.PersistableExpression)17 Expression (javax.jdo.query.Expression)15 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)13 OrderExpression (org.datanucleus.query.expression.OrderExpression)12 List (java.util.List)10 CharacterExpression (javax.jdo.query.CharacterExpression)10 StringExpression (javax.jdo.query.StringExpression)10 LocalDateTime (java.time.LocalDateTime)7 Calendar (java.util.Calendar)7