[jboss-cvs] JBossAS SVN: r76780 - projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 7 15:16:54 EDT 2008
Author: bstansberry at jboss.com
Date: 2008-08-07 15:16:54 -0400 (Thu, 07 Aug 2008)
New Revision: 76780
Modified:
projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/JBCCache.java
projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/OptimisticJBCCache.java
Log:
[JBCLUSTER-206] Move to JBoss-style 3 space indentation
Modified: projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/JBCCache.java
===================================================================
--- projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/JBCCache.java 2008-08-07 19:14:16 UTC (rev 76779)
+++ projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/JBCCache.java 2008-08-07 19:16:54 UTC (rev 76780)
@@ -47,33 +47,34 @@
* @author Brian Stansberry
* @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
*/
-public class JBCCache implements Cache {
+public class JBCCache implements Cache
+{
private static final Logger log = Logger.getLogger(JBCCache.class);
- private static final String ITEM = "item";
+ private static final String ITEM = "item";
- private org.jboss.cache.TreeCache cache;
- private final String regionName;
- private final Fqn regionFqn;
- private final TransactionManager transactionManager;
+ private org.jboss.cache.TreeCache cache;
+ private final String regionName;
+ private final Fqn regionFqn;
+ private final TransactionManager transactionManager;
private boolean queryCacheLocalWritesOnly;
private boolean localPutsOnly;
-
+
private final CacheProperties cacheProperties;
-
- public JBCCache(org.jboss.cache.TreeCache cache, String regionName,
- CacheProperties cacheProperties, TransactionManager transactionManager)
- throws CacheException
+
+ public JBCCache(org.jboss.cache.TreeCache cache, String regionName,
+ CacheProperties cacheProperties, TransactionManager transactionManager)
+ throws CacheException
{
- this.cache = cache;
- this.regionName = regionName;
- this.cacheProperties = cacheProperties;
- this.regionFqn = Fqn.fromString(SecondLevelCacheUtil.createRegionFqn(regionName, this.cacheProperties.getCacheRegionPrefix()));
- this.transactionManager = transactionManager;
-
- this.queryCacheLocalWritesOnly = this.cacheProperties.isQueryCacheLocalWritesOnly() && regionName.contains(StandardQueryCache.class.getName());
- this.localPutsOnly = this.cacheProperties.isLocalPutsOnly() && (regionName.contains(UpdateTimestampsCache.class.getName()) == false);
-
+ this.cache = cache;
+ this.regionName = regionName;
+ this.cacheProperties = cacheProperties;
+ this.regionFqn = Fqn.fromString(SecondLevelCacheUtil.createRegionFqn(regionName, this.cacheProperties.getCacheRegionPrefix()));
+ this.transactionManager = transactionManager;
+
+ this.queryCacheLocalWritesOnly = this.cacheProperties.isQueryCacheLocalWritesOnly() && regionName.contains(StandardQueryCache.class.getName());
+ this.localPutsOnly = this.cacheProperties.isLocalPutsOnly() && (regionName.contains(UpdateTimestampsCache.class.getName()) == false);
+
if (cache.getUseRegionBasedMarshalling())
{
boolean fetchState = cache.getFetchInMemoryState();
@@ -83,7 +84,7 @@
// as it can include classes from multiple scoped classloaders
if (queryCacheLocalWritesOnly)
cache.setFetchInMemoryState(false);
-
+
// We always activate
activateCacheRegion(regionFqn.toString());
}
@@ -98,254 +99,254 @@
{
log.debug("TreeCache is not configured for region based marshalling");
}
- }
+ }
- public Object get(Object key) throws CacheException {
- Transaction tx = suspend();
- try {
- return read(key);
- }
- finally {
- resume( tx );
- }
- }
-
- public Object read(Object key) throws CacheException {
- try {
- return cache.get( new Fqn( regionFqn, key ), ITEM );
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ public Object get(Object key) throws CacheException {
+ Transaction tx = suspend();
+ try {
+ return read(key);
+ }
+ finally {
+ resume( tx );
+ }
+ }
- public void update(Object key, Object value) throws CacheException {
- try {
- if (queryCacheLocalWritesOnly) {
- Option option = new Option();
- option.setCacheModeLocal(true);
- cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
+ public Object read(Object key) throws CacheException {
+ try {
+ return cache.get( new Fqn( regionFqn, key ), ITEM );
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
+
+ public void update(Object key, Object value) throws CacheException {
+ try {
+ if (queryCacheLocalWritesOnly) {
+ Option option = new Option();
+ option.setCacheModeLocal(true);
+ cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
+ }
+ else {
+ cache.put( new Fqn( regionFqn, key ), ITEM, value );
+ }
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
+
+ public void put(Object key, Object value) throws CacheException {
+ Transaction tx = suspend();
+ try {
+ if (queryCacheLocalWritesOnly || localPutsOnly) {
+ Option option = new Option();
+ option.setCacheModeLocal(true);
+ // Overloaded method isn't available, so have to use InvocationContext
+ cache.getInvocationContext().setOptionOverrides(option);
+ try {
+ // do the failfast put outside the scope of the JTA txn
+ cache.putFailFast( new Fqn( regionFqn, key ), ITEM, value, 0 );
}
- else {
- cache.put( new Fqn( regionFqn, key ), ITEM, value );
+ finally {
+ cache.getInvocationContext().setOptionOverrides(null);
}
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ }
+ else {
+ //do the failfast put outside the scope of the JTA txn
+ cache.putFailFast( new Fqn( regionFqn, key ), ITEM, value, 0 );
+ }
+ }
+ catch (TimeoutException te) {
+ //ignore!
+ log.debug("ignoring write lock acquisition failure");
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ finally {
+ resume( tx );
+ }
+ }
- public void put(Object key, Object value) throws CacheException {
- Transaction tx = suspend();
- try {
- if (queryCacheLocalWritesOnly || localPutsOnly) {
- Option option = new Option();
- option.setCacheModeLocal(true);
- // Overloaded method isn't available, so have to use InvocationContext
- cache.getInvocationContext().setOptionOverrides(option);
- try {
- // do the failfast put outside the scope of the JTA txn
- cache.putFailFast( new Fqn( regionFqn, key ), ITEM, value, 0 );
- }
- finally {
- cache.getInvocationContext().setOptionOverrides(null);
- }
- }
- else {
- //do the failfast put outside the scope of the JTA txn
- cache.putFailFast( new Fqn( regionFqn, key ), ITEM, value, 0 );
- }
- }
- catch (TimeoutException te) {
- //ignore!
- log.debug("ignoring write lock acquisition failure");
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- finally {
- resume( tx );
- }
- }
+ private void resume(Transaction tx) {
+ try {
+ if (tx!=null) transactionManager.resume(tx);
+ }
+ catch (Exception e) {
+ throw new CacheException("Could not resume transaction", e);
+ }
+ }
- private void resume(Transaction tx) {
- try {
- if (tx!=null) transactionManager.resume(tx);
- }
- catch (Exception e) {
- throw new CacheException("Could not resume transaction", e);
- }
- }
+ private 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;
+ }
- private 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;
- }
+ public void remove(Object key) throws CacheException {
+ try {
+ if (queryCacheLocalWritesOnly) {
+ Option option = new Option();
+ option.setCacheModeLocal(true);
+ cache.remove( new Fqn( regionFqn, key ), option );
+ }
+ else {
+ cache.remove( new Fqn( regionFqn, key ) );
+ }
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- public void remove(Object key) throws CacheException {
- try {
- if (queryCacheLocalWritesOnly) {
- Option option = new Option();
- option.setCacheModeLocal(true);
- cache.remove( new Fqn( regionFqn, key ), option );
- }
- else {
- cache.remove( new Fqn( regionFqn, key ) );
- }
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ public void clear() throws CacheException {
+ try {
+ cache.remove( regionFqn );
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- public void clear() throws CacheException {
- try {
- cache.remove( regionFqn );
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ public void destroy() throws CacheException {
+ try {
+ // NOTE : Hibernate's class uses evict() but that isn't recursive!
+ //cache.evict( regionFqn );
+ Option opt = new Option();
+ opt.setCacheModeLocal(true);
+ cache.remove(regionFqn, opt);
- public void destroy() throws CacheException {
- try {
- // NOTE : Hibernate's class uses evict() but that isn't recursive!
- //cache.evict( regionFqn );
- Option opt = new Option();
- opt.setCacheModeLocal(true);
- cache.remove(regionFqn, opt);
-
- if (cache.getUseRegionBasedMarshalling() && !SecondLevelCacheUtil.isSharedClassLoaderRegion(regionName))
- {
- inactivateCacheRegion();
- }
- }
- catch (CacheException e)
- {
- throw e;
- }
- catch( Exception e ) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ if (cache.getUseRegionBasedMarshalling() && !SecondLevelCacheUtil.isSharedClassLoaderRegion(regionName))
+ {
+ inactivateCacheRegion();
+ }
+ }
+ catch (CacheException e)
+ {
+ throw e;
+ }
+ catch( Exception e ) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- public void lock(Object key) throws CacheException {
- throw new UnsupportedOperationException( "TreeCache is a fully transactional cache: " + regionName );
- }
+ public void lock(Object key) throws CacheException {
+ throw new UnsupportedOperationException( "TreeCache is a fully transactional cache: " + regionName );
+ }
- public void unlock(Object key) throws CacheException {
- throw new UnsupportedOperationException( "TreeCache is a fully transactional cache: " + regionName );
- }
+ public void unlock(Object key) throws CacheException {
+ throw new UnsupportedOperationException( "TreeCache is a fully transactional cache: " + regionName );
+ }
- public long nextTimestamp() {
- return System.currentTimeMillis() / 100;
- }
+ public long nextTimestamp() {
+ return System.currentTimeMillis() / 100;
+ }
- public int getTimeout() {
- return 600; //60 seconds
- }
+ public int getTimeout() {
+ return 600; //60 seconds
+ }
- public String getRegionName() {
- return regionName;
- }
+ public String getRegionName() {
+ return regionName;
+ }
- public long getSizeInMemory() {
- return -1;
- }
+ public long getSizeInMemory() {
+ return -1;
+ }
- public long getElementCountInMemory() {
- try {
- Set children = cache.getChildrenNames( regionFqn );
- return children == null ? 0 : children.size();
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ public long getElementCountInMemory() {
+ try {
+ Set children = cache.getChildrenNames( regionFqn );
+ return children == null ? 0 : children.size();
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- public long getElementCountOnDisk() {
- return 0;
- }
-
- public Map toMap() {
- try {
- Map result = new HashMap();
- Set childrenNames = cache.getChildrenNames( regionFqn );
- if (childrenNames != null) {
- Iterator iter = childrenNames.iterator();
- while ( iter.hasNext() ) {
- Object key = iter.next();
- result.put(
- key,
- cache.get( new Fqn( regionFqn, key ), ITEM )
- );
- }
- }
- return result;
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
-
- public String toString() {
- return "JBCCache(" + regionName + ')';
- }
-
- private void activateCacheRegion(String regionName) throws CacheException
- {
- String fqnString = regionFqn.toString();
- // FIXME -- find a way that doesn't involve this API
- if (cache.getMarshaller().isInactive(fqnString))
- {
- try
- {
- // Only register the classloader if it's not a shared region.
- // If it's shared, no single classloader is valid
- if (!SecondLevelCacheUtil.isSharedClassLoaderRegion(regionName))
- {
- cache.registerClassLoader(fqnString, Thread.currentThread().getContextClassLoader());
- }
- cache.activateRegion(fqnString);
- }
- catch (Exception e)
- {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
- else
- {
- log.debug("activateCacheRegion(): Region " + fqnString + " is already active");
- }
- }
-
- private void inactivateCacheRegion() throws CacheException
- {
- String fqnString = regionFqn.toString();
- // FIXME -- find a way that doesn't involve this API
- if (!cache.getMarshaller().isInactive(fqnString))
- {
- try
- {
- cache.inactivateRegion(fqnString);
- cache.unregisterClassLoader(fqnString);
- }
- catch (Exception e)
- {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
- else
- {
- log.debug("inactivateCacheRegion(): Region " + fqnString + " is already inactive");
- }
- }
+ public long getElementCountOnDisk() {
+ return 0;
+ }
+
+ public Map toMap() {
+ try {
+ Map result = new HashMap();
+ Set childrenNames = cache.getChildrenNames( regionFqn );
+ if (childrenNames != null) {
+ Iterator iter = childrenNames.iterator();
+ while ( iter.hasNext() ) {
+ Object key = iter.next();
+ result.put(
+ key,
+ cache.get( new Fqn( regionFqn, key ), ITEM )
+ );
+ }
+ }
+ return result;
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
+
+ public String toString() {
+ return "JBCCache(" + regionName + ')';
+ }
+
+ private void activateCacheRegion(String regionName) throws CacheException
+ {
+ String fqnString = regionFqn.toString();
+ // FIXME -- find a way that doesn't involve this API
+ if (cache.getMarshaller().isInactive(fqnString))
+ {
+ try
+ {
+ // Only register the classloader if it's not a shared region.
+ // If it's shared, no single classloader is valid
+ if (!SecondLevelCacheUtil.isSharedClassLoaderRegion(regionName))
+ {
+ cache.registerClassLoader(fqnString, Thread.currentThread().getContextClassLoader());
+ }
+ cache.activateRegion(fqnString);
+ }
+ catch (Exception e)
+ {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
+ else
+ {
+ log.debug("activateCacheRegion(): Region " + fqnString + " is already active");
+ }
+ }
+
+ private void inactivateCacheRegion() throws CacheException
+ {
+ String fqnString = regionFqn.toString();
+ // FIXME -- find a way that doesn't involve this API
+ if (!cache.getMarshaller().isInactive(fqnString))
+ {
+ try
+ {
+ cache.inactivateRegion(fqnString);
+ cache.unregisterClassLoader(fqnString);
+ }
+ catch (Exception e)
+ {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
+ else
+ {
+ log.debug("inactivateCacheRegion(): Region " + fqnString + " is already inactive");
+ }
+ }
}
Modified: projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/OptimisticJBCCache.java
===================================================================
--- projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/OptimisticJBCCache.java 2008-08-07 19:14:16 UTC (rev 76779)
+++ projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/OptimisticJBCCache.java 2008-08-07 19:16:54 UTC (rev 76780)
@@ -47,34 +47,34 @@
* @author Steve Ebersole
* @author Brian Stansberry
*/
-public class OptimisticJBCCache implements OptimisticCache {
+public class OptimisticJBCCache implements OptimisticCache
+{
+ // todo : eventually merge this with TreeCache and just add optional opt-lock support there.
- // todo : eventually merge this with TreeCache and just add optional opt-lock support there.
-
private static final Logger log = Logger.getLogger(OptimisticJBCCache.class);
- private static final String ITEM = "item";
+ private static final String ITEM = "item";
- private org.jboss.cache.TreeCache cache;
- private final String regionName;
- private final Fqn regionFqn;
- private OptimisticCacheSource source;
+ private org.jboss.cache.TreeCache cache;
+ private final String regionName;
+ private final Fqn regionFqn;
+ private OptimisticCacheSource source;
private boolean queryCacheLocalWritesOnly;
private boolean localPutsOnly;
-
+
private final CacheProperties cacheProperties;
- public OptimisticJBCCache(org.jboss.cache.TreeCache cache, String regionName,
- CacheProperties cacheProperties) throws CacheException
- {
- this.cache = cache;
- this.regionName = regionName;
- this.cacheProperties = cacheProperties;
+ public OptimisticJBCCache(org.jboss.cache.TreeCache cache, String regionName,
+ CacheProperties cacheProperties) throws CacheException
+ {
+ this.cache = cache;
+ this.regionName = regionName;
+ this.cacheProperties = cacheProperties;
this.regionFqn = Fqn.fromString(SecondLevelCacheUtil.createRegionFqn(regionName, this.cacheProperties.getCacheRegionPrefix()));
-
+
this.queryCacheLocalWritesOnly = this.cacheProperties.isQueryCacheLocalWritesOnly() && regionName.contains(StandardQueryCache.class.getName());
this.localPutsOnly = this.cacheProperties.isLocalPutsOnly() && (regionName.contains(UpdateTimestampsCache.class.getName()) == false);
-
+
if (cache.getUseRegionBasedMarshalling())
{
boolean fetchState = cache.getFetchInMemoryState();
@@ -84,7 +84,7 @@
// as it can include classes from multiple scoped classloaders
if (queryCacheLocalWritesOnly)
cache.setFetchInMemoryState(false);
-
+
// We always activate
activateCacheRegion(regionFqn.toString());
}
@@ -99,365 +99,365 @@
{
log.debug("TreeCache is not configured for region based marshalling");
}
- }
+ }
- // OptimisticCache impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // OptimisticCache impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public void setSource(OptimisticCacheSource source) {
- this.source = source;
- }
+ public void setSource(OptimisticCacheSource source) {
+ this.source = source;
+ }
- public void writeInsert(Object key, Object value, Object currentVersion) {
- writeUpdate( key, value, currentVersion, null );
- }
+ public void writeInsert(Object key, Object value, Object currentVersion) {
+ writeUpdate( key, value, currentVersion, null );
+ }
- public void writeUpdate(Object key, Object value, Object currentVersion, Object previousVersion) {
- try {
- Option option = new Option();
- DataVersion dv = ( source != null && source.isVersioned() )
- ? new DataVersionAdapter( currentVersion, previousVersion, source.getVersionComparator(), source.toString() )
- : NonLockingDataVersion.INSTANCE;
- option.setDataVersion( dv );
+ public void writeUpdate(Object key, Object value, Object currentVersion, Object previousVersion) {
+ try {
+ Option option = new Option();
+ DataVersion dv = ( source != null && source.isVersioned() )
+ ? new DataVersionAdapter( currentVersion, previousVersion, source.getVersionComparator(), source.toString() )
+ : NonLockingDataVersion.INSTANCE;
+ option.setDataVersion( dv );
option.setCacheModeLocal(queryCacheLocalWritesOnly);
- cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
- }
- catch ( Exception e ) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
+ }
+ catch ( Exception e ) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- public void writeLoad(Object key, Object value, Object currentVersion) {
- try {
- Option option = new Option();
- option.setFailSilently( true );
- option.setDataVersion( NonLockingDataVersion.INSTANCE );
- option.setCacheModeLocal(queryCacheLocalWritesOnly || localPutsOnly);
- cache.remove( new Fqn( regionFqn, key ), "ITEM", option );
+ public void writeLoad(Object key, Object value, Object currentVersion) {
+ try {
+ Option option = new Option();
+ option.setFailSilently( true );
+ option.setDataVersion( NonLockingDataVersion.INSTANCE );
+ option.setCacheModeLocal(queryCacheLocalWritesOnly || localPutsOnly);
+ cache.remove( new Fqn( regionFqn, key ), "ITEM", option );
- option = new Option();
- option.setFailSilently( true );
- DataVersion dv = ( source != null && source.isVersioned() )
- ? new DataVersionAdapter( currentVersion, currentVersion, source.getVersionComparator(), source.toString() )
- : NonLockingDataVersion.INSTANCE;
- option.setDataVersion( dv );
- option.setCacheModeLocal(queryCacheLocalWritesOnly || localPutsOnly);
- cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ option = new Option();
+ option.setFailSilently( true );
+ DataVersion dv = ( source != null && source.isVersioned() )
+ ? new DataVersionAdapter( currentVersion, currentVersion, source.getVersionComparator(), source.toString() )
+ : NonLockingDataVersion.INSTANCE;
+ option.setDataVersion( dv );
+ option.setCacheModeLocal(queryCacheLocalWritesOnly || localPutsOnly);
+ cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- // Cache impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // Cache impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- public Object get(Object key) throws CacheException {
- try {
- Option option = new Option();
- option.setFailSilently( true );
-// option.setDataVersion( NonLockingDataVersion.INSTANCE );
- return cache.get( new Fqn( regionFqn, key ), ITEM, option );
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ public Object get(Object key) throws CacheException {
+ try {
+ Option option = new Option();
+ option.setFailSilently( true );
+// option.setDataVersion( NonLockingDataVersion.INSTANCE );
+ return cache.get( new Fqn( regionFqn, key ), ITEM, option );
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- public Object read(Object key) throws CacheException {
- try {
- return cache.get( new Fqn( regionFqn, key ), ITEM );
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ public Object read(Object key) throws CacheException {
+ try {
+ return cache.get( new Fqn( regionFqn, key ), ITEM );
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- public void update(Object key, Object value) throws CacheException {
- try {
- Option option = new Option();
- option.setDataVersion( NonLockingDataVersion.INSTANCE );
+ public void update(Object key, Object value) throws CacheException {
+ try {
+ Option option = new Option();
+ option.setDataVersion( NonLockingDataVersion.INSTANCE );
option.setCacheModeLocal(queryCacheLocalWritesOnly);
- cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- public void put(Object key, Object value) throws CacheException {
- try {
- log.trace( "performing put() into region [" + regionName + "]" );
- // do the put outside the scope of the JTA txn
- Option option = new Option();
- option.setFailSilently( true );
- option.setDataVersion( NonLockingDataVersion.INSTANCE );
- option.setCacheModeLocal(queryCacheLocalWritesOnly || localPutsOnly);
- cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
- }
- catch (TimeoutException te) {
- //ignore!
- log.debug("ignoring write lock acquisition failure");
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ public void put(Object key, Object value) throws CacheException {
+ try {
+ log.trace( "performing put() into region [" + regionName + "]" );
+ // do the put outside the scope of the JTA txn
+ Option option = new Option();
+ option.setFailSilently( true );
+ option.setDataVersion( NonLockingDataVersion.INSTANCE );
+ option.setCacheModeLocal(queryCacheLocalWritesOnly || localPutsOnly);
+ cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
+ }
+ catch (TimeoutException te) {
+ //ignore!
+ log.debug("ignoring write lock acquisition failure");
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- public void remove(Object key) throws CacheException {
- try {
- // tree cache in optimistic mode seems to have as very difficult
- // time with remove calls on non-existent nodes (NPEs)...
- if ( cache.get( new Fqn( regionFqn, key ), ITEM ) != null ) {
- Option option = new Option();
- option.setDataVersion( NonLockingDataVersion.INSTANCE );
- option.setCacheModeLocal(queryCacheLocalWritesOnly);
- cache.remove( new Fqn( regionFqn, key ), option );
- }
- else {
- log.trace( "skipping remove() call as the underlying node did not seem to exist" );
- }
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
-
- public void clear() throws CacheException {
- try {
- Option option = new Option();
- option.setDataVersion( NonLockingDataVersion.INSTANCE );
+ public void remove(Object key) throws CacheException {
+ try {
+ // tree cache in optimistic mode seems to have as very difficult
+ // time with remove calls on non-existent nodes (NPEs)...
+ if ( cache.get( new Fqn( regionFqn, key ), ITEM ) != null ) {
+ Option option = new Option();
+ option.setDataVersion( NonLockingDataVersion.INSTANCE );
option.setCacheModeLocal(queryCacheLocalWritesOnly);
- cache.remove( regionFqn, option );
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ cache.remove( new Fqn( regionFqn, key ), option );
+ }
+ else {
+ log.trace( "skipping remove() call as the underlying node did not seem to exist" );
+ }
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- public void destroy() throws CacheException {
- try {
- Option option = new Option();
- option.setCacheModeLocal( true );
- option.setFailSilently( true );
- option.setDataVersion( NonLockingDataVersion.INSTANCE );
- cache.remove( regionFqn, option );
-
- if (cache.getUseRegionBasedMarshalling() && !SecondLevelCacheUtil.isSharedClassLoaderRegion(regionName))
- {
- inactivateCacheRegion();
- }
- }
- catch( Exception e ) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ public void clear() throws CacheException {
+ try {
+ Option option = new Option();
+ option.setDataVersion( NonLockingDataVersion.INSTANCE );
+ option.setCacheModeLocal(queryCacheLocalWritesOnly);
+ cache.remove( regionFqn, option );
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- public void lock(Object key) throws CacheException {
- throw new UnsupportedOperationException( "TreeCache is a fully transactional cache: " + regionName );
- }
+ public void destroy() throws CacheException {
+ try {
+ Option option = new Option();
+ option.setCacheModeLocal( true );
+ option.setFailSilently( true );
+ option.setDataVersion( NonLockingDataVersion.INSTANCE );
+ cache.remove( regionFqn, option );
- public void unlock(Object key) throws CacheException {
- throw new UnsupportedOperationException( "TreeCache is a fully transactional cache: " + regionName );
- }
+ if (cache.getUseRegionBasedMarshalling() && !SecondLevelCacheUtil.isSharedClassLoaderRegion(regionName))
+ {
+ inactivateCacheRegion();
+ }
+ }
+ catch( Exception e ) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- public long nextTimestamp() {
- return System.currentTimeMillis() / 100;
- }
+ public void lock(Object key) throws CacheException {
+ throw new UnsupportedOperationException( "TreeCache is a fully transactional cache: " + regionName );
+ }
- public int getTimeout() {
- return 600; //60 seconds
- }
+ public void unlock(Object key) throws CacheException {
+ throw new UnsupportedOperationException( "TreeCache is a fully transactional cache: " + regionName );
+ }
- public String getRegionName() {
- return regionName;
- }
+ public long nextTimestamp() {
+ return System.currentTimeMillis() / 100;
+ }
- public long getSizeInMemory() {
- return -1;
- }
+ public int getTimeout() {
+ return 600; //60 seconds
+ }
- public long getElementCountInMemory() {
- try {
- Set children = cache.getChildrenNames( regionFqn );
- return children == null ? 0 : children.size();
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ public String getRegionName() {
+ return regionName;
+ }
- public long getElementCountOnDisk() {
- return 0;
- }
+ public long getSizeInMemory() {
+ return -1;
+ }
- public Map toMap() {
- try {
- Map result = new HashMap();
- Set childrenNames = cache.getChildrenNames( regionFqn );
- if (childrenNames != null) {
- Iterator iter = childrenNames.iterator();
- while ( iter.hasNext() ) {
- Object key = iter.next();
- result.put(
- key,
- cache.get( new Fqn( regionFqn, key ), ITEM )
- );
- }
- }
- return result;
- }
- catch (Exception e) {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
+ public long getElementCountInMemory() {
+ try {
+ Set children = cache.getChildrenNames( regionFqn );
+ return children == null ? 0 : children.size();
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- public String toString() {
- return "OptimisticJBCCache(" + regionName + ')';
- }
-
- private void activateCacheRegion(String regionName) throws CacheException
- {
- String fqnString = regionFqn.toString();
- // FIXME -- find a way that doesn't involve this API
- if (cache.getMarshaller().isInactive(fqnString))
- {
- try
- {
- // Only register the classloader if it's not a shared region.
- // If it's shared, no single classloader is valid
- if (!SecondLevelCacheUtil.isSharedClassLoaderRegion(regionName))
- {
- cache.registerClassLoader(fqnString, Thread.currentThread().getContextClassLoader());
- }
- cache.activateRegion(fqnString);
- }
- catch (Exception e)
- {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
- else
- {
- log.debug("activateCacheRegion(): Region " + fqnString + " is already active");
- }
- }
-
- private void inactivateCacheRegion() throws CacheException
- {
- String fqnString = regionFqn.toString();
- // FIXME -- find a way that doesn't involve this API
- if (!cache.getMarshaller().isInactive(fqnString))
- {
- try
- {
- cache.inactivateRegion(fqnString);
- cache.unregisterClassLoader(fqnString);
- }
- catch (Exception e)
- {
- throw SecondLevelCacheUtil.convertToHibernateException(e);
- }
- }
- else
- {
- log.debug("inactivateCacheRegion(): Region " + fqnString + " is already inactive");
- }
- }
+ public long getElementCountOnDisk() {
+ return 0;
+ }
- public static class DataVersionAdapter implements DataVersion
- {
- private static final long serialVersionUID = 5564692336076405571L;
- private final Object currentVersion;
- private final Object previousVersion;
- private final Comparator versionComparator;
- private final String sourceIdentifer;
+ public Map toMap() {
+ try {
+ Map result = new HashMap();
+ Set childrenNames = cache.getChildrenNames( regionFqn );
+ if (childrenNames != null) {
+ Iterator iter = childrenNames.iterator();
+ while ( iter.hasNext() ) {
+ Object key = iter.next();
+ result.put(
+ key,
+ cache.get( new Fqn( regionFqn, key ), ITEM )
+ );
+ }
+ }
+ return result;
+ }
+ catch (Exception e) {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
- 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 );
- }
+ public String toString() {
+ return "OptimisticJBCCache(" + regionName + ')';
+ }
- /**
- * 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.
- * <p/>
- * 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;
- }
- 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)
+ private void activateCacheRegion(String regionName) throws CacheException
+ {
+ String fqnString = regionFqn.toString();
+ // FIXME -- find a way that doesn't involve this API
+ if (cache.getMarshaller().isInactive(fqnString))
+ {
+ try
+ {
+ // Only register the classloader if it's not a shared region.
+ // If it's shared, no single classloader is valid
+ if (!SecondLevelCacheUtil.isSharedClassLoaderRegion(regionName))
{
- // 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);
+ cache.registerClassLoader(fqnString, Thread.currentThread().getContextClassLoader());
}
-
- return versionComparator.compare( currentVersion, other.previousVersion ) >= 1;
- }
+ cache.activateRegion(fqnString);
+ }
+ catch (Exception e)
+ {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
+ else
+ {
+ log.debug("activateCacheRegion(): Region " + fqnString + " is already active");
+ }
+ }
- public String toString() {
- return super.toString() + " [current=" + currentVersion + ", previous=" + previousVersion + ", src=" + sourceIdentifer + "]";
- }
- }
+ private void inactivateCacheRegion() throws CacheException
+ {
+ String fqnString = regionFqn.toString();
+ // FIXME -- find a way that doesn't involve this API
+ if (!cache.getMarshaller().isInactive(fqnString))
+ {
+ try
+ {
+ cache.inactivateRegion(fqnString);
+ cache.unregisterClassLoader(fqnString);
+ }
+ catch (Exception e)
+ {
+ throw SecondLevelCacheUtil.convertToHibernateException(e);
+ }
+ }
+ else
+ {
+ log.debug("inactivateCacheRegion(): Region " + fqnString + " is already inactive");
+ }
+ }
- /**
- * 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.
- */
- public static class NonLockingDataVersion implements DataVersion
- {
- private static final long serialVersionUID = 7050722490368630553L;
+ public static class DataVersionAdapter implements DataVersion
+ {
+ private static final long serialVersionUID = 5564692336076405571L;
+ private final Object currentVersion;
+ private final Object previousVersion;
+ private final 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.
+ * <p/>
+ * 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;
+ }
+ 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);
+ }
+
+ return versionComparator.compare( currentVersion, other.previousVersion ) >= 1;
+ }
+
+ public String toString() {
+ return super.toString() + " [current=" + currentVersion + ", previous=" + previousVersion + ", src=" + sourceIdentifer + "]";
+ }
+ }
+
+ /**
+ * 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.
+ */
+ public static class NonLockingDataVersion implements DataVersion
+ {
+ private static final long serialVersionUID = 7050722490368630553L;
public static final DataVersion INSTANCE = new NonLockingDataVersion();
- public boolean newerThan(DataVersion dataVersion) {
- log.trace( "non locking lock check...");
- return false;
- }
- }
+ public boolean newerThan(DataVersion dataVersion) {
+ log.trace( "non locking lock check...");
+ return false;
+ }
+ }
- /**
- * 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...).
- */
- public static class CircumventChecksDataVersion implements DataVersion
- {
- private static final long serialVersionUID = 7996980646166032369L;
+ /**
+ * 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...).
+ */
+ public static class CircumventChecksDataVersion implements DataVersion
+ {
+ private static final long serialVersionUID = 7996980646166032369L;
public static final DataVersion INSTANCE = new CircumventChecksDataVersion();
- public boolean newerThan(DataVersion dataVersion) {
- throw new CacheException( "optimistic locking checks should never happen on CircumventChecksDataVersion" );
- }
- }
+ public boolean newerThan(DataVersion dataVersion) {
+ throw new CacheException( "optimistic locking checks should never happen on CircumventChecksDataVersion" );
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list