use of org.datanucleus.store.rdbms.sql.expression.NullLiteral in project datanucleus-rdbms by datanucleus.
the class MathLogMethod 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 Math.log without an argument");
}
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.log(originalValue)));
return new ByteLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
} else if (expr instanceof IntegerLiteral) {
int originalValue = ((Number) ((IntegerLiteral) expr).getValue()).intValue();
Double absValue = new Double(Math.log(originalValue));
return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
} else if (expr instanceof FloatingPointLiteral) {
double originalValue = ((BigDecimal) ((FloatingPointLiteral) expr).getValue()).doubleValue();
Double absValue = new Double(Math.log(originalValue));
return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
}
throw new IllegalExpressionOperationException("Math.log()", expr);
} else {
// Relay to the equivalent "log(expr)" function
SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
return exprFactory.invokeMethod(stmt, null, "log", null, args);
}
}
use of org.datanucleus.store.rdbms.sql.expression.NullLiteral in project datanucleus-rdbms by datanucleus.
the class MathPowerMethod 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 Math.power without an argument");
}
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.cos(originalValue)));
return new ByteLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
} else if (expr instanceof IntegerLiteral) {
int originalValue = ((Number) ((IntegerLiteral) expr).getValue()).intValue();
Double absValue = new Double(Math.cos(originalValue));
return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
} else if (expr instanceof FloatingPointLiteral) {
double originalValue = ((BigDecimal) ((FloatingPointLiteral) expr).getValue()).doubleValue();
Double absValue = new Double(Math.cos(originalValue));
return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
}
throw new IllegalExpressionOperationException("Math.power()", expr);
} else {
// Relay to the equivalent "cos(expr)" function
SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
return exprFactory.invokeMethod(stmt, null, "POWER", null, args);
}
}
use of org.datanucleus.store.rdbms.sql.expression.NullLiteral in project datanucleus-rdbms by datanucleus.
the class MathSinMethod 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 Math.sin without an argument");
}
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.sin(originalValue)));
return new ByteLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
} else if (expr instanceof IntegerLiteral) {
int originalValue = ((Number) ((IntegerLiteral) expr).getValue()).intValue();
Double absValue = new Double(Math.sin(originalValue));
return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
} else if (expr instanceof FloatingPointLiteral) {
double originalValue = ((BigDecimal) ((FloatingPointLiteral) expr).getValue()).doubleValue();
Double absValue = new Double(Math.sin(originalValue));
return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
}
throw new IllegalExpressionOperationException("Math.sin()", expr);
} else {
// Relay to the equivalent "sin(expr)" function
SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
return exprFactory.invokeMethod(stmt, null, "sin", null, args);
}
}
use of org.datanucleus.store.rdbms.sql.expression.NullLiteral in project datanucleus-rdbms by datanucleus.
the class MathTanMethod 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 Math.tan without an argument");
}
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.tan(originalValue)));
return new ByteLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
} else if (expr instanceof IntegerLiteral) {
int originalValue = ((Number) ((IntegerLiteral) expr).getValue()).intValue();
Double absValue = new Double(Math.tan(originalValue));
return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
} else if (expr instanceof FloatingPointLiteral) {
double originalValue = ((BigDecimal) ((FloatingPointLiteral) expr).getValue()).doubleValue();
Double absValue = new Double(Math.tan(originalValue));
return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
}
throw new IllegalExpressionOperationException("Math.tan()", expr);
} else {
// Relay to the equivalent "tan(expr)" function
SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
return exprFactory.invokeMethod(stmt, null, "tan", null, args);
}
}
use of org.datanucleus.store.rdbms.sql.expression.NullLiteral in project datanucleus-rdbms by datanucleus.
the class MathToRadiansMethod 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 Math.toRadians without an argument");
}
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.cos(originalValue)));
return new ByteLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
} else if (expr instanceof IntegerLiteral) {
int originalValue = ((Number) ((IntegerLiteral) expr).getValue()).intValue();
Double absValue = new Double(Math.cos(originalValue));
return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
} else if (expr instanceof FloatingPointLiteral) {
double originalValue = ((BigDecimal) ((FloatingPointLiteral) expr).getValue()).doubleValue();
Double absValue = new Double(Math.cos(originalValue));
return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
}
throw new IllegalExpressionOperationException("Math.toRadians()", expr);
} else {
// Relay to the equivalent "radians(expr)" function
SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
return exprFactory.invokeMethod(stmt, null, "radians", null, args);
}
}
Aggregations