Search in sources :

Example 41 with ObjectContext

use of org.apache.cayenne.ObjectContext in project cayenne by apache.

the class ColumnSelectIT method testNestedContextMixedResult.

@Test
public void testNestedContextMixedResult() {
    ObjectContext childContext = runtime.newContext(context);
    Property<Artist> artistProperty = Property.createSelf(Artist.class);
    List<Object[]> data = ObjectSelect.columnQuery(Artist.class, Artist.ARTIST_NAME, artistProperty).select(childContext);
    assertEquals(20, data.size());
    for (Object[] next : data) {
        assertTrue(next[0] instanceof String);
        assertTrue(next[1] instanceof Artist);
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 42 with ObjectContext

use of org.apache.cayenne.ObjectContext in project cayenne by apache.

the class DataContextEntityWithMeaningfulPKIT method testToManyRelationshipWithMeaningfulPK1.

@Test
public void testToManyRelationshipWithMeaningfulPK1() {
    MeaningfulPKTest1 obj = context.newObject(MeaningfulPKTest1.class);
    obj.setPkAttribute(1000);
    obj.setDescr("aaa-aaa");
    context.commitChanges();
    // must be able to resolve to-many relationship
    ObjectContext context = runtime.newContext();
    List<MeaningfulPKTest1> objects = ObjectSelect.query(MeaningfulPKTest1.class).select(context);
    assertEquals(1, objects.size());
    obj = objects.get(0);
    assertEquals(0, obj.getMeaningfulPKDepArray().size());
}
Also used : MeaningfulPKTest1(org.apache.cayenne.testdo.meaningful_pk.MeaningfulPKTest1) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 43 with ObjectContext

use of org.apache.cayenne.ObjectContext in project cayenne by apache.

the class DataContextEntityWithMeaningfulPKIT method testMeaningfulIntegerPK.

@Test
public void testMeaningfulIntegerPK() {
    MeaningfulPkTest2 obj1 = context.newObject(MeaningfulPkTest2.class);
    obj1.setIntegerAttribute(10);
    obj1.setPkAttribute(1);
    MeaningfulPkTest2 obj2 = context.newObject(MeaningfulPkTest2.class);
    obj2.setIntegerAttribute(20);
    obj2.setPkAttribute(2);
    context.commitChanges();
    ObjectContext context = runtime.newContext();
    List<MeaningfulPkTest2> objects = ObjectSelect.query(MeaningfulPkTest2.class).select(context);
    assertEquals(2, objects.size());
    assertEquals(Integer.valueOf(1), obj1.getPkAttribute());
    assertEquals(Integer.valueOf(2), obj2.getPkAttribute());
}
Also used : MeaningfulPkTest2(org.apache.cayenne.testdo.meaningful_pk.MeaningfulPkTest2) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 44 with ObjectContext

use of org.apache.cayenne.ObjectContext in project cayenne by apache.

the class DataContextLocalObjectIT method testLocalObject_TempId_NestedContext.

@Test
public void testLocalObject_TempId_NestedContext() throws Exception {
    final Artist a1 = context1.newObject(Artist.class);
    final ObjectContext nestedContext = runtime.newContext(context1);
    interceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            Artist a3 = nestedContext.localObject(a1);
            assertNotSame(a3, a1);
            assertEquals(a3.getObjectId(), a1.getObjectId());
            assertSame(nestedContext, a3.getObjectContext());
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 45 with ObjectContext

use of org.apache.cayenne.ObjectContext in project cayenne by apache.

the class DataContextDataChannelEventsIT method testChangeEventOnChildChange.

@Test
public void testChangeEventOnChildChange() throws Exception {
    Artist a = context.newObject(Artist.class);
    a.setArtistName("X");
    context.commitChanges();
    final MockChannelListener listener = new MockChannelListener();
    EventUtil.listenForChannelEvents(context, listener);
    ObjectContext childContext = runtime.newContext(context);
    Artist a1 = childContext.localObject(a);
    a1.setArtistName("Y");
    childContext.commitChangesToParent();
    new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertFalse(listener.graphCommitted);
            assertTrue(listener.graphChanged);
            assertFalse(listener.graphRolledBack);
        }
    }.runTest(10000);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjectContext(org.apache.cayenne.ObjectContext) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)108 Test (org.junit.Test)99 Artist (org.apache.cayenne.testdo.testmap.Artist)32 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)14 SelectQuery (org.apache.cayenne.query.SelectQuery)13 Painting (org.apache.cayenne.testdo.testmap.Painting)13 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)12 ParallelTestContainer (org.apache.cayenne.test.parallel.ParallelTestContainer)10 GraphDiff (org.apache.cayenne.graph.GraphDiff)9 ObjectId (org.apache.cayenne.ObjectId)8 Table2 (org.apache.cayenne.crypto.db.Table2)7 HashMap (java.util.HashMap)6 Persistent (org.apache.cayenne.Persistent)6 QueryResponse (org.apache.cayenne.QueryResponse)6 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)6 Query (org.apache.cayenne.query.Query)5 CayenneContext (org.apache.cayenne.CayenneContext)4 DataChannel (org.apache.cayenne.DataChannel)4 ObjectContextFactory (org.apache.cayenne.configuration.ObjectContextFactory)4 EntityResolver (org.apache.cayenne.map.EntityResolver)4