Search in sources :

Example 91 with ObjectContext

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

the class Main method main.

public static void main(String[] args) {
    // starting Cayenne
    ServerRuntime cayenneRuntime = ServerRuntime.builder().addConfig("cayenne-project.xml").build();
    // getting a hold of ObjectContext
    ObjectContext context = cayenneRuntime.newContext();
    newObjectsTutorial(context);
    selectTutorial(context);
    deleteTutorial(context);
}
Also used : ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) ObjectContext(org.apache.cayenne.ObjectContext)

Example 92 with ObjectContext

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

the class ValueInjectorIT method testClient.

@Test
public void testClient() {
    ObjectContext context = createROPContext();
    ObjEntity entity = context.getEntityResolver().getObjEntity(ClientMtTable1Subclass1.class);
    Expression qualifier = entity.getDeclaredQualifier();
    try {
        ClientMtTable1Subclass1 ee = context.newObject(ClientMtTable1Subclass1.class);
        assertEquals(ee.getGlobalAttribute1(), "sub1");
        // check AND
        entity.setDeclaredQualifier(qualifier.andExp(ExpressionFactory.exp("serverAttribute1 = 'sa'")));
        ee = context.newObject(ClientMtTable1Subclass1.class);
        assertEquals(ee.getGlobalAttribute1(), "sub1");
        assertEquals(ee.getServerAttribute1(), "sa");
    } finally {
        entity.setDeclaredQualifier(qualifier);
    }
}
Also used : ClientMtTable1Subclass1(org.apache.cayenne.testdo.mt.ClientMtTable1Subclass1) ObjEntity(org.apache.cayenne.map.ObjEntity) Expression(org.apache.cayenne.exp.Expression) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 93 with ObjectContext

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

the class ROPPrefetchToManyMapIT method test.

@Test
public void test() {
    ObjectContext context = createROPContext();
    ClientIdMapToMany map = context.newObject(ClientIdMapToMany.class);
    ClientIdMapToManyTarget target = context.newObject(ClientIdMapToManyTarget.class);
    target.setMapToMany(map);
    context.commitChanges();
    context.performQuery(new RefreshQuery());
    ObjectSelect<ClientIdMapToMany> query = ObjectSelect.query(ClientIdMapToMany.class).prefetch("targets", PrefetchTreeNode.UNDEFINED_SEMANTICS);
    final ClientIdMapToMany mapToMany = (ClientIdMapToMany) Cayenne.objectForQuery(context, query);
    queryInterceptor.runWithQueriesBlocked(() -> assertEquals(mapToMany.getTargets().size(), 1));
}
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) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 94 with ObjectContext

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

the class RemoteCallbacksIT method testDefault.

@Test
public void testDefault() throws InterruptedException {
    ObjectContext context = createROPContext();
    context.getEntityResolver().getCallbackRegistry().addListener(ClientLifecycles.class, this);
    assertAll(0, 0, 0, 0, 0, 0, 0, 0);
    ClientLifecycles l1 = context.newObject(ClientLifecycles.class);
    assertAll(1, 0, 0, 0, 0, 0, 0, 0);
    l1.setName("x");
    assertAll(1, 0, 0, 0, 0, 0, 0, 0);
    context.commitChanges();
    // until commit
    Thread.sleep(5);
    assertAll(1, 0, 1, 1, 0, 0, 0, 0);
    l1.setName("x2");
    assertAll(1, 0, 1, 1, 0, 0, 0, 0);
    context.commitChanges();
    // until commit
    Thread.sleep(5);
    assertAll(1, 0, 1, 1, 1, 1, 0, 0);
    context.deleteObjects(l1);
    assertAll(1, 0, 1, 1, 1, 1, 1, 0);
    context.commitChanges();
    // until commit
    Thread.sleep(5);
    assertAll(1, 0, 1, 1, 1, 1, 1, 1);
}
Also used : ClientLifecycles(org.apache.cayenne.testdo.lifecycles.ClientLifecycles) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 95 with ObjectContext

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

the class SyncMessageTest method testHessianSerialization.

@Test
public void testHessianSerialization() throws Exception {
    // id must be a serializable object; source doesn't have to be
    ObjectContext source = mock(ObjectContext.class);
    GraphDiff diff = new NodeCreateOperation("id-string");
    SyncMessage message = new SyncMessage(source, DataChannel.FLUSH_NOCASCADE_SYNC, diff);
    Object d = HessianUtil.cloneViaClientServerSerialization(message, new EntityResolver());
    assertNotNull(d);
    assertTrue(d instanceof SyncMessage);
    SyncMessage ds = (SyncMessage) d;
    assertNull(ds.getSource());
    assertEquals(message.getType(), ds.getType());
    assertNotNull(ds.getSenderChanges());
}
Also used : NodeCreateOperation(org.apache.cayenne.graph.NodeCreateOperation) GraphDiff(org.apache.cayenne.graph.GraphDiff) ObjectContext(org.apache.cayenne.ObjectContext) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)127 Test (org.junit.Test)116 Artist (org.apache.cayenne.testdo.testmap.Artist)35 Painting (org.apache.cayenne.testdo.testmap.Painting)14 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)12 Table1 (org.apache.cayenne.crypto.db.Table1)10 ParallelTestContainer (org.apache.cayenne.test.parallel.ParallelTestContainer)10 ObjectId (org.apache.cayenne.ObjectId)8 GraphDiff (org.apache.cayenne.graph.GraphDiff)8 Table2 (org.apache.cayenne.crypto.db.Table2)7 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)7 HashMap (java.util.HashMap)6 Persistent (org.apache.cayenne.Persistent)6 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)6 IvImpl (org.apache.cayenne.testdo.inheritance_vertical.IvImpl)5 CayenneContext (org.apache.cayenne.CayenneContext)4 DataChannel (org.apache.cayenne.DataChannel)4 QueryResponse (org.apache.cayenne.QueryResponse)4 ObjectContextFactory (org.apache.cayenne.configuration.ObjectContextFactory)4 EntityResolver (org.apache.cayenne.map.EntityResolver)4