use of org.datanucleus.store.query.AbstractJDOQLQuery in project tests by datanucleus.
the class JDOQLSingleStringParserTest method testSubquery2.
/**
* Test for parse and compile of single-string JDOQL subquery case.
*/
public void testSubquery2() {
PersistenceManager pm = pmf.getPersistenceManager();
Query q = pm.newQuery("JDOQL", null);
AbstractJDOQLQuery query = (AbstractJDOQLQuery) ((JDOQuery) q).getInternalQuery();
String str = "SELECT FROM org.jpox.samples.MyClass WHERE " + "field1 > (SELECT avg(f.field1) FROM org.jpox.samples.MyClass f) AND " + "field2 > (SELECT min(s.field1) FROM org.jpox.samples.OtherClass s)";
JDOQLSingleStringParser parser = new JDOQLSingleStringParser(query, str);
try {
parser.parse();
SubqueryDefinition subq1 = query.getSubqueryForVariable("DN_SUBQUERY_1");
assertNotNull("Subquery #1 should be generated by single-string parser but isnt", subq1);
assertEquals("SELECT avg(f.field1) FROM org.jpox.samples.MyClass f", subq1.getQuery().toString());
SubqueryDefinition subq2 = query.getSubqueryForVariable("DN_SUBQUERY_2");
assertNotNull("Subquery #2 should be generated by single-string parser but isnt", subq2);
assertEquals("SELECT min(s.field1) FROM org.jpox.samples.OtherClass s", subq2.getQuery().toString());
} catch (NucleusUserException e) {
fail("Exception in parser : " + e.getMessage());
}
}
use of org.datanucleus.store.query.AbstractJDOQLQuery in project tests by datanucleus.
the class JDOQLSingleStringParserTest method testSubselectWithMissingCloseParen.
/**
* Test that we give an appropriate exception when parsing a subselect with a missing close paren.
*/
public void testSubselectWithMissingCloseParen() {
PersistenceManager pm = pmf.getPersistenceManager();
Query q = pm.newQuery("JDOQL", null);
AbstractJDOQLQuery query = (AbstractJDOQLQuery) ((JDOQuery) q).getInternalQuery();
String str = "SELECT FROM org.jpox.samples.MyClass WHERE field1 > (SELECT avg(f.field1) FROM org.jpox.samples.MyClass f";
JDOQLSingleStringParser parser = new JDOQLSingleStringParser(query, str);
try {
parser.parse();
// Should preserve spaces in the WHERE
fail("Expected NucleusException");
} catch (NucleusUserException e) {
// Expected since we're missing a close parent
}
}
Aggregations