Author: sergiykarpenko
Date: 2010-09-15 03:48:08 -0400 (Wed, 15 Sep 2010)
New Revision: 3114
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBCleaner.java
Log:
EXOJCR-939: DBCleaner code cleanup
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBCleaner.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBCleaner.java 2010-09-14
15:58:35 UTC (rev 3113)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBCleaner.java 2010-09-15
07:48:08 UTC (rev 3114)
@@ -39,10 +39,10 @@
protected final static Log LOG =
ExoLogger.getLogger("exo.jcr.component.core.DBCleaner");
+ protected final static int MAX_IDS_RETURNED = 100;
+
protected String REMOVE_PROPERTIES;
- protected String REMOVE_ROOT;
-
protected String REMOVE_ITEMS;
protected String REMOVE_VALUES;
@@ -94,7 +94,7 @@
{
try
{
- //connection.setAutoCommit(false);
+ connection.setAutoCommit(false);
// check is multi db
if (isMultiDB)
{
@@ -106,12 +106,10 @@
// clean up all record of this container
removeWorkspaceRecords();
}
- //connection.commit();
+ connection.commit();
}
catch (SQLException e)
{
-
- // TODO do we need rollback here?
try
{
connection.rollback();
@@ -144,12 +142,9 @@
GET_CHILD_IDS =
"select ID from JCR_SITEM where CONTAINER_NAME=? and ID not in(select
PARENT_ID from JCR_SITEM where CONTAINER_NAME=?)";
- REMOVE_ITEMS =
// "delete from JCR_SITEM where CONTAINER_NAME=?";
- "delete from JCR_SITEM where ID in( ? )";
+ REMOVE_ITEMS = "delete from JCR_SITEM where ID in( ? )";
- //REMOVE_ROOT = "delete from JCR_SITEM where CONTAINER_NAME=? and ID=?";
-
REMOVE_VALUES =
"delete from JCR_SVALUE where exists"
+ "(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID
and JCR_SITEM.CONTAINER_NAME=?)";
@@ -225,9 +220,8 @@
// Remove only child nodes in cycle, till all nodes will be removed.
// Such algorithm used to avoid any constraint violation exception related to
foreign key.
-
PreparedStatement getChildItems = null;
- PreparedStatement removeItems = null;
+ Statement removeItems = connection.createStatement();
try
{
@@ -235,33 +229,27 @@
getChildItems.setString(1, containerName);
getChildItems.setString(2, containerName);
- // TODO constant
- getChildItems.setMaxRows(100);
+ getChildItems.setMaxRows(MAX_IDS_RETURNED);
- //removeItems = connection.prepareStatement(REMOVE_ITEMS);
-
do
{
ResultSet result = getChildItems.executeQuery();
- if (result.first())
+ StringBuilder childListBuilder = new StringBuilder();
+ if (result.next())
{
- StringBuilder childListBuilder = new StringBuilder("'" +
result.getString(1) + "'");
- while (result.next())
- {
- childListBuilder.append(" , '" + result.getString(1) +
"'");
- }
-
- // now remove nodes;
- String q = REMOVE_ITEMS.replace("?",
childListBuilder.toString());
- removeItems = connection.prepareStatement(q);
- //removeItems.se.setString(1, childListBuilder.toString());
- int res = removeItems.executeUpdate();
+ childListBuilder.append("'" + result.getString(1) +
"'");
}
else
{
break;
}
-
+ while (result.next())
+ {
+ childListBuilder.append(" , '" + result.getString(1) +
"'");
+ }
+ // now remove nodes;
+ String q = REMOVE_ITEMS.replace("?", childListBuilder.toString());
+ removeItems.executeUpdate(q);
}
while (true);
}
Show replies by date