javax.cache.spi.CachingProvider Java Examples

The following examples show how to use javax.cache.spi.CachingProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleEh107ConfigTest.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoaderConfiguration() throws Exception {
  final AtomicBoolean loaderCreated = new AtomicBoolean(false);

  MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
  configuration.setTypes(String.class, String.class).setReadThrough(true);
  configuration.setCacheLoaderFactory(() -> {
    loaderCreated.set(true);
    return new TestCacheLoader();
  });

  CachingProvider provider = Caching.getCachingProvider();
  CacheManager cacheManager = provider.getCacheManager();
  Cache<String, String> cache = cacheManager.createCache("cache", configuration);

  assertThat(loaderCreated.get(), is(true));

  cache.putIfAbsent("42", "The Answer");

  TestCacheLoader.seen.clear();
  CompletionListenerFuture future = new CompletionListenerFuture();
  cache.loadAll(Collections.singleton("42"), true, future);
  future.get();

  assertThat(TestCacheLoader.seen, contains("42"));
}
 
Example #2
Source File: TestJCache.java    From jframe with Apache License 2.0 6 votes vote down vote up
@Test
public void cacheConfigTest() {
    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();

    MutableConfiguration<Long, String> configuration = new MutableConfiguration<Long, String>();
    configuration.setTypes(Long.class, String.class);
    Cache<Long, String> cache = cacheManager.createCache("someCache", configuration);

    CompleteConfiguration<Long, String> completeConfiguration = cache.getConfiguration(CompleteConfiguration.class);

    Eh107Configuration<Long, String> eh107Configuration = cache.getConfiguration(Eh107Configuration.class);

    CacheRuntimeConfiguration<Long, String> runtimeConfiguration = eh107Configuration
            .unwrap(CacheRuntimeConfiguration.class);
}
 
Example #3
Source File: CacheManagerClassLoadingTest.java    From cache2k with Apache License 2.0 6 votes vote down vote up
/**
 * Request cache manager with different class loader and put a value in the cache that
 * was loaded by that class loader. equals() needs to work and class loaders needs to be
 * identical
 */
@Test
public void testCorrectClassLoaderForValue() throws Exception {
  SpecialClassLoader loader = new SpecialClassLoader();
  CachingProvider provider = Caching.getCachingProvider();
  CacheManager mgr = Caching.getCachingProvider().getCacheManager(provider.getDefaultURI(), loader);
  Cache<Object, Object> cache = mgr.createCache(CACHE_NAME, new MutableConfiguration());
  Class valueClass = loader.loadSpecial(DomainValue.class);
  assertEquals(valueClass.getClassLoader(), loader);
  Object value = valueClass.newInstance();
  setValue(value, "someValue");
  String someKey = "Key";
  cache.put(someKey, value);
  Cache.Entry e = cache.iterator().next();
  assertSame("class loaders identical", value.getClass().getClassLoader(), e.getValue().getClass().getClassLoader());
  assertEquals(value, e.getValue());
  mgr.close();
}
 
Example #4
Source File: CacheLoaderTest.java    From blazingcache with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoReadThrough() {

    CachingProvider cachingProvider = Caching.getCachingProvider();
    Properties p = new Properties();
    try (CacheManager cacheManager = cachingProvider.getCacheManager(cachingProvider.getDefaultURI(), cachingProvider.getDefaultClassLoader(), p)) {
        MutableConfiguration<String, String> config
                = new MutableConfiguration<String, String>()
                .setTypes(String.class, String.class)
                .setCacheLoaderFactory(new FactoryBuilder.ClassFactory(MockCacheLoader.class))
                .setReadThrough(false);

        Cache<String, String> cache = cacheManager.createCache("simpleCache", config);

        String key = "key";
        String result = cache.get(key);
        assertNull(result);
    }
}
 
