[hibernate-commits] Hibernate SVN: r18614 - in core/trunk: annotations/src/main/java/org/hibernate/cfg and 7 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Sun Jan 24 12:07:29 EST 2010


Author: steve.ebersole at jboss.com
Date: 2010-01-24 12:07:28 -0500 (Sun, 24 Jan 2010)
New Revision: 18614

Modified:
   core/trunk/annotations/src/main/java/org/hibernate/annotations/CacheConcurrencyStrategy.java
   core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
   core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
   core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java
   core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
   core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/ClusterAwareRegionFactory.java
   core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/JBossCacheRegionFactory.java
   core/trunk/core/src/main/java/org/hibernate/cache/RegionFactory.java
   core/trunk/core/src/main/java/org/hibernate/cache/impl/NoCachingRegionFactory.java
   core/trunk/core/src/main/java/org/hibernate/cache/impl/bridge/RegionFactoryCacheProviderBridge.java
Log:
HHH-4659 - Add support for standard declarative cache (@Cacheable)


Modified: core/trunk/annotations/src/main/java/org/hibernate/annotations/CacheConcurrencyStrategy.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/annotations/CacheConcurrencyStrategy.java	2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/annotations/src/main/java/org/hibernate/annotations/CacheConcurrencyStrategy.java	2010-01-24 17:07:28 UTC (rev 18614)
@@ -23,15 +23,67 @@
  */
 package org.hibernate.annotations;
 
+import org.hibernate.cache.access.AccessType;
+
 /**
  * Cache concurrency strategy
  *
  * @author Emmanuel Bernard
  */
 public enum CacheConcurrencyStrategy {
-	NONE,
-	READ_ONLY,
-	NONSTRICT_READ_WRITE,
-	READ_WRITE,
-	TRANSACTIONAL
+	NONE( null ),
+	READ_ONLY( AccessType.READ_ONLY ),
+	NONSTRICT_READ_WRITE( AccessType.NONSTRICT_READ_WRITE ),
+	READ_WRITE( AccessType.READ_WRITE ),
+	TRANSACTIONAL( AccessType.TRANSACTIONAL );
+
+	private final AccessType accessType;
+
+	private CacheConcurrencyStrategy(AccessType accessType) {
+		this.accessType = accessType;
+	}
+
+	public static CacheConcurrencyStrategy fromAccessType(AccessType accessType) {
+		final String name = accessType == null ? null : accessType.getName();
+		if ( AccessType.READ_ONLY.getName().equals( name ) ) {
+			return READ_ONLY;
+		}
+		else if ( AccessType.READ_WRITE.getName().equals( name ) ) {
+			return READ_WRITE;
+		}
+		else if ( AccessType.NONSTRICT_READ_WRITE.getName().equals( name ) ) {
+			return NONSTRICT_READ_WRITE;
+		}
+		else if ( AccessType.TRANSACTIONAL.getName().equals( name ) ) {
+			return TRANSACTIONAL;
+		}
+		else {
+			return NONE;
+		}
+	}
+
+	public static CacheConcurrencyStrategy parse(String name) {
+		if ( READ_ONLY.accessType.getName().equalsIgnoreCase( name ) ) {
+			return READ_ONLY;
+		}
+		else if ( READ_WRITE.accessType.getName().equalsIgnoreCase( name ) ) {
+			return READ_WRITE;
+		}
+		else if ( NONSTRICT_READ_WRITE.accessType.getName().equalsIgnoreCase( name ) ) {
+			return NONSTRICT_READ_WRITE;
+		}
+		else if ( TRANSACTIONAL.accessType.getName().equalsIgnoreCase( name ) ) {
+			return TRANSACTIONAL;
+		}
+		else if ( "none".equalsIgnoreCase( name ) ) {
+			return NONE;
+		}
+		else {
+			return null;
+		}
+	}
+
+	public AccessType toAccessType() {
+		return accessType;
+	}
 }

Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java	2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java	2010-01-24 17:07:28 UTC (rev 18614)
@@ -814,12 +814,33 @@
 
 	private static CacheConcurrencyStrategy DEFAULT_CACHE_CONCURRENCY_STRATEGY;
 
