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;
}
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);
}
}
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());
}
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));
}
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);
}
Aggregations