use of org.datanucleus.store.rdbms.sql.expression.SQLExpression in project datanucleus-rdbms by datanucleus.
the class TemporalYearMethod4 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();
SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
funcArgs.add(exprFactory.newLiteral(stmt, mapping, "%Y"));
funcArgs.add(invokedExpr);
return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "strftime", funcArgs);
}
use of org.datanucleus.store.rdbms.sql.expression.SQLExpression in project datanucleus-rdbms by datanucleus.
the class TemporalYearMethod5 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");
invokedExpr.toSQLText().prepend("YEAR FROM ");
ArrayList funcArgs = new ArrayList();
funcArgs.add(invokedExpr);
return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "EXTRACT", funcArgs);
}
use of org.datanucleus.store.rdbms.sql.expression.SQLExpression in project datanucleus-rdbms by datanucleus.
the class Concat3Operation 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) {
/*
* We cast it to VARCHAR otherwise the concatenation in derby it is promoted to LONG VARCHAR.
*
* In Derby, ? string parameters are promoted to LONG VARCHAR, and Derby
* does not allow comparisons between LONG VARCHAR types. so the below
* example would be invalid in Derby
* (THIS.FIRSTNAME||?) = ?
*
* Due to that we convert it to
* (CAST(THIS.FIRSTNAME||? AS VARCHAR(4000))) = ?
*
* The only issue with this solution is for columns bigger than 4000 chars.
* Secondly, if both operands are parameters, derby does not allow concatenation e.g.
* ? || ? is not allowed by derby
*
* so we do
* CAST(? AS VARCHAR(4000)) || CAST(? AS VARCHAR(4000))
*
* If both situations happen,
* (CAST(CAST( ? AS VARCHAR(4000) ) || CAST( ? AS VARCHAR(4000) ) AS VARCHAR(4000))) = ?
*/
JavaTypeMapping m = expr.getSQLStatement().getSQLExpressionFactory().getMappingForType(String.class, false);
List types = new ArrayList();
types.add("VARCHAR(4000)");
List argsOp1 = new ArrayList();
argsOp1.add(expr);
SQLExpression firstExpr = new StringExpression(expr.getSQLStatement(), m, "CAST", argsOp1, types).encloseInParentheses();
List argsOp2 = new ArrayList();
argsOp2.add(expr2);
SQLExpression secondExpr = new StringExpression(expr.getSQLStatement(), m, "CAST", argsOp2, types).encloseInParentheses();
StringExpression concatExpr = new StringExpression(expr.getSQLStatement(), null, null);
SQLText sql = concatExpr.toSQLText();
sql.clearStatement();
sql.append(firstExpr);
sql.append("||");
sql.append(secondExpr);
List args = new ArrayList();
args.add(concatExpr);
return new StringExpression(expr.getSQLStatement(), m, "CAST", args, types);
}
use of org.datanucleus.store.rdbms.sql.expression.SQLExpression in project datanucleus-rdbms by datanucleus.
the class TemporalMonthJavaMethod5 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, "MONTH_JAVA");
expr.toSQLText().prepend("MONTH FROM ");
ArrayList funcArgs = new ArrayList();
funcArgs.add(invokedExpr);
return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "EXTRACT", funcArgs);
}
use of org.datanucleus.store.rdbms.sql.expression.SQLExpression in project datanucleus-rdbms by datanucleus.
the class TemporalMonthMethod 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, "MONTH");
ArrayList funcArgs = new ArrayList();
funcArgs.add(invokedExpr);
return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class, true), "MONTH", funcArgs);
}
Aggregations