Example #5
Source File: ParametersInURITest.java    From blazingcache with Apache License 2.0 6 votes vote down vote up
@Test
public void testParametersInURI() throws URISyntaxException {

    CachingProvider cachingProvider = Caching.getCachingProvider();
    Properties p = new Properties();
    try (CacheManager cacheManager = cachingProvider.getCacheManager(new URI(cachingProvider.getDefaultURI() + "?secret=testsecret"), cachingProvider.getDefaultClassLoader(), p)) {
        MutableConfiguration<String, Integer> config
                = new MutableConfiguration<String, Integer>()
                .setTypes(String.class, Integer.class)
                .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR))
                .setStatisticsEnabled(true);

        Cache<String, Integer> cache = cacheManager.createCache("simpleCache", config);
        BlazingCacheManager manager = cacheManager.unwrap(BlazingCacheManager.class);
        assertEquals("testsecret", manager.getProperties().get("blazingcache.secret"));

        String key = "key";
        Integer value1 = 1;
        cache.put("key", value1);
        Integer value2 = cache.get(key);
        assertEquals(value1, value2);
        cache.remove(key);
        assertNull(cache.get(key));
    }
}
 
Example #6
Source File: JSRExamplesTest.java    From blazingcache with Apache License 2.0 6 votes vote down vote up
@Test
public void testJSRExample1() {

    CachingProvider cachingProvider = Caching.getCachingProvider();
    Properties p = new Properties();
    try (CacheManager cacheManager = cachingProvider.getCacheManager(cachingProvider.getDefaultURI(), cachingProvider.getDefaultClassLoader(), p)) {
        MutableConfiguration<String, Integer> config
                = new MutableConfiguration<String, Integer>()
                .setTypes(String.class, Integer.class)
                .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR))
                .setStatisticsEnabled(true);

        Cache<String, Integer> cache = cacheManager.createCache("simpleCache", config);

        String key = "key";
        Integer value1 = 1;
        cache.put("key", value1);
        Integer value2 = cache.get(key);
        assertEquals(value1, value2);
        cache.remove(key);
        assertNull(cache.get(key));
    }
}
 
Example #7
Source File: CacheWriterTest.java    From blazingcache with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldWriteThroughUsingInvoke_remove_nonExistingEntry() {
    RecordingCacheWriter<Integer, String> cacheWriter = new RecordingCacheWriter<>();
    CachingProvider cachingProvider = Caching.getCachingProvider();
    Properties p = new Properties();
    try (CacheManager cacheManager = cachingProvider.getCacheManager(cachingProvider.getDefaultURI(), cachingProvider.getDefaultClassLoader(), p)) {
        MutableConfiguration<Integer, String> config
                = new MutableConfiguration<Integer, String>()
                .setTypes(Integer.class, String.class)
                .setCacheWriterFactory(new FactoryBuilder.SingletonFactory<>(cacheWriter))
                .setWriteThrough(true);

        Cache<Integer, String> cache = cacheManager.createCache("simpleCache", config);
        assertEquals(0, cacheWriter.getWriteCount());
        assertEquals(0, cacheWriter.getDeleteCount());

        cache.invoke(1, new RemoveEntryProcessor<Integer, String, Object>());
        assertEquals(0, cacheWriter.getWriteCount());
        assertEquals(1, cacheWriter.getDeleteCount());
        assertFalse(cacheWriter.hasWritten(1));
    }
}
 
Example #8
Source File: ManagementTest.java    From blazingcache with Apache License 2.0 6 votes vote down vote up
@Test
public void testCacheStatisticsInvokeEntryProcessorRemove() throws Exception {
    CachingProvider cachingProvider = Caching.getCachingProvider();
    Properties p = new Properties();
    try (CacheManager cacheManager = cachingProvider.getCacheManager(cachingProvider.getDefaultURI(), cachingProvider.getDefaultClassLoader(), p)) {
        MutableConfiguration<Long, String> config
                = new MutableConfiguration<Long, String>()
                .setTypes(Long.class, String.class)
                .setStatisticsEnabled(true)
                .setManagementEnabled(true);
        BlazingCacheCache<Long, String> cache = cacheManager.createCache("simpleCache", config).unwrap(BlazingCacheCache.class);

        cache.put(1l, "Sooty");
        String result = cache.invoke(1l, new RemoveEntryProcessor<Long, String, String>(true));
        assertEquals(result, "Sooty");
        assertEquals((int) 1, (int) cache.getStatisticsMXBean().getCacheHits());
        assertEquals((int) 1, (int) cache.getStatisticsMXBean().getCachePuts());
        assertEquals((int) 1, (int) cache.getStatisticsMXBean().getCacheRemovals());
    }
}
 
Example #9
Source File: CachingProviderClassLoaderTest.java    From cache2k with Apache License 2.0 6 votes vote down vote up
/**
 * Close all CacheManagers from a CachingProvider, each CacheManager being
 * based on a different ClassLoader.
 */
