use of org.datanucleus.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);
}
use of org.datanucleus.query.expression.SubqueryExpression in project tests by datanucleus.
the class JPQLCompilerTest method testFilterWithExistsSubquery.
/**
* Tests for "EXISTS (subquery)".
*/
public void testFilterWithExistsSubquery() {
JavaQueryCompiler compiler = null;
QueryCompilation compilation = null;
try {
compiler = new JPQLCompiler(nucCtx, nucCtx.getClassLoaderResolver(null), null, Project.class, null, "EXISTS (SUBQ_1)", null, null, null, null, null, null, null);
compilation = compiler.compile(new HashMap(), null);
} catch (NucleusException ne) {
NucleusLogger.QUERY.error("Exception during compile", ne);
fail("compilation of filter with valid field threw exception : " + ne.getMessage());
}
Expression expr = compilation.getExprFilter();
assertTrue("Expression is not a SubqueryExpression", expr instanceof SubqueryExpression);
SubqueryExpression subExpr = (SubqueryExpression) expr;
assertEquals("Subquery keyword is incorrect", "EXISTS", subExpr.getKeyword());
assertTrue("Subquery right expression is not VariableExpression", subExpr.getRight() instanceof VariableExpression);
VariableExpression varExpr = (VariableExpression) subExpr.getRight();
assertEquals("VariableExpression name is incorrect", "SUBQ_1", varExpr.getId());
}
Aggregations