diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/ClusteredTimestampsRegionImpl.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/ClusteredTimestampsRegionImpl.java index 6567e697b1..37d5be6c70 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/ClusteredTimestampsRegionImpl.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/ClusteredTimestampsRegionImpl.java @@ -16,7 +16,9 @@ import org.hibernate.cache.spi.RegionFactory; import org.hibernate.engine.spi.SessionImplementor; import org.infinispan.AdvancedCache; +import org.infinispan.CacheSet; import org.infinispan.commons.util.CloseableIterable; +import org.infinispan.commons.util.CloseableIterator; import org.infinispan.container.entries.CacheEntry; import org.infinispan.context.Flag; import org.infinispan.notifications.Listener; @@ -109,14 +111,14 @@ public class ClusteredTimestampsRegionImpl extends TimestampsRegionImpl { * Brings all data from the distributed cache into our local cache. */ private void populateLocalCache() { - CloseableIterable iterable = Caches.keys(cache); + CloseableIterator iterator = cache.keySet().iterator(); try { - for (Object key : iterable) { - get(null, key); + while (iterator.hasNext()) { + get(null, iterator.next()); } } finally { - iterable.close(); + iterator.close(); } } diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/BeginInvalidationCommand.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/BeginInvalidationCommand.java index 25dadc3e7d..51c49fc084 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/BeginInvalidationCommand.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/BeginInvalidationCommand.java @@ -7,6 +7,7 @@ package org.hibernate.cache.infinispan.util; import org.hibernate.internal.util.compare.EqualsHelper; +import org.infinispan.commands.CommandInvocationId; import org.infinispan.commands.write.AbstractDataWriteCommand; import org.infinispan.commands.write.InvalidateCommand; import org.infinispan.context.Flag; @@ -14,7 +15,6 @@ import org.infinispan.notifications.cachelistener.CacheNotifier; import org.infinispan.remoting.transport.Address; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; import java.util.Set; @@ -23,56 +23,14 @@ import java.util.Set; * @author Radim Vansa <rvansa@redhat.com> */ public class BeginInvalidationCommand extends InvalidateCommand { - // this is a hack to keep compatibility with both Infinispan 7 and 8 - // TODO: remove this when rebasing on Infinispan 8 - private static final Field commandInvocationIdField; - private static final Method generateIdMethod; - - static { - Field commandInvocationId = null; - Method generateId = null; - try { - commandInvocationId = AbstractDataWriteCommand.class.getDeclaredField("commandInvocationId"); - commandInvocationId.setAccessible(true); - Class commandInvocationIdClass = Class.forName("org.infinispan.commands.CommandInvocationId"); - generateId = commandInvocationIdClass.getMethod("generateId", Address.class); - } - catch (NoSuchFieldException e) { - } - catch (ClassNotFoundException e) { - // already found field and not the class? - throw new IllegalStateException(e); - } - catch (NoSuchMethodException e) { - // already found field and not the method? - throw new IllegalStateException(e); - } - commandInvocationIdField = commandInvocationId; - generateIdMethod = generateId; - } - private Object sessionTransactionId; public BeginInvalidationCommand() { } - public BeginInvalidationCommand(CacheNotifier notifier, Set flags, Object[] keys, Address address, Object sessionTransactionId) { - super(); - this.notifier = notifier; - this.flags = flags; - this.keys = keys; + public BeginInvalidationCommand(CacheNotifier notifier, Set flags, CommandInvocationId commandInvocationId, Object[] keys, Object sessionTransactionId) { + super(notifier, flags, commandInvocationId, keys); this.sessionTransactionId = sessionTransactionId; - if (commandInvocationIdField != null) { - try { - commandInvocationIdField.set(this, generateIdMethod.invoke(null, address)); - } - catch (IllegalAccessException e) { - throw new IllegalStateException(e); - } - catch (InvocationTargetException e) { - throw new IllegalStateException(e); - } - } } public Object getSessionTransactionId() { @@ -81,15 +39,6 @@ public class BeginInvalidationCommand extends InvalidateCommand { @Override public Object[] getParameters() { - Object commandInvocationId = null; - if (commandInvocationIdField != null) { - try { - commandInvocationId = commandInvocationIdField.get(this); - } - catch (IllegalAccessException e) { - throw new IllegalStateException(e); - } - } if (keys == null || keys.length == 0) { return new Object[]{flags, sessionTransactionId, commandInvocationId, 0}; } @@ -112,15 +61,7 @@ public class BeginInvalidationCommand extends InvalidateCommand { } flags = (Set) args[0]; sessionTransactionId = args[1]; - Object commandInvocationId = args[2]; - if (commandInvocationIdField != null) { - try { - commandInvocationIdField.set(this, commandInvocationId); - } - catch (IllegalAccessException e) { - throw new IllegalStateException(e); - } - } + commandInvocationId = (CommandInvocationId) args[2]; int size = (Integer) args[3]; keys = new Object[size]; if (size == 1) { diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandInitializer.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandInitializer.java index f2f6194226..0da9688119 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandInitializer.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandInitializer.java @@ -7,6 +7,7 @@ package org.hibernate.cache.infinispan.util; import org.hibernate.cache.infinispan.access.PutFromLoadValidator; +import org.infinispan.commands.CommandInvocationId; import org.infinispan.commands.ReplicableCommand; import org.infinispan.commands.module.ModuleCommandInitializer; import org.infinispan.configuration.cache.Configuration; @@ -66,7 +67,7 @@ public class CacheCommandInitializer implements ModuleCommandInitializer { } public BeginInvalidationCommand buildBeginInvalidationCommand(Set flags, Object[] keys, Object sessionTransactionId) { - return new BeginInvalidationCommand(notifier, flags, keys, clusteringDependentLogic.getAddress(), sessionTransactionId); + return new BeginInvalidationCommand(notifier, flags, CommandInvocationId.generateId(clusteringDependentLogic.getAddress()), keys, sessionTransactionId); } public EndInvalidationCommand buildEndInvalidationCommand(String cacheName, Object[] keys, Object sessionTransactionId) { diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/Caches.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/Caches.java index 55b5c3e85c..85c82f0392 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/Caches.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/Caches.java @@ -278,7 +278,7 @@ public class Caches { public static void removeAll(AdvancedCache cache) { - CloseableIterator it = keys(cache).iterator(); + CloseableIterator it = cache.keySet().iterator(); try { while (it.hasNext()) { // Cannot use it.next(); it.remove() due to ISPN-5653 @@ -301,15 +301,7 @@ public class Caches { Map toMap(); } - public static CollectableCloseableIterable keys(AdvancedCache cache) { - return keys(cache, (KeyValueFilter) AcceptAllKeyValueFilter.getInstance()); - } - public static CollectableCloseableIterable keys(AdvancedCache cache, KeyValueFilter filter) { - if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) { - // Dummy read to enlist the LocalTransaction as workaround for ISPN-5676 - cache.containsKey(false); - } // HHH-10023: we can't use keySet() final CloseableIterable> entryIterable = cache .filterEntries( filter ) @@ -317,10 +309,6 @@ public class Caches { return new CollectableCloseableIterableImpl(entryIterable, Selector.KEY); } - public static CollectableCloseableIterable values(AdvancedCache cache) { - return values(cache, (KeyValueFilter) AcceptAllKeyValueFilter.getInstance()); - } - public static CollectableCloseableIterable values(AdvancedCache cache, KeyValueFilter filter) { if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) { // Dummy read to enlist the LocalTransaction as workaround for ISPN-5676 @@ -341,7 +329,6 @@ public class Caches { return new CollectableCloseableIterableImpl(entryIterable, Selector.VALUE); } - public static MapCollectableCloseableIterable entrySet(AdvancedCache cache) { return entrySet(cache, (KeyValueFilter) AcceptAllKeyValueFilter.getInstance()); } diff --git a/hibernate-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml b/hibernate-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml index b8fca11b15..40aec53a20 100644 --- a/hibernate-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml +++ b/hibernate-infinispan/src/main/resources/org/hibernate/cache/infinispan/builder/infinispan-configs.xml @@ -6,8 +6,8 @@ ~ See the lgpl.txt file in the root directory or . --> + xmlns="urn:infinispan:config:8.0" + xsi:schemaLocation="urn:infinispan:config:8.0 http://www.infinispan.org/schemas/infinispan-config-8.0.xsd"> @@ -16,51 +16,51 @@ - + - + - + - + - + - + - + - + - + - + - + diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTest.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTest.java index e382428324..7f84370dc1 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTest.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTest.java @@ -170,10 +170,10 @@ public abstract class AbstractGeneralDataRegionTest extends AbstractRegionImplTe SessionImplementor remoteSession = (SessionImplementor) sessionFactories.get(1).openSession(); try { - Set localKeys = Caches.keys(localCache).toSet(); + Set localKeys = localCache.keySet(); assertEquals( "No valid children in " + localKeys, 0, localKeys.size() ); - Set remoteKeys = Caches.keys(remoteCache).toSet(); + Set remoteKeys = remoteCache.keySet(); assertEquals( "No valid children in " + remoteKeys, 0, remoteKeys.size() ); assertNull( "local is clean", localRegion.get(null, KEY ) ); @@ -197,14 +197,14 @@ public abstract class AbstractGeneralDataRegionTest extends AbstractRegionImplTe sleep( 250 ); // This should re-establish the region root node in the optimistic case assertNull( localRegion.get(null, KEY ) ); - localKeys = Caches.keys(localCache).toSet(); + localKeys = localCache.keySet(); assertEquals( "No valid children in " + localKeys, 0, localKeys.size() ); // Re-establishing the region root on the local node doesn't // propagate it to other nodes. Do a get on the remote node to re-establish // This only adds a node in the case of optimistic locking assertEquals( null, remoteRegion.get(null, KEY ) ); - remoteKeys = Caches.keys(remoteCache).toSet(); + remoteKeys = remoteCache.keySet(); assertEquals( "No valid children in " + remoteKeys, 0, remoteKeys.size() ); assertEquals( "local is clean", null, localRegion.get(null, KEY ) ); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/AbstractNonInvalidationTest.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/AbstractNonInvalidationTest.java index 6a92e9996f..2a34eb3d29 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/AbstractNonInvalidationTest.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/AbstractNonInvalidationTest.java @@ -71,7 +71,7 @@ public abstract class AbstractNonInvalidationTest extends SingleNodeTest { Item item = new Item("my item", "Original item"); withTxSession(s -> s.persist(item)); entityCache.clear(); - assertEquals("Cache is not empty", Collections.EMPTY_SET, Caches.keys(entityCache).toSet()); + assertEquals("Cache is not empty", Collections.EMPTY_SET, entityCache.keySet()); itemId = item.getId(); log.info("Insert and clear finished"); } diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/MultiTenancyTest.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/MultiTenancyTest.java index 1082654305..aab917935a 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/MultiTenancyTest.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/MultiTenancyTest.java @@ -13,6 +13,7 @@ import org.hibernate.test.cache.infinispan.tm.XaConnectionProvider; import org.hibernate.testing.env.ConnectionProviderBuilder; import org.infinispan.AdvancedCache; import org.infinispan.commons.util.CloseableIterable; +import org.infinispan.commons.util.CloseableIterator; import org.infinispan.context.Flag; import org.junit.Test; @@ -101,8 +102,9 @@ public class MultiTenancyTest extends SingleNodeTest { // } EntityRegionImpl region = (EntityRegionImpl) sessionFactory().getSecondLevelCacheRegion(Item.class.getName()); AdvancedCache localCache = region.getCache().withFlags(Flag.CACHE_MODE_LOCAL); - CloseableIterable keys = Caches.keys(localCache); assertEquals(1, localCache.size()); - assertEquals("OldCacheKeyImplementation", keys.iterator().next().getClass().getSimpleName()); + try (CloseableIterator iterator = localCache.keySet().iterator()) { + assertEquals("OldCacheKeyImplementation", iterator.next().getClass().getSimpleName()); + } } } diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/NoTenancyTest.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/NoTenancyTest.java index 5e4f03169e..41b78b4772 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/NoTenancyTest.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/NoTenancyTest.java @@ -5,6 +5,7 @@ import org.hibernate.cache.infinispan.util.Caches; import org.hibernate.test.cache.infinispan.functional.entities.Item; import org.infinispan.AdvancedCache; import org.infinispan.commons.util.CloseableIterable; +import org.infinispan.commons.util.CloseableIterator; import org.infinispan.context.Flag; import org.junit.Test; @@ -38,8 +39,9 @@ public class NoTenancyTest extends SingleNodeTest { } EntityRegionImpl region = (EntityRegionImpl) sessionFactory().getSecondLevelCacheRegion(Item.class.getName()); AdvancedCache localCache = region.getCache().withFlags(Flag.CACHE_MODE_LOCAL); - CloseableIterable keys = Caches.keys(localCache); assertEquals(1, localCache.size()); - assertEquals(sessionFactory().getClassMetadata(Item.class).getIdentifierType().getReturnedClass(), keys.iterator().next().getClass()); + try (CloseableIterator iterator = localCache.keySet().iterator()) { + assertEquals(sessionFactory().getClassMetadata(Item.class).getIdentifierType().getReturnedClass(), iterator.next().getClass()); + } } } diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTest.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTest.java index d14fa6d7b8..0619a05a96 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTest.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTest.java @@ -122,7 +122,7 @@ public class NaturalIdInvalidationTest extends DualNodeTest { deleteCitizenWithCriteria(remoteFactory); sleep(250); - Set localKeys = Caches.keys(localNaturalIdCache.getAdvancedCache()).toSet(); + Set localKeys = localNaturalIdCache.keySet(); assertEquals(1, localKeys.size()); // Only key left is the one for the citizen *not* in France localKeys.toString().contains("000"); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/timestamp/TimestampsRegionImplTest.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/timestamp/TimestampsRegionImplTest.java index cb7d145e68..65bf9676dd 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/timestamp/TimestampsRegionImplTest.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/timestamp/TimestampsRegionImplTest.java @@ -30,7 +30,6 @@ import org.infinispan.context.Flag; import org.infinispan.notifications.Listener; import org.infinispan.notifications.cachelistener.annotation.CacheEntryActivated; import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated; -import org.infinispan.notifications.cachelistener.annotation.CacheEntryEvicted; import org.infinispan.notifications.cachelistener.annotation.CacheEntryInvalidated; import org.infinispan.notifications.cachelistener.annotation.CacheEntryLoaded; import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified; @@ -132,7 +131,6 @@ public class TimestampsRegionImplTest extends AbstractGeneralDataRegionTest { @CacheEntryActivated @CacheEntryCreated - @CacheEntryEvicted @CacheEntryInvalidated @CacheEntryLoaded @CacheEntryModified diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/ClassLoaderAwareCache.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/ClassLoaderAwareCache.java index ddc54c4234..541fe25b28 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/ClassLoaderAwareCache.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/ClassLoaderAwareCache.java @@ -26,7 +26,6 @@ import org.infinispan.interceptors.base.CommandInterceptor; import org.infinispan.notifications.Listener; import org.infinispan.notifications.cachelistener.annotation.CacheEntryActivated; import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated; -import org.infinispan.notifications.cachelistener.annotation.CacheEntryEvicted; import org.infinispan.notifications.cachelistener.annotation.CacheEntryInvalidated; import org.infinispan.notifications.cachelistener.annotation.CacheEntryLoaded; import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified; @@ -95,7 +94,6 @@ public class ClassLoaderAwareCache extends AbstractDelegatingAdvancedCache static { events.put(CacheEntryActivated.class, Event.Type.CACHE_ENTRY_ACTIVATED); events.put(CacheEntryCreated.class, Event.Type.CACHE_ENTRY_CREATED); - events.put(CacheEntryEvicted.class, Event.Type.CACHE_ENTRY_EVICTED); events.put(CacheEntryInvalidated.class, Event.Type.CACHE_ENTRY_INVALIDATED); events.put(CacheEntryLoaded.class, Event.Type.CACHE_ENTRY_LOADED); events.put(CacheEntryModified.class, Event.Type.CACHE_ENTRY_MODIFIED); @@ -130,7 +128,6 @@ public class ClassLoaderAwareCache extends AbstractDelegatingAdvancedCache @CacheEntryActivated @CacheEntryCreated - @CacheEntryEvicted @CacheEntryInvalidated @CacheEntryLoaded @CacheEntryModified diff --git a/libraries.gradle b/libraries.gradle index e493c6fb2c..8c7dc3068c 100644 --- a/libraries.gradle +++ b/libraries.gradle @@ -13,7 +13,7 @@ ext { // h2Version = '1.2.145' h2Version = '1.3.176' bytemanVersion = '2.1.2' - infinispanVersion = '7.2.1.Final' + infinispanVersion = '8.0.1.Final' jnpVersion = '5.0.6.CR1' elVersion = '2.2.4'