use of org.apache.cayenne.util.PersistentObjectHolder in project cayenne by apache.
the class PersistentObjectInContextIT method testResolveToOneReverseResolved.
@Test
public void testResolveToOneReverseResolved() throws Exception {
createTwoMtTable1sAnd2sDataSet();
ObjectId gid = new ObjectId("MtTable2", MtTable2.TABLE2_ID_PK_COLUMN, new Integer(1));
ClientMtTable2 mtTable21 = (ClientMtTable2) Cayenne.objectForQuery(context, new ObjectIdQuery(gid));
assertNotNull(mtTable21);
ClientMtTable1 mtTable1 = mtTable21.getTable1();
assertNotNull("To one relationship incorrectly resolved to null", mtTable1);
List<ClientMtTable2> list = mtTable1.getTable2Array();
assertNotNull(list);
assertTrue(list instanceof ValueHolder);
assertTrue(((ValueHolder) list).isFault());
// resolve it here...
assertEquals(2, list.size());
for (ClientMtTable2 t2 : list) {
PersistentObjectHolder holder = (PersistentObjectHolder) t2.getTable1Direct();
assertFalse(holder.isFault());
assertSame(mtTable1, holder.getValue());
}
assertEquals("g1", mtTable1.getGlobalAttribute1());
}
use of org.apache.cayenne.util.PersistentObjectHolder in project cayenne by apache.
the class ClientServerChannelQueryIT method testSelectQueryPrefetchToOne.
@Test
public void testSelectQueryPrefetchToOne() throws Exception {
createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable2.class, ExpressionFactory.exp("globalAttribute = 'g1'"));
q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);
List<?> results = context.performQuery(q);
assertEquals(1, results.size());
ClientMtTable2 result = (ClientMtTable2) results.get(0);
ValueHolder holder = result.getTable1Direct();
assertNotNull(holder);
assertTrue(holder instanceof PersistentObjectHolder);
PersistentObjectHolder objectHolder = (PersistentObjectHolder) holder;
assertFalse(objectHolder.isFault());
ClientMtTable1 target = (ClientMtTable1) objectHolder.getValue();
assertNotNull(target);
}
use of org.apache.cayenne.util.PersistentObjectHolder in project cayenne by apache.
the class _Painting method setArtist.
public void setArtist(Artist artist) {
if (objectContext != null) {
objectContext.prepareForAccess(this, "artist", true);
} else if (this.artist == null) {
this.artist = new PersistentObjectHolder(this, "artist");
}
// note how we notify ObjectContext of change BEFORE the object is actually
// changed... this is needed to take a valid current snapshot
Object oldValue = this.artist.getValueDirectly();
if (objectContext != null) {
objectContext.propertyChanged(this, "artist", oldValue, artist);
}
this.artist.setValue(artist);
}
use of org.apache.cayenne.util.PersistentObjectHolder in project cayenne by apache.
the class _Painting method setGallery.
public void setGallery(Gallery gallery) {
if (objectContext != null) {
objectContext.prepareForAccess(this, "gallery", true);
} else if (this.gallery == null) {
this.gallery = new PersistentObjectHolder(this, "gallery");
}
// note how we notify ObjectContext of change BEFORE the object is actually
// changed... this is needed to take a valid current snapshot
Object oldValue = this.gallery.getValueDirectly();
if (objectContext != null) {
objectContext.propertyChanged(this, "gallery", oldValue, gallery);
}
this.gallery.setValue(gallery);
}
use of org.apache.cayenne.util.PersistentObjectHolder in project cayenne by apache.
the class PersistentObjectInContextIT method testResolveToManyReverseResolved.
@Test
public void testResolveToManyReverseResolved() throws Exception {
createTwoMtTable1sAnd2sDataSet();
ObjectId gid = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, new Integer(1));
ClientMtTable1 t1 = (ClientMtTable1) Cayenne.objectForQuery(context, new ObjectIdQuery(gid));
assertNotNull(t1);
List<ClientMtTable2> t2s = t1.getTable2Array();
assertEquals(2, t2s.size());
for (ClientMtTable2 t2 : t2s) {
PersistentObjectHolder holder = (PersistentObjectHolder) t2.getTable1Direct();
assertFalse(holder.isFault());
assertSame(t1, holder.getValue());
}
}
Aggregations