Search in sources :

Example 1 with DefaultEventManager

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));
}
Also used : NodeIdChangeOperation(org.apache.cayenne.graph.NodeIdChangeOperation) GraphDiff(org.apache.cayenne.graph.GraphDiff) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) EntityResolver(org.apache.cayenne.map.EntityResolver) DataMap(org.apache.cayenne.map.DataMap) ObjEntity(org.apache.cayenne.map.ObjEntity) CompoundDiff(org.apache.cayenne.graph.CompoundDiff) Test(org.junit.Test)

Example 2 with DefaultEventManager

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;
}
Also used : UnitLocalConnection(org.apache.cayenne.unit.UnitLocalConnection) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) MapQueryCache(org.apache.cayenne.cache.MapQueryCache) ClientServerChannel(org.apache.cayenne.access.ClientServerChannel) CayenneContext(org.apache.cayenne.CayenneContext)

Example 3 with DefaultEventManager

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);
    }
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) DataDomain(org.apache.cayenne.access.DataDomain) AshwoodEntitySorter(org.apache.cayenne.ashwood.AshwoodEntitySorter) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) MapQueryCache(org.apache.cayenne.cache.MapQueryCache) URL(java.net.URL) SQLException(java.sql.SQLException) DataMap(org.apache.cayenne.map.DataMap)

Example 4 with DefaultEventManager

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);
}
Also used : RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) Injector(org.apache.cayenne.di.Injector) TransactionManager(org.apache.cayenne.tx.TransactionManager) ServerCase(org.apache.cayenne.unit.di.server.ServerCase) Module(org.apache.cayenne.di.Module) MockEventBridgeProvider(org.apache.cayenne.event.MockEventBridgeProvider) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) EventBridge(org.apache.cayenne.event.EventBridge) JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) TransactionFactory(org.apache.cayenne.tx.TransactionFactory) ServerModule(org.apache.cayenne.configuration.server.ServerModule) DIBootstrap(org.apache.cayenne.di.DIBootstrap) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) MockEventBridge(org.apache.cayenne.event.MockEventBridge) DefaultTransactionManager(org.apache.cayenne.tx.DefaultTransactionManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) DefaultTransactionFactory(org.apache.cayenne.tx.DefaultTransactionFactory) Test(org.junit.Test) CayenneProjects(org.apache.cayenne.unit.di.server.CayenneProjects) EventManager(org.apache.cayenne.event.EventManager) NoopEventBridgeProvider(org.apache.cayenne.event.NoopEventBridgeProvider) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) UseServerRuntime(org.apache.cayenne.unit.di.server.UseServerRuntime) Assert.assertEquals(org.junit.Assert.assertEquals) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) EventManager(org.apache.cayenne.event.EventManager) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) DefaultTransactionManager(org.apache.cayenne.tx.DefaultTransactionManager) DefaultTransactionFactory(org.apache.cayenne.tx.DefaultTransactionFactory) MockEventBridgeProvider(org.apache.cayenne.event.MockEventBridgeProvider) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) ServerModule(org.apache.cayenne.configuration.server.ServerModule) Test(org.junit.Test)

Example 5 with DefaultEventManager

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");
}
Also used : DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) TableHelper(org.apache.cayenne.test.jdbc.TableHelper) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) Before(org.junit.Before)

Aggregations

DefaultEventManager (org.apache.cayenne.event.DefaultEventManager)10 Test (org.junit.Test)7 DefaultRuntimeProperties (org.apache.cayenne.configuration.DefaultRuntimeProperties)4 Injector (org.apache.cayenne.di.Injector)3 EventBridge (org.apache.cayenne.event.EventBridge)3 EventManager (org.apache.cayenne.event.EventManager)3 HashMap (java.util.HashMap)2 MapQueryCache (org.apache.cayenne.cache.MapQueryCache)2 RuntimeProperties (org.apache.cayenne.configuration.RuntimeProperties)2 ServerModule (org.apache.cayenne.configuration.server.ServerModule)2 ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)2 DIBootstrap (org.apache.cayenne.di.DIBootstrap)2 Module (org.apache.cayenne.di.Module)2 MockEventBridge (org.apache.cayenne.event.MockEventBridge)2 MockEventBridgeProvider (org.apache.cayenne.event.MockEventBridgeProvider)2 NoopEventBridgeProvider (org.apache.cayenne.event.NoopEventBridgeProvider)2 JdbcEventLogger (org.apache.cayenne.log.JdbcEventLogger)2 Slf4jJdbcEventLogger (org.apache.cayenne.log.Slf4jJdbcEventLogger)2 DataMap (org.apache.cayenne.map.DataMap)2 DefaultTransactionFactory (org.apache.cayenne.tx.DefaultTransactionFactory)2