+	static void prepareDefaultCacheConcurrencyStrategy(Properties properties) {
+		if ( DEFAULT_CACHE_CONCURRENCY_STRATEGY != null ) {
+			log.info( "Default cache concurrency strategy already defined" );
+			return;
+		}
+
+		if ( ! properties.containsKey( AnnotationConfiguration.DEFAULT_CACHE_CONCURRENCY_STRATEGY ) ) {
+			log.trace( "Given properties did not contain any default cache concurrency strategy setting" );
+			return;
+		}
+
+		final String strategyName = properties.getProperty( AnnotationConfiguration.DEFAULT_CACHE_CONCURRENCY_STRATEGY );
+		log.trace( "Discovered default cache concurrency strategy via config [" + strategyName + "]" );
+		CacheConcurrencyStrategy strategy = CacheConcurrencyStrategy.parse( strategyName );
+		if ( strategy == null ) {
+			log.trace( "Discovered default cache concurrency strategy specified nothing" );
+			return;
+		}
+
+		log.info( "Setting default cache concurrency strategy via config [" + strategy.name() + "]" );
+		DEFAULT_CACHE_CONCURRENCY_STRATEGY = strategy;
+	}
+
 	private static CacheConcurrencyStrategy determineCacheConcurrencyStrategy(ExtendedMappings mappings) {
 		if ( DEFAULT_CACHE_CONCURRENCY_STRATEGY == null ) {
-// todo need to figure out how we will determine the default cache access-type/concurrency-strategy
-//			RegionFactory cacheRegionFactory = SettingsFactory.createRegionFactory( mappings.getConfigurationProperties(), true );
-//			DEFAULT_CACHE_CONCURRENCY_STRATEGY = cacheRegionFactory.[getDefault...]
-			DEFAULT_CACHE_CONCURRENCY_STRATEGY = CacheConcurrencyStrategy.TRANSACTIONAL;
+			final RegionFactory cacheRegionFactory = SettingsFactory.createRegionFactory( mappings.getConfigurationProperties(), true );
+			DEFAULT_CACHE_CONCURRENCY_STRATEGY = CacheConcurrencyStrategy.fromAccessType( cacheRegionFactory.getDefaultAccessType() );
 		}
 		return DEFAULT_CACHE_CONCURRENCY_STRATEGY;
 	}

Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java	2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java	2010-01-24 17:07:28 UTC (rev 18614)
@@ -106,6 +106,13 @@
 	private Logger log = LoggerFactory.getLogger( AnnotationConfiguration.class );
 
 	/**
+	 * Setting used to give the name of the default {@link org.hibernate.annotations.CacheConcurrencyStrategy}
+	 * to use when either {@link javax.persistence.Cacheable @Cacheable} or
+	 * {@link Cache @Cache} is used.  {@link Cache @Cache(strategy=".."} is used to override.
+	 */
+	public static final String DEFAULT_CACHE_CONCURRENCY_STRATEGY = "org.hibernate.cache.default_cache_concurrency_strategy";
+
+	/**
 	 * Class name of the class needed to enable Search.
 	 */
 	private static final String SEARCH_STARTUP_CLASS = "org.hibernate.search.event.EventListenerRegister";

Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java	2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java	2010-01-24 17:07:28 UTC (rev 18614)
@@ -771,20 +771,8 @@
 	}
 
 	public static String getCacheConcurrencyStrategy(CacheConcurrencyStrategy strategy) {
-		switch ( strategy ) {
-			case NONE:
-				return null;
-			case READ_ONLY:
-				return org.hibernate.cache.access.AccessType.READ_ONLY.getName();
-			case READ_WRITE:
-				return org.hibernate.cache.access.AccessType.READ_WRITE.getName();
-			case NONSTRICT_READ_WRITE:
-				return org.hibernate.cache.access.AccessType.NONSTRICT_READ_WRITE.getName();
-			case TRANSACTIONAL:
-				return org.hibernate.cache.access.AccessType.TRANSACTIONAL.getName();
-			default:
-				throw new AssertionFailure( "CacheConcurrencyStrategy unknown: " + strategy );
-		}
+		org.hibernate.cache.access.AccessType accessType = strategy.toAccessType();
+		return accessType == null ? null : accessType.getName();
 	}
 
 	public void addFilter(String name, String condition) {

Modified: core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
===================================================================
--- core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java	2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java	2010-01-24 17:07:28 UTC (rev 18614)
@@ -18,6 +18,7 @@
 import org.hibernate.cache.QueryResultsRegion;
 import org.hibernate.cache.RegionFactory;
 import org.hibernate.cache.TimestampsRegion;
+import org.hibernate.cache.access.AccessType;
 import org.hibernate.cache.infinispan.collection.CollectionRegionImpl;
 import org.hibernate.cache.infinispan.entity.EntityRegionImpl;
 import org.hibernate.cache.infinispan.query.QueryResultsRegionImpl;
@@ -205,7 +206,12 @@
       return true;
    }
 
-   /**
+	@Override
+	public AccessType getDefaultAccessType() {
+		return AccessType.TRANSACTIONAL;
+	}
+
+	/**
     * {@inheritDoc}
     */
    public long nextTimestamp() {

Modified: core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/ClusterAwareRegionFactory.java
===================================================================
--- core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/ClusterAwareRegionFactory.java	2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/ClusterAwareRegionFactory.java	2010-01-24 17:07:28 UTC (rev 18614)
@@ -31,6 +31,7 @@
 import org.hibernate.cache.QueryResultsRegion;
 import org.hibernate.cache.RegionFactory;
 import org.hibernate.cache.TimestampsRegion;
+import org.hibernate.cache.access.AccessType;
 import org.hibernate.cache.infinispan.InfinispanRegionFactory;
 import org.hibernate.cfg.Settings;
 import org.infinispan.manager.CacheManager;
@@ -117,7 +118,12 @@
       return delegate.isMinimalPutsEnabledByDefault();
    }
 
-   public long nextTimestamp() {
+	@Override
+	public AccessType getDefaultAccessType() {
+		return AccessType.TRANSACTIONAL;
+	}
+
+	public long nextTimestamp() {
       return delegate.nextTimestamp();
    }
 }

