[exo-jcr-commits] exo-jcr SVN: r3599 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Dec 3 08:33:48 EST 2010
Author: tolusha
Date: 2010-12-03 08:33:47 -0500 (Fri, 03 Dec 2010)
New Revision: 3599
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/HSQLSingleDBCleaner.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MultiDBCleaner.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/SingleDBCleaner.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/WorkspaceDBCleaner.java
Log:
EXOJCR-939: clean JCR_LOCK tables also
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/HSQLSingleDBCleaner.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/HSQLSingleDBCleaner.java 2010-12-03 11:19:01 UTC (rev 3598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/HSQLSingleDBCleaner.java 2010-12-03 13:33:47 UTC (rev 3599)
@@ -17,6 +17,8 @@
package org.exoplatform.services.jcr.impl.util.jdbc.cleaner;
import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author <a href="mailto:anatoliy.bazko at gmail.com">Anatoliy Bazko</a>
@@ -31,12 +33,17 @@
public HSQLSingleDBCleaner(String containerName, Connection connection)
{
super(containerName, connection, true);
+ }
- this.scripts =
- new String[]{
- "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 I_CLASS=2 and CONTAINER_NAME=?"};
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected List<String> getDBCleanScripts()
+ {
+ List<String> scripts = new ArrayList<String>(commonSingleDBCleanScripts);
+ scripts.add("delete from JCR_SITEM where I_CLASS=2 and CONTAINER_NAME='" + containerName + "'");
+
+ return scripts;
}
-
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MultiDBCleaner.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MultiDBCleaner.java 2010-12-03 11:19:01 UTC (rev 3598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MultiDBCleaner.java 2010-12-03 13:33:47 UTC (rev 3599)
@@ -17,6 +17,8 @@
package org.exoplatform.services.jcr.impl.util.jdbc.cleaner;
import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author <a href="mailto:anatoliy.bazko at gmail.com">Anatoliy Bazko</a>
@@ -26,12 +28,30 @@
{
/**
+ * Common clean scripts for multi database.
+ */
+ protected final List<String> commonMutliDBCleanScripts = new ArrayList<String>();
+
+ /**
* MultiDBCleaner constructor.
*/
public MultiDBCleaner(String containerName, Connection connection)
{
super(containerName, connection);
- this.scripts = new String[]{"DROP TABLE JCR_MREF", "DROP TABLE JCR_MVALUE", "DROP TABLE JCR_MITEM"};
+ commonMutliDBCleanScripts.add("drop table JCR_MREF");
+ commonMutliDBCleanScripts.add("drop table JCR_MVALUE");
+ commonMutliDBCleanScripts.add("drop table JCR_MITEM");
+ commonMutliDBCleanScripts.add("drop table JCR_LOCK_" + containerName.toUpperCase());
+ commonMutliDBCleanScripts.add("drop table JCR_LOCK_" + containerName.toUpperCase() + "_D");
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected List<String> getDBCleanScripts()
+ {
+ return commonMutliDBCleanScripts;
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java 2010-12-03 11:19:01 UTC (rev 3598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java 2010-12-03 13:33:47 UTC (rev 3599)
@@ -17,6 +17,8 @@
package org.exoplatform.services.jcr.impl.util.jdbc.cleaner;
import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author <a href="mailto:anatoliy.bazko at gmail.com">Anatoliy Bazko</a>
@@ -31,12 +33,17 @@
public MySQLSingleDBCleaner(String containerName, Connection connection)
{
super(containerName, connection, true);
+ }
- this.scripts =
- new String[]{
- "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 I_CLASS=2 and CONTAINER_NAME=?"};
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected List<String> getDBCleanScripts()
+ {
+ List<String> scripts = new ArrayList<String>(commonSingleDBCleanScripts);
+ scripts.add("delete from JCR_SITEM where I_CLASS=2 and CONTAINER_NAME='" + containerName + "'");
+
+ return scripts;
}
-
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/SingleDBCleaner.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/SingleDBCleaner.java 2010-12-03 11:19:01 UTC (rev 3598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/SingleDBCleaner.java 2010-12-03 13:33:47 UTC (rev 3599)
@@ -17,8 +17,8 @@
package org.exoplatform.services.jcr.impl.util.jdbc.cleaner;
import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author <a href="mailto:anatoliy.bazko at gmail.com">Anatoliy Bazko</a>
@@ -28,6 +28,11 @@
{
/**
+ * Common clean scripts for single database.
+ */
+ protected final List<String> commonSingleDBCleanScripts = new ArrayList<String>();
+
+ /**
* Indicates if need to use clean helper.
*/
protected final boolean postHelpClean;
@@ -54,11 +59,15 @@
this.postHelpClean = postHelpClean;
this.dbCleanHelper = new DBCleanHelper(containerName, connection);
- this.scripts =
- new String[]{
- "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=?"};
+
+ commonSingleDBCleanScripts
+ .add("delete from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
+ + containerName + "')");
+ commonSingleDBCleanScripts
+ .add("delete from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
+ + containerName + "')");
+ commonSingleDBCleanScripts.add("drop table JCR_LOCK_" + containerName.toUpperCase());
+ commonSingleDBCleanScripts.add("drop table JCR_LOCK_" + containerName.toUpperCase() + "_D");
}
/**
@@ -94,9 +103,11 @@
* {@inheritDoc}
*/
@Override
- protected void executeQuery(Statement statement, String sql) throws SQLException
+ protected List<String> getDBCleanScripts()
{
- final String q = (containerName != null) ? sql.replace("?", "'" + containerName + "'") : sql;
- super.executeQuery(statement, q);
+ List<String> scripts = new ArrayList<String>(commonSingleDBCleanScripts);
+ scripts.add("delete from JCR_SITEM where CONTAINER_NAME='" + containerName + "'");
+
+ return scripts;
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/WorkspaceDBCleaner.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/WorkspaceDBCleaner.java 2010-12-03 11:19:01 UTC (rev 3598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/WorkspaceDBCleaner.java 2010-12-03 13:33:47 UTC (rev 3599)
@@ -27,6 +27,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -54,11 +55,6 @@
protected final Connection connection;
/**
- * SQL scripts for data cleaning.
- */
- protected String[] scripts;
-
- /**
* Pattern for JCR tables.
*/
protected final Pattern dbObjectNamePattern;
@@ -99,14 +95,14 @@
{
connection.setAutoCommit(false);
st = connection.createStatement();
- for (String scr : scripts)
+ for (String scr : getDBCleanScripts())
{
String s = cleanWhitespaces(scr.trim());
if (s.length() > 0)
{
if (!canExecuteQuery(sql = s))
{
- // table from query not found , so try drop other
+ // table from query not found, so try drop other
continue;
}
@@ -180,8 +176,7 @@
String tableName = sql.substring(tMatcher.start(), tMatcher.end());
if (!isTableExists(connection, tableName))
{
- LOG.error("Table [" + tableName + "] from query [" + sql
- + "] was not found. So query will not be executed.");
+ LOG.warn("Table [" + tableName + "] from query [" + sql + "] was not found. So query will not be executed.");
return false;
}
}
@@ -251,4 +246,12 @@
return string;
}
+ /**
+ * Get SQL scripts for data cleaning.
+ *
+ * @return
+ * List of sql scripts
+ */
+ abstract List<String> getDBCleanScripts();
+
}
More information about the exo-jcr-commits
mailing list