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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations