[jboss-cvs] JBossAS SVN: r80670 - in projects/cluster/hibernate-jbc-cacheprovider/trunk/src: test/java/org/jboss/hibernate/jbc/cacheprovider and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 7 12:05:03 EST 2008


Author: galder.zamarreno at jboss.com
Date: 2008-11-07 12:05:03 -0500 (Fri, 07 Nov 2008)
New Revision: 80670

Added:
   projects/cluster/hibernate-jbc-cacheprovider/trunk/src/test/java/org/jboss/hibernate/jbc/cacheprovider/CachePropertiesTestCase.java
Modified:
   projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/CacheProperties.java
Log:
[JBCLUSTER-212] Properties modified accordingly while legacy style properties as supported if new ones are not defined.

Modified: projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/CacheProperties.java
===================================================================
--- projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/CacheProperties.java	2008-11-07 17:03:19 UTC (rev 80669)
+++ projects/cluster/hibernate-jbc-cacheprovider/trunk/src/main/java/org/jboss/hibernate/jbc/cacheprovider/CacheProperties.java	2008-11-07 17:05:03 UTC (rev 80670)
@@ -42,14 +42,49 @@
     */
    public static final String DEFAULT_CACHE_OBJECT_NAME = "jboss.cache:service=TreeCache";
    
+   /**
+    * A prefix to use for second-level cache region names. This is a very 
+    * useful option when trying to segregate (quite often isolated) deployments 
+    * in the Second Level Cache. Each isolated deployment would use a different 
+    * region prefix.
+    */
    public static final String HIBERNATE_CACHE_REGION_PREFIX_PROPERTY = "hibernate.cache.region_prefix";
    
-   public static final String HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY = "hibernate.treecache.querycache.local.writes.only";
+   /**
+    * If query cache has been enabled, this property controls whether the query 
+    * cache is only populated and updated locally or instead it's replicated. 
+    * If the property is set to true, the query cache is only local.  
+    */
+   public static final String HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY = "hibernate.treecache.querycache.local_writes_only";
    
+   /**
+    * @deprecated Deprecated version of {@link HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY}.
+    */
+   public static final String LEGACY_HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY = "hibernate.treecache.querycache.local.writes.only";
+   
+   /**
+    * Default value for the JBoss Cache instance that will be used
+    * if {@link HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY} is not provided.
+    */
    public static final String DEFAULT_QUERYCACHE_LOCAL_WRITES_ONLY = "true";
    
-   public static final String HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY = "hibernate.treecache.local.puts.only";
+   /**
+    * This property controls whether any put calls on the Second Level Cache 
+    * as a result of a read operation from the database are done locally or not. 
+    * If the property is set to true, it means that data read from database is 
+    * not replicated to other nodes.
+    */
+   public static final String HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY = "hibernate.treecache.local_puts_only";
    
+   /**
+    * @deprecated Deprecated version of {@link HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY}.
+    */
+   public static final String LEGACY_HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY = "hibernate.treecache.local.puts.only";
+   
+   /**
+    * Default value for the JBoss Cache instance that will be used
+    * if {@link HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY} is not provided.
+    */
    public static final String DEFAULT_LOCAL_PUTS_ONLY = "true";
    
    private final String cacheObjectName;
@@ -67,13 +102,41 @@
       
       cacheRegionPrefix = properties.getProperty(HIBERNATE_CACHE_REGION_PREFIX_PROPERTY);
       
-      queryCacheLocalWritesOnly = new Boolean(properties.getProperty(
-            HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY, 
-            DEFAULT_QUERYCACHE_LOCAL_WRITES_ONLY)).booleanValue();
+      String prop = properties.getProperty(HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY); 
+      if (prop != null)
+      {
+         queryCacheLocalWritesOnly = new Boolean(prop).booleanValue();         
+      }
+      else
+      {
+         prop = properties.getProperty(LEGACY_HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY);
+         if (prop != null)
+         {
+            queryCacheLocalWritesOnly = new Boolean(prop).booleanValue();   
+         }
+         else
+         {
+            queryCacheLocalWritesOnly = new Boolean(DEFAULT_QUERYCACHE_LOCAL_WRITES_ONLY).booleanValue();
+         }
+      }
       
