use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class CayenneIT method testObjectForQueryNoObject.
@Test
public void testObjectForQueryNoObject() throws Exception {
ObjectId id = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, new Integer(44001));
Object object = Cayenne.objectForQuery(context, new ObjectIdQuery(id));
assertNull(object);
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class CDOOneToOneFKIT method testDelete.
@Test
public void testDelete() throws Exception {
ToOneFK2 src = context.newObject(ToOneFK2.class);
ToOneFK1 target = context.newObject(ToOneFK1.class);
src.setToOneToFK(target);
context.commitChanges();
src.setToOneToFK(null);
context.deleteObjects(target);
context.commitChanges();
// test database data
ObjectIdQuery refetch = new ObjectIdQuery(src.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
assertNull(src.getToOneToFK());
assertEquals(src.getObjectId(), src2.getObjectId());
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class CDOOneToOneFKIT method test2Null.
@Test
public void test2Null() throws Exception {
ToOneFK2 src = context.newObject(ToOneFK2.class);
context.commitChanges();
// test database data
ObjectIdQuery refetch = new ObjectIdQuery(src.getObjectId(), false, ObjectIdQuery.CACHE_REFRESH);
ToOneFK2 src2 = (ToOneFK2) Cayenne.objectForQuery(context1, refetch);
// *** TESTING THIS ***
assertNull(src2.getToOneToFK());
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class CayenneContextClientChannelEventsIT method testSyncToManyRelationship.
@Test
public void testSyncToManyRelationship() throws Exception {
tMtTable1.insert(1, "g1", "s1");
tMtTable2.insert(1, 1, "g1");
CayenneContext c1 = (CayenneContext) runtime.newContext();
CayenneContext c2 = (CayenneContext) runtime.newContext();
ClientMtTable1 o1 = (ClientMtTable1) Cayenne.objectForQuery(c1, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 1)));
ClientMtTable1 o2 = (ClientMtTable1) Cayenne.objectForQuery(c2, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 1)));
assertEquals(1, o1.getTable2Array().size());
assertEquals(1, o2.getTable2Array().size());
ClientMtTable2 o1r = c1.newObject(ClientMtTable2.class);
o1r.setGlobalAttribute("X");
o1.addToTable2Array(o1r);
c1.commitChanges();
// let the events propagate to peers
Thread.sleep(500);
assertEquals(2, o1.getTable2Array().size());
assertEquals(2, o2.getTable2Array().size());
assertFalse(c1.internalGraphManager().hasChanges());
assertFalse(c2.internalGraphManager().hasChanges());
}
use of org.apache.cayenne.query.ObjectIdQuery in project cayenne by apache.
the class CayenneContextMapRelationshipIT method testAddToMany.
@Test
public void testAddToMany() throws Exception {
createTwoMapToManysWithTargetsDataSet();
ObjectId id = new ObjectId("IdMapToMany", IdMapToMany.ID_PK_COLUMN, 1);
ClientIdMapToMany o1 = (ClientIdMapToMany) Cayenne.objectForQuery(context, new ObjectIdQuery(id));
Map<Object, ClientIdMapToManyTarget> targets = o1.getTargets();
assertNotNull(targets);
assertEquals(3, targets.size());
ClientIdMapToManyTarget newTarget = o1.getObjectContext().newObject(ClientIdMapToManyTarget.class);
o1.addToTargets(newTarget);
assertEquals(4, targets.size());
assertSame(o1, newTarget.getMapToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(4, o1.getTargets().size());
int newId = Cayenne.intPKForObject(newTarget);
assertSame(newTarget, o1.getTargets().get(newId));
assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, newTarget.getPersistenceState());
}
Aggregations