Search in sources :

Example 1 with SubqueryExpression

use of org.datanucleus.store.query.expression.SubqueryExpression in project datanucleus-rdbms by datanucleus.

the class QueryToSQLMapper method processSubqueryExpression.

/* (non-Javadoc)
     * @see org.datanucleus.query.evaluator.AbstractExpressionEvaluator#processSubqueryExpression(org.datanucleus.query.expression.SubqueryExpression)
     */
@Override
protected Object processSubqueryExpression(SubqueryExpression expr) {
    String keyword = expr.getKeyword();
    Expression subqueryExpr = expr.getRight();
    if (subqueryExpr instanceof VariableExpression) {
        processVariableExpression((VariableExpression) subqueryExpr);
        SQLExpression subquerySqlExpr = stack.pop();
        if (keyword.equals("EXISTS")) {
            // EXISTS expressions need to be Boolean
            if (subquerySqlExpr instanceof org.datanucleus.store.rdbms.sql.expression.SubqueryExpression) {
                SQLStatement subStmt = ((org.datanucleus.store.rdbms.sql.expression.SubqueryExpression) subquerySqlExpr).getSubqueryStatement();
                subquerySqlExpr = new BooleanSubqueryExpression(stmt, keyword, subStmt);
            } else {
                SQLStatement subStmt = ((SubqueryExpressionComponent) subquerySqlExpr).getSubqueryStatement();
                subquerySqlExpr = new BooleanSubqueryExpression(stmt, keyword, subStmt);
            }
        } else if (subquerySqlExpr instanceof org.datanucleus.store.rdbms.sql.expression.SubqueryExpression) {
            SQLStatement subStmt = ((org.datanucleus.store.rdbms.sql.expression.SubqueryExpression) subquerySqlExpr).getSubqueryStatement();
            subquerySqlExpr = new BooleanSubqueryExpression(stmt, keyword, subStmt);
        } else if (subquerySqlExpr instanceof NumericSubqueryExpression) {
            if ((keyword.equalsIgnoreCase("SOME") || keyword.equalsIgnoreCase("ALL") || keyword.equalsIgnoreCase("ANY")) && !storeMgr.getDatastoreAdapter().supportsOption(DatastoreAdapter.SOME_ANY_ALL_SUBQUERY_EXPRESSIONS)) {
                throw new NucleusException("'SOME|ALL|ANY{subquery}' is not supported by this datastore");
            }
            // Apply keyword (e.g ALL, SOME, ANY) to numeric expressions
            ((NumericSubqueryExpression) subquerySqlExpr).setKeyword(keyword);
        }
        stack.push(subquerySqlExpr);
        return subquerySqlExpr;
    }
    throw new NucleusException("Dont currently support SubqueryExpression " + keyword + " for type " + subqueryExpr);
}
Also used : SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) VariableExpression(org.datanucleus.store.query.expression.VariableExpression) SQLStatement(org.datanucleus.store.rdbms.sql.SQLStatement) NumericSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.NumericSubqueryExpression) BooleanSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.BooleanSubqueryExpression) NumericSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.NumericSubqueryExpression) StringSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.StringSubqueryExpression) TemporalSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.TemporalSubqueryExpression) SubqueryExpression(org.datanucleus.store.query.expression.SubqueryExpression) PrimaryExpression(org.datanucleus.store.query.expression.PrimaryExpression) BooleanSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.BooleanSubqueryExpression) TypeConverterExpression(org.datanucleus.store.rdbms.sql.expression.TypeConverterExpression) StringExpression(org.datanucleus.store.rdbms.sql.expression.StringExpression) NumericSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.NumericSubqueryExpression) StringSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.StringSubqueryExpression) MapExpression(org.datanucleus.store.rdbms.sql.expression.MapExpression) ArrayExpression(org.datanucleus.store.query.expression.ArrayExpression) CaseExpression(org.datanucleus.store.query.expression.CaseExpression) CreatorExpression(org.datanucleus.store.query.expression.CreatorExpression) NewObjectExpression(org.datanucleus.store.rdbms.sql.expression.NewObjectExpression) OrderExpression(org.datanucleus.store.query.expression.OrderExpression) TemporalSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.TemporalSubqueryExpression) ClassExpression(org.datanucleus.store.query.expression.ClassExpression) BooleanExpression(org.datanucleus.store.rdbms.sql.expression.BooleanExpression) Expression(org.datanucleus.store.query.expression.Expression) SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) ParameterExpression(org.datanucleus.store.query.expression.ParameterExpression) UnboundExpression(org.datanucleus.store.rdbms.sql.expression.UnboundExpression) TemporalExpression(org.datanucleus.store.rdbms.sql.expression.TemporalExpression) SubqueryExpression(org.datanucleus.store.query.expression.SubqueryExpression) ResultAliasExpression(org.datanucleus.store.rdbms.sql.expression.ResultAliasExpression) VariableExpression(org.datanucleus.store.query.expression.VariableExpression) TypeExpression(org.datanucleus.store.query.expression.TypeExpression) NumericExpression(org.datanucleus.store.rdbms.sql.expression.NumericExpression) CollectionExpression(org.datanucleus.store.rdbms.sql.expression.CollectionExpression) DyadicExpression(org.datanucleus.store.query.expression.DyadicExpression) ColumnExpression(org.datanucleus.store.rdbms.sql.expression.ColumnExpression) JoinExpression(org.datanucleus.store.query.expression.JoinExpression) InvokeExpression(org.datanucleus.store.query.expression.InvokeExpression) BooleanSubqueryExpression(org.datanucleus.store.rdbms.sql.expression.BooleanSubqueryExpression) SubqueryExpressionComponent(org.datanucleus.store.rdbms.sql.expression.SubqueryExpressionComponent) NucleusException(org.datanucleus.exceptions.NucleusException)

Aggregations

NucleusException (org.datanucleus.exceptions.NucleusException)1 ArrayExpression (org.datanucleus.store.query.expression.ArrayExpression)1 CaseExpression (org.datanucleus.store.query.expression.CaseExpression)1 ClassExpression (org.datanucleus.store.query.expression.ClassExpression)1 CreatorExpression (org.datanucleus.store.query.expression.CreatorExpression)1 DyadicExpression (org.datanucleus.store.query.expression.DyadicExpression)1 Expression (org.datanucleus.store.query.expression.Expression)1 InvokeExpression (org.datanucleus.store.query.expression.InvokeExpression)1 JoinExpression (org.datanucleus.store.query.expression.JoinExpression)1 OrderExpression (org.datanucleus.store.query.expression.OrderExpression)1 ParameterExpression (org.datanucleus.store.query.expression.ParameterExpression)1 PrimaryExpression (org.datanucleus.store.query.expression.PrimaryExpression)1 SubqueryExpression (org.datanucleus.store.query.expression.SubqueryExpression)1 TypeExpression (org.datanucleus.store.query.expression.TypeExpression)1 VariableExpression (org.datanucleus.store.query.expression.VariableExpression)1 SQLStatement (org.datanucleus.store.rdbms.sql.SQLStatement)1 BooleanExpression (org.datanucleus.store.rdbms.sql.expression.BooleanExpression)1 BooleanSubqueryExpression (org.datanucleus.store.rdbms.sql.expression.BooleanSubqueryExpression)1 CollectionExpression (org.datanucleus.store.rdbms.sql.expression.CollectionExpression)1 ColumnExpression (org.datanucleus.store.rdbms.sql.expression.ColumnExpression)1