use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class DataContextObjectIdQueryIT method testRefreshNullifiedValuesExisting.
@Test
public void testRefreshNullifiedValuesExisting() {
SQLTemplate insert = new SQLTemplate(Artist.class, "INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME, DATE_OF_BIRTH) VALUES (44, 'X', #bind($date 'DATE'))");
insert.setParameters(Collections.singletonMap("date", new Date()));
context.performGenericQuery(insert);
Artist a = Cayenne.objectForPK(context, Artist.class, 44l);
assertNotNull(a.getDateOfBirth());
assertEquals("X", a.getArtistName());
context.performGenericQuery(new SQLTemplate(Artist.class, "UPDATE ARTIST SET DATE_OF_BIRTH = NULL"));
ObjectIdQuery query = new ObjectIdQuery(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 44l), false, ObjectIdQuery.CACHE_REFRESH);
Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
assertNull(a1.getDateOfBirth());
assertEquals("X", a1.getArtistName());
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class DataContextObjectIdQuery_PolymorphicIT method testPolymorphicSharedCache.
@Test
public void testPolymorphicSharedCache() throws SQLException {
tPerson.insert(1, "P1", "EM");
final ObjectIdQuery q1 = new ObjectIdQuery(new ObjectId("AbstractPerson", "PERSON_ID", 1), false, ObjectIdQuery.CACHE);
AbstractPerson ap1 = (AbstractPerson) Cayenne.objectForQuery(context1, q1);
assertTrue(ap1 instanceof Manager);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
@Override
public void execute() {
// use different context to ensure we hit shared cache
AbstractPerson ap2 = (AbstractPerson) Cayenne.objectForQuery(context2, q1);
assertTrue(ap2 instanceof Manager);
}
});
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class DataContextObjectIdQuery_PolymorphicIT method testPolymorphicLocalCache.
@Test
public void testPolymorphicLocalCache() throws SQLException {
tPerson.insert(1, "P1", "EM");
final ObjectIdQuery q1 = new ObjectIdQuery(new ObjectId("AbstractPerson", "PERSON_ID", 1), false, ObjectIdQuery.CACHE);
AbstractPerson ap1 = (AbstractPerson) Cayenne.objectForQuery(context1, q1);
assertTrue(ap1 instanceof Manager);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
@Override
public void execute() {
// use same context to ensure we hit local cache
// note that this does not guarantee test correctness. If local
// cache polymorphic ID lookup is broken, shared cache will pick
// it up
AbstractPerson ap2 = (AbstractPerson) Cayenne.objectForQuery(context1, q1);
assertTrue(ap2 instanceof Manager);
}
});
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class CDOOneToOneFKIT method testTakeObjectSnapshotDependentFault.
@Test
public void testTakeObjectSnapshotDependentFault() throws Exception {
ToOneFK2 src = context.newObject(ToOneFK2.class);
ToOneFK1 target = context.newObject(ToOneFK1.class);
src.setToOneToFK(target);
context.commitChanges();
ObjectIdQuery refetch = new ObjectIdQuery(src.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
assertTrue(src2.readPropertyDirectly("toOneToFK") instanceof Fault);
// test that taking a snapshot does not trigger a fault, and generally works well
context.currentSnapshot(src2);
assertTrue(src2.readPropertyDirectly("toOneToFK") instanceof Fault);
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class CayenneIT method testObjectForQuery.
@Test
public void testObjectForQuery() throws Exception {
createOneArtist();
ObjectId id = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, new Integer(33002));
assertNull(context.getGraphManager().getNode(id));
Object object = Cayenne.objectForQuery(context, new ObjectIdQuery(id));
assertNotNull(object);
assertTrue(object instanceof Artist);
assertEquals("artist2", ((Artist) object).getArtistName());
}
Aggregations