libhibernate-jbosscache-java-3.6.8.Final.orig/0000755000000000000000000000000011675734517016076 5ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/0000755000000000000000000000000011675734517016665 5ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/0000755000000000000000000000000011675734517017611 5ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/0000755000000000000000000000000011675734517020532 5ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/0000755000000000000000000000000011652065432022457 5ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/0000755000000000000000000000000011652065432023522 5ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/0000755000000000000000000000000011675734517024274 5ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/0000755000000000000000000000000011675734517025610 5ustar ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/OptimisticTransactionalAccess.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/OptimisticTra0000644000000000000000000000343411652065432030316 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.entity; import org.hibernate.cache.jbc.access.OptimisticTransactionalAccessDelegate; /** * Defines the strategy for transactional access to entity data in an * optimistic-locking JBoss Cache using its 2.x APIs * * @author Brian Stansberry * @version $Revision: 1 $ */ public class OptimisticTransactionalAccess extends TransactionalAccess { /** * Create a new OptimisticTransactionalAccess. * * @param region The region\ to which this is providing access */ public OptimisticTransactionalAccess(EntityRegionImpl region) { super(region, new OptimisticTransactionalAccessDelegate(region, region.getPutFromLoadValidator())); } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/OptimisticReadOnlyAccess.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/OptimisticRea0000644000000000000000000000571611652065432030304 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.entity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.hibernate.cache.access.SoftLock; import org.hibernate.cache.CacheException; /** * This defines the strategy for read-only access to enity data in an * optimistic-locking JBossCache using its 2.x APIs

The read-only access to * a JBossCache really is still transactional, just with the extra semantic or * guarantee that we will not update data. * * @author Brian Stansberry */ public class OptimisticReadOnlyAccess extends OptimisticTransactionalAccess { private static final Logger log = LoggerFactory.getLogger(OptimisticReadOnlyAccess.class); public OptimisticReadOnlyAccess(EntityRegionImpl region) { super(region); } @Override public SoftLock lockItem(Object key, Object version) throws CacheException { throw new UnsupportedOperationException("Illegal attempt to edit read only item"); } @Override public SoftLock lockRegion() throws CacheException { throw new UnsupportedOperationException("Illegal attempt to edit read only region"); } @Override public void unlockItem(Object key, SoftLock lock) throws CacheException { log.error("Illegal attempt to edit read only item"); } @Override public void unlockRegion(SoftLock lock) throws CacheException { log.error("Illegal attempt to edit read only region"); } @Override public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { throw new UnsupportedOperationException("Illegal attempt to edit read only item"); } @Override public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { throw new UnsupportedOperationException("Illegal attempt to edit read only item"); } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/EntityRegionImpl.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/EntityRegionI0000644000000000000000000000621211652065432030251 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.entity; import org.jboss.cache.Cache; import org.jboss.cache.Fqn; import org.jboss.cache.config.Configuration.NodeLockingScheme; import org.jboss.cache.notifications.annotation.CacheListener; import org.hibernate.cache.CacheDataDescription; import org.hibernate.cache.CacheException; import org.hibernate.cache.EntityRegion; import org.hibernate.cache.access.AccessType; import org.hibernate.cache.access.EntityRegionAccessStrategy; import org.hibernate.cache.jbc.TransactionalDataRegionAdapter; import org.hibernate.cache.jbc.access.PutFromLoadValidator; /** * Defines the behavior of the entity cache regions for JBossCache. * * @author Steve Ebersole */ @CacheListener public class EntityRegionImpl extends TransactionalDataRegionAdapter implements EntityRegion { public static final String TYPE = "ENTITY"; private boolean optimistic; public EntityRegionImpl(Cache jbcCache, String regionName, String regionPrefix, CacheDataDescription metadata) { super(jbcCache, regionName, regionPrefix, metadata); optimistic = (jbcCache.getConfiguration().getNodeLockingScheme() == NodeLockingScheme.OPTIMISTIC); } /** * {@inheritDoc} */ public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException { if (AccessType.READ_ONLY.equals(accessType)) { return optimistic ? new OptimisticReadOnlyAccess(this) : new ReadOnlyAccess(this); } if (AccessType.TRANSACTIONAL.equals(accessType)) { return optimistic ? new OptimisticTransactionalAccess(this) : new TransactionalAccess(this); } // todo : add support for READ_WRITE ( + NONSTRICT_READ_WRITE ??? ) throw new CacheException("unsupported access type [" + accessType.getName() + "]"); } @Override protected Fqn createRegionFqn(String regionName, String regionPrefix) { return getTypeLastRegionFqn(regionName, regionPrefix, TYPE); } public PutFromLoadValidator getPutFromLoadValidator() { return new PutFromLoadValidator(transactionManager); } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/TransactionalAccess.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/Transactional0000644000000000000000000001037211652065432030324 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.entity; import org.hibernate.cache.access.EntityRegionAccessStrategy; import org.hibernate.cache.access.SoftLock; import org.hibernate.cache.jbc.access.TransactionalAccessDelegate; import org.hibernate.cache.EntityRegion; import org.hibernate.cache.CacheException; /** * Defines the strategy for transactional access to entity data in a * pessimistic-locking JBossCache using its 2.x APIs * * @author Steve Ebersole */ public class TransactionalAccess implements EntityRegionAccessStrategy { protected final EntityRegionImpl region; /** * Most of our logic is shared between this and entity regions, so we * delegate to a class that encapsulates it */ private final TransactionalAccessDelegate delegate; public TransactionalAccess(EntityRegionImpl region) { this(region, new TransactionalAccessDelegate(region, region.getPutFromLoadValidator())); } protected TransactionalAccess(EntityRegionImpl region, TransactionalAccessDelegate delegate) { this.region = region; this.delegate = delegate; } public EntityRegion getRegion() { return region; } public Object get(Object key, long txTimestamp) throws CacheException { return delegate.get(key, txTimestamp); } public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { return delegate.putFromLoad(key, value, txTimestamp, version); } public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { return delegate.putFromLoad(key, value, txTimestamp, version, minimalPutOverride); } public boolean insert(Object key, Object value, Object version) throws CacheException { return delegate.insert(key, value, version); } public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { return delegate.update(key, value, currentVersion, previousVersion); } public void remove(Object key) throws CacheException { delegate.remove(key); } public void removeAll() throws CacheException { delegate.removeAll(); } public void evict(Object key) throws CacheException { delegate.evict(key); } public void evictAll() throws CacheException { delegate.evictAll(); } // Following methods we don't delegate since they have so little logic // it's clearer to just implement them here public SoftLock lockItem(Object key, Object version) throws CacheException { return null; } public SoftLock lockRegion() throws CacheException { return null; } public void unlockItem(Object key, SoftLock lock) throws CacheException { } public void unlockRegion(SoftLock lock) throws CacheException { } public boolean afterInsert(Object key, Object value, Object version) throws CacheException { return false; } public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { return false; } } ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/ReadOnlyAccess.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/ReadOnlyAcces0000644000000000000000000000561611652065432030203 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.entity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.hibernate.cache.access.SoftLock; import org.hibernate.cache.CacheException; /** * This defines the strategy for transactional access to enity data in * JBossCache using its 2.x APIs

read-only access to a JBossCache really is * still transactional, just with the extra semantic or guarentee that we will * not update data. * * @author Steve Ebersole */ public class ReadOnlyAccess extends TransactionalAccess { private static final Logger log = LoggerFactory.getLogger(ReadOnlyAccess.class); public ReadOnlyAccess(EntityRegionImpl region) { super(region); } @Override public SoftLock lockItem(Object key, Object version) throws CacheException { throw new UnsupportedOperationException("Illegal attempt to edit read only item"); } @Override public SoftLock lockRegion() throws CacheException { throw new UnsupportedOperationException("Illegal attempt to edit read only region"); } @Override public void unlockItem(Object key, SoftLock lock) throws CacheException { log.error("Illegal attempt to edit read only item"); } @Override public void unlockRegion(SoftLock lock) throws CacheException { log.error("Illegal attempt to edit read only region"); } @Override public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { throw new UnsupportedOperationException("Illegal attempt to edit read only item"); } @Override public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { throw new UnsupportedOperationException("Illegal attempt to edit read only item"); } } libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/0000755000000000000000000000000011675734517025251 5ustar ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/CacheHelper.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/CacheHelper.jav0000644000000000000000000004225311652065432030110 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.util; import java.util.Collections; import java.util.Set; import org.hibernate.cache.CacheException; import org.jboss.cache.Cache; import org.jboss.cache.Fqn; import org.jboss.cache.InvocationContext; import org.jboss.cache.Node; import org.jboss.cache.config.Configuration; import org.jboss.cache.config.Option; import org.jboss.cache.lock.TimeoutException; import org.jboss.cache.optimistic.DataVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Helper for dealing with JBossCache {@link Configuration.CacheMode}. * * @author Steve Ebersole * @author Brian Stansberry */ public class CacheHelper { public static enum Internal { NODE, LOCAL }; /** Key under which items are cached */ public static final String ITEM = "item"; /** Key and value used in a hack to create region root nodes */ public static final String DUMMY = "dummy"; private static final Logger log = LoggerFactory.getLogger(CacheHelper.class); /** * Disallow external instantiation of CacheHelper. */ private CacheHelper() { } /** * Is this cache participating in a cluster with invalidation? * * @param cache * The cache to check. * @return True if the cache is configured for synchronous/asynchronous * invalidation; false otherwise. */ public static boolean isClusteredInvalidation(Cache cache) { return isClusteredInvalidation(cache.getConfiguration().getCacheMode()); } /** * Does this cache mode indicate clustered invalidation? * * @param cacheMode * The cache to check * @return True if the cache mode is confiogured for * synchronous/asynchronous invalidation; false otherwise. */ public static boolean isClusteredInvalidation(Configuration.CacheMode cacheMode) { return cacheMode == Configuration.CacheMode.INVALIDATION_ASYNC || cacheMode == Configuration.CacheMode.INVALIDATION_SYNC; } /** * Is this cache participating in a cluster with replication? * * @param cache * The cache to check. * @return True if the cache is configured for synchronous/asynchronous * invalidation; false otherwise. */ public static boolean isClusteredReplication(Cache cache) { return isClusteredReplication(cache.getConfiguration().getCacheMode()); } /** * Does this cache mode indicate clustered replication? * * @param cacheMode * The cache to check * @return True if the cache mode is confiogured for * synchronous/asynchronous invalidation; false otherwise. */ public static boolean isClusteredReplication(Configuration.CacheMode cacheMode) { return cacheMode == Configuration.CacheMode.REPL_ASYNC || cacheMode == Configuration.CacheMode.REPL_SYNC; } public static boolean isSynchronous(Cache cache) { return isSynchronous(cache.getConfiguration().getCacheMode()); } public static boolean isSynchronous(Configuration.CacheMode cacheMode) { return cacheMode == Configuration.CacheMode.REPL_SYNC || cacheMode == Configuration.CacheMode.INVALIDATION_SYNC; } public static Set getChildrenNames(Cache cache, Fqn fqn) { Node node = cache.getRoot().getChild(fqn); return (node != null) ? node.getChildrenNames() : Collections.emptySet(); } /** * Builds an {@link Fqn} from region and key * and performs a JBoss Cache get(Fqn, Object), wrapping any * exception in a {@link CacheException}. * * @param cache * the cache to invoke on * @param region * base Fqn for the cache region * @param key * specific key to append to the region to form * the full Fqn */ public static Object get(Cache cache, Fqn region, Object key) throws CacheException { try { return cache.get(new Fqn(region, key), ITEM); } catch (Exception e) { throw new CacheException(e); } } /** * Builds an {@link Fqn} from region and key * and performs a JBoss Cache get(Fqn, Object), wrapping any * exception in a {@link CacheException}. * * @param cache * the cache to invoke on * @param region * base Fqn for the cache region * @param key * specific key to append to the region to form * the full Fqn */ public static Object getAllowingTimeout(Cache cache, Fqn region, Object key) throws CacheException { try { return cache.get(new Fqn(region, key), ITEM); } catch (TimeoutException ignored) { // ignore it return null; } catch (Exception e) { throw new CacheException(e); } } /** * Builds an {@link Fqn} from region and key * and performs a JBoss Cache put(Object, Object), wrapping * any exception in a {@link CacheException}. * * @param cache * the cache to invoke on * @param region * base Fqn for the cache region * @param key * specific key to append to the region to form * the full Fqn * @param value * data to store in the cache node */ public static void put(Cache cache, Fqn region, Object key, Object value) throws CacheException { put(cache, region, key, value, null); } /** * Builds an {@link Fqn} from region and key * and performs a JBoss Cache put(Object, Object), wrapping * any exception in a {@link CacheException}. * * @param cache * the cache to invoke on * @param region * base Fqn for the cache region * @param key * specific key to append to the region to form * the full Fqn * @param value * data to store in the cache node * @param option * invocation Option to set for this invocation. May be * null. */ public static void put(Cache cache, Fqn region, Object key, Object value, Option option) throws CacheException { try { setInvocationOption(cache, option); cache.put(new Fqn(region, key), ITEM, value); } catch (Exception e) { throw new CacheException(e); } } /** * Builds an {@link Fqn} from region and key * and performs a JBoss Cache put(Object, Object), ignoring any * {@link TimeoutException} and wrapping any other exception in a {@link CacheException}. * * @param cache * the cache to invoke on * @param region * base Fqn for the cache region * @param key * specific key to append to the region to form * the full Fqn * @param value * data to store in the cache node * @param option * invocation Option to set for this invocation. May be * null. */ public static void putAllowingTimeout(Cache cache, Fqn region, Object key, Object value, Option option) throws CacheException { try { setInvocationOption(cache, option); cache.put(new Fqn(region, key), ITEM, value); } catch (TimeoutException allowed) { // ignore it } catch (Exception e) { throw new CacheException(e); } } /** * Builds an {@link Fqn} from region and key * and performs a JBoss Cache * putForExternalRead(Object, Object), wrapping any * exception in a {@link CacheException}. Ignores any JBoss Cache * {@link TimeoutException}. * * @param cache * the cache to invoke on * @param region * base Fqn for the cache region * @param key * specific key to append to the region to form * the full Fqn * @param value * data to store in the cache node */ public static boolean putForExternalRead(Cache cache, Fqn region, Object key, Object value) throws CacheException { return putForExternalRead(cache, region, key, value, null); } /** * Builds an {@link Fqn} from region and key * and performs a JBoss Cache * putForExternalRead(Object, Object), wrapping any * exception in a {@link CacheException}. Ignores any JBoss Cache * {@link TimeoutException}. * * @param cache * the cache to invoke on * @param region * base Fqn for the cache region * @param key * specific key to append to the region to form * the full Fqn * @param value * data to store in the cache node * @param option * invocation Option to set for this invocation. May be * null. */ public static boolean putForExternalRead(Cache cache, Fqn region, Object key, Object value, Option option) throws CacheException { try { setInvocationOption(cache, option); cache.putForExternalRead(new Fqn(region, key), ITEM, value); return true; } catch (TimeoutException te) { // ignore! log.debug("ignoring write lock acquisition failure"); return false; } catch (Throwable t) { throw new CacheException(t); } } /** * Builds an {@link Fqn} from region and key * and performs a JBoss Cache removeNode(Fqn), wrapping any * exception in a {@link CacheException}. * * @param cache * the cache to invoke on * @param region * base Fqn for the cache region * @param key * specific key to append to the region to form * the full Fqn */ public static void remove(Cache cache, Fqn region, Object key) throws CacheException { remove(cache, region, key, null); } /** * Builds an {@link Fqn} from region and key * and performs a JBoss Cache removeNode(Fqn), wrapping any * exception in a {@link CacheException}. * * @param cache * the cache to invoke on * @param region * base Fqn for the cache region * @param key * specific key to append to the region to form * the full Fqn * @param option * invocation Option to set for this invocation. May be * null. */ public static void remove(Cache cache, Fqn region, Object key, Option option) throws CacheException { try { setInvocationOption(cache, option); cache.removeNode(new Fqn(region, key)); } catch (Exception e) { throw new CacheException(e); } } /** * Performs a JBoss Cache removeNode(Fqn), wrapping any * exception in a {@link CacheException}. * * @param cache * the cache to invoke on * @param region * base Fqn for the cache region */ public static void removeAll(Cache cache, Fqn region) throws CacheException { removeAll(cache, region, null); } /** * Performs a JBoss Cache removeNode(Fqn), wrapping any * exception in a {@link CacheException}. * * @param cache * the cache to invoke on * @param region * base Fqn for the cache region * @param option * invocation Option to set for this invocation. May be * null. */ public static void removeAll(Cache cache, Fqn region, Option option) throws CacheException { try { setInvocationOption(cache, option); cache.removeNode(region); } catch (Exception e) { throw new CacheException(e); } } /** * Performs a JBoss Cache removeNode(Fqn), wrapping any * exception in a {@link CacheException}. * * @param cache * the cache to invoke on * @param region * base Fqn for the cache region * @param option * invocation Option to set for this invocation. May be * null. */ public static void removeNode(Cache cache, Fqn region, Object key, Option option) throws CacheException { try { setInvocationOption(cache, option); cache.removeNode(new Fqn(region, key)); } catch (Exception e) { throw new CacheException(e); } } public static Node addNode(Cache cache, Fqn fqn, boolean localOnly, boolean resident, DataVersion version) throws CacheException { try { Option option = null; if (localOnly || version != null) { option = new Option(); option.setCacheModeLocal(localOnly); option.setDataVersion(version); } Node root = cache.getRoot(); setInvocationOption(cache, option); // FIXME hack to work around fact that calling // Node added = root.addChild( fqn ); doesn't // properly set the version on the node Node added = null; if (version == null) { added = root.addChild( fqn ); } else { cache.put(fqn, DUMMY, DUMMY); added = root.getChild(fqn); } if (resident) added.setResident(true); return added; } catch (Exception e) { throw new CacheException(e); } } /** * Assigns the given Option to the cache's {@link InvocationContext}. Does * nothing if option is null. * * @param cache * the cache. Cannot be null. * @param option * the option. May be null. * * @see {@link Cache#getInvocationContext()} * @see {@link InvocationContext#setOptionOverrides(Option)} */ public static void setInvocationOption(Cache cache, Option option) { if (option != null) { cache.getInvocationContext().setOptionOverrides(option); } } /** * Creates an {@link Option} using the given {@link DataVersion} and passes * it to {@link #setInvocationOption(Cache, Option)}. * * @param cache * the cache to set the Option on. Cannot be null. * @param version * the DataVersion to set. Cannot be null. */ public static void setDataVersionOption(Cache cache, DataVersion version) { Option option = new Option(); option.setDataVersion(version); setInvocationOption(cache, option); } public static Fqn getInternalFqn(Fqn region) { return Fqn.fromRelativeElements(region, Internal.NODE); } public static void sendEvictNotification(Cache cache, Fqn region, Object member, Object key, Option option) { setInvocationOption(cache, option); Fqn f = Fqn.fromRelativeElements(region, Internal.NODE, member == null ? Internal.LOCAL : member, key); cache.put(f, ITEM, DUMMY); } public static void sendEvictAllNotification(Cache cache, Fqn region, Object member, Option option) { setInvocationOption(cache, option); Fqn f = Fqn.fromRelativeElements(region, Internal.NODE, member == null ? Internal.LOCAL : member); cache.put(f, ITEM, DUMMY); } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/NonLockingDataVersion.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/NonLockingDataV0000644000000000000000000000474311652065432030151 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.util; import org.hibernate.cache.jbc.entity.TransactionalAccess; import org.jboss.cache.config.Option; import org.jboss.cache.optimistic.DataVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * {@link DataVersion} used in regions where no locking should ever occur. This * includes query-caches, update-timestamps caches, collection caches, and * entity caches where the entity is not versioned. * * @author Brian Stansberry * @version $Revision: 1 $ */ public class NonLockingDataVersion implements DataVersion { private static final Logger log = LoggerFactory.getLogger(TransactionalAccess.class); private static final long serialVersionUID = 7050722490368630553L; public static final DataVersion INSTANCE = new NonLockingDataVersion(); public static Option getInvocationOption() { Option option = new Option(); option.setDataVersion(INSTANCE); return option; } public boolean newerThan(DataVersion dataVersion) { // if (dataVersion instanceof DefaultDataVersion) { // log.info("unexpectedly validating against a DefaultDataVersion", new Exception("Just a stack trace")); // return true; // } // else { log.trace("non locking lock check..."); return false; // } } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/DataVersionAdapter.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/DataVersionAdap0000644000000000000000000001473311652065432030175 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.util; import java.io.IOException; import java.util.Comparator; import org.hibernate.cache.jbc.entity.TransactionalAccess; import org.hibernate.util.CalendarComparator; import org.hibernate.util.ComparableComparator; import org.jboss.cache.optimistic.DataVersion; import org.jboss.cache.optimistic.DefaultDataVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A DataVersionAdapter. * * @author Brian Stansberry * @version $Revision: 1 $ */ public class DataVersionAdapter implements DataVersion { private static final Logger log = LoggerFactory.getLogger(TransactionalAccess.class); private static final long serialVersionUID = 5564692336076405571L; private final Object currentVersion; private final Object previousVersion; /** * Comparator does not extend Serializable and the std impls don't either, * so we make the field transient to allow special handling */ private transient Comparator versionComparator; private final String sourceIdentifer; public DataVersionAdapter(Object currentVersion, Object previousVersion, Comparator versionComparator, String sourceIdentifer) { this.currentVersion = currentVersion; this.previousVersion = previousVersion; this.versionComparator = versionComparator; this.sourceIdentifer = sourceIdentifer; log.trace("created " + this); } /** * newerThan() call is dispatched against the DataVersion currently * associated with the node; the passed dataVersion param is the DataVersion * associated with the data we are trying to put into the node.

we are * expected to return true in the case where we (the current node * DataVersion) are newer that then incoming value. Returning true here * essentially means that a optimistic lock failure has occured (because * conversely, the value we are trying to put into the node is "older than" * the value already there...) */ public boolean newerThan(DataVersion dataVersion) { log.trace("checking [" + this + "] against [" + dataVersion + "]"); if (dataVersion instanceof CircumventChecksDataVersion) { log.trace("skipping lock checks..."); return false; } else if (dataVersion instanceof NonLockingDataVersion) { // can happen because of the multiple ways Cache.remove() // can be invoked :( log.trace("skipping lock checks..."); return false; } else if (dataVersion instanceof DefaultDataVersion) { // JBC put a version in the node when it created as part of // some internal operation. We are always newer, but if // the JBC version is > 1 something odd has happened if (((DefaultDataVersion) dataVersion).getRawVersion() > 1) { log.warn("Unexpected comparison to " + dataVersion + " -- we are " + toString()); } return true; } DataVersionAdapter other = (DataVersionAdapter) dataVersion; if (other.previousVersion == null) { log.warn("Unexpected optimistic lock check on inserting data"); // work around the "feature" where tree cache is validating the // inserted node during the next transaction. no idea... if (this == dataVersion) { log.trace("skipping lock checks due to same DV instance"); return false; } } if (currentVersion == null) { // If the workspace node has null as well, OK; if not we've // been modified in a non-comparable manner, which we have to // treat as us being newer return (other.previousVersion != null); } // Can't be newer than itself if ( this == dataVersion ) { return false; } return versionComparator.compare(currentVersion, other.previousVersion) >= 1; } public String toString() { return super.toString() + " [current=" + currentVersion + ", previous=" + previousVersion + ", src=" + sourceIdentifer + "]"; } private void writeObject(java.io.ObjectOutputStream out) throws IOException { out.defaultWriteObject(); // The standard comparator types are not Serializable but are singletons if (versionComparator instanceof ComparableComparator) out.writeByte(0); else if (versionComparator instanceof CalendarComparator) out.writeByte(1); else { out.writeByte(999); out.writeObject(versionComparator); } } private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); byte comparatorType = in.readByte(); switch (comparatorType) { case 0: versionComparator = ComparableComparator.INSTANCE; break; case 1: versionComparator = CalendarComparator.INSTANCE; break; default: versionComparator = (Comparator) in.readObject(); } } } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/CircumventChecksDataVersion.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/CircumventCheck0000644000000000000000000000416111652065432030237 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.util; import org.hibernate.cache.CacheException; import org.jboss.cache.config.Option; import org.jboss.cache.optimistic.DataVersion; /** * Used to signal to a DataVersionAdapter to simply not perform any checks. This * is currently needed for proper handling of remove() calls for entity cache * regions (we do not know the version info...). * * @author Brian Stansberry * @version $Revision: 1 $ */ public class CircumventChecksDataVersion implements DataVersion { private static final long serialVersionUID = 7996980646166032369L; public static final DataVersion INSTANCE = new CircumventChecksDataVersion(); public static Option getInvocationOption() { Option option = new Option(); option.setDataVersion(INSTANCE); return option; } public boolean newerThan(DataVersion dataVersion) { throw new CacheException("optimistic locking checks should never happen on CircumventChecksDataVersion"); } } libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/0000755000000000000000000000000011675734517026427 5ustar ././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/OptimisticTransactionalAccess.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/Optimisti0000644000000000000000000000360011652065432030316 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.collection; import org.hibernate.cache.jbc.access.OptimisticTransactionalAccessDelegate; /** * Defines the strategy for transactional access to entity data in an * optimistic-locking JBoss Cache using its 2.x APIs * * @author Brian Stansberry * @version $Revision: 1 $ */ public class OptimisticTransactionalAccess extends TransactionalAccess { /** * Create a new OptimisticTransactionalAccess. * * @param region The region to which this is providing access */ public OptimisticTransactionalAccess(CollectionRegionImpl region) { // We use a different delegate than the non-optimistic superclass default super(region, new OptimisticTransactionalAccessDelegate(region, region.getPutFromLoadValidator())); } } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/OptimisticReadOnlyAccess.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/Optimisti0000644000000000000000000000525511652065432030326 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.collection; import org.hibernate.cache.CacheException; import org.hibernate.cache.access.SoftLock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * This defines the strategy for transactional access to collection data in an * optimistic-locking JBossCache using its 2.x APIs.

The read-only access * to a JBossCache really is still transactional, just with the extra semantic * or guarantee that we will not update data. * * @author Brian Stansberry */ public class OptimisticReadOnlyAccess extends OptimisticTransactionalAccess { private static final Logger log = LoggerFactory.getLogger(OptimisticReadOnlyAccess.class); /** * Create a new OptimisticReadOnlyAccess. * * @param region The region to which this is providing access */ public OptimisticReadOnlyAccess(CollectionRegionImpl region) { super(region); } @Override public SoftLock lockItem(Object key, Object version) throws CacheException { throw new UnsupportedOperationException("Illegal attempt to edit read only item"); } @Override public SoftLock lockRegion() throws CacheException { throw new UnsupportedOperationException("Illegal attempt to edit read only region"); } @Override public void unlockItem(Object key, SoftLock lock) throws CacheException { log.error("Illegal attempt to edit read only item"); } @Override public void unlockRegion(SoftLock lock) throws CacheException { log.error("Illegal attempt to edit read only region"); } } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/TransactionalAccess.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/Transacti0000644000000000000000000001023611652065432030270 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.collection; import org.hibernate.cache.CacheException; import org.hibernate.cache.CollectionRegion; import org.hibernate.cache.access.CollectionRegionAccessStrategy; import org.hibernate.cache.access.SoftLock; import org.hibernate.cache.jbc.access.TransactionalAccessDelegate; /** * This defines the strategy for transactional access to collection data in a * pessimistic-locking JBossCache using its 2.x APIs * * @author Steve Ebersole * @author Brian Stansberry */ public class TransactionalAccess implements CollectionRegionAccessStrategy { private final CollectionRegionImpl region; /** * Most of our logic is shared between this and entity regions, so we * delegate to a class that encapsulates it */ private final TransactionalAccessDelegate delegate; /** * Create a new TransactionalAccess. * * @param region the region to which this provides access */ public TransactionalAccess(CollectionRegionImpl region) { this(region, new TransactionalAccessDelegate(region, region.getPutFromLoadValidator())); } /** * Allow subclasses to define the delegate. * * @param region the region to which this provides access * @param delegate type of transactional access */ protected TransactionalAccess(CollectionRegionImpl region, TransactionalAccessDelegate delegate) { this.region = region; this.delegate = delegate; } /** * {@inheritDoc} */ public CollectionRegion getRegion() { return region; } /** * {@inheritDoc} */ public Object get(Object key, long txTimestamp) throws CacheException { return delegate.get(key, txTimestamp); } /** * {@inheritDoc} */ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { return delegate.putFromLoad(key, value, txTimestamp, version); } /** * {@inheritDoc} */ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { return delegate.putFromLoad(key, value, txTimestamp, version, minimalPutOverride); } /** * {@inheritDoc} */ public void remove(Object key) throws CacheException { delegate.remove(key); } /** * {@inheritDoc} */ public void removeAll() throws CacheException { delegate.removeAll(); } /** * {@inheritDoc} */ public void evict(Object key) throws CacheException { delegate.evict(key); } /** * {@inheritDoc} */ public void evictAll() throws CacheException { delegate.evictAll(); } /** * {@inheritDoc} */ public SoftLock lockItem(Object key, Object version) throws CacheException { return null; } /** * {@inheritDoc} */ public SoftLock lockRegion() throws CacheException { return null; } /** * {@inheritDoc} */ public void unlockItem(Object key, SoftLock lock) throws CacheException { } /** * {@inheritDoc} */ public void unlockRegion(SoftLock lock) throws CacheException { } } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/ReadOnlyAccess.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/ReadOnlyA0000644000000000000000000000525511652065432030163 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.collection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.hibernate.cache.access.SoftLock; import org.hibernate.cache.CacheException; /** * This defines the strategy for transactional access to collection data in a * pessimistic-locking JBossCache using its 2.x APIs.

The read-only access * to a JBossCache really is still transactional, just with the extra semantic * or guarantee that we will not update data. * * @author Steve Ebersole */ public class ReadOnlyAccess extends TransactionalAccess { private static final Logger log = LoggerFactory.getLogger(ReadOnlyAccess.class); /** * Create a provider of read-only access to the specific region. * * @param region The region to which this provides access. */ public ReadOnlyAccess(CollectionRegionImpl region) { super(region); } /** * {@inheritDoc} */ @Override public SoftLock lockItem(Object key, Object version) throws CacheException { throw new UnsupportedOperationException("Illegal attempt to edit read only item"); } /** * {@inheritDoc} */ @Override public SoftLock lockRegion() throws CacheException { throw new UnsupportedOperationException("Illegal attempt to edit read only region"); } /** * {@inheritDoc} */ @Override public void unlockItem(Object key, SoftLock lock) throws CacheException { log.error("Illegal attempt to edit read only item"); } /** * {@inheritDoc} */ @Override public void unlockRegion(SoftLock lock) throws CacheException { log.error("Illegal attempt to edit read only region"); } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/CollectionRegionImpl.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/Collectio0000644000000000000000000000620111652065432030252 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.collection; import org.jboss.cache.Cache; import org.jboss.cache.Fqn; import org.jboss.cache.config.Configuration.NodeLockingScheme; import org.jboss.cache.notifications.annotation.CacheListener; import org.hibernate.cache.CacheDataDescription; import org.hibernate.cache.CacheException; import org.hibernate.cache.CollectionRegion; import org.hibernate.cache.access.AccessType; import org.hibernate.cache.access.CollectionRegionAccessStrategy; import org.hibernate.cache.jbc.TransactionalDataRegionAdapter; import org.hibernate.cache.jbc.access.PutFromLoadValidator; /** * Defines the behavior of the collection cache regions for JBossCache 2.x. * * @author Steve Ebersole */ @CacheListener public class CollectionRegionImpl extends TransactionalDataRegionAdapter implements CollectionRegion { public static final String TYPE = "COLL"; private boolean optimistic; public CollectionRegionImpl(Cache jbcCache, String regionName, String regionPrefix, CacheDataDescription metadata) { super(jbcCache, regionName, regionPrefix, metadata); optimistic = (jbcCache.getConfiguration().getNodeLockingScheme() == NodeLockingScheme.OPTIMISTIC); } public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException { if (AccessType.READ_ONLY.equals(accessType)) { return optimistic ? new OptimisticReadOnlyAccess(this) : new ReadOnlyAccess(this); } if (AccessType.TRANSACTIONAL.equals(accessType)) { return optimistic ? new OptimisticTransactionalAccess(this) : new TransactionalAccess(this); } // todo : add support for READ_WRITE ( + NONSTRICT_READ_WRITE ??? ) throw new CacheException("unsupported access type [" + accessType.getName() + "]"); } @Override protected Fqn createRegionFqn(String regionName, String regionPrefix) { return getTypeLastRegionFqn(regionName, regionPrefix, TYPE); } public PutFromLoadValidator getPutFromLoadValidator() { return new PutFromLoadValidator(transactionManager); } } libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/query/0000755000000000000000000000000011675734517025441 5ustar ././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/query/QueryResultsRegionImpl.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/query/QueryResultsRe0000644000000000000000000001432711652065432030335 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.query; import java.util.Properties; import javax.transaction.Transaction; import org.hibernate.cache.CacheException; import org.hibernate.cache.QueryResultsRegion; import org.hibernate.cache.jbc.TransactionalDataRegionAdapter; import org.hibernate.cache.jbc.util.CacheHelper; import org.hibernate.util.PropertiesHelper; import org.jboss.cache.Cache; import org.jboss.cache.Fqn; import org.jboss.cache.config.Option; import org.jboss.cache.notifications.annotation.CacheListener; /** * Defines the behavior of the query cache regions for JBossCache 2.x. * * @author Brian Stansberry * @version $Revision$ */ @CacheListener public class QueryResultsRegionImpl extends TransactionalDataRegionAdapter implements QueryResultsRegion { public static final String QUERY_CACHE_LOCAL_ONLY_PROP = "hibernate.cache.jbc.query.localonly"; public static final String LEGACY_QUERY_CACHE_LOCAL_ONLY_PROP = "hibernate.cache.region.jbc2.query.localonly"; public static final String TYPE = "QUERY"; /** * Whether we should set an option to disable propagation of changes around * cluster. */ private boolean localOnly; /** * Create a new QueryResultsRegionImpl. * * @param jbcCache The JBC cache instance to use to store the query results * @param regionName The name of the region (within the JBC cache) * @param regionPrefix Any region prefix to apply * @param properties The configuration properties. */ public QueryResultsRegionImpl(Cache jbcCache, String regionName, String regionPrefix, Properties properties) { super(jbcCache, regionName, regionPrefix, null); // If JBC is using INVALIDATION, we don't want to propagate changes. // We use the Timestamps cache to manage invalidation localOnly = CacheHelper.isClusteredInvalidation(jbcCache); if (!localOnly) { // We don't want to waste effort setting an option if JBC is // already in LOCAL mode. If JBC is REPL_(A)SYNC then check // if they passed an config option to disable query replication if (CacheHelper.isClusteredReplication(jbcCache)) { if (properties.containsKey(QUERY_CACHE_LOCAL_ONLY_PROP)) { localOnly = PropertiesHelper.getBoolean(QUERY_CACHE_LOCAL_ONLY_PROP, properties, false); } else { localOnly = PropertiesHelper.getBoolean(LEGACY_QUERY_CACHE_LOCAL_ONLY_PROP, properties, false); } } } } public void evict(Object key) throws CacheException { ensureRegionRootExists(); Option opt = getNonLockingDataVersionOption(false); if (localOnly) opt.setCacheModeLocal(true); CacheHelper.removeNode(getCacheInstance(), getRegionFqn(), key, opt); } public void evictAll() throws CacheException { Transaction tx = suspend(); try { ensureRegionRootExists(); Option opt = getNonLockingDataVersionOption(true); CacheHelper.sendEvictAllNotification(jbcCache, regionFqn, getMemberId(), opt); } finally { resume(tx); } } public Object get(Object key) throws CacheException { if (!checkValid()) return null; ensureRegionRootExists(); // Don't hold the JBC node lock throughout the tx, as that // prevents updates // Add a zero (or low) timeout option so we don't block // waiting for tx's that did a put to commit Option opt = new Option(); opt.setLockAcquisitionTimeout(0); return suspendAndGet(key, opt, true); } public void put(Object key, Object value) throws CacheException { if (checkValid()) { ensureRegionRootExists(); // Here we don't want to suspend the tx. If we do: // 1) We might be caching query results that reflect uncommitted // changes. No tx == no WL on cache node, so other threads // can prematurely see those query results // 2) No tx == immediate replication. More overhead, plus we // spread issue #1 above around the cluster // Add a zero (or quite low) timeout option so we don't block. // Ignore any TimeoutException. Basically we forego caching the // query result in order to avoid blocking. // Reads are done with suspended tx, so they should not hold the // lock for long. Not caching the query result is OK, since // any subsequent read will just see the old result with its // out-of-date timestamp; that result will be discarded and the // db query performed again. Option opt = getNonLockingDataVersionOption(false); opt.setLockAcquisitionTimeout(2); if (localOnly) opt.setCacheModeLocal(true); CacheHelper.putAllowingTimeout(getCacheInstance(), getRegionFqn(), key, value, opt); } } @Override protected Fqn createRegionFqn(String regionName, String regionPrefix) { return getTypeLastRegionFqn(regionName, regionPrefix, TYPE); } } libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/timestamp/0000755000000000000000000000000011675734517026277 5ustar ././@LongLink0000000000000000000000000000020700000000000011564 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/timestamp/ClusteredConcurrentTimestampsRegionImpl.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/timestamp/ClusteredC0000644000000000000000000003134311652065432030247 0ustar /* * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, v. 2.1. This program is distributed in the * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. You should have received a * copy of the GNU Lesser General Public License, v.2.1 along with this * distribution; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Red Hat Author(s): Brian Stansberry */ package org.hibernate.cache.jbc.timestamp; import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Semaphore; import javax.transaction.Transaction; import org.hibernate.cache.CacheException; import org.hibernate.cache.TimestampsRegion; import org.hibernate.cache.jbc.TransactionalDataRegionAdapter; import org.hibernate.cache.jbc.util.CacheHelper; import org.jboss.cache.Cache; import org.jboss.cache.Fqn; import org.jboss.cache.config.Option; import org.jboss.cache.notifications.annotation.CacheListener; import org.jboss.cache.notifications.annotation.NodeModified; import org.jboss.cache.notifications.annotation.NodeRemoved; import org.jboss.cache.notifications.event.NodeModifiedEvent; import org.jboss.cache.notifications.event.NodeRemovedEvent; /** * Prototype of a clustered timestamps cache region impl usable if the * TimestampsRegion API is changed. *

* Maintains a local (authoritative) cache of timestamps along with the * distributed cache held in JBoss Cache. Listens for changes in the distributed * cache and updates the local cache accordingly. Ensures that any changes in * the local cache represent either 1) an increase in the timestamp or * 2) a stepback in the timestamp by the caller that initially increased * it as part of a pre-invalidate call. This approach allows * timestamp changes to be replicated asynchronously by JBoss Cache while still * preventing invalid backward changes in timestamps. *

* * NOTE: This is just a prototype!!! Only useful if we change the * TimestampsRegion API. * * @author Brian Stansberry * @version $Revision: 14106 $ */ @CacheListener public class ClusteredConcurrentTimestampsRegionImpl extends TransactionalDataRegionAdapter implements TimestampsRegion { public static final String TYPE = "TS"; private final ConcurrentHashMap localCache = new ConcurrentHashMap(); /** * Create a new ClusteredConccurentTimestampsRegionImpl. * * @param jbcCache * @param regionName * @param regionPrefix * TODO * @param metadata */ public ClusteredConcurrentTimestampsRegionImpl(Cache jbcCache, String regionName, String regionPrefix, Properties properties) { super(jbcCache, regionName, regionPrefix, null); jbcCache.addCacheListener(this); populateLocalCache(); } @Override protected Fqn createRegionFqn(String regionName, String regionPrefix) { return getTypeFirstRegionFqn(regionName, regionPrefix, TYPE); } public void evict(Object key) throws CacheException { Option opt = getNonLockingDataVersionOption(true); CacheHelper.removeNode(getCacheInstance(), getRegionFqn(), key, opt); } public void evictAll() throws CacheException { Option opt = getNonLockingDataVersionOption(true); CacheHelper.removeAll(getCacheInstance(), getRegionFqn(), opt); } public Object get(Object key) throws CacheException { Entry entry = getLocalEntry(key); Object timestamp = entry.getCurrent(); if (timestamp == null) { // Double check the distributed cache Object[] vals = (Object[]) suspendAndGet(key, null, false); if (vals != null) { storeDataFromJBC(key, vals); timestamp = entry.getCurrent(); } } return timestamp; } public void put(Object key, Object value) throws CacheException { throw new UnsupportedOperationException("Prototype only; Hibernate core must change the API before really using"); } public void preInvalidate(Object key, Object value) throws CacheException { Entry entry = getLocalEntry(key); if (entry.preInvalidate(value)) { putInJBossCache(key, entry); } } public void invalidate(Object key, Object value, Object preInvalidateValue) throws CacheException { Entry entry = getLocalEntry(key); if (entry.invalidate(value, preInvalidateValue)) { putInJBossCache(key, entry); } } private void putInJBossCache(Object key, Entry entry) { // Get an exclusive right to update JBC for this key from this node. boolean locked = false; try { entry.acquireJBCWriteMutex(); locked = true; // We have the JBCWriteMutex, so no other *local* thread will // be trying to write this key. // It's possible here some remote thread has come in and // changed the values again, but since we are reading the // values to write to JBC right now, we know we are writing // the latest values; i.e. we don't assume that what we cached // in entry.update() above is what we should write to JBC *now*. // Our write could be redundant, i.e. we are writing what // some remote thread just came in an wrote. There is a chance // that yet another remote thread will update us, and we'll then // overwrite that later data in JBC. But, all remote nodes will // ignore that change in their localCache; the only place it // will live will be in JBC, where it can only effect the // initial state transfer values on newly joined nodes // (i.e. populateLocalCache()). // Don't hold the JBC node lock throughout the tx, as that // prevents reads and other updates Transaction tx = suspend(); try { Option opt = getNonLockingDataVersionOption(false); // We ensure ASYNC semantics (JBCACHE-1175) opt.setForceAsynchronous(true); CacheHelper.put(getCacheInstance(), getRegionFqn(), key, entry.getJBCUpdateValues(), opt); } finally { resume(tx); } } catch (InterruptedException e) { throw new CacheException("Interrupted while acquiring right to update " + key, e); } finally { if (locked) { entry.releaseJBCWriteMutex(); } } } @Override public void destroy() throws CacheException { getCacheInstance().removeCacheListener(this); super.destroy(); localCache.clear(); } /** * Monitors cache events and updates the local cache * * @param event */ @NodeModified public void nodeModified(NodeModifiedEvent event) { if (event.isOriginLocal() || event.isPre()) return; Fqn fqn = event.getFqn(); Fqn regFqn = getRegionFqn(); if (fqn.size() == regFqn.size() + 1 && fqn.isChildOf(regFqn)) { Object key = fqn.get(regFqn.size()); Object[] vals = (Object[]) event.getData().get(ITEM); storeDataFromJBC(key, vals); // TODO consider this hack instead of the simple entry.update above: // if (!entry.update(vals[0], vals[1])) { // // Hack! Use the fact that the Object[] stored in JBC is // // mutable to correct our local JBC state in this callback // Object[] correct = entry.getJBCUpdateValues(); // vals[0] = correct[0]; // vals[1] = correct[1]; // } } } private void storeDataFromJBC(Object key, Object[] vals) { Entry entry = getLocalEntry(key); if (vals[0].equals(vals[1])) { entry.preInvalidate(vals[0]); } else { entry.invalidate(vals[0], vals[1]); } } /** * Monitors cache events and updates the local cache * * @param event */ @NodeRemoved public void nodeRemoved(NodeRemovedEvent event) { if (event.isOriginLocal() || event.isPre()) return; Fqn fqn = event.getFqn(); Fqn regFqn = getRegionFqn(); if (fqn.isChildOrEquals(regFqn)) { if (fqn.size() == regFqn.size()) { localCache.clear(); } else { Object key = fqn.get(regFqn.size()); localCache.remove(key); } } } /** * Brings all data from the distributed cache into our local cache. */ private void populateLocalCache() { Set children = CacheHelper.getChildrenNames(getCacheInstance(), getRegionFqn()); for (Object key : children) { Object[] vals = (Object[]) suspendAndGet(key, null, false); if (vals != null) { storeDataFromJBC(key, vals); } } } private Entry getLocalEntry(Object key) { Entry entry = new Entry(); Entry oldEntry = (Entry) localCache.putIfAbsent(key, entry); return (oldEntry == null ? entry : oldEntry); } private class Entry { private Semaphore writeMutex = new Semaphore(1); private boolean preInvalidated = false; private Object preInval = null; private Object current = null; void acquireJBCWriteMutex() throws InterruptedException { writeMutex.acquire(); } void releaseJBCWriteMutex() { writeMutex.release(); } synchronized boolean preInvalidate(Object newVal) { boolean result = false; if (newVal instanceof Comparable) { if (current == null || ((Comparable) newVal).compareTo(current) > 0) { preInval = current = newVal; preInvalidated = true; result = true; } } else { preInval = current = newVal; result = true; } return result; } synchronized boolean invalidate(Object newVal, Object preInvalidateValue) { boolean result = false; if (current == null) { // Initial load from JBC current = newVal; preInval = preInvalidateValue; preInvalidated = false; result = true; } else if (preInvalidated) { if (newVal instanceof Comparable) { if (safeEquals(preInvalidateValue, this.preInval) || ((Comparable) newVal).compareTo(preInval) > 0) { current = newVal; preInval = preInvalidateValue; preInvalidated = false; result = true; } } else { current = newVal; preInval = preInvalidateValue; result = true; } } else if (newVal instanceof Comparable) { // See if we had a 2nd invalidation from the same initial // preinvalidation timestamp. If so, only increment // if the new current value is an increase if (safeEquals(preInvalidateValue, this.preInval) && ((Comparable) newVal).compareTo(current) > 0) { current = newVal; preInval = preInvalidateValue; result = true; } } return result; } synchronized Object getCurrent() { return current; } synchronized Object getPreInval() { return preInval; } synchronized Object[] getJBCUpdateValues() { return new Object[] {current, preInval}; } private boolean safeEquals(Object a, Object b) { return (a == b || (a != null && a.equals(b))); } } } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/timestamp/TimestampsRegionImpl.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/timestamp/Timestamps0000644000000000000000000001621611652065432030342 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.timestamp; import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import javax.transaction.Transaction; import org.hibernate.cache.CacheException; import org.hibernate.cache.TimestampsRegion; import org.hibernate.cache.jbc.TransactionalDataRegionAdapter; import org.hibernate.cache.jbc.util.CacheHelper; import org.jboss.cache.Cache; import org.jboss.cache.Fqn; import org.jboss.cache.config.Option; import org.jboss.cache.notifications.annotation.CacheListener; import org.jboss.cache.notifications.annotation.NodeModified; import org.jboss.cache.notifications.annotation.NodeRemoved; import org.jboss.cache.notifications.event.NodeInvalidatedEvent; import org.jboss.cache.notifications.event.NodeModifiedEvent; import org.jboss.cache.notifications.event.NodeRemovedEvent; /** * Defines the behavior of the timestamps cache region for JBossCache 2.x. * * TODO Need to define a way to ensure asynchronous replication events * do not result in timestamps moving backward, while dealing with the fact * that the normal sequence of UpdateTimestampsCache.preinvalidate() then * UpdateTimestampsCache.invalidate() will result in 2 calls to put() with * the latter call having an earlier timestamp. * * @author Brian Stansberry * @version $Revision$ */ @CacheListener public class TimestampsRegionImpl extends TransactionalDataRegionAdapter implements TimestampsRegion { public static final String TYPE = "TS"; private Map localCache = new ConcurrentHashMap(); /** * Create a new TimestampsRegionImpl. * * @param jbcCache The JBC cache instance to use to store the timestamps data * @param regionName The name of the region (within the JBC cache) * @param regionPrefix Any region prefix to apply * @param properties The configuration properties. */ public TimestampsRegionImpl(Cache jbcCache, String regionName, String regionPrefix, Properties properties) { super(jbcCache, regionName, regionPrefix, null); jbcCache.addCacheListener(this); populateLocalCache(); } @Override protected Fqn createRegionFqn(String regionName, String regionPrefix) { return getTypeFirstRegionFqn(regionName, regionPrefix, TYPE); } public void evict(Object key) throws CacheException { ensureRegionRootExists(); // TODO Is this a valid operation on a timestamps cache? Option opt = getNonLockingDataVersionOption(true); CacheHelper.removeNode(getCacheInstance(), getRegionFqn(), key, opt); } public void evictAll() throws CacheException { // TODO Is this a valid operation on a timestamps cache? Transaction tx = suspend(); try { ensureRegionRootExists(); Option opt = getNonLockingDataVersionOption(true); CacheHelper.sendEvictAllNotification(jbcCache, regionFqn, getMemberId(), opt); } finally { resume(tx); } } public Object get(Object key) throws CacheException { Object value = localCache.get(key); if (value == null && checkValid()) { ensureRegionRootExists(); value = suspendAndGet(key, null, false); if (value != null) localCache.put(key, value); } return value; } public void put(Object key, Object value) throws CacheException { ensureRegionRootExists(); // Don't hold the JBC node lock throughout the tx, as that // prevents reads and other updates Transaction tx = suspend(); try { // TODO Why not use the timestamp in a DataVersion? Option opt = getNonLockingDataVersionOption(false); // We ensure ASYNC semantics (JBCACHE-1175) opt.setForceAsynchronous(true); CacheHelper.put(getCacheInstance(), getRegionFqn(), key, value, opt); } catch (Exception e) { throw new CacheException(e); } finally { resume(tx); } } @Override public void destroy() throws CacheException { localCache.clear(); getCacheInstance().removeCacheListener(this); super.destroy(); } /** * Monitors cache events and updates the local cache * * @param event */ @NodeModified public void nodeModified(NodeModifiedEvent event) { if (!handleEvictAllModification(event) && !event.isPre()) { Fqn fqn = event.getFqn(); Fqn regFqn = getRegionFqn(); if (fqn.size() == regFqn.size() + 1 && fqn.isChildOf(regFqn)) { Object key = fqn.get(regFqn.size()); localCache.put(key, event.getData().get(ITEM)); } } } /** * Monitors cache events and updates the local cache * * @param event */ @NodeRemoved public void nodeRemoved(NodeRemovedEvent event) { if (event.isPre()) return; Fqn fqn = event.getFqn(); Fqn regFqn = getRegionFqn(); if (fqn.size() == regFqn.size() + 1 && fqn.isChildOf(regFqn)) { Object key = fqn.get(regFqn.size()); localCache.remove(key); } else if (fqn.equals(regFqn)) { localCache.clear(); } } @Override protected boolean handleEvictAllInvalidation(NodeInvalidatedEvent event) { boolean result = super.handleEvictAllInvalidation(event); if (result) { localCache.clear(); } return result; } @Override protected boolean handleEvictAllModification(NodeModifiedEvent event) { boolean result = super.handleEvictAllModification(event); if (result) { localCache.clear(); } return result; } /** * Brings all data from the distributed cache into our local cache. */ private void populateLocalCache() { Set children = CacheHelper.getChildrenNames(getCacheInstance(), getRegionFqn()); for (Object key : children) { get(key); } } } libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/0000755000000000000000000000000011675734517025722 5ustar ././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/MultiplexingCacheInstanceManager.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/Multiplexing0000644000000000000000000005250111652065432030315 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.builder; import java.util.Properties; import javax.transaction.TransactionManager; import org.jboss.cache.Cache; import org.jboss.cache.CacheManager; import org.jboss.cache.CacheManagerImpl; import org.jboss.cache.CacheStatus; import org.jboss.cache.config.Configuration; import org.jgroups.ChannelFactory; import org.jgroups.JChannelFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.hibernate.cache.CacheException; import org.hibernate.cache.jbc.CacheInstanceManager; import org.hibernate.cache.jbc.util.CacheHelper; import org.hibernate.cfg.Settings; import org.hibernate.transaction.TransactionManagerLookup; import org.hibernate.util.PropertiesHelper; /** * Allows building separate {@link Cache} instances for each type of region, * with the expectation that a single multiplexed JGroups resource (i.e. a * multiplexed channel or a shared transport channel) will be shared between * the caches.

* * @author Steve Ebersole * @author Brian Stansberry */ public class MultiplexingCacheInstanceManager implements CacheInstanceManager { private static final Logger log = LoggerFactory.getLogger(MultiplexingCacheInstanceManager.class); /** * Classpath or filesystem resource containing JBoss Cache * configurations the factory should use. * * @see #DEF_CACHE_FACTORY_RESOURCE */ public static final String CACHE_FACTORY_RESOURCE_PROP = "hibernate.cache.jbc.configs"; /** * Legacy name for configuration property {@link #CACHE_FACTORY_RESOURCE_PROP}. * * @see #DEF_CACHE_FACTORY_RESOURCE */ public static final String LEGACY_CACHE_FACTORY_RESOURCE_PROP = "hibernate.cache.region.jbc2.configs"; /** * Classpath or filesystem resource containing JGroups protocol * stack configurations the org.jgroups.ChannelFactory * should use. * * @see #DEF_JGROUPS_RESOURCE */ public static final String CHANNEL_FACTORY_RESOURCE_PROP = "hibernate.cache.jbc.jgroups.stacks"; /** * Legacy name for configuration property {@link #CHANNEL_FACTORY_RESOURCE_PROP}. * * @see #DEF_JGROUPS_RESOURCE */ public static final String LEGACY_CHANNEL_FACTORY_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.jgroups.stacks"; /** * Name of the configuration that should be used for entity caches. * * @see #DEF_ENTITY_RESOURCE */ public static final String ENTITY_CACHE_RESOURCE_PROP = "hibernate.cache.jbc.cfg.entity"; /** * Legacy name for configuration property {@link #ENTITY_CACHE_RESOURCE_PROP}. * * @see #DEF_ENTITY_RESOURCE */ public static final String LEGACY_ENTITY_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.entity"; /** * Name of the configuration that should be used for collection caches. * No default value, as by default we try to use the same JBoss Cache * instance we use for entity caching. * * @see #ENTITY_CACHE_RESOURCE_PROP * @see #DEF_ENTITY_RESOURCE */ public static final String COLLECTION_CACHE_RESOURCE_PROP = "hibernate.cache.jbc.cfg.collection"; /** * Legacy name for configuration property {@link #COLLECTION_CACHE_RESOURCE_PROP}. * * @see #ENTITY_CACHE_RESOURCE_PROP * @see #DEF_ENTITY_RESOURCE */ public static final String LEGACY_COLLECTION_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.collection"; /** * Name of the configuration that should be used for timestamp caches. * * @see #DEF_TS_RESOURCE */ public static final String TIMESTAMP_CACHE_RESOURCE_PROP = "hibernate.cache.jbc.cfg.timestamps"; /** * Legacy name for configuration property {@link #TIMESTAMP_CACHE_RESOURCE_PROP}. * * @see #DEF_TS_RESOURCE */ public static final String LEGACY_TIMESTAMP_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.ts"; /** * Name of the configuration that should be used for query caches. * * @see #DEF_QUERY_RESOURCE */ public static final String QUERY_CACHE_RESOURCE_PROP = "hibernate.cache.jbc.cfg.query"; /** * Legacy name for configuration property {@link #QUERY_CACHE_RESOURCE_PROP}. * * @see #DEF_QUERY_RESOURCE */ public static final String LEGACY_QUERY_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.query"; /** * Default value for {@link #CACHE_FACTORY_RESOURCE_PROP}. Specifies * the "jbc2-configs.xml" file in this package. */ public static final String DEF_CACHE_FACTORY_RESOURCE = "org/hibernate/cache/jbc/builder/jbc-configs.xml"; /** * Default value for {@link #CHANNEL_FACTORY_RESOURCE_PROP}. Specifies * the "jgroups-stacks.xml" file in this package. */ public static final String DEF_JGROUPS_RESOURCE = "org/hibernate/cache/jbc/builder/jgroups-stacks.xml"; /** * Default value for {@link #ENTITY_CACHE_RESOURCE_PROP}. */ public static final String DEF_ENTITY_RESOURCE = "optimistic-entity"; /** * Default value for {@link #TIMESTAMP_CACHE_RESOURCE_PROP}. */ public static final String DEF_TS_RESOURCE = "timestamps-cache"; /** * Default value for {@link #ENTITY_CACHE_RESOURCE_PROP}. */ public static final String DEF_QUERY_RESOURCE = "local-query"; /** Cache for entities */ private Cache jbcEntityCache; /** Cache for collections */ private Cache jbcCollectionCache; /** Cache for timestamps */ private Cache jbcTsCache; /** Cache for queries */ private Cache jbcQueryCache; /** Name of config used for entities. */ private String entityConfig = null; /** Name of config used for collections. */ private String collectionConfig = null; /** Name of config used for queries. */ private String queryConfig = null; /** Name of config used for timestamps. */ private String tsConfig = null; /** Our cache factory */ private CacheManager jbcFactory; /** Our channel factory */ private ChannelFactory channelFactory; /** * Did we create the factory ourself and thus can assume we are not * sharing it (and the caches) with other users? */ private boolean selfCreatedFactory; /** * Create a new MultiplexingCacheInstanceManager. */ public MultiplexingCacheInstanceManager() { } /** * Create a new MultiplexingCacheInstanceManager using the provided {@link Cache}s. *

* If this constructor is used, the {@link #start(Settings, Properties)} * method will make no attempt to create a cache factory or obtain caches * from it. Only the Caches passed as arguments to this * constructor will be available. * * @param jbcEntityCache The entity cache * @param jbcCollectionCache the collection cache * @param jbcTsCache The timestamps cache * @param jbcQueryCache The query cache */ public MultiplexingCacheInstanceManager( Cache jbcEntityCache, Cache jbcCollectionCache, Cache jbcTsCache, Cache jbcQueryCache) { this.jbcEntityCache = jbcEntityCache; this.jbcCollectionCache = jbcCollectionCache; this.jbcTsCache = jbcTsCache; this.jbcQueryCache = jbcQueryCache; } /** * Getter for property 'cacheFactory'. * @see #setCacheFactory * * @return Value for property 'cacheFactory'. */ public CacheManager getCacheFactory() { return jbcFactory; } /** * Setter for property 'cacheFactory'. * @see #getCacheFactory * * @param factory Value to set for property 'cacheFactory'. */ public void setCacheFactory(CacheManager factory) { this.jbcFactory = factory; } /** * Getter for property 'channelFactory'. * @see #setChannelFactory * * @return Value for property 'channelFactory'. */ public ChannelFactory getChannelFactory() { return channelFactory; } /** * Setter for property 'channelFactory'. * @see #getChannelFactory * * @param factory Value to set for property 'channelFactory'. */ public void setChannelFactory(ChannelFactory factory) { this.channelFactory = factory; } /** * {@inheritDoc} */ public Cache getEntityCacheInstance() { return jbcEntityCache; } /** * {@inheritDoc} */ public Cache getCollectionCacheInstance() { return jbcCollectionCache; } /** * {@inheritDoc} */ public Cache getQueryCacheInstance() { if (jbcQueryCache != null && jbcTsCache == null) { // This should only be possible if the caches are constructor injected throw new CacheException("Timestamps cache must be configured if a query cache is used"); } return jbcQueryCache; } /** * {@inheritDoc} */ public Cache getTimestampsCacheInstance() { if (jbcTsCache != null && CacheHelper.isClusteredInvalidation(jbcTsCache)) { throw new CacheException("Clustered invalidation not supported for timestamps cache"); } return jbcTsCache; } /** * {@inheritDoc} */ public void start(Settings settings, Properties properties) throws CacheException { try { // We need our tm, so get it now and avoid doing other work // if there is a problem TransactionManagerLookup tml = settings.getTransactionManagerLookup(); TransactionManager tm = (tml == null ? null : tml.getTransactionManager(properties)); // We only build caches if *none* were passed in. Passing in // caches counts as a clear statement of exactly what is wanted boolean buildCaches = jbcEntityCache == null && jbcCollectionCache == null && jbcTsCache == null && jbcQueryCache == null; // Set up the cache factory if (buildCaches && jbcFactory == null) { // See if the user configured a multiplexer stack if (channelFactory == null) { String muxStacks = PropertiesHelper.getString(CHANNEL_FACTORY_RESOURCE_PROP, properties, null); if (muxStacks == null) { muxStacks = PropertiesHelper.getString(LEGACY_CHANNEL_FACTORY_RESOURCE_PROP, properties, DEF_JGROUPS_RESOURCE); } if (muxStacks != null) { channelFactory = new JChannelFactory(); channelFactory.setMultiplexerConfig(muxStacks); } } String factoryRes = PropertiesHelper.getString(CACHE_FACTORY_RESOURCE_PROP, properties, null); if (factoryRes == null) { factoryRes = PropertiesHelper.getString(LEGACY_CACHE_FACTORY_RESOURCE_PROP, properties, DEF_CACHE_FACTORY_RESOURCE); } jbcFactory = new CacheManagerImpl(factoryRes, channelFactory); ((CacheManagerImpl) jbcFactory).start(); selfCreatedFactory = true; } if (settings.isSecondLevelCacheEnabled()) { if (buildCaches) { entityConfig = PropertiesHelper .getString(ENTITY_CACHE_RESOURCE_PROP, properties, null); if (entityConfig == null) { entityConfig = PropertiesHelper.getString(LEGACY_ENTITY_CACHE_RESOURCE_PROP, properties, DEF_ENTITY_RESOURCE); } jbcEntityCache = jbcFactory.getCache(entityConfig, true); // Default to collections sharing entity cache if there is one collectionConfig = PropertiesHelper.getString(COLLECTION_CACHE_RESOURCE_PROP, properties, null); if (collectionConfig == null) { collectionConfig = PropertiesHelper.getString(LEGACY_COLLECTION_CACHE_RESOURCE_PROP, properties, entityConfig); } if (entityConfig.equals(collectionConfig)) { jbcCollectionCache = jbcEntityCache; } else { jbcCollectionCache = jbcFactory.getCache(collectionConfig, true); } } if (jbcEntityCache != null) { configureTransactionManager(jbcEntityCache, tm, false); jbcEntityCache.start(); } if (jbcCollectionCache != null) { configureTransactionManager(jbcCollectionCache, tm, false); jbcCollectionCache.start(); } } else { jbcEntityCache = null; jbcCollectionCache = null; } if (settings.isQueryCacheEnabled()) { if (buildCaches) { // Default to sharing the entity cache if there is one String dfltQueryResource = (entityConfig == null ? DEF_QUERY_RESOURCE : entityConfig); queryConfig = PropertiesHelper.getString(QUERY_CACHE_RESOURCE_PROP, properties, null); if (queryConfig == null) { queryConfig = PropertiesHelper.getString(LEGACY_QUERY_CACHE_RESOURCE_PROP, properties, dfltQueryResource); } if (queryConfig.equals(entityConfig)) { jbcQueryCache = jbcEntityCache; } else if (queryConfig.equals(collectionConfig)) { jbcQueryCache = jbcCollectionCache; } else { jbcQueryCache = jbcFactory.getCache(queryConfig, true); } // For Timestamps, we default to a separate config tsConfig = PropertiesHelper.getString(TIMESTAMP_CACHE_RESOURCE_PROP, properties, null); if (tsConfig == null) { tsConfig = PropertiesHelper.getString(LEGACY_TIMESTAMP_CACHE_RESOURCE_PROP, properties, DEF_TS_RESOURCE); } if (tsConfig.equals(queryConfig)) { jbcTsCache = jbcQueryCache; } else if (tsConfig.equals(entityConfig)) { jbcTsCache = jbcEntityCache; } else if (tsConfig.equals(collectionConfig)) { jbcTsCache = jbcCollectionCache; } else { jbcTsCache = jbcFactory.getCache(tsConfig, true); } } if (jbcQueryCache != null) { configureTransactionManager(jbcQueryCache, tm, false); jbcQueryCache.start(); // TODO: I considered validating the presence of the TS cache here, // but decided to defer unti getQueryCacheInstance() in case the // cache is never actually used } if (jbcTsCache != null) { configureTransactionManager(jbcTsCache, tm, true); jbcTsCache.start(); // TODO: I considered validating TS cache config here, // but decided to defer unti getTimestampsCacheInstance() in case the // cache is never actually used } } else { jbcTsCache = null; jbcQueryCache = null; } } catch (CacheException ce) { throw ce; } catch (Throwable t) { throw new CacheException("Unable to start region factory", t); } } /** * {@inheritDoc} */ public void stop() { releaseCaches(); if (selfCreatedFactory) { ((CacheManagerImpl) jbcFactory).stop(); } } /** * Injects the given TransactionManager into the cache. * * @param cache the cache. cannot be null * @param tm the transaction manager Hibernate recognizes * May be null * @param allowNull whether we accept a null transaction manager in the cache * if tm is not null * * @throws CacheException if cache is already started and is * configured with a different TransactionManager * than the one we would inject */ private void configureTransactionManager(Cache cache, TransactionManager tm, boolean allowNull) { Configuration cacheConfig = cache.getConfiguration(); TransactionManager cacheTm = cacheConfig.getRuntimeConfig().getTransactionManager(); if (!safeEquals(tm, cacheTm)) { if (cache.getCacheStatus() != CacheStatus.INSTANTIATED) { // We can't change the TM on a running cache; just check // if the cache has no TM and we're OK with that if (!allowNull && cacheTm == null) { throw new CacheException("JBoss Cache is already started with no transaction manager configured"); } else { log.debug("JBoss Cache is already started with a transaction manager (" + cacheTm + ") that is not equal to our own (" + tm + ")"); } } else { // Configure the cache to use our TM cacheConfig.getRuntimeConfig().setTransactionManager(tm); if (tm == null) { // Make sure JBC doesn't look one up cacheConfig.setTransactionManagerLookupClass(null); } } } } /** * Notify cache factory that we are no longer using the caches. */ private void releaseCaches() { // This method should be implemented assuming it's valid to // do start/stop/start -- leave state appropriate for another start if (jbcEntityCache != null && entityConfig != null) { try { jbcFactory.releaseCache(entityConfig); jbcEntityCache = null; // Make sure we don't re-release the same cache if (entityConfig.equals(collectionConfig)) collectionConfig = null; if (entityConfig.equals(queryConfig)) queryConfig = null; if (entityConfig.equals(tsConfig)) tsConfig = null; entityConfig = null; } catch (Throwable t) { log.info("Unable to release entity cache instance", t); } } if (jbcCollectionCache != null && collectionConfig != null) { try { jbcFactory.releaseCache(collectionConfig); jbcCollectionCache = null; if (collectionConfig.equals(queryConfig)) queryConfig = null; if (collectionConfig.equals(tsConfig)) tsConfig = null; collectionConfig = null; } catch (Throwable t) { log.info("Unable to stop collection cache instance", t); } } if (jbcQueryCache != null && queryConfig != null) { try { jbcFactory.releaseCache(queryConfig); jbcQueryCache = null; if (queryConfig.equals(tsConfig)) tsConfig = null; queryConfig = null; } catch (Throwable t) { log.info("Unable to stop query cache instance", t); } } if (jbcTsCache != null && tsConfig != null) { try { jbcFactory.releaseCache(tsConfig); jbcTsCache = null; tsConfig = null; } catch (Throwable t) { log.info("Unable to stop timestamp cache instance", t); } } } private boolean safeEquals(Object a, Object b) { return (a == b || (a != null && a.equals(b))); } } ././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/JndiSharedCacheInstanceManager.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/JndiSharedCa0000644000000000000000000000762711652065432030124 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.builder; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.hibernate.cache.CacheException; import org.hibernate.cfg.Settings; import org.hibernate.util.NamingHelper; import org.hibernate.util.PropertiesHelper; import org.jboss.cache.Cache; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A {@link SharedCacheInstanceManager} that finds the shared cache in JNDI * rather than instantiating one from an XML config file. * * @author Brian Stansberry * @version $Revision: 1 $ */ public class JndiSharedCacheInstanceManager extends SharedCacheInstanceManager { private static final Logger log = LoggerFactory.getLogger(JndiSharedCacheInstanceManager.class); /** * Specifies the JNDI name under which the {@link Cache} to use is bound. *

* Note that although this configuration property has the same name as that by * in {@link SharedCacheInstanceManager#CACHE_RESOURCE_PROP the superclass}, * the meaning here is different. Note also that in this class' usage * of the property, there is no default value -- the user must specify * the property. */ public static final String CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.shared"; /** * Create a new JndiSharedCacheInstanceManager. * */ public JndiSharedCacheInstanceManager() { super(); } @Override protected Cache createSharedCache(Settings settings, Properties properties) { String name = PropertiesHelper.getString(CACHE_RESOURCE_PROP, properties, null); if (name == null) throw new CacheException("Configuration property " + CACHE_RESOURCE_PROP + " not set"); return locateCache( name, NamingHelper.getJndiProperties( properties ) ); } /** * No-op; we don't own the cache so we shouldn't stop it. */ @Override protected void stopSharedCache(Cache cache) { // no-op. We don't own the cache so we shouldn't stop it. } private Cache locateCache(String jndiNamespace, Properties jndiProperties) { Context ctx = null; try { ctx = new InitialContext( jndiProperties ); return (Cache) ctx.lookup( jndiNamespace ); } catch (NamingException ne) { String msg = "Unable to retreive Cache from JNDI [" + jndiNamespace + "]"; log.info( msg, ne ); throw new CacheException( msg ); } finally { if ( ctx != null ) { try { ctx.close(); } catch( NamingException ne ) { log.info( "Unable to release initial context", ne ); } } } } } ././@LongLink0000000000000000000000000000020200000000000011557 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/JndiMultiplexingCacheInstanceManager.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/JndiMultiple0000644000000000000000000000715211652065432030236 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.builder; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.hibernate.cache.CacheException; import org.hibernate.cfg.Settings; import org.hibernate.util.NamingHelper; import org.hibernate.util.PropertiesHelper; import org.jboss.cache.CacheManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A {@link MultiplexingCacheInstanceManager} that finds its cache factory * in JNDI rather than creating one itself. * * @author Brian Stansberry * @version $Revision: 1 $ */ public class JndiMultiplexingCacheInstanceManager extends MultiplexingCacheInstanceManager { private static final Logger log = LoggerFactory.getLogger(JndiMultiplexingCacheInstanceManager.class); /** * Specifies the JNDI name under which the {@link CacheManager} to use is bound. * There is no default value -- the user must specify the property. */ public static final String CACHE_FACTORY_RESOURCE_PROP = "hibernate.cache.region.jbc2.cachefactory"; /** * Create a new JndiMultiplexingCacheInstanceManager. */ public JndiMultiplexingCacheInstanceManager() { super(); } @Override public void start(Settings settings, Properties properties) throws CacheException { String name = PropertiesHelper.getString(CACHE_FACTORY_RESOURCE_PROP, properties, null); if (name == null) throw new CacheException("Configuration property " + CACHE_FACTORY_RESOURCE_PROP + " not set"); CacheManager cf = locateCacheFactory( name, NamingHelper.getJndiProperties( properties ) ); setCacheFactory( cf ); super.start(settings, properties); } private CacheManager locateCacheFactory(String jndiNamespace, Properties jndiProperties) { Context ctx = null; try { ctx = new InitialContext( jndiProperties ); return (CacheManager) ctx.lookup( jndiNamespace ); } catch (NamingException ne) { String msg = "Unable to retreive Cache from JNDI [" + jndiNamespace + "]"; log.info( msg, ne ); throw new CacheException( msg ); } finally { if ( ctx != null ) { try { ctx.close(); } catch( NamingException ne ) { log.info( "Unable to release initial context", ne ); } } } } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/SharedCacheInstanceManager.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/SharedCacheI0000644000000000000000000002310111652065432030071 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.builder; import java.util.Properties; import javax.transaction.TransactionManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.jboss.cache.Cache; import org.jboss.cache.CacheStatus; import org.jboss.cache.DefaultCacheFactory; import org.jboss.cache.config.Configuration; import org.jgroups.ChannelFactory; import org.jgroups.JChannelFactory; import org.hibernate.cache.CacheException; import org.hibernate.cache.jbc.CacheInstanceManager; import org.hibernate.cache.jbc.util.CacheHelper; import org.hibernate.cfg.Settings; import org.hibernate.util.PropertiesHelper; /** * A {@link CacheInstanceManager} implementation where we use a single JBoss Cache * instance for each type of region. If operating on a cluster, the cache must * be configured for REPL_SYNC if query caching is enabled. If query caching * is not used, REPL_SYNC or INVALIDATION_SYNC are valid, with * INVALIDATION_SYNC preferred. * * @author Steve Ebersole * @author Brian Stansberry */ public class SharedCacheInstanceManager implements CacheInstanceManager { private static final Logger log = LoggerFactory.getLogger(SharedCacheInstanceManager.class); /** * Classpath or filesystem resource containing JBoss Cache * configuration settings the {@link Cache} should use. * * @see #DEFAULT_CACHE_RESOURCE */ public static final String CACHE_RESOURCE_PROP = "hibernate.cache.jbc.cfg.shared"; /** * Legacy name for configuration property {@link #CACHE_RESOURCE_PROP}. * * @see #DEFAULT_CACHE_RESOURCE */ public static final String LEGACY_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.shared"; /** * Default name for the JBoss Cache configuration file. */ public static final String DEFAULT_CACHE_RESOURCE = "treecache.xml"; /** * Classpath or filesystem resource containing JGroups protocol * stack configurations the org.jgroups.ChannelFactory * should use. * * @see #DEF_JGROUPS_RESOURCE */ public static final String CHANNEL_FACTORY_RESOURCE_PROP = "hibernate.cache.jbc.cfg.jgroups.stacks"; /** * Legacy name for configuration property {@link #CHANNEL_FACTORY_RESOURCE_PROP}. * * @see #DEF_JGROUPS_RESOURCE */ public static final String LEGACY_CHANNEL_FACTORY_RESOURCE_PROP = "hibernate.cache.region.jbc2.cfg.jgroups.stacks"; /** * Default value for {@link #CHANNEL_FACTORY_RESOURCE_PROP}. Specifies * the "jgroups-stacks.xml" file in this package. */ public static final String DEF_JGROUPS_RESOURCE = "org/hibernate/cache/jbc/builder/jgroups-stacks.xml"; private Cache cache; private ChannelFactory channelFactory; private boolean use2ndLevel; private boolean useQuery; public SharedCacheInstanceManager() { } public SharedCacheInstanceManager(ChannelFactory channelFactory) { this.channelFactory = channelFactory; } public SharedCacheInstanceManager(Cache cache) { this.cache = cache; } /** * {@inheritDoc} */ public Cache getEntityCacheInstance() { return use2ndLevel ? cache : null; } /** * {@inheritDoc} */ public Cache getCollectionCacheInstance() { return use2ndLevel ? cache : null; } /** * {@inheritDoc} */ public Cache getQueryCacheInstance() { if (!useQuery) return null; if (CacheHelper.isClusteredInvalidation(cache)) { throw new CacheException("Query cache not supported for clustered invalidation"); } return cache; } /** * {@inheritDoc} */ public void start(Settings settings, Properties properties) throws CacheException { use2ndLevel = settings.isSecondLevelCacheEnabled(); useQuery = settings.isQueryCacheEnabled(); if (cache == null) { if (channelFactory == null) { String muxStacks = PropertiesHelper.getString(CHANNEL_FACTORY_RESOURCE_PROP, properties, null); if (muxStacks == null) { PropertiesHelper.getString(LEGACY_CHANNEL_FACTORY_RESOURCE_PROP, properties, DEF_JGROUPS_RESOURCE); } if (muxStacks != null) { channelFactory = new JChannelFactory(); try { channelFactory.setMultiplexerConfig(muxStacks); } catch (Exception e) { throw new CacheException("Problem setting ChannelFactory config", e); } } } cache = createSharedCache(settings, properties); configureTransactionManager(cache, settings, properties); if (cache.getConfiguration().getMultiplexerStack() != null && cache.getConfiguration().getRuntimeConfig().getMuxChannelFactory() == null) { cache.getConfiguration().getRuntimeConfig().setMuxChannelFactory(channelFactory); } } cache.start(); } /** * {@inheritDoc} */ public Cache getTimestampsCacheInstance() { if (!useQuery) return null; if (CacheHelper.isClusteredInvalidation(cache)) { throw new CacheException("Query cache not supported for clustered invalidation"); } return cache; } /** * {@inheritDoc} */ public void stop() { if (cache != null) { stopSharedCache(cache); } } /** * Create a cache using the given settings and properties. * * @param settings The Hibernate settings * @param properties The configuration properties * @return The created cache */ protected Cache createSharedCache(Settings settings, Properties properties) { String configResource = PropertiesHelper.getString(CACHE_RESOURCE_PROP, properties, null); if (configResource == null) { configResource = PropertiesHelper.getString(LEGACY_CACHE_RESOURCE_PROP, properties, DEFAULT_CACHE_RESOURCE); } return new DefaultCacheFactory().createCache(configResource, false); } /** * Injects the TransactionManager found via {@link Settings#getTransactionManagerLookup()} * into the cache. * * @param cache The cache instance * @param settings The Hibernate settings * @param properties The configuration properties * * @throws CacheException if cache is already started and is * configured with a different TransactionManager * than the one we would inject */ protected void configureTransactionManager(Cache cache, Settings settings, Properties properties) { TransactionManager tm = null; if (settings.getTransactionManagerLookup() != null) { tm = settings.getTransactionManagerLookup().getTransactionManager(properties); } Configuration cacheConfig = cache.getConfiguration(); TransactionManager cacheTm = cacheConfig.getRuntimeConfig().getTransactionManager(); if (!safeEquals(tm, cacheTm)) { if (cache.getCacheStatus() != CacheStatus.INSTANTIATED && cache.getCacheStatus() != CacheStatus.DESTROYED) { log.debug("JBoss Cache is already started with a transaction manager (" + cacheTm + ") that is not equal to our own (" + tm + ")"); } else { // Configure the cache to use our TM cacheConfig.getRuntimeConfig().setTransactionManager(tm); if (tm == null) { // Make sure JBC doesn't look one up cacheConfig.setTransactionManagerLookupClass(null); } } } } private boolean safeEquals(Object a, Object b) { return (a == b || (a != null && a.equals(b))); } /** * Stops the shared cache. * @param cache the shared cache */ protected void stopSharedCache(Cache cache) { try { if (cache.getCacheStatus() == CacheStatus.STARTED) { cache.stop(); } if (cache.getCacheStatus() != CacheStatus.DESTROYED && cache.getCacheStatus() != CacheStatus.INSTANTIATED) { cache.destroy(); } } catch (Throwable t) { log.warn("Unable to stop cache instance", t); } } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/jbc-configs.xmllibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/jbc-configs.0000644000000000000000000014344511652065432030106 0ustar  OPTIMISTIC INVALIDATION_SYNC optimistic-entity udp false 20000 20000 15000 false true true 0 5 org.jboss.cache.eviction.LRUPolicy 10000 1000 120 PESSIMISTIC READ_COMMITTED INVALIDATION_SYNC pessimistic-entity udp false 20000 20000 15000 false true true 0 5 org.jboss.cache.eviction.LRUPolicy 10000 1000 120 MVCC READ_COMMITTED INVALIDATION_SYNC mvcc-entity udp false 20000 20000 15000 false true true 0 5 org.jboss.cache.eviction.LRUPolicy 10000 1000 120 PESSIMISTIC REPEATABLE_READ INVALIDATION_SYNC pessimistic-entity-rr udp false 20000 20000 15000 false true true 0 5 org.jboss.cache.eviction.LRUPolicy 10000 1000 120 MVCC REPEATABLE_READ INVALIDATION_SYNC mvcc-entity-rr udp false 20000 20000 15000 false true true 0 5 org.jboss.cache.eviction.LRUPolicy 10000 1000 120 OPTIMISTIC LOCAL 15000 false 5 org.jboss.cache.eviction.LRUPolicy 10000 1000 120 OPTIMISTIC REPL_ASYNC replicated-query udp false 20000 20000 15000 false true true 0 5 org.jboss.cache.eviction.LRUPolicy 10000 1000 120 MVCC READ_COMMITTED REPL_ASYNC timestamp-cache udp true 20000 20000 15000 false true true 0 5 org.jboss.cache.eviction.LRUPolicy 10000 1000 120 OPTIMISTIC REPL_SYNC true true optimistic-shared udp true 20000 20000 15000 false true true 0 5 org.jboss.cache.eviction.LRUPolicy 10000 1000 120 PESSIMISTIC READ_COMMITTED REPL_SYNC pessimistic-shared udp true 20000 20000 15000 false true true 0 5 org.jboss.cache.eviction.LRUPolicy 10000 1000 120 MVCC READ_COMMITTED REPL_SYNC true mvcc-shared udp true 20000 20000 15000 false true true 0 5 org.jboss.cache.eviction.LRUPolicy 10000 1000 120 PESSIMISTIC REPEATABLE_READ REPL_SYNC pessimistic-shared-rr udp true 20000 20000 15000 false true true 0 5 org.jboss.cache.eviction.LRUPolicy 10000 1000 120 MVCC REPEATABLE_READ REPL_SYNC true mvcc-shared-rr udp true 20000 20000 15000 false true true 0 5 org.jboss.cache.eviction.LRUPolicy 10000 1000 120 ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/jgroups-stacks.xmllibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/jgroups-stac0000644000000000000000000003355511652065432030265 0ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/access/0000755000000000000000000000000011675734517025535 5ustar ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/access/PutFromLoadValidator.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/access/PutFromLoadVa0000644000000000000000000005407111652065432030136 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2009, Red Hat, Inc or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.access; import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import javax.transaction.SystemException; import javax.transaction.Transaction; import javax.transaction.TransactionManager; import org.hibernate.cache.CacheException; /** * Encapsulates logic to allow a {@link TransactionalAccessDelegate} to determine * whether a {@link TransactionalAccessDelegate#putFromLoad(Object, Object, long, Object, boolean) * call should be allowed to update the cache. A putFromLoad has * the potential to store stale data, since the data may have been removed from the * database and the cache between the time when the data was read from the database * and the actual call to putFromLoad. *

* The expected usage of this class by a thread that read the cache and did * not find data is: * *

    *
  1. Call {@link #registerPendingPut(Object)}
  2. *
  3. Read the database
  4. *
  5. Call {@link #acquirePutFromLoadLock(Object)} *
  6. if above returns false, the thread should not cache the data; * only if above returns true, put data in the cache and...
  7. *
  8. then call {@link #releasePutFromLoadLock(Object)}
  9. *
*

* *

* The expected usage by a thread that is taking an action such that any pending * putFromLoad may have stale data and should not cache it is to either * call * *

*

* *

* This class also supports the concept of "naked puts", which are calls to * {@link #acquirePutFromLoadLock(Object)} without a preceding {@link #registerPendingPut(Object)} * call. *

* * @author Brian Stansberry * * @version $Revision: $ */ public class PutFromLoadValidator { /** * Period in ms after a removal during which a call to * {@link #acquirePutFromLoadLock(Object)} that hasn't been * {@link #registerPendingPut(Object) pre-registered} (aka a "naked put") * will return false. */ public static final long NAKED_PUT_INVALIDATION_PERIOD = 20 * 1000; /** Period (in ms) after which a pending put is placed in the over-age queue */ private static final long PENDING_PUT_OVERAGE_PERIOD = 5 * 1000; /** Period (in ms) before which we stop trying to clean out pending puts */ private static final long PENDING_PUT_RECENT_PERIOD = 2 * 1000; /** * Period (in ms) after which a pending put is never expected to come in * and should be cleaned */ private static final long MAX_PENDING_PUT_DELAY = 2 * 60 * 1000; /** * Used to determine whether the owner of a pending put is a thread or a * transaction */ private final TransactionManager transactionManager; private final long nakedPutInvalidationPeriod; private final long pendingPutOveragePeriod; private final long pendingPutRecentPeriod; private final long maxPendingPutDelay; /** * Registry of expected, future, isPutValid calls. If a key+owner is * registered in this map, it is not a "naked put" and is allowed to * proceed. */ private final ConcurrentMap pendingPuts = new ConcurrentHashMap(); /** * List of pending puts. Used to ensure we don't leak memory via the * pendingPuts map */ private final List> pendingQueue = new LinkedList>(); /** * Separate list of pending puts that haven't been resolved within * PENDING_PUT_OVERAGE_PERIOD. Used to ensure we don't leak memory via the * pendingPuts map. Tracked separately from more recent pending puts for * efficiency reasons. */ private final List> overagePendingQueue = new LinkedList>(); /** Lock controlling access to pending put queues */ private final Lock pendingLock = new ReentrantLock(); private final ConcurrentMap recentRemovals = new ConcurrentHashMap(); /** * List of recent removals. Used to ensure we don't leak memory via the * recentRemovals map */ private final List removalsQueue = new LinkedList(); /** * The time when the first element in removalsQueue will expire. No reason * to do housekeeping on the queue before this time. */ private volatile long earliestRemovalTimestamp; /** Lock controlling access to removalsQueue */ private final Lock removalsLock = new ReentrantLock(); /** * The time of the last call to regionRemoved(), plus * NAKED_PUT_INVALIDATION_PERIOD. All naked puts will be rejected until the * current time is greater than this value. */ private volatile long invalidationTimestamp; /** * Creates a new PutFromLoadValidator. * * @param transactionManager * transaction manager to use to associate changes with a * transaction; may be null */ public PutFromLoadValidator(TransactionManager transactionManager) { this(transactionManager, NAKED_PUT_INVALIDATION_PERIOD, PENDING_PUT_OVERAGE_PERIOD, PENDING_PUT_RECENT_PERIOD, MAX_PENDING_PUT_DELAY); } /** * Constructor variant for use by unit tests; allows control of various * timeouts by the test. */ protected PutFromLoadValidator(TransactionManager transactionManager, long nakedPutInvalidationPeriod, long pendingPutOveragePeriod, long pendingPutRecentPeriod, long maxPendingPutDelay) { this.transactionManager = transactionManager; this.nakedPutInvalidationPeriod = nakedPutInvalidationPeriod; this.pendingPutOveragePeriod = pendingPutOveragePeriod; this.pendingPutRecentPeriod = pendingPutRecentPeriod; this.maxPendingPutDelay = maxPendingPutDelay; } // ----------------------------------------------------------------- Public /** * Acquire a lock giving the calling thread the right to put data in the * cache for the given key. *

* NOTE: A call to this method that returns true * should always be matched with a call to {@link #releasePutFromLoadLock(Object)}. *

* * @param key the key * * @return true if the lock is acquired and the cache put * can proceed; false if the data should not be cached */ public boolean acquirePutFromLoadLock(Object key) { boolean valid = false; boolean locked = false; long now = System.currentTimeMillis(); // Important: Do cleanup before we acquire any locks so we // don't deadlock with invalidateRegion cleanOutdatedPendingPuts(now, true); try { PendingPutMap pending = pendingPuts.get(key); if (pending != null) { locked = pending.acquireLock(100, TimeUnit.MILLISECONDS); if (locked) { try { PendingPut toCancel = pending.remove(getOwnerForPut()); if (toCancel != null) { valid = !toCancel.completed; toCancel.completed = true; } } finally { if (!valid) { pending.releaseLock(); locked = false; } } } } else { // Key wasn't in pendingPuts, so either this is a "naked put" // or regionRemoved has been called. Check if we can proceed if (now > invalidationTimestamp) { Long removedTime = recentRemovals.get(key); if (removedTime == null || now > removedTime.longValue()) { // It's legal to proceed. But we have to record this key // in pendingPuts so releasePutFromLoadLock can find it. // To do this we basically simulate a normal "register // then acquire lock" pattern registerPendingPut(key); locked = acquirePutFromLoadLock(key); valid = locked; } } } } catch (Throwable t) { valid = false; if (locked) { PendingPutMap toRelease = pendingPuts.get(key); if (toRelease != null) { toRelease.releaseLock(); } } if (t instanceof RuntimeException) { throw (RuntimeException) t; } else if (t instanceof Error) { throw (Error) t; } else { throw new RuntimeException(t); } } return valid; } /** * Releases the lock previously obtained by a call to * {@link #acquirePutFromLoadLock(Object)} that returned true. * * @param key the key */ public void releasePutFromLoadLock(Object key) { PendingPutMap pending = pendingPuts.get(key); if (pending != null) { if (pending.size() == 0) { pendingPuts.remove(key); } pending.releaseLock(); } } /** * Invalidates any {@link #registerPendingPut(Object) previously registered pending puts} * ensuring a subsequent call to {@link #acquirePutFromLoadLock(Object)} will * return false. *

* This method will block until any concurrent thread that has * {@link #acquirePutFromLoadLock(Object) acquired the putFromLoad lock} for * the given key has released the lock. This allows the caller to be certain * the putFromLoad will not execute after this method returns, possibly * caching stale data. *

* * @param key key identifying data whose pending puts should be invalidated * * @return true if the invalidation was successful; false * if a problem occured (which the caller should treat as an * exception condition) */ public boolean invalidateKey(Object key) { boolean success = true; // Invalidate any pending puts PendingPutMap pending = pendingPuts.get(key); if (pending != null) { // This lock should be available very quickly, but we'll be // very patient waiting for it as callers should treat not // acquiring it as an exception condition if (pending.acquireLock(60, TimeUnit.SECONDS)) { try { pending.invalidate(); } finally { pending.releaseLock(); } } else { success = false; } } // Record when this occurred to invalidate later naked puts RecentRemoval removal = new RecentRemoval(key, this.nakedPutInvalidationPeriod); recentRemovals.put(key, removal.timestamp); // Don't let recentRemovals map become a memory leak RecentRemoval toClean = null; boolean attemptClean = removal.timestamp.longValue() > earliestRemovalTimestamp; removalsLock.lock(); try { removalsQueue.add(removal); if (attemptClean) { if (removalsQueue.size() > 1) { // we have at least one as we // just added it toClean = removalsQueue.remove(0); } earliestRemovalTimestamp = removalsQueue.get(0).timestamp .longValue(); } } finally { removalsLock.unlock(); } if (toClean != null) { Long cleaned = recentRemovals.get(toClean.key); if (cleaned != null && cleaned.equals(toClean.timestamp)) { cleaned = recentRemovals.remove(toClean.key); if (cleaned != null && cleaned.equals(toClean.timestamp) == false) { // Oops; removed the wrong timestamp; restore it recentRemovals.putIfAbsent(toClean.key, cleaned); } } } return success; } /** * Invalidates all {@link #registerPendingPut(Object) previously registered pending puts} * ensuring a subsequent call to {@link #acquirePutFromLoadLock(Object)} will * return false. *

* This method will block until any concurrent thread that has * {@link #acquirePutFromLoadLock(Object) acquired the putFromLoad lock} for * the any key has released the lock. This allows the caller to be certain * the putFromLoad will not execute after this method returns, possibly * caching stale data. *

* * @return true if the invalidation was successful; false * if a problem occured (which the caller should treat as an * exception condition) */ public boolean invalidateRegion() { boolean ok = false; invalidationTimestamp = System.currentTimeMillis() + this.nakedPutInvalidationPeriod; try { // Acquire the lock for each entry to ensure any ongoing // work associated with it is completed before we return for (PendingPutMap entry : pendingPuts.values()) { if (entry.acquireLock(60, TimeUnit.SECONDS)) { try { entry.invalidate(); } finally { entry.releaseLock(); } } else { ok = false; } } removalsLock.lock(); try { recentRemovals.clear(); removalsQueue.clear(); ok = true; } finally { removalsLock.unlock(); } } catch (Exception e) { ok = false; } finally { earliestRemovalTimestamp = invalidationTimestamp; } return ok; } /** * Notifies this validator that it is expected that a database read followed * by a subsequent {@link #acquirePutFromLoadLock(Object)} call will occur. The intent * is this method would be called following a cache miss wherein it is * expected that a database read plus cache put will occur. Calling this * method allows the validator to treat the subsequent * acquirePutFromLoadLock as if the database read occurred when this method * was invoked. This allows the validator to compare the timestamp of this * call against the timestamp of subsequent removal notifications. A put * that occurs without this call preceding it is "naked"; i.e the validator * must assume the put is not valid if any relevant removal has occurred * within {@link #NAKED_PUT_INVALIDATION_PERIOD} milliseconds. * * @param key key that will be used for subsequent cache put */ public void registerPendingPut(Object key) { PendingPut pendingPut = new PendingPut(key, getOwnerForPut()); PendingPutMap pendingForKey = new PendingPutMap(pendingPut); for (;;) { PendingPutMap existing = pendingPuts.putIfAbsent(key, pendingForKey); if (existing != null) { if (existing.acquireLock(10, TimeUnit.SECONDS)) { try { existing.put(pendingPut); PendingPutMap doublecheck = pendingPuts.putIfAbsent( key, existing); if (doublecheck == null || doublecheck == existing) { break; } // else we hit a race and need to loop to try again } finally { existing.releaseLock(); } } else { // Can't get the lock; when we come back we'll be a "naked put" break; } } else { // normal case break; } } // Guard against memory leaks preventOutdatedPendingPuts(pendingPut); } // -------------------------------------------------------------- Protected /** Only for use by unit tests; may be removed at any time */ protected int getPendingPutQueueLength() { pendingLock.lock(); try { return pendingQueue.size(); } finally { pendingLock.unlock(); } } /** Only for use by unit tests; may be removed at any time */ protected int getOveragePendingPutQueueLength() { pendingLock.lock(); try { return overagePendingQueue.size(); } finally { pendingLock.unlock(); } } /** Only for use by unit tests; may be removed at any time */ protected int getRemovalQueueLength() { removalsLock.lock(); try { return removalsQueue.size(); } finally { removalsLock.unlock(); } } // ---------------------------------------------------------------- Private private Object getOwnerForPut() { Transaction tx = null; try { if (transactionManager != null) { tx = transactionManager.getTransaction(); } } catch (SystemException se) { throw new CacheException("Could not obtain transaction", se); } return tx == null ? Thread.currentThread() : tx; } private void preventOutdatedPendingPuts(PendingPut pendingPut) { pendingLock.lock(); try { pendingQueue.add(new WeakReference(pendingPut)); if (pendingQueue.size() > 1) { cleanOutdatedPendingPuts(pendingPut.timestamp, false); } } finally { pendingLock.unlock(); } } private void cleanOutdatedPendingPuts(long now, boolean lock) { PendingPut toClean = null; if (lock) { pendingLock.lock(); } try { // Clean items out of the basic queue long overaged = now - this.pendingPutOveragePeriod; long recent = now - this.pendingPutRecentPeriod; int pos = 0; while (pendingQueue.size() > pos) { WeakReference ref = pendingQueue.get(pos); PendingPut item = ref.get(); if (item == null || item.completed) { pendingQueue.remove(pos); } else if (item.timestamp < overaged) { // Potential leak; move to the overaged queued pendingQueue.remove(pos); overagePendingQueue.add(ref); } else if (item.timestamp >= recent) { // Don't waste time on very recent items break; } else if (pos > 2) { // Don't spend too much time getting nowhere break; } else { // Move on to the next item pos++; } } // Process the overage queue until we find an item to clean // or an incomplete item that hasn't aged out long mustCleanTime = now - this.maxPendingPutDelay; while (overagePendingQueue.size() > 0) { WeakReference ref = overagePendingQueue.get(0); PendingPut item = ref.get(); if (item == null || item.completed) { overagePendingQueue.remove(0); } else { if (item.timestamp < mustCleanTime) { overagePendingQueue.remove(0); toClean = item; } break; } } } finally { if (lock) { pendingLock.unlock(); } } // We've found a pendingPut that never happened; clean it up if (toClean != null) { PendingPutMap map = pendingPuts.get(toClean.key); if (map != null) { if (map.acquireLock(100, TimeUnit.MILLISECONDS)) { try { PendingPut cleaned = map.remove(toClean.owner); if (toClean.equals(cleaned) == false) { // Oops. Restore it. map.put(cleaned); } else if (map.size() == 0) { pendingPuts.remove(toClean.key); } } finally { map.releaseLock(); } } else { // Something's gone wrong and the lock isn't being released. // We removed toClean from the queue and need to restore it // TODO this is pretty dodgy restorePendingPut(toClean); } } } } private void restorePendingPut(PendingPut toRestore) { pendingLock.lock(); try { // Give it a new lease on life so it's not out of order. We could // scan the queue and put toRestore back at the front, but then // we'll just immediately try removing it again; instead we // let it cycle through the queue again toRestore.refresh(); pendingQueue.add(new WeakReference(toRestore)); } finally { pendingLock.unlock(); } } /** * Lazy-initialization map for PendingPut. Optimized for the expected usual * case where only a single put is pending for a given key. * * This class is NOT THREAD SAFE. All operations on it must be performed * with the lock held. */ private static class PendingPutMap { private PendingPut singlePendingPut; private Map fullMap; private final Lock lock = new ReentrantLock(); PendingPutMap(PendingPut singleItem) { this.singlePendingPut = singleItem; } public void put(PendingPut pendingPut) { if (singlePendingPut == null) { if (fullMap == null) { // initial put singlePendingPut = pendingPut; } else { fullMap.put(pendingPut.owner, pendingPut); } } else { // 2nd put; need a map fullMap = new HashMap(4); fullMap.put(singlePendingPut.owner, singlePendingPut); singlePendingPut = null; fullMap.put(pendingPut.owner, pendingPut); } } public PendingPut remove(Object ownerForPut) { PendingPut removed = null; if (fullMap == null) { if (singlePendingPut != null && singlePendingPut.owner.equals(ownerForPut)) { removed = singlePendingPut; singlePendingPut = null; } } else { removed = fullMap.remove(ownerForPut); } return removed; } public int size() { return fullMap == null ? (singlePendingPut == null ? 0 : 1) : fullMap.size(); } public boolean acquireLock(long time, TimeUnit unit) { try { return lock.tryLock(time, unit); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return false; } } public void releaseLock() { lock.unlock(); } public void invalidate() { if (singlePendingPut != null) { singlePendingPut.completed = true; } else if (fullMap != null) { for (PendingPut pp : fullMap.values()) { pp.completed = true; } } } } private static class PendingPut { private final Object key; private final Object owner; private long timestamp = System.currentTimeMillis(); private volatile boolean completed; private PendingPut(Object key, Object owner) { this.key = key; this.owner = owner; } private void refresh() { timestamp = System.currentTimeMillis(); } } private static class RecentRemoval { private final Object key; private final Long timestamp; private RecentRemoval(Object key, long nakedPutInvalidationPeriod) { this.key = key; timestamp = Long.valueOf(System.currentTimeMillis() + nakedPutInvalidationPeriod); } } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/access/TransactionalAccessDelegate.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/access/Transactional0000644000000000000000000001662011652065432030253 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.access; import javax.transaction.Transaction; import org.hibernate.cache.CacheException; import org.hibernate.cache.access.CollectionRegionAccessStrategy; import org.hibernate.cache.access.EntityRegionAccessStrategy; import org.hibernate.cache.access.SoftLock; import org.hibernate.cache.jbc.BasicRegionAdapter; import org.hibernate.cache.jbc.util.CacheHelper; import org.jboss.cache.Cache; import org.jboss.cache.Fqn; import org.jboss.cache.config.Option; /** * Defines the strategy for transactional access to entity or collection data in * a pessimistic-locking JBoss Cache using its 2.x APIs. *

* The intent of this class is to encapsulate common code and serve as a * delegate for {@link EntityRegionAccessStrategy} and * {@link CollectionRegionAccessStrategy} implementations. *

* * @author Brian Stansberry */ public class TransactionalAccessDelegate { protected final Cache cache; protected final Fqn regionFqn; protected final boolean invalidation; protected final BasicRegionAdapter region; protected final PutFromLoadValidator putValidator; public TransactionalAccessDelegate(BasicRegionAdapter adapter, PutFromLoadValidator validator) { this.region = adapter; this.cache = adapter.getCacheInstance(); this.regionFqn = adapter.getRegionFqn(); this.putValidator = validator; this.invalidation = CacheHelper.isClusteredInvalidation(this.cache); } public Object get(Object key, long txTimestamp) throws CacheException { if (!region.checkValid()) return null; region.ensureRegionRootExists(); Object val = CacheHelper.get(cache, regionFqn, key); if (val == null) { putValidator.registerPendingPut(key); } return val; } public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { if (!region.checkValid()) return false; if (!putValidator.acquirePutFromLoadLock(key)) return false; try { region.ensureRegionRootExists(); return CacheHelper.putForExternalRead(cache, regionFqn, key, value); } finally { putValidator.releasePutFromLoadLock(key); } } public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { if (!region.checkValid()) return false; if (!putValidator.acquirePutFromLoadLock(key)) return false; try { region.ensureRegionRootExists(); // We ignore minimalPutOverride. JBossCache putForExternalRead is // already about as minimal as we can get; it will promptly return // if it discovers that the node we want to write to already exists return CacheHelper.putForExternalRead(cache, regionFqn, key, value); } finally { putValidator.releasePutFromLoadLock(key); } } public SoftLock lockItem(Object key, Object version) throws CacheException { return null; } public SoftLock lockRegion() throws CacheException { return null; } public void unlockItem(Object key, SoftLock lock) throws CacheException { } public void unlockRegion(SoftLock lock) throws CacheException { } public boolean insert(Object key, Object value, Object version) throws CacheException { if (!region.checkValid()) return false; region.ensureRegionRootExists(); if (invalidation) { Option opt = new Option(); opt.setCacheModeLocal(true); CacheHelper.put(cache, regionFqn, key, value, opt); } else { CacheHelper.put(cache, regionFqn, key, value); } return true; } public boolean afterInsert(Object key, Object value, Object version) throws CacheException { return false; } public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { // We update whether or not the region is valid. Other nodes // may have already restored the region so they need to // be informed of the change. region.ensureRegionRootExists(); CacheHelper.put(cache, regionFqn, key, value); return true; } public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { return false; } public void remove(Object key) throws CacheException { if (!putValidator.invalidateKey(key)) { throw new CacheException("Failed to invalidate pending putFromLoad calls for key " + key + " from region " + region.getName()); } // We remove whether or not the region is valid. Other nodes // may have already restored the region so they need to // be informed of the change. region.ensureRegionRootExists(); CacheHelper.remove(cache, regionFqn, key); } public void removeAll() throws CacheException { if (!putValidator.invalidateRegion()) { throw new CacheException("Failed to invalidate pending putFromLoad calls for region " + region.getName()); } CacheHelper.removeAll(cache, regionFqn); } public void evict(Object key) throws CacheException { if (!putValidator.invalidateKey(key)) { throw new CacheException("Failed to invalidate pending putFromLoad calls for key " + key + " from region " + region.getName()); } region.ensureRegionRootExists(); CacheHelper.remove(cache, regionFqn, key); } public void evictAll() throws CacheException { if (!putValidator.invalidateRegion()) { throw new CacheException("Failed to invalidate pending putFromLoad calls for region " + region.getName()); } Transaction tx = region.suspend(); try { region.ensureRegionRootExists(); CacheHelper.sendEvictAllNotification(cache, regionFqn, region.getMemberId(), null); } finally { region.resume(tx); } } } ././@LongLink0000000000000000000000000000020200000000000011557 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/access/OptimisticTransactionalAccessDelegate.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/access/OptimisticTra0000644000000000000000000001746211652065432030251 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc.access; import javax.transaction.Transaction; import org.hibernate.cache.CacheDataDescription; import org.hibernate.cache.CacheException; import org.hibernate.cache.access.CollectionRegionAccessStrategy; import org.hibernate.cache.access.EntityRegionAccessStrategy; import org.hibernate.cache.jbc.TransactionalDataRegionAdapter; import org.hibernate.cache.jbc.util.CacheHelper; import org.hibernate.cache.jbc.util.DataVersionAdapter; import org.hibernate.cache.jbc.util.NonLockingDataVersion; import org.jboss.cache.config.Option; /** * Defines the strategy for transactional access to entity or collection data in * an optimistic-locking JBoss Cache using its 2.x APIs. *

* The intent of this class is to encapsulate common code and serve as a * delegate for {@link EntityRegionAccessStrategy} and * {@link CollectionRegionAccessStrategy} implementations. *

* * @author Brian Stansberry * @version $Revision: 1 $ */ public class OptimisticTransactionalAccessDelegate extends TransactionalAccessDelegate { protected final CacheDataDescription dataDescription; public OptimisticTransactionalAccessDelegate(TransactionalDataRegionAdapter region, PutFromLoadValidator validator) { super(region, validator); this.dataDescription = region.getCacheDataDescription(); } /** * Overrides the * {@link TransactionalAccessDelegate#evict(Object) superclass} by adding a * {@link NonLockingDataVersion} to the invocation. */ @Override public void evict(Object key) throws CacheException { if (!putValidator.invalidateKey(key)) { throw new CacheException("Failed to invalidate pending putFromLoad calls for key " + key + " from region " + region.getName()); } region.ensureRegionRootExists(); Option opt = NonLockingDataVersion.getInvocationOption(); CacheHelper.remove(cache, regionFqn, key, opt); } @Override public void evictAll() throws CacheException { if (!putValidator.invalidateRegion()) { throw new CacheException("Failed to invalidate pending putFromLoad calls for region " + region.getName()); } Transaction tx = region.suspend(); try { region.ensureRegionRootExists(); Option opt = NonLockingDataVersion.getInvocationOption(); CacheHelper.sendEvictAllNotification(cache, regionFqn, region.getMemberId(), opt); } finally { region.resume(tx); } } /** * Overrides the * {@link TransactionalAccessDelegate#insert(Object, Object, Object) superclass} * by adding a {@link DataVersion} to the invocation. */ @Override public boolean insert(Object key, Object value, Object version) throws CacheException { if (!region.checkValid()) return false; region.ensureRegionRootExists(); Option opt = getDataVersionOption(version, null); if (this.invalidation) { opt.setCacheModeLocal(true); } CacheHelper.put(cache, regionFqn, key, value, opt); return true; } @Override public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { if (!region.checkValid()) return false; if (!putValidator.acquirePutFromLoadLock(key)) return false; try { region.ensureRegionRootExists(); // We ignore minimalPutOverride. JBossCache putForExternalRead is // already about as minimal as we can get; it will promptly return // if it discovers that the node we want to write to already exists Option opt = getDataVersionOption(version, version); return CacheHelper.putForExternalRead(cache, regionFqn, key, value, opt); } finally { putValidator.releasePutFromLoadLock(key); } } @Override public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { if (!region.checkValid()) return false; if (!putValidator.acquirePutFromLoadLock(key)) return false; try { region.ensureRegionRootExists(); Option opt = getDataVersionOption(version, version); return CacheHelper.putForExternalRead(cache, regionFqn, key, value, opt); } finally { putValidator.releasePutFromLoadLock(key); } } @Override public void remove(Object key) throws CacheException { if (!putValidator.invalidateKey(key)) { throw new CacheException("Failed to invalidate pending putFromLoad calls for key " + key + " from region " + region.getName()); } // We remove whether or not the region is valid. Other nodes // may have already restored the region so they need to // be informed of the change. region.ensureRegionRootExists(); Option opt = NonLockingDataVersion.getInvocationOption(); CacheHelper.remove(cache, regionFqn, key, opt); } @Override public void removeAll() throws CacheException { if (!putValidator.invalidateRegion()) { throw new CacheException("Failed to invalidate pending putFromLoad calls for region " + region.getName()); } Option opt = NonLockingDataVersion.getInvocationOption(); CacheHelper.removeAll(cache, regionFqn, opt); } @Override public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { // We update whether or not the region is valid. Other nodes // may have already restored the region so they need to // be informed of the change. region.ensureRegionRootExists(); Option opt = getDataVersionOption(currentVersion, previousVersion); CacheHelper.put(cache, regionFqn, key, value, opt); return true; } @SuppressWarnings("deprecation") private Option getDataVersionOption(Object currentVersion, Object previousVersion) { org.jboss.cache.optimistic.DataVersion dv = (dataDescription != null && dataDescription.isVersioned()) ? new DataVersionAdapter( currentVersion, previousVersion, dataDescription.getVersionComparator(), dataDescription.toString()) : NonLockingDataVersion.INSTANCE; Option opt = new Option(); opt.setDataVersion(dv); return opt; } } ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/JndiSharedJBossCacheRegionFactory.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/JndiSharedJBossCache0000644000000000000000000000444211652065432030107 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc; import java.util.Properties; import org.hibernate.cache.jbc.builder.JndiSharedCacheInstanceManager; /** * {@link JBossCacheRegionFactory} that uses * {@link JndiSharedCacheInstanceManager} as its * {@link #getCacheInstanceManager() CacheInstanceManager}. *

* Basically, uses a single shared JBoss Cache for entities, collections, * queries and timestamps. The JBoss Cache instance is found in JNDI * using the value of the {@link JndiSharedCacheInstanceManager#CACHE_RESOURCE_PROP} * configuration property as the name to look up. *

* * @deprecated Favor Infinispan integration; see HHH-5489 for details. * * @author Brian Stansberry * @version $Revision$ */ @Deprecated public class JndiSharedJBossCacheRegionFactory extends JBossCacheRegionFactory { /** * FIXME Per the RegionFactory class Javadoc, this constructor version * should not be necessary. * * @param props The configuration properties */ public JndiSharedJBossCacheRegionFactory(Properties props) { this(); } /** * Create a new MultiplexedJBossCacheRegionFactory. * */ public JndiSharedJBossCacheRegionFactory() { super(new JndiSharedCacheInstanceManager()); } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/MultiplexedJBossCacheRegionFactory.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/MultiplexedJBossCach0000644000000000000000000000471711652065432030230 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc; import java.util.Properties; import org.hibernate.cache.jbc.builder.MultiplexingCacheInstanceManager; /** * {@link JBossCacheRegionFactory} that uses * {@link MultiplexingCacheInstanceManager} as its * {@link #getCacheInstanceManager() CacheInstanceManager}. *

* Supports separate JBoss Cache instances for entity, collection, query * and timestamp caching, with the expectation that a single JGroups resource * (i.e. a multiplexed channel or a shared transport channel) will be shared * between the caches. JBoss Cache instances are created from a factory. *

*

* This version instantiates the factory itself. See * {@link MultiplexingCacheInstanceManager} for configuration details. *

* * @deprecated Favor Infinispan integration; see HHH-5489 for details. * * @author Brian Stansberry * @version $Revision$ */ @Deprecated public class MultiplexedJBossCacheRegionFactory extends JBossCacheRegionFactory { /** * FIXME Per the RegionFactory class Javadoc, this constructor version * should not be necessary. * * @param props The configuration properties */ public MultiplexedJBossCacheRegionFactory(Properties props) { this(); } /** * Create a new MultiplexedJBossCacheRegionFactory. * */ public MultiplexedJBossCacheRegionFactory() { super(new MultiplexingCacheInstanceManager()); } } ././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/JndiMultiplexedJBossCacheRegionFactory.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/JndiMultiplexedJBoss0000644000000000000000000000505311652065432030250 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc; import java.util.Properties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.hibernate.cache.jbc.builder.JndiMultiplexingCacheInstanceManager; /** * {@link JBossCacheRegionFactory} that uses * {@link JndiMultiplexingCacheInstanceManager} as its * {@link #getCacheInstanceManager() CacheInstanceManager}. *

* Supports separate JBoss Cache instances for entity, collection, query * and timestamp caching, with the expectation that a single multiplexed JGroups * resource (i.e. a multiplexed channel or a shared transport channel) will be * shared between the caches. JBoss Cache instances are created from a factory. *

*

* This version finds the factory in JNDI. See * {@link JndiMultiplexingCacheInstanceManager} for configuration details. *

* * @deprecated Favor Infinispan integration; see HHH-5489 for details. * * @author Brian Stansberry * @version $Revision$ */ @Deprecated public class JndiMultiplexedJBossCacheRegionFactory extends JBossCacheRegionFactory { /** * FIXME Per the RegionFactory class Javadoc, this constructor version * should not be necessary. * * @param props The configuration properties */ public JndiMultiplexedJBossCacheRegionFactory(Properties props) { this(); } /** * Create a new MultiplexedJBossCacheRegionFactory. * */ public JndiMultiplexedJBossCacheRegionFactory() { super(new JndiMultiplexingCacheInstanceManager()); } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/SharedJBossCacheRegionFactory.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/SharedJBossCacheRegi0000644000000000000000000000471511652065432030114 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc; import java.util.Properties; import org.hibernate.cache.jbc.builder.JndiSharedCacheInstanceManager; import org.hibernate.cache.jbc.builder.SharedCacheInstanceManager; import org.jboss.cache.DefaultCacheFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * {@link JBossCacheRegionFactory} that uses * {@link SharedCacheInstanceManager} as its * {@link #getCacheInstanceManager() CacheInstanceManager}. *

* Basically, uses a single shared JBoss Cache for entities, collections, * queries and timestamps. The JBoss Cache instance created by the * JBC {@link DefaultCacheFactory} using the resource identified by the * {@link JndiSharedCacheInstanceManager#CACHE_RESOURCE_PROP} * configuration property. *

* * @deprecated Favor Infinispan integration; see HHH-5489 for details. * * @author Brian Stansberry * @version $Revision$ */ @Deprecated public class SharedJBossCacheRegionFactory extends JBossCacheRegionFactory { /** * FIXME Per the RegionFactory class Javadoc, this constructor version * should not be necessary. * * @param props The configuration properties */ public SharedJBossCacheRegionFactory(Properties props) { this(); } /** * Create a new MultiplexedJBossCacheRegionFactory. * */ public SharedJBossCacheRegionFactory() { super(new SharedCacheInstanceManager()); } } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/TransactionalDataRegionAdapter.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/TransactionalDataReg0000644000000000000000000000405011652065432030234 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc; import org.hibernate.cache.CacheDataDescription; import org.hibernate.cache.TransactionalDataRegion; import org.jboss.cache.Cache; /** * {@inheritDoc} * * @author Steve Ebersole */ public abstract class TransactionalDataRegionAdapter extends BasicRegionAdapter implements TransactionalDataRegion { protected final CacheDataDescription metadata; public TransactionalDataRegionAdapter(Cache jbcCache, String regionName, String regionPrefix, CacheDataDescription metadata) { super(jbcCache, regionName, regionPrefix); this.metadata = metadata; } /** * Here, for JBossCache, we consider the cache to be transaction aware if * the underlying cache instance has a reference to the transaction manager. */ public boolean isTransactionAware() { return transactionManager != null; } /** * {@inheritDoc} */ public CacheDataDescription getCacheDataDescription() { return metadata; } } ././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/BasicRegionAdapter.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/BasicRegionAdapter.j0000644000000000000000000005123511652065432030127 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import javax.transaction.SystemException; import javax.transaction.Transaction; import javax.transaction.TransactionManager; import org.hibernate.cache.CacheException; import org.hibernate.cache.Region; import org.hibernate.cache.jbc.util.CacheHelper; import org.hibernate.cache.jbc.util.NonLockingDataVersion; import org.jboss.cache.Cache; import org.jboss.cache.Fqn; import org.jboss.cache.Node; import org.jboss.cache.NodeSPI; import org.jboss.cache.config.Configuration; import org.jboss.cache.config.Option; import org.jboss.cache.config.Configuration.NodeLockingScheme; import org.jboss.cache.notifications.annotation.NodeInvalidated; import org.jboss.cache.notifications.annotation.NodeModified; import org.jboss.cache.notifications.annotation.ViewChanged; import org.jboss.cache.notifications.event.NodeInvalidatedEvent; import org.jboss.cache.notifications.event.NodeModifiedEvent; import org.jboss.cache.notifications.event.ViewChangedEvent; import org.jboss.cache.optimistic.DataVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * General support for writing {@link Region} implementations for JBoss Cache * 2.x. * * @author Steve Ebersole */ public abstract class BasicRegionAdapter implements Region { private enum InvalidateState { INVALID, CLEARING, VALID }; public static final String ITEM = CacheHelper.ITEM; protected final Cache jbcCache; protected final String regionName; protected final Fqn regionFqn; protected final Fqn internalFqn; protected Node regionRoot; protected final boolean optimistic; protected final TransactionManager transactionManager; protected final Logger log; protected final Object regionRootMutex = new Object(); protected final Object memberId; protected final boolean replication; protected final Object invalidationMutex = new Object(); protected final AtomicReference invalidateState = new AtomicReference(InvalidateState.VALID); protected final Set currentView = new HashSet(); // protected RegionRootListener listener; public BasicRegionAdapter(Cache jbcCache, String regionName, String regionPrefix) { this.log = LoggerFactory.getLogger(getClass()); this.jbcCache = jbcCache; this.transactionManager = jbcCache.getConfiguration().getRuntimeConfig().getTransactionManager(); this.regionName = regionName; this.regionFqn = createRegionFqn(regionName, regionPrefix); this.internalFqn = CacheHelper.getInternalFqn(regionFqn); this.optimistic = jbcCache.getConfiguration().getNodeLockingScheme() == NodeLockingScheme.OPTIMISTIC; this.memberId = jbcCache.getLocalAddress(); this.replication = CacheHelper.isClusteredReplication(jbcCache); this.jbcCache.addCacheListener(this); synchronized (currentView) { List view = jbcCache.getMembers(); if (view != null) { currentView.addAll(view); } } activateLocalClusterNode(); log.debug("Created Region for " + regionName + " -- regionPrefix is " + regionPrefix); } protected abstract Fqn createRegionFqn(String regionName, String regionPrefix); protected void activateLocalClusterNode() { // Regions can get instantiated in the course of normal work (e.g. // a named query region will be created the first time the query is // executed), so suspend any ongoing tx Transaction tx = suspend(); try { Configuration cfg = jbcCache.getConfiguration(); if (cfg.isUseRegionBasedMarshalling()) { org.jboss.cache.Region jbcRegion = jbcCache.getRegion(regionFqn, true); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = getClass().getClassLoader(); } jbcRegion.registerContextClassLoader(classLoader); if ( !jbcRegion.isActive() ) { jbcRegion.activate(); } } // // If we are using replication, we may remove the root node // // and then need to re-add it. In that case, the fact // // that it is resident will not replicate, so use a listener // // to set it as resident // if (CacheHelper.isClusteredReplication(cfg.getCacheMode()) // || CacheHelper.isClusteredInvalidation(cfg.getCacheMode())) { // listener = new RegionRootListener(); // jbcCache.addCacheListener(listener); // } regionRoot = jbcCache.getRoot().getChild( regionFqn ); if (regionRoot == null || !regionRoot.isValid()) { // Establish the region root node with a non-locking data version DataVersion version = optimistic ? NonLockingDataVersion.INSTANCE : null; regionRoot = CacheHelper.addNode(jbcCache, regionFqn, true, true, version); } else if (optimistic && regionRoot instanceof NodeSPI) { // FIXME Hacky workaround to JBCACHE-1202 if ( !( ( ( NodeSPI ) regionRoot ).getVersion() instanceof NonLockingDataVersion ) ) { ((NodeSPI) regionRoot).setVersion(NonLockingDataVersion.INSTANCE); } } if (!regionRoot.isResident()) { regionRoot.setResident(true); } establishInternalNodes(); } catch (Exception e) { throw new CacheException(e.getMessage(), e); } finally { resume(tx); } } private void establishRegionRootNode() { synchronized (regionRootMutex) { // If we've been blocking for the mutex, perhaps another // thread has already reestablished the root. // In case the node was reestablised via replication, confirm it's // marked "resident" (a status which doesn't replicate) if (regionRoot != null && regionRoot.isValid()) { return; } // For pessimistic locking, we just want to toss out our ref // to any old invalid root node and get the latest (may be null) if (!optimistic) { establishInternalNodes(); regionRoot = jbcCache.getRoot().getChild( regionFqn ); return; } // The rest only matters for optimistic locking, where we // need to establish the proper data version on the region root // Don't hold a transactional lock for this Transaction tx = suspend(); Node newRoot = null; try { // Make sure the root node for the region exists and // has a DataVersion that never complains newRoot = jbcCache.getRoot().getChild( regionFqn ); if (newRoot == null || !newRoot.isValid()) { // Establish the region root node with a non-locking data version DataVersion version = optimistic ? NonLockingDataVersion.INSTANCE : null; newRoot = CacheHelper.addNode(jbcCache, regionFqn, true, true, version); } else if (newRoot instanceof NodeSPI) { // FIXME Hacky workaround to JBCACHE-1202 if ( !( ( ( NodeSPI ) newRoot ).getVersion() instanceof NonLockingDataVersion ) ) { ((NodeSPI) newRoot).setVersion(NonLockingDataVersion.INSTANCE); } } // Never evict this node newRoot.setResident(true); establishInternalNodes(); } finally { resume(tx); regionRoot = newRoot; } } } private void establishInternalNodes() { synchronized (currentView) { Transaction tx = suspend(); try { for (Object member : currentView) { DataVersion version = optimistic ? NonLockingDataVersion.INSTANCE : null; Fqn f = Fqn.fromRelativeElements(internalFqn, member); CacheHelper.addNode(jbcCache, f, true, false, version); } } finally { resume(tx); } } } public String getName() { return regionName; } public Cache getCacheInstance() { return jbcCache; } public Fqn getRegionFqn() { return regionFqn; } public Object getMemberId() { return this.memberId; } /** * Checks for the validity of the root cache node for this region, * creating a new one if it does not exist or is invalid, and also * ensuring that the root node is marked as resident. Suspends any * transaction while doing this to ensure no transactional locks are held * on the region root. * * TODO remove this once JBCACHE-1250 is resolved. */ public void ensureRegionRootExists() { if (regionRoot == null || !regionRoot.isValid()) establishRegionRootNode(); // Fix up the resident flag if (regionRoot != null && regionRoot.isValid() && !regionRoot.isResident()) regionRoot.setResident(true); } public boolean checkValid() { boolean valid = invalidateState.get() == InvalidateState.VALID; if (!valid) { synchronized (invalidationMutex) { if (invalidateState.compareAndSet(InvalidateState.INVALID, InvalidateState.CLEARING)) { Transaction tx = suspend(); try { Option opt = new Option(); opt.setLockAcquisitionTimeout(1); opt.setCacheModeLocal(true); CacheHelper.removeAll(jbcCache, regionFqn, opt); invalidateState.compareAndSet(InvalidateState.CLEARING, InvalidateState.VALID); } catch (Exception e) { if (log.isTraceEnabled()) { log.trace("Could not invalidate region: " + e.getLocalizedMessage()); } } finally { resume(tx); } } } valid = invalidateState.get() == InvalidateState.VALID; } return valid; } public void destroy() throws CacheException { try { // NOTE : this is being used from the process of shutting down a // SessionFactory. Specific things to consider: // (1) this clearing of the region should not propagate to // other nodes on the cluster (if any); this is the // cache-mode-local option bit... // (2) really just trying a best effort to cleanup after // ourselves; lock failures, etc are not critical here; // this is the fail-silently option bit... Option option = new Option(); option.setCacheModeLocal(true); option.setFailSilently(true); if (optimistic) { option.setDataVersion(NonLockingDataVersion.INSTANCE); } jbcCache.getInvocationContext().setOptionOverrides(option); jbcCache.removeNode(regionFqn); deactivateLocalNode(); } catch (Exception e) { throw new CacheException(e); } finally { jbcCache.removeCacheListener(this); } } protected void deactivateLocalNode() { org.jboss.cache.Region jbcRegion = jbcCache.getRegion(regionFqn, false); if (jbcRegion != null && jbcRegion.isActive()) { jbcRegion.deactivate(); jbcRegion.unregisterContextClassLoader(); } } public boolean contains(Object key) { if ( !checkValid() ) { return false; } try { Option opt = new Option(); opt.setLockAcquisitionTimeout(100); CacheHelper.setInvocationOption( jbcCache, opt ); return CacheHelper.getAllowingTimeout( jbcCache, regionFqn, key ) != null; } catch ( CacheException ce ) { throw ce; } catch ( Throwable t ) { throw new CacheException( t ); } } public long getSizeInMemory() { // not supported return -1; } public long getElementCountInMemory() { if (checkValid()) { try { Set childrenNames = CacheHelper.getChildrenNames(jbcCache, regionFqn); int size = childrenNames.size(); if (childrenNames.contains(CacheHelper.Internal.NODE)) { size--; } return size; } catch ( CacheException ce ) { throw ce; } catch (Exception e) { throw new CacheException(e); } } else { return 0; } } public long getElementCountOnDisk() { return -1; } public Map toMap() { if (checkValid()) { try { Map result = new HashMap(); Set childrenNames = CacheHelper.getChildrenNames(jbcCache, regionFqn); for (Object childName : childrenNames) { if (CacheHelper.Internal.NODE != childName) { result.put(childName, CacheHelper.get(jbcCache,regionFqn, childName)); } } return result; } catch (CacheException e) { throw e; } catch (Exception e) { throw new CacheException(e); } } else { return Collections.emptyMap(); } } public long nextTimestamp() { return System.currentTimeMillis() / 100; } public int getTimeout() { return 600; // 60 seconds } /** * Performs a JBoss Cache get(Fqn, Object) after first * {@link #suspend suspending any ongoing transaction}. Wraps any exception * in a {@link CacheException}. Ensures any ongoing transaction is resumed. * * @param key The key of the item to get * @param opt any option to add to the get invocation. May be null * @param suppressTimeout should any TimeoutException be suppressed? * @return The retrieved object * @throws CacheException issue managing transaction or talking to cache */ protected Object suspendAndGet(Object key, Option opt, boolean suppressTimeout) throws CacheException { Transaction tx = suspend(); try { CacheHelper.setInvocationOption(getCacheInstance(), opt); if (suppressTimeout) return CacheHelper.getAllowingTimeout(getCacheInstance(), getRegionFqn(), key); else return CacheHelper.get(getCacheInstance(), getRegionFqn(), key); } finally { resume(tx); } } /** * Tell the TransactionManager to suspend any ongoing transaction. * * @return the transaction that was suspended, or null if * there wasn't one */ public Transaction suspend() { Transaction tx = null; try { if (transactionManager != null) { tx = transactionManager.suspend(); } } catch (SystemException se) { throw new CacheException("Could not suspend transaction", se); } return tx; } /** * Tell the TransactionManager to resume the given transaction * * @param tx * the transaction to suspend. May be null. */ public void resume(Transaction tx) { try { if (tx != null) transactionManager.resume(tx); } catch (Exception e) { throw new CacheException("Could not resume transaction", e); } } /** * Get an Option with a {@link Option#getDataVersion() data version} * of {@link NonLockingDataVersion}. The data version will not be * set if the cache is not configured for optimistic locking. * * @param allowNullReturn If true, return null * if the cache is not using optimistic locking. * If false, return a default * {@link Option}. * * @return the Option, or null. */ protected Option getNonLockingDataVersionOption(boolean allowNullReturn) { return optimistic ? NonLockingDataVersion.getInvocationOption() : (allowNullReturn) ? null : new Option(); } public static Fqn getTypeFirstRegionFqn(String regionName, String regionPrefix, String regionType) { Fqn base = Fqn.fromString(regionType); Fqn added = Fqn.fromString(escapeRegionName(regionName, regionPrefix)); return new Fqn(base, added); } public static Fqn getTypeLastRegionFqn(String regionName, String regionPrefix, String regionType) { Fqn base = Fqn.fromString(escapeRegionName(regionName, regionPrefix)); return new Fqn(base, regionType); } public static String escapeRegionName(String regionName, String regionPrefix) { String escaped = null; int idx = -1; if (regionPrefix != null) { idx = regionName.indexOf(regionPrefix); } if (idx > -1) { int regionEnd = idx + regionPrefix.length(); String prefix = regionName.substring(0, regionEnd); String suffix = regionName.substring(regionEnd); suffix = suffix.replace('.', '/'); escaped = prefix + suffix; } else { escaped = regionName.replace('.', '/'); if (regionPrefix != null && regionPrefix.length() > 0) { escaped = regionPrefix + "/" + escaped; } } return escaped; } @NodeModified public void nodeModified(NodeModifiedEvent event) { handleEvictAllModification(event); } protected boolean handleEvictAllModification(NodeModifiedEvent event) { if (!event.isPre() && (replication || event.isOriginLocal()) && event.getData().containsKey(ITEM)) { if (event.getFqn().isChildOf(internalFqn)) { invalidateState.set(InvalidateState.INVALID); return true; } } return false; } @NodeInvalidated public void nodeInvalidated(NodeInvalidatedEvent event) { handleEvictAllInvalidation(event); } protected boolean handleEvictAllInvalidation(NodeInvalidatedEvent event) { if (!event.isPre() && event.getFqn().isChildOf(internalFqn)) { invalidateState.set(InvalidateState.INVALID); return true; } return false; } @ViewChanged public void viewChanged(ViewChangedEvent event) { synchronized (currentView) { List view = event.getNewView().getMembers(); if (view != null) { currentView.addAll(view); establishInternalNodes(); } } } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/JBossCacheRegionFactory.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/JBossCacheRegionFact0000644000000000000000000001430111652065432030110 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc; import java.util.Properties; import org.hibernate.cache.CacheDataDescription; import org.hibernate.cache.CacheException; import org.hibernate.cache.CollectionRegion; import org.hibernate.cache.EntityRegion; import org.hibernate.cache.QueryResultsRegion; import org.hibernate.cache.RegionFactory; import org.hibernate.cache.TimestampsRegion; import org.hibernate.cache.access.AccessType; import org.hibernate.cache.jbc.builder.JndiSharedCacheInstanceManager; import org.hibernate.cache.jbc.builder.SharedCacheInstanceManager; import org.hibernate.cache.jbc.collection.CollectionRegionImpl; import org.hibernate.cache.jbc.entity.EntityRegionImpl; import org.hibernate.cache.jbc.query.QueryResultsRegionImpl; import org.hibernate.cache.jbc.timestamp.TimestampsRegionImpl; import org.hibernate.cfg.Environment; import org.hibernate.cfg.Settings; import org.hibernate.util.PropertiesHelper; import org.jboss.cache.DefaultCacheFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * {@link RegionFactory} that uses one or more JBoss Cache instances for * caching entities, collections, queries and timestamps. How the factory * obtains a reference to the needed JBoss Cache instance(s) is determined * by the injected {@link CacheInstanceManager}. *

* By default uses {@link SharedCacheInstanceManager} as its * {@link #getCacheInstanceManager() CacheInstanceManager}. * Basically, this uses a single shared JBoss Cache for entities, collections, * queries and timestamps. The JBoss Cache instance is created by the * JBC {@link DefaultCacheFactory} using the resource identified by the * {@link JndiSharedCacheInstanceManager#CACHE_RESOURCE_PROP} * configuration property. *

*

* Also exposes an overloaded constructor that allows injection of different * CacheInstanceManager implementations. *

* * @deprecated Favor Infinispan integration; see HHH-5489 for details. * * @author Steve Ebersole * @author Brian Stansberry */ @Deprecated public class JBossCacheRegionFactory implements RegionFactory { private static final Logger log = LoggerFactory.getLogger( JBossCacheRegionFactory.class ); private CacheInstanceManager cacheInstanceManager; /** * FIXME Per the RegionFactory class Javadoc, this constructor version * should not be necessary. * * @param props The configuration properties */ public JBossCacheRegionFactory(Properties props) { this(); } /** * Create a new JBossCacheRegionFactory. */ public JBossCacheRegionFactory() { log.warn( "Integration with JBossCache is deprecated in favor of Infinispan" ); } /** * Create a new JBossCacheRegionFactory that uses the provided * {@link CacheInstanceManager}. * * @param cacheInstanceManager The contract for how we get JBC cache instances. */ public JBossCacheRegionFactory(CacheInstanceManager cacheInstanceManager) { this.cacheInstanceManager = cacheInstanceManager; log.warn( "Integration with JBossCache is deprecated in favor of Infinispan" ); } public CacheInstanceManager getCacheInstanceManager() { return cacheInstanceManager; } public void start(Settings settings, Properties properties) throws CacheException { if (cacheInstanceManager == null) { cacheInstanceManager = new SharedCacheInstanceManager(); } cacheInstanceManager.start(settings, properties); } public void stop() { if (cacheInstanceManager != null) { cacheInstanceManager.stop(); } } public boolean isMinimalPutsEnabledByDefault() { return true; } public AccessType getDefaultAccessType() { return AccessType.TRANSACTIONAL; } public long nextTimestamp() { return System.currentTimeMillis() / 100; } public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException { return new EntityRegionImpl(cacheInstanceManager.getEntityCacheInstance(), regionName, getRegionPrefix(properties), metadata); } public CollectionRegion buildCollectionRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException { return new CollectionRegionImpl(cacheInstanceManager.getCollectionCacheInstance(), regionName, getRegionPrefix(properties), metadata); } public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties) throws CacheException { return new QueryResultsRegionImpl(cacheInstanceManager.getQueryCacheInstance(), regionName, getRegionPrefix(properties), properties); } public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties) throws CacheException { return new TimestampsRegionImpl(cacheInstanceManager.getTimestampsCacheInstance(), regionName, getRegionPrefix(properties), properties); } public static String getRegionPrefix(Properties properties) { return PropertiesHelper.getString(Environment.CACHE_REGION_PREFIX, properties, null); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/CacheInstanceManager.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/CacheInstanceManager0000644000000000000000000000607011652065432030171 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2007, Red Hat Middleware LLC or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat Middleware LLC. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc; import java.util.Properties; import org.hibernate.cache.CacheException; import org.hibernate.cfg.Settings; import org.jboss.cache.Cache; /** * Acts as a buffer from how instances of {@link Cache} are built/obtained. * * @author Steve Ebersole */ public interface CacheInstanceManager { /** * Retrieve a handle to the {@link Cache} instance to be used for storing * entity data. * * @return The entity data cache instance. */ public Cache getEntityCacheInstance(); /** * Retrieve a handle to the {@link Cache} instance to be used for storing * collection data. * * @return The collection data cache instance. */ public Cache getCollectionCacheInstance(); /** * Retrieve a handle to the {@link Cache} instance to be used for storing * query results. * * @return The query result cache instance. */ public Cache getQueryCacheInstance(); /** * Retrieve a handle to the {@link Cache} instance to be used for storing * timestamps. * * @return The timestamps cache instance. */ public Cache getTimestampsCacheInstance(); /** * Lifecycle callback to perform any necessary initialization of the * CacheInstanceManager. Called exactly once during the construction of a * {@link org.hibernate.impl.SessionFactoryImpl}. * * @param settings * The settings in effect. * @param properties * The defined cfg properties * @throws CacheException * Indicates problems starting the L2 cache impl; considered as * a sign to stop {@link org.hibernate.SessionFactory} building. */ public void start(Settings settings, Properties properties) throws CacheException; /** * Lifecycle callback to perform any necessary cleanup of the underlying * CacheInstanceManager. Called exactly once during * {@link org.hibernate.SessionFactory#close}. */ public void stop(); } libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc2/0000755000000000000000000000000011675734517024356 5ustar ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc2/JndiSharedJBossCacheRegionFactory.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc2/JndiSharedJBossCach0000644000000000000000000000355711652065432030032 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2009, Red Hat, Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat, Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc2; import java.util.Properties; /** * Deprecated version of superclass maintained solely for forwards * compatibility. * * @deprecated use {@link org.hibernate.cache.jbc.JndiSharedJBossCacheRegionFactory} * * @author Brian Stansberry * @version $Revision$ */ @Deprecated public class JndiSharedJBossCacheRegionFactory extends org.hibernate.cache.jbc.JndiSharedJBossCacheRegionFactory { /** * FIXME Per the RegionFactory class Javadoc, this constructor version * should not be necessary. * * @param props The configuration properties */ public JndiSharedJBossCacheRegionFactory(Properties props) { super(props); } /** * Create a new JndiSharedJBossCacheRegionFactory. * */ public JndiSharedJBossCacheRegionFactory() { super(); } } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc2/MultiplexedJBossCacheRegionFactory.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc2/MultiplexedJBossCac0000644000000000000000000000355111652065432030135 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2009, Red Hat, Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat, Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc2; import java.util.Properties; /** * Deprecated version of superclass maintained solely for forwards * compatibility. * * @deprecated use {@link org.hibernate.cache.jbc.MultiplexedJBossCacheRegionFactory} * * @author Brian Stansberry * @version $Revision$ */ public class MultiplexedJBossCacheRegionFactory extends org.hibernate.cache.jbc.MultiplexedJBossCacheRegionFactory { /** * FIXME Per the RegionFactory class Javadoc, this constructor version * should not be necessary. * * @param props The configuration properties */ public MultiplexedJBossCacheRegionFactory(Properties props) { super(props); } /** * Create a new MultiplexedJBossCacheRegionFactory. * */ public MultiplexedJBossCacheRegionFactory() { super(); } } ././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc2/JndiMultiplexedJBossCacheRegionFactory.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc2/JndiMultiplexedJBos0000644000000000000000000000361111652065432030145 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2009, Red Hat, Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat, Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc2; import java.util.Properties; /** * Deprecated version of superclass maintained solely for forwards * compatibility. * * @deprecated use {@link org.hibernate.cache.jbc.JndiMultiplexedJBossCacheRegionFactory} * * @author Brian Stansberry * @version $Revision$ */ @Deprecated public class JndiMultiplexedJBossCacheRegionFactory extends org.hibernate.cache.jbc.JndiMultiplexedJBossCacheRegionFactory { /** * FIXME Per the RegionFactory class Javadoc, this constructor version * should not be necessary. * * @param props The configuration properties */ public JndiMultiplexedJBossCacheRegionFactory(Properties props) { super(props); } /** * Create a new MultiplexedJBossCacheRegionFactory. * */ public JndiMultiplexedJBossCacheRegionFactory() { super(); } } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc2/SharedJBossCacheRegionFactory.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc2/SharedJBossCacheReg0000644000000000000000000000352711652065432030025 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2009, Red Hat, Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat, Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc2; import java.util.Properties; /** * Deprecated version of superclass maintained solely for forwards * compatibility. * * @deprecated use {@link org.hibernate.cache.jbc.SharedJBossCacheRegionFactory} * * @author Brian Stansberry * @version $Revision$ */ @Deprecated public class SharedJBossCacheRegionFactory extends org.hibernate.cache.jbc.SharedJBossCacheRegionFactory { /** * FIXME Per the RegionFactory class Javadoc, this constructor version * should not be necessary. * * @param props The configuration properties */ public SharedJBossCacheRegionFactory(Properties props) { super(props); } /** * Create a new SharedJBossCacheRegionFactory. * */ public SharedJBossCacheRegionFactory() { super(); } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootlibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc2/JBossCacheRegionFactory.javalibhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc2/JBossCacheRegionFac0000644000000000000000000000426311652065432030014 0ustar /* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2009, Red Hat, Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors.  All third-party contributions are * distributed under license by Red Hat, Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.jbc2; import java.util.Properties; import org.hibernate.cache.jbc.CacheInstanceManager; /** * Deprecated version of superclass maintained solely for forwards * compatibility. * * @deprecated use {@link org.hibernate.cache.jbc.JBossCacheRegionFactory} * * @author Steve Ebersole * @author Brian Stansberry */ @Deprecated public class JBossCacheRegionFactory extends org.hibernate.cache.jbc.JBossCacheRegionFactory { /** * FIXME Per the RegionFactory class Javadoc, this constructor version * should not be necessary. * * @param props The configuration properties */ public JBossCacheRegionFactory(Properties props) { super(props); } /** * Create a new JBossCacheRegionFactory. */ public JBossCacheRegionFactory() { super(); } /** * Create a new JBossCacheRegionFactory that uses the provided * {@link CacheInstanceManager}. * * @param cacheInstanceManager The contract for how we get JBC cache instances. */ public JBossCacheRegionFactory(CacheInstanceManager cacheInstanceManager) { super(cacheInstanceManager); } }