Search in sources :

Example 1 with SQLFunctionMapping

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;
}
Also used : SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) StringLiteral(org.datanucleus.store.rdbms.sql.expression.StringLiteral) JavaTypeMapping(org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) ArrayList(java.util.ArrayList) ObjectExpression(org.datanucleus.store.rdbms.sql.expression.ObjectExpression) SQLFunctionMapping(org.datanucleus.store.rdbms.mapping.java.SQLFunctionMapping)

Aggregations

ArrayList (java.util.ArrayList)1 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)1 SQLFunctionMapping (org.datanucleus.store.rdbms.mapping.java.SQLFunctionMapping)1 ObjectExpression (org.datanucleus.store.rdbms.sql.expression.ObjectExpression)1 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)1 StringLiteral (org.datanucleus.store.rdbms.sql.expression.StringLiteral)1