Search in sources :

Example 1 with MapQueryCache

use of org.apache.cayenne.cache.MapQueryCache 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 2 with MapQueryCache

use of org.apache.cayenne.cache.MapQueryCache 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 3 with MapQueryCache

use of org.apache.cayenne.cache.MapQueryCache 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 4 with MapQueryCache

use of org.apache.cayenne.cache.MapQueryCache in project cayenne by apache.

the class DataContextQueryCachingIT method setUp.

@Before
public void setUp() throws Exception {
    tArtist = new TableHelper(dbHelper, "ARTIST");
    tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
    tPainting = new TableHelper(dbHelper, "PAINTING");
    tPainting.setColumns("PAINTING_ID", "PAINTING_TITLE", "ARTIST_ID", "ESTIMATED_PRICE");
    domain = context.getParentDataDomain();
    oldCache = domain.getQueryCache();
    domain.setQueryCache(new MapQueryCache(50));
    context.setQueryCache(new MapQueryCache(50));
}
Also used : TableHelper(org.apache.cayenne.test.jdbc.TableHelper) MapQueryCache(org.apache.cayenne.cache.MapQueryCache) Before(org.junit.Before)

Example 5 with MapQueryCache

use of org.apache.cayenne.cache.MapQueryCache in project cayenne by apache.

the class CacheInvalidationCacheGroupsHandlerIT method buildCustomModule.

@Override
protected Module buildCustomModule() {
    // Proxy query cache that will count methods calls
    final QueryCache cache = new MapQueryCache() {

        @Override
        public void removeGroup(String groupKey) {
            removeGroupUntypedCounter.incrementAndGet();
            super.removeGroup(groupKey);
        }

        @Override
        public void removeGroup(String groupKey, Class<?> keyType, Class<?> valueType) {
            removeGroupTypedCounter.incrementAndGet();
            super.removeGroup(groupKey, keyType, valueType);
        }
    };
    return binder -> binder.bind(QueryCache.class).toInstance(cache);
}
Also used : ObjectContext(org.apache.cayenne.ObjectContext) MapQueryCache(org.apache.cayenne.cache.MapQueryCache) E1(org.apache.cayenne.cache.invalidation.db.E1) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) E2(org.apache.cayenne.cache.invalidation.db.E2) QueryCache(org.apache.cayenne.cache.QueryCache) Module(org.apache.cayenne.di.Module) ObjectSelect(org.apache.cayenne.query.ObjectSelect) Test(org.junit.Test) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) MapQueryCache(org.apache.cayenne.cache.MapQueryCache) QueryCache(org.apache.cayenne.cache.QueryCache) MapQueryCache(org.apache.cayenne.cache.MapQueryCache)

Aggregations

MapQueryCache (org.apache.cayenne.cache.MapQueryCache)6 DataDomain (org.apache.cayenne.access.DataDomain)3 QueryCache (org.apache.cayenne.cache.QueryCache)3 Module (org.apache.cayenne.di.Module)3 Test (org.junit.Test)3 Collections (java.util.Collections)2 DataContext (org.apache.cayenne.access.DataContext)2 DataRowStoreFactory (org.apache.cayenne.access.DataRowStoreFactory)2 DefaultDataRowStoreFactory (org.apache.cayenne.access.DefaultDataRowStoreFactory)2 DefaultObjectMapRetainStrategy (org.apache.cayenne.access.DefaultObjectMapRetainStrategy)2 ObjectMapRetainStrategy (org.apache.cayenne.access.ObjectMapRetainStrategy)2 DefaultObjectStoreFactory (org.apache.cayenne.configuration.DefaultObjectStoreFactory)2 DefaultRuntimeProperties (org.apache.cayenne.configuration.DefaultRuntimeProperties)2 ObjectStoreFactory (org.apache.cayenne.configuration.ObjectStoreFactory)2 RuntimeProperties (org.apache.cayenne.configuration.RuntimeProperties)2 DIBootstrap (org.apache.cayenne.di.DIBootstrap)2 Injector (org.apache.cayenne.di.Injector)2 DefaultEventManager (org.apache.cayenne.event.DefaultEventManager)2 EventBridge (org.apache.cayenne.event.EventBridge)2 EventManager (org.apache.cayenne.event.EventManager)2