[jboss-cvs] JBossAS SVN: r63775 - in trunk/ejb3/src: main/org/jboss/ejb3/entity and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jul 2 12:29:44 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-07-02 12:29:44 -0400 (Mon, 02 Jul 2007)
New Revision: 63775
Added:
trunk/ejb3/src/main/org/jboss/ejb3/entity/SecondLevelCacheUtil.java
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
trunk/ejb3/src/main/org/jboss/ejb3/entity/JBCCache.java
trunk/ejb3/src/main/org/jboss/ejb3/entity/JBCCacheFactory.java
trunk/ejb3/src/main/org/jboss/ejb3/entity/OptimisticJBCCache.java
trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/Customer.java
Log:
[EJBTHREE-955] Port EJBTHREE-954 to trunk
Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java 2007-07-02 16:23:37 UTC (rev 63774)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java 2007-07-02 16:29:44 UTC (rev 63775)
@@ -53,6 +53,7 @@
import org.jboss.ejb3.enc.MessageDestinationResolver;
import org.jboss.ejb3.entity.PersistenceUnitDeployment;
import org.jboss.ejb3.entity.PersistenceXmlLoader;
+import org.jboss.ejb3.entity.SecondLevelCacheUtil;
import org.jboss.ejb3.metamodel.EjbJarDD;
import org.jboss.ejb3.metamodel.EjbJarDDObjectFactory;
import org.jboss.ejb3.metamodel.JBossDDObjectFactory;
@@ -537,6 +538,17 @@
{
String earShortName = deploymentScope == null ? null : deploymentScope.getShortName();
boolean isScoped = ejbContainers.size() > 0;
+
+ // Ensure 2nd level cache entries are segregated from other deployments
+ String cache_prefix = metadata.getProps().getProperty(SecondLevelCacheUtil.HIBERNATE_CACHE_REGION_PREFIX);
+ if (cache_prefix == null)
+ {
+ // Create a region_prefix for the 2nd level cache to ensure
+ // deployments are segregated
+ String jarName = isScoped ? unit.getShortName() : null;
+ cache_prefix = SecondLevelCacheUtil.createCacheRegionPrefix(earShortName, jarName, metadata.getName());
+ metadata.getProps().setProperty(SecondLevelCacheUtil.HIBERNATE_CACHE_REGION_PREFIX, cache_prefix);
+ }
PersistenceUnitDeployment deployment = new PersistenceUnitDeployment(initialContext, this, explicitEntityClasses, persistenceXmlUrl, metadata, earShortName,
unit.getShortName(), isScoped);
PersistenceUnitRegistry.register(deployment);
Modified: trunk/ejb3/src/main/org/jboss/ejb3/entity/JBCCache.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/entity/JBCCache.java 2007-07-02 16:23:37 UTC (rev 63774)
+++ trunk/ejb3/src/main/org/jboss/ejb3/entity/JBCCache.java 2007-07-02 16:29:44 UTC (rev 63775)
@@ -1,3 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.ejb3.entity;
import java.util.HashMap;
@@ -14,7 +35,6 @@
import org.hibernate.cache.Cache;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.StandardQueryCache;
-import org.hibernate.cache.UpdateTimestampsCache;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.Node;
@@ -41,11 +61,12 @@
private final TransactionManager transactionManager;
private boolean localWritesOnly;
- public JBCCache(org.jboss.cache.Cache cache, String regionName, TransactionManager transactionManager)
+ public JBCCache(org.jboss.cache.Cache cache, String regionName,
+ String regionPrefix, TransactionManager transactionManager)
throws CacheException {
this.cache = cache;
this.regionName = regionName;
- this.regionFqn = Fqn.fromString( regionName.replace( '.', '/' ) );
+ this.regionFqn = Fqn.fromString(SecondLevelCacheUtil.createRegionFqn(regionName, regionPrefix));
this.transactionManager = transactionManager;
if (cache.getConfiguration().isUseRegionBasedMarshalling())
{
@@ -69,6 +90,10 @@
cache.getConfiguration().setFetchInMemoryState(fetchState);
}
}
+ else
+ {
+ log.debug("TreeCache is not configured for region based marshalling");
+ }
}
public Object get(Object key) throws CacheException {
@@ -196,7 +221,7 @@
ctx.setOptionOverrides(opt);
cache.removeNode( regionFqn );
- if (cache.getConfiguration().isUseRegionBasedMarshalling() && !isSharedClassLoaderRegion(regionName))
+ if (cache.getConfiguration().isUseRegionBasedMarshalling() && !SecondLevelCacheUtil.isSharedClassLoaderRegion(regionName))
{
inactivateCacheRegion();
}
@@ -279,12 +304,6 @@
public String toString() {
return "JBCCache(" + regionName + ')';
}
-
- private boolean isSharedClassLoaderRegion(String regionName)
- {
- return (StandardQueryCache.class.getName().equals(regionName)
- || UpdateTimestampsCache.class.getName().equals(regionName));
- }
private void activateCacheRegion(String regionName) throws CacheException
{
@@ -295,7 +314,7 @@
{
// Only register the classloader if it's not a shared region.
// If it's shared, no single classloader is valid
- if (!isSharedClassLoaderRegion(regionName))
+ if (!SecondLevelCacheUtil.isSharedClassLoaderRegion(regionName))
{
region.registerContextClassLoader(Thread.currentThread().getContextClassLoader());
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/entity/JBCCacheFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/entity/JBCCacheFactory.java 2007-07-02 16:23:37 UTC (rev 63774)
+++ trunk/ejb3/src/main/org/jboss/ejb3/entity/JBCCacheFactory.java 2007-07-02 16:29:44 UTC (rev 63775)
@@ -43,13 +43,16 @@
public Cache buildCache(String regionName, Properties properties) throws CacheException
{
+ String regionPrefix = properties.getProperty(SecondLevelCacheUtil.HIBERNATE_CACHE_REGION_PREFIX);
+
if (optimistic)
{
- return new OptimisticJBCCache(cache, regionName);
+ return new OptimisticJBCCache(cache, regionName, regionPrefix);
}
else
{
- return new JBCCache(cache, regionName, TxUtil.getTransactionManager());
+ return new JBCCache(cache, regionName, regionPrefix,
+ TxUtil.getTransactionManager());
}
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/entity/OptimisticJBCCache.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/entity/OptimisticJBCCache.java 2007-07-02 16:23:37 UTC (rev 63774)
+++ trunk/ejb3/src/main/org/jboss/ejb3/entity/OptimisticJBCCache.java 2007-07-02 16:29:44 UTC (rev 63775)
@@ -66,11 +66,12 @@
private OptimisticCacheSource source;
private boolean localWritesOnly;
- public OptimisticJBCCache(org.jboss.cache.Cache cache, String regionName)
+ public OptimisticJBCCache(org.jboss.cache.Cache cache,
+ String regionName, String regionPrefix)
throws CacheException {
this.cache = cache;
this.regionName = regionName;
- this.regionFqn = Fqn.fromString( regionName.replace( '.', '/' ) );
+ this.regionFqn = Fqn.fromString(SecondLevelCacheUtil.createRegionFqn(regionName, regionPrefix));
Configuration config = cache.getConfiguration();
if (config.isUseRegionBasedMarshalling())
{
Copied: trunk/ejb3/src/main/org/jboss/ejb3/entity/SecondLevelCacheUtil.java (from rev 62816, branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/entity/SecondLevelCacheUtil.java)
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/entity/SecondLevelCacheUtil.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/entity/SecondLevelCacheUtil.java 2007-07-02 16:29:44 UTC (rev 63775)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.ejb3.entity;
+
+import org.hibernate.cache.StandardQueryCache;
+import org.hibernate.cache.UpdateTimestampsCache;
+import org.jboss.cache.Fqn;
+
+/**
+ * Utilities related to the Hibernate 2nd Level Cache
+ *
+ * @author Brian Stansberry
+ */
+public class SecondLevelCacheUtil
+{
+ public static final String HIBERNATE_CACHE_REGION_PREFIX = "hibernate.cache.region_prefix";
+
+ public static String createCacheRegionPrefix(String earName, String jarName, String unitName)
+ {
+ StringBuilder sb = new StringBuilder();
+ if (earName != null)
+ {
+ sb.append(earName);
+ if (!earName.endsWith(".ear"))
+ sb.append("_ear");
+ sb.append(",");
+ }
+ if (jarName != null)
+ {
+ sb.append(jarName);
+ if (!jarName.endsWith(".jar"))
+ sb.append("_jar");
+ sb.append(",");
+ }
+ sb.append(unitName);
+ String raw = sb.toString();
+ // Replace any '.' otherwise the JBoss Cache integration may replace
+ // it with a '/' and it will become a level in the FQN
+ String escaped = raw.replace('.', '_');
+ return escaped;
+ }
+
+ public static String createRegionFqn(String regionName, String regionPrefix)
+ {
+ String escaped = null;
+ int idx = -1;
+ if (regionPrefix != null)
+ {
+ idx = regionName.indexOf(regionPrefix);
+ }
+
+ if (idx > -1)
+ {
+ int regionEnd = idx + regionPrefix.length();
+ String prefix = regionName.substring(0, regionEnd);
+ String suffix = regionName.substring(regionEnd);
+ suffix = suffix.replace('.', '/');
+ escaped = prefix + suffix;
+ }
+ else
+ {
+ escaped = regionName.replace('.', '/');
+ }
+ return escaped;
+ }
+
+ public static boolean isSharedClassLoaderRegion(String regionName)
+ {
+ return (StandardQueryCache.class.getName().equals(regionName)
+ || UpdateTimestampsCache.class.getName().equals(regionName));
+ }
+
+ // Prevent instantiation
+ private SecondLevelCacheUtil() {}
+}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/Customer.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/Customer.java 2007-07-02 16:23:37 UTC (rev 63774)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/Customer.java 2007-07-02 16:29:44 UTC (rev 63775)
@@ -43,7 +43,7 @@
Integer id;
String name;
- private Set<Contact> contacts;
+ private transient Set<Contact> contacts;
public Customer()
{
More information about the jboss-cvs-commits
mailing list