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);
}
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);
}
}
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));
}
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);
}
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());
}
Aggregations