use of org.jpox.samples.models.company.Person in project tests by datanucleus.
the class JDOQLInMemoryTest method testParameterMethodInvoke.
/**
* Test of parameter.method().
*/
public void testParameterMethodInvoke() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query q = pm.newQuery(getQueryLanguage(), "SELECT FROM " + Person.class.getName() + " WHERE firstName.toUpperCase() == param1.toUpperCase()");
q.addExtension("datanucleus.query.evaluateInMemory", "true");
q.declareParameters("java.lang.String param1");
Collection results = (Collection) q.execute("aNa");
assertEquals("Number of results is incorrect", 1, results.size());
Person p = (Person) results.iterator().next();
assertEquals("First name of result is incorrect", "Ana", p.getFirstName());
tx.commit();
} catch (Exception e) {
LOG.error("Exception in execution of query", e);
fail(e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.jpox.samples.models.company.Person in project tests by datanucleus.
the class JDOQLInMemoryTest method testParamToUpperCaseStartsWith.
/**
* Test for JDOQL chained String methods, using toUpperCase().startsWith() using parameters.
*/
public void testParamToUpperCaseStartsWith() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query<Person> q = pm.newQuery(Person.class, ":param1.toUpperCase().startsWith(:param2.toUpperCase())");
q.addExtension("datanucleus.query.evaluateInMemory", "true");
Map<String, String> params = new HashMap<>();
params.put("param1", "First");
params.put("param2", "f");
q.setNamedParameters(params);
List results = q.executeList();
assertEquals(3, results.size());
tx.commit();
} catch (Exception e) {
LOG.error("Exception during param.toUpperCase().startsWith() evaluation", e);
fail("Exception thrown querying data " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.jpox.samples.models.company.Person in project tests by datanucleus.
the class JDOQLInMemoryTest method testImplicitParameter.
/**
* Test of implicit parameter.
*/
public void testImplicitParameter() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query<Person> q = pm.newQuery(Person.class);
q.addExtension("datanucleus.query.evaluateInMemory", "true");
q.setFilter("personNum == :param1");
Map<String, Integer> params = new HashMap<>();
params.put("param1", 4);
q.setNamedParameters(params);
Collection<Person> c = q.executeList();
assertEquals(1, c.size());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.jpox.samples.models.company.Person in project tests by datanucleus.
the class JDOQLInMemoryTest method testStringStartsWith.
/**
* Test for JDOQL String startsWith method.
*/
public void testStringStartsWith() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query q = pm.newQuery(getQueryLanguage(), "SELECT FROM " + Person.class.getName() + " WHERE firstName.startsWith('B')");
q.addExtension("datanucleus.query.evaluateInMemory", "true");
Object res = q.execute();
assertNotNull("Result set from JDOQL query is null!", res);
assertTrue("Result set from JDOQL query is of incorrect type!", res instanceof List);
Collection c = (Collection) res;
assertEquals("Collection from String.startsWith() has wrong size", 1, c.size());
// same test with parameter expression
q = pm.newQuery(getQueryLanguage(), "SELECT FROM " + Person.class.getName());
q.addExtension("datanucleus.query.evaluateInMemory", "true");
q.declareParameters("java.lang.String p1");
q.setFilter("firstName.startsWith(p1)");
c = (Collection) q.execute("B");
assertEquals(1, c.size());
Iterator it = c.iterator();
assertEquals("Bugs", ((Person) it.next()).getFirstName());
tx.commit();
} catch (Exception e) {
e.printStackTrace();
fail("Exception thrown querying data " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.jpox.samples.models.company.Person in project tests by datanucleus.
the class JDOQLInMemoryTest method testStringEndsWith.
/**
* Test for JDOQL String endsWith method.
*/
public void testStringEndsWith() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query q = pm.newQuery(getQueryLanguage(), "SELECT FROM " + Person.class.getName() + " WHERE lastName.endsWith('ck')");
q.addExtension("datanucleus.query.evaluateInMemory", "true");
Object res = q.execute();
assertNotNull("Result set from JDOQL query is null!", res);
assertTrue("Result set from JDOQL query is of incorrect type!", res instanceof List);
Collection c = (Collection) res;
assertEquals("Collection from String.endsWith() has wrong size", 1, c.size());
// same test with parameter expression
q = pm.newQuery(getQueryLanguage(), "SELECT FROM " + Person.class.getName());
q.addExtension("datanucleus.query.evaluateInMemory", "true");
q.declareParameters("java.lang.String p1");
q.setFilter("firstName.endsWith(p1)");
c = (Collection) q.execute("a");
assertEquals(1, c.size());
Iterator it = c.iterator();
assertEquals("Ana", ((Person) it.next()).getFirstName());
tx.commit();
} catch (Exception e) {
e.printStackTrace();
fail("Exception thrown querying data " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
Aggregations