[exo-jcr-commits] exo-jcr SVN: r3679 - in jcr/trunk: exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Dec 20 04:24:05 EST 2010


Author: tolusha
Date: 2010-12-20 04:24:04 -0500 (Mon, 20 Dec 2010)
New Revision: 3679

Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerException.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc/TestDBCleanerService.java
   jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/db-cleaner-service.xml
Log:
EXOJCR-939: clean data for single workspace in case of multi-db is not supported

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerException.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerException.java	2010-12-20 08:22:12 UTC (rev 3678)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerException.java	2010-12-20 09:24:04 UTC (rev 3679)
@@ -35,4 +35,15 @@
    {
       super(message, e);
    }
+
+   /**
+    * Constructor DBCleanerException.
+    * 
+    * @param message
+    *          error message
+    */
+   public DBCleanerException(String message)
+   {
+      super(message);
+   }
 }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java	2010-12-20 08:22:12 UTC (rev 3678)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java	2010-12-20 09:24:04 UTC (rev 3679)
@@ -20,6 +20,7 @@
 import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
 import org.exoplatform.services.jcr.config.RepositoryEntry;
 import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
 import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
 import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
 import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
@@ -58,6 +59,69 @@
     */
    public void cleanWorkspaceData(WorkspaceEntry wsEntry) throws DBCleanerException
    {
+      SecurityManager security = System.getSecurityManager();
+      if (security != null)
+      {
+         security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
+      }
+
+      boolean isMultiDb;
+      try
+      {
+         String multiDb = wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB);
+         if (multiDb == null)
+         {
+            throw new RepositoryConfigurationException("Parameter " + JDBCWorkspaceDataContainer.MULTIDB
+               + " not found in workspace configuration " + wsEntry.getName());
+         }
+
+         isMultiDb = Boolean.parseBoolean(multiDb);
+      }
+      catch (RepositoryConfigurationException e)
+      {
+         throw new DBCleanerException("Can't define " + JDBCWorkspaceDataContainer.MULTIDB + " parameter", e);
+      }
+
+      if (isMultiDb)
+      {
+         throw new DBCleanerException("Clean of single workspace for multi-db is not supported");
+      }
+
+      getDBCleaner(wsEntry).clean();
+   }
+
+   /**
+    * Cleanup repository data from database.
+    * 
+    * @param repoEntry 
+    *          repository configuration
+    * @throws DBCleanerException 
+    *          if any exception is occurred
+    */
+   public void cleanRepositoryData(RepositoryEntry repoEntry) throws DBCleanerException
+   {
+      SecurityManager security = System.getSecurityManager();
+      if (security != null)
+      {
+         security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
+      }
+
+      for (WorkspaceEntry wsEntry : repoEntry.getWorkspaceEntries())
+      {
+         getDBCleaner(wsEntry).clean();
+      }
+   }
+
+   /**
+    * Returns DBCleaner for defined workspace.
+    * 
+    * @param wsEntry 
+    *          workspace configuration
+    * @throws DBCleanerException 
+    *          if any exception is occurred
+    */
+   private DBCleaner getDBCleaner(WorkspaceEntry wsEntry) throws DBCleanerException
+   {
       String sourceName;
       try
       {
@@ -175,23 +239,6 @@
          }
       }
 
-      // clean data
-      dbCleaner.clean();
+      return dbCleaner;
    }
-
-   /**
-    * Cleanup repository data from database.
-    * 
-    * @param repoEntry 
-    *          repository configuration
-    * @throws DBCleanerException 
-    *          if any exception is occurred
-    */
-   public void cleanRepositoryData(RepositoryEntry repoEntry) throws DBCleanerException
-   {
-      for (WorkspaceEntry wsEntry : repoEntry.getWorkspaceEntries())
-      {
-         cleanWorkspaceData(wsEntry);
-      }
-   }
 }

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc/TestDBCleanerService.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc/TestDBCleanerService.java	2010-12-20 08:22:12 UTC (rev 3678)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/util/jdbc/TestDBCleanerService.java	2010-12-20 09:24:04 UTC (rev 3679)
@@ -23,6 +23,7 @@
 import org.exoplatform.services.jcr.impl.core.NodeImpl;
 import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
 import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerException;
 import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerService;
 import org.exoplatform.services.jcr.util.IdGenerator;
 import org.exoplatform.services.jcr.util.TesterConfigurationHelper;
@@ -249,21 +250,18 @@
       Statement statement = conn.createStatement();
       ResultSet res = statement.executeQuery("select * from JCR_MITEM where ID='" + id + "'");
       assertTrue(res.next());
+      statement.close();
 
       // remove workspace data from database
-      new DBCleanerService().cleanWorkspaceData(repositoryEntry.getWorkspaceEntries().get(0));
-
-      // check - does JCR_SITEM become empty
       try
       {
-         res = statement.executeQuery("select * from JCR_MITEM where ID='" + id + "'");
-         fail();
+         new DBCleanerService().cleanWorkspaceData(repositoryEntry.getWorkspaceEntries().get(0));
+         fail("Exception should be thrown");
       }
-      catch (SQLException e)
+      catch (DBCleanerException e)
       {
-         //ok
+
       }
-      statement.close();
 
       service.removeRepository(repositoryName);
    }

Modified: jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/db-cleaner-service.xml
===================================================================
--- jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/db-cleaner-service.xml	2010-12-20 08:22:12 UTC (rev 3678)
+++ jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/db-cleaner-service.xml	2010-12-20 09:24:04 UTC (rev 3679)
@@ -64,30 +64,8 @@
   </section>
 
   <section>
-    <title>Scripts in detail</title>
+    <title>Limitation</title>
 
-    <para>Single and Multi DB scripts examples</para>
-
-    <para>In case of isMultiDB="true", will use:</para>
-
-    <programlisting>DROP TABLE JCR_MREF;
-DROP TABLE JCR_MVALUE;
-DROP TABLE JCR_MITEM;</programlisting>
-
-    <para>In case of isMultiDB="false", will use:</para>
-
-    <programlisting>delete from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?);
-delete from JCR_SREF where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SREF.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?);
-delete from JCR_SITEM where CONTAINER_NAME=?;</programlisting>
-
-    <note>
-      <para>"?" will be replased with container name on execution.</para>
-    </note>
-
-    <para>But some database do not support cascade delete or need special
-    sittings, so query "delete from JCR_SITEM where CONTAINER_NAME=?" may
-    causes constraint violation exception. In such case will be used deleting
-    like visitor does. First traverse to the bottom of the tree and then go up
-    to the root and perform deleting children. </para>
+    <para>Clean of single workspace for multi-db is not supported.</para>
   </section>
 </chapter>



More information about the exo-jcr-commits mailing list