Search in sources :

Example 6 with MapExpression

use of org.datanucleus.store.rdbms.sql.expression.MapExpression in project datanucleus-rdbms by datanucleus.

the class MapGetMethod 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) {
    if (args == null || args.size() == 0 || args.size() > 1) {
        throw new NucleusException(Localiser.msg("060016", "get", "MapExpression", 1));
    }
    MapExpression mapExpr = (MapExpression) expr;
    SQLExpression keyValExpr = args.get(0);
    if (keyValExpr instanceof UnboundExpression) {
        // TODO Add support for unbound variables (as per CollectionContains)
        throw new NucleusException("Dont currently support binding of unbound variables using Map.get");
    }
    if (mapExpr instanceof MapLiteral && keyValExpr instanceof SQLLiteral) {
        MapLiteral lit = (MapLiteral) expr;
        if (lit.getValue() == null) {
            return new NullLiteral(stmt, null, null, null);
        }
        return lit.getKeyLiteral().invoke("get", args);
    } else if (mapExpr instanceof MapLiteral) {
        // MapLiteral.get(SQLExpression)
        throw new NucleusUserException("We do not support MapLiteral.get(SQLExpression) since SQL doesnt allow such constructs");
    } else {
        if (stmt.getQueryGenerator().getCompilationComponent() == CompilationComponent.FILTER || stmt.getQueryGenerator().getCompilationComponent() == CompilationComponent.ORDERING) {
            return getAsInnerJoin(stmt, mapExpr, keyValExpr);
        } else if (stmt.getQueryGenerator().getCompilationComponent() == CompilationComponent.RESULT || stmt.getQueryGenerator().getCompilationComponent() == CompilationComponent.HAVING) {
            return getAsSubquery(stmt, mapExpr, keyValExpr);
        }
        throw new NucleusException("Map.get() is not supported for " + mapExpr + " with argument " + keyValExpr + " for query component " + stmt.getQueryGenerator().getCompilationComponent());
    }
}
Also used : MapExpression(org.datanucleus.store.rdbms.sql.expression.MapExpression) MapLiteral(org.datanucleus.store.rdbms.sql.expression.MapLiteral) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) SQLLiteral(org.datanucleus.store.rdbms.sql.expression.SQLLiteral) UnboundExpression(org.datanucleus.store.rdbms.sql.expression.UnboundExpression) NucleusException(org.datanucleus.exceptions.NucleusException) NullLiteral(org.datanucleus.store.rdbms.sql.expression.NullLiteral)

Aggregations

NucleusException (org.datanucleus.exceptions.NucleusException)6 MapExpression (org.datanucleus.store.rdbms.sql.expression.MapExpression)6 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)6 UnboundExpression (org.datanucleus.store.rdbms.sql.expression.UnboundExpression)5 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)4 BooleanExpression (org.datanucleus.store.rdbms.sql.expression.BooleanExpression)4 MapLiteral (org.datanucleus.store.rdbms.sql.expression.MapLiteral)4 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)4 Map (java.util.Map)3 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)3 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)3 BooleanLiteral (org.datanucleus.store.rdbms.sql.expression.BooleanLiteral)3 NullLiteral (org.datanucleus.store.rdbms.sql.expression.NullLiteral)3 NumericExpression (org.datanucleus.store.rdbms.sql.expression.NumericExpression)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)2 DyadicExpression (org.datanucleus.query.expression.DyadicExpression)2 InvokeExpression (org.datanucleus.query.expression.InvokeExpression)2 Literal (org.datanucleus.query.expression.Literal)2