Search in sources :

Example 1 with EventManager

use of org.apache.cayenne.event.EventManager in project cayenne by apache.

the class CayenneContextGraphManager method send.

/**
 * Wraps GraphDiff in a GraphEvent and sends it via EventManager with specified
 * subject.
 */
void send(GraphDiff diff, EventSubject subject, Object eventSource) {
    EventManager manager = (context.getChannel() != null) ? context.getChannel().getEventManager() : null;
    if (manager != null) {
        GraphEvent e = new GraphEvent(context, eventSource, diff);
        manager.postEvent(e, subject);
    }
}
Also used : GraphEvent(org.apache.cayenne.graph.GraphEvent) EventManager(org.apache.cayenne.event.EventManager)

Example 2 with EventManager

use of org.apache.cayenne.event.EventManager in project cayenne by apache.

the class BaseContext method fireDataChannelRolledback.

/**
 * @since 1.2
 */
protected void fireDataChannelRolledback(Object postedBy, GraphDiff changes) {
    EventManager manager = getEventManager();
    if (manager != null) {
        GraphEvent e = new GraphEvent(this, postedBy, changes);
        manager.postEvent(e, DataChannel.GRAPH_ROLLEDBACK_SUBJECT);
    }
}
Also used : GraphEvent(org.apache.cayenne.graph.GraphEvent) EventManager(org.apache.cayenne.event.EventManager)

Example 3 with EventManager

use of org.apache.cayenne.event.EventManager in project cayenne by apache.

the class BaseContext method fireDataChannelCommitted.

/**
 * @since 1.2
 */
protected void fireDataChannelCommitted(Object postedBy, GraphDiff changes) {
    EventManager manager = getEventManager();
    if (manager != null) {
        GraphEvent e = new GraphEvent(this, postedBy, changes);
        manager.postEvent(e, DataChannel.GRAPH_FLUSHED_SUBJECT);
    }
}
Also used : GraphEvent(org.apache.cayenne.graph.GraphEvent) EventManager(org.apache.cayenne.event.EventManager)

Example 4 with EventManager

use of org.apache.cayenne.event.EventManager 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());
}
Also used : RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) Injector(org.apache.cayenne.di.Injector) DataContext(org.apache.cayenne.access.DataContext) DataRowStoreFactory(org.apache.cayenne.access.DataRowStoreFactory) MapQueryCache(org.apache.cayenne.cache.MapQueryCache) TransactionManager(org.apache.cayenne.tx.TransactionManager) QueryCache(org.apache.cayenne.cache.QueryCache) Module(org.apache.cayenne.di.Module) ObjectMapRetainStrategy(org.apache.cayenne.access.ObjectMapRetainStrategy) ObjectStoreFactory(org.apache.cayenne.configuration.ObjectStoreFactory) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) DataDomain(org.apache.cayenne.access.DataDomain) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) EventBridge(org.apache.cayenne.event.EventBridge) MockEventManager(org.apache.cayenne.event.MockEventManager) JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) TransactionFactory(org.apache.cayenne.tx.TransactionFactory) DefaultDataRowStoreFactory(org.apache.cayenne.access.DefaultDataRowStoreFactory) DIBootstrap(org.apache.cayenne.di.DIBootstrap) DefaultTransactionManager(org.apache.cayenne.tx.DefaultTransactionManager) DefaultTransactionFactory(org.apache.cayenne.tx.DefaultTransactionFactory) Test(org.junit.Test) DefaultObjectMapRetainStrategy(org.apache.cayenne.access.DefaultObjectMapRetainStrategy) EventManager(org.apache.cayenne.event.EventManager) NoopEventBridgeProvider(org.apache.cayenne.event.NoopEventBridgeProvider) Assert(org.junit.Assert) Collections(java.util.Collections) DefaultObjectStoreFactory(org.apache.cayenne.configuration.DefaultObjectStoreFactory) DataDomain(org.apache.cayenne.access.DataDomain) MockEventManager(org.apache.cayenne.event.MockEventManager) EventManager(org.apache.cayenne.event.EventManager) DefaultObjectStoreFactory(org.apache.cayenne.configuration.DefaultObjectStoreFactory) MapQueryCache(org.apache.cayenne.cache.MapQueryCache) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) DefaultDataRowStoreFactory(org.apache.cayenne.access.DefaultDataRowStoreFactory) DefaultTransactionManager(org.apache.cayenne.tx.DefaultTransactionManager) DataContext(org.apache.cayenne.access.DataContext) DefaultObjectMapRetainStrategy(org.apache.cayenne.access.DefaultObjectMapRetainStrategy) DefaultTransactionFactory(org.apache.cayenne.tx.DefaultTransactionFactory) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) Injector(org.apache.cayenne.di.Injector) NoopEventBridgeProvider(org.apache.cayenne.event.NoopEventBridgeProvider) Module(org.apache.cayenne.di.Module) MockEventManager(org.apache.cayenne.event.MockEventManager) Test(org.junit.Test)

Example 5 with EventManager

use of org.apache.cayenne.event.EventManager 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)

Aggregations

EventManager (org.apache.cayenne.event.EventManager)14 Test (org.junit.Test)7 Module (org.apache.cayenne.di.Module)6 DefaultRuntimeProperties (org.apache.cayenne.configuration.DefaultRuntimeProperties)5 RuntimeProperties (org.apache.cayenne.configuration.RuntimeProperties)5 DIBootstrap (org.apache.cayenne.di.DIBootstrap)5 Injector (org.apache.cayenne.di.Injector)5 EventBridge (org.apache.cayenne.event.EventBridge)5 NoopEventBridgeProvider (org.apache.cayenne.event.NoopEventBridgeProvider)5 JdbcEventLogger (org.apache.cayenne.log.JdbcEventLogger)5 Slf4jJdbcEventLogger (org.apache.cayenne.log.Slf4jJdbcEventLogger)5 TransactionFactory (org.apache.cayenne.tx.TransactionFactory)5 Collections (java.util.Collections)4 DefaultTransactionFactory (org.apache.cayenne.tx.DefaultTransactionFactory)4 DefaultTransactionManager (org.apache.cayenne.tx.DefaultTransactionManager)4 TransactionManager (org.apache.cayenne.tx.TransactionManager)4 Assert (org.junit.Assert)4 DataContext (org.apache.cayenne.access.DataContext)3 DataDomain (org.apache.cayenne.access.DataDomain)3 DataRowStoreFactory (org.apache.cayenne.access.DataRowStoreFactory)3