@Test
public void closeAllCacheManagers() throws Exception {
  ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();

  CachingProvider provider = Caching.getCachingProvider(contextLoader);

  URI uri = provider.getDefaultURI();

  ClassLoader loader1 = new MyClassLoader(contextLoader);
  CacheManager manager1 = provider.getCacheManager(uri, loader1);

  ClassLoader loader2 = new MyClassLoader(contextLoader);
  CacheManager manager2 = provider.getCacheManager(uri, loader2);

  ClassLoader loader3 = new MyClassLoader(contextLoader);
  CacheManager manager3 = provider.getCacheManager(uri, loader3);

  provider.close();

  assertNotSame(manager1, provider.getCacheManager(uri, loader1));
  assertNotSame(manager2, provider.getCacheManager(uri, loader2));
  assertNotSame(manager3, provider.getCacheManager(uri, loader3));
}
 
Example #10
Source File: JCacheProxy.java    From bucket4j with Apache License 2.0 6 votes vote down vote up
private void checkProviders(Cache<K, GridBucketState> cache) {
    CacheManager cacheManager = cache.getCacheManager();
    if (cacheManager == null) {
        return;
    }

    CachingProvider cachingProvider = cacheManager.getCachingProvider();
    if (cachingProvider == null) {
        return;
    }

    String providerClassName = cachingProvider.getClass().getName();
    incompatibleProviders.forEach((providerPrefix, recommendation) -> {
        if (providerClassName.startsWith(providerPrefix)) {
            String message = "The Cache provider " + providerClassName + " is incompatible with Bucket4j, " + recommendation;
            throw new UnsupportedOperationException(message);
        }
    });
}
 
Example #11
Source File: CachingProviderTest.java    From cache2k with Apache License 2.0 6 votes vote down vote up
@Test
public void closeCacheManagersByClassLoader() {
  CachingProvider provider = Caching.getCachingProvider();

  ClassLoader loader1 = CLASS_LOADER;
  CacheManager manager1 = provider.getCacheManager(provider.getDefaultURI(), loader1, null);

  ClassLoader loader2 = new MyClassLoader(CLASS_LOADER);
  CacheManager manager2 = provider.getCacheManager(provider.getDefaultURI(), loader2, null);

  provider.close(loader1);
  provider.close(loader2);

  assertNotSame(manager1, provider.getCacheManager(provider.getDefaultURI(), loader1, null));
  assertNotSame(manager2, provider.getCacheManager(provider.getDefaultURI(), loader2, null));
}
 
Example #12
Source File: EntityCacheTest.java    From requery with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerializeGetPut() {
    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();

    EntityCache cache = new EntityCacheBuilder(Models.DEFAULT)
            .useReferenceCache(false)
            .useSerializableCache(true)
            .useCacheManager(cacheManager)
            .build();

    Person p = new Person();
    p.setName("Alice");
    p.setUUID(UUID.randomUUID());
    p.setAddress(new Address());
    p.getAddress().setType(AddressType.HOME);

    int id = 100;
    cache.put(Person.class, id, p);

    Person d = cache.get(Person.class, id);
    Assert.assertNotNull(d);
    Assert.assertNotSame(p, d);
    Assert.assertEquals(p.getName(), d.getName());
    Assert.assertEquals(p.getUUID(), d.getUUID());
}
 
Example #13
Source File: CachingProviderClassLoaderTest.java    From cache2k with Apache License 2.0 6 votes vote down vote up
/**
 * The URI of the CacheManager returned by {@link CachingProvider#getCacheManager(java.net.URI, ClassLoader)}
 * is the same as the URI used in the invocation.
 */
@Test
public void getCacheManagerSameURI() {
  ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();

  CachingProvider provider = Caching.getCachingProvider(contextLoader);
  URI uri = provider.getDefaultURI();

  CacheManager manager = provider.getCacheManager(uri, contextLoader);
  assertEquals(uri, manager.getURI());

  // using a different ClassLoader
  ClassLoader otherLoader = new MyClassLoader(contextLoader);
  CachingProvider otherProvider = Caching.getCachingProvider(otherLoader);
  assertNotSame(provider, otherProvider);

  CacheManager otherManager = otherProvider.getCacheManager(uri, contextLoader);
  assertNotSame(manager, otherManager);
  assertEquals(uri, otherManager.getURI());
}
 
