Author: steve.ebersole(a)jboss.com
Date: 2007-07-25 23:53:09 -0400 (Wed, 25 Jul 2007)
New Revision: 12823
Added:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/TransactionalDataRegionAdapter.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/collection/
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/collection/CollectionRegionImpl.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/collection/ReadOnlyAccess.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/collection/TransactionalAccess.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/entity/TransactionalAccess.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/util/
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/util/CacheModeHelper.java
core/trunk/cache-jbosscache2/src/test/
core/trunk/cache-jbosscache2/src/test/java/
core/trunk/cache-jbosscache2/src/test/java/org/
core/trunk/cache-jbosscache2/src/test/resources/
Modified:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/BasicRegionAdapter.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/JBossCacheRegionFactory.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/builder/InvalidationCacheInstanceManager.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/builder/MultiplexingCacheInstanceManager.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/entity/EntityRegionImpl.java
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/entity/ReadOnlyAccess.java
core/trunk/core/src/main/java/org/hibernate/cache/access/CollectionRegionAccessStrategy.java
core/trunk/core/src/main/java/org/hibernate/cache/access/EntityRegionAccessStrategy.java
core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java
Log:
jbosscache 2.x work
Modified:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/BasicRegionAdapter.java
===================================================================
---
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/BasicRegionAdapter.java 2007-07-26
02:12:05 UTC (rev 12822)
+++
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/BasicRegionAdapter.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -63,6 +63,14 @@
return regionName;
}
+ public Cache getCacheInstance() {
+ return jbcCache;
+ }
+
+ public Fqn getRegionFqn() {
+ return regionFqn;
+ }
+
public void destroy() throws CacheException {
try {
// NOTE : this is being used from the process of shutting down a
Modified:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/JBossCacheRegionFactory.java
===================================================================
---
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/JBossCacheRegionFactory.java 2007-07-26
02:12:05 UTC (rev 12822)
+++
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/JBossCacheRegionFactory.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -25,6 +25,7 @@
import org.hibernate.cache.RegionFactory;
import org.hibernate.cache.TimestampsRegion;
import org.hibernate.cache.jbc2.builder.InvalidationCacheInstanceManager;
+import org.hibernate.cache.jbc2.collection.CollectionRegionImpl;
import org.hibernate.cache.jbc2.entity.EntityRegionImpl;
import org.hibernate.cfg.Settings;
@@ -74,7 +75,7 @@
String regionName,
Properties properties,
CacheDataDescription metadata) throws CacheException {
- return null;
+ return new CollectionRegionImpl( cacheInstanceManager.getCollectionCacheInstance(),
regionName, metadata );
}
public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties
properties) throws CacheException {
Added:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/TransactionalDataRegionAdapter.java
===================================================================
---
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/TransactionalDataRegionAdapter.java
(rev 0)
+++
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/TransactionalDataRegionAdapter.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.cache.jbc2;
+
+import org.jboss.cache.Cache;
+
+import org.hibernate.cache.TransactionalDataRegion;
+import org.hibernate.cache.CacheDataDescription;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class TransactionalDataRegionAdapter extends BasicRegionAdapter implements
TransactionalDataRegion {
+ protected final CacheDataDescription metadata;
+
+ public TransactionalDataRegionAdapter(Cache jbcCache, String regionName,
CacheDataDescription metadata) {
+ super( jbcCache, regionName );
+ this.metadata = metadata;
+ }
+
+ /**
+ * Here, for JBossCache, we consider the cache to be transaction aware if the
underlying
+ * cache instance has a refernece to the transaction manager.
+ */
+ public boolean isTransactionAware() {
+ return jbcCache.getConfiguration().getRuntimeConfig().getTransactionManager() != null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public CacheDataDescription getCacheDataDescription() {
+ return metadata;
+ }
+}
Modified:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/builder/InvalidationCacheInstanceManager.java
===================================================================
---
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/builder/InvalidationCacheInstanceManager.java 2007-07-26
02:12:05 UTC (rev 12822)
+++
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/builder/InvalidationCacheInstanceManager.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -16,22 +16,25 @@
package org.hibernate.cache.jbc2.builder;
import java.util.Properties;
-
import javax.transaction.TransactionManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.util.PropertiesHelper;
+import org.hibernate.cache.CacheException;
import org.hibernate.cache.jbc2.CacheInstanceManager;
+import org.hibernate.cache.jbc2.util.CacheModeHelper;
import org.hibernate.cfg.Settings;
+import org.hibernate.util.PropertiesHelper;
/**
- * A {@link org.hibernate.cache.jbc2.CacheInstanceManager} implementation where we use a
single cache instance
+ * A {@link CacheInstanceManager} implementation where we use a single cache instance
* we assume to be configured for invalidation if operating on a cluster. Under that
* assumption, we can store all data into the same {@link Cache} instance.
+ * <p/>
+ * todo : this is built on the assumption that JBC clustered invalidation is changed to
keep the "cache node" around on the other "cluster nodes"
*
* @author Steve Ebersole
*/
@@ -77,6 +80,9 @@
* {@inheritDoc}
*/
public Cache getQueryCacheInstance() {
+ if ( CacheModeHelper.isClusteredInvalidation( cache ) ) {
+ throw new CacheException( "Query cache not supported for clustered
invalidation" );
+ }
return cache;
}
@@ -84,6 +90,9 @@
* {@inheritDoc}
*/
public Cache getTimestampsCacheInstance() {
+ if ( CacheModeHelper.isClusteredInvalidation( cache ) ) {
+ throw new CacheException( "Query cache not supported for clustered
invalidation" );
+ }
return cache;
}
Modified:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/builder/MultiplexingCacheInstanceManager.java
===================================================================
---
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/builder/MultiplexingCacheInstanceManager.java 2007-07-26
02:12:05 UTC (rev 12822)
+++
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/builder/MultiplexingCacheInstanceManager.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -30,9 +30,11 @@
/**
* Here we build separate {@link Cache} instances for each type of region, but
- * using the jgroups multiplexer under the covers to re-use the same group comm
- * stack.
- *
+ * using the jgroups multiplexer under the covers to re-use the same group
+ * communication stack.
+ * <p/>
+ * todo : this can get simplified once JBC implemants their "configuration
factory" (the stuff akin to channel factory)
+ *
* @author Steve Ebersole
*/
public class MultiplexingCacheInstanceManager implements CacheInstanceManager {
Added:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/collection/CollectionRegionImpl.java
===================================================================
---
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/collection/CollectionRegionImpl.java
(rev 0)
+++
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/collection/CollectionRegionImpl.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.cache.jbc2.collection;
+
+import org.jboss.cache.Cache;
+
+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.jbc2.TransactionalDataRegionAdapter;
+
+/**
+ * Defines the behavior of the collection cache regions for JBossCache.
+ *
+ * @author Steve Ebersole
+ */
+public class CollectionRegionImpl extends TransactionalDataRegionAdapter implements
CollectionRegion {
+ public CollectionRegionImpl(Cache jbcCache, String regionName, CacheDataDescription
metadata) {
+ super( jbcCache, regionName, metadata );
+ }
+
+ public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws
CacheException {
+ if ( AccessType.READ_ONLY.equals( accessType ) ) {
+ return new ReadOnlyAccess( this );
+ }
+ if ( AccessType.TRANSACTIONAL.equals( accessType ) ) {
+ return new TransactionalAccess( this );
+ }
+
+ // todo : add support for READ_WRITE ( + NONSTRICT_READ_WRITE ??? )
+
+ throw new CacheException( "unsupported access type [" + accessType.getName()
+ "]" );
+ }
+}
Added:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/collection/ReadOnlyAccess.java
===================================================================
---
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/collection/ReadOnlyAccess.java
(rev 0)
+++
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/collection/ReadOnlyAccess.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.cache.jbc2.collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.hibernate.cache.access.SoftLock;
+import org.hibernate.cache.CacheException;
+
+/**
+ * This defines the strategy for transactional access to enity data in JBossCache using
its 2.x APIs
+ * <p/>
+ * read-only access to a JBossCache really is still transactional, just with
+ * the extra semantic or guarentee that we will not update data.
+ *
+ * @author Steve Ebersole
+ */
+public class ReadOnlyAccess extends TransactionalAccess {
+ private static final Log log = LogFactory.getLog( ReadOnlyAccess.class );
+
+ public ReadOnlyAccess(CollectionRegionImpl region) {
+ super( region );
+ }
+
+ public SoftLock lockItem(Object key, Object version) throws CacheException {
+ throw new UnsupportedOperationException( "Illegal attempt to edit read only
item" );
+ }
+
+ public SoftLock lockRegion() throws CacheException {
+ throw new UnsupportedOperationException( "Illegal attempt to edit read only
region" );
+ }
+
+ public void unlockItem(Object key, SoftLock lock) throws CacheException {
+ log.error( "Illegal attempt to edit read only item" );
+ }
+
+ public void unlockRegion(SoftLock lock) throws CacheException {
+ log.error( "Illegal attempt to edit read only region" );
+ }
+
+ public boolean update(
+ Object key,
+ Object value,
+ Object currentVersion,
+ Object previousVersion) throws CacheException {
+ throw new UnsupportedOperationException( "Illegal attempt to edit read only
item" );
+ }
+
+ 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" );
+ }
+}
Added:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/collection/TransactionalAccess.java
===================================================================
---
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/collection/TransactionalAccess.java
(rev 0)
+++
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/collection/TransactionalAccess.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.cache.jbc2.collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.hibernate.cache.access.CollectionRegionAccessStrategy;
+import org.hibernate.cache.access.SoftLock;
+import org.hibernate.cache.CollectionRegion;
+import org.hibernate.cache.CacheException;
+
+/**
+ * todo : implement
+ *
+ * @author Steve Ebersole
+ */
+public class TransactionalAccess implements CollectionRegionAccessStrategy {
+ private static final Log log = LogFactory.getLog( TransactionalAccess.class );
+
+ private final CollectionRegionImpl region;
+
+ public TransactionalAccess(CollectionRegionImpl region) {
+ this.region = region;
+ }
+
+ public CollectionRegion getRegion() {
+ return region;
+ }
+
+ public Object get(Object key, long txTimestamp) throws CacheException {
+ return null;
+ }
+
+ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version)
throws CacheException {
+ return false;
+ }
+
+ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version,
boolean minimalPutOverride)
+ throws CacheException {
+ return false;
+ }
+
+ public SoftLock lockItem(Object key, Object version) throws CacheException {
+ return null;
+ }
+
+ public SoftLock lockRegion() throws CacheException {
+ return null;
+ }
+
+ public void unlockItem(Object key, SoftLock lock) throws CacheException {
+ }
+
+ public void unlockRegion(SoftLock lock) throws CacheException {
+ }
+
+ public void remove(Object key) throws CacheException {
+ }
+
+ public void removeAll() throws CacheException {
+ }
+
+ public void evict(Object key) throws CacheException {
+ }
+
+ public void evictAll() throws CacheException {
+ }
+}
Modified:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/entity/EntityRegionImpl.java
===================================================================
---
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/entity/EntityRegionImpl.java 2007-07-26
02:12:05 UTC (rev 12822)
+++
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/entity/EntityRegionImpl.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -16,63 +16,38 @@
package org.hibernate.cache.jbc2.entity;
import org.jboss.cache.Cache;
-import org.jboss.cache.Fqn;
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.jbc2.BasicRegionAdapter;
+import org.hibernate.cache.jbc2.TransactionalDataRegionAdapter;
-
/**
* Defines the behavior of the entity cache regions for JBossCache.
*
* @author Steve Ebersole
*/
-public class EntityRegionImpl extends BasicRegionAdapter implements EntityRegion {
- private final CacheDataDescription metadata;
+public class EntityRegionImpl extends TransactionalDataRegionAdapter implements
EntityRegion {
public EntityRegionImpl(Cache jbcCache, String regionName, CacheDataDescription
metadata) {
- super( jbcCache, regionName );
- this.metadata = metadata;
+ super( jbcCache, regionName, metadata );
}
/**
* {@inheritDoc}
*/
public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws
CacheException {
- // todo : allow the other strategies, which will require a non-transactional cache
instance
- if ( ! ( AccessType.READ_ONLY.equals( accessType ) || AccessType.TRANSACTIONAL.equals(
accessType ) ) ) {
- throw new CacheException(
- "TreeCacheRegionFactory only supports " + AccessType.READ_ONLY.getName() +
" or " +
- AccessType.TRANSACTIONAL + " access strategies [" + accessType.getName()
+ "]"
- );
+ if ( AccessType.READ_ONLY.equals( accessType ) ) {
+ return new ReadOnlyAccess( this );
}
- return null;
- }
+ if ( AccessType.TRANSACTIONAL.equals( accessType ) ) {
+ return new TransactionalAccess( this );
+ }
- /**
- * Here, for JBossCache, we consider the cache to be transaction aware if the
underlying
- * cache instance has a refernece to the transaction manager.
- */
- public boolean isTransactionAware() {
- return jbcCache.getConfiguration().getRuntimeConfig().getTransactionManager() != null;
- }
+ // todo : add support for READ_WRITE ( + NONSTRICT_READ_WRITE ??? )
- /**
- * {@inheritDoc}
- */
- public CacheDataDescription getCacheDataDescription() {
- return metadata;
+ throw new CacheException( "unsupported access type [" + accessType.getName()
+ "]" );
}
-
- Cache getCacheInstance() {
- return jbcCache;
- }
-
- Fqn getRegionFqn() {
- return regionFqn;
- }
}
Modified:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/entity/ReadOnlyAccess.java
===================================================================
---
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/entity/ReadOnlyAccess.java 2007-07-26
02:12:05 UTC (rev 12822)
+++
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/entity/ReadOnlyAccess.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -15,107 +15,49 @@
*/
package org.hibernate.cache.jbc2.entity;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.lock.TimeoutException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.hibernate.cache.access.EntityRegionAccessStrategy;
import org.hibernate.cache.access.SoftLock;
-import org.hibernate.cache.EntityRegion;
import org.hibernate.cache.CacheException;
/**
- * {@inheritDoc}
+ * This defines the strategy for transactional access to enity data in JBossCache using
its 2.x APIs
+ * <p/>
+ * read-only access to a JBossCache really is still transactional, just with
+ * the extra semantic or guarentee that we will not update data.
*
* @author Steve Ebersole
*/
-public class ReadOnlyAccess implements EntityRegionAccessStrategy {
+public class ReadOnlyAccess extends TransactionalAccess {
private static final Log log = LogFactory.getLog( ReadOnlyAccess.class );
- private final EntityRegionImpl region;
-
public ReadOnlyAccess(EntityRegionImpl region) {
- this.region = region;
+ super( region );
}
- public EntityRegion getRegion() {
- return region;
- }
-
- public Object get(Object key, long txTimestamp) throws CacheException {
- try {
- return region.getCacheInstance().get( region.getRegionFqn(), EntityRegionImpl.ITEM );
- }
- catch ( Exception e ) {
- throw new CacheException( e );
- }
- }
-
- public boolean putFromLoad(
- Object key,
- Object value,
- long txTimestamp,
- Object version) throws CacheException {
- try {
- region.getCacheInstance().putForExternalRead( region.getRegionFqn(), key, value );
- return true;
- }
- catch ( TimeoutException te) {
- //ignore!
- log.debug( "ignoring write lock acquisition failure" );
- return false;
- }
- catch ( Throwable t ) {
- throw new CacheException( t );
- }
- }
-
- public boolean putFromLoad(
- Object key,
- Object value,
- long txTimestamp,
- Object version,
- boolean minimalPutOverride) throws CacheException {
- return putFromLoad( key, value, txTimestamp, version );
- }
-
public SoftLock lockItem(Object key, Object version) throws CacheException {
- throw new UnsupportedOperationException( "Illegal attempt to lock (edit) read only
item" );
+ throw new UnsupportedOperationException( "Illegal attempt to edit read only
item" );
}
public SoftLock lockRegion() throws CacheException {
- throw new UnsupportedOperationException( "Illegal attempt to lock (edit) read only
region" );
+ throw new UnsupportedOperationException( "Illegal attempt to edit read only
region" );
}
public void unlockItem(Object key, SoftLock lock) throws CacheException {
- log.error( "Illegal attempt to lock (edit) read only item" );
+ log.error( "Illegal attempt to edit read only item" );
}
public void unlockRegion(SoftLock lock) throws CacheException {
- log.error( "Illegal attempt to lock (edit) read only region" );
+ log.error( "Illegal attempt to edit read only region" );
}
- public boolean insert(Object key, Object value, Object version) throws CacheException {
- try {
- region.getCacheInstance().put( new Fqn( region.getRegionFqn(), key ),
EntityRegionImpl.ITEM, value );
- }
- catch (Exception e) {
- throw new CacheException(e);
- }
- return true;
- }
-
- public boolean afterInsert(Object key, Object value, Object version) throws
CacheException {
- return false;
- }
-
public boolean update(
Object key,
Object value,
Object currentVersion,
Object previousVersion) throws CacheException {
- throw new UnsupportedOperationException( "Illegal attempt to lock (edit) read only
item" );
+ throw new UnsupportedOperationException( "Illegal attempt to edit read only
item" );
}
public boolean afterUpdate(
@@ -124,34 +66,6 @@
Object currentVersion,
Object previousVersion,
SoftLock lock) throws CacheException {
- throw new UnsupportedOperationException( "Illegal attempt to lock (edit) read only
item" );
+ throw new UnsupportedOperationException( "Illegal attempt to edit read only
item" );
}
-
- public void remove(Object key) throws CacheException {
- try {
- region.getCacheInstance().remove( region.getRegionFqn(), key );
- }
- catch ( Exception e ) {
- throw new CacheException( e );
- }
- }
-
- public void removeAll() throws CacheException {
- try {
- region.getCacheInstance().removeNode( region.getRegionFqn() );
- }
- catch ( Exception e ) {
- throw new CacheException( e );
- }
- }
-
- public void evict(Object key) throws CacheException {
- }
-
- public void evictAll() throws CacheException {
- }
-
- public void destroy() {
- region.destroy();
- }
}
Added:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/entity/TransactionalAccess.java
===================================================================
---
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/entity/TransactionalAccess.java
(rev 0)
+++
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/entity/TransactionalAccess.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.cache.jbc2.entity;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.lock.TimeoutException;
+
+import org.hibernate.cache.access.EntityRegionAccessStrategy;
+import org.hibernate.cache.access.SoftLock;
+import org.hibernate.cache.EntityRegion;
+import org.hibernate.cache.CacheException;
+
+/**
+ * This defines the strategy for transactional access to enity data
+ * in JBossCache using its 2.x APIs
+ *
+ * @author Steve Ebersole
+ */
+public class TransactionalAccess implements EntityRegionAccessStrategy {
+ private static final Log log = LogFactory.getLog( TransactionalAccess.class );
+
+ private final EntityRegionImpl region;
+
+ public TransactionalAccess(EntityRegionImpl region) {
+ this.region = region;
+ }
+
+ public EntityRegion getRegion() {
+ return region;
+ }
+
+ public Object get(Object key, long txTimestamp) throws CacheException {
+ try {
+ return region.getCacheInstance().get( region.getRegionFqn(), EntityRegionImpl.ITEM );
+ }
+ catch ( Exception e ) {
+ throw new CacheException( e );
+ }
+ }
+
+ public boolean putFromLoad(
+ Object key,
+ Object value,
+ long txTimestamp,
+ Object version) throws CacheException {
+ try {
+ region.getCacheInstance().putForExternalRead( new Fqn( region.getRegionFqn(), key ),
EntityRegionImpl.ITEM, value );
+ return true;
+ }
+ catch ( TimeoutException te) {
+ //ignore!
+ log.debug( "ignoring write lock acquisition failure" );
+ return false;
+ }
+ catch ( Throwable t ) {
+ throw new CacheException( t );
+ }
+ }
+
+ public boolean putFromLoad(
+ Object key,
+ Object value,
+ long txTimestamp,
+ Object version,
+ boolean minimalPutOverride) throws CacheException {
+ if ( minimalPutOverride && get( key, txTimestamp ) != null ) {
+ if ( log.isDebugEnabled() ) {
+ log.debug( "item already cached: " + key );
+ }
+ return false;
+ }
+ return putFromLoad( key, value, txTimestamp, version );
+ }
+
+ public SoftLock lockItem(Object key, Object version) throws CacheException {
+ return null;
+ }
+
+ public SoftLock lockRegion() throws CacheException {
+ return null;
+ }
+
+ public void unlockItem(Object key, SoftLock lock) throws CacheException {
+ }
+
+ public void unlockRegion(SoftLock lock) throws CacheException {
+ }
+
+ public boolean insert(Object key, Object value, Object version) throws CacheException {
+ try {
+ region.getCacheInstance().put( new Fqn( region.getRegionFqn(), key ),
EntityRegionImpl.ITEM, value );
+ }
+ catch ( Throwable t ) {
+ throw new CacheException( t );
+ }
+ return true;
+ }
+
+ public boolean afterInsert(Object key, Object value, Object version) throws
CacheException {
+ return false;
+ }
+
+ public boolean update(Object key, Object value, Object currentVersion, Object
previousVersion)
+ throws CacheException {
+ try {
+ region.getCacheInstance().put( new Fqn( region.getRegionFqn(), key ),
EntityRegionImpl.ITEM, value );
+ }
+ catch ( Throwable t ) {
+ throw new CacheException( t );
+ }
+ return true;
+ }
+
+ public boolean afterUpdate(Object key, Object value, Object currentVersion, Object
previousVersion, SoftLock lock)
+ throws CacheException {
+ return false;
+ }
+
+ public void remove(Object key) throws CacheException {
+ try {
+ region.getCacheInstance().removeNode( new Fqn( region.getRegionFqn(), key ) );
+ }
+ catch ( Exception e ) {
+ throw new CacheException( e );
+ }
+ }
+
+ public void removeAll() throws CacheException {
+ try {
+ region.getCacheInstance().removeNode( region.getRegionFqn() );
+ }
+ catch ( Exception e ) {
+ throw new CacheException( e );
+ }
+ }
+
+ public void evict(Object key) throws CacheException {
+ remove( key );
+ }
+
+ public void evictAll() throws CacheException {
+ removeAll();
+ }
+}
Added:
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/util/CacheModeHelper.java
===================================================================
---
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/util/CacheModeHelper.java
(rev 0)
+++
core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/util/CacheModeHelper.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.hibernate.cache.jbc2.util;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.config.Configuration;
+
+/**
+ * Helper for dealing with JBossCache {@link Configuration.CacheMode}.
+ *
+ * @author Steve Ebersole
+ */
+public class CacheModeHelper {
+ /**
+ * Disallow external instantiation of CacheModeHelper.
+ */
+ private CacheModeHelper() {
+ }
+
+ /**
+ * Is this cache participating in a cluster with invalidation?
+ *
+ * @param cache The cache to check.
+ * @return True if the cache is configured for synchronous/asynchronous invalidation;
false
+ * otherwise.
+ */
+ public static boolean isClusteredInvalidation(Cache cache) {
+ return isClusteredInvalidation( cache.getConfiguration().getCacheMode() );
+ }
+
+ /**
+ * Does this cache mode indicate clustered invalidation?
+ *
+ * @param cacheMode The cache to check
+ * @return True if the cache mode is confiogured for synchronous/asynchronous
invalidation; false
+ * otherwise.
+ */
+ public static boolean isClusteredInvalidation(Configuration.CacheMode cacheMode) {
+ return cacheMode == Configuration.CacheMode.REPL_ASYNC || cacheMode ==
Configuration.CacheMode.REPL_SYNC;
+ }
+}
Modified:
core/trunk/core/src/main/java/org/hibernate/cache/access/CollectionRegionAccessStrategy.java
===================================================================
---
core/trunk/core/src/main/java/org/hibernate/cache/access/CollectionRegionAccessStrategy.java 2007-07-26
02:12:05 UTC (rev 12822)
+++
core/trunk/core/src/main/java/org/hibernate/cache/access/CollectionRegionAccessStrategy.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -1,7 +1,5 @@
package org.hibernate.cache.access;
-import java.util.Comparator;
-
import org.hibernate.cache.CacheException;
import org.hibernate.cache.CollectionRegion;
@@ -148,9 +146,4 @@
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.Region}
*/
public void evictAll() throws CacheException;
-
- /**
- * Clean up all resources.
- */
- public void destroy();
}
Modified:
core/trunk/core/src/main/java/org/hibernate/cache/access/EntityRegionAccessStrategy.java
===================================================================
---
core/trunk/core/src/main/java/org/hibernate/cache/access/EntityRegionAccessStrategy.java 2007-07-26
02:12:05 UTC (rev 12822)
+++
core/trunk/core/src/main/java/org/hibernate/cache/access/EntityRegionAccessStrategy.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -203,9 +203,4 @@
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.Region}
*/
public void evictAll() throws CacheException;
-
- /**
- * Clean up all resources.
- */
- public void destroy();
}
Modified: core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java 2007-07-26
02:12:05 UTC (rev 12822)
+++ core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java 2007-07-26
03:53:09 UTC (rev 12823)
@@ -772,7 +772,7 @@
while ( iter.hasNext() ) {
EntityPersister p = (EntityPersister) iter.next();
if ( p.hasCache() ) {
- p.getCacheAccessStrategy().destroy();
+ p.getCacheAccessStrategy().getRegion().destroy();
}
}
@@ -780,7 +780,7 @@
while ( iter.hasNext() ) {
CollectionPersister p = (CollectionPersister) iter.next();
if ( p.hasCache() ) {
- p.getCacheAccessStrategy().destroy();
+ p.getCacheAccessStrategy().getRegion().destroy();
}
}