[exo-jcr-commits] exo-jcr SVN: r850 - in jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc: db and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Nov 25 04:00:49 EST 2009


Author: nzamosenchuk
Date: 2009-11-25 04:00:49 -0500 (Wed, 25 Nov 2009)
New Revision: 850

Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
Log:
EXOJCR-262: Cleanup implemented on JDBCWorkspaceDataContainer startup, using method deleteLockProperties() from JDBCStorageConnection.

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java	2009-11-24 16:50:33 UTC (rev 849)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java	2009-11-25 09:00:49 UTC (rev 850)
@@ -218,6 +218,16 @@
    protected String DELETE_REF;
 
    /**
+    * Sweep Lock-property's value(jcr:LockIsDeep, jcr:LockOwner)
+    */
+   protected String DELETE_LOCK_VALUES;
+
+   /**
+    * Sweep Lock-properties (jcr:LockIsDeep, jcr:LockOwner)
+    */
+   protected String DELETE_LOCK_PROPERTIES;
+
+   /**
     * FIND_REFERENCE
     */
    protected String FIND_REFERENCE;

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java	2009-11-24 16:50:33 UTC (rev 849)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java	2009-11-25 09:00:49 UTC (rev 850)
@@ -2413,5 +2413,7 @@
    protected abstract ResultSet findAllNodeIdentifiers() throws SQLException;
 
    protected abstract ResultSet findAllReferencedNodeIdentifiers() throws SQLException;
+   
+   protected abstract void deleteLockProperties() throws SQLException;
 
 }

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java	2009-11-24 16:50:33 UTC (rev 849)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java	2009-11-25 09:00:49 UTC (rev 850)
@@ -46,6 +46,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.sql.Connection;
+import java.sql.SQLException;
 
 import javax.jcr.RepositoryException;
 import javax.naming.InitialContext;
@@ -295,6 +296,8 @@
             LOG.debug("update-storage parameter is not set " + dbSourceName);
       }
 
+      deleteLockProperties();
+
       this.storageVersion =
          StorageUpdateManager.checkVersion(dbSourceName, this.connFactory.getJdbcConnection(), multiDb,
             enableStorageUpdate);
@@ -303,6 +306,30 @@
    }
 
    /**
+    * Removes all the properties in repository: "jcr:lockOwner" & "jcr:lockIsDeep"
+    * 
+    * @throws RepositoryException
+    * @throws IllegalStateException
+    */
+   protected void deleteLockProperties() throws RepositoryException
+   {
+      // try to sweep lock properties
+      JDBCStorageConnection connection = (JDBCStorageConnection)this.connFactory.openConnection();
+      try
+      {
+         if (LOG.isDebugEnabled())
+            LOG.debug("Sweeping old lock's properties on " + dbSourceName);
+         (connection).deleteLockProperties();
+         connection.commit();
+      }
+      catch (SQLException e)
+      {
+         connection.rollback();
+         LOG.error("Unable to remove lock properties. Rollback...", e);
+      }
+   }
+
+   /**
     * Prepare sefault connection factory.
     * 
     * @return GenericConnectionFactory

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java	2009-11-24 16:50:33 UTC (rev 849)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java	2009-11-25 09:00:49 UTC (rev 850)
@@ -122,6 +122,10 @@
 
    protected PreparedStatement deleteValue;
 
+   protected PreparedStatement deleteLockValues;
+
+   protected PreparedStatement deleteLockProperties;
+
    protected PreparedStatement renameNode;
 
    protected PreparedStatement findReference;
@@ -246,6 +250,9 @@
       DELETE_VALUE = "delete from JCR_MVALUE where PROPERTY_ID=?";
       DELETE_REF = "delete from JCR_MREF where PROPERTY_ID=?";
 
+      DELETE_LOCK_VALUES =
+         "delete from JCR_MVALUE where PROPERTY_ID in (select ID from JCR_MITEM where (NAME=? or NAME=?) and I_CLASS=2)";
+      DELETE_LOCK_PROPERTIES = "delete from JCR_MITEM where (NAME=? or NAME=?) and I_CLASS=2";
    }
 
    /**
@@ -745,4 +752,31 @@
 
       return result;
    }
+
+   /**
+    * @see org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection#deleteLockProperties()
+    */
+   @Override
+   protected void deleteLockProperties() throws SQLException
+   {
+      // delete property values first
+      if (deleteLockValues == null)
+      {
+         deleteLockValues = dbConnection.prepareStatement(DELETE_LOCK_VALUES);
+         deleteLockValues.setString(1, "[" + Constants.NS_JCR_URI + "]" + Constants.JCR_LOCKISDEEP.getName());
+         deleteLockValues.setString(2, "[" + Constants.NS_JCR_URI + "]" + Constants.JCR_LOCKOWNER.getName());
+      }
+
+      deleteLockValues.executeUpdate();
+
+      // delete actuall properties
+      if (deleteLockProperties == null)
+      {
+         deleteLockProperties = dbConnection.prepareStatement(DELETE_LOCK_PROPERTIES);
+         deleteLockProperties.setString(1, "[" + Constants.NS_JCR_URI + "]" + Constants.JCR_LOCKISDEEP.getName());
+         deleteLockProperties.setString(2, "[" + Constants.NS_JCR_URI + "]" + Constants.JCR_LOCKOWNER.getName());
+      }
+
+      deleteLockProperties.executeUpdate();
+   }
 }

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java	2009-11-24 16:50:33 UTC (rev 849)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java	2009-11-25 09:00:49 UTC (rev 850)
@@ -121,6 +121,10 @@
 
    protected PreparedStatement deleteValue;
 