Example #14
Source File: JPAModelTest.java    From requery with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws SQLException {
    CommonDataSource dataSource = DatabaseType.getDataSource(new H2());
    EntityModel model = Models.JPA;

    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();
    Configuration configuration = new ConfigurationBuilder(dataSource, model)
        .useDefaultLogging()
        .setEntityCache(new EntityCacheBuilder(model)
            .useReferenceCache(true)
            .useSerializableCache(true)
            .useCacheManager(cacheManager)
            .build())
        .build();
    data = new EntityDataStore<>(configuration);
    SchemaModifier tables = new SchemaModifier(configuration);
    tables.dropTables();
    TableCreationMode mode = TableCreationMode.CREATE;
    System.out.println(tables.createTablesString(mode));
    tables.createTables(mode);
}
 
Example #15
Source File: CachingTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
/**
 * Multiple invocations of {@link CachingProvider#getCacheManager()} return the same CacheManager
 */
@Test
public void getCacheManager_singleton() {
  CachingProvider provider = Caching.getCachingProvider();

  CacheManager manager = provider.getCacheManager();
  manager.getProperties();
  assertNotNull(manager);
  assertSame(manager, provider.getCacheManager());
}
 
Example #16
Source File: CachingProviderClassLoaderTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
/**
 * Multiple invocations of {@link javax.cache.spi.CachingProvider#getCacheManager()}
 * will return the same instance.
 */
@Test
public void getCacheManagerSingleton() {

  // obtain the default caching provider
  CachingProvider provider = Caching.getCachingProvider();

  // obtain the default class loader
  ClassLoader classLoader = Caching.getDefaultClassLoader();

  // obtain the default cache manager
  CacheManager manager = provider.getCacheManager();

  assertNotNull(classLoader);
  assertNotNull(manager);

  // ensure the default manager is the same as asking the provider
  // for a cache manager using the default URI and classloader
  assertSame(manager, provider.getCacheManager());
  assertSame(manager, provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader()));

  // using a different ClassLoader
  ClassLoader otherLoader = new MyClassLoader(classLoader);
  CachingProvider otherProvider = Caching.getCachingProvider(otherLoader);

  CacheManager otherManager = otherProvider.getCacheManager();
  assertSame(otherManager, otherProvider.getCacheManager());
  assertSame(otherManager, otherProvider.getCacheManager(otherProvider.getDefaultURI(), otherProvider.getDefaultClassLoader()));
}
 
Example #17
Source File: LoaderWriterTest.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);

  CachingProvider provider = Caching.getCachingProvider();
  cacheManager = provider.getCacheManager(this.getClass().getResource("/ehcache-loader-writer-107.xml").toURI(), getClass().getClassLoader());

  testCache = cacheManager.createCache("testCache", new MutableConfiguration<Number, CharSequence>()
      .setReadThrough(true)
      .setWriteThrough(true)
      .setCacheLoaderFactory(() -> cacheLoader)
      .setCacheWriterFactory(() -> cacheWriter)
      .setTypes(Number.class, CharSequence.class));
}
 
Example #18
Source File: CacheListenersTest.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateListenerSynch() {

    CachingProvider cachingProvider = Caching.getCachingProvider();
    Properties p = new Properties();
    try (CacheManager cacheManager = cachingProvider.getCacheManager(cachingProvider.getDefaultURI(), cachingProvider.getDefaultClassLoader(), p)) {
        Map<String, String> created = new HashMap<>();
        CacheEntryCreatedListener<String, String> listener = new CacheEntryCreatedListener<String, String>() {
            @Override
            public void onCreated(Iterable<CacheEntryEvent<? extends String, ? extends String>> events) throws CacheEntryListenerException {
                for (CacheEntryEvent<? extends String, ? extends String> e : events) {
                    created.put(e.getKey(), e.getValue());
                }
            }
        };

        MutableConfiguration<String, String> config
                = new MutableConfiguration<String, String>()
                .setTypes(String.class, String.class)
                .addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<>(
                        new FactoryBuilder.SingletonFactory(listener), null, true, true)
                );

        Cache<String, String> cache = cacheManager.createCache("simpleCache", config);

        String key = "key";
        cache.put(key, "value");
        assertEquals("value", created.get(key));
    }
}
 
