use of org.datanucleus.store.query.AbstractJDOQLQuery in project tests by datanucleus.
the class JDOQLSingleStringParserTest method testImport.
/**
* Test for the detection of "import" blocks.
*/
public void testImport() {
// Test of the basic import parsing
PersistenceManager pm = pmf.getPersistenceManager();
Query q = pm.newQuery("JDOQL", null);
AbstractJDOQLQuery query = (AbstractJDOQLQuery) ((JDOQuery) q).getInternalQuery();
String str = "SELECT FROM org.jpox.samples.MyClass import java.util.*; import java.net.*";
JDOQLSingleStringParser parser = new JDOQLSingleStringParser(query, str);
parser.parse();
String queryString = query.toString();
// Parser will strip out whitespace from the imports
String expectationString = "SELECT FROM org.jpox.samples.MyClass import java.util.*;import java.net.*";
assertEquals("Parse of single-string basic import failed", expectationString, queryString);
}
use of org.datanucleus.store.query.AbstractJDOQLQuery in project tests by datanucleus.
the class JDOQLSingleStringParserTest method testLiteralWithKeyword.
/**
* Test for the parse of a literal which includes a keyword.
*/
public void testLiteralWithKeyword() {
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 == 'The book from which I took inspiration'";
JDOQLSingleStringParser parser = new JDOQLSingleStringParser(query, str);
try {
parser.parse();
} catch (NucleusUserException e) {
LOG.error("Exception in test", e);
fail("Exception in parse : " + e.getMessage());
}
}
use of org.datanucleus.store.query.AbstractJDOQLQuery in project tests by datanucleus.
the class JDOQLSingleStringParserTest method testWhereWithMultipleSpaces.
/**
* Test for the parse of a WHERE clause which has multiple spaces present.
*/
public void testWhereWithMultipleSpaces() {
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 == 'The value to compare against'";
JDOQLSingleStringParser parser = new JDOQLSingleStringParser(query, str);
try {
parser.parse();
// Should preserve spaces in the WHERE
assertEquals("The WHERE clause was not correctly parsed", "field1 == 'The value to compare against'", query.getFilter());
} catch (NucleusUserException e) {
fail("Exception in parse : " + e.getMessage());
}
}
use of org.datanucleus.store.query.AbstractJDOQLQuery in project tests by datanucleus.
the class JDOQLSingleStringParserTest method testSubquery.
/**
* Test for parse and compile of single-string JDOQL subquery case.
*/
public void testSubquery() {
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();
SubqueryDefinition subq1 = query.getSubqueryForVariable("DN_SUBQUERY_1");
assertNotNull("Subquery #1 should be generated by single-string parser but isnt", subq1);
assertEquals(subq1.getQuery().toString(), "SELECT avg(f.field1) FROM org.jpox.samples.MyClass f");
SubqueryDefinition subq2 = query.getSubqueryForVariable("DN_SUBQUERY_2");
assertNull("Subquery #2 shouldnt be generated by single-string parser but is", subq2);
} 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 testVariableBeforeParameter.
/**
* Test for the order of variable and parameter definitions.
*/
public void testVariableBeforeParameter() {
PersistenceManager pm = pmf.getPersistenceManager();
Query q = pm.newQuery("JDOQL", null);
AbstractJDOQLQuery query = (AbstractJDOQLQuery) ((JDOQuery) q).getInternalQuery();
String str = "SELECT FROM org.jpox.samples.MyClass PARAMETERS String p1 VARIABLES int v1";
JDOQLSingleStringParser parser = new JDOQLSingleStringParser(query, str);
try {
parser.parse();
fail("Query using VARIABLES after PARAMETERS should have thrown an exception but passed");
} catch (NucleusUserException e) {
// Expected since VARIABLES should be before PARAMETERS
}
}
Aggregations