Search in sources :

Example 21 with StringExpression

use of org.datanucleus.store.rdbms.sql.expression.StringExpression 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 22 with StringExpression

use of org.datanucleus.store.rdbms.sql.expression.StringExpression 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 23 with StringExpression

use of org.datanucleus.store.rdbms.sql.expression.StringExpression 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 24 with StringExpression

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

the class TemporalYearMethod2 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, "YEAR");
    RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
    JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(String.class);
    ArrayList funcArgs = new ArrayList();
    funcArgs.add(invokedExpr);
    SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
    funcArgs.add(exprFactory.newLiteral(stmt, mapping, "YYYY"));
    ArrayList funcArgs2 = new ArrayList();
    funcArgs2.add(new StringExpression(stmt, mapping, "TO_CHAR", funcArgs));
    return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "TO_NUMBER", funcArgs2);
}
Also used : SQLExpressionFactory(org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) StringExpression(org.datanucleus.store.rdbms.sql.expression.StringExpression) ArrayList(java.util.ArrayList) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

Example 25 with StringExpression

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

the class Concat2Operation 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) {
    RDBMSStoreManager storeMgr = expr.getSQLStatement().getRDBMSManager();
    JavaTypeMapping m = storeMgr.getSQLExpressionFactory().getMappingForType(String.class, false);
    ArrayList args = new ArrayList();
    args.add(expr);
    args.add(expr2);
    return new StringExpression(expr.getSQLStatement(), m, "CONCAT", args);
}
Also used : JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) StringExpression(org.datanucleus.store.rdbms.sql.expression.StringExpression) ArrayList(java.util.ArrayList) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

Aggregations

StringExpression (org.datanucleus.store.rdbms.sql.expression.StringExpression)43 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)33 ArrayList (java.util.ArrayList)29 NucleusException (org.datanucleus.exceptions.NucleusException)28 NumericExpression (org.datanucleus.store.rdbms.sql.expression.NumericExpression)24 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)23 SQLExpressionFactory (org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory)23 CharacterExpression (org.datanucleus.store.rdbms.sql.expression.CharacterExpression)18 ParameterLiteral (org.datanucleus.store.rdbms.sql.expression.ParameterLiteral)16 StringLiteral (org.datanucleus.store.rdbms.sql.expression.StringLiteral)12 BooleanExpression (org.datanucleus.store.rdbms.sql.expression.BooleanExpression)9 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)8 TemporalExpression (org.datanucleus.store.rdbms.sql.expression.TemporalExpression)8 List (java.util.List)7 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)5 IntegerLiteral (org.datanucleus.store.rdbms.sql.expression.IntegerLiteral)5 SQLLiteral (org.datanucleus.store.rdbms.sql.expression.SQLLiteral)5 UnboundExpression (org.datanucleus.store.rdbms.sql.expression.UnboundExpression)5 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)4 EnumExpression (org.datanucleus.store.rdbms.sql.expression.EnumExpression)4