Search in sources :

Example 6 with EntityRegionImpl

use of org.hibernate.cache.infinispan.entity.EntityRegionImpl in project hibernate-orm by hibernate.

the class AbstractNonInvalidationTest method insertAndClearCache.

@Before
public void insertAndClearCache() throws Exception {
    region = sessionFactory().getSecondLevelCacheRegion(Item.class.getName());
    entityCache = ((EntityRegionImpl) region).getCache();
    timeout = ((EntityRegionImpl) region).getRegionFactory().getPendingPutsCacheConfiguration().expiration().maxIdle();
    Item item = new Item("my item", "Original item");
    withTxSession(s -> s.persist(item));
    entityCache.clear();
    assertEquals("Cache is not empty", Collections.EMPTY_SET, entityCache.keySet());
    itemId = item.getId();
    log.info("Insert and clear finished");
}
Also used : Item(org.hibernate.test.cache.infinispan.functional.entities.Item) EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) Before(org.junit.Before)

Example 7 with EntityRegionImpl

use of org.hibernate.cache.infinispan.entity.EntityRegionImpl in project hibernate-orm by hibernate.

the class InfinispanRegionFactory method buildEntityRegion.

@Override
public EntityRegion buildEntityRegion(String regionName, Map<String, Object> configValues, CacheDataDescription metadata) {
    if (log.isDebugEnabled()) {
        log.debugf("Building entity cache region [%s] (mutable=%s, versioned=%s)", regionName, metadata.isMutable(), metadata.isVersioned());
    }
    final AdvancedCache cache = getCache(regionName, metadata.isMutable() ? DataType.ENTITY : DataType.IMMUTABLE_ENTITY, metadata);
    final EntityRegionImpl region = new EntityRegionImpl(cache, regionName, transactionManager, metadata, this, getCacheKeysFactory());
    startRegion(region);
    return region;
}
Also used : EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) AdvancedCache(org.infinispan.AdvancedCache)

Example 8 with EntityRegionImpl

use of org.hibernate.cache.infinispan.entity.EntityRegionImpl in project hibernate-orm by hibernate.

the class InvalidationTest method getPendingPutsCache.

protected AdvancedCache getPendingPutsCache(Class<Item> entityClazz) {
    EntityRegionImpl region = (EntityRegionImpl) sessionFactory().getCache().getEntityRegionAccess(entityClazz.getName()).getRegion();
    AdvancedCache entityCache = region.getCache();
    return (AdvancedCache) entityCache.getCacheManager().getCache(entityCache.getName() + "-" + InfinispanRegionFactory.DEF_PENDING_PUTS_RESOURCE).getAdvancedCache();
}
Also used : EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) AdvancedCache(org.infinispan.AdvancedCache)

Example 9 with EntityRegionImpl

use of org.hibernate.cache.infinispan.entity.EntityRegionImpl in project hibernate-orm by hibernate.

the class MultiTenancyTest method testMultiTenancy.

@Test
public void testMultiTenancy() throws Exception {
    final Item item = new Item("my item", "description");
    withTxSession(sessionFactory().withOptions().tenantIdentifier(DB1), s -> s.persist(item));
    for (int i = 0; i < 5; ++i) {
        // make sure we get something cached
        withTxSession(sessionFactory().withOptions().tenantIdentifier(DB1), s -> {
            Item item2 = s.get(Item.class, item.getId());
            assertNotNull(item2);
            assertEquals(item.getName(), item2.getName());
        });
    }
    // The table ITEMS is not created in DB2 - we would get just an exception
    //        for (int i = 0; i < 5; ++i) { // make sure we get something cached
    //            withTx(tm, new Callable<Void>() {
    //                @Override
    //                public Void call() throws Exception {
    //                    Session s = sessionFactory().withOptions().tenantIdentifier(DB2).openSession();
    //                    s.getTransaction().begin();
    //                    Item item2 = s.get(Item.class, id);
    //                    s.getTransaction().commit();
    //                    s.close();
    //                    assertNull(item2);
    //                    return null;
    //                }
    //            });
    //        }
    EntityRegionImpl region = (EntityRegionImpl) sessionFactory().getSecondLevelCacheRegion(Item.class.getName());
    AdvancedCache localCache = region.getCache().withFlags(Flag.CACHE_MODE_LOCAL);
    assertEquals(1, localCache.size());
    try (CloseableIterator iterator = localCache.keySet().iterator()) {
        assertEquals("CacheKeyImplementation", iterator.next().getClass().getSimpleName());
    }
}
Also used : Item(org.hibernate.test.cache.infinispan.functional.entities.Item) EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) CloseableIterator(org.infinispan.commons.util.CloseableIterator) AdvancedCache(org.infinispan.AdvancedCache) Test(org.junit.Test)

Example 10 with EntityRegionImpl

use of org.hibernate.cache.infinispan.entity.EntityRegionImpl in project hibernate-orm by hibernate.

the class NoTenancyTest method testNoTenancy.

@Test
public void testNoTenancy() throws Exception {
    final Item item = new Item("my item", "description");
    withTxSession(s -> s.persist(item));
    for (int i = 0; i < 5; ++i) {
        // make sure we get something cached
        withTxSession(s -> {
            Item item2 = s.get(Item.class, item.getId());
            assertNotNull(item2);
            assertEquals(item.getName(), item2.getName());
        });
    }
    EntityRegionImpl region = (EntityRegionImpl) sessionFactory().getSecondLevelCacheRegion(Item.class.getName());
    AdvancedCache localCache = region.getCache().withFlags(Flag.CACHE_MODE_LOCAL);
    assertEquals(1, localCache.size());
    try (CloseableIterator iterator = localCache.keySet().iterator()) {
        assertEquals(sessionFactory().getClassMetadata(Item.class).getIdentifierType().getReturnedClass(), iterator.next().getClass());
    }
}
Also used : Item(org.hibernate.test.cache.infinispan.functional.entities.Item) EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) CloseableIterator(org.infinispan.commons.util.CloseableIterator) AdvancedCache(org.infinispan.AdvancedCache) Test(org.junit.Test)

Aggregations

EntityRegionImpl (org.hibernate.cache.infinispan.entity.EntityRegionImpl)12 AdvancedCache (org.infinispan.AdvancedCache)10 Test (org.junit.Test)8 Properties (java.util.Properties)6 CollectionRegionImpl (org.hibernate.cache.infinispan.collection.CollectionRegionImpl)4 Configuration (org.infinispan.configuration.cache.Configuration)4 Item (org.hibernate.test.cache.infinispan.functional.entities.Item)3 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)2 QueryResultsRegionImpl (org.hibernate.cache.infinispan.query.QueryResultsRegionImpl)2 TimestampsRegionImpl (org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl)2 CloseableIterator (org.infinispan.commons.util.CloseableIterator)2 ClusteringConfigurationBuilder (org.infinispan.configuration.cache.ClusteringConfigurationBuilder)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2 Before (org.junit.Before)1