Search in sources :

Example 11 with JCacheManager

use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.

the class InvokeProcessorTest method invokeProcessor.

private void invokeProcessor(Method m, final MutableConfiguration<String, Entry> jcacheCfg) {
    final String name = getName(m);
    CacheManager cm = new JCacheManager(URI.create(name), TestCacheManagerFactory.createCacheManager(JCacheTestSCI.INSTANCE), null);
    Cache<String, Entry> cache = cm.createCache(name, jcacheCfg);
    ArrayList<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3));
    final String query = "select * from x";
    cache.put(query, new Entry(list));
    cache.invoke(query, new TestEntryProcessor());
    assertEquals(new ArrayList<>(Arrays.asList(1, 2, 3, 4)), cache.get(query).integers);
}
Also used : MutableEntry(javax.cache.processor.MutableEntry) JCacheManager(org.infinispan.jcache.embedded.JCacheManager) ArrayList(java.util.ArrayList) CacheManager(javax.cache.CacheManager) JCacheManager(org.infinispan.jcache.embedded.JCacheManager)

Example 12 with JCacheManager

use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.

the class InvokeProcessorTest method invokeProcessorThrowsException.

private void invokeProcessorThrowsException(Method m, final MutableConfiguration<String, Entry> jcacheCfg, final List<Integer> expectedValue) {
    final String name = getName(m);
    CacheManager cm = new JCacheManager(URI.create(name), TestCacheManagerFactory.createCacheManager(JCacheTestSCI.INSTANCE), null);
    Cache<String, Entry> cache = cm.createCache(name, jcacheCfg);
    final String query = "select * from x";
    cache.put(query, new Entry(new ArrayList<>(Arrays.asList(1, 2, 3))));
    try {
        cache.invoke(query, new TestExceptionThrowingEntryProcessor());
        fail("Expected an exception to be thrown");
    } catch (CacheException e) {
        assertTrue(e.getCause() instanceof UnexpectedException);
    }
    assertEquals(expectedValue, cache.get(query).integers);
}
Also used : MutableEntry(javax.cache.processor.MutableEntry) CacheException(javax.cache.CacheException) JCacheManager(org.infinispan.jcache.embedded.JCacheManager) ArrayList(java.util.ArrayList) CacheManager(javax.cache.CacheManager) JCacheManager(org.infinispan.jcache.embedded.JCacheManager)

Example 13 with JCacheManager

use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.

the class JCacheConfigurationTest method testNamedCacheConfiguration.

public void testNamedCacheConfiguration() {
    withCacheManager(TestCacheManagerFactory.createCacheManager(false), cm -> {
        cm.defineConfiguration("oneCache", new ConfigurationBuilder().build());
        JCacheManager jCacheManager = new JCacheManager(URI.create("oneCacheManager"), cm, null);
        assertNotNull(jCacheManager.getCache("oneCache"));
    });
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) PrivateGlobalConfigurationBuilder(org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) JCacheManager(org.infinispan.jcache.embedded.JCacheManager)

Example 14 with JCacheManager

use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.

the class InjectedCacheResolver method resolveCache.

@Override
public <K, V> Cache<K, V> resolveCache(final CacheInvocationContext<? extends Annotation> cacheInvocationContext) {
    Contracts.assertNotNull(cacheInvocationContext, "cacheInvocationContext parameter must not be null");
    final String cacheName = cacheInvocationContext.getCacheName();
    // If the cache name is empty the default cache of the default cache manager is returned.
    if (cacheName.trim().isEmpty()) {
        if (log.isTraceEnabled())
            log.tracef("Resolved cache %s on %s", cacheName, defaultJCacheManager.getURI());
        return getCacheFromDefaultCacheManager(cacheName);
    }
    // interceptor could use a specific cache manager.
    for (final EmbeddedCacheManager cm : jcacheManagers.keySet()) {
        final Set<String> cacheNames = cm.getCacheNames();
        for (final String name : cacheNames) {
            if (name.equals(cacheName)) {
                final JCacheManager jcacheManager = jcacheManagers.get(cm);
                final Cache<K, V> cache = jcacheManager.getCache(cacheName);
                if (cache != null)
                    return cache;
                if (log.isTraceEnabled())
                    log.tracef("Resolved cache %s on %s", cacheName, jcacheManager.getURI());
                return jcacheManager.getOrCreateCache(cacheName, cm.<K, V>getCache(cacheName).getAdvancedCache());
            }
        }
    }
    // cache manager with the default configuration.
    return getCacheFromDefaultCacheManager(cacheName);
}
Also used : JCacheManager(org.infinispan.jcache.embedded.JCacheManager) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Aggregations

JCacheManager (org.infinispan.jcache.embedded.JCacheManager)14 URI (java.net.URI)6 MutableConfiguration (javax.cache.configuration.MutableConfiguration)5 Properties (java.util.Properties)4 Cache (javax.cache.Cache)4 AdvancedCache (org.infinispan.AdvancedCache)4 PrivateGlobalConfiguration (org.infinispan.configuration.internal.PrivateGlobalConfiguration)4 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)3 PrivateGlobalConfigurationBuilder (org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder)3 InMemoryJCacheLoader (org.infinispan.jcache.util.InMemoryJCacheLoader)3 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)3 CacheManagerCallable (org.infinispan.test.CacheManagerCallable)3 File (java.io.File)2 URLClassLoader (java.net.URLClassLoader)2 ArrayList (java.util.ArrayList)2 CacheManager (javax.cache.CacheManager)2 MutableEntry (javax.cache.processor.MutableEntry)2 Configuration (org.infinispan.configuration.cache.Configuration)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)2