[exo-jcr-commits] exo-jcr SVN: r1458 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/core and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jan 18 05:23:10 EST 2010


Author: pnedonosko
Date: 2010-01-18 05:23:10 -0500 (Mon, 18 Jan 2010)
New Revision: 1458

Added:
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionException.java
Modified:
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/XASession.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java
Log:
EXOJCR-405 XASession can return last commit Exception; log.debug added; TransactionableDM commit execptions with messages

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/XASession.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/XASession.java	2010-01-18 08:56:04 UTC (rev 1457)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/XASession.java	2010-01-18 10:23:10 UTC (rev 1458)
@@ -18,6 +18,8 @@
  */
 package org.exoplatform.services.jcr.core;
 
+import org.exoplatform.services.transaction.TransactionException;
+
 import javax.jcr.Session;
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
@@ -50,4 +52,11 @@
     * @throws XAException
     */
    void delistResource() throws XAException;
+   
+   /**
+    * Returns TransactionException of a last commit XA intransaction context. Can be null. For information purpose.
+    *
+    * @return TransactionException commit exception
+    */
+   TransactionException getCommitException();
 }

Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionException.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionException.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionException.java	2010-01-18 10:23:10 UTC (rev 1458)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.services.jcr.impl.core;
+
+import javax.transaction.xa.XAException;
+
+/**
+ * Provides XAException functionality with constructor for errorcode and message.
+ * 
+ * @author <a href="mailto:peter.nedonosko at exoplatform.com">Peter Nedonosko</a>
+ * @version $Id$
+ *  */
+public class XASessionException extends XAException
+{
+
+   /**
+    * serialVersionUID.
+    */
+   private static final long serialVersionUID = -1853702973389878895L;
+
+   public XASessionException()
+   {
+      super();
+   }
+
+   public XASessionException(int errcode)
+   {
+      super(errcode);
+   }
+
+   public XASessionException(String s)
+   {
+      super(s);
+   }
+   
+   public XASessionException(String s, int errorCode)
+   {
+      super(s);
+      this.errorCode = errorCode;
+   }
+}


Property changes on: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionException.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java	2010-01-18 08:56:04 UTC (rev 1457)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java	2010-01-18 10:23:10 UTC (rev 1458)
@@ -75,6 +75,11 @@
    private Object payload;
 
    /**
+    * TransactionException of a last commit in context of a transaction. Can be set on commit and will be restet on enlist/delist resource or rollback. 
+    */
+   private TransactionException commitException = null;
+
+   /**
     * XASessionImpl constructor.
     * 
     * @param workspaceName
@@ -130,16 +135,27 @@
             LOG.debug("Delist session: " + getSessionInfo() + ", " + this);
          }
 
+         commitException = null;
          txResourceManager.remove(this);
          tService.delistResource(this);
       }
       catch (RollbackException e)
       {
-         throw new XAException(e.getMessage());
+         if (LOG.isDebugEnabled())
+         {
+            LOG.debug("Delist error, session: " + getSessionInfo() + ", " + this, e);
+         }
+
+         throw new XASessionException("Cannot delist resource XASession " + getSessionInfo() + ". " + e);
       }
       catch (SystemException e)
       {
-         throw new XAException(e.getMessage());
+         if (LOG.isDebugEnabled())
+         {
+            LOG.debug("Delist error, session: " + getSessionInfo() + ", " + this, e);
+         }
+
+         throw new XASessionException("Cannot delist resource XASession " + getSessionInfo() + ". " + e);
       }
    }
 
@@ -156,16 +172,27 @@
             LOG.debug("Enlist session: " + getSessionInfo() + ", " + this);
          }
 
+         commitException = null;
          txResourceManager.add(this);
          tService.enlistResource(this);
       }
       catch (RollbackException e)
       {
-         throw new XAException(e.getMessage());
+         if (LOG.isDebugEnabled())
+         {
+            LOG.debug("Enlist error, session: " + getSessionInfo() + ", " + this, e);
+         }
+
+         throw new XASessionException("Cannot enlist resource XASession " + getSessionInfo() + ". " + e);
       }
       catch (SystemException e)
       {
-         throw new XAException(e.getMessage());
+         if (LOG.isDebugEnabled())
+         {
+            LOG.debug("Enlist error, session: " + getSessionInfo() + ", " + this, e);
+         }
+
+         throw new XASessionException("Cannot enlist resource XASession " + getSessionInfo() + ". " + e);
       }
    }
 
@@ -180,7 +207,13 @@
       }
       catch (TransactionException e)
       {
-         throw new XAException(XAException.XA_RBOTHER);
+         commitException = e;
+         if (LOG.isDebugEnabled())
+         {
+            LOG.debug("Commit Error. Xid:" + xid + ", session: " + getSessionInfo() + ", " + this, e);
+         }
+
+         throw new XASessionException(e.toString(), XAException.XA_RBOTHER);
       }
 
       if (LOG.isDebugEnabled())
@@ -207,6 +240,13 @@
     */
    public void forget(Xid xid) throws XAException
    {
+      // TODO forget = rollback?
+      //txResourceManager.rollback(this);
+
+      //if (LOG.isDebugEnabled())
+      //{
+      //   LOG.debug("Forget. Xid:" + xid + ", session: " + getSessionInfo() + ", " + this);
+      //}
    }
 
    /**
@@ -231,6 +271,7 @@
             LOG.debug("isSameRM: " + getSessionInfo() + " -- " + session.getSessionInfo() + " : " + isSame + ", "
                + this + " -- " + session + ", Flags:" + startFlags);
          }
+
          return isSame;
       }
       return false;
@@ -263,6 +304,7 @@
    public void rollback(Xid xid) throws XAException
    {
       txResourceManager.rollback(this);
+      commitException = null;
 
       if (LOG.isDebugEnabled())
       {
@@ -281,7 +323,13 @@
       }
       catch (SystemException e)
       {
-         throw new XAException(e.getMessage());
+         if (LOG.isDebugEnabled())
+         {
+            LOG.debug("Cannot set transaction timeout " + seconds + "sec via XASession " + getSessionInfo() + ". ", e);
+         }
+
+         throw new XASessionException("Cannot set transaction timeout " + seconds + "sec via XASession "
+            + getSessionInfo() + ". " + e);
       }
       this.txTimeout = seconds;
       return true;
@@ -330,7 +378,7 @@
          }
          catch (XAException e)
          {
-            LOG.error("Logut error " + e, e);
+            LOG.error("Logout error " + e, e);
          }
       }
    }
@@ -345,13 +393,27 @@
       return getUserID() + "@" + workspaceName;
    }
 
+   /**
+    * {@inheritDoc}
+    */
    public Object getPayload()
    {
       return payload;
    }
 
