use of org.jpox.samples.types.basic.BasicTypeHolder in project tests by datanucleus.
the class JDOQLBasicTest method testArrayContains.
/**
* Tests the Array.contains expression
*/
public void testArrayContains() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
// Persist some objects
tx.begin();
BasicTypeHolder[] basics = new BasicTypeHolder[5];
for (int i = 0; i < basics.length; i++) {
basics[i] = new BasicTypeHolder();
basics[i].setLongField(-10 - i);
basics[i].setCharField('0');
}
pm.makePersistentAll(basics);
tx.commit();
Object[] ids = new Object[5];
for (int i = 0; i < basics.length; i++) {
ids[i] = pm.getObjectId(basics[i]);
}
// Test array.contains
tx.begin();
Query q = pm.newQuery(BasicTypeHolder.class, "{1,3,-11}.contains(this.longField)");
Collection c = (Collection) q.execute();
Assert.assertEquals(1, c.size());
q = pm.newQuery(BasicTypeHolder.class, "{1,3,4}.contains(this.longField)");
c = (Collection) q.execute();
Assert.assertEquals(0, c.size());
q = pm.newQuery(BasicTypeHolder.class, "{1,3,4,this.longField}.contains(this.longField)");
c = (Collection) q.execute();
Assert.assertEquals(5, c.size());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
// Clean out our data
clean(BasicTypeHolder.class);
}
}
use of org.jpox.samples.types.basic.BasicTypeHolder in project tests by datanucleus.
the class JDOQLBasicTest method testArrayParameter.
/**
* Tests the Array in parameter expression
*/
public void testArrayParameter() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
BasicTypeHolder[] basics = new BasicTypeHolder[5];
for (int i = 0; i < basics.length; i++) {
basics[i] = new BasicTypeHolder();
basics[i].setLongField(-10 - i);
basics[i].setCharField('0');
}
pm.makePersistentAll(basics);
tx.commit();
Object[] ids = new Object[5];
for (int i = 0; i < basics.length; i++) {
ids[i] = pm.getObjectId(basics[i]);
}
tx.begin();
Query q = pm.newQuery(BasicTypeHolder.class, "p.length() == 3");
q.declareParameters("Integer[] p");
Collection c = (Collection) q.execute(new Integer[] { new Integer(1), new Integer(3), new Integer(-11) });
Assert.assertEquals(5, c.size());
q = pm.newQuery(BasicTypeHolder.class, "3 == p.length()");
q.declareParameters("Integer[] p");
c = (Collection) q.execute(new Integer[] { new Integer(1), new Integer(3), new Integer(-11) });
Assert.assertEquals(5, c.size());
q = pm.newQuery(BasicTypeHolder.class, "p.contains(1)");
q.declareParameters("Integer[] p");
c = (Collection) q.execute(new Integer[] { new Integer(1), new Integer(3), new Integer(-11) });
Assert.assertEquals(5, c.size());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
// Clean out our data
clean(BasicTypeHolder.class);
}
}
use of org.jpox.samples.types.basic.BasicTypeHolder in project tests by datanucleus.
the class JDOQLBasicTest method testNullEqualsNull.
public void testNullEqualsNull() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
BasicTypeHolder[] basics = new BasicTypeHolder[5];
for (int i = 0; i < basics.length; i++) {
basics[i] = new BasicTypeHolder();
basics[i].setLongField(i + 1);
basics[i].setCharField('0');
}
pm.makePersistentAll(basics);
tx.commit();
Object[] ids = new Object[5];
for (int i = 0; i < basics.length; i++) {
ids[i] = pm.getObjectId(basics[i]);
}
tx.begin();
Query q = pm.newQuery(BasicTypeHolder.class, "null == null");
q.declareParameters("java.lang.Integer str");
Collection c = (Collection) q.execute(null);
Assert.assertEquals(5, c.size());
q = pm.newQuery(BasicTypeHolder.class, "null != null");
q.declareParameters("java.lang.Integer str");
c = (Collection) q.execute(null);
Assert.assertEquals(0, c.size());
q = pm.newQuery(BasicTypeHolder.class, "null == null || null != null");
q.declareParameters("java.lang.Integer str");
c = (Collection) q.execute(null);
Assert.assertEquals(5, c.size());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
// Clean out our data
clean(BasicTypeHolder.class);
}
}
use of org.jpox.samples.types.basic.BasicTypeHolder in project tests by datanucleus.
the class JDOQLBasicTest method testMathAbs.
/**
* Tests the Math.abs expression
*/
public void testMathAbs() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
BasicTypeHolder[] basics = new BasicTypeHolder[5];
for (int i = 0; i < basics.length; i++) {
basics[i] = new BasicTypeHolder();
basics[i].setLongField(-10 - i);
basics[i].setCharField('0');
}
pm.makePersistentAll(basics);
tx.commit();
Object[] ids = new Object[5];
for (int i = 0; i < basics.length; i++) {
ids[i] = pm.getObjectId(basics[i]);
}
tx.begin();
Query q = pm.newQuery(BasicTypeHolder.class, "Math.abs(this.longField) == 10");
Collection c = (Collection) q.execute();
Assert.assertEquals(1, c.size());
Assert.assertEquals(ids[0], JDOHelper.getObjectId(c.iterator().next()));
q = pm.newQuery(BasicTypeHolder.class, "java.lang.Math.abs(this.longField) == 10");
c = (Collection) q.execute();
Assert.assertEquals(1, c.size());
Assert.assertEquals(ids[0], JDOHelper.getObjectId(c.iterator().next()));
q = pm.newQuery(BasicTypeHolder.class, "Math.abs(this.longField) == Math.abs(-11)");
c = (Collection) q.execute();
Assert.assertEquals(1, c.size());
Assert.assertEquals(ids[1], JDOHelper.getObjectId(c.iterator().next()));
q = pm.newQuery(BasicTypeHolder.class, "Math.abs(this.longField) == Math.abs(-12.0)");
c = (Collection) q.execute();
Assert.assertEquals(1, c.size());
Assert.assertEquals(ids[2], JDOHelper.getObjectId(c.iterator().next()));
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
// Clean out our data
clean(BasicTypeHolder.class);
}
}
use of org.jpox.samples.types.basic.BasicTypeHolder in project tests by datanucleus.
the class JDOQLBasicTest method testPCLiteralOnQueryCompile.
public void testPCLiteralOnQueryCompile() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
// Persist some simple objects
tx.begin();
BasicTypeHolder[] basics = new BasicTypeHolder[5];
for (int i = 0; i < basics.length; i++) {
basics[i] = new BasicTypeHolder();
basics[i].setLongField((i + 2) * (i + 2));
basics[i].setCharField('0');
}
pm.makePersistentAll(basics);
tx.commit();
Object[] ids = new Object[5];
for (int i = 0; i < basics.length; i++) {
ids[i] = pm.getObjectId(basics[i]);
}
tx.begin();
for (int i = 0; i < basics.length; i++) {
Query q = pm.newQuery(BasicTypeHolder.class, "this == obj");
q.declareParameters("BasicTypeHolder obj");
// test that query can be compiled
q.compile();
Collection c = (Collection) q.execute(basics[i]);
Assert.assertEquals(1, c.size());
Assert.assertEquals(ids[i], JDOHelper.getObjectId(c.iterator().next()));
}
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
// Clean out our data
clean(BasicTypeHolder.class);
}
}
Aggregations