use of org.datanucleus.store.rdbms.mapping.java.SQLFunctionMapping in project datanucleus-rdbms by datanucleus.
the class SQLFunctionMethod 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 args) {
if (args == null || args.size() < 1) {
throw new NucleusUserException("Cannot invoke SQL_function() without first argument defining the function");
}
SQLExpression expr = (SQLExpression) args.get(0);
if (!(expr instanceof StringLiteral)) {
throw new NucleusUserException("Cannot use SQL_function() without first argument defining the function");
}
String sql = (String) ((StringLiteral) expr).getValue();
List<SQLExpression> funcArgs = new ArrayList<>();
if (args.size() > 1) {
funcArgs.addAll(args.subList(1, args.size()));
}
// Return as ObjectExpression with an underlying SQLFunctionMapping
JavaTypeMapping m = new SQLFunctionMapping();
m.initialize(stmt.getRDBMSManager(), null);
ObjectExpression retExpr = new ObjectExpression(stmt, m, sql, funcArgs);
return retExpr;
}
Aggregations