libhibernate-jbosscache-java-3.6.8.Final.orig/ 0000755 0000000 0000000 00000000000 11675734517 016076 5 ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/ 0000755 0000000 0000000 00000000000 11675734517 016665 5 ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/ 0000755 0000000 0000000 00000000000 11675734517 017611 5 ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/ 0000755 0000000 0000000 00000000000 11675734517 020532 5 ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/ 0000755 0000000 0000000 00000000000 11652065432 022457 5 ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/ 0000755 0000000 0000000 00000000000 11652065432 023522 5 ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/ 0000755 0000000 0000000 00000000000 11675734517 024274 5 ustar libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/ 0000755 0000000 0000000 00000000000 11675734517 025610 5 ustar ././@LongLink 0000000 0000000 0000000 00000000172 00000000000 011565 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/OptimisticTransactionalAccess.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/OptimisticTra0000644 0000000 0000000 00000003434 11652065432 030316 0 ustar /* * 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())); } } ././@LongLink 0000000 0000000 0000000 00000000165 00000000000 011567 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/OptimisticReadOnlyAccess.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/OptimisticRea0000644 0000000 0000000 00000005716 11652065432 030304 0 ustar /* * 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"); } } ././@LongLink 0000000 0000000 0000000 00000000155 00000000000 011566 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/EntityRegionImpl.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/entity/EntityRegionI0000644 0000000 0000000 00000006212 11652065432 030251 0 ustar /* * 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 Fqnregion
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);
}
}
././@LongLink 0000000 0000000 0000000 00000000160 00000000000 011562 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/NonLockingDataVersion.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/NonLockingDataV0000644 0000000 0000000 00000004743 11652065432 030151 0 ustar /*
* 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;
// }
}
}
././@LongLink 0000000 0000000 0000000 00000000155 00000000000 011566 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/DataVersionAdapter.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/DataVersionAdap0000644 0000000 0000000 00000014733 11652065432 030175 0 ustar /*
* 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();
}
}
}
././@LongLink 0000000 0000000 0000000 00000000166 00000000000 011570 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/CircumventChecksDataVersion.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/util/CircumventCheck0000644 0000000 0000000 00000004161 11652065432 030237 0 ustar /*
* 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/ 0000755 0000000 0000000 00000000000 11675734517 026427 5 ustar ././@LongLink 0000000 0000000 0000000 00000000176 00000000000 011571 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/OptimisticTransactionalAccess.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/Optimisti0000644 0000000 0000000 00000003600 11652065432 030316 0 ustar /*
* 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()));
}
}
././@LongLink 0000000 0000000 0000000 00000000171 00000000000 011564 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/OptimisticReadOnlyAccess.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/Optimisti0000644 0000000 0000000 00000005255 11652065432 030326 0 ustar /*
* 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");
}
}
././@LongLink 0000000 0000000 0000000 00000000164 00000000000 011566 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/TransactionalAccess.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/Transacti0000644 0000000 0000000 00000010236 11652065432 030270 0 ustar /*
* 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 {
}
}
././@LongLink 0000000 0000000 0000000 00000000157 00000000000 011570 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/ReadOnlyAccess.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/ReadOnlyA0000644 0000000 0000000 00000005255 11652065432 030163 0 ustar /*
* 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");
}
}
././@LongLink 0000000 0000000 0000000 00000000165 00000000000 011567 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/CollectionRegionImpl.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/collection/Collectio0000644 0000000 0000000 00000006201 11652065432 030252 0 ustar /*
* 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* 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 Fqnorg.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 Cache
s 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)));
}
}
././@LongLink 0000000 0000000 0000000 00000000174 00000000000 011567 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/JndiSharedCacheInstanceManager.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/JndiSharedCa0000644 0000000 0000000 00000007627 11652065432 030124 0 ustar /*
* 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 );
}
}
}
}
}
././@LongLink 0000000 0000000 0000000 00000000202 00000000000 011557 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/JndiMultiplexingCacheInstanceManager.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/JndiMultiple0000644 0000000 0000000 00000007152 11652065432 030236 0 ustar /*
* 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 );
}
}
}
}
}
././@LongLink 0000000 0000000 0000000 00000000170 00000000000 011563 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/SharedCacheInstanceManager.java libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/SharedCacheI0000644 0000000 0000000 00000023101 11652065432 030071 0 ustar /*
* 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);
}
}
}
././@LongLink 0000000 0000000 0000000 00000000150 00000000000 011561 L ustar root root libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/jbc-configs.xml libhibernate-jbosscache-java-3.6.8.Final.orig/src/main/java/hibernate/cache/jbc/builder/jbc-configs.0000644 0000000 0000000 00000143445 11652065432 030106 0 ustar
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: * *
false
, the thread should not cache the data;
* only if above returns true
, put data in the cache and...
* 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