Example #19
Source File: CachingTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test
public void getCacheManager_nullClassLoader() {
  CachingProvider provider = Caching.getCachingProvider();
  final ClassLoader NULL_CLASSLOADER = null;

  // null classloader is treated as provider.getDefaultClassLoader().
  CacheManager manager = provider.getCacheManager(provider.getDefaultURI(), NULL_CLASSLOADER, null);
  assertNotNull(manager);
  CacheManager sameManager = provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader(), null);
  assertEquals(sameManager, manager);
  assertEquals(sameManager.getClassLoader(), manager.getClassLoader());
}
 
Example #20
Source File: EventListenerIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Before
public void setup() {
    CachingProvider cachingProvider = Caching.getCachingProvider(CACHE_PROVIDER_NAME);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    MutableConfiguration<String, String> config = new MutableConfiguration<String, String>();
    this.cache = cacheManager.createCache("MyCache", config);
    this.listener = new SimpleCacheEntryListener();
}
 
Example #21
Source File: EmbeddedServerTest.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmbeddedServer() throws Exception {

    CachingProvider cachingProvider = Caching.getCachingProvider();
    Properties p_1 = new Properties();
    p_1.setProperty("blazingcache.mode", "server");
    p_1.setProperty("blazingcache.zookeeper.connectstring", zkServer.getConnectString());
    p_1.setProperty("blazingcache.server.port", "7000");

    Properties p_2 = new Properties();
    p_2.setProperty("blazingcache.mode", "server");
    p_2.setProperty("blazingcache.zookeeper.connectstring", zkServer.getConnectString());
    p_2.setProperty("blazingcache.server.port", "7001");

    try (CacheManager cacheManager_1 = cachingProvider
        .getCacheManager(new URI("cacheManager1"), cachingProvider.getDefaultClassLoader(), p_1);
        CacheManager cacheManager_2 = cachingProvider
            .getCacheManager(new URI("cacheManager2"), cachingProvider.getDefaultClassLoader(), p_2)) {

        assertNotSame(cacheManager_1, cacheManager_2);

        MutableConfiguration<String, MyBean> config
            = new MutableConfiguration<String, MyBean>()
                .setTypes(String.class, MyBean.class)
                .setStoreByValue(false);

        Cache<String, MyBean> cache_from_1 = cacheManager_1.createCache("simpleCache", config);
        MyBean bean_in_1 = new MyBean("foo");
        cache_from_1.put("foo", bean_in_1);
        assertSame(bean_in_1, cache_from_1.get("foo"));

        Cache<String, MyBean> cache_from_2 = cacheManager_2.createCache("simpleCache", config);
        MyBean bean_from_2 = cache_from_2.get("foo");
        assertEquals(bean_from_2, bean_in_1);

    }
}
 
Example #22
Source File: CacheManagerTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test
public void create_empty_config() {
  CachingProvider p = Caching.getCachingProvider();
  CacheManager cm = p.getCacheManager();
  MutableConfiguration<String, BigDecimal> mc = new ExtendedMutableConfiguration<String, BigDecimal>();
  mc.setTypes(String.class, BigDecimal.class);
  Cache<String, BigDecimal> c = cm.createCache("aCache", mc);
  assertEquals("aCache", c.getName());
  assertEquals(String.class, c.getConfiguration(Configuration.class).getKeyType());
  assertEquals(BigDecimal.class, c.getConfiguration(Configuration.class).getValueType());
  c.close();
}
 
Example #23
Source File: CachingProviderTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test
public void getCacheManagerUsingDefaultURI() {
  CachingProvider provider = Caching.getCachingProvider();

  CacheManager manager1 = provider.getCacheManager();
  assertNotNull(manager1);
  assertEquals(provider.getDefaultURI(), manager1.getURI());

  CacheManager manager2 = provider.getCacheManager();
  assertSame(manager1, manager2);
}
 
Example #24
Source File: CacheLoaderTest.java    From triava with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a tCache CacheManager.  
 * @return
 */
public synchronized CacheManager cacheManager()
{
	if (cacheManager == null)
	{
		CachingProvider cachingProvider = Caching.getCachingProvider();
		cacheManager = cachingProvider.getCacheManager();
	}
	
	return cacheManager;
}
 
Example #25
Source File: CachingTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
/**
 * Multiple invocations of {@link CachingProvider#getCacheManager(java.net.URI, ClassLoader)} with the same name
 * return the same CacheManager instance
 */
