Search in sources :

Example 21 with ObjectIdQuery

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);
}
Also used : ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 22 with ObjectIdQuery

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());
}
Also used : ToOneFK2(org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2) ToOneFK1(org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK1) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 23 with ObjectIdQuery

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());
}
Also used : ToOneFK2(org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 24 with ObjectIdQuery

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());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 25 with ObjectIdQuery

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());
}
Also used : ClientIdMapToManyTarget(org.apache.cayenne.testdo.map_to_many.ClientIdMapToManyTarget) RefreshQuery(org.apache.cayenne.query.RefreshQuery) ClientIdMapToMany(org.apache.cayenne.testdo.map_to_many.ClientIdMapToMany) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Aggregations

ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)42 Test (org.junit.Test)34 ObjectId (org.apache.cayenne.ObjectId)15 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)11 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)6 ToOneFK2 (org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK2)6 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)6 DataRow (org.apache.cayenne.DataRow)5 Artist (org.apache.cayenne.testdo.testmap.Artist)5 ToOneFK1 (org.apache.cayenne.testdo.relationships_to_one_fk.ToOneFK1)4 List (java.util.List)3 ObjectContext (org.apache.cayenne.ObjectContext)3 Persistent (org.apache.cayenne.Persistent)3 QueryResponse (org.apache.cayenne.QueryResponse)3 SQLTemplate (org.apache.cayenne.query.SQLTemplate)3 AbstractPerson (org.apache.cayenne.testdo.inheritance_people.AbstractPerson)3 Date (java.util.Date)2 SelectQuery (org.apache.cayenne.query.SelectQuery)2 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)2 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)2