Search in sources :

Example 21 with JDOQuery

use of org.datanucleus.api.jdo.JDOQuery 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
    }
}
Also used : AbstractJDOQLQuery(org.datanucleus.store.query.AbstractJDOQLQuery) AbstractJDOQLQuery(org.datanucleus.store.query.AbstractJDOQLQuery) JDOQuery(org.datanucleus.api.jdo.JDOQuery) Query(javax.jdo.Query) JDOQLSingleStringParser(org.datanucleus.query.JDOQLSingleStringParser) PersistenceManager(javax.jdo.PersistenceManager) NucleusUserException(org.datanucleus.exceptions.NucleusUserException)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)21 JDOQuery (org.datanucleus.api.jdo.JDOQuery)21 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 List (java.util.List)14 Transaction (javax.jdo.Transaction)14 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)14 JDOQLCompiler (org.datanucleus.query.compiler.JDOQLCompiler)14 JavaQueryCompiler (org.datanucleus.query.compiler.JavaQueryCompiler)14 QueryCompilation (org.datanucleus.query.compiler.QueryCompilation)14 JDOQLInMemoryEvaluator (org.datanucleus.query.inmemory.JDOQLInMemoryEvaluator)14 JavaQueryInMemoryEvaluator (org.datanucleus.query.inmemory.JavaQueryInMemoryEvaluator)14 Query (org.datanucleus.store.query.Query)14 Person (org.jpox.samples.models.company.Person)10 Query (javax.jdo.Query)7 JDOQLSingleStringParser (org.datanucleus.query.JDOQLSingleStringParser)7 AbstractJDOQLQuery (org.datanucleus.store.query.AbstractJDOQLQuery)7 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)6 Iterator (java.util.Iterator)2 SubqueryDefinition (org.datanucleus.store.query.Query.SubqueryDefinition)2