use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class DataContextObjectIdQueryIT method testRefreshNullifiedValuesNew.
@Test
public void testRefreshNullifiedValuesNew() {
Artist a = context.newObject(Artist.class);
a.setArtistName("X");
a.setDateOfBirth(new Date());
context.commitChanges();
context.performGenericQuery(new SQLTemplate(Artist.class, "UPDATE ARTIST SET DATE_OF_BIRTH = NULL"));
long id = Cayenne.longPKForObject(a);
ObjectIdQuery query = new ObjectIdQuery(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, id), false, ObjectIdQuery.CACHE_REFRESH);
Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
assertNull(a1.getDateOfBirth());
assertEquals("X", a1.getArtistName());
}
use of org.apache.cayenne.ObjectId 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.ObjectId 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.ObjectId 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.ObjectId in project cayenne by apache.
the class DataContextCommitIT method testFlushToParent_Commit_Mix.
@Test
public void testFlushToParent_Commit_Mix() {
Artist a = context.newObject(Artist.class);
a.setArtistName("Test");
context.flushToParent(true);
// commit a mix of new and modified
Painting p = context.newObject(Painting.class);
p.setPaintingTitle("PT");
p.setToArtist(a);
a.setArtistName("Test_");
ObjectId beforeId = p.getObjectId();
GraphDiff diff = context.flushToParent(true);
ObjectId afterId = p.getObjectId();
assertNotNull(diff);
assertFalse(context.hasChanges());
GraphChangeHandler diffChecker = mock(GraphChangeHandler.class);
diff.apply(diffChecker);
verify(diffChecker).nodeIdChanged(beforeId, afterId);
verifyZeroInteractions(diffChecker);
}
Aggregations