use of org.apache.cayenne.event.DefaultEventManager in project cayenne by apache.
the class CayenneContextIT method testCommitChangesNew.
@Test
public void testCommitChangesNew() {
final CompoundDiff diff = new CompoundDiff();
final Object newObjectId = new ObjectId("test", "key", "generated");
eventManager = new DefaultEventManager(0);
// test that ids that are passed back are actually propagated to the
// right
// objects...
MockDataChannel channel = new MockDataChannel() {
@Override
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType) {
return diff;
}
// must provide a channel with working event manager
@Override
public EventManager getEventManager() {
return eventManager;
}
};
CayenneContext context = new CayenneContext(channel);
ObjEntity entity = new ObjEntity("test_entity");
entity.setClassName(MockPersistentObject.class.getName());
DataMap dataMap = new DataMap("test");
dataMap.addObjEntity(entity);
Collection<DataMap> entities = Collections.singleton(dataMap);
context.setEntityResolver(new EntityResolver(entities));
Persistent object = context.newObject(MockPersistentObject.class);
// record change here to make it available to the anonymous connector
// method..
diff.add(new NodeIdChangeOperation(object.getObjectId(), newObjectId));
// check that a generated object ID is assigned back to the object...
assertNotSame(newObjectId, object.getObjectId());
context.commitChanges();
assertSame(newObjectId, object.getObjectId());
assertSame(object, context.graphManager.getNode(newObjectId));
}
use of org.apache.cayenne.event.DefaultEventManager in project cayenne by apache.
the class RemoteCayenneCase method createROPContext.
protected CayenneContext createROPContext() {
ClientServerChannel clientServerChannel = new ClientServerChannel(serverContext);
UnitLocalConnection connection = new UnitLocalConnection(clientServerChannel, serializationPolicy);
ClientChannel channel = new ClientChannel(connection, false, // TODO: replace with container managed ClientCase.
new DefaultEventManager(0), false);
CayenneContext context = new CayenneContext(channel, true, true);
context.setQueryCache(new MapQueryCache(10));
return context;
}
use of org.apache.cayenne.event.DefaultEventManager in project cayenne by apache.
the class SchemaBuilder method rebuildSchema.
/**
* Completely rebuilds test schema.
*/
// TODO - this method changes the internal state of the object ... refactor
public void rebuildSchema() {
// generate schema combining all DataMaps that require schema support.
// Schema generation is done like that instead of per DataMap on demand
// to avoid conflicts when dropping and generating PK objects.
DataMap[] maps = new DataMap[MAPS_REQUIRING_SCHEMA_SETUP.length];
for (int i = 0; i < maps.length; i++) {
URL mapURL = getClass().getClassLoader().getResource(MAPS_REQUIRING_SCHEMA_SETUP[i]);
maps[i] = loader.load(new URLResource(mapURL));
}
this.domain = new DataDomain("temp");
domain.setEventManager(new DefaultEventManager(2));
domain.setEntitySorter(new AshwoodEntitySorter());
domain.setQueryCache(new MapQueryCache(50));
try {
for (DataMap map : maps) {
initNode(map);
}
if ("true".equalsIgnoreCase(System.getProperty(SKIP_SCHEMA_KEY))) {
logger.info("skipping schema generation... ");
} else {
dropSchema();
dropPKSupport();
createSchema();
createPKSupport();
}
} catch (Exception e) {
throw new RuntimeException("Error rebuilding schema", e);
}
}
use of org.apache.cayenne.event.DefaultEventManager in project cayenne by apache.
the class DefaultDataRowStoreFactoryIT method testGetDataRowStoreWithBridge.
@Test
public void testGetDataRowStoreWithBridge() {
final DataDomain DOMAIN = new DataDomain("test");
final EventManager EVENT_MANAGER = new DefaultEventManager();
Module testModule = binder -> {
binder.bind(DataDomain.class).toInstance(DOMAIN);
binder.bind(EventManager.class).toInstance(EVENT_MANAGER);
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
binder.bind(EventBridge.class).toProvider(MockEventBridgeProvider.class);
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
ServerModule.contributeProperties(binder);
};
Injector injector = DIBootstrap.createInjector(testModule);
DataRowStore dataStore = injector.getInstance(DataRowStoreFactory.class).createDataRowStore("test");
assertEquals(dataStore.getEventBridge().getClass(), MockEventBridge.class);
}
use of org.apache.cayenne.event.DefaultEventManager in project cayenne by apache.
the class DataContextSharedCacheEmpiricIT method setUp.
@Before
public void setUp() throws Exception {
eventManager = new DefaultEventManager();
DataRowStore cache = new DataRowStore("cacheTest", new DefaultRuntimeProperties(Collections.<String, String>emptyMap()), eventManager);
c1 = new DataContext(runtime.getDataDomain(), objectStoreFactory.createObjectStore(cache));
c2 = new DataContext(runtime.getDataDomain(), objectStoreFactory.createObjectStore(cache));
// prepare a single artist record
TableHelper tArtist = new TableHelper(dbHelper, "ARTIST");
tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
tArtist.insert(1, "version1");
}
Aggregations