Search in sources :

Example 26 with ParameterLiteral

use of org.datanucleus.store.rdbms.sql.expression.ParameterLiteral in project datanucleus-rdbms by datanucleus.

the class StringCharAtMethod method getExpression.

/* (non-Javadoc)
     * @see org.datanucleus.store.rdbms.sql.method.SQLMethod#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, java.util.List)
     */
public SQLExpression getExpression(SQLStatement stmt, SQLExpression expr, List<SQLExpression> args) {
    if (args == null || args.size() == 0 || args.size() > 1) {
        throw new NucleusException(Localiser.msg("060003", "charAt", "StringExpression", 0, "NumericExpression/IntegerLiteral/ParameterLiteral"));
    }
    // {strExpr}.charAt(numExpr)
    SQLExpression startExpr = args.get(0);
    if (!(startExpr instanceof NumericExpression) && !(startExpr instanceof ParameterLiteral)) {
        throw new NucleusException(Localiser.msg("060003", "charAt", "StringExpression", 0, "NumericExpression/IntegerLiteral/ParameterLiteral"));
    }
    SQLExpression endExpr = startExpr.add(ExpressionUtils.getLiteralForOne(stmt));
    // Invoke substring(startExpr, endExpr)
    List<SQLExpression> newArgs = new ArrayList<>(2);
    newArgs.add(startExpr);
    newArgs.add(endExpr);
    SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
    return exprFactory.invokeMethod(stmt, String.class.getName(), "substring", expr, newArgs);
}
Also used : ParameterLiteral(org.datanucleus.store.rdbms.sql.expression.ParameterLiteral) SQLExpressionFactory(org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression) ArrayList(java.util.ArrayList) NucleusException(org.datanucleus.exceptions.NucleusException)

Example 27 with ParameterLiteral

use of org.datanucleus.store.rdbms.sql.expression.ParameterLiteral in project datanucleus-rdbms by datanucleus.

the class StringStartsWith2Method method getExpression.

/* (non-Javadoc)
     * @see org.datanucleus.store.rdbms.sql.method.SQLMethod#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, java.util.List)
     */
public SQLExpression getExpression(SQLStatement stmt, SQLExpression expr, List<SQLExpression> args) {
    if (args == null || args.size() == 0 || args.size() > 2) {
        throw new NucleusException(Localiser.msg("060003", "startsWith", "StringExpression", 0, "StringExpression/CharacterExpression/Parameter"));
    }
    // {stringExpr}.indexOf(strExpr1 [,numExpr2])
    SQLExpression one = ExpressionUtils.getLiteralForOne(stmt);
    ArrayList funcArgs = new ArrayList();
    SQLExpression substrExpr = args.get(0);
    if (!(substrExpr instanceof StringExpression) && !(substrExpr instanceof CharacterExpression) && !(substrExpr instanceof ParameterLiteral)) {
        throw new NucleusException(Localiser.msg("060003", "startsWith", "StringExpression", 0, "StringExpression/CharacterExpression/Parameter"));
    }
    if (args.size() == 2) {
        NumericExpression numExpr = (NumericExpression) args.get(1);
        funcArgs.add(substrExpr);
        funcArgs.add(expr);
        return new BooleanExpression(new StringExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "CHARINDEX", funcArgs), Expression.OP_EQ, one.add(numExpr));
    }
    funcArgs.add(substrExpr);
    funcArgs.add(expr);
    return new BooleanExpression(new StringExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "CHARINDEX", funcArgs), Expression.OP_EQ, one);
}
Also used : BooleanExpression(org.datanucleus.store.rdbms.sql.expression.BooleanExpression) ParameterLiteral(org.datanucleus.store.rdbms.sql.expression.ParameterLiteral) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) StringExpression(org.datanucleus.store.rdbms.sql.expression.StringExpression) ArrayList(java.util.ArrayList) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression) NucleusException(org.datanucleus.exceptions.NucleusException) CharacterExpression(org.datanucleus.store.rdbms.sql.expression.CharacterExpression)

Aggregations

ParameterLiteral (org.datanucleus.store.rdbms.sql.expression.ParameterLiteral)27 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)23 NucleusException (org.datanucleus.exceptions.NucleusException)17 StringExpression (org.datanucleus.store.rdbms.sql.expression.StringExpression)16 ArrayList (java.util.ArrayList)15 CharacterExpression (org.datanucleus.store.rdbms.sql.expression.CharacterExpression)12 BooleanExpression (org.datanucleus.store.rdbms.sql.expression.BooleanExpression)11 NumericExpression (org.datanucleus.store.rdbms.sql.expression.NumericExpression)11 SQLExpressionFactory (org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory)7 StringLiteral (org.datanucleus.store.rdbms.sql.expression.StringLiteral)7 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)6 UnboundExpression (org.datanucleus.store.rdbms.sql.expression.UnboundExpression)6 IntegerLiteral (org.datanucleus.store.rdbms.sql.expression.IntegerLiteral)5 SQLLiteral (org.datanucleus.store.rdbms.sql.expression.SQLLiteral)4 DatastoreAdapter (org.datanucleus.store.rdbms.adapter.DatastoreAdapter)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 FetchPlanForClass (org.datanucleus.FetchPlanForClass)1