Author: manik.surtani(a)jboss.com
Date: 2008-11-26 15:27:59 -0500 (Wed, 26 Nov 2008)
New Revision: 7200
Modified:
core/trunk/src/main/java/org/jboss/cache/loader/bdbje/BdbjeCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoader.java
Log:
JBCACHE-1448 Jdbm and BDBJE cache loader incorrectly reading database name from location
String
Modified: core/trunk/src/main/java/org/jboss/cache/loader/bdbje/BdbjeCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/bdbje/BdbjeCacheLoader.java 2008-11-26
20:16:12 UTC (rev 7199)
+++ core/trunk/src/main/java/org/jboss/cache/loader/bdbje/BdbjeCacheLoader.java 2008-11-26
20:27:59 UTC (rev 7200)
@@ -26,26 +26,16 @@
import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;
-import com.sleepycat.je.Cursor;
-import com.sleepycat.je.Database;
-import com.sleepycat.je.DatabaseConfig;
-import com.sleepycat.je.DatabaseEntry;
-import com.sleepycat.je.DeadlockException;
-import com.sleepycat.je.Environment;
-import com.sleepycat.je.EnvironmentConfig;
-import com.sleepycat.je.JEVersion;
-import com.sleepycat.je.LockMode;
-import com.sleepycat.je.OperationStatus;
-import com.sleepycat.je.Transaction;
+import com.sleepycat.je.*;
import net.jcip.annotations.ThreadSafe;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
-import org.jboss.cache.marshall.NodeData;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.loader.AbstractCacheLoader;
+import org.jboss.cache.marshall.NodeData;
import org.jboss.cache.util.reflect.ReflectionUtil;
import java.io.File;
@@ -66,7 +56,7 @@
* <p>The configuration string format is:</p>
* <pre>environmentDirectoryName[#databaseName]</pre>
* <p>where databaseName, if omitted, defaults to the ClusterName property
- * of the CacheImpl.</p>
+ * of the Cache.</p>
* <p/>
* <p>A je.properties file may optionally be placed in the JE environment
* directory and used to customize the default JE configuration.</p>
@@ -156,7 +146,6 @@
}
-
/**
* Opens the JE environment and the database specified by the configuration
* string. The environment and databases are created if necessary.
@@ -182,6 +171,20 @@
config.setLocation(configStr);
}
+ // JBCACHE-1448 db name parsing fix courtesy of Ciro Cavani
+ /* Parse config string. */
+ int offset = configStr.indexOf('#');
+ String cacheDbName;
+ if (offset >= 0 && offset < configStr.length() - 1)
+ {
+ cacheDbName = configStr.substring(offset + 1);
+ configStr = configStr.substring(0, offset);
+ }
+ else
+ {
+ cacheDbName = cache.getClusterName();
+ }
+
// test location
File location = new File(configStr);
if (!location.exists())
@@ -195,19 +198,6 @@
throw new IOException("Cache loader location [" + location + "]
is not a directory!");
}
- /* Parse config string. */
- File homeDir;
- int offset = configStr.indexOf('#');
- if (offset >= 0 && offset < configStr.length() - 1)
- {
- homeDir = new File(configStr.substring(0, offset));
- cacheDbName = configStr.substring(offset + 1);
- }
- else
- {
- homeDir = new File(configStr);
- cacheDbName = cache.getClusterName();
- }
catalogDbName = cacheDbName + "_class_catalog";
/*
@@ -224,8 +214,8 @@
envConfig.setAllowCreate(true);
envConfig.setTransactional(true);
envConfig.setLockTimeout(1000 *
cache.getConfiguration().getLockAcquisitionTimeout()); // these are in nanos
- if (log.isTraceEnabled()) log.trace("Creating JE environment with home dir
" + homeDir);
- env = new Environment(homeDir, envConfig);
+ if (log.isTraceEnabled()) log.trace("Creating JE environment with home dir
" + location);
+ env = new Environment(location, envConfig);
if (log.isDebugEnabled()) log.debug("Created JE environment " + env +
" for cache loader " + this);
/* Open cache and catalog databases. */
openDatabases();
@@ -585,8 +575,9 @@
throws Exception
{
// JBCACHE-769 -- make a defensive copy
- if (values != null && !(values instanceof HashMap)) {
- values = new HashMap(values);
+ if (values != null && !(values instanceof HashMap))
+ {
+ values = new HashMap(values);
}
/* To update-or-insert, try putNoOverwrite first, then a RMW cycle. */
@@ -911,11 +902,12 @@
{
throw new UnsupportedOperationException(
"prepare() not allowed with a non-transactional cache loader");
- } else if (onePhase)
+ }
+ else if (onePhase)
{
- for (Modification modification: modifications)
+ for (Modification modification : modifications)
{
-
+
}
}
Transaction txn = performTransaction(modifications);
Modified: core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoader.java 2008-11-26
20:16:12 UTC (rev 7199)
+++ core/trunk/src/main/java/org/jboss/cache/loader/jdbm/JdbmCacheLoader.java 2008-11-26
20:27:59 UTC (rev 7200)
@@ -56,7 +56,7 @@
* <p>The configuration string format is:</p>
* <pre>environmentDirectoryName[#databaseName]</pre>
* <p>where databaseName, if omitted, defaults to the ClusterName property
- * of the CacheImpl.</p>
+ * of the Cache.</p>
* <p/>
* Data is sorted out like:
* <pre>
@@ -123,6 +123,20 @@
config.setLocation(locationStr);
}
+ // JBCACHE-1448 db name parsing fix courtesy of Ciro Cavani
+ /* Parse config string. */
+ int offset = locationStr.indexOf('#');
+ String cacheDbName;
+ if (offset >= 0 && offset < locationStr.length() - 1)
+ {
+ cacheDbName = locationStr.substring(offset + 1);
+ locationStr = locationStr.substring(0, offset);
+ }
+ else
+ {
+ cacheDbName = cache.getClusterName();
+ }
+
// test location
File location = new File(locationStr);
if (!location.exists())
@@ -136,24 +150,9 @@
throw new IOException("Cache loader location [" + location + "]
is not a directory!");
}
- /* Parse config string. */
- File homeDir;
- int offset = locationStr.indexOf('#');
- String cacheDbName;
- if (offset >= 0 && offset < locationStr.length() - 1)
- {
- homeDir = new File(locationStr.substring(0, offset));
- cacheDbName = locationStr.substring(offset + 1);
- }
- else
- {
- homeDir = new File(locationStr);
- cacheDbName = cache.getClusterName();
- }
-
try
{
- openDatabase(new File(homeDir, cacheDbName));
+ openDatabase(new File(location, cacheDbName));
}
catch (Exception e)
{
@@ -584,7 +583,7 @@
erase0(m.getFqn(), false);
break;
case REMOVE_KEY_VALUE:
- eraseKey0(m.getFqn(), m.getKey());
+ eraseKey0(m.getFqn(), m.getKey());
break;
case REMOVE_NODE:
erase0(m.getFqn());