-      localPutsOnly = new Boolean(properties.getProperty(
-            HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY, 
-            DEFAULT_LOCAL_PUTS_ONLY)).booleanValue();
+      prop = properties.getProperty(HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY);
+      if (prop != null)
+      {
+         localPutsOnly = new Boolean(prop).booleanValue();
+      }
+      else
+      {
+         prop = properties.getProperty(LEGACY_HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY);
+         if (prop != null)
+         {
+            localPutsOnly = new Boolean(prop).booleanValue();
+         }
+         else
+         {
+            localPutsOnly = new Boolean(DEFAULT_LOCAL_PUTS_ONLY).booleanValue();
+         }
+      }      
    }
 
    public String getCacheObjectName()

Added: projects/cluster/hibernate-jbc-cacheprovider/trunk/src/test/java/org/jboss/hibernate/jbc/cacheprovider/CachePropertiesTestCase.java
===================================================================
--- projects/cluster/hibernate-jbc-cacheprovider/trunk/src/test/java/org/jboss/hibernate/jbc/cacheprovider/CachePropertiesTestCase.java	                        (rev 0)
+++ projects/cluster/hibernate-jbc-cacheprovider/trunk/src/test/java/org/jboss/hibernate/jbc/cacheprovider/CachePropertiesTestCase.java	2008-11-07 17:05:03 UTC (rev 80670)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.hibernate.jbc.cacheprovider;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+/**
+ * CachePropertiesTestCase.
+ * 
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class CachePropertiesTestCase extends TestCase
+{
+   public void testLocalProperties()
+   {
+      Properties p = new Properties();
+      p.setProperty(CacheProperties.HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY, "false");
+      p.setProperty(CacheProperties.HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY, "false");
+      
+      CacheProperties cp = new CacheProperties(p);
+      assertFalse(cp.isQueryCacheLocalWritesOnly());
+      assertFalse(cp.isLocalPutsOnly());
+   }
+
+   public void testLegacyLocalProperties()
+   {
+      Properties p = new Properties();
+      p.setProperty(CacheProperties.LEGACY_HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY, "false");
+      p.setProperty(CacheProperties.LEGACY_HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY, "false");
+      
+      CacheProperties cp = new CacheProperties(p);
+      assertFalse(cp.isQueryCacheLocalWritesOnly());
+      assertFalse(cp.isLocalPutsOnly());
+   }   
+   
+   public void testMixedLocalProperties()
+   {
+      Properties p = new Properties();
+      p.setProperty(CacheProperties.HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY, "false");
+      p.setProperty(CacheProperties.HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY, "false");
+      p.setProperty(CacheProperties.LEGACY_HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY, "true");
+      p.setProperty(CacheProperties.LEGACY_HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY, "true");
+
+      CacheProperties cp = new CacheProperties(p);
+      assertFalse(cp.isQueryCacheLocalWritesOnly());
+      assertFalse(cp.isLocalPutsOnly());
+      
+      p = new Properties();
+      p.setProperty(CacheProperties.HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY, "true");
+      p.setProperty(CacheProperties.HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY, "true");
+      p.setProperty(CacheProperties.LEGACY_HIBERNATE_CACHE_QUERYCACHE_LOCAL_WRITES_ONLY_PROPERTY, "false");
+      p.setProperty(CacheProperties.LEGACY_HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY, "false");
+
+      cp = new CacheProperties(p);
+      assertTrue(cp.isQueryCacheLocalWritesOnly());
+      assertTrue(cp.isLocalPutsOnly());
+   }
+   
+   public void testNoLocalProperties()
+   {
+      Properties p = new Properties();
+      CacheProperties cp = new CacheProperties(p);
+      assertTrue(cp.isQueryCacheLocalWritesOnly());
+      assertTrue(cp.isLocalPutsOnly());
+   }
+}




More information about the jboss-cvs-commits mailing list