+   /**
+    * {@inheritDoc}
+    */
    public void setPayload(Object payload)
    {
       this.payload = payload;
    }
+
+   /**
+    * {@inheritDoc}
+    */
+   public TransactionException getCommitException()
+   {
+      return commitException;
+   }
 }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java	2010-01-18 08:56:04 UTC (rev 1457)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/TransactionableDataManager.java	2010-01-18 10:23:10 UTC (rev 1458)
@@ -303,11 +303,11 @@
          }
          catch (InvalidItemStateException e)
          {
-            throw new TransactionException(e);
+            throw new TransactionException(e.getMessage(), e);
          }
          catch (RepositoryException e)
          {
-            throw new TransactionException(e);
+            throw new TransactionException(e.getMessage(), e);
          }
       }
    }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java	2010-01-18 08:56:04 UTC (rev 1457)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/xa/TestUserTransaction.java	2010-01-18 10:23:10 UTC (rev 1458)
@@ -31,8 +31,8 @@
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
 import javax.naming.InitialContext;
+import javax.transaction.RollbackException;
 import javax.transaction.UserTransaction;
-import javax.transaction.xa.XAException;
 
 /**
  * Created by The eXo Platform SAS. <br>
@@ -112,7 +112,7 @@
       return someSessions;
    }
 
-   public void testCommit() throws Exception
+   public void _testCommit() throws Exception
    {
       assertNotNull(txService);
       List<Session> someSessions = openSomeSessions();
@@ -143,7 +143,7 @@
       someSessions.clear();
    }
 
-   public void testRollback() throws Exception
+   public void _testRollback() throws Exception
    {
       assertNotNull(txService);
       UserTransaction ut = txService.getUserTransaction();
@@ -168,17 +168,15 @@
       }
    }
 
-   public void testUserTransactionFromJndi() throws Exception
+   public void _testUserTransactionFromJndi() throws Exception
    {
       assertNotNull(txService);
 
       // TODO in JNDI only JOTM today
-      //InitialContext ctx = new InitialContext();
-      //Object obj = ctx.lookup("UserTransaction");
-      //UserTransaction ut = (UserTransaction)obj;
+      InitialContext ctx = new InitialContext();
+      Object obj = ctx.lookup("UserTransaction");
+      UserTransaction ut = (UserTransaction)obj;
 
-      UserTransaction ut = txService.getUserTransaction();
-
       ut.begin();
       Session s1 =
          repository.login(new SimpleCredentials("admin", "admin".toCharArray()), session.getWorkspace().getName());
@@ -186,10 +184,9 @@
       s1.save();
       ut.commit();
       assertNotNull(session.getItem("/txcommit1"));
-
    }
 
-   public void testReuseUT() throws Exception
+   public void _testReuseUT() throws Exception
    {
       assertNotNull(txService);
       // TODO in JNDI only JOTM today
@@ -230,7 +227,7 @@
       UserTransaction ut = txService.getUserTransaction();
 
       Session s0 =
-         repository.login(new SimpleCredentials("admin", "admin".toCharArray()), session.getWorkspace().getName());
+         repository.login(new SimpleCredentials("root", "exo".toCharArray()), session.getWorkspace().getName());
       Node pretx = s0.getRootNode().addNode("pretx");
       s0.save();
 
@@ -250,17 +247,19 @@
       {
          ut.commit();
          // internally XAException should be thrown
-         fail("XAException with InvalidItemState should occurs");
+         fail("Exception should occurs");
       }
-      catch (Throwable e)
+      catch (Exception e)
       {
          // ok
-         e.printStackTrace();
-         System.out.println(e);
+         assertNotNull(((XASession) s1).getCommitException());
       }
 
-      assertNotNull(session.getItem("/pretx/tx1"));
-
+      try {
+         session.getItem("/pretx/tx1");
+         fail("PathNotFoundException should be thrown");
+      } catch(PathNotFoundException e) {
+         // ok
+      }
    }
-
 }



More information about the exo-jcr-commits mailing list