use of org.datanucleus.store.rdbms.sql.expression.NumericExpression in project datanucleus-rdbms by datanucleus.
the class RoundMethod 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() == 0) {
throw new NucleusUserException("Cannot invoke ROUND without an argument");
} else if (args.size() > 2) {
throw new NucleusUserException("Cannot invoke ROUND with more than 2 arguments");
}
SQLExpression expr = args.get(0);
if (expr == null) {
return new NullLiteral(stmt, null, null, null);
} else if (expr instanceof SQLLiteral) {
if (expr instanceof ByteLiteral) {
int originalValue = ((BigInteger) ((ByteLiteral) expr).getValue()).intValue();
BigInteger absValue = new BigInteger(String.valueOf(Math.floor(originalValue)));
return new ByteLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
} else if (expr instanceof IntegerLiteral) {
int originalValue = ((Number) ((IntegerLiteral) expr).getValue()).intValue();
Double absValue = Double.valueOf(Math.floor(originalValue));
return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
} else if (expr instanceof FloatingPointLiteral) {
double originalValue = ((BigDecimal) ((FloatingPointLiteral) expr).getValue()).doubleValue();
Double absValue = Double.valueOf(Math.floor(originalValue));
return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
}
throw new IllegalExpressionOperationException("ROUND()", expr);
} else {
// Relay to the SQL "ROUND(expr)" function
Class numericType = int.class;
if (args.size() == 2) {
numericType = double.class;
}
return new NumericExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(numericType, true), "ROUND", args);
}
}
use of org.datanucleus.store.rdbms.sql.expression.NumericExpression in project datanucleus-rdbms by datanucleus.
the class QueryToSQLMapper method processBitAndExpression.
/* (non-Javadoc)
* @see org.datanucleus.query.evaluator.AbstractExpressionEvaluator#processBitAndExpression(org.datanucleus.query.expression.Expression)
*/
@Override
protected Object processBitAndExpression(Expression expr) {
SQLExpression rightExpr = stack.pop();
SQLExpression leftExpr = stack.pop();
if (rightExpr instanceof BooleanExpression && leftExpr instanceof BooleanExpression) {
// Handle as Boolean logical AND
stack.push(leftExpr);
stack.push(rightExpr);
return processAndExpression(expr);
} else if (rightExpr instanceof NumericExpression && leftExpr instanceof NumericExpression) {
if (storeMgr.getDatastoreAdapter().supportsOption(DatastoreAdapter.OPERATOR_BITWISE_AND)) {
SQLExpression bitAndExpr = new NumericExpression(leftExpr, Expression.OP_BIT_AND, rightExpr).encloseInParentheses();
stack.push(bitAndExpr);
return bitAndExpr;
}
}
throw new NucleusUserException("Operation BITWISE AND is not supported for " + leftExpr + " and " + rightExpr + " for this datastore");
}
Aggregations