use of org.datanucleus.store.rdbms.sql.expression.NumericExpression in project datanucleus-rdbms by datanucleus.
the class SQLNumericMethod 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 ignore, List<SQLExpression> args) {
if (args == null || args.size() != 1) {
throw new NucleusUserException("Cannot invoke SQL_numeric() without a string argument");
}
SQLExpression expr = args.get(0);
if (!(expr instanceof StringLiteral)) {
throw new NucleusUserException("Cannot use SQL_numeric() without string argument");
}
String sql = (String) ((StringLiteral) expr).getValue();
JavaTypeMapping m = stmt.getSQLExpressionFactory().getMappingForType(boolean.class, false);
NumericExpression retExpr = new NumericExpression(stmt, m, sql);
return retExpr;
}
use of org.datanucleus.store.rdbms.sql.expression.NumericExpression in project datanucleus-rdbms by datanucleus.
the class TemoralMinuteMethod6 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 args) {
if (!(expr instanceof TemporalExpression)) {
throw new NucleusException(Localiser.msg("060001", "getMinute()", expr));
}
expr.toSQLText().prepend("MINUTE FROM ");
ArrayList funcArgs = new ArrayList();
funcArgs.add(expr);
return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "EXTRACT", funcArgs);
}
use of org.datanucleus.store.rdbms.sql.expression.NumericExpression in project datanucleus-rdbms by datanucleus.
the class TemporalDayMethod 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, "DAY");
ArrayList funcArgs = new ArrayList();
funcArgs.add(invokedExpr);
return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "DAY", funcArgs);
}
use of org.datanucleus.store.rdbms.sql.expression.NumericExpression in project datanucleus-rdbms by datanucleus.
the class TemporalDayOfWeekMethod 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, "DAY_OF_WEEK");
ArrayList funcArgs = new ArrayList();
funcArgs.add(invokedExpr);
return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "DAY_OF_WEEK", funcArgs);
}
use of org.datanucleus.store.rdbms.sql.expression.NumericExpression in project datanucleus-rdbms by datanucleus.
the class TemporalDayOfWeekMethod2 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, "DAY");
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, "dow"));
funcArgs.add(invokedExpr);
// Add one to the SQL "dow" (origin=0) to be compatible with Java Calendar day of week (origin=1)
SQLExpression one = ExpressionUtils.getLiteralForOne(stmt);
NumericExpression numExpr = new NumericExpression(new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "date_part", funcArgs), Expression.OP_ADD, one);
numExpr.encloseInParentheses();
return numExpr;
}
Aggregations