Search in sources :

Example 11 with StringLiteral

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

the class NumericToString2Operation method getExpression.

/* (non-Javadoc)
     * @see org.datanucleus.store.rdbms.sql.operation.SQLOperation#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, org.datanucleus.store.rdbms.sql.expression.SQLExpression)
     */
public SQLExpression getExpression(SQLExpression expr, SQLExpression expr2) {
    SQLExpressionFactory exprFactory = expr.getSQLStatement().getSQLExpressionFactory();
    JavaTypeMapping m = exprFactory.getMappingForType(String.class, false);
    if (expr instanceof SQLLiteral) {
        // Just convert the literal value directly
        if (((SQLLiteral) expr).getValue() == null) {
            return new StringLiteral(expr.getSQLStatement(), m, null, null);
        }
        return new StringLiteral(expr.getSQLStatement(), m, ((SQLLiteral) expr).getValue().toString(), null);
    }
    List args = new ArrayList();
    args.add(expr);
    List types = new ArrayList();
    types.add("CHAR(4000)");
    return new StringExpression(expr.getSQLStatement(), m, "CAST", args, types);
}
Also used : SQLExpressionFactory(org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory) StringLiteral(org.datanucleus.store.rdbms.sql.expression.StringLiteral) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) StringExpression(org.datanucleus.store.rdbms.sql.expression.StringExpression) ArrayList(java.util.ArrayList) SQLLiteral(org.datanucleus.store.rdbms.sql.expression.SQLLiteral) List(java.util.List) ArrayList(java.util.ArrayList)

Example 12 with StringLiteral

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

the class NumericToString3Operation method getExpression.

/* (non-Javadoc)
     * @see org.datanucleus.store.rdbms.sql.operation.SQLOperation#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, org.datanucleus.store.rdbms.sql.expression.SQLExpression)
     */
public SQLExpression getExpression(SQLExpression expr, SQLExpression expr2) {
    SQLExpressionFactory exprFactory = expr.getSQLStatement().getSQLExpressionFactory();
    JavaTypeMapping m = exprFactory.getMappingForType(String.class, false);
    if (expr instanceof SQLLiteral) {
        // Just convert the literal value directly
        if (((SQLLiteral) expr).getValue() == null) {
            return new StringLiteral(expr.getSQLStatement(), m, null, null);
        }
        return new StringLiteral(expr.getSQLStatement(), m, ((SQLLiteral) expr).getValue().toString(), null);
    }
    List args = new ArrayList();
    args.add(expr);
    List trimArgs = new ArrayList();
    trimArgs.add(new StringExpression(expr.getSQLStatement(), m, "CHAR", args));
    return new StringExpression(expr.getSQLStatement(), m, "RTRIM", trimArgs);
}
Also used : SQLExpressionFactory(org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory) StringLiteral(org.datanucleus.store.rdbms.sql.expression.StringLiteral) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) StringExpression(org.datanucleus.store.rdbms.sql.expression.StringExpression) ArrayList(java.util.ArrayList) SQLLiteral(org.datanucleus.store.rdbms.sql.expression.SQLLiteral) List(java.util.List) ArrayList(java.util.ArrayList)

Example 13 with StringLiteral

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

the class NumericToStringOperation method getExpression.

/* (non-Javadoc)
     * @see org.datanucleus.store.rdbms.sql.operation.SQLOperation#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, org.datanucleus.store.rdbms.sql.expression.SQLExpression)
     */