Modified: core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/JBossCacheRegionFactory.java
===================================================================
--- core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/JBossCacheRegionFactory.java	2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/cache-jbosscache/src/main/java/org/hibernate/cache/jbc/JBossCacheRegionFactory.java	2010-01-24 17:07:28 UTC (rev 18614)
@@ -32,6 +32,7 @@
 import org.hibernate.cache.QueryResultsRegion;
 import org.hibernate.cache.RegionFactory;
 import org.hibernate.cache.TimestampsRegion;
+import org.hibernate.cache.access.AccessType;
 import org.hibernate.cache.jbc.builder.JndiSharedCacheInstanceManager;
 import org.hibernate.cache.jbc.builder.SharedCacheInstanceManager;
 import org.hibernate.cache.jbc.collection.CollectionRegionImpl;
@@ -116,7 +117,11 @@
         return true;
     }
 
-    public long nextTimestamp() {
+	public AccessType getDefaultAccessType() {
+		return AccessType.TRANSACTIONAL;
+	}
+
+	public long nextTimestamp() {
         return System.currentTimeMillis() / 100;
     }
 

Modified: core/trunk/core/src/main/java/org/hibernate/cache/RegionFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cache/RegionFactory.java	2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/core/src/main/java/org/hibernate/cache/RegionFactory.java	2010-01-24 17:07:28 UTC (rev 18614)
@@ -26,6 +26,7 @@
 
 import java.util.Properties;
 
+import org.hibernate.cache.access.AccessType;
 import org.hibernate.cfg.Settings;
 
 /**
@@ -77,6 +78,14 @@
 	public boolean isMinimalPutsEnabledByDefault();
 
 	/**
+	 * Get the default access type for {@link EntityRegion entity} and
+	 * {@link CollectionRegion collection} regions.
+	 *
+	 * @return This factory's default access type.
+	 */
+	public AccessType getDefaultAccessType();
+
+	/**
 	 * Generate a timestamp.
 	 * <p/>
 	 * This is generally used for cache content locking/unlocking purposes

Modified: core/trunk/core/src/main/java/org/hibernate/cache/impl/NoCachingRegionFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cache/impl/NoCachingRegionFactory.java	2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/core/src/main/java/org/hibernate/cache/impl/NoCachingRegionFactory.java	2010-01-24 17:07:28 UTC (rev 18614)
@@ -1,10 +1,10 @@
 /*
  * Hibernate, Relational Persistence for Idiomatic Java
  *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
  * indicated by the @author tags or express copyright attribution
  * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
  *
  * This copyrighted material is made available to anyone wishing to use, modify,
  * copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
  * Free Software Foundation, Inc.
  * 51 Franklin Street, Fifth Floor
  * Boston, MA  02110-1301  USA
- *
  */
 package org.hibernate.cache.impl;
 
@@ -34,6 +33,7 @@
 import org.hibernate.cache.TimestampsRegion;
 import org.hibernate.cache.NoCachingEnabledException;
 import org.hibernate.cache.CacheDataDescription;
+import org.hibernate.cache.access.AccessType;
 import org.hibernate.cfg.Settings;
 
 /**
@@ -57,6 +57,10 @@
 		return false;
 	}
 
+	public AccessType getDefaultAccessType() {
+		return null;
+	}
+
 	public long nextTimestamp() {
 		return System.currentTimeMillis() / 100;
 	}

Modified: core/trunk/core/src/main/java/org/hibernate/cache/impl/bridge/RegionFactoryCacheProviderBridge.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cache/impl/bridge/RegionFactoryCacheProviderBridge.java	2010-01-23 01:53:20 UTC (rev 18613)
+++ core/trunk/core/src/main/java/org/hibernate/cache/impl/bridge/RegionFactoryCacheProviderBridge.java	2010-01-24 17:07:28 UTC (rev 18614)
@@ -1,10 +1,10 @@
 /*
  * Hibernate, Relational Persistence for Idiomatic Java
  *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
  * indicated by the @author tags or express copyright attribution
  * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
  *
  * This copyrighted material is made available to anyone wishing to use, modify,
  * copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
  * Free Software Foundation, Inc.
  * 51 Franklin Street, Fifth Floor
  * Boston, MA  02110-1301  USA
- *
  */
 package org.hibernate.cache.impl.bridge;
 
@@ -38,6 +37,7 @@
 import org.hibernate.cache.NoCacheProvider;
 import org.hibernate.cache.TimestampsRegion;
 import org.hibernate.cache.CacheDataDescription;
+import org.hibernate.cache.access.AccessType;
 import org.hibernate.util.PropertiesHelper;
 import org.hibernate.util.ReflectHelper;
 import org.hibernate.cfg.Environment;
@@ -81,6 +81,14 @@
 		return cacheProvider.isMinimalPutsEnabledByDefault();
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
+	public AccessType getDefaultAccessType() {
+		// we really have no idea
+		return null;
+	}
+
 	public long nextTimestamp() {
 		return cacheProvider.nextTimestamp();
 	}



More information about the hibernate-commits mailing list