{
OpenJPAEntityManager pm = getPM();
startTx(pm);
String theQuery =
"SELECT r FROM RuntimeTest1 r WHERE r.stringField = \'testSimple\'";
OpenJPAQuery query = pm.createQuery(theQuery);
List list = query.getResultList();
assertSize(1, list);
endTx(pm);
endEm(pm);
}
// test Update
{
OpenJPAEntityManager pm = getPM();
startTx(pm);
String theQuery =
"SELECT r FROM RuntimeTest1 r WHERE r.stringField = \'testSimple\'";
OpenJPAQuery query = pm.createQuery(theQuery);
RuntimeTest1 toUpdate = (RuntimeTest1) query.getSingleResult();
toUpdate.setStringField("testSimple2");
endTx(pm);
endEm(pm);
pm = getPM();
startTx(pm);
String query1 =
"SELECT r FROM RuntimeTest1 r WHERE r.stringField = \'testSimple\'";
String query2 =
"SELECT r FROM RuntimeTest1 r WHERE r.stringField = \'testSimple2\'";
OpenJPAQuery q1 = pm.createQuery(query1);
OpenJPAQuery q2 = pm.createQuery(query2);
assertSize(0, q1.getResultList());
assertSize(1, q2.getResultList());
endTx(pm);
endEm(pm);
}
// test Extent
{
OpenJPAEntityManager pm = getPM();
startTx(pm);
Extent e = pm.createExtent(RuntimeTest1.class, true);
assertTrue(e.iterator().hasNext());
assertEquals("testSimple2", ((RuntimeTest1) e.iterator().next()).
getStringField());
endTx(pm);
endEm(pm);
}
// test delete
{
OpenJPAEntityManager pm = getPM();
startTx(pm);
String delete =
"DELETE FROM RuntimeTest1 r WHERE r.stringField = \'testSimple2\'";
OpenJPAQuery deleteQuery = pm.createQuery(delete);
int deleted = deleteQuery.executeUpdate();
endTx(pm);
endEm(pm);
pm = getPM();
startTx(pm);
String select =
"SELECT r FROM RuntimeTest1 r WHERE r.stringField = \'testSimple2\'";
OpenJPAQuery selectQuery = pm.createQuery(select);
assertSize(0, selectQuery.getResultList());
endTx(pm);
endEm(pm);
}
}