public SQLExpression getExpression(SQLExpression expr, SQLExpression expr2) {
    JavaTypeMapping m = expr.getSQLStatement().getSQLExpressionFactory().getMappingForType(String.class, false);
    if (expr instanceof SQLLiteral) {
        // Just convert the literal value directly
        if (((SQLLiteral) expr).getValue() == null) {
            return new StringLiteral(expr.getSQLStatement(), m, null, null);
        }
        return new StringLiteral(expr.getSQLStatement(), m, ((SQLLiteral) expr).getValue().toString(), null);
    }
    List args = new ArrayList();
    args.add(expr);
    List types = new ArrayList();
    types.add("VARCHAR(4000)");
    return new StringExpression(expr.getSQLStatement(), m, "CAST", args, types);
}
Also used : StringLiteral(org.datanucleus.store.rdbms.sql.expression.StringLiteral) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) StringExpression(org.datanucleus.store.rdbms.sql.expression.StringExpression) ArrayList(java.util.ArrayList) SQLLiteral(org.datanucleus.store.rdbms.sql.expression.SQLLiteral) List(java.util.List) ArrayList(java.util.ArrayList)

Example 14 with StringLiteral

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

the class TemporalMinuteMethod4 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) {
    SQLExpression invokedExpr = getInvokedExpression(expr, args, "MINUTE");
    RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
    JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(String.class);
    SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
    SQLExpression mi = exprFactory.newLiteral(stmt, mapping, "mi");
    ((StringLiteral) mi).generateStatementWithoutQuotes();
    ArrayList funcArgs = new ArrayList();
    funcArgs.add(mi);
    // CAST {invokedExpr} AS DATETIME
    List castArgs = new ArrayList<>();
    castArgs.add(invokedExpr);
    funcArgs.add(new TemporalExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(Date.class, true), "CAST", castArgs, asList("DATETIME")));
    return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "DATEPART", funcArgs);
}
Also used : TemporalExpression(org.datanucleus.store.rdbms.sql.expression.TemporalExpression) SQLExpressionFactory(org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) StringLiteral(org.datanucleus.store.rdbms.sql.expression.StringLiteral) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) ArrayList(java.util.ArrayList) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression) List(java.util.List) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

Example 15 with StringLiteral

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

the class TemporalSecondMethod4 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) {
    SQLExpression invokedExpr = getInvokedExpression(expr, args, "SECOND");
    RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
    JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(String.class);
    SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
    SQLExpression ss = exprFactory.newLiteral(stmt, mapping, "ss");
    ((StringLiteral) ss).generateStatementWithoutQuotes();
    List funcArgs = new ArrayList<>();
    funcArgs.add(ss);
    // CAST {invokedExpr} AS DATETIME
    List castArgs = new ArrayList<>();
    castArgs.add(invokedExpr);
    funcArgs.add(new TemporalExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(Date.class, true), "CAST", castArgs, asList("DATETIME")));
    return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "DATEPART", funcArgs);
}
Also used : TemporalExpression(org.datanucleus.store.rdbms.sql.expression.TemporalExpression) SQLExpressionFactory(org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) StringLiteral(org.datanucleus.store.rdbms.sql.expression.StringLiteral) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) ArrayList(java.util.ArrayList) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression) List(java.util.List) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

Aggregations

StringLiteral (org.datanucleus.store.rdbms.sql.expression.StringLiteral)25 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)21 SQLExpressionFactory (org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory)16 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)14 ArrayList (java.util.ArrayList)13 NucleusException (org.datanucleus.exceptions.NucleusException)13 StringExpression (org.datanucleus.store.rdbms.sql.expression.StringExpression)12 NumericExpression (org.datanucleus.store.rdbms.sql.expression.NumericExpression)8 ParameterLiteral (org.datanucleus.store.rdbms.sql.expression.ParameterLiteral)7 List (java.util.List)6 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)6 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)6 SelectStatement (org.datanucleus.store.rdbms.sql.SelectStatement)6 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)5 NumericSubqueryExpression (org.datanucleus.store.rdbms.sql.expression.NumericSubqueryExpression)5 SQLLiteral (org.datanucleus.store.rdbms.sql.expression.SQLLiteral)5 IntegerLiteral (org.datanucleus.store.rdbms.sql.expression.IntegerLiteral)4 TemporalExpression (org.datanucleus.store.rdbms.sql.expression.TemporalExpression)4 Arrays.asList (java.util.Arrays.asList)3 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)3