[jboss-cvs] JBossCache/src/org/jboss/cache/loader/bdbje ...

Manik Surtani msurtani at jboss.com
Fri Sep 22 12:27:55 EDT 2006


  User: msurtani
  Date: 06/09/22 12:27:55

  Modified:    src/org/jboss/cache/loader/bdbje  BdbjeCacheLoader.java
  Log:
  - Modification types to Enums.
  - Abstracted put(List)
  
  Revision  Changes    Path
  1.16      +399 -239  JBossCache/src/org/jboss/cache/loader/bdbje/BdbjeCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BdbjeCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/bdbje/BdbjeCacheLoader.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -b -r1.15 -r1.16
  --- BdbjeCacheLoader.java	18 Sep 2006 21:39:27 -0000	1.15
  +++ BdbjeCacheLoader.java	22 Sep 2006 16:27:55 -0000	1.16
  @@ -6,9 +6,17 @@
   import com.sleepycat.bind.tuple.TupleBinding;
   import com.sleepycat.bind.tuple.TupleInput;
   import com.sleepycat.bind.tuple.TupleOutput;
  -import com.sleepycat.je.*;
  -import com.sleepycat.je.util.DbDump;
  -import com.sleepycat.je.util.DbLoad;
  +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 org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.CacheSPI;
  @@ -16,15 +24,8 @@
   import org.jboss.cache.Modification;
   import org.jboss.cache.loader.AbstractCacheLoader;
   
  -import java.io.BufferedReader;
  -import java.io.ByteArrayInputStream;
  -import java.io.ByteArrayOutputStream;
   import java.io.File;
   import java.io.IOException;
  -import java.io.InputStreamReader;
  -import java.io.ObjectInputStream;
  -import java.io.ObjectOutputStream;
  -import java.io.PrintStream;
   import java.io.Serializable;
   import java.util.Collections;
   import java.util.HashMap;
  @@ -38,18 +39,18 @@
   
   /**
    * A persistent <code>CacheLoader</code> based on Berkeley DB Java Edition.
  - *
  + * <p/>
    * <p>The configuration string format is:</p>
    * <pre>environmentDirectoryName[#databaseName]</pre>
    * <p>where databaseName, if omitted, defaults to the ClusterName property
    * of the TreeCache.</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>
    *
    * @author Mark Hayes May 16, 2004
    * @author Bela Ban
  - * @version $Id: BdbjeCacheLoader.java,v 1.15 2006/09/18 21:39:27 bstansberry Exp $
  + * @version $Id: BdbjeCacheLoader.java,v 1.16 2006/09/22 16:27:55 msurtani Exp $
    */
   public class BdbjeCacheLoader extends AbstractCacheLoader
   {
  @@ -78,8 +79,9 @@
      /**
       * Does nothing since start() does all the work.
       */
  -   public void create() throws Exception {
  -      String license="\n*************************************************************************************\n" +
  +   public void create() throws Exception
  +   {
  +      String license = "\n*************************************************************************************\n" +
               "Berkeley DB Java Edition version: " + JEVersion.CURRENT_VERSION.toString() + "\n" +
               "JBossCache can use Berkeley DB Java Edition from Sleepycat Software \n" +
               "(http://www.sleepycat.com/jeforjbosscache)\n" +
  @@ -100,7 +102,8 @@
      /**
       * Does nothing since stop() does all the work.
       */
  -   public void destroy() {
  +   public void destroy()
  +   {
      }
   
      /**
  @@ -108,17 +111,20 @@
       * string.  The environment and databases are created if necessary.
       */
      public void start()
  -      throws Exception {
  +           throws Exception
  +   {
   
         log.trace("Starting BdbjeCacheLoader instance.");
         checkNotOpen();
   
  -      if (cache == null) {
  +      if (cache == null)
  +      {
            throw new IllegalStateException(
               "A non-null Cache property (CacheSPI object) is required");
         }
  -      if (configStr == null) {
  -         configStr=System.getProperty("java.io.tmpdir");
  +      if (configStr == null)
  +      {
  +         configStr = System.getProperty("java.io.tmpdir");
         }
   
         // test location
  @@ -129,15 +135,21 @@
             if (!created) throw new IOException("Unable to create cache loader location " + location);
   
         }
  -      if (!location.isDirectory()) throw new IOException("Cache loader location [" + location + "] is not a directory!");
  +      if (!location.isDirectory())
  +      {
  +         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) {
  +      if (offset >= 0 && offset < configStr.length() - 1)
  +      {
            homeDir = new File(configStr.substring(0, offset));
            cacheDbName = configStr.substring(offset + 1);
  -      } else {
  +      }
  +      else
  +      {
            homeDir = new File(configStr);
            cacheDbName = cache.getClusterName();
         }
  @@ -150,7 +162,8 @@
          */
         transactional = cache.getTransactionManager() != null;
   
  -      try {
  +      try
  +      {
            /* Open the environment, creating it if it doesn't exist. */
            EnvironmentConfig envConfig = new EnvironmentConfig();
            envConfig.setAllowCreate(true);
  @@ -160,7 +173,9 @@
            if (log.isDebugEnabled()) log.debug("Created JE environment " + env + " for cache loader " + this);
            /* Open cache and catalog databases. */
            openDatabases();
  -      } catch (Exception e) {
  +      }
  +      catch (Exception e)
  +      {
            destroy();
            throw e;
         }
  @@ -170,7 +185,8 @@
       * Opens all databases and initializes database related information.
       */
      private void openDatabases()
  -      throws Exception {
  +           throws Exception
  +   {
   
         /* Use a generic database config, with no duplicates allowed. */
         DatabaseConfig dbConfig  = new DatabaseConfig();
  @@ -193,19 +209,28 @@
       * Closes all databases, ignoring exceptions, and nulls references to all
       * database related information.
       */
  -   private void closeDatabases() {
  +   private void closeDatabases()
  +   {
   
  -      if (cacheDb != null) {
  -         try {
  +      if (cacheDb != null)
  +      {
  +         try
  +         {
               cacheDb.close();
  -         } catch (Exception shouldNotOccur) {
  +         }
  +         catch (Exception shouldNotOccur)
  +         {
               log.warn("Caught unexpected exception", shouldNotOccur);
            }
         }
  -      if (catalogDb != null) {
  -         try {
  +      if (catalogDb != null)
  +      {
  +         try
  +         {
               catalogDb.close();
  -         } catch (Exception shouldNotOccur) {
  +         }
  +         catch (Exception shouldNotOccur)
  +         {
               log.warn("Caught unexpected exception", shouldNotOccur);
            }
         }
  @@ -221,14 +246,19 @@
       * The environment and databases are not removed from the file system.
       * Exceptions during close are ignored.
       */
  -   public void stop() {
  +   public void stop()
  +   {
   
         closeDatabases();
   
  -      if (env != null) {
  -         try {
  +      if (env != null)
  +      {
  +         try
  +         {
               env.close();
  -         } catch (Exception shouldNotOccur) {
  +         }
  +         catch (Exception shouldNotOccur)
  +         {
               log.warn("Unexpected exception", shouldNotOccur);
            }
         }
  @@ -242,9 +272,10 @@
      /**
       * Sets the configuration string for this cache loader.
       */
  -   public void setConfig(Properties props) {
  +   public void setConfig(Properties props)
  +   {
         checkNotOpen();
  -       configStr = props != null? props.getProperty("location") : null;
  +      configStr = props != null ? props.getProperty("location") : null;
          if (log.isTraceEnabled()) log.trace("Configuring cache loader with location = " + configStr);
      }
   
  @@ -265,7 +296,8 @@
       * transaction is not recommended.
       */
      public Set<String> getChildrenNames(Fqn name)
  -      throws Exception {
  +           throws Exception
  +   {
   
         checkOpen();
         checkNonNull(name, "name");
  @@ -279,16 +311,20 @@
         Set<String> set = null;
   
         Cursor cursor = cacheDb.openCursor(null, null);
  -      try {
  -         while (true) {
  +      try
  +      {
  +         while (true)
  +         {
               DatabaseEntry keyEntry = makeKeyEntry(prefixEntry, namePart);
               OperationStatus status =
                  cursor.getSearchKeyRange(keyEntry, dataEntry, null);
               if (status != OperationStatus.SUCCESS ||
  -                !startsWith(keyEntry, prefixEntry)) {
  +                !startsWith(keyEntry, prefixEntry))
  +            {
                  break;
               }
  -            if (set == null) {
  +            if (set == null)
  +            {
                  set = new HashSet<String>();
               }
               Fqn childName = makeKeyObject(keyEntry);
  @@ -296,12 +332,17 @@
               set.add(namePart);
               namePart += LOWEST_UTF_CHAR;
            }
  -      } finally {
  +      }
  +      finally
  +      {
            cursor.close();
         }
  -      if (set != null) {
  +      if (set != null)
  +      {
            return Collections.unmodifiableSet(set);
  -      } else {
  +      }
  +      else
  +      {
            return null;
         }
      }
  @@ -313,7 +354,8 @@
       * environment.
       */
      public Map get(Fqn name)
  -      throws Exception {
  +           throws Exception
  +   {
   
         checkOpen();
         checkNonNull(name, "name");
  @@ -321,11 +363,14 @@
         DatabaseEntry keyEntry = makeKeyEntry(name);
         DatabaseEntry foundData = new DatabaseEntry();
         OperationStatus status = cacheDb.get(null, keyEntry, foundData, null);
  -      if (status == OperationStatus.SUCCESS) {
  +      if (status == OperationStatus.SUCCESS)
  +      {
            //  changed createIfNull param to true
             // See http://jira.jboss.com/jira/browse/JBCACHE-118
             return makeDataObject(foundData, true);
  -      } else {
  +      }
  +      else
  +      {
            return null;
         }
      }
  @@ -353,7 +398,8 @@
       * Returns whether the given node exists.
       */
      public boolean exists(Fqn name)
  -      throws Exception {
  +           throws Exception
  +   {
   
         checkOpen();
         checkNonNull(name, "name");
  @@ -371,18 +417,22 @@
       * Intended to be used in a non-transactional environment, but will use
       * auto-commit in a transactional environment.
       */
  -   public Object put(Fqn name, Object key, Object value) throws Exception {
  +   public Object put(Fqn name, Object key, Object value) throws Exception
  +   {
   
         checkOpen();
         checkNonNull(name, "name");
   
         Object oldVal;
  -      if (transactional) {
  +      if (transactional)
  +      {
            Modification mod =
  -            new Modification(Modification.PUT_KEY_VALUE, name, key, value);
  +                 new Modification(Modification.ModificationType.PUT_KEY_VALUE, name, key, value);
            commitModification(mod);
            oldVal = mod.getOldValue();
  -      } else {
  +      }
  +      else
  +      {
            oldVal = doPut(null, name, key, value);
         }
         return oldVal;
  @@ -394,7 +444,8 @@
       * transaction.
       */
      private Object doPut(Transaction txn, Fqn name, Object key, Object value)
  -      throws Exception {
  +           throws Exception
  +   {
   
         Object oldVal = null;
         /* To update-or-insert, try putNoOverwrite first, then a RMW cycle. */
  @@ -403,29 +454,33 @@
         DatabaseEntry dataEntry = makeDataEntry(map);
         DatabaseEntry keyEntry = makeKeyEntry(name);
         Cursor cursor = cacheDb.openCursor(txn, null);
  -      try {
  -         OperationStatus status=cursor.putNoOverwrite(keyEntry, dataEntry);
  -         if(status == OperationStatus.SUCCESS) {
  +      try
  +      {
  +         OperationStatus status = cursor.putNoOverwrite(keyEntry, dataEntry);
  +         if (status == OperationStatus.SUCCESS)
  +         {
               createParentNodes(cursor, name);
            }
  -         else {
  -            DatabaseEntry foundData=new DatabaseEntry();
  -            status=cursor.getSearchKey(keyEntry, foundData, LockMode.RMW);
  -            if(status == OperationStatus.SUCCESS) {
  -               map=makeDataObject(foundData, true);
  +         else
  +         {
  +            DatabaseEntry foundData = new DatabaseEntry();
  +            status = cursor.getSearchKey(keyEntry, foundData, LockMode.RMW);
  +            if (status == OperationStatus.SUCCESS)
  +            {
  +               map = makeDataObject(foundData, true);
                  oldVal = map.put(key, value);
                  cursor.putCurrent(makeDataEntry(map));
               }
            }
         }
  -      finally {
  +      finally
  +      {
            cursor.close();
         }
         return oldVal;
      }
   
   
  -
      /**
       * Stores a map of key-values for a given FQN, but does not delete existing
       * key-value pairs (that is, it does not erase).
  @@ -433,15 +488,19 @@
       * auto-commit in a transactional environment.
       */
      public void put(Fqn name, Map values)
  -      throws Exception {
  +           throws Exception
  +   {
   
         checkOpen();
         checkNonNull(name, "name");
   
  -      if (transactional) {
  +      if (transactional)
  +      {
            commitModification(
  -            new Modification(Modification.PUT_DATA, name, values));
  -      } else {
  +                 new Modification(Modification.ModificationType.PUT_DATA, name, values));
  +      }
  +      else
  +      {
            doPut(null, name, values);
         }
      }
  @@ -452,7 +511,8 @@
        * transaction.
        */
       private void doPut(Transaction txn, Fqn name, Map values)
  -       throws Exception {
  +           throws Exception
  +   {
          
          // JBCACHE-769 -- make a defensive copy
          values = (values == null ? null : new HashMap(values));
  @@ -461,21 +521,30 @@
          DatabaseEntry dataEntry = makeDataEntry(values);
          DatabaseEntry keyEntry = makeKeyEntry(name);
          Cursor cursor = cacheDb.openCursor(txn, null);
  -       try {
  +      try
  +      {
             OperationStatus status = cursor.putNoOverwrite(keyEntry, dataEntry);
  -          if (status == OperationStatus.SUCCESS) {
  +         if (status == OperationStatus.SUCCESS)
  +         {
                createParentNodes(cursor, name);
  -          } else {
  +         }
  +         else
  +         {
                DatabaseEntry foundData = new DatabaseEntry();
                status = cursor.getSearchKey(keyEntry, foundData, LockMode.RMW);
  -             if (status == OperationStatus.SUCCESS) {
  +            if (status == OperationStatus.SUCCESS)
  +            {
                   Map map = makeDataObject(foundData, true);
  -                if(values != null)
  +               if (values != null)
  +               {
                      map.putAll(values);
  +               }
                   cursor.putCurrent(makeDataEntry(map));
                }
             }
  -       } finally {
  +      }
  +      finally
  +      {
             cursor.close();
          }
       }
  @@ -485,7 +554,8 @@
       * transaction and erases existing data.
       */
      private void doPutErase(Transaction txn, Fqn name, Map values)
  -      throws Exception {
  +           throws Exception
  +   {
         
         // JBCACHE-769 -- make a defensive copy
         values = (values == null ? null : new HashMap(values));
  @@ -493,10 +563,13 @@
         DatabaseEntry dataEntry = makeDataEntry(values);
         DatabaseEntry keyEntry = makeKeyEntry(name);
         Cursor cursor = cacheDb.openCursor(txn, null);
  -      try {
  +      try
  +      {
            cursor.put(keyEntry, dataEntry);
            createParentNodes(cursor, name);
  -      } finally {
  +      }
  +      finally
  +      {
            cursor.close();
         }
      }
  @@ -511,9 +584,12 @@
         checkOpen();
         checkNonNull(modifications, "modifications");
   
  -      if (transactional) {
  +      if (transactional)
  +      {
            commitModifications(modifications);
  -      } else {
  +      }
  +      else
  +      {
            doPut(null, modifications);
         }
      }
  @@ -522,34 +598,37 @@
       * Internal version of put(List) that allows passing a transaction.
       */
      private void doPut(Transaction txn, List modifications)
  -      throws Exception {
  +           throws Exception
  +   {
   
         /* This could be optimized by grouping modifications by Fqn, and
          * performing a single database operation for each Fqn (record). */
   
  -      for (Iterator i = modifications.iterator(); i.hasNext();) {
  +      for (Iterator i = modifications.iterator(); i.hasNext();)
  +      {
            Modification mod = (Modification) i.next();
            Fqn name = mod.getFqn();
            Object oldVal;
  -         switch (mod.getType()) {
  -            case Modification.PUT_KEY_VALUE:
  +         switch (mod.getType())
  +         {
  +            case PUT_KEY_VALUE:
                  oldVal = doPut(txn, name, mod.getKey(), mod.getValue());
                  mod.setOldValue(oldVal);
                  break;
  -            case Modification.PUT_DATA:
  +            case PUT_DATA:
                  doPut(txn, name, mod.getData());
                  break;
  -            case Modification.PUT_DATA_ERASE:
  +            case PUT_DATA_ERASE:
                  doPutErase(txn, name, mod.getData());
                  break;
  -            case Modification.REMOVE_KEY_VALUE:
  +            case REMOVE_KEY_VALUE:
                  oldVal = doRemove(txn, name, mod.getKey());
                  mod.setOldValue(oldVal);
                  break;
  -            case Modification.REMOVE_NODE:
  +            case REMOVE_NODE:
                  doRemove(txn, name);
                  break;
  -            case Modification.REMOVE_DATA:
  +            case REMOVE_DATA:
                  doRemoveData(txn, name);
                  break;
               default:
  @@ -564,13 +643,16 @@
       * node is found.
       */
      private void createParentNodes(Cursor cursor, Fqn name)
  -      throws Exception {
  +           throws Exception
  +   {
   
         DatabaseEntry dataEntry = makeDataEntry(null);
  -      for (int nParts = name.size() - 1; nParts >= 1; nParts -= 1) {
  +      for (int nParts = name.size() - 1; nParts >= 1; nParts -= 1)
  +      {
            DatabaseEntry keyEntry = makeKeyEntry(name, nParts);
            OperationStatus status = cursor.putNoOverwrite(keyEntry, dataEntry);
  -         if (status != OperationStatus.SUCCESS) {
  +         if (status != OperationStatus.SUCCESS)
  +         {
               break;
            }
         }
  @@ -582,15 +664,19 @@
       * auto-commit in a transactional environment.
       */
      public void remove(Fqn name)
  -      throws Exception {
  +           throws Exception
  +   {
   
         checkOpen();
         checkNonNull(name, "name");
   
  -      if (transactional) {
  +      if (transactional)
  +      {
            commitModification(
  -            new Modification(Modification.REMOVE_NODE, name));
  -      } else {
  +                 new Modification(Modification.ModificationType.REMOVE_NODE, name));
  +      }
  +      else
  +      {
            doRemove(null, name);
         }
      }
  @@ -599,25 +685,31 @@
       * Internal version of remove(Fqn) that allows passing a transaction.
       */
      private void doRemove(Transaction txn, Fqn name)
  -      throws Exception {
  +           throws Exception
  +   {
   
         DatabaseEntry keyEntry = makeKeyEntry(name);
         DatabaseEntry foundKey = new DatabaseEntry();
         DatabaseEntry foundData = new DatabaseEntry();
         foundData.setPartial(0, 0, true);
         Cursor cursor = cacheDb.openCursor(txn, null);
  -      try {
  +      try
  +      {
            OperationStatus status =
               cursor.getSearchKey(keyEntry, foundData, LockMode.RMW);
  -         while (status == OperationStatus.SUCCESS) {
  +         while (status == OperationStatus.SUCCESS)
  +         {
               cursor.delete();
               status = cursor.getNext(foundKey, foundData, LockMode.RMW);
               if (status == OperationStatus.SUCCESS &&
  -                !startsWith(foundKey, keyEntry)) {
  +                !startsWith(foundKey, keyEntry))
  +            {
                  status = OperationStatus.NOTFOUND;
               }
            }
  -      } finally {
  +      }
  +      finally
  +      {
            cursor.close();
         }
      }
  @@ -628,18 +720,22 @@
       * auto-commit in a transactional environment.
       */
      public Object remove(Fqn name, Object key)
  -      throws Exception {
  +           throws Exception
  +   {
   
         checkOpen();
         checkNonNull(name, "name");
   
         Object oldVal;
  -      if (transactional) {
  +      if (transactional)
  +      {
            Modification mod =
  -            new Modification(Modification.REMOVE_KEY_VALUE, name, key);
  +                 new Modification(Modification.ModificationType.REMOVE_KEY_VALUE, name, key);
            commitModification(mod);
            oldVal = mod.getOldValue();
  -      } else {
  +      }
  +      else
  +      {
            oldVal = doRemove(null, name, key);
         }
         return oldVal;
  @@ -650,21 +746,26 @@
       * transaction.
       */
      private Object doRemove(Transaction txn, Fqn name, Object key)
  -      throws Exception {
  +           throws Exception
  +   {
   
         Object oldVal = null;
         DatabaseEntry keyEntry = makeKeyEntry(name);
         DatabaseEntry foundData = new DatabaseEntry();
         Cursor cursor = cacheDb.openCursor(txn, null);
  -      try {
  +      try
  +      {
            OperationStatus status =
               cursor.getSearchKey(keyEntry, foundData, LockMode.RMW);
  -         if (status == OperationStatus.SUCCESS) {
  +         if (status == OperationStatus.SUCCESS)
  +         {
               Map map = makeDataObject(foundData, true);
               oldVal = map.remove(key);
               cursor.putCurrent(makeDataEntry(map));
            }
  -      } finally {
  +      }
  +      finally
  +      {
            cursor.close();
         }
         return oldVal;
  @@ -674,15 +775,19 @@
       * Clears the map for the given node, but does not remove the node.
       */
      public void removeData(Fqn name)
  -      throws Exception {
  +           throws Exception
  +   {
   
         checkOpen();
         checkNonNull(name, "name");
   
  -      if (transactional) {
  +      if (transactional)
  +      {
            commitModification(
  -            new Modification(Modification.REMOVE_DATA, name));
  -      } else {
  +                 new Modification(Modification.ModificationType.REMOVE_DATA, name));
  +      }
  +      else
  +      {
            doRemoveData(null, name);
         }
      }
  @@ -691,26 +796,31 @@
        * Internal version of removeData(Fqn) that allows passing a transaction.
        */
       private void doRemoveData(Transaction txn, Fqn name)
  -       throws Exception {
  +           throws Exception
  +   {
   
          DatabaseEntry dataEntry = new DatabaseEntry();
          dataEntry.setPartial(0, 0, true);
          DatabaseEntry keyEntry = makeKeyEntry(name);
          Cursor cursor = cacheDb.openCursor(txn, null);
  -       try {
  +      try
  +      {
             OperationStatus status =
                cursor.getSearchKey(keyEntry, dataEntry, LockMode.RMW);
  -          if (status == OperationStatus.SUCCESS) {
  +         if (status == OperationStatus.SUCCESS)
  +         {
                cursor.putCurrent(makeDataEntry(null));
             }
  -       } finally {
  +      }
  +      finally
  +      {
             cursor.close();
          }
       }
   
      /**
       * Begins a transaction and applies the given modifications.
  -    *
  +    * <p/>
       * <p>If onePhase is true, commits the transaction; otherwise, associates
       * the txn value with the transaction and expects commit() or rollback() to
       * be called later with the same tx value.  Performs retries if necessary to
  @@ -720,17 +830,22 @@
       {
         checkOpen();
         checkNonNull(modifications, "modifications");
  -      if (!onePhase) {
  +      if (!onePhase)
  +      {
            checkNonNull(tx, "tx");
         }
  -      if (!transactional) {
  +      if (!transactional)
  +      {
            throw new UnsupportedOperationException(
               "prepare() not allowed with a non-transactional cache loader");
         }
         Transaction txn = performTransaction(modifications);
  -      if (onePhase) {
  +      if (onePhase)
  +      {
            txn.commit();
  -      } else {
  +      }
  +      else
  +      {
            txnMap.put(tx, txn);
         }
      }
  @@ -741,7 +856,8 @@
       * transaction and throws an exception if not successful.
       */
      private void commitModification(Modification mod)
  -      throws Exception {
  +           throws Exception
  +   {
   
         commitModifications(Collections.singletonList(mod));
      }
  @@ -752,7 +868,8 @@
       * transaction and throws an exception if not successful.
       */
      private void commitModifications(List mods)
  -      throws Exception {
  +           throws Exception
  +   {
   
         if (!transactional) throw new IllegalStateException();
         Transaction txn = performTransaction(mods);
  @@ -765,7 +882,8 @@
       * and throws an exception if not successful.
       */
      private Transaction performTransaction(List modifications)
  -      throws Exception {
  +           throws Exception
  +   {
   
         /*
          * Note that we can't use TransactionRunner here since if onePhase=false
  @@ -774,16 +892,23 @@
          */
   
         int retries = MAX_TXN_RETRIES;
  -      while (true) {
  +      while (true)
  +      {
            Transaction txn = env.beginTransaction(null, null);
  -         try {
  +         try
  +         {
               doPut(txn, modifications);
               return txn;
  -         } catch (Exception e) {
  +         }
  +         catch (Exception e)
  +         {
               txn.abort();
  -            if (e instanceof DeadlockException && retries > 0) {
  +            if (e instanceof DeadlockException && retries > 0)
  +            {
                  retries -= 1;
  -            } else {
  +            }
  +            else
  +            {
                  throw e;
               }
            }
  @@ -795,15 +920,19 @@
       * given key is not associated with an uncommited transaction.
       */
      public void commit(Object tx)
  -      throws Exception {
  +           throws Exception
  +   {
   
         checkOpen();
         checkNonNull(tx, "tx");
   
         Transaction txn = (Transaction) txnMap.remove(tx);
  -      if (txn != null) {
  +      if (txn != null)
  +      {
            txn.commit();
  -      } else if (transactional) {
  +      }
  +      else if (transactional)
  +      {
            throw new IllegalArgumentException("Unknown txn key: " + tx);
         }
      }
  @@ -812,17 +941,25 @@
       * Commits the given transaction, or throws IllegalArgumentException if the
       * given key is not associated with an uncommited transaction.
       */
  -   public void rollback(Object tx) {
  +   public void rollback(Object tx)
  +   {
   
         checkOpen();
         checkNonNull(tx, "tx");
   
         Transaction txn = (Transaction) txnMap.remove(tx);
  -      if (txn != null) {
  -         try {
  +      if (txn != null)
  +      {
  +         try
  +         {
               txn.abort();
  -         } catch (Exception ignored) {}
  -      } else if (transactional) {
  +         }
  +         catch (Exception ignored)
  +         {
  +         }
  +      }
  +      else if (transactional)
  +      {
            throw new IllegalArgumentException("Unknown txn key: " + tx);
         }
      }
  @@ -832,17 +969,21 @@
       * Used to determine whether a database key starts with a given FQN.
       */
      private boolean startsWith(DatabaseEntry entry,
  -                              DatabaseEntry prefix) {
  +                              DatabaseEntry prefix)
  +   {
         int size = prefix.getSize();
  -      if (size > entry.getSize()) {
  +      if (size > entry.getSize())
  +      {
            return false;
         }
         byte[] d1 = entry.getData();
         byte[] d2 = prefix.getData();
         int o1 = entry.getOffset();
         int o2 = prefix.getOffset();
  -      for (int i = 0; i < size; i += 1) {
  -         if (d1[o1 + i] != d2[o2 + i]) {
  +      for (int i = 0; i < size; i += 1)
  +      {
  +         if (d1[o1 + i] != d2[o2 + i])
  +         {
               return false;
            }
         }
  @@ -852,13 +993,15 @@
      /**
       * Converts a database entry to an Fqn.
       */
  -   private Fqn makeKeyObject(DatabaseEntry entry) {
  +   private Fqn makeKeyObject(DatabaseEntry entry)
  +   {
   
         Fqn name = Fqn.ROOT;
         TupleInput tupleInput = TupleBinding.entryToInput(entry);
  -      while (tupleInput.available() > 0) {
  +      while (tupleInput.available() > 0)
  +      {
            String part = tupleInput.readString();
  -         name=new Fqn(name, part);
  +         name = new Fqn(name, part);
         }
         return name;
      }
  @@ -866,7 +1009,8 @@
      /**
       * Converts an Fqn to a database entry.
       */
  -   private DatabaseEntry makeKeyEntry(Fqn name) {
  +   private DatabaseEntry makeKeyEntry(Fqn name)
  +   {
   
         return makeKeyEntry(name, name.size());
      }
  @@ -875,11 +1019,13 @@
       * Converts an Fqn to a database entry, outputing the given number of name
       * parts.
       */
  -   private DatabaseEntry makeKeyEntry(Fqn name, int nParts) {
  +   private DatabaseEntry makeKeyEntry(Fqn name, int nParts)
  +   {
   
         /* Write the sequence of name parts. */
         TupleOutput tupleOutput = new TupleOutput();
  -      for (int i = 0; i < nParts; i += 1) {
  +      for (int i = 0; i < nParts; i += 1)
  +      {
            tupleOutput.writeString(name.get(i).toString());
         }
   
  @@ -893,7 +1039,8 @@
       * Creates a key database entry from a parent database entry (prefix) and
       * a child name part.
       */
  -   private DatabaseEntry makeKeyEntry(DatabaseEntry prefix, String namePart) {
  +   private DatabaseEntry makeKeyEntry(DatabaseEntry prefix, String namePart)
  +   {
   
         /* Write the bytes of the prefix followed by the child name. */
         TupleOutput tupleOutput = new TupleOutput();
  @@ -911,9 +1058,11 @@
      /**
       * Converts a database entry to a Map.
       */
  -   private Map makeDataObject(DatabaseEntry entry, boolean createIfNull) {
  +   private Map makeDataObject(DatabaseEntry entry, boolean createIfNull)
  +   {
         Map map = (Map) serialBinding.entryToObject(entry);
  -      if (createIfNull && map == null) {
  +      if (createIfNull && map == null)
  +      {
            map = new HashMap();
         }
         return map;
  @@ -922,12 +1071,17 @@
      /**
       * Converts a Map to a database entry.
       */
  -   private DatabaseEntry makeDataEntry(Map map) {
  +   private DatabaseEntry makeDataEntry(Map map)
  +   {
   
  -      if (map != null) {
  -         if (map.size() == 0) {
  +      if (map != null)
  +      {
  +         if (map.size() == 0)
  +         {
               map = null;
  -         } else if (!(map instanceof Serializable)) {
  +         }
  +         else if (!(map instanceof Serializable))
  +         {
               map = new HashMap(map);
            }
         }
  @@ -939,8 +1093,10 @@
      /**
       * Throws an exception if the environment is not open.
       */
  -   private void checkOpen() {
  -      if (env == null) {
  +   private void checkOpen()
  +   {
  +      if (env == null)
  +      {
            throw new IllegalStateException(
                  "Operation not allowed before calling create()");
         }
  @@ -949,8 +1105,10 @@
      /**
       * Throws an exception if the environment is not open.
       */
  -   private void checkNotOpen() {
  -      if (env != null) {
  +   private void checkNotOpen()
  +   {
  +      if (env != null)
  +      {
            throw new IllegalStateException(
                  "Operation not allowed after calling create()");
         }
  @@ -959,8 +1117,10 @@
      /**
       * Throws an exception if the parameter is null.
       */
  -   private void checkNonNull(Object param, String paramName) {
  -      if (param ==  null) {
  +   private void checkNonNull(Object param, String paramName)
  +   {
  +      if (param == null)
  +      {
            throw new NullPointerException(
                  "Parameter must not be null: " + paramName);
         }
  
  
  



More information about the jboss-cvs-commits mailing list