+   protected PreparedStatement deleteLockValues;
+
+   protected PreparedStatement deleteLockProperties;
+
    protected PreparedStatement renameNode;
 
    protected PreparedStatement findReference;
@@ -257,6 +261,10 @@
       DELETE_ITEM = "delete from JCR_SITEM where ID=?";
       DELETE_VALUE = "delete from JCR_SVALUE where PROPERTY_ID=?";
       DELETE_REF = "delete from JCR_SREF where PROPERTY_ID=?";
+
+      DELETE_LOCK_VALUES =
+         "delete from JCR_SVALUE where PROPERTY_ID in (select ID from JCR_SITEM where (NAME=? or NAME=?) and I_CLASS=2)";
+      DELETE_LOCK_PROPERTIES = "delete from JCR_SITEM where (NAME=? or NAME=?) and I_CLASS=2";
    }
 
    /**
@@ -761,4 +769,31 @@
 
       return result;
    }
+
+   /**
+    * @see org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection#deleteLockProperties()
+    */
+   @Override
+   protected void deleteLockProperties() throws SQLException
+   {
+      // delete property values first
+      if (deleteLockValues == null)
+      {
+         deleteLockValues = dbConnection.prepareStatement(DELETE_LOCK_VALUES);
+         deleteLockValues.setString(1, "[" + Constants.NS_JCR_URI + "]" + Constants.JCR_LOCKISDEEP.getName());
+         deleteLockValues.setString(2, "[" + Constants.NS_JCR_URI + "]" + Constants.JCR_LOCKOWNER.getName());
+      }
+
+      deleteLockValues.executeUpdate();
+
+      // delete actuall properties
+      if (deleteLockProperties == null)
+      {
+         deleteLockProperties = dbConnection.prepareStatement(DELETE_LOCK_PROPERTIES);
+         deleteLockProperties.setString(1, "[" + Constants.NS_JCR_URI + "]" + Constants.JCR_LOCKISDEEP.getName());
+         deleteLockProperties.setString(2, "[" + Constants.NS_JCR_URI + "]" + Constants.JCR_LOCKOWNER.getName());
+      }
+
+      deleteLockProperties.executeUpdate();
+   }
 }



More information about the exo-jcr-commits mailing list