You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jo...@apache.org on 2006/06/22 00:57:28 UTC

svn commit: r416152 - in /jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file: DirectTransactionIdToPathMapper.java FileResourceManager.java TransactionIdToPathMapper.java

Author: joerg
Date: Wed Jun 21 15:57:28 2006
New Revision: 416152

URL: http://svn.apache.org/viewvc?rev=416152&view=rev
Log:
introduce TransactionIdToPathMapper interface:
the former version just with getTransactionBaseDir(), which could be overridden,
suffered from a problem in recoverContexts() where also an 1:1-matching of txId to path was assumed

Added:
    jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/DirectTransactionIdToPathMapper.java
    jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/TransactionIdToPathMapper.java
Modified:
    jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/FileResourceManager.java

Added: jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/DirectTransactionIdToPathMapper.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/DirectTransactionIdToPathMapper.java?rev=416152&view=auto
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/DirectTransactionIdToPathMapper.java (added)
+++ jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/DirectTransactionIdToPathMapper.java Wed Jun 21 15:57:28 2006
@@ -0,0 +1,36 @@
+/*
+ * Copyright 1999-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.transaction.file;
+
+/**
+ * Default implementation of {@link TransactionIdToPathMapper}, which converts
+ * transaction ids directly to paths using <code>toString()</code> and the path
+ * to transaction ids as is.
+ * 
+ * @version SVN $Id$
+ * @since 1.2
+ */
+public class DirectTransactionIdToPathMapper implements TransactionIdToPathMapper {
+
+    public String getPathForId(Object txId) {
+        return txId.toString();
+    }
+
+    public Object getIdForPath(String path) {
+        return path;
+    }
+
+}

Modified: jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/FileResourceManager.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/FileResourceManager.java?rev=416152&r1=416151&r2=416152&view=diff
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/FileResourceManager.java (original)
+++ jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/FileResourceManager.java Wed Jun 21 15:57:28 2006
@@ -199,6 +199,7 @@
     protected LockManager2 lockManager;
 
     protected ResourceIdToPathMapper idMapper = null;
+    protected TransactionIdToPathMapper txIdMapper = null;
 
     protected int idCnt = 0;
 
@@ -235,7 +236,7 @@
         boolean urlEncodePath,
         LoggerFacade logger,
         boolean debug) {
-        this(storeDir, workDir, urlEncodePath ? new URLEncodeIdMapper() : null, logger, debug);
+        this(storeDir, workDir, urlEncodePath ? new URLEncodeIdMapper() : null, new DirectTransactionIdToPathMapper(), logger, debug);
     }
 
     /**
@@ -244,6 +245,7 @@
      * @param storeDir directory where main data should go after commit
      * @param workDir directory where transactions store temporary data 
      * @param idMapper mapper for resourceId to path
+     * @param txIdMapper mapper for transaction id to path
      * @param logger the logger to be used by this store
      * @param debug if set to <code>true</code> logs all locking information to "transaction.log" for debugging inspection 
      */
@@ -251,13 +253,15 @@
         String storeDir,
         String workDir,
         ResourceIdToPathMapper idMapper,
+        TransactionIdToPathMapper txIdMapper,
         LoggerFacade logger,
         boolean debug) {
         this.workDir = workDir;
         this.storeDir = storeDir;
+        this.idMapper = idMapper;
+        this.txIdMapper = txIdMapper;
         this.logger = logger;
         this.debug = debug;
-        this.idMapper = idMapper;
     }
 
     /**
@@ -505,7 +509,7 @@
         if (logger.isFineEnabled()) logger.logFine("Starting Tx " + txId);
 
         assureStarted(); // can only start a new transaction when not already stopping
-        if (txId == null || txId.toString().length() == 0) {
+        if (txId == null || txIdMapper.getPathForId(txId).length() == 0) {
             throw new ResourceManagerException(ERR_TXID_INVALID, txId);
         }
 
@@ -1032,7 +1036,7 @@
     }
 
     protected String getTransactionBaseDir(Object txId) {
-        return workDir + '/' + txId.toString();
+        return workDir + '/' + txIdMapper.getPathForId(txId);
     }
 
     protected String getChangePath(Object txId, Object path) {
@@ -1278,7 +1282,7 @@
             return;
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
-            String txId = file.getName();
+            Object txId = txIdMapper.getIdForPath(file.getName());
             // recover all transactions we do not already know
             if (!globalTransactions.containsKey(txId)) {
 

Added: jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/TransactionIdToPathMapper.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/TransactionIdToPathMapper.java?rev=416152&view=auto
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/TransactionIdToPathMapper.java (added)
+++ jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/file/TransactionIdToPathMapper.java Wed Jun 21 15:57:28 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright 1999-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.transaction.file;
+
+/**
+ * Maps transaction ids to paths and back.
+ * 
+ * @version SVN $Id$
+ * @since 1.2
+ */
+public interface TransactionIdToPathMapper {
+
+    /**
+     * Maps the transaction id object to a path string. 
+     * 
+     * @param txId the transaction id
+     * @return the path string
+     */
+    String getPathForId(Object txId);
+    
+    /**
+     * Maps the path string to a transaction id object. 
+     * 
+     * @param path the path
+     * @return the path string
+     */
+    Object getIdForPath(String path);
+    
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org