@Test
public void getCacheManager_URI() throws Exception {
  CachingProvider provider = Caching.getCachingProvider();

  URI uri = provider.getDefaultURI();

  CacheManager manager = provider.getCacheManager(uri, provider.getDefaultClassLoader());
  assertNotNull(manager);
  assertSame(manager, provider.getCacheManager(uri, provider.getDefaultClassLoader()));

  assertEquals(uri, manager.getURI());
}
 
Example #26
Source File: ParameterizedFunctionalTest.java    From requery with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws SQLException {
    CommonDataSource dataSource = DatabaseType.getDataSource(platform);
    EntityModel model = Models.DEFAULT;

    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();
    Configuration configuration = new ConfigurationBuilder(dataSource, model)
        .useDefaultLogging()
        // work around bug reusing prepared statements in xerial sqlite
        .setStatementCacheSize(platform instanceof SQLite ? 0 : 10)
        .setBatchUpdateSize(50)
        .setEntityCache(new EntityCacheBuilder(model)
            .useReferenceCache(true)
            .useSerializableCache(true)
            .useCacheManager(cacheManager)
            .build())
        .build();
    data = new EntityDataStore<>(configuration);
    SchemaModifier tables = new SchemaModifier(configuration);
    try {
        tables.dropTables();
    } catch (Exception e) {
        // expected if 'drop if exists' not supported (so ignore in that case)
        if (!platform.supportsIfExists()) {
            throw e;
        }
    }
    TableCreationMode mode = TableCreationMode.CREATE;
    System.out.println(tables.createTablesString(mode));
    tables.createTables(mode);
}
 
Example #27
Source File: Jsr107OsgiTest.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void testJsr107EhcacheOsgi() throws Exception {
  CachingProvider cachingProvider = Caching.getCachingProvider("org.ehcache.jsr107.EhcacheCachingProvider", TestMethods.class.getClassLoader());
  CacheManager cacheManager = cachingProvider.getCacheManager(TestMethods.class.getResource("/org/ehcache/osgi/ehcache-107-osgi.xml").toURI(), TestMethods.class.getClassLoader());
  Cache<Long, Person> personCache = cacheManager.getCache("personCache", Long.class, Person.class);
  assertEquals(Person.class, personCache.getConfiguration(javax.cache.configuration.Configuration.class).getValueType());
}
 
Example #28
Source File: CacheLoaderIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Before
public void setup() {
    // Adding fully qualified class name because of multiple Cache Provider (Ignite and Hazelcast)
    CachingProvider cachingProvider = Caching.getCachingProvider("com.hazelcast.cache.HazelcastCachingProvider");
    CacheManager cacheManager = cachingProvider.getCacheManager();
    MutableConfiguration<Integer, String> config = new MutableConfiguration<Integer, String>().setReadThrough(true).setCacheLoaderFactory(new FactoryBuilder.SingletonFactory<>(new SimpleCacheLoader()));
    this.cache = cacheManager.createCache("SimpleCache", config);
}
 
Example #29
Source File: InfinispanJCache.java    From infinispan-simple-tutorials with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
   // Construct a simple local cache manager with default configuration
   CachingProvider jcacheProvider = Caching.getCachingProvider();
   CacheManager cacheManager = jcacheProvider.getCacheManager();
   MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
   configuration.setTypes(String.class, String.class);
   // create a cache using the supplied configuration
   Cache<String, String> cache = cacheManager.createCache("myCache", configuration);
   // Store a value
   cache.put("key", "value");
   // Retrieve the value and print it out
   System.out.printf("key = %s\n", cache.get("key"));
   // Stop the cache manager and release all resources
   cacheManager.close();
}
 
Example #30
Source File: RateLimitingFilter.java    From tutorials with MIT License 5 votes vote down vote up
public RateLimitingFilter(JHipsterProperties jHipsterProperties) {
    this.jHipsterProperties = jHipsterProperties;

    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();
    CompleteConfiguration<String, GridBucketState> config =
        new MutableConfiguration<String, GridBucketState>()
            .setTypes(String.class, GridBucketState.class);

    this.cache = cacheManager.createCache(GATEWAY_RATE_LIMITING_CACHE_NAME, config);
    this.buckets = Bucket4j.extension(JCache.class).proxyManagerForCache(cache);
}