Author: pnedonosko
Date: 2009-11-17 07:26:25 -0500 (Tue, 17 Nov 2009)
New Revision: 714
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
Log:
EXOJCR-203: JDBC loader TX support
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-11-17
11:57:53 UTC (rev 713)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-11-17
12:26:25 UTC (rev 714)
@@ -23,6 +23,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import javax.jcr.RepositoryException;
@@ -56,6 +57,12 @@
{
protected static final Log LOG =
ExoLogger.getLogger("jcr.JDBCCacheLoader");
+ /**
+ * Storage connections involved in transactions.
+ */
+ protected Map<Object, WorkspaceStorageConnection> transactions =
+ new ConcurrentHashMap<Object, WorkspaceStorageConnection>();
+
private IndividualCacheLoaderConfig config;
private WorkspaceDataContainer dataContainer;
@@ -81,7 +88,7 @@
}
/**
- * Put all Modifications into JDBC database, but don't commite them.
+ * Apply all Modifications to JDBC database, but don't commite them.
*
* @param modifications List if Modification
* @param conn WorkspaceStorageConnection
@@ -103,10 +110,10 @@
switch (m.getType())
{
case PUT_DATA :
- LOG.info("PUT_DATA modification");
+ LOG.warn("PUT_DATA modification");
break;
case PUT_DATA_ERASE :
- LOG.info("PUT_DATA_ERASE modification");
+ LOG.warn("PUT_DATA_ERASE modification");
break;
case PUT_KEY_VALUE :
@@ -117,10 +124,10 @@
break;
case REMOVE_DATA :
- LOG.info("REMOVE_DATA modification");
+ LOG.warn("REMOVE_DATA modification");
break;
case REMOVE_KEY_VALUE :
- LOG.info("REMOVE_KEY_VALUE modification");
+ LOG.warn("REMOVE_KEY_VALUE modification");
break;
case REMOVE_NODE :
@@ -128,7 +135,7 @@
break;
case MOVE :
- LOG.info("MOVE modification");
+ LOG.warn("MOVE modification");
break;
default :
throw new CacheException("Unknown modification " +
m.getType());
@@ -492,24 +499,36 @@
}
- // TRANSACTION support
+ // 2-phase TRANSACTION support
/**
* {@inheritDoc}
*/
- public void prepare(Object tx, List<Modification> modifications, boolean
one_phase) throws Exception
+ public void prepare(Object tx, List<Modification> modifications, boolean
onePhase) throws Exception
{
- put(modifications);
+ final WorkspaceStorageConnection exconn = transactions.remove(tx);
+ if (exconn != null)
+ {
+ apply(exconn, modifications);
+ }
+ else
+ {
+ final WorkspaceStorageConnection conn = dataContainer.openConnection();
+ apply(exconn, modifications);
+ transactions.put(tx, conn);
+ }
- if (one_phase)
+ final WorkspaceStorageConnection conn = dataContainer.openConnection();
+ apply(conn, modifications);
+
+ if (onePhase)
{
- //put(modifications);
- //commitJDBC();
+ conn.commit();
}
else
{
- //transactions.put(tx, modifications);
+ transactions.put(tx, conn);
}
}
@@ -518,14 +537,13 @@
*/
public void commit(Object tx) throws Exception
{
- // List<Modification> modifications = transactions.remove(tx);
- // if (modifications == null)
- // {
- // throw new Exception("transaction " + tx + " not found in
transaction table");
- // }
- // put(modifications);
+ final WorkspaceStorageConnection conn = transactions.remove(tx);
+ if (conn == null)
+ {
+ throw new RepositoryException("Transaction " + tx + " not found
in transaction table.");
+ }
- //commitJDBC();
+ conn.commit();
}
/**
@@ -533,9 +551,23 @@
*/
public void rollback(Object tx)
{
- //transactions.remove(tx);
-
- //rollbackJDBC();
+ final WorkspaceStorageConnection conn = transactions.remove(tx);
+ if (conn != null)
+ {
+ try
+ {
+ conn.rollback();
+ }
+ catch (Throwable e)
+ {
+ // TODO why we cannot throw an exception???
+ LOG.error("Error of transaction " + tx + " rollback.",
e);
+ }
+ }
+ else
+ {
+ LOG.warn("Transaction " + tx + " not found in transaction table,
but rollback called.");
+ }
}
// SHOULD NOT BE USED methods
Show replies by date