use of org.apache.cayenne.access.DataContext in project cayenne by apache.
the class LocalClientServerChannelProvider method get.
public DataChannel get() throws ConfigurationException {
ObjectContextFactory factory = serverInjector.getInstance(ObjectContextFactory.class);
// TODO: ugly cast
DataContext serverContext = (DataContext) factory.createContext();
return new ClientServerChannel(serverContext);
}
use of org.apache.cayenne.access.DataContext in project cayenne by apache.
the class CayenneContextWithDataContextIT method testLocalCacheStaysLocal.
@SuppressWarnings("deprecation")
@Test
public void testLocalCacheStaysLocal() {
DataContext serverContext = (DataContext) clientServerChannel.getParentChannel();
SelectQuery query = new SelectQuery(ClientMtTable1.class);
query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
List<?> results = clientContext.performQuery(query);
assertSame(results, clientContext.getQueryCache().get(query.getMetaData(clientContext.getEntityResolver())));
}
use of org.apache.cayenne.access.DataContext in project cayenne by apache.
the class CayenneContextWithDataContextIT method testPostAddOnObjectCallback.
@Test
public void testPostAddOnObjectCallback() throws Exception {
final DataContext serverContext = (DataContext) clientServerChannel.getParentChannel();
LifecycleCallbackRegistry callbackRegistry = serverContext.getEntityResolver().getCallbackRegistry();
try {
callbackRegistry.addCallback(LifecycleEvent.POST_ADD, MtTable1.class, "prePersistMethod");
final Persistent clientObject = clientContext.newObject(ClientMtTable1.class);
clientContext.commitChanges();
new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
// find peer
MtTable1 peer = (MtTable1) serverContext.getGraphManager().getNode(clientObject.getObjectId());
assertNotNull(peer);
assertTrue(peer.isPrePersisted());
}
}.runTest(1000);
} finally {
callbackRegistry.clear();
}
}
use of org.apache.cayenne.access.DataContext in project cayenne by apache.
the class DataContextFactoryTest method testCreateDataContextWithDedicatedCache.
@Test
public void testCreateDataContextWithDedicatedCache() throws Exception {
final EventManager eventManager = new MockEventManager();
final DataDomain domain = new DataDomain("d1");
domain.setSharedCacheEnabled(false);
Module testModule = binder -> {
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
binder.bind(DataDomain.class).toInstance(domain);
binder.bind(EventManager.class).toInstance(eventManager);
binder.bind(QueryCache.class).toInstance(new MapQueryCache(5));
binder.bind(RuntimeProperties.class).toInstance(new DefaultRuntimeProperties(Collections.<String, String>emptyMap()));
binder.bind(ObjectMapRetainStrategy.class).to(DefaultObjectMapRetainStrategy.class);
binder.bind(ObjectStoreFactory.class).to(DefaultObjectStoreFactory.class);
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
binder.bind(EventBridge.class).toProvider(NoopEventBridgeProvider.class);
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
};
Injector injector = DIBootstrap.createInjector(testModule);
DataContextFactory factory = new DataContextFactory();
injector.injectMembers(factory);
DataContext c3 = (DataContext) factory.createContext();
assertNotNull(c3.getObjectStore().getDataRowCache());
assertNull(domain.getSharedSnapshotCache());
assertNotSame(c3.getObjectStore().getDataRowCache(), domain.getSharedSnapshotCache());
}
use of org.apache.cayenne.access.DataContext in project cayenne by apache.
the class ServerRuntimeTest method testGetObjectContext_CustomModule.
@Test
public void testGetObjectContext_CustomModule() {
final ObjectContext context = new DataContext();
final ObjectContextFactory factory = new ObjectContextFactory() {
public ObjectContext createContext(DataChannel parent) {
return context;
}
public ObjectContext createContext() {
return context;
}
};
Module module = binder -> binder.bind(ObjectContextFactory.class).toInstance(factory);
ServerRuntime runtime = new ServerRuntime(Collections.singleton(module));
assertSame(context, runtime.newContext());
assertSame(context, runtime.newContext());
}
Aggregations