exo-jcr SVN: r5718 - jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db.
by do-not-reply@jboss.org
Author: tolusha
Date: 2012-02-29 10:27:03 -0500 (Wed, 29 Feb 2012)
New Revision: 5718
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
Log:
EXOJCR-1762: auto-repair for DB inconsistency
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2012-02-29 15:25:40 UTC (rev 5717)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2012-02-29 15:27:03 UTC (rev 5718)
@@ -1165,11 +1165,11 @@
{
findMaxPropertyVersions = dbConnection.prepareStatement(FIND_MAX_PROPERTY_VERSIONS);
}
-.......
+
findMaxPropertyVersions.setString(1, getInternalId(parentId));
findMaxPropertyVersions.setString(2, name);
findMaxPropertyVersions.setInt(3, index);
-.
+
return findMaxPropertyVersions.executeQuery();
}
12 years, 1 month
exo-jcr SVN: r5717 - in jcr/branches/1.15.x/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/storage/jdbc and 3 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2012-02-29 10:25:40 -0500 (Wed, 29 Feb 2012)
New Revision: 5717
Added:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverValueRecords.java
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java
Log:
EXOJCR-1762: auto-repair for DB inconsistency
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java 2012-02-29 15:23:31 UTC (rev 5716)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java 2012-02-29 15:25:40 UTC (rev 5717)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.jcr.impl.checker;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
@@ -73,30 +74,10 @@
rollback(conn);
throw e;
}
- finally
- {
- closeConnection(conn);
- }
}
abstract void repairInternally(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException;
- protected void closeConnection(WorkspaceStorageConnection conn)
- {
- try
- {
- conn.close();
- }
- catch (IllegalStateException e)
- {
- LOG.error("Can not close connection", e);
- }
- catch (RepositoryException e)
- {
- LOG.error("Can not close connection", e);
- }
- }
-
protected void rollback(WorkspaceStorageConnection conn)
{
try
@@ -116,4 +97,17 @@
}
}
+ protected String exctractId(ResultSet resultSet) throws SQLException
+ {
+ String containerName = "";
+ try
+ {
+ containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
+ }
+ catch (SQLException e)
+ {
+ }
+
+ return resultSet.getString(DBConstants.COLUMN_ID).substring(containerName.length());
+ }
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java 2012-02-29 15:23:31 UTC (rev 5716)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java 2012-02-29 15:25:40 UTC (rev 5717)
@@ -125,33 +125,4 @@
throw new SQLException(e);
}
}
-
- private String exctractId(ResultSet resultSet) throws SQLException
- {
- String containerName = "";
- try
- {
- containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
- }
- catch (SQLException e)
- {
- }
-
- return resultSet.getString(DBConstants.COLUMN_ID).substring(containerName.length());
- }
-
- private String concatId(ResultSet resultSet, String id) throws SQLException
- {
- String containerName = "";
- try
- {
- containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
- }
- catch (SQLException e)
- {
- }
-
- return containerName + id;
- }
-
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java 2012-02-29 15:23:31 UTC (rev 5716)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java 2012-02-29 15:25:40 UTC (rev 5717)
@@ -18,12 +18,16 @@
*/
package org.exoplatform.services.jcr.impl.checker;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
+import javax.jcr.RepositoryException;
+
/**
* @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
* @version $Id: RemoveEarlierVersions.java 34360 2009-07-22 23:58:59Z tolusha $
@@ -44,5 +48,23 @@
*/
protected void repairInternally(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
{
+ try
+ {
+ PropertyData data = (PropertyData)conn.getItemData(exctractId(resultSet));
+ int maxVersion = conn.getMaxPropertyVersion(data);
+
+ if (resultSet.getInt(DBConstants.COLUMN_VERSION) < maxVersion)
+ {
+ conn.delete(data);
+ }
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
}
}
Added: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverValueRecords.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverValueRecords.java (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverValueRecords.java 2012-02-29 15:25:40 UTC (rev 5717)
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import org.exoplatform.services.jcr.datamodel.IllegalPathException;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.datamodel.ValueData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
+import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: RemoverValueRecords.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class RemoverValueRecords extends AbstractInconsistencyRepair
+{
+
+ private final String containerName;
+
+ private final boolean multiDb;
+
+ public RemoverValueRecords(WorkspaceStorageConnectionFactory connFactory, String containerName, boolean multiDb)
+ {
+ super(connFactory);
+ this.containerName = containerName;
+ this.multiDb = multiDb;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ void repairInternally(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ try
+ {
+ String propertyId = exctractId(resultSet);
+ QPath path = QPath.parse("[]");
+
+ PropertyData data = new TransientPropertyData(path, propertyId, 0, 0, null, false, new ArrayList<ValueData>());
+
+ conn.delete(data);
+ }
+ catch (IllegalPathException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (UnsupportedOperationException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (JCRInvalidItemStateException e)
+ {
+ // this is ok, since record is absent in ITEM table
+ }
+ catch (InvalidItemStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
+ }
+
+ protected String exctractId(ResultSet resultSet) throws SQLException
+ {
+ return resultSet.getString(DBConstants.COLUMN_VPROPERTY_ID).substring(multiDb ? 0 : containerName.length());
+ }
+}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-02-29 15:23:31 UTC (rev 5716)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-02-29 15:25:40 UTC (rev 5717)
@@ -141,9 +141,9 @@
protected String FIND_PROPERTIES_BY_PARENTID;
/**
- * FIND_LOWEST_PROPERTY_VERSIONS.
+ * FIND_MAX_PROPERTY_VERSIONS.
*/
- protected String FIND_LOWEST_PROPERTY_VERSIONS;
+ protected String FIND_MAX_PROPERTY_VERSIONS;
/**
* INSERT_NODE.
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2012-02-29 15:23:31 UTC (rev 5716)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2012-02-29 15:25:40 UTC (rev 5717)
@@ -167,7 +167,7 @@
protected PreparedStatement findPropertiesByParentId;
- protected PreparedStatement findLowestPropertyVersions;
+ protected PreparedStatement findMaxPropertyVersions;
protected PreparedStatement insertItem;
@@ -485,9 +485,9 @@
findPropertiesByParentId.close();
}
- if (findLowestPropertyVersions != null)
+ if (findMaxPropertyVersions != null)
{
- findLowestPropertyVersions.close();
+ findMaxPropertyVersions.close();
}
if (insertItem != null)
@@ -1006,6 +1006,44 @@
/**
* {@inheritDoc}
*/
+ public int getMaxPropertyVersion(PropertyData data) throws RepositoryException
+ {
+ checkIfOpened();
+ try
+ {
+ ResultSet count = findMaxPropertyVersion(data.getParentIdentifier(), data.getQPath().getName().getAsString(), data.getQPath().getIndex());
+ try
+ {
+ if (count.next())
+ {
+ return count.getInt(1);
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ finally
+ {
+ try
+ {
+ count.close();
+ }
+ catch (SQLException e)
+ {
+ LOG.error("Can't close the ResultSet: " + e);
+ }
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public int getChildNodesCount(NodeData parent) throws RepositoryException
{
checkIfOpened();
@@ -2699,16 +2737,6 @@
}
};
- protected ResultSet findLowestPropertyVersions() throws SQLException
- {
- if (findLowestPropertyVersions == null)
- {
- findLowestPropertyVersions = dbConnection.prepareStatement(FIND_LOWEST_PROPERTY_VERSIONS);
- }
-
- return findLowestPropertyVersions.executeQuery();
- }
-
protected abstract int addNodeRecord(NodeData data) throws SQLException;
protected abstract int addPropertyRecord(PropertyData prop) throws SQLException;
@@ -2773,4 +2801,6 @@
protected abstract ResultSet findValueByPropertyIdOrderNumber(String cid, int orderNumb) throws SQLException;
+ protected abstract ResultSet findMaxPropertyVersion(String parentId, String name, int index) throws SQLException;
+
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 15:23:31 UTC (rev 5716)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 15:25:40 UTC (rev 5717)
@@ -29,6 +29,8 @@
import org.exoplatform.services.jcr.impl.checker.InspectionQuery;
import org.exoplatform.services.jcr.impl.checker.InspectionQueryFilteredMultivaluedProperties;
import org.exoplatform.services.jcr.impl.checker.InspectionReport;
+import org.exoplatform.services.jcr.impl.checker.RemoverEarlierVersions;
+import org.exoplatform.services.jcr.impl.checker.RemoverValueRecords;
import org.exoplatform.services.jcr.impl.core.lock.LockTableHandler;
import org.exoplatform.services.jcr.impl.core.lock.LockTableHandlerFactory;
import org.exoplatform.services.jcr.impl.storage.value.ValueDataNotFoundException;
@@ -481,14 +483,14 @@
DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME}, "A node that doesn't have primary type property",
new DummyRepair()));
- itemsInspectionQuery
- .add(new InspectionQuery(jdbcDataContainer.multiDb
- ? "select * from JCR_MVALUE V where NOT EXISTS(select * from JCR_MITEM P "
- + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)"
- : "select * from JCR_SVALUE V where NOT EXISTS(select * from JCR_SITEM P "
- + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)", new String[]{DBConstants.COLUMN_ID,
- DBConstants.COLUMN_VPROPERTY_ID}, "All value records that has not related property record",
- new DummyRepair()));
+ itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select * from JCR_MVALUE V where NOT EXISTS(select * from JCR_MITEM P "
+ + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)"
+ : "select * from JCR_SVALUE V where NOT EXISTS(select * from JCR_SITEM P "
+ + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)", new String[]{DBConstants.COLUMN_ID,
+ DBConstants.COLUMN_VPROPERTY_ID}, "All value records that has not related property record",
+ new RemoverValueRecords(jdbcDataContainer.getConnectionFactory(), jdbcDataContainer.containerName,
+ jdbcDataContainer.multiDb)));
// The differences in the queries by DB dialect.
String statement;
@@ -540,7 +542,7 @@
+ " and I.VERSION != J.VERSION)",
new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME,
DBConstants.COLUMN_VERSION, DBConstants.COLUMN_CLASS, DBConstants.COLUMN_INDEX},
- "Several versions of same item.", new DummyRepair()));
+ "Several versions of same item.", new RemoverEarlierVersions(jdbcDataContainer.getConnectionFactory())));
itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
? "select * from JCR_MITEM P, JCR_MVALUE V where P.ID=V.PROPERTY_ID and P.P_TYPE=9 and NOT EXISTS "
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2012-02-29 15:23:31 UTC (rev 5716)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2012-02-29 15:25:40 UTC (rev 5717)
@@ -136,9 +136,8 @@
FIND_PROPERTIES_BY_PARENTID = "select * from JCR_MITEM" + " where I_CLASS=2 and PARENT_ID=?" + " order by ID";
- FIND_LOWEST_PROPERTY_VERSIONS =
- "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
- + " GROUP BY PARENT_ID, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+ FIND_MAX_PROPERTY_VERSIONS =
+ "select max(VERSION) FROM JCR_MITEM WHERE PARENT_ID=? and NAME=? and I_INDEX=? and I_CLASS=2";
INSERT_NODE =
"insert into JCR_MITEM(ID, PARENT_ID, NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,"
@@ -676,4 +675,20 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
+ protected ResultSet findMaxPropertyVersion(String parentId, String name, int index) throws SQLException
+ {
+ if (findMaxPropertyVersions == null)
+ {
+ findMaxPropertyVersions = dbConnection.prepareStatement(FIND_MAX_PROPERTY_VERSIONS);
+ }
+
+ findMaxPropertyVersions.setString(1, getInternalId(parentId));
+ findMaxPropertyVersions.setString(2, name);
+ findMaxPropertyVersions.setInt(3, index);
+
+ return findMaxPropertyVersions.executeQuery();
+ }
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2012-02-29 15:23:31 UTC (rev 5716)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2012-02-29 15:25:40 UTC (rev 5717)
@@ -145,9 +145,8 @@
FIND_PROPERTIES_BY_PARENTID =
"select * from JCR_SITEM" + " where I_CLASS=2 and CONTAINER_NAME=? and PARENT_ID=?" + " order by ID";
- FIND_LOWEST_PROPERTY_VERSIONS =
- "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, CONTAINER_NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
- + " GROUP BY PARENT_ID, CONTAINER_NAME, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+ FIND_MAX_PROPERTY_VERSIONS =
+ "select max(VERSION) FROM JCR_SITEM WHERE PARENT_ID=? and CONTAINER_NAME=? and NAME=? and I_INDEX=? and I_CLASS=2";
INSERT_NODE =
"insert into JCR_SITEM(ID, PARENT_ID, NAME, CONTAINER_NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,?,"
@@ -708,4 +707,22 @@
}
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ protected ResultSet findMaxPropertyVersion(String parentId, String name, int index) throws SQLException
+ {
+ if (findMaxPropertyVersions == null)
+ {
+ findMaxPropertyVersions = dbConnection.prepareStatement(FIND_MAX_PROPERTY_VERSIONS);
+ }
+
+ findMaxPropertyVersions.setString(1, getInternalId(parentId));
+ findMaxPropertyVersions.setString(2, containerName);
+ findMaxPropertyVersions.setString(3, name);
+ findMaxPropertyVersions.setInt(4, index);
+
+ return findMaxPropertyVersions.executeQuery();
+ }
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2012-02-29 15:23:31 UTC (rev 5716)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2012-02-29 15:25:40 UTC (rev 5717)
@@ -180,9 +180,8 @@
FIND_NODES_BY_PARENTID_AND_PATTERN_CQ_TEMPLATE =
"select I.*, P.NAME AS PROP_NAME, V.ORDER_NUM, V.DATA from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V";
- FIND_LOWEST_PROPERTY_VERSIONS =
- "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
- + " GROUP BY PARENT_ID, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+ FIND_MAX_PROPERTY_VERSIONS =
+ "select max(VERSION) FROM JCR_MITEM WHERE PARENT_ID=? and NAME=? and I_INDEX=? and I_CLASS=2";
INSERT_NODE =
"insert into JCR_MITEM(ID, PARENT_ID, NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,"
@@ -1157,4 +1156,21 @@
return findNodesCount.executeQuery();
}
+ /**
+ * {@inheritDoc}
+ */
+ protected ResultSet findMaxPropertyVersion(String parentId, String name, int index) throws SQLException
+ {
+ if (findMaxPropertyVersions == null)
+ {
+ findMaxPropertyVersions = dbConnection.prepareStatement(FIND_MAX_PROPERTY_VERSIONS);
+ }
+.......
+ findMaxPropertyVersions.setString(1, getInternalId(parentId));
+ findMaxPropertyVersions.setString(2, name);
+ findMaxPropertyVersions.setInt(3, index);
+.
+ return findMaxPropertyVersions.executeQuery();
+ }
+
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2012-02-29 15:23:31 UTC (rev 5716)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2012-02-29 15:25:40 UTC (rev 5717)
@@ -189,9 +189,8 @@
FIND_NODES_BY_PARENTID_AND_PATTERN_CQ_TEMPLATE =
"select I.*, P.NAME AS PROP_NAME, V.ORDER_NUM, V.DATA from JCR_SITEM I, JCR_SITEM P, JCR_SVALUE V";
- FIND_LOWEST_PROPERTY_VERSIONS =
- "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, CONTAINER_NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
- + " GROUP BY PARENT_ID, CONTAINER_NAME, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+ FIND_MAX_PROPERTY_VERSIONS =
+ "select max(VERSION) FROM JCR_SITEM WHERE PARENT_ID=? and CONTAINER_NAME=? and NAME=? and I_INDEX=? and I_CLASS=2";
INSERT_NODE =
"insert into JCR_SITEM(ID, PARENT_ID, NAME, CONTAINER_NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,?,"
@@ -1087,4 +1086,22 @@
}
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ protected ResultSet findMaxPropertyVersion(String parentId, String name, int index) throws SQLException
+ {
+ if (findMaxPropertyVersions == null)
+ {
+ findMaxPropertyVersions = dbConnection.prepareStatement(FIND_MAX_PROPERTY_VERSIONS);
+ }
+
+ findMaxPropertyVersions.setString(1, getInternalId(parentId));
+ findMaxPropertyVersions.setString(2, containerName);
+ findMaxPropertyVersions.setString(3, name);
+ findMaxPropertyVersions.setInt(4, index);
+
+ return findMaxPropertyVersions.executeQuery();
+ }
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java 2012-02-29 15:23:31 UTC (rev 5716)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java 2012-02-29 15:25:40 UTC (rev 5717)
@@ -656,10 +656,10 @@
conn.commit();
conn.close();
- // repository is inconsistent
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ checkController.repairDataBase("yes");
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
/**
@@ -818,9 +818,10 @@
conn.close();
// repository is inconsistent
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ checkController.repairDataBase("yes");
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
/**
12 years, 1 month
exo-jcr SVN: r5716 - in jcr/trunk/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/storage/jdbc and 3 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2012-02-29 10:23:31 -0500 (Wed, 29 Feb 2012)
New Revision: 5716
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverValueRecords.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java
Log:
EXOJCR-1762: auto-repair for DB inconsistency
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java 2012-02-29 13:34:12 UTC (rev 5715)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java 2012-02-29 15:23:31 UTC (rev 5716)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.jcr.impl.checker;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
@@ -73,30 +74,10 @@
rollback(conn);
throw e;
}
- finally
- {
- closeConnection(conn);
- }
}
abstract void repairInternally(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException;
- protected void closeConnection(WorkspaceStorageConnection conn)
- {
- try
- {
- conn.close();
- }
- catch (IllegalStateException e)
- {
- LOG.error("Can not close connection", e);
- }
- catch (RepositoryException e)
- {
- LOG.error("Can not close connection", e);
- }
- }
-
protected void rollback(WorkspaceStorageConnection conn)
{
try
@@ -116,4 +97,17 @@
}
}
+ protected String exctractId(ResultSet resultSet) throws SQLException
+ {
+ String containerName = "";
+ try
+ {
+ containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
+ }
+ catch (SQLException e)
+ {
+ }
+
+ return resultSet.getString(DBConstants.COLUMN_ID).substring(containerName.length());
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java 2012-02-29 13:34:12 UTC (rev 5715)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java 2012-02-29 15:23:31 UTC (rev 5716)
@@ -125,33 +125,4 @@
throw new SQLException(e);
}
}
-
- private String exctractId(ResultSet resultSet) throws SQLException
- {
- String containerName = "";
- try
- {
- containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
- }
- catch (SQLException e)
- {
- }
-
- return resultSet.getString(DBConstants.COLUMN_ID).substring(containerName.length());
- }
-
- private String concatId(ResultSet resultSet, String id) throws SQLException
- {
- String containerName = "";
- try
- {
- containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
- }
- catch (SQLException e)
- {
- }
-
- return containerName + id;
- }
-
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java 2012-02-29 13:34:12 UTC (rev 5715)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java 2012-02-29 15:23:31 UTC (rev 5716)
@@ -18,12 +18,16 @@
*/
package org.exoplatform.services.jcr.impl.checker;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
+import javax.jcr.RepositoryException;
+
/**
* @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
* @version $Id: RemoveEarlierVersions.java 34360 2009-07-22 23:58:59Z tolusha $
@@ -44,5 +48,23 @@
*/
protected void repairInternally(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
{
+ try
+ {
+ PropertyData data = (PropertyData)conn.getItemData(exctractId(resultSet));
+ int maxVersion = conn.getMaxPropertyVersion(data);
+
+ if (resultSet.getInt(DBConstants.COLUMN_VERSION) < maxVersion)
+ {
+ conn.delete(data);
+ }
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
}
}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverValueRecords.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverValueRecords.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverValueRecords.java 2012-02-29 15:23:31 UTC (rev 5716)
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import org.exoplatform.services.jcr.datamodel.IllegalPathException;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.datamodel.ValueData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
+import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: RemoverValueRecords.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class RemoverValueRecords extends AbstractInconsistencyRepair
+{
+
+ private final String containerName;
+
+ private final boolean multiDb;
+
+ public RemoverValueRecords(WorkspaceStorageConnectionFactory connFactory, String containerName, boolean multiDb)
+ {
+ super(connFactory);
+ this.containerName = containerName;
+ this.multiDb = multiDb;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ void repairInternally(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ try
+ {
+ String propertyId = exctractId(resultSet);
+ QPath path = QPath.parse("[]");
+
+ PropertyData data = new TransientPropertyData(path, propertyId, 0, 0, null, false, new ArrayList<ValueData>());
+
+ conn.delete(data);
+ }
+ catch (IllegalPathException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (UnsupportedOperationException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (JCRInvalidItemStateException e)
+ {
+ // this is ok, since record is absent in ITEM table
+ }
+ catch (InvalidItemStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
+ }
+
+ protected String exctractId(ResultSet resultSet) throws SQLException
+ {
+ return resultSet.getString(DBConstants.COLUMN_VPROPERTY_ID).substring(multiDb ? 0 : containerName.length());
+ }
+}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-02-29 13:34:12 UTC (rev 5715)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-02-29 15:23:31 UTC (rev 5716)
@@ -145,9 +145,9 @@
protected String FIND_PROPERTIES_BY_PARENTID;
/**
- * FIND_LOWEST_PROPERTY_VERSIONS.
+ * FIND_MAX_PROPERTY_VERSIONS.
*/
- protected String FIND_LOWEST_PROPERTY_VERSIONS;
+ protected String FIND_MAX_PROPERTY_VERSIONS;
/**
* INSERT_NODE.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2012-02-29 13:34:12 UTC (rev 5715)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2012-02-29 15:23:31 UTC (rev 5716)
@@ -167,7 +167,7 @@
protected PreparedStatement findPropertiesByParentId;
- protected PreparedStatement findLowestPropertyVersions;
+ protected PreparedStatement findMaxPropertyVersions;
protected PreparedStatement insertItem;
@@ -483,9 +483,9 @@
findPropertiesByParentId.close();
}
- if (findLowestPropertyVersions != null)
+ if (findMaxPropertyVersions != null)
{
- findLowestPropertyVersions.close();
+ findMaxPropertyVersions.close();
}
if (insertItem != null)
@@ -999,6 +999,44 @@
/**
* {@inheritDoc}
*/
+ public int getMaxPropertyVersion(PropertyData data) throws RepositoryException
+ {
+ checkIfOpened();
+ try
+ {
+ ResultSet count = findMaxPropertyVersion(data.getParentIdentifier(), data.getQPath().getName().getAsString(), data.getQPath().getIndex());
+ try
+ {
+ if (count.next())
+ {
+ return count.getInt(1);
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ finally
+ {
+ try
+ {
+ count.close();
+ }
+ catch (SQLException e)
+ {
+ LOG.error("Can't close the ResultSet: " + e);
+ }
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public int getChildNodesCount(NodeData parent) throws RepositoryException
{
checkIfOpened();
@@ -2673,16 +2711,6 @@
}
};
- protected ResultSet findLowestPropertyVersions() throws SQLException
- {
- if (findLowestPropertyVersions == null)
- {
- findLowestPropertyVersions = dbConnection.prepareStatement(FIND_LOWEST_PROPERTY_VERSIONS);
- }
-
- return findLowestPropertyVersions.executeQuery();
- }
-
protected abstract int addNodeRecord(NodeData data) throws SQLException;
protected abstract int addPropertyRecord(PropertyData prop) throws SQLException;
@@ -2745,4 +2773,6 @@
protected abstract ResultSet findValueByPropertyIdOrderNumber(String cid, int orderNumb) throws SQLException;
+ protected abstract ResultSet findMaxPropertyVersion(String parentId, String name, int index) throws SQLException;
+
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 13:34:12 UTC (rev 5715)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 15:23:31 UTC (rev 5716)
@@ -28,6 +28,8 @@
import org.exoplatform.services.jcr.impl.checker.InspectionQuery;
import org.exoplatform.services.jcr.impl.checker.InspectionQueryFilteredMultivaluedProperties;
import org.exoplatform.services.jcr.impl.checker.InspectionReport;
+import org.exoplatform.services.jcr.impl.checker.RemoverEarlierVersions;
+import org.exoplatform.services.jcr.impl.checker.RemoverValueRecords;
import org.exoplatform.services.jcr.impl.core.lock.LockTableHandler;
import org.exoplatform.services.jcr.impl.core.lock.LockTableHandlerFactory;
import org.exoplatform.services.jcr.impl.storage.value.ValueDataNotFoundException;
@@ -491,14 +493,14 @@
DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME}, "A node that doesn't have primary type property",
new DummyRepair()));
- itemsInspectionQuery
- .add(new InspectionQuery(jdbcDataContainer.multiDb
- ? "select * from JCR_MVALUE V where NOT EXISTS(select * from JCR_MITEM P "
- + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)"
- : "select * from JCR_SVALUE V where NOT EXISTS(select * from JCR_SITEM P "
- + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)", new String[]{DBConstants.COLUMN_ID,
- DBConstants.COLUMN_VPROPERTY_ID}, "All value records that has not related property record",
- new DummyRepair()));
+ itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select * from JCR_MVALUE V where NOT EXISTS(select * from JCR_MITEM P "
+ + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)"
+ : "select * from JCR_SVALUE V where NOT EXISTS(select * from JCR_SITEM P "
+ + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)", new String[]{DBConstants.COLUMN_ID,
+ DBConstants.COLUMN_VPROPERTY_ID}, "All value records that has not related property record",
+ new RemoverValueRecords(jdbcDataContainer.getConnectionFactory(), jdbcDataContainer.containerName,
+ jdbcDataContainer.multiDb)));
// The differences in the queries by DB dialect.
String statement;
@@ -550,7 +552,7 @@
+ " and I.VERSION != J.VERSION)",
new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME,
DBConstants.COLUMN_VERSION, DBConstants.COLUMN_CLASS, DBConstants.COLUMN_INDEX},
- "Several versions of same item.", new DummyRepair()));
+ "Several versions of same item.", new RemoverEarlierVersions(jdbcDataContainer.getConnectionFactory())));
itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
? "select * from JCR_MITEM P, JCR_MVALUE V where P.ID=V.PROPERTY_ID and P.P_TYPE=9 and NOT EXISTS "
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2012-02-29 13:34:12 UTC (rev 5715)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2012-02-29 15:23:31 UTC (rev 5716)
@@ -137,9 +137,8 @@
FIND_PROPERTIES_BY_PARENTID = "select * from JCR_MITEM" + " where I_CLASS=2 and PARENT_ID=?" + " order by ID";
- FIND_LOWEST_PROPERTY_VERSIONS =
- "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
- + " GROUP BY PARENT_ID, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+ FIND_MAX_PROPERTY_VERSIONS =
+ "select max(VERSION) FROM JCR_MITEM WHERE PARENT_ID=? and NAME=? and I_INDEX=? and I_CLASS=2";
INSERT_NODE =
"insert into JCR_MITEM(ID, PARENT_ID, NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,"
@@ -662,4 +661,20 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
+ protected ResultSet findMaxPropertyVersion(String parentId, String name, int index) throws SQLException
+ {
+ if (findMaxPropertyVersions == null)
+ {
+ findMaxPropertyVersions = dbConnection.prepareStatement(FIND_MAX_PROPERTY_VERSIONS);
+ }
+
+ findMaxPropertyVersions.setString(1, getInternalId(parentId));
+ findMaxPropertyVersions.setString(2, name);
+ findMaxPropertyVersions.setInt(3, index);
+
+ return findMaxPropertyVersions.executeQuery();
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2012-02-29 13:34:12 UTC (rev 5715)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2012-02-29 15:23:31 UTC (rev 5716)
@@ -146,9 +146,8 @@
FIND_PROPERTIES_BY_PARENTID =
"select * from JCR_SITEM" + " where I_CLASS=2 and CONTAINER_NAME=? and PARENT_ID=?" + " order by ID";
- FIND_LOWEST_PROPERTY_VERSIONS =
- "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, CONTAINER_NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
- + " GROUP BY PARENT_ID, CONTAINER_NAME, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+ FIND_MAX_PROPERTY_VERSIONS =
+ "select max(VERSION) FROM JCR_SITEM WHERE PARENT_ID=? and CONTAINER_NAME=? and NAME=? and I_INDEX=? and I_CLASS=2";
INSERT_NODE =
"insert into JCR_SITEM(ID, PARENT_ID, NAME, CONTAINER_NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,?,"
@@ -687,4 +686,22 @@
}
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ protected ResultSet findMaxPropertyVersion(String parentId, String name, int index) throws SQLException
+ {
+ if (findMaxPropertyVersions == null)
+ {
+ findMaxPropertyVersions = dbConnection.prepareStatement(FIND_MAX_PROPERTY_VERSIONS);
+ }
+
+ findMaxPropertyVersions.setString(1, getInternalId(parentId));
+ findMaxPropertyVersions.setString(2, containerName);
+ findMaxPropertyVersions.setString(3, name);
+ findMaxPropertyVersions.setInt(4, index);
+
+ return findMaxPropertyVersions.executeQuery();
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2012-02-29 13:34:12 UTC (rev 5715)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2012-02-29 15:23:31 UTC (rev 5716)
@@ -181,9 +181,8 @@
FIND_NODES_BY_PARENTID_AND_PATTERN_CQ_TEMPLATE =
"select I.*, P.NAME AS PROP_NAME, V.ORDER_NUM, V.DATA from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V";
- FIND_LOWEST_PROPERTY_VERSIONS =
- "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
- + " GROUP BY PARENT_ID, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+ FIND_MAX_PROPERTY_VERSIONS =
+ "select max(VERSION) FROM JCR_MITEM WHERE PARENT_ID=? and NAME=? and I_INDEX=? and I_CLASS=2";
INSERT_NODE =
"insert into JCR_MITEM(ID, PARENT_ID, NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,"
@@ -1142,4 +1141,21 @@
}
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ protected ResultSet findMaxPropertyVersion(String parentId, String name, int index) throws SQLException
+ {
+ if (findMaxPropertyVersions == null)
+ {
+ findMaxPropertyVersions = dbConnection.prepareStatement(FIND_MAX_PROPERTY_VERSIONS);
+ }
+
+ findMaxPropertyVersions.setString(1, getInternalId(parentId));
+ findMaxPropertyVersions.setString(2, name);
+ findMaxPropertyVersions.setInt(3, index);
+
+ return findMaxPropertyVersions.executeQuery();
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2012-02-29 13:34:12 UTC (rev 5715)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2012-02-29 15:23:31 UTC (rev 5716)
@@ -190,9 +190,8 @@
FIND_NODES_BY_PARENTID_AND_PATTERN_CQ_TEMPLATE =
"select I.*, P.NAME AS PROP_NAME, V.ORDER_NUM, V.DATA from JCR_SITEM I, JCR_SITEM P, JCR_SVALUE V";
- FIND_LOWEST_PROPERTY_VERSIONS =
- "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, CONTAINER_NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
- + " GROUP BY PARENT_ID, CONTAINER_NAME, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+ FIND_MAX_PROPERTY_VERSIONS =
+ "select max(VERSION) FROM JCR_SITEM WHERE PARENT_ID=? and CONTAINER_NAME=? and NAME=? and I_INDEX=? and I_CLASS=2";
INSERT_NODE =
"insert into JCR_SITEM(ID, PARENT_ID, NAME, CONTAINER_NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,?,"
@@ -1066,4 +1065,22 @@
}
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ protected ResultSet findMaxPropertyVersion(String parentId, String name, int index) throws SQLException
+ {
+ if (findMaxPropertyVersions == null)
+ {
+ findMaxPropertyVersions = dbConnection.prepareStatement(FIND_MAX_PROPERTY_VERSIONS);
+ }
+
+ findMaxPropertyVersions.setString(1, getInternalId(parentId));
+ findMaxPropertyVersions.setString(2, containerName);
+ findMaxPropertyVersions.setString(3, name);
+ findMaxPropertyVersions.setInt(4, index);
+
+ return findMaxPropertyVersions.executeQuery();
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java 2012-02-29 13:34:12 UTC (rev 5715)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java 2012-02-29 15:23:31 UTC (rev 5716)
@@ -655,10 +655,10 @@
conn.commit();
conn.close();
- // repository is inconsistent
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ checkController.repairDataBase("yes");
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
/**
@@ -817,9 +817,10 @@
conn.close();
// repository is inconsistent
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ checkController.repairDataBase("yes");
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
/**
12 years, 1 month
exo-jcr SVN: r5715 - jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker.
by do-not-reply@jboss.org
Author: tolusha
Date: 2012-02-29 08:34:12 -0500 (Wed, 29 Feb 2012)
New Revision: 5715
Added:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java
Log:
EXOJCR-1762: auto-repair for DB inconsistency
Added: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java 2012-02-29 13:34:12 UTC (rev 5715)
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
+import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
+import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import javax.jcr.RepositoryException;
+
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: AbstractInconsistencyRepair.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public abstract class AbstractInconsistencyRepair implements InconsistencyRepair
+{
+ protected static final Log LOG = ExoLogger.getLogger("exo.jcr.component.core.AbstractInconsistencyRepair");
+
+ protected final WorkspaceStorageConnectionFactory connFactory;
+
+ AbstractInconsistencyRepair(WorkspaceStorageConnectionFactory connFactory)
+ {
+ this.connFactory = connFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void doRepair(ResultSet resultSet) throws SQLException
+ {
+ WorkspaceStorageConnection conn = null;
+ try
+ {
+ conn = connFactory.openConnection();
+ if (!(conn instanceof JDBCStorageConnection))
+ {
+ throw new SQLException("Connection is instance of " + conn);
+ }
+
+ repairInternally((JDBCStorageConnection)conn, resultSet);
+
+ conn.commit();
+ }
+ catch (RepositoryException e)
+ {
+ rollback(conn);
+ throw new SQLException(e);
+ }
+ catch (SQLException e)
+ {
+ rollback(conn);
+ throw e;
+ }
+ finally
+ {
+ closeConnection(conn);
+ }
+ }
+
+ abstract void repairInternally(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException;
+
+ protected void closeConnection(WorkspaceStorageConnection conn)
+ {
+ try
+ {
+ conn.close();
+ }
+ catch (IllegalStateException e)
+ {
+ LOG.error("Can not close connection", e);
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error("Can not close connection", e);
+ }
+ }
+
+ protected void rollback(WorkspaceStorageConnection conn)
+ {
+ try
+ {
+ if (conn != null)
+ {
+ conn.rollback();
+ }
+ }
+ catch (IllegalStateException e)
+ {
+ LOG.error("Can not rollback connection", e);
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error("Can not rollback connection", e);
+ }
+ }
+
+}
Added: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java 2012-02-29 13:34:12 UTC (rev 5715)
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import org.exoplatform.services.jcr.datamodel.IllegalNameException;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
+import org.exoplatform.services.jcr.datamodel.ValueData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
+import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: AssignRootAsParentRepair.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class AssignerRootAsParent extends AbstractInconsistencyRepair
+{
+
+ public AssignerRootAsParent(WorkspaceStorageConnectionFactory connFactory)
+ {
+ super(connFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void repairInternally(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ if (resultSet.getInt(DBConstants.COLUMN_CLASS) == 1)
+ {
+ repairNode(conn, resultSet);
+ }
+ else
+ {
+ repairProperty(conn, resultSet);
+ }
+ }
+
+ private void repairProperty(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ try
+ {
+ String propertyId = exctractId(resultSet);
+ QPath path = QPath.parse(resultSet.getString(DBConstants.COLUMN_NAME));
+
+ PropertyData data = new TransientPropertyData(path, propertyId, 0, 0, null, false, new ArrayList<ValueData>());
+
+ conn.delete(data);
+ }
+ catch (UnsupportedOperationException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (InvalidItemStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
+ }
+
+ private void repairNode(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ try
+ {
+ String nodeId = exctractId(resultSet);
+ int orderNum = resultSet.getInt(DBConstants.COLUMN_NORDERNUM);
+ int version = resultSet.getInt(DBConstants.COLUMN_VERSION);
+ QPath path =
+ new QPath(new QPathEntry[]{new QPathEntry(
+ InternalQName.parse(resultSet.getString(DBConstants.COLUMN_NAME)),
+ resultSet.getInt(DBConstants.COLUMN_INDEX))});
+
+ NodeData data =
+ new TransientNodeData(path, nodeId, version, null, null, orderNum, Constants.ROOT_UUID, null);
+
+ conn.rename(data);
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (IllegalNameException e)
+ {
+ throw new SQLException(e);
+ }
+ }
+
+ private String exctractId(ResultSet resultSet) throws SQLException
+ {
+ String containerName = "";
+ try
+ {
+ containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
+ }
+ catch (SQLException e)
+ {
+ }
+
+ return resultSet.getString(DBConstants.COLUMN_ID).substring(containerName.length());
+ }
+
+ private String concatId(ResultSet resultSet, String id) throws SQLException
+ {
+ String containerName = "";
+ try
+ {
+ containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
+ }
+ catch (SQLException e)
+ {
+ }
+
+ return containerName + id;
+ }
+
+}
Added: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java 2012-02-29 13:34:12 UTC (rev 5715)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
+import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: RemoveEarlierVersions.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class RemoverEarlierVersions extends AbstractInconsistencyRepair
+{
+
+ /**
+ * RemoveEarlierVersions constructor.
+ */
+ public RemoverEarlierVersions(WorkspaceStorageConnectionFactory connFactory)
+ {
+ super(connFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void repairInternally(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ }
+}
12 years, 1 month
exo-jcr SVN: r5714 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: storage/jdbc and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2012-02-29 08:32:36 -0500 (Wed, 29 Feb 2012)
New Revision: 5714
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java
Removed:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignRootAsParentRepair.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
Log:
EXOJCR-1762: auto-repair for DB inconsistency
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java 2012-02-29 13:32:36 UTC (rev 5714)
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
+import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
+import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import javax.jcr.RepositoryException;
+
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: AbstractInconsistencyRepair.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public abstract class AbstractInconsistencyRepair implements InconsistencyRepair
+{
+ protected static final Log LOG = ExoLogger.getLogger("exo.jcr.component.core.AbstractInconsistencyRepair");
+
+ protected final WorkspaceStorageConnectionFactory connFactory;
+
+ AbstractInconsistencyRepair(WorkspaceStorageConnectionFactory connFactory)
+ {
+ this.connFactory = connFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void doRepair(ResultSet resultSet) throws SQLException
+ {
+ WorkspaceStorageConnection conn = null;
+ try
+ {
+ conn = connFactory.openConnection();
+ if (!(conn instanceof JDBCStorageConnection))
+ {
+ throw new SQLException("Connection is instance of " + conn);
+ }
+
+ repairInternally((JDBCStorageConnection)conn, resultSet);
+
+ conn.commit();
+ }
+ catch (RepositoryException e)
+ {
+ rollback(conn);
+ throw new SQLException(e);
+ }
+ catch (SQLException e)
+ {
+ rollback(conn);
+ throw e;
+ }
+ finally
+ {
+ closeConnection(conn);
+ }
+ }
+
+ abstract void repairInternally(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException;
+
+ protected void closeConnection(WorkspaceStorageConnection conn)
+ {
+ try
+ {
+ conn.close();
+ }
+ catch (IllegalStateException e)
+ {
+ LOG.error("Can not close connection", e);
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error("Can not close connection", e);
+ }
+ }
+
+ protected void rollback(WorkspaceStorageConnection conn)
+ {
+ try
+ {
+ if (conn != null)
+ {
+ conn.rollback();
+ }
+ }
+ catch (IllegalStateException e)
+ {
+ LOG.error("Can not rollback connection", e);
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error("Can not rollback connection", e);
+ }
+ }
+
+}
Deleted: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignRootAsParentRepair.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignRootAsParentRepair.java 2012-02-29 12:52:01 UTC (rev 5713)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignRootAsParentRepair.java 2012-02-29 13:32:36 UTC (rev 5714)
@@ -1,220 +0,0 @@
-/*
- * Copyright (C) 2012 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.impl.checker;
-
-import org.exoplatform.services.jcr.datamodel.IllegalNameException;
-import org.exoplatform.services.jcr.datamodel.InternalQName;
-import org.exoplatform.services.jcr.datamodel.NodeData;
-import org.exoplatform.services.jcr.datamodel.PropertyData;
-import org.exoplatform.services.jcr.datamodel.QPath;
-import org.exoplatform.services.jcr.datamodel.QPathEntry;
-import org.exoplatform.services.jcr.datamodel.ValueData;
-import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
-import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
-import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
-import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
-import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.RepositoryException;
-
-/**
- * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
- * @version $Id: AssignRootAsParentRepair.java 34360 2009-07-22 23:58:59Z tolusha $
- */
-public class AssignRootAsParentRepair implements InconsistencyRepair
-{
-
- protected static final Log LOG = ExoLogger.getLogger("exo.jcr.component.core.AssignRootAsParentRepair");
-
- protected final WorkspaceStorageConnectionFactory connFactory;
-
- public AssignRootAsParentRepair(WorkspaceStorageConnectionFactory connFactory)
- {
- this.connFactory = connFactory;
- }
-
- /**
- * {@inheritDoc}
- */
- public void doRepair(ResultSet resultSet) throws SQLException
- {
- WorkspaceStorageConnection conn = null;
- try
- {
- conn = connFactory.openConnection();
- if (!(conn instanceof JDBCStorageConnection))
- {
- throw new SQLException("Connection is instance of " + conn);
- }
-
- if (resultSet.getInt(DBConstants.COLUMN_CLASS) == 1)
- {
- repairNode((JDBCStorageConnection)conn, resultSet);
- }
- else
- {
- repairProperty((JDBCStorageConnection)conn, resultSet);
- }
-
- conn.commit();
- }
- catch (RepositoryException e)
- {
- rollback(conn);
- throw new SQLException(e);
- }
- finally
- {
- closeConnection(conn);
- }
- }
-
- private void repairProperty(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
- {
- try
- {
- String propertyId = exctractId(resultSet);
- QPath path = QPath.parse(resultSet.getString(DBConstants.COLUMN_NAME));
-
- PropertyData data = new TransientPropertyData(path, propertyId, 0, 0, null, false, new ArrayList<ValueData>());
-
- conn.delete(data);
- }
- catch (UnsupportedOperationException e)
- {
- throw new SQLException(e);
- }
- catch (InvalidItemStateException e)
- {
- throw new SQLException(e);
- }
- catch (IllegalStateException e)
- {
- throw new SQLException(e);
- }
- catch (RepositoryException e)
- {
- throw new SQLException(e);
- }
- }
-
- private void repairNode(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
- {
- try
- {
- String nodeId = exctractId(resultSet);
- int orderNum = resultSet.getInt(DBConstants.COLUMN_NORDERNUM);
- int version = resultSet.getInt(DBConstants.COLUMN_VERSION);
- QPath path =
- new QPath(new QPathEntry[]{new QPathEntry(
- InternalQName.parse(resultSet.getString(DBConstants.COLUMN_NAME)),
- resultSet.getInt(DBConstants.COLUMN_INDEX))});
-
- NodeData data =
- new TransientNodeData(path, nodeId, version, null, null, orderNum, Constants.ROOT_UUID, null);
-
- conn.rename(data);
- }
- catch (IllegalStateException e)
- {
- throw new SQLException(e);
- }
- catch (RepositoryException e)
- {
- throw new SQLException(e);
- }
- catch (IllegalNameException e)
- {
- throw new SQLException(e);
- }
- }
-
- private void closeConnection(WorkspaceStorageConnection conn) throws SQLException
- {
- try
- {
- conn.close();
- }
- catch (IllegalStateException e)
- {
- throw new SQLException(e);
- }
- catch (RepositoryException e)
- {
- throw new SQLException(e);
- }
- }
-
- private void rollback(WorkspaceStorageConnection conn)
- {
- try
- {
- if (conn != null)
- {
- conn.rollback();
- }
- }
- catch (IllegalStateException e)
- {
- LOG.error("Can not rollback", e);
- }
- catch (RepositoryException e)
- {
- LOG.error("Can not rollback", e);
- }
- }
-
- private String exctractId(ResultSet resultSet) throws SQLException
- {
- String containerName = "";
- try
- {
- containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
- }
- catch (SQLException e)
- {
- }
-
- return resultSet.getString(DBConstants.COLUMN_ID).substring(containerName.length());
- }
-
- private String concatId(ResultSet resultSet, String id) throws SQLException
- {
- String containerName = "";
- try
- {
- containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
- }
- catch (SQLException e)
- {
- }
-
- return containerName + id;
- }
-
-}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java 2012-02-29 13:32:36 UTC (rev 5714)
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import org.exoplatform.services.jcr.datamodel.IllegalNameException;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
+import org.exoplatform.services.jcr.datamodel.ValueData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
+import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: AssignRootAsParentRepair.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class AssignerRootAsParent extends AbstractInconsistencyRepair
+{
+
+ public AssignerRootAsParent(WorkspaceStorageConnectionFactory connFactory)
+ {
+ super(connFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void repairInternally(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ if (resultSet.getInt(DBConstants.COLUMN_CLASS) == 1)
+ {
+ repairNode(conn, resultSet);
+ }
+ else
+ {
+ repairProperty(conn, resultSet);
+ }
+ }
+
+ private void repairProperty(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ try
+ {
+ String propertyId = exctractId(resultSet);
+ QPath path = QPath.parse(resultSet.getString(DBConstants.COLUMN_NAME));
+
+ PropertyData data = new TransientPropertyData(path, propertyId, 0, 0, null, false, new ArrayList<ValueData>());
+
+ conn.delete(data);
+ }
+ catch (UnsupportedOperationException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (InvalidItemStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
+ }
+
+ private void repairNode(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ try
+ {
+ String nodeId = exctractId(resultSet);
+ int orderNum = resultSet.getInt(DBConstants.COLUMN_NORDERNUM);
+ int version = resultSet.getInt(DBConstants.COLUMN_VERSION);
+ QPath path =
+ new QPath(new QPathEntry[]{new QPathEntry(
+ InternalQName.parse(resultSet.getString(DBConstants.COLUMN_NAME)),
+ resultSet.getInt(DBConstants.COLUMN_INDEX))});
+
+ NodeData data =
+ new TransientNodeData(path, nodeId, version, null, null, orderNum, Constants.ROOT_UUID, null);
+
+ conn.rename(data);
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (IllegalNameException e)
+ {
+ throw new SQLException(e);
+ }
+ }
+
+ private String exctractId(ResultSet resultSet) throws SQLException
+ {
+ String containerName = "";
+ try
+ {
+ containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
+ }
+ catch (SQLException e)
+ {
+ }
+
+ return resultSet.getString(DBConstants.COLUMN_ID).substring(containerName.length());
+ }
+
+ private String concatId(ResultSet resultSet, String id) throws SQLException
+ {
+ String containerName = "";
+ try
+ {
+ containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
+ }
+ catch (SQLException e)
+ {
+ }
+
+ return containerName + id;
+ }
+
+}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java 2012-02-29 13:32:36 UTC (rev 5714)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
+import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: RemoveEarlierVersions.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class RemoverEarlierVersions extends AbstractInconsistencyRepair
+{
+
+ /**
+ * RemoveEarlierVersions constructor.
+ */
+ public RemoverEarlierVersions(WorkspaceStorageConnectionFactory connFactory)
+ {
+ super(connFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void repairInternally(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ }
+}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 12:52:01 UTC (rev 5713)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 13:32:36 UTC (rev 5714)
@@ -224,8 +224,19 @@
logBrokenObjectAndSetInconsistency(getBrokenObject(resultSet, query.getFieldNames()));
if (autoRepair)
{
- query.getRepair().doRepair(resultSet);
- logComment("Inconsistency has been fixed");
+ try
+ {
+ query.getRepair().doRepair(resultSet);
+ logComment("Inconsistency has been fixed");
+ }
+ catch (SQLException e)
+ {
+ if (LOG.isTraceEnabled())
+ {
+ LOG.trace(e.getMessage(), e);
+ }
+ }
+
}
}
while (resultSet.next());
12 years, 1 month
exo-jcr SVN: r5713 - in jcr/branches/1.15.x: exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db and 2 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2012-02-29 07:52:01 -0500 (Wed, 29 Feb 2012)
New Revision: 5713
Modified:
jcr/branches/1.15.x/exo.jcr.component.core.impl.infinispan.v5/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNLockTableHandler.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
Log:
EXOJCR-1762: repair db
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-02-29 12:50:41 UTC (rev 5712)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-02-29 12:52:01 UTC (rev 5713)
@@ -141,6 +141,11 @@
protected String FIND_PROPERTIES_BY_PARENTID;
/**
+ * FIND_LOWEST_PROPERTY_VERSIONS.
+ */
+ protected String FIND_LOWEST_PROPERTY_VERSIONS;
+
+ /**
* INSERT_NODE.
*/
protected String INSERT_NODE;
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2012-02-29 12:50:41 UTC (rev 5712)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2012-02-29 12:52:01 UTC (rev 5713)
@@ -167,6 +167,8 @@
protected PreparedStatement findPropertiesByParentId;
+ protected PreparedStatement findLowestPropertyVersions;
+
protected PreparedStatement insertItem;
protected PreparedStatement insertNode;
@@ -483,6 +485,11 @@
findPropertiesByParentId.close();
}
+ if (findLowestPropertyVersions != null)
+ {
+ findLowestPropertyVersions.close();
+ }
+
if (insertItem != null)
{
insertItem.close();
@@ -2692,6 +2699,16 @@
}
};
+ protected ResultSet findLowestPropertyVersions() throws SQLException
+ {
+ if (findLowestPropertyVersions == null)
+ {
+ findLowestPropertyVersions = dbConnection.prepareStatement(FIND_LOWEST_PROPERTY_VERSIONS);
+ }
+
+ return findLowestPropertyVersions.executeQuery();
+ }
+
protected abstract int addNodeRecord(NodeData data) throws SQLException;
protected abstract int addPropertyRecord(PropertyData prop) throws SQLException;
@@ -2755,4 +2772,5 @@
protected abstract ResultSet findValuesStorageDescriptorsByPropertyId(String cid) throws SQLException;
protected abstract ResultSet findValueByPropertyIdOrderNumber(String cid, int orderNumb) throws SQLException;
+
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 12:50:41 UTC (rev 5712)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 12:52:01 UTC (rev 5713)
@@ -24,7 +24,7 @@
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.checker.AssignRootAsParentRepair;
+import org.exoplatform.services.jcr.impl.checker.AssignerRootAsParent;
import org.exoplatform.services.jcr.impl.checker.DummyRepair;
import org.exoplatform.services.jcr.impl.checker.InspectionQuery;
import org.exoplatform.services.jcr.impl.checker.InspectionQueryFilteredMultivaluedProperties;
@@ -457,7 +457,7 @@
: "select * from JCR_SITEM I where I.CONTAINER_NAME='" + jdbcDataContainer.containerName
+ "' and NOT EXISTS(select * from JCR_SITEM P where P.ID = I.PARENT_ID)", new String[]{
DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME, DBConstants.COLUMN_CLASS},
- "Items that do not have parent nodes", new AssignRootAsParentRepair(jdbcDataContainer
+ "Items that do not have parent nodes", new AssignerRootAsParent(jdbcDataContainer
.getConnectionFactory())));
itemsInspectionQuery
@@ -525,7 +525,7 @@
: "select * from JCR_SITEM I where I.ID = I.PARENT_ID and I.CONTAINER_NAME='"
+ jdbcDataContainer.containerName + "' and I.NAME <> '" + Constants.ROOT_PARENT_NAME + "'", new String[]{
DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME}, "An item is its own parent.",
- new AssignRootAsParentRepair(jdbcDataContainer.getConnectionFactory())));
+ new AssignerRootAsParent(jdbcDataContainer.getConnectionFactory())));
itemsInspectionQuery
.add(new InspectionQuery(
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2012-02-29 12:50:41 UTC (rev 5712)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2012-02-29 12:52:01 UTC (rev 5713)
@@ -136,6 +136,10 @@
FIND_PROPERTIES_BY_PARENTID = "select * from JCR_MITEM" + " where I_CLASS=2 and PARENT_ID=?" + " order by ID";
+ FIND_LOWEST_PROPERTY_VERSIONS =
+ "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
+ + " GROUP BY PARENT_ID, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+
INSERT_NODE =
"insert into JCR_MITEM(ID, PARENT_ID, NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,"
+ I_CLASS_NODE + ",?,?)";
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2012-02-29 12:50:41 UTC (rev 5712)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2012-02-29 12:52:01 UTC (rev 5713)
@@ -145,6 +145,10 @@
FIND_PROPERTIES_BY_PARENTID =
"select * from JCR_SITEM" + " where I_CLASS=2 and CONTAINER_NAME=? and PARENT_ID=?" + " order by ID";
+ FIND_LOWEST_PROPERTY_VERSIONS =
+ "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, CONTAINER_NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
+ + " GROUP BY PARENT_ID, CONTAINER_NAME, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+
INSERT_NODE =
"insert into JCR_SITEM(ID, PARENT_ID, NAME, CONTAINER_NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,?,"
+ I_CLASS_NODE + ",?,?)";
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2012-02-29 12:50:41 UTC (rev 5712)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2012-02-29 12:52:01 UTC (rev 5713)
@@ -180,6 +180,10 @@
FIND_NODES_BY_PARENTID_AND_PATTERN_CQ_TEMPLATE =
"select I.*, P.NAME AS PROP_NAME, V.ORDER_NUM, V.DATA from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V";
+ FIND_LOWEST_PROPERTY_VERSIONS =
+ "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
+ + " GROUP BY PARENT_ID, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+
INSERT_NODE =
"insert into JCR_MITEM(ID, PARENT_ID, NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,"
+ I_CLASS_NODE + ",?,?)";
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2012-02-29 12:50:41 UTC (rev 5712)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2012-02-29 12:52:01 UTC (rev 5713)
@@ -189,6 +189,10 @@
FIND_NODES_BY_PARENTID_AND_PATTERN_CQ_TEMPLATE =
"select I.*, P.NAME AS PROP_NAME, V.ORDER_NUM, V.DATA from JCR_SITEM I, JCR_SITEM P, JCR_SVALUE V";
+ FIND_LOWEST_PROPERTY_VERSIONS =
+ "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, CONTAINER_NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
+ + " GROUP BY PARENT_ID, CONTAINER_NAME, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+
INSERT_NODE =
"insert into JCR_SITEM(ID, PARENT_ID, NAME, CONTAINER_NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,?,"
+ I_CLASS_NODE + ",?,?)";
Modified: jcr/branches/1.15.x/exo.jcr.component.core.impl.infinispan.v5/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNLockTableHandler.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core.impl.infinispan.v5/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNLockTableHandler.java 2012-02-29 12:50:41 UTC (rev 5712)
+++ jcr/branches/1.15.x/exo.jcr.component.core.impl.infinispan.v5/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNLockTableHandler.java 2012-02-29 12:52:01 UTC (rev 5713)
@@ -20,6 +20,7 @@
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.checker.DummyRepair;
import org.exoplatform.services.jcr.impl.checker.InspectionQuery;
import org.exoplatform.services.jcr.impl.core.lock.AbstractLockTableHandler;
import org.exoplatform.services.log.ExoLogger;
@@ -54,7 +55,8 @@
*/
protected InspectionQuery getSelectQuery() throws SQLException
{
- return new InspectionQuery("SELECT * FROM " + getTableName(), new String[]{getIdColumn()}, "Locks table match");
+ return new InspectionQuery("SELECT * FROM " + getTableName(), new String[]{getIdColumn()}, "Locks table match",
+ new DummyRepair());
}
/**
@@ -63,7 +65,7 @@
public InspectionQuery getDeleteQuery(String nodeId) throws SQLException
{
return new InspectionQuery("DELETE FROM " + getTableName() + " WHERE " + getIdColumn() + "='" + nodeId + "'",
- new String[]{}, "");
+ new String[]{}, "", new DummyRepair());
}
/**
12 years, 1 month
exo-jcr SVN: r5712 - in jcr/trunk: exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db and 2 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2012-02-29 07:50:41 -0500 (Wed, 29 Feb 2012)
New Revision: 5712
Modified:
jcr/trunk/exo.jcr.component.core.impl.infinispan.v5/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNLockTableHandler.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
Log:
EXOJCR-1762: repair db
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-02-29 12:48:50 UTC (rev 5711)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-02-29 12:50:41 UTC (rev 5712)
@@ -145,6 +145,11 @@
protected String FIND_PROPERTIES_BY_PARENTID;
/**
+ * FIND_LOWEST_PROPERTY_VERSIONS.
+ */
+ protected String FIND_LOWEST_PROPERTY_VERSIONS;
+
+ /**
* INSERT_NODE.
*/
protected String INSERT_NODE;
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2012-02-29 12:48:50 UTC (rev 5711)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2012-02-29 12:50:41 UTC (rev 5712)
@@ -167,6 +167,8 @@
protected PreparedStatement findPropertiesByParentId;
+ protected PreparedStatement findLowestPropertyVersions;
+
protected PreparedStatement insertItem;
protected PreparedStatement insertNode;
@@ -481,6 +483,11 @@
findPropertiesByParentId.close();
}
+ if (findLowestPropertyVersions != null)
+ {
+ findLowestPropertyVersions.close();
+ }
+
if (insertItem != null)
{
insertItem.close();
@@ -2666,6 +2673,16 @@
}
};
+ protected ResultSet findLowestPropertyVersions() throws SQLException
+ {
+ if (findLowestPropertyVersions == null)
+ {
+ findLowestPropertyVersions = dbConnection.prepareStatement(FIND_LOWEST_PROPERTY_VERSIONS);
+ }
+
+ return findLowestPropertyVersions.executeQuery();
+ }
+
protected abstract int addNodeRecord(NodeData data) throws SQLException;
protected abstract int addPropertyRecord(PropertyData prop) throws SQLException;
@@ -2727,4 +2744,5 @@
protected abstract ResultSet findValuesStorageDescriptorsByPropertyId(String cid) throws SQLException;
protected abstract ResultSet findValueByPropertyIdOrderNumber(String cid, int orderNumb) throws SQLException;
+
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 12:48:50 UTC (rev 5711)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 12:50:41 UTC (rev 5712)
@@ -23,7 +23,7 @@
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.checker.AssignRootAsParentRepair;
+import org.exoplatform.services.jcr.impl.checker.AssignerRootAsParent;
import org.exoplatform.services.jcr.impl.checker.DummyRepair;
import org.exoplatform.services.jcr.impl.checker.InspectionQuery;
import org.exoplatform.services.jcr.impl.checker.InspectionQueryFilteredMultivaluedProperties;
@@ -456,7 +456,7 @@
: "select * from JCR_SITEM I where I.CONTAINER_NAME='" + jdbcDataContainer.containerName
+ "' and NOT EXISTS(select * from JCR_SITEM P where P.ID = I.PARENT_ID)", new String[]{
DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME, DBConstants.COLUMN_CLASS},
- "Items that do not have parent nodes", new AssignRootAsParentRepair(jdbcDataContainer
+ "Items that do not have parent nodes", new AssignerRootAsParent(jdbcDataContainer
.getConnectionFactory())));
itemsInspectionQuery
@@ -524,7 +524,7 @@
: "select * from JCR_SITEM I where I.ID = I.PARENT_ID and I.CONTAINER_NAME='"
+ jdbcDataContainer.containerName + "' and I.NAME <> '" + Constants.ROOT_PARENT_NAME + "'", new String[]{
DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME}, "An item is its own parent.",
- new AssignRootAsParentRepair(jdbcDataContainer.getConnectionFactory())));
+ new AssignerRootAsParent(jdbcDataContainer.getConnectionFactory())));
itemsInspectionQuery
.add(new InspectionQuery(
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2012-02-29 12:48:50 UTC (rev 5711)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2012-02-29 12:50:41 UTC (rev 5712)
@@ -137,6 +137,10 @@
FIND_PROPERTIES_BY_PARENTID = "select * from JCR_MITEM" + " where I_CLASS=2 and PARENT_ID=?" + " order by ID";
+ FIND_LOWEST_PROPERTY_VERSIONS =
+ "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
+ + " GROUP BY PARENT_ID, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+
INSERT_NODE =
"insert into JCR_MITEM(ID, PARENT_ID, NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,"
+ I_CLASS_NODE + ",?,?)";
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2012-02-29 12:48:50 UTC (rev 5711)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2012-02-29 12:50:41 UTC (rev 5712)
@@ -146,6 +146,10 @@
FIND_PROPERTIES_BY_PARENTID =
"select * from JCR_SITEM" + " where I_CLASS=2 and CONTAINER_NAME=? and PARENT_ID=?" + " order by ID";
+ FIND_LOWEST_PROPERTY_VERSIONS =
+ "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, CONTAINER_NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
+ + " GROUP BY PARENT_ID, CONTAINER_NAME, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+
INSERT_NODE =
"insert into JCR_SITEM(ID, PARENT_ID, NAME, CONTAINER_NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,?,"
+ I_CLASS_NODE + ",?,?)";
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2012-02-29 12:48:50 UTC (rev 5711)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2012-02-29 12:50:41 UTC (rev 5712)
@@ -181,6 +181,10 @@
FIND_NODES_BY_PARENTID_AND_PATTERN_CQ_TEMPLATE =
"select I.*, P.NAME AS PROP_NAME, V.ORDER_NUM, V.DATA from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V";
+ FIND_LOWEST_PROPERTY_VERSIONS =
+ "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
+ + " GROUP BY PARENT_ID, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+
INSERT_NODE =
"insert into JCR_MITEM(ID, PARENT_ID, NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,"
+ I_CLASS_NODE + ",?,?)";
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2012-02-29 12:48:50 UTC (rev 5711)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2012-02-29 12:50:41 UTC (rev 5712)
@@ -190,6 +190,10 @@
FIND_NODES_BY_PARENTID_AND_PATTERN_CQ_TEMPLATE =
"select I.*, P.NAME AS PROP_NAME, V.ORDER_NUM, V.DATA from JCR_SITEM I, JCR_SITEM P, JCR_SVALUE V";
+ FIND_LOWEST_PROPERTY_VERSIONS =
+ "select max(VERSION) as MAX_VERSION, PARENT_ID, NAME, CONTAINER_NAME, I_CLASS, I_INDEX from JCR_SITEM WHERE I_CLASS=2"
+ + " GROUP BY PARENT_ID, CONTAINER_NAME, NAME, I_CLASS, I_INDEX HAVING count(VERSION) > 1";
+
INSERT_NODE =
"insert into JCR_SITEM(ID, PARENT_ID, NAME, CONTAINER_NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,?,"
+ I_CLASS_NODE + ",?,?)";
Modified: jcr/trunk/exo.jcr.component.core.impl.infinispan.v5/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNLockTableHandler.java
===================================================================
--- jcr/trunk/exo.jcr.component.core.impl.infinispan.v5/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNLockTableHandler.java 2012-02-29 12:48:50 UTC (rev 5711)
+++ jcr/trunk/exo.jcr.component.core.impl.infinispan.v5/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNLockTableHandler.java 2012-02-29 12:50:41 UTC (rev 5712)
@@ -20,6 +20,7 @@
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.checker.DummyRepair;
import org.exoplatform.services.jcr.impl.checker.InspectionQuery;
import org.exoplatform.services.jcr.impl.core.lock.AbstractLockTableHandler;
import org.exoplatform.services.log.ExoLogger;
@@ -54,7 +55,8 @@
*/
protected InspectionQuery getSelectQuery() throws SQLException
{
- return new InspectionQuery("SELECT * FROM " + getTableName(), new String[]{getIdColumn()}, "Locks table match");
+ return new InspectionQuery("SELECT * FROM " + getTableName(), new String[]{getIdColumn()}, "Locks table match",
+ new DummyRepair());
}
/**
@@ -63,7 +65,7 @@
public InspectionQuery getDeleteQuery(String nodeId) throws SQLException
{
return new InspectionQuery("DELETE FROM " + getTableName() + " WHERE " + getIdColumn() + "='" + nodeId + "'",
- new String[]{}, "");
+ new String[]{}, "", new DummyRepair());
}
/**
12 years, 1 month
exo-jcr SVN: r5711 - in jcr/branches/1.15.x/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache and 2 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2012-02-29 07:48:50 -0500 (Wed, 29 Feb 2012)
New Revision: 5711
Added:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignRootAsParentRepair.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/DummyRepair.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InconsistencyRepair.java
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQuery.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQueryFilteredMultivaluedProperties.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCLockTableHandler.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCShareableLockTableHandler.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java
Log:
EXOJCR-1762: repair db
Added: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignRootAsParentRepair.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignRootAsParentRepair.java (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignRootAsParentRepair.java 2012-02-29 12:48:50 UTC (rev 5711)
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import org.exoplatform.services.jcr.datamodel.IllegalNameException;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
+import org.exoplatform.services.jcr.datamodel.ValueData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
+import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
+import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: AssignRootAsParentRepair.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class AssignRootAsParentRepair implements InconsistencyRepair
+{
+
+ protected static final Log LOG = ExoLogger.getLogger("exo.jcr.component.core.AssignRootAsParentRepair");
+
+ protected final WorkspaceStorageConnectionFactory connFactory;
+
+ public AssignRootAsParentRepair(WorkspaceStorageConnectionFactory connFactory)
+ {
+ this.connFactory = connFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void doRepair(ResultSet resultSet) throws SQLException
+ {
+ WorkspaceStorageConnection conn = null;
+ try
+ {
+ conn = connFactory.openConnection();
+ if (!(conn instanceof JDBCStorageConnection))
+ {
+ throw new SQLException("Connection is instance of " + conn);
+ }
+
+ if (resultSet.getInt(DBConstants.COLUMN_CLASS) == 1)
+ {
+ repairNode((JDBCStorageConnection)conn, resultSet);
+ }
+ else
+ {
+ repairProperty((JDBCStorageConnection)conn, resultSet);
+ }
+
+ conn.commit();
+ }
+ catch (RepositoryException e)
+ {
+ rollback(conn);
+ throw new SQLException(e);
+ }
+ finally
+ {
+ closeConnection(conn);
+ }
+ }
+
+ private void repairProperty(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ try
+ {
+ String propertyId = exctractId(resultSet);
+ QPath path = QPath.parse(resultSet.getString(DBConstants.COLUMN_NAME));
+
+ PropertyData data = new TransientPropertyData(path, propertyId, 0, 0, null, false, new ArrayList<ValueData>());
+
+ conn.delete(data);
+ }
+ catch (UnsupportedOperationException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (InvalidItemStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
+ }
+
+ private void repairNode(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ try
+ {
+ String nodeId = exctractId(resultSet);
+ int orderNum = resultSet.getInt(DBConstants.COLUMN_NORDERNUM);
+ int version = resultSet.getInt(DBConstants.COLUMN_VERSION);
+ QPath path =
+ new QPath(new QPathEntry[]{new QPathEntry(
+ InternalQName.parse(resultSet.getString(DBConstants.COLUMN_NAME)),
+ resultSet.getInt(DBConstants.COLUMN_INDEX))});
+
+ NodeData data =
+ new TransientNodeData(path, nodeId, version, null, null, orderNum, Constants.ROOT_UUID, null);
+
+ conn.rename(data);
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (IllegalNameException e)
+ {
+ throw new SQLException(e);
+ }
+ }
+
+ private void closeConnection(WorkspaceStorageConnection conn) throws SQLException
+ {
+ try
+ {
+ conn.close();
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
+ }
+
+ private void rollback(WorkspaceStorageConnection conn)
+ {
+ try
+ {
+ if (conn != null)
+ {
+ conn.rollback();
+ }
+ }
+ catch (IllegalStateException e)
+ {
+ LOG.error("Can not rollback", e);
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error("Can not rollback", e);
+ }
+ }
+
+ private String exctractId(ResultSet resultSet) throws SQLException
+ {
+ String containerName = "";
+ try
+ {
+ containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
+ }
+ catch (SQLException e)
+ {
+ }
+
+ return resultSet.getString(DBConstants.COLUMN_ID).substring(containerName.length());
+ }
+
+ private String concatId(ResultSet resultSet, String id) throws SQLException
+ {
+ String containerName = "";
+ try
+ {
+ containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
+ }
+ catch (SQLException e)
+ {
+ }
+
+ return containerName + id;
+ }
+
+}
Added: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/DummyRepair.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/DummyRepair.java (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/DummyRepair.java 2012-02-29 12:48:50 UTC (rev 5711)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: DummyRepair.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class DummyRepair implements InconsistencyRepair
+{
+
+ /**
+ * {@inheritDoc}
+ */
+ public void doRepair(ResultSet resultSet) throws SQLException
+ {
+ // do nothing
+ }
+}
Added: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InconsistencyRepair.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InconsistencyRepair.java (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InconsistencyRepair.java 2012-02-29 12:48:50 UTC (rev 5711)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: RepairInconsistency.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public interface InconsistencyRepair
+{
+ /**
+ * Repair inconsistency based on resultSet.
+ *
+ * @param resultSet
+ * @throws SQLException
+ */
+ void doRepair(ResultSet resultSet) throws SQLException;
+}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQuery.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQuery.java 2012-02-29 11:24:32 UTC (rev 5710)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQuery.java 2012-02-29 12:48:50 UTC (rev 5711)
@@ -44,13 +44,19 @@
public String[] fieldNames;
/**
+ * Utility class which help to fix inconsistency.
+ */
+ public InconsistencyRepair repair;
+
+ /**
* Data class, contains a combination of SQL states, description, field names and status
*/
- public InspectionQuery(String statement, String[] fieldNames, String headerMessage)
+ public InspectionQuery(String statement, String[] fieldNames, String headerMessage, InconsistencyRepair repair)
{
this.statement = statement;
this.description = headerMessage;
this.fieldNames = fieldNames;
+ this.repair = repair;
}
public String getStatement()
@@ -68,6 +74,11 @@
return fieldNames;
}
+ public InconsistencyRepair getRepair()
+ {
+ return repair;
+ }
+
/**
* Creates a PreparedStatement object for sending parameterized SQL statements to the database.
*
@@ -82,5 +93,4 @@
{
return connection.prepareStatement(statement);
}
-
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQueryFilteredMultivaluedProperties.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQueryFilteredMultivaluedProperties.java 2012-02-29 11:24:32 UTC (rev 5710)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQueryFilteredMultivaluedProperties.java 2012-02-29 12:48:50 UTC (rev 5711)
@@ -33,9 +33,10 @@
/**
* {@inheritDoc}
*/
- public InspectionQueryFilteredMultivaluedProperties(String statement, String[] fieldNames, String headerMessage)
+ public InspectionQueryFilteredMultivaluedProperties(String statement, String[] fieldNames, String headerMessage,
+ InconsistencyRepair repair)
{
- super(statement, fieldNames, headerMessage);
+ super(statement, fieldNames, headerMessage, repair);
}
/**
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java 2012-02-29 11:24:32 UTC (rev 5710)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java 2012-02-29 12:48:50 UTC (rev 5711)
@@ -21,10 +21,8 @@
import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
-import org.exoplatform.management.annotations.ManagedName;
import org.exoplatform.management.jmx.annotations.NameTemplate;
import org.exoplatform.management.jmx.annotations.Property;
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.impl.AbstractRepositorySuspender;
@@ -311,15 +309,14 @@
}
}
- private void doCheckDataBase(boolean autoRepair) throws RepositoryException, IOException,
- RepositoryConfigurationException
+ private void doCheckDataBase(boolean autoRepair)
{
for (String wsName : repository.getWorkspaceNames())
{
logComment("Check DB consistency. Workspace " + wsName);
JDBCWorkspaceDataContainerChecker jdbcChecker = getJDBCChecker(wsName);
- jdbcChecker.checkDataBase();
+ jdbcChecker.checkDataBase(autoRepair);
jdbcChecker.checkLocksInDataBase(autoRepair);
}
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCLockTableHandler.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCLockTableHandler.java 2012-02-29 11:24:32 UTC (rev 5710)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCLockTableHandler.java 2012-02-29 12:48:50 UTC (rev 5711)
@@ -20,6 +20,7 @@
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.checker.DummyRepair;
import org.exoplatform.services.jcr.impl.checker.InspectionQuery;
import org.exoplatform.services.jcr.impl.core.lock.AbstractLockTableHandler;
import org.exoplatform.services.log.ExoLogger;
@@ -53,7 +54,7 @@
protected InspectionQuery getSelectQuery() throws SQLException
{
return new InspectionQuery("SELECT * FROM " + getTableName() + " WHERE " + getParentColumn() + "='/"
- + CacheableLockManagerImpl.LOCKS + "'", new String[]{getIdColumn()}, "Locks table match");
+ + CacheableLockManagerImpl.LOCKS + "'", new String[]{getIdColumn()}, "Locks table match", new DummyRepair());
}
/**
@@ -62,7 +63,7 @@
protected InspectionQuery getDeleteQuery(String nodeId) throws SQLException
{
return new InspectionQuery("DELETE FROM " + getTableName() + " WHERE " + getIdColumn() + "='/"
- + CacheableLockManagerImpl.LOCKS + "/" + nodeId + "'", new String[]{}, "");
+ + CacheableLockManagerImpl.LOCKS + "/" + nodeId + "'", new String[]{}, "", new DummyRepair());
}
/**
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCShareableLockTableHandler.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCShareableLockTableHandler.java 2012-02-29 11:24:32 UTC (rev 5710)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCShareableLockTableHandler.java 2012-02-29 12:48:50 UTC (rev 5711)
@@ -17,6 +17,7 @@
package org.exoplatform.services.jcr.impl.core.lock.jbosscache;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.checker.DummyRepair;
import org.exoplatform.services.jcr.impl.checker.InspectionQuery;
import org.exoplatform.services.jcr.impl.core.lock.LockTableHandler;
@@ -49,14 +50,14 @@
{
return new InspectionQuery("SELECT * FROM " + getTableName() + " WHERE " + getParentColumn() + "='/"
+ workspaceEntry.getUniqueName() + "/" + CacheableLockManagerImpl.LOCKS + "'", new String[]{getIdColumn()},
- "Locks table match");
+ "Locks table match", new DummyRepair());
}
protected InspectionQuery getDeleteQuery(String nodeId) throws SQLException
{
return new InspectionQuery("DELETE FROM " + getTableName() + " WHERE " + getIdColumn() + "='/"
+ workspaceEntry.getUniqueName() + "/" + CacheableLockManagerImpl.LOCKS + "/" + nodeId + "'", new String[]{},
- "");
+ "", new DummyRepair());
}
}
\ No newline at end of file
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-02-29 11:24:32 UTC (rev 5710)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-02-29 12:48:50 UTC (rev 5711)
@@ -204,67 +204,72 @@
/**
* COLUMN_ID.
*/
- protected static final String COLUMN_ID = "ID";
+ public static final String COLUMN_ID = "ID";
/**
* COLUMN_PARENTID.
*/
- protected static final String COLUMN_PARENTID = "PARENT_ID";
+ public static final String COLUMN_PARENTID = "PARENT_ID";
/**
* COLUMN_NAME.
*/
- protected static final String COLUMN_NAME = "NAME";
+ public static final String COLUMN_NAME = "NAME";
/**
* COLUMN_VERSION.
*/
- protected static final String COLUMN_VERSION = "VERSION";
+ public static final String COLUMN_VERSION = "VERSION";
/**
+ * CONTAINER_NAME. Exists only for single-db.
+ */
+ public static final String CONTAINER_NAME = "CONTAINER_NAME";
+
+ /**
* COLUMN_CLASS.
*/
- protected static final String COLUMN_CLASS = "I_CLASS";
+ public static final String COLUMN_CLASS = "I_CLASS";
/**
* COLUMN_INDEX.
*/
- protected static final String COLUMN_INDEX = "I_INDEX";
+ public static final String COLUMN_INDEX = "I_INDEX";
/**
* COLUMN_NORDERNUM.
*/
- protected static final String COLUMN_NORDERNUM = "N_ORDER_NUM";
+ public static final String COLUMN_NORDERNUM = "N_ORDER_NUM";
/**
* COLUMN_PTYPE.
*/
- protected static final String COLUMN_PTYPE = "P_TYPE";
+ public static final String COLUMN_PTYPE = "P_TYPE";
/**
* COLUMN_PMULTIVALUED.
*/
- protected static final String COLUMN_PMULTIVALUED = "P_MULTIVALUED";
+ public static final String COLUMN_PMULTIVALUED = "P_MULTIVALUED";
// VALUE table
/**
* PROPERTY_ID
*/
- protected static final String COLUMN_VPROPERTY_ID = "PROPERTY_ID";
+ public static final String COLUMN_VPROPERTY_ID = "PROPERTY_ID";
/**
* COLUMN_VDATA.
*/
- protected static final String COLUMN_VDATA = "DATA";
+ public static final String COLUMN_VDATA = "DATA";
/**
* COLUMN_VORDERNUM.
*/
- protected static final String COLUMN_VORDERNUM = "ORDER_NUM";
+ public static final String COLUMN_VORDERNUM = "ORDER_NUM";
/**
* COLUMN_VSTORAGE_DESC.
*/
- protected static final String COLUMN_VSTORAGE_DESC = "STORAGE_DESC";
+ public static final String COLUMN_VSTORAGE_DESC = "STORAGE_DESC";
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 11:24:32 UTC (rev 5710)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 12:48:50 UTC (rev 5711)
@@ -24,6 +24,8 @@
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.checker.AssignRootAsParentRepair;
+import org.exoplatform.services.jcr.impl.checker.DummyRepair;
import org.exoplatform.services.jcr.impl.checker.InspectionQuery;
import org.exoplatform.services.jcr.impl.checker.InspectionQueryFilteredMultivaluedProperties;
import org.exoplatform.services.jcr.impl.checker.InspectionReport;
@@ -42,7 +44,9 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.jcr.RepositoryException;
@@ -69,6 +73,8 @@
private InspectionQuery lockInspectionQuery;
+ private List<InspectionQuery> itemsInspectionQuery = new ArrayList<InspectionQuery>();;
+
private LockTableHandler lockHandler;
/**
@@ -92,7 +98,7 @@
* and has no corresponding record in LockManager persistent layer (db table);
* or the opposite.
*/
- public void checkLocksInDataBase(boolean autoRepair) throws RepositoryException, IOException
+ public void checkLocksInDataBase(boolean autoRepair)
{
SecurityHelper.validateSecurityPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
@@ -118,16 +124,20 @@
}
catch (SQLException e)
{
- report.logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
+ logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
}
catch (NamingException e)
{
- report.logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
+ logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
}
catch (RepositoryConfigurationException e)
{
- report.logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
+ logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
}
+ catch (RepositoryException e)
+ {
+ logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
+ }
finally
{
JDBCUtils.freeResources(resultSet, preparedStatement, jdbcConnection);
@@ -188,132 +198,17 @@
* <p>
* Check that database is not broken, and all base relation between jcr-items are not corrupted.
* </p>
- *
- * @param inspectionLog - log where inspection results will be placed
- * @return InspectionLog
- * @throws RepositoryException
- * @throws IOException
*/
- public void checkDataBase()
- throws RepositoryException, IOException
+ public void checkDataBase(boolean autoRepair)
{
SecurityHelper.validateSecurityPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
- Set<InspectionQuery> queries = new HashSet<InspectionQuery>();
-
- // preload queries
- queries.add(new InspectionQuery(jdbcDataContainer.multiDb
- ? "select * from JCR_MITEM I where NOT EXISTS(select * from JCR_MITEM P where P.ID = I.PARENT_ID)"
- : "select * from JCR_SITEM I where I.CONTAINER_NAME='" + jdbcDataContainer.containerName
- + "' and NOT EXISTS(select * from JCR_SITEM P where P.ID = I.PARENT_ID)", new String[]{
- DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME, DBConstants.COLUMN_CLASS},
- "Items that do not have parent nodes"));
-
- queries.add(new InspectionQuery(jdbcDataContainer.multiDb
- ? "select * from JCR_MITEM N where N.I_CLASS=1 and NOT EXISTS "
- + "(select * from JCR_MITEM P where P.I_CLASS=2 and P.PARENT_ID=N.ID "
- + "and P.NAME='[http://www.jcp.org/jcr/1.0]primaryType')"
- : "select * from JCR_SITEM N where N.CONTAINER_NAME='" + jdbcDataContainer.containerName
- + "' and N.I_CLASS=1 and NOT EXISTS (select * from JCR_SITEM P "
- + "where P.I_CLASS=2 and P.PARENT_ID=N.ID and P.NAME='[http://www.jcp.org/jcr/1.0]primaryType' "
- + "and P.CONTAINER_NAME='" + jdbcDataContainer.containerName + "')", new String[]{DBConstants.COLUMN_ID,
- DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME},
- "Nodes that do not have at least one jcr:primaryType property"));
-
- queries.add(new InspectionQuery(jdbcDataContainer.multiDb
- ? "select * from JCR_MVALUE V where NOT EXISTS(select * from JCR_MITEM P "
- + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)"
- : "select * from JCR_SVALUE V where NOT EXISTS(select * from JCR_SITEM P "
- + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)", new String[]{DBConstants.COLUMN_ID,
- DBConstants.COLUMN_VPROPERTY_ID}, "All value records that has not owner-property record"));
-
- queries
- .add(new InspectionQueryFilteredMultivaluedProperties(
- jdbcDataContainer.multiDb
- ? "select * from JCR_MITEM P where P.I_CLASS=2 and P.P_MULTIVALUED=? and NOT EXISTS( select * from JCR_MVALUE V "
- + "where V.PROPERTY_ID=P.ID)"
- : "select * from JCR_SITEM P where P.CONTAINER_NAME='"
- + jdbcDataContainer.containerName
- + "' and P.I_CLASS=2 and P.P_MULTIVALUED=? and NOT EXISTS( select * from JCR_SVALUE V where V.PROPERTY_ID=P.ID)",
- new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME},
- "All properties that have not value record."));
-
- // The differences in the queries by DB dialect.
- // Oracle doesn't work correct with default query because empty value stored as null value.
- String statement;
- if (jdbcDataContainer.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE))
- {
- statement =
- jdbcDataContainer.multiDb
- ? "select * from JCR_MVALUE where (STORAGE_DESC is null and DATA like null) or "
- + "(STORAGE_DESC is not null and not DATA like null)"
- : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
- + jdbcDataContainer.containerName
- + "' AND ((STORAGE_DESC is null and DATA like null) or (STORAGE_DESC is not null and not DATA like null))";
- }
- else if (jdbcDataContainer.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLE)
- || jdbcDataContainer.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLEOCI))
- {
- statement =
- jdbcDataContainer.multiDb
- ? "select * from JCR_MVALUE where (STORAGE_DESC is not null and DATA is not null)"
- : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
- + jdbcDataContainer.containerName + "' AND (STORAGE_DESC is not null and DATA is not null)";
- }
- else
- {
- statement =
- jdbcDataContainer.multiDb
- ? "select * from JCR_MVALUE where (STORAGE_DESC is null and DATA is null) or "
- + "(STORAGE_DESC is not null and DATA is not null)"
- : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
- + jdbcDataContainer.containerName
- + "' AND ((STORAGE_DESC is null and DATA is null) or (STORAGE_DESC is not null and DATA is not null))";
- }
- queries.add(new InspectionQuery(statement, new String[]{DBConstants.COLUMN_ID}, "Incorrect JCR_VALUE records"));
-
- queries
- .add(new InspectionQueryFilteredMultivaluedProperties(
- jdbcDataContainer.multiDb
- ? "select * from JCR_MITEM P where P.P_TYPE=9 and P.P_MULTIVALUED=? and NOT EXISTS "
- + "(select * from JCR_MREF R where P.ID=R.PROPERTY_ID)"
- : "select * from JCR_SITEM P where P.CONTAINER_NAME='"
- + jdbcDataContainer.containerName
- + "' and P.P_TYPE=9 and P.P_MULTIVALUED=? and NOT EXISTS( select * from JCR_SREF R where P.ID=R.PROPERTY_ID)",
- new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME},
- "Reference properties without reference records"));
-
- // an item is its own parent.
- queries.add(new InspectionQuery(jdbcDataContainer.multiDb
- ? "select * from JCR_MITEM I where I.ID = I.PARENT_ID and I.NAME <> '" + Constants.ROOT_PARENT_NAME + "'"
- : "select * from JCR_SITEM I where I.ID = I.PARENT_ID and I.CONTAINER_NAME='"
- + jdbcDataContainer.containerName + "' and I.NAME <> '" + Constants.ROOT_PARENT_NAME + "'", new String[]{
- DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME}, "An item is its own parent."));
-
- // Several versions of same item
- queries
- .add(new InspectionQuery(
- jdbcDataContainer.multiDb
- ? "select * from JCR_MITEM I where EXISTS (select * from JCR_MITEM J"
- + " WHERE I.PARENT_ID = J.PARENT_ID AND I.NAME = J.NAME and I.I_INDEX = J.I_INDEX and I.I_CLASS = J.I_CLASS"
- + " and I.VERSION != J.VERSION)"
- : "select * from JCR_SITEM I where I.CONTAINER_NAME='"
- + jdbcDataContainer.containerName
- + "' and"
- + " EXISTS (select * from JCR_SITEM J WHERE I.CONTAINER_NAME = J.CONTAINER_NAME and"
- + " I.PARENT_ID = J.PARENT_ID AND I.NAME = J.NAME and I.I_INDEX = J.I_INDEX and I.I_CLASS = J.I_CLASS"
- + " and I.VERSION != J.VERSION)",
- new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME,
- DBConstants.COLUMN_VERSION, DBConstants.COLUMN_CLASS, DBConstants.COLUMN_INDEX},
- "Several versions of same item."));
-
- // using existing DataSource to get a JDBC Connection.
- Connection jdbcConn = jdbcDataContainer.getConnectionFactory().getJdbcConnection();
-
+ Connection jdbcConn = null;
try
{
- // perform all queries on-by-one
- for (InspectionQuery query : queries)
+ jdbcConn = jdbcDataContainer.getConnectionFactory().getJdbcConnection();
+
+ for (InspectionQuery query : itemsInspectionQuery)
{
PreparedStatement st = null;
ResultSet resultSet = null;
@@ -321,32 +216,18 @@
{
st = query.prepareStatement(jdbcConn);
- // the result of query is expected to be empty
resultSet = st.executeQuery();
if (resultSet.next())
{
- // but if result not empty, then inconsistency takes place
- report.logDescription(query.getDescription());
+ logDescription(query.getDescription());
do
{
- StringBuilder record = new StringBuilder();
- for (String fieldName : query.getFieldNames())
+ logBrokenObjectAndSetInconsistency(getBrokenObject(resultSet, query.getFieldNames()));
+ if (autoRepair)
{
- record.append(fieldName);
- record.append('=');
- if (fieldName.equals(DBConstants.COLUMN_NORDERNUM)
- || fieldName.equals(DBConstants.COLUMN_VORDERNUM))
- {
- record.append(resultSet.getInt(fieldName));
- }
- else
- {
- record.append(resultSet.getString(fieldName));
- }
- record.append(' ');
+ query.getRepair().doRepair(resultSet);
+ logComment("Inconsistency has been fixed");
}
-
- report.logBrokenObjectAndSetInconsistency(record.toString());
}
while (resultSet.next());
}
@@ -359,8 +240,12 @@
}
catch (SQLException e)
{
- report.logExceptionAndSetInconsistency("Exception during DB inspection.", e);
+ logExceptionAndSetInconsistency("Unexpected exception during DB checking.", e);
}
+ catch (RepositoryException e)
+ {
+ logExceptionAndSetInconsistency("Unexpected exception during DB checking.", e);
+ }
finally
{
JDBCUtils.freeResources(null, null, jdbcConn);
@@ -549,29 +434,121 @@
private void initInspectionQueries()
{
- String singleDbQuery =
- "SELECT V.PROPERTY_ID, V.ORDER_NUM, V.STORAGE_DESC from JCR_SVALUE V, JCR_SITEM I"
- + " where I.CONTAINER_NAME='" + jdbcDataContainer.containerName
- + "' and V.PROPERTY_ID = I.ID and STORAGE_DESC is not null";
- String multiDbQuery =
- "SELECT PROPERTY_ID, ORDER_NUM, STORAGE_DESC from JCR_MVALUE where STORAGE_DESC is not null";
-
vsInspectionQuery =
- new InspectionQuery(jdbcDataContainer.multiDb ? multiDbQuery : singleDbQuery, new String[]{
- DBConstants.COLUMN_VPROPERTY_ID, DBConstants.COLUMN_VORDERNUM, DBConstants.COLUMN_VSTORAGE_DESC},
- "Items with value data stored in value storage");
+ new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select PROPERTY_ID, ORDER_NUM, STORAGE_DESC from JCR_MVALUE where STORAGE_DESC is not null"
+ : "select V.PROPERTY_ID, V.ORDER_NUM, V.STORAGE_DESC from JCR_SVALUE V, JCR_SITEM I"
+ + " where I.CONTAINER_NAME='" + jdbcDataContainer.containerName
+ + "' and V.PROPERTY_ID = I.ID and STORAGE_DESC is not null",
+ new String[]{DBConstants.COLUMN_VPROPERTY_ID, DBConstants.COLUMN_VORDERNUM,
+ DBConstants.COLUMN_VSTORAGE_DESC}, "Items with value data stored in value storage", new DummyRepair());
- singleDbQuery =
- "SELECT DISTINCT PARENT_ID from JCR_MITEM WHERE I_CLASS=2 "
- + "AND (NAME='[http://www.jcp.org/jcr/1.0]lockOwner' OR NAME='[http://www.jcp.org/jcr/1.0]lockIsDeep')";
+ lockInspectionQuery =
+ new InspectionQuery(jdbcDataContainer.multiDb ? "select distinct PARENT_ID from JCR_MITEM where I_CLASS=2 AND"
+ + " (NAME='[http://www.jcp.org/jcr/1.0]lockOwner' OR NAME='[http://www.jcp.org/jcr/1.0]lockIsDeep')"
+ : "select distinct PARENT_ID from JCR_SITEM WHERE CONTAINER_NAME='" + jdbcDataContainer.containerName + "'"
+ + " AND I_CLASS=2 and (NAME='[http://www.jcp.org/jcr/1.0]lockOwner'"
+ + " OR NAME='[http://www.jcp.org/jcr/1.0]lockIsDeep')", new String[]{DBConstants.COLUMN_PARENTID},
+ "Items which have jcr:lockOwner and jcr:lockIsDeep properties", new DummyRepair());
- multiDbQuery =
- "SELECT DISTINCT PARENT_ID from JCR_SITEM WHERE CONTAINER_NAME='"
- + jdbcDataContainer.containerName
- + "' AND I_CLASS=2 and (NAME='[http://www.jcp.org/jcr/1.0]lockOwner' OR NAME='[http://www.jcp.org/jcr/1.0]lockIsDeep')";
+ // ITEM tables
+ itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select * from JCR_MITEM I where NOT EXISTS(select * from JCR_MITEM P where P.ID = I.PARENT_ID)"
+ : "select * from JCR_SITEM I where I.CONTAINER_NAME='" + jdbcDataContainer.containerName
+ + "' and NOT EXISTS(select * from JCR_SITEM P where P.ID = I.PARENT_ID)", new String[]{
+ DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME, DBConstants.COLUMN_CLASS},
+ "Items that do not have parent nodes", new AssignRootAsParentRepair(jdbcDataContainer
+ .getConnectionFactory())));
- lockInspectionQuery =
- new InspectionQuery(jdbcDataContainer.multiDb ? singleDbQuery : multiDbQuery,
- new String[]{DBConstants.COLUMN_PARENTID}, "Items which have jcr:lockOwner and jcr:lockIsDeep properties");
+ itemsInspectionQuery
+ .add(new InspectionQueryFilteredMultivaluedProperties(
+ jdbcDataContainer.multiDb
+ ? "select * from JCR_MITEM P where P.I_CLASS=2 and P.P_MULTIVALUED=? and NOT EXISTS( select * from JCR_MVALUE V "
+ + "where V.PROPERTY_ID=P.ID)" : "select * from JCR_SITEM P where P.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName + "' and P.I_CLASS=2"
+ + " and P.P_MULTIVALUED=? and NOT EXISTS( select * from JCR_SVALUE V where V.PROPERTY_ID=P.ID)",
+ new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME},
+ "A node that has a single valued properties with nothing declared in the VALUE table.", new DummyRepair()));
+
+ itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select * from JCR_MITEM N where N.I_CLASS=1 and NOT EXISTS "
+ + "(select * from JCR_MITEM P where P.I_CLASS=2 and P.PARENT_ID=N.ID "
+ + "and P.NAME='[http://www.jcp.org/jcr/1.0]primaryType')"
+ : "select * from JCR_SITEM N where N.CONTAINER_NAME='" + jdbcDataContainer.containerName
+ + "' and N.I_CLASS=1 and NOT EXISTS (select * from JCR_SITEM P "
+ + "where P.I_CLASS=2 and P.PARENT_ID=N.ID and P.NAME='[http://www.jcp.org/jcr/1.0]primaryType' "
+ + "and P.CONTAINER_NAME='" + jdbcDataContainer.containerName + "')", new String[]{DBConstants.COLUMN_ID,
+ DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME}, "A node that doesn't have primary type property",
+ new DummyRepair()));
+
+ itemsInspectionQuery
+ .add(new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select * from JCR_MVALUE V where NOT EXISTS(select * from JCR_MITEM P "
+ + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)"
+ : "select * from JCR_SVALUE V where NOT EXISTS(select * from JCR_SITEM P "
+ + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)", new String[]{DBConstants.COLUMN_ID,
+ DBConstants.COLUMN_VPROPERTY_ID}, "All value records that has not related property record",
+ new DummyRepair()));
+
+ // The differences in the queries by DB dialect.
+ String statement;
+ if (jdbcDataContainer.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE))
+ {
+ statement =
+ jdbcDataContainer.multiDb
+ ? "select * from JCR_MVALUE where (STORAGE_DESC is not null and not DATA like null)"
+ : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName + "' AND ((STORAGE_DESC is not null and not DATA like null))";
+ }
+ else if (jdbcDataContainer.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLE)
+ || jdbcDataContainer.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLEOCI))
+ {
+ statement =
+ jdbcDataContainer.multiDb
+ ? "select * from JCR_MVALUE where (STORAGE_DESC is not null and DATA is not null)"
+ : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName + "' AND (STORAGE_DESC is not null and DATA is not null)";
+ }
+ else
+ {
+ statement =
+ jdbcDataContainer.multiDb
+ ? "select * from JCR_MVALUE where (STORAGE_DESC is not null and DATA is not null)"
+ : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName + "' AND ((STORAGE_DESC is not null and DATA is not null))";
+ }
+ itemsInspectionQuery.add(new InspectionQuery(statement, new String[]{DBConstants.COLUMN_ID},
+ "Incorrect VALUE records. Both fields STORAGE_DESC and DATA contain not null value.", new DummyRepair()));
+
+ itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select * from JCR_MITEM I where I.ID = I.PARENT_ID and I.NAME <> '" + Constants.ROOT_PARENT_NAME + "'"
+ : "select * from JCR_SITEM I where I.ID = I.PARENT_ID and I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName + "' and I.NAME <> '" + Constants.ROOT_PARENT_NAME + "'", new String[]{
+ DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME}, "An item is its own parent.",
+ new AssignRootAsParentRepair(jdbcDataContainer.getConnectionFactory())));
+
+ itemsInspectionQuery
+ .add(new InspectionQuery(
+ jdbcDataContainer.multiDb
+ ? "select * from JCR_MITEM I where EXISTS (select * from JCR_MITEM J"
+ + " WHERE I.PARENT_ID = J.PARENT_ID AND I.NAME = J.NAME and I.I_INDEX = J.I_INDEX and I.I_CLASS = J.I_CLASS"
+ + " and I.VERSION != J.VERSION)"
+ : "select * from JCR_SITEM I where I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName
+ + "' and EXISTS (select * from JCR_SITEM J WHERE I.CONTAINER_NAME = J.CONTAINER_NAME and"
+ + " I.PARENT_ID = J.PARENT_ID AND I.NAME = J.NAME and I.I_INDEX = J.I_INDEX and I.I_CLASS = J.I_CLASS"
+ + " and I.VERSION != J.VERSION)",
+ new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME,
+ DBConstants.COLUMN_VERSION, DBConstants.COLUMN_CLASS, DBConstants.COLUMN_INDEX},
+ "Several versions of same item.", new DummyRepair()));
+
+ itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select * from JCR_MITEM P, JCR_MVALUE V where P.ID=V.PROPERTY_ID and P.P_TYPE=9 and NOT EXISTS "
+ + "(select * from JCR_MREF R where P.ID=R.PROPERTY_ID)"
+ : "select * from JCR_SITEM P, JCR_SVALUE V where P.ID=V.PROPERTY_ID and P.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName
+ + "' and P.P_TYPE=9 and NOT EXISTS (select * from JCR_SREF R where P.ID=R.PROPERTY_ID)", new String[]{
+ DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME},
+ "Reference properties without reference records", new DummyRepair()));
}
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java 2012-02-29 11:24:32 UTC (rev 5710)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java 2012-02-29 12:48:50 UTC (rev 5711)
@@ -503,6 +503,7 @@
public void testDBUsecasesTheParentIdIsIdOfThisNodeSingleDB() throws Exception
{
checkDBUsecasesTheParentIdIsIdOfThisNode(helper.createRepository(container, false, false));
+ checkDBUsecasesTheParentIdIsIdOfThisNode2(helper.createRepository(container, false, false));
}
/**
@@ -511,6 +512,7 @@
public void testDBUsecasesTheParentIdIsIdOfThisNodeMultiDB() throws Exception
{
checkDBUsecasesTheParentIdIsIdOfThisNode(helper.createRepository(container, true, false));
+ checkDBUsecasesTheParentIdIsIdOfThisNode2(helper.createRepository(container, true, false));
}
private void checkDBUsecasesTheParentIdIsIdOfThisNode(ManageableRepository repository) throws Exception
@@ -546,12 +548,51 @@
conn.commit();
conn.close();
- // repository is inconsistent
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ checkController.repairDataBase("yes");
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+
}
+ private void checkDBUsecasesTheParentIdIsIdOfThisNode2(ManageableRepository repository) throws Exception
+ {
+ // create repository and add property
+ SessionImpl session =
+ (SessionImpl)repository.login(credentials, repository.getConfiguration().getSystemWorkspaceName());
+ NodeImpl node = (NodeImpl)session.getRootNode().addNode("testNode");
+ PropertyImpl prop = (PropertyImpl)node.setProperty("prop", "test");
+ session.save();
+ session.logout();
+
+ // repository is consistent
+ TesterRepositoryCheckController checkController = new TesterRepositoryCheckController(repository);
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+
+ WorkspaceEntry wsEntry = repository.getConfiguration().getWorkspaceEntries().get(0);
+ boolean isMultiDb = wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
+
+ // change ITEM table
+ String sourceName = wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
+
+ Connection conn = ((DataSource)new InitialContext().lookup(sourceName)).getConnection();
+
+ conn.prepareStatement("DROP INDEX JCR_IDX_" + (isMultiDb ? "M" : "S") + "ITEM_PARENT").execute();
+ conn.prepareStatement(
+ "UPDATE JCR_" + (isMultiDb ? "M" : "S") + "ITEM SET PARENT_ID = '" + (isMultiDb ? "" : wsEntry.getName())
+ + prop.getInternalIdentifier() + "' WHERE ID='" + (isMultiDb ? "" : wsEntry.getName())
+ + prop.getInternalIdentifier() + "'").execute();
+
+ conn.commit();
+ conn.close();
+
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+
+ checkController.repairDataBase("yes");
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+
+ }
+
/**
* Usecase: property doens't have have parent node.
*/
@@ -683,7 +724,6 @@
public void testDBUsecasesIncorrectValueRecordsSingleDB() throws Exception
{
checkDBUsecasesIncorrectValueRecords(helper.createRepository(container, false, false));
- checkDBUsecasesIncorrectValueRecords2(helper.createRepository(container, false, false));
}
/**
@@ -692,7 +732,6 @@
public void testDBUsecasesIncorrectValueRecordsMultiDB() throws Exception
{
checkDBUsecasesIncorrectValueRecords(helper.createRepository(container, true, false));
- checkDBUsecasesIncorrectValueRecords2(helper.createRepository(container, true, false));
}
private void checkDBUsecasesIncorrectValueRecords(ManageableRepository repository) throws Exception
@@ -730,41 +769,6 @@
}
- private void checkDBUsecasesIncorrectValueRecords2(ManageableRepository repository) throws Exception
- {
- // create repository and add property
- SessionImpl session =
- (SessionImpl)repository.login(credentials, repository.getConfiguration().getSystemWorkspaceName());
- PropertyImpl prop = (PropertyImpl)session.getRootNode().addNode("testNode").setProperty("prop", "test");
- session.save();
- session.logout();
-
- // repository is consistent
- TesterRepositoryCheckController checkController = new TesterRepositoryCheckController(repository);
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
-
-
- WorkspaceEntry wsEntry = repository.getConfiguration().getWorkspaceEntries().get(0);
- boolean isMultiDb = wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
-
- // change VALUE table
- String sourceName = wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
-
- Connection conn = ((DataSource)new InitialContext().lookup(sourceName)).getConnection();
- conn.prepareStatement(
- "UPDATE JCR_" + (isMultiDb ? "M" : "S") + "VALUE SET DATA = NULL WHERE PROPERTY_ID = '"
- + (isMultiDb ? "" : wsEntry.getName()) + prop.getInternalIdentifier() + "'").execute();
-
- conn.commit();
- conn.close();
-
- // repository is inconsistent
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
-
- }
-
/**
* Usecase: value records has no item record.
*/
12 years, 1 month
exo-jcr SVN: r5710 - in jcr/trunk/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache and 3 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2012-02-29 06:24:32 -0500 (Wed, 29 Feb 2012)
New Revision: 5710
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignRootAsParentRepair.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/DummyRepair.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InconsistencyRepair.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQuery.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQueryFilteredMultivaluedProperties.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCLockTableHandler.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCShareableLockTableHandler.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java
Log:
EXOJCR-1762: auto-repair for DB inconsistency
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignRootAsParentRepair.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignRootAsParentRepair.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignRootAsParentRepair.java 2012-02-29 11:24:32 UTC (rev 5710)
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import org.exoplatform.services.jcr.datamodel.IllegalNameException;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
+import org.exoplatform.services.jcr.datamodel.ValueData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
+import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
+import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: AssignRootAsParentRepair.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class AssignRootAsParentRepair implements InconsistencyRepair
+{
+
+ protected static final Log LOG = ExoLogger.getLogger("exo.jcr.component.core.AssignRootAsParentRepair");
+
+ protected final WorkspaceStorageConnectionFactory connFactory;
+
+ public AssignRootAsParentRepair(WorkspaceStorageConnectionFactory connFactory)
+ {
+ this.connFactory = connFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void doRepair(ResultSet resultSet) throws SQLException
+ {
+ WorkspaceStorageConnection conn = null;
+ try
+ {
+ conn = connFactory.openConnection();
+ if (!(conn instanceof JDBCStorageConnection))
+ {
+ throw new SQLException("Connection is instance of " + conn);
+ }
+
+ if (resultSet.getInt(DBConstants.COLUMN_CLASS) == 1)
+ {
+ repairNode((JDBCStorageConnection)conn, resultSet);
+ }
+ else
+ {
+ repairProperty((JDBCStorageConnection)conn, resultSet);
+ }
+
+ conn.commit();
+ }
+ catch (RepositoryException e)
+ {
+ rollback(conn);
+ throw new SQLException(e);
+ }
+ finally
+ {
+ closeConnection(conn);
+ }
+ }
+
+ private void repairProperty(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ try
+ {
+ String propertyId = exctractId(resultSet);
+ QPath path = QPath.parse(resultSet.getString(DBConstants.COLUMN_NAME));
+
+ PropertyData data = new TransientPropertyData(path, propertyId, 0, 0, null, false, new ArrayList<ValueData>());
+
+ conn.delete(data);
+ }
+ catch (UnsupportedOperationException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (InvalidItemStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
+ }
+
+ private void repairNode(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ try
+ {
+ String nodeId = exctractId(resultSet);
+ int orderNum = resultSet.getInt(DBConstants.COLUMN_NORDERNUM);
+ int version = resultSet.getInt(DBConstants.COLUMN_VERSION);
+ QPath path =
+ new QPath(new QPathEntry[]{new QPathEntry(
+ InternalQName.parse(resultSet.getString(DBConstants.COLUMN_NAME)),
+ resultSet.getInt(DBConstants.COLUMN_INDEX))});
+
+ NodeData data =
+ new TransientNodeData(path, nodeId, version, null, null, orderNum, Constants.ROOT_UUID, null);
+
+ conn.rename(data);
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (IllegalNameException e)
+ {
+ throw new SQLException(e);
+ }
+ }
+
+ private void closeConnection(WorkspaceStorageConnection conn) throws SQLException
+ {
+ try
+ {
+ conn.close();
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
+ }
+
+ private void rollback(WorkspaceStorageConnection conn)
+ {
+ try
+ {
+ if (conn != null)
+ {
+ conn.rollback();
+ }
+ }
+ catch (IllegalStateException e)
+ {
+ LOG.error("Can not rollback", e);
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error("Can not rollback", e);
+ }
+ }
+
+ private String exctractId(ResultSet resultSet) throws SQLException
+ {
+ String containerName = "";
+ try
+ {
+ containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
+ }
+ catch (SQLException e)
+ {
+ }
+
+ return resultSet.getString(DBConstants.COLUMN_ID).substring(containerName.length());
+ }
+
+ private String concatId(ResultSet resultSet, String id) throws SQLException
+ {
+ String containerName = "";
+ try
+ {
+ containerName = resultSet.getString(DBConstants.CONTAINER_NAME);
+ }
+ catch (SQLException e)
+ {
+ }
+
+ return containerName + id;
+ }
+
+}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/DummyRepair.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/DummyRepair.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/DummyRepair.java 2012-02-29 11:24:32 UTC (rev 5710)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: DummyRepair.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class DummyRepair implements InconsistencyRepair
+{
+
+ /**
+ * {@inheritDoc}
+ */
+ public void doRepair(ResultSet resultSet) throws SQLException
+ {
+ // do nothing
+ }
+}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InconsistencyRepair.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InconsistencyRepair.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InconsistencyRepair.java 2012-02-29 11:24:32 UTC (rev 5710)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: RepairInconsistency.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public interface InconsistencyRepair
+{
+ /**
+ * Repair inconsistency based on resultSet.
+ *
+ * @param resultSet
+ * @throws SQLException
+ */
+ void doRepair(ResultSet resultSet) throws SQLException;
+}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQuery.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQuery.java 2012-02-29 08:24:57 UTC (rev 5709)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQuery.java 2012-02-29 11:24:32 UTC (rev 5710)
@@ -44,13 +44,19 @@
public String[] fieldNames;
/**
+ * Utility class which help to fix inconsistency.
+ */
+ public InconsistencyRepair repair;
+
+ /**
* Data class, contains a combination of SQL states, description, field names and status
*/
- public InspectionQuery(String statement, String[] fieldNames, String headerMessage)
+ public InspectionQuery(String statement, String[] fieldNames, String headerMessage, InconsistencyRepair repair)
{
this.statement = statement;
this.description = headerMessage;
this.fieldNames = fieldNames;
+ this.repair = repair;
}
public String getStatement()
@@ -68,6 +74,11 @@
return fieldNames;
}
+ public InconsistencyRepair getRepair()
+ {
+ return repair;
+ }
+
/**
* Creates a PreparedStatement object for sending parameterized SQL statements to the database.
*
@@ -82,5 +93,4 @@
{
return connection.prepareStatement(statement);
}
-
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQueryFilteredMultivaluedProperties.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQueryFilteredMultivaluedProperties.java 2012-02-29 08:24:57 UTC (rev 5709)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQueryFilteredMultivaluedProperties.java 2012-02-29 11:24:32 UTC (rev 5710)
@@ -33,9 +33,10 @@
/**
* {@inheritDoc}
*/
- public InspectionQueryFilteredMultivaluedProperties(String statement, String[] fieldNames, String headerMessage)
+ public InspectionQueryFilteredMultivaluedProperties(String statement, String[] fieldNames, String headerMessage,
+ InconsistencyRepair repair)
{
- super(statement, fieldNames, headerMessage);
+ super(statement, fieldNames, headerMessage, repair);
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java 2012-02-29 08:24:57 UTC (rev 5709)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java 2012-02-29 11:24:32 UTC (rev 5710)
@@ -21,10 +21,8 @@
import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
-import org.exoplatform.management.annotations.ManagedName;
import org.exoplatform.management.jmx.annotations.NameTemplate;
import org.exoplatform.management.jmx.annotations.Property;
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.impl.AbstractRepositorySuspender;
@@ -311,15 +309,14 @@
}
}
- private void doCheckDataBase(boolean autoRepair) throws RepositoryException, IOException,
- RepositoryConfigurationException
+ private void doCheckDataBase(boolean autoRepair)
{
for (String wsName : repository.getWorkspaceNames())
{
logComment("Check DB consistency. Workspace " + wsName);
JDBCWorkspaceDataContainerChecker jdbcChecker = getJDBCChecker(wsName);
- jdbcChecker.checkDataBase();
+ jdbcChecker.checkDataBase(autoRepair);
jdbcChecker.checkLocksInDataBase(autoRepair);
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCLockTableHandler.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCLockTableHandler.java 2012-02-29 08:24:57 UTC (rev 5709)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCLockTableHandler.java 2012-02-29 11:24:32 UTC (rev 5710)
@@ -20,6 +20,7 @@
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.checker.DummyRepair;
import org.exoplatform.services.jcr.impl.checker.InspectionQuery;
import org.exoplatform.services.jcr.impl.core.lock.AbstractLockTableHandler;
import org.exoplatform.services.log.ExoLogger;
@@ -53,7 +54,7 @@
protected InspectionQuery getSelectQuery() throws SQLException
{
return new InspectionQuery("SELECT * FROM " + getTableName() + " WHERE " + getParentColumn() + "='/"
- + CacheableLockManagerImpl.LOCKS + "'", new String[]{getIdColumn()}, "Locks table match");
+ + CacheableLockManagerImpl.LOCKS + "'", new String[]{getIdColumn()}, "Locks table match", new DummyRepair());
}
/**
@@ -62,7 +63,7 @@
protected InspectionQuery getDeleteQuery(String nodeId) throws SQLException
{
return new InspectionQuery("DELETE FROM " + getTableName() + " WHERE " + getIdColumn() + "='/"
- + CacheableLockManagerImpl.LOCKS + "/" + nodeId + "'", new String[]{}, "");
+ + CacheableLockManagerImpl.LOCKS + "/" + nodeId + "'", new String[]{}, "", new DummyRepair());
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCShareableLockTableHandler.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCShareableLockTableHandler.java 2012-02-29 08:24:57 UTC (rev 5709)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JBCShareableLockTableHandler.java 2012-02-29 11:24:32 UTC (rev 5710)
@@ -17,6 +17,7 @@
package org.exoplatform.services.jcr.impl.core.lock.jbosscache;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.checker.DummyRepair;
import org.exoplatform.services.jcr.impl.checker.InspectionQuery;
import org.exoplatform.services.jcr.impl.core.lock.LockTableHandler;
@@ -49,13 +50,13 @@
{
return new InspectionQuery("SELECT * FROM " + getTableName() + " WHERE " + getParentColumn() + "='/"
+ workspaceEntry.getUniqueName() + "/" + CacheableLockManagerImpl.LOCKS + "'", new String[]{getIdColumn()},
- "Locks table match");
+ "Locks table match", new DummyRepair());
}
protected InspectionQuery getDeleteQuery(String nodeId) throws SQLException
{
return new InspectionQuery("DELETE FROM " + getTableName() + " WHERE " + getIdColumn() + "='/"
+ workspaceEntry.getUniqueName() + "/" + CacheableLockManagerImpl.LOCKS + "/" + nodeId + "'", new String[]{},
- "");
+ "", new DummyRepair());
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2012-02-29 08:24:57 UTC (rev 5709)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2012-02-29 11:24:32 UTC (rev 5710)
@@ -49,7 +49,6 @@
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.ValueData;
import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.InspectionReport;
import org.exoplatform.services.jcr.impl.backup.BackupException;
import org.exoplatform.services.jcr.impl.backup.Backupable;
import org.exoplatform.services.jcr.impl.backup.DataRestore;
@@ -58,6 +57,7 @@
import org.exoplatform.services.jcr.impl.backup.Suspendable;
import org.exoplatform.services.jcr.impl.backup.rdbms.DataRestoreContext;
import org.exoplatform.services.jcr.impl.backup.rdbms.DirectoryRestore;
+import org.exoplatform.services.jcr.impl.checker.InspectionReport;
import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
import org.exoplatform.services.jcr.impl.core.SessionDataManager;
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-02-29 08:24:57 UTC (rev 5709)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-02-29 11:24:32 UTC (rev 5710)
@@ -203,68 +203,73 @@
/**
* COLUMN_ID.
*/
- protected static final String COLUMN_ID = "ID";
+ public static final String COLUMN_ID = "ID";
/**
* COLUMN_PARENTID.
*/
- protected static final String COLUMN_PARENTID = "PARENT_ID";
+ public static final String COLUMN_PARENTID = "PARENT_ID";
/**
* COLUMN_NAME.
*/
- protected static final String COLUMN_NAME = "NAME";
+ public static final String COLUMN_NAME = "NAME";
/**
* COLUMN_VERSION.
*/
- protected static final String COLUMN_VERSION = "VERSION";
+ public static final String COLUMN_VERSION = "VERSION";
/**
+ * CONTAINER_NAME. Exists only for single-db.
+ */
+ public static final String CONTAINER_NAME = "CONTAINER_NAME";
+
+ /**
* COLUMN_CLASS.
*/
- protected static final String COLUMN_CLASS = "I_CLASS";
+ public static final String COLUMN_CLASS = "I_CLASS";
/**
* COLUMN_INDEX.
*/
- protected static final String COLUMN_INDEX = "I_INDEX";
+ public static final String COLUMN_INDEX = "I_INDEX";
/**
* COLUMN_NORDERNUM.
*/
- protected static final String COLUMN_NORDERNUM = "N_ORDER_NUM";
+ public static final String COLUMN_NORDERNUM = "N_ORDER_NUM";
/**
* COLUMN_PTYPE.
*/
- protected static final String COLUMN_PTYPE = "P_TYPE";
+ public static final String COLUMN_PTYPE = "P_TYPE";
/**
* COLUMN_PMULTIVALUED.
*/
- protected static final String COLUMN_PMULTIVALUED = "P_MULTIVALUED";
+ public static final String COLUMN_PMULTIVALUED = "P_MULTIVALUED";
// VALUE table
/**
* PROPERTY_ID
*/
- protected static final String COLUMN_VPROPERTY_ID = "PROPERTY_ID";
+ public static final String COLUMN_VPROPERTY_ID = "PROPERTY_ID";
/**
* COLUMN_VDATA.
*/
- protected static final String COLUMN_VDATA = "DATA";
+ public static final String COLUMN_VDATA = "DATA";
/**
* COLUMN_VORDERNUM.
*/
- protected static final String COLUMN_VORDERNUM = "ORDER_NUM";
+ public static final String COLUMN_VORDERNUM = "ORDER_NUM";
/**
* COLUMN_VSTORAGE_DESC.
*/
- protected static final String COLUMN_VSTORAGE_DESC = "STORAGE_DESC";
+ public static final String COLUMN_VSTORAGE_DESC = "STORAGE_DESC";
// Dialects
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 08:24:57 UTC (rev 5709)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 11:24:32 UTC (rev 5710)
@@ -23,6 +23,8 @@
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.checker.AssignRootAsParentRepair;
+import org.exoplatform.services.jcr.impl.checker.DummyRepair;
import org.exoplatform.services.jcr.impl.checker.InspectionQuery;
import org.exoplatform.services.jcr.impl.checker.InspectionQueryFilteredMultivaluedProperties;
import org.exoplatform.services.jcr.impl.checker.InspectionReport;
@@ -41,7 +43,9 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.jcr.RepositoryException;
@@ -68,6 +72,8 @@
private InspectionQuery lockInspectionQuery;
+ private List<InspectionQuery> itemsInspectionQuery = new ArrayList<InspectionQuery>();;
+
private LockTableHandler lockHandler;
/**
@@ -91,7 +97,7 @@
* and has no corresponding record in LockManager persistent layer (db table);
* or the opposite.
*/
- public void checkLocksInDataBase(boolean autoRepair) throws RepositoryException, IOException
+ public void checkLocksInDataBase(boolean autoRepair)
{
SecurityHelper.validateSecurityPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
@@ -117,16 +123,20 @@
}
catch (SQLException e)
{
- report.logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
+ logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
}
catch (NamingException e)
{
- report.logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
+ logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
}
catch (RepositoryConfigurationException e)
{
- report.logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
+ logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
}
+ catch (RepositoryException e)
+ {
+ logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
+ }
finally
{
JDBCUtils.freeResources(resultSet, preparedStatement, jdbcConnection);
@@ -187,132 +197,17 @@
* <p>
* Check that database is not broken, and all base relation between jcr-items are not corrupted.
* </p>
- *
- * @param inspectionLog - log where inspection results will be placed
- * @return InspectionLog
- * @throws RepositoryException
- * @throws IOException
*/
- public void checkDataBase()
- throws RepositoryException, IOException
+ public void checkDataBase(boolean autoRepair)
{
SecurityHelper.validateSecurityPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
- Set<InspectionQuery> queries = new HashSet<InspectionQuery>();
-
- // preload queries
- queries.add(new InspectionQuery(jdbcDataContainer.multiDb
- ? "select * from JCR_MITEM I where NOT EXISTS(select * from JCR_MITEM P where P.ID = I.PARENT_ID)"
- : "select * from JCR_SITEM I where I.CONTAINER_NAME='" + jdbcDataContainer.containerName
- + "' and NOT EXISTS(select * from JCR_SITEM P where P.ID = I.PARENT_ID)", new String[]{
- DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME, DBConstants.COLUMN_CLASS},
- "Items that do not have parent nodes"));
-
- queries.add(new InspectionQuery(jdbcDataContainer.multiDb
- ? "select * from JCR_MITEM N where N.I_CLASS=1 and NOT EXISTS "
- + "(select * from JCR_MITEM P where P.I_CLASS=2 and P.PARENT_ID=N.ID "
- + "and P.NAME='[http://www.jcp.org/jcr/1.0]primaryType')"
- : "select * from JCR_SITEM N where N.CONTAINER_NAME='" + jdbcDataContainer.containerName
- + "' and N.I_CLASS=1 and NOT EXISTS (select * from JCR_SITEM P "
- + "where P.I_CLASS=2 and P.PARENT_ID=N.ID and P.NAME='[http://www.jcp.org/jcr/1.0]primaryType' "
- + "and P.CONTAINER_NAME='" + jdbcDataContainer.containerName + "')", new String[]{DBConstants.COLUMN_ID,
- DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME},
- "Nodes that do not have at least one jcr:primaryType property"));
-
- queries.add(new InspectionQuery(jdbcDataContainer.multiDb
- ? "select * from JCR_MVALUE V where NOT EXISTS(select * from JCR_MITEM P "
- + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)"
- : "select * from JCR_SVALUE V where NOT EXISTS(select * from JCR_SITEM P "
- + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)", new String[]{DBConstants.COLUMN_ID,
- DBConstants.COLUMN_VPROPERTY_ID}, "All value records that has not owner-property record"));
-
- queries
- .add(new InspectionQueryFilteredMultivaluedProperties(
- jdbcDataContainer.multiDb
- ? "select * from JCR_MITEM P where P.I_CLASS=2 and P.P_MULTIVALUED=? and NOT EXISTS( select * from JCR_MVALUE V "
- + "where V.PROPERTY_ID=P.ID)"
- : "select * from JCR_SITEM P where P.CONTAINER_NAME='"
- + jdbcDataContainer.containerName
- + "' and P.I_CLASS=2 and P.P_MULTIVALUED=? and NOT EXISTS( select * from JCR_SVALUE V where V.PROPERTY_ID=P.ID)",
- new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME},
- "All properties that have not value record."));
-
- // The differences in the queries by DB dialect.
- // Oracle doesn't work correct with default query because empty value stored as null value.
- String statement;
- if (jdbcDataContainer.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE))
- {
- statement =
- jdbcDataContainer.multiDb
- ? "select * from JCR_MVALUE where (STORAGE_DESC is null and DATA like null) or "
- + "(STORAGE_DESC is not null and not DATA like null)"
- : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
- + jdbcDataContainer.containerName
- + "' AND ((STORAGE_DESC is null and DATA like null) or (STORAGE_DESC is not null and not DATA like null))";
- }
- else if (jdbcDataContainer.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLE)
- || jdbcDataContainer.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLEOCI))
- {
- statement =
- jdbcDataContainer.multiDb
- ? "select * from JCR_MVALUE where (STORAGE_DESC is not null and DATA is not null)"
- : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
- + jdbcDataContainer.containerName + "' AND (STORAGE_DESC is not null and DATA is not null)";
- }
- else
- {
- statement =
- jdbcDataContainer.multiDb
- ? "select * from JCR_MVALUE where (STORAGE_DESC is null and DATA is null) or "
- + "(STORAGE_DESC is not null and DATA is not null)"
- : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
- + jdbcDataContainer.containerName
- + "' AND ((STORAGE_DESC is null and DATA is null) or (STORAGE_DESC is not null and DATA is not null))";
- }
- queries.add(new InspectionQuery(statement, new String[]{DBConstants.COLUMN_ID}, "Incorrect JCR_VALUE records"));
-
- queries
- .add(new InspectionQueryFilteredMultivaluedProperties(
- jdbcDataContainer.multiDb
- ? "select * from JCR_MITEM P where P.P_TYPE=9 and P.P_MULTIVALUED=? and NOT EXISTS "
- + "(select * from JCR_MREF R where P.ID=R.PROPERTY_ID)"
- : "select * from JCR_SITEM P where P.CONTAINER_NAME='"
- + jdbcDataContainer.containerName
- + "' and P.P_TYPE=9 and P.P_MULTIVALUED=? and NOT EXISTS( select * from JCR_SREF R where P.ID=R.PROPERTY_ID)",
- new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME},
- "Reference properties without reference records"));
-
- // an item is its own parent.
- queries.add(new InspectionQuery(jdbcDataContainer.multiDb
- ? "select * from JCR_MITEM I where I.ID = I.PARENT_ID and I.NAME <> '" + Constants.ROOT_PARENT_NAME + "'"
- : "select * from JCR_SITEM I where I.ID = I.PARENT_ID and I.CONTAINER_NAME='"
- + jdbcDataContainer.containerName + "' and I.NAME <> '" + Constants.ROOT_PARENT_NAME + "'", new String[]{
- DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME}, "An item is its own parent."));
-
- // Several versions of same item
- queries
- .add(new InspectionQuery(
- jdbcDataContainer.multiDb
- ? "select * from JCR_MITEM I where EXISTS (select * from JCR_MITEM J"
- + " WHERE I.PARENT_ID = J.PARENT_ID AND I.NAME = J.NAME and I.I_INDEX = J.I_INDEX and I.I_CLASS = J.I_CLASS"
- + " and I.VERSION != J.VERSION)"
- : "select * from JCR_SITEM I where I.CONTAINER_NAME='"
- + jdbcDataContainer.containerName
- + "' and"
- + " EXISTS (select * from JCR_SITEM J WHERE I.CONTAINER_NAME = J.CONTAINER_NAME and"
- + " I.PARENT_ID = J.PARENT_ID AND I.NAME = J.NAME and I.I_INDEX = J.I_INDEX and I.I_CLASS = J.I_CLASS"
- + " and I.VERSION != J.VERSION)",
- new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME,
- DBConstants.COLUMN_VERSION, DBConstants.COLUMN_CLASS, DBConstants.COLUMN_INDEX},
- "Several versions of same item."));
-
- // using existing DataSource to get a JDBC Connection.
- Connection jdbcConn = jdbcDataContainer.getConnectionFactory().getJdbcConnection();
-
+ Connection jdbcConn = null;
try
{
- // perform all queries on-by-one
- for (InspectionQuery query : queries)
+ jdbcConn = jdbcDataContainer.getConnectionFactory().getJdbcConnection();
+
+ for (InspectionQuery query : itemsInspectionQuery)
{
PreparedStatement st = null;
ResultSet resultSet = null;
@@ -320,32 +215,18 @@
{
st = query.prepareStatement(jdbcConn);
- // the result of query is expected to be empty
resultSet = st.executeQuery();
if (resultSet.next())
{
- // but if result not empty, then inconsistency takes place
- report.logDescription(query.getDescription());
+ logDescription(query.getDescription());
do
{
- StringBuilder record = new StringBuilder();
- for (String fieldName : query.getFieldNames())
+ logBrokenObjectAndSetInconsistency(getBrokenObject(resultSet, query.getFieldNames()));
+ if (autoRepair)
{
- record.append(fieldName);
- record.append('=');
- if (fieldName.equals(DBConstants.COLUMN_NORDERNUM)
- || fieldName.equals(DBConstants.COLUMN_VORDERNUM))
- {
- record.append(resultSet.getInt(fieldName));
- }
- else
- {
- record.append(resultSet.getString(fieldName));
- }
- record.append(' ');
+ query.getRepair().doRepair(resultSet);
+ logComment("Inconsistency has been fixed");
}
-
- report.logBrokenObjectAndSetInconsistency(record.toString());
}
while (resultSet.next());
}
@@ -358,8 +239,12 @@
}
catch (SQLException e)
{
- report.logExceptionAndSetInconsistency("Exception during DB inspection.", e);
+ logExceptionAndSetInconsistency("Unexpected exception during DB checking.", e);
}
+ catch (RepositoryException e)
+ {
+ logExceptionAndSetInconsistency("Unexpected exception during DB checking.", e);
+ }
finally
{
JDBCUtils.freeResources(null, null, jdbcConn);
@@ -548,29 +433,121 @@
private void initInspectionQueries()
{
- String singleDbQuery =
- "SELECT V.PROPERTY_ID, V.ORDER_NUM, V.STORAGE_DESC from JCR_SVALUE V, JCR_SITEM I"
- + " where I.CONTAINER_NAME='" + jdbcDataContainer.containerName
- + "' and V.PROPERTY_ID = I.ID and STORAGE_DESC is not null";
- String multiDbQuery =
- "SELECT PROPERTY_ID, ORDER_NUM, STORAGE_DESC from JCR_MVALUE where STORAGE_DESC is not null";
-
vsInspectionQuery =
- new InspectionQuery(jdbcDataContainer.multiDb ? multiDbQuery : singleDbQuery, new String[]{
- DBConstants.COLUMN_VPROPERTY_ID, DBConstants.COLUMN_VORDERNUM, DBConstants.COLUMN_VSTORAGE_DESC},
- "Items with value data stored in value storage");
+ new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select PROPERTY_ID, ORDER_NUM, STORAGE_DESC from JCR_MVALUE where STORAGE_DESC is not null"
+ : "select V.PROPERTY_ID, V.ORDER_NUM, V.STORAGE_DESC from JCR_SVALUE V, JCR_SITEM I"
+ + " where I.CONTAINER_NAME='" + jdbcDataContainer.containerName
+ + "' and V.PROPERTY_ID = I.ID and STORAGE_DESC is not null",
+ new String[]{DBConstants.COLUMN_VPROPERTY_ID, DBConstants.COLUMN_VORDERNUM,
+ DBConstants.COLUMN_VSTORAGE_DESC}, "Items with value data stored in value storage", new DummyRepair());
- singleDbQuery =
- "SELECT DISTINCT PARENT_ID from JCR_MITEM WHERE I_CLASS=2 "
- + "AND (NAME='[http://www.jcp.org/jcr/1.0]lockOwner' OR NAME='[http://www.jcp.org/jcr/1.0]lockIsDeep')";
+ lockInspectionQuery =
+ new InspectionQuery(jdbcDataContainer.multiDb ? "select distinct PARENT_ID from JCR_MITEM where I_CLASS=2 AND"
+ + " (NAME='[http://www.jcp.org/jcr/1.0]lockOwner' OR NAME='[http://www.jcp.org/jcr/1.0]lockIsDeep')"
+ : "select distinct PARENT_ID from JCR_SITEM WHERE CONTAINER_NAME='" + jdbcDataContainer.containerName + "'"
+ + " AND I_CLASS=2 and (NAME='[http://www.jcp.org/jcr/1.0]lockOwner'"
+ + " OR NAME='[http://www.jcp.org/jcr/1.0]lockIsDeep')", new String[]{DBConstants.COLUMN_PARENTID},
+ "Items which have jcr:lockOwner and jcr:lockIsDeep properties", new DummyRepair());
- multiDbQuery =
- "SELECT DISTINCT PARENT_ID from JCR_SITEM WHERE CONTAINER_NAME='"
- + jdbcDataContainer.containerName
- + "' AND I_CLASS=2 and (NAME='[http://www.jcp.org/jcr/1.0]lockOwner' OR NAME='[http://www.jcp.org/jcr/1.0]lockIsDeep')";
+ // ITEM tables
+ itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select * from JCR_MITEM I where NOT EXISTS(select * from JCR_MITEM P where P.ID = I.PARENT_ID)"
+ : "select * from JCR_SITEM I where I.CONTAINER_NAME='" + jdbcDataContainer.containerName
+ + "' and NOT EXISTS(select * from JCR_SITEM P where P.ID = I.PARENT_ID)", new String[]{
+ DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME, DBConstants.COLUMN_CLASS},
+ "Items that do not have parent nodes", new AssignRootAsParentRepair(jdbcDataContainer
+ .getConnectionFactory())));
- lockInspectionQuery =
- new InspectionQuery(jdbcDataContainer.multiDb ? singleDbQuery : multiDbQuery,
- new String[]{DBConstants.COLUMN_PARENTID}, "Items which have jcr:lockOwner and jcr:lockIsDeep properties");
+ itemsInspectionQuery
+ .add(new InspectionQueryFilteredMultivaluedProperties(
+ jdbcDataContainer.multiDb
+ ? "select * from JCR_MITEM P where P.I_CLASS=2 and P.P_MULTIVALUED=? and NOT EXISTS( select * from JCR_MVALUE V "
+ + "where V.PROPERTY_ID=P.ID)" : "select * from JCR_SITEM P where P.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName + "' and P.I_CLASS=2"
+ + " and P.P_MULTIVALUED=? and NOT EXISTS( select * from JCR_SVALUE V where V.PROPERTY_ID=P.ID)",
+ new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME},
+ "A node that has a single valued properties with nothing declared in the VALUE table.", new DummyRepair()));
+
+ itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select * from JCR_MITEM N where N.I_CLASS=1 and NOT EXISTS "
+ + "(select * from JCR_MITEM P where P.I_CLASS=2 and P.PARENT_ID=N.ID "
+ + "and P.NAME='[http://www.jcp.org/jcr/1.0]primaryType')"
+ : "select * from JCR_SITEM N where N.CONTAINER_NAME='" + jdbcDataContainer.containerName
+ + "' and N.I_CLASS=1 and NOT EXISTS (select * from JCR_SITEM P "
+ + "where P.I_CLASS=2 and P.PARENT_ID=N.ID and P.NAME='[http://www.jcp.org/jcr/1.0]primaryType' "
+ + "and P.CONTAINER_NAME='" + jdbcDataContainer.containerName + "')", new String[]{DBConstants.COLUMN_ID,
+ DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME}, "A node that doesn't have primary type property",
+ new DummyRepair()));
+
+ itemsInspectionQuery
+ .add(new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select * from JCR_MVALUE V where NOT EXISTS(select * from JCR_MITEM P "
+ + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)"
+ : "select * from JCR_SVALUE V where NOT EXISTS(select * from JCR_SITEM P "
+ + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)", new String[]{DBConstants.COLUMN_ID,
+ DBConstants.COLUMN_VPROPERTY_ID}, "All value records that has not related property record",
+ new DummyRepair()));
+
+ // The differences in the queries by DB dialect.
+ String statement;
+ if (jdbcDataContainer.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE))
+ {
+ statement =
+ jdbcDataContainer.multiDb
+ ? "select * from JCR_MVALUE where (STORAGE_DESC is not null and not DATA like null)"
+ : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName + "' AND ((STORAGE_DESC is not null and not DATA like null))";
+ }
+ else if (jdbcDataContainer.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLE)
+ || jdbcDataContainer.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLEOCI))
+ {
+ statement =
+ jdbcDataContainer.multiDb
+ ? "select * from JCR_MVALUE where (STORAGE_DESC is not null and DATA is not null)"
+ : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName + "' AND (STORAGE_DESC is not null and DATA is not null)";
+ }
+ else
+ {
+ statement =
+ jdbcDataContainer.multiDb
+ ? "select * from JCR_MVALUE where (STORAGE_DESC is not null and DATA is not null)"
+ : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName + "' AND ((STORAGE_DESC is not null and DATA is not null))";
+ }
+ itemsInspectionQuery.add(new InspectionQuery(statement, new String[]{DBConstants.COLUMN_ID},
+ "Incorrect VALUE records. Both fields STORAGE_DESC and DATA contain not null value.", new DummyRepair()));
+
+ itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select * from JCR_MITEM I where I.ID = I.PARENT_ID and I.NAME <> '" + Constants.ROOT_PARENT_NAME + "'"
+ : "select * from JCR_SITEM I where I.ID = I.PARENT_ID and I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName + "' and I.NAME <> '" + Constants.ROOT_PARENT_NAME + "'", new String[]{
+ DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME}, "An item is its own parent.",
+ new AssignRootAsParentRepair(jdbcDataContainer.getConnectionFactory())));
+
+ itemsInspectionQuery
+ .add(new InspectionQuery(
+ jdbcDataContainer.multiDb
+ ? "select * from JCR_MITEM I where EXISTS (select * from JCR_MITEM J"
+ + " WHERE I.PARENT_ID = J.PARENT_ID AND I.NAME = J.NAME and I.I_INDEX = J.I_INDEX and I.I_CLASS = J.I_CLASS"
+ + " and I.VERSION != J.VERSION)"
+ : "select * from JCR_SITEM I where I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName
+ + "' and EXISTS (select * from JCR_SITEM J WHERE I.CONTAINER_NAME = J.CONTAINER_NAME and"
+ + " I.PARENT_ID = J.PARENT_ID AND I.NAME = J.NAME and I.I_INDEX = J.I_INDEX and I.I_CLASS = J.I_CLASS"
+ + " and I.VERSION != J.VERSION)",
+ new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME,
+ DBConstants.COLUMN_VERSION, DBConstants.COLUMN_CLASS, DBConstants.COLUMN_INDEX},
+ "Several versions of same item.", new DummyRepair()));
+
+ itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
+ ? "select * from JCR_MITEM P, JCR_MVALUE V where P.ID=V.PROPERTY_ID and P.P_TYPE=9 and NOT EXISTS "
+ + "(select * from JCR_MREF R where P.ID=R.PROPERTY_ID)"
+ : "select * from JCR_SITEM P, JCR_SVALUE V where P.ID=V.PROPERTY_ID and P.CONTAINER_NAME='"
+ + jdbcDataContainer.containerName
+ + "' and P.P_TYPE=9 and NOT EXISTS (select * from JCR_SREF R where P.ID=R.PROPERTY_ID)", new String[]{
+ DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME},
+ "Reference properties without reference records", new DummyRepair()));
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java 2012-02-29 08:24:57 UTC (rev 5709)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java 2012-02-29 11:24:32 UTC (rev 5710)
@@ -500,6 +500,7 @@
public void testDBUsecasesTheParentIdIsIdOfThisNodeSingleDB() throws Exception
{
checkDBUsecasesTheParentIdIsIdOfThisNode(helper.createRepository(container, false, false));
+ checkDBUsecasesTheParentIdIsIdOfThisNode2(helper.createRepository(container, false, false));
}
/**
@@ -508,6 +509,7 @@
public void testDBUsecasesTheParentIdIsIdOfThisNodeMultiDB() throws Exception
{
checkDBUsecasesTheParentIdIsIdOfThisNode(helper.createRepository(container, true, false));
+ checkDBUsecasesTheParentIdIsIdOfThisNode2(helper.createRepository(container, true, false));
}
private void checkDBUsecasesTheParentIdIsIdOfThisNode(ManageableRepository repository) throws Exception
@@ -544,12 +546,52 @@
conn.commit();
conn.close();
- // repository is inconsistent
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ checkController.repairDataBase("yes");
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+
}
+ private void checkDBUsecasesTheParentIdIsIdOfThisNode2(ManageableRepository repository) throws Exception
+ {
+ // create repository and add property
+ SessionImpl session =
+ (SessionImpl)repository.login(credentials, repository.getConfiguration().getSystemWorkspaceName());
+ NodeImpl node = (NodeImpl)session.getRootNode().addNode("testNode");
+ PropertyImpl prop = (PropertyImpl)node.setProperty("prop", "test");
+ session.save();
+ session.logout();
+
+ // repository is consistent
+ TesterRepositoryCheckController checkController = new TesterRepositoryCheckController(repository);
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+
+ WorkspaceEntry wsEntry = repository.getConfiguration().getWorkspaceEntries().get(0);
+ boolean isMultiDb = wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
+
+ // change ITEM table
+ String sourceName = wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
+
+ Connection conn = ((DataSource)new InitialContext().lookup(sourceName)).getConnection();
+
+ conn.prepareStatement("DROP INDEX JCR_IDX_" + (isMultiDb ? "M" : "S") + "ITEM_PARENT").execute();
+ conn.prepareStatement("DROP INDEX JCR_IDX_" + (isMultiDb ? "M" : "S") + "ITEM_PARENT_NAME").execute();
+ conn.prepareStatement(
+ "UPDATE JCR_" + (isMultiDb ? "M" : "S") + "ITEM SET PARENT_ID = '" + (isMultiDb ? "" : wsEntry.getName())
+ + prop.getInternalIdentifier() + "' WHERE ID='" + (isMultiDb ? "" : wsEntry.getName())
+ + prop.getInternalIdentifier() + "'").execute();
+
+ conn.commit();
+ conn.close();
+
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+
+ checkController.repairDataBase("yes");
+ assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+
+ }
+
/**
* Usecase: property doens't have have parent node.
*/
@@ -681,7 +723,6 @@
public void testDBUsecasesIncorrectValueRecordsSingleDB() throws Exception
{
checkDBUsecasesIncorrectValueRecords(helper.createRepository(container, false, false));
- checkDBUsecasesIncorrectValueRecords2(helper.createRepository(container, false, false));
}
/**
@@ -690,7 +731,6 @@
public void testDBUsecasesIncorrectValueRecordsMultiDB() throws Exception
{
checkDBUsecasesIncorrectValueRecords(helper.createRepository(container, true, false));
- checkDBUsecasesIncorrectValueRecords2(helper.createRepository(container, true, false));
}
private void checkDBUsecasesIncorrectValueRecords(ManageableRepository repository) throws Exception
@@ -728,41 +768,6 @@
}
- private void checkDBUsecasesIncorrectValueRecords2(ManageableRepository repository) throws Exception
- {
- // create repository and add property
- SessionImpl session =
- (SessionImpl)repository.login(credentials, repository.getConfiguration().getSystemWorkspaceName());
- PropertyImpl prop = (PropertyImpl)session.getRootNode().addNode("testNode").setProperty("prop", "test");
- session.save();
- session.logout();
-
- // repository is consistent
- TesterRepositoryCheckController checkController = new TesterRepositoryCheckController(repository);
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
-
-
- WorkspaceEntry wsEntry = repository.getConfiguration().getWorkspaceEntries().get(0);
- boolean isMultiDb = wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
-
- // change VALUE table
- String sourceName = wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
-
- Connection conn = ((DataSource)new InitialContext().lookup(sourceName)).getConnection();
- conn.prepareStatement(
- "UPDATE JCR_" + (isMultiDb ? "M" : "S") + "VALUE SET DATA = NULL WHERE PROPERTY_ID = '"
- + (isMultiDb ? "" : wsEntry.getName()) + prop.getInternalIdentifier() + "'").execute();
-
- conn.commit();
- conn.close();
-
- // repository is inconsistent
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
-
- }
-
/**
* Usecase: value records has no item record.
*/
12 years, 1 month
exo-jcr SVN: r5709 - jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker.
by do-not-reply@jboss.org
Author: tolusha
Date: 2012-02-29 03:24:57 -0500 (Wed, 29 Feb 2012)
New Revision: 5709
Added:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQuery.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQueryFilteredMultivaluedProperties.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionReport.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java
Log:
EXOJCR-1762: auto-repair for VS and Lock inconsistency
Added: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQuery.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQuery.java (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQuery.java 2012-02-29 08:24:57 UTC (rev 5709)
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+/**
+ * @author <a href="mailto:aplotnikov@exoplatform.com">Andrey Plotnikov</a>
+ * @version $Id: InspectionQuery.java 34360 16.02.2012 andrew.plotnikov $
+ */
+public class InspectionQuery
+{
+ /**
+ * SQL query that must be executed.
+ */
+ public String statement;
+
+ /**
+ * Inspection query description.
+ */
+ public String description;
+
+ /**
+ * Field names that must be showed in inspection log if something wrong.
+ */
+ public String[] fieldNames;
+
+ /**
+ * Data class, contains a combination of SQL states, description, field names and status
+ */
+ public InspectionQuery(String statement, String[] fieldNames, String headerMessage)
+ {
+ this.statement = statement;
+ this.description = headerMessage;
+ this.fieldNames = fieldNames;
+ }
+
+ public String getStatement()
+ {
+ return statement;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public String[] getFieldNames()
+ {
+ return fieldNames;
+ }
+
+ /**
+ * Creates a PreparedStatement object for sending parameterized SQL statements to the database.
+ *
+ * @param connection
+ * connection to workspace storage
+ * @return
+ * a new default PreparedStatement object containing the pre-compiled SQL statement
+ * @throws SQLException
+ * if a database access error occurs or this method is called on a closed connection
+ */
+ public PreparedStatement prepareStatement(Connection connection) throws SQLException
+ {
+ return connection.prepareStatement(statement);
+ }
+
+}
Added: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQueryFilteredMultivaluedProperties.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQueryFilteredMultivaluedProperties.java (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionQueryFilteredMultivaluedProperties.java 2012-02-29 08:24:57 UTC (rev 5709)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+/**
+ * @author <a href="mailto:aplotnikov@exoplatform.com">Andrey Plotnikov</a>
+ * @version $Id: InspectionQueryFilteredMultivaluedProperties.java 34360 16.02.2012 andrew.plotnikov $
+ */
+public class InspectionQueryFilteredMultivaluedProperties extends InspectionQuery
+{
+
+ /**
+ * {@inheritDoc}
+ */
+ public InspectionQueryFilteredMultivaluedProperties(String statement, String[] fieldNames, String headerMessage)
+ {
+ super(statement, fieldNames, headerMessage);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PreparedStatement prepareStatement(Connection connection) throws SQLException
+ {
+ PreparedStatement preparedStatement = super.prepareStatement(connection);
+ preparedStatement.setBoolean(1, false);
+
+ return preparedStatement;
+ }
+
+}
Added: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionReport.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionReport.java (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InspectionReport.java 2012-02-29 08:24:57 UTC (rev 5709)
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import org.exoplatform.commons.utils.SecurityHelper;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.security.PrivilegedExceptionAction;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Text-based inspection log implementation.
+ *
+ * @author <a href="mailto:skarpenko@exoplatform.com">Sergiy Karpenko</a>
+ * @version $Id: InspectionReport.java 34360 6.10.2011 skarpenko $
+ */
+public class InspectionReport
+{
+ private static final String COMMENT = "//";
+
+ private static final String DELIMITER = "\n";
+
+ private static final String WHITE_SPACE = " ";
+
+ private Writer writer;
+
+ private boolean reportHasInconsistency;
+
+ private String reportPath;
+
+ /**
+ * InspectionReport constructor.
+ */
+ public InspectionReport(String forRepository) throws IOException
+ {
+ final File reportFile =
+ new File("report-" + forRepository + "-" + new SimpleDateFormat("dd-MMM-yy-HH-mm").format(new Date()) + ".txt");
+
+ SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
+ {
+ public Void run() throws IOException
+ {
+ reportPath = reportFile.getAbsolutePath();
+ writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(reportFile)));
+
+ return null;
+ }
+ });
+
+ }
+
+ /**
+ * Indicates if report has inconsistency info or not.
+ */
+ public boolean hasInconsistency()
+ {
+ return reportHasInconsistency;
+ }
+
+ /**
+ * Adds comment to log.
+ */
+ public void logComment(String message) throws IOException
+ {
+ writeLine(message);
+ writer.flush();
+ }
+
+ /**
+ * Adds description to log.
+ */
+ public void logDescription(String description) throws IOException
+ {
+ writeLine(description);
+ writer.flush();
+ }
+
+ /**
+ * Adds detailed event to log.
+ */
+ public void logBrokenObjectAndSetInconsistency(String brokenObject) throws IOException
+ {
+ setInconsistency();
+
+ writer.write(brokenObject);
+ writer.write(DELIMITER);
+ writer.flush();
+ }
+
+ /**
+ * Adds exception with full stack trace.
+ */
+ public void logExceptionAndSetInconsistency(String message, Throwable e) throws IOException
+ {
+ setInconsistency();
+
+ writeLine(message);
+ writeStackTrace(e);
+ writer.flush();
+ }
+
+ /**
+ * Closes report and frees all allocated resources.
+ */
+ public void close() throws IOException
+ {
+ writer.close();
+ }
+
+ /**
+ * Returns the absolute path to report file.
+ */
+ public String getReportPath()
+ {
+ return reportPath;
+ }
+
+ private void setInconsistency()
+ {
+ reportHasInconsistency = true;
+ }
+
+ private void writeLine(String message) throws IOException
+ {
+ writer.write(COMMENT);
+ writer.write(message);
+ writer.write(DELIMITER);
+ writer.flush();
+ }
+
+ private void writeStackTrace(Throwable e) throws IOException
+ {
+ writeLine(e.getMessage());
+ writeLine(e.toString());
+ StackTraceElement[] trace = e.getStackTrace();
+ for (int i = 0; i < trace.length; i++)
+ {
+ writeLine("\tat " + trace[i]);
+ }
+
+ Throwable ourCause = e.getCause();
+ if (ourCause != null)
+ {
+ writeLine("Cause:");
+ writeStackTrace(ourCause);
+ }
+ }
+}
Added: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java 2012-02-29 08:24:57 UTC (rev 5709)
@@ -0,0 +1,385 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.checker;
+
+import org.exoplatform.commons.utils.SecurityHelper;
+import org.exoplatform.management.annotations.Managed;
+import org.exoplatform.management.annotations.ManagedDescription;
+import org.exoplatform.management.annotations.ManagedName;
+import org.exoplatform.management.jmx.annotations.NameTemplate;
+import org.exoplatform.management.jmx.annotations.Property;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.impl.AbstractRepositorySuspender;
+import org.exoplatform.services.jcr.impl.core.query.SearchManager;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainerChecker;
+import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.picocontainer.Startable;
+
+import java.io.IOException;
+import java.security.PrivilegedAction;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Repository check controller allows check jcr repository consistency:
+ * <ul>
+ * <li>Check DB consistency</li>
+ * <li>Check value storage</li>
+ * <li>Check index</li>
+ * </ul>
+ *
+ * @author <a href="mailto:skarpenko@exoplatform.com">Sergiy Karpenko</a>
+ * @version $Id: RepositoryCheckController.java 34360 3.10.2011 skarpenko $
+ */
+@Managed
+@NameTemplate(@Property(key = "service", value = "RepositoryCheckController"))
+public class RepositoryCheckController extends AbstractRepositorySuspender implements Startable
+{
+ /**
+ * Logger.
+ */
+ protected static Log LOG = ExoLogger.getLogger("exo.jcr.component.core.RepositoryCheckController");
+
+ public static final String REPORT_CONSISTENT_MESSAGE = "Repository data is consistent";
+
+ public static final String REPORT_NOT_CONSISTENT_MESSAGE = "Repository data is NOT consistent";
+
+ public static final String EXCEPTION_DURING_CHECKING_MESSAGE = "Exception occured during consistency checking";
+
+ public static final String CONFIRMATION_FAILED_MESSAGE =
+ "For starting auto-repair function please enter \"YES\" as method parameter";
+
+ /**
+ * The list of available storages for checking.
+ */
+ public enum DataStorage {
+ DB, VALUE_STORAGE, LUCENE_INDEX
+ };
+
+ /**
+ * Store the results of last checking.
+ */
+ protected InspectionReport lastReport;
+
+ /**
+ * RepositoryCheckController constructor.
+ */
+ public RepositoryCheckController(ManageableRepository repository)
+ {
+ super(repository);
+ }
+
+ /**
+ * This method will make next steps:
+ * <ul>
+ * <li>Suspend repository</li>
+ * <li>Check DB consistency</li>
+ * <li>Check value storage</li>
+ * <li>Check index</li>
+ * <li>Resume repository</li>
+ * </ul>
+ *
+ * @return String check consistency report
+ */
+ @Managed
+ @ManagedDescription("Check repository data consistency. DB data, value storage and lucene index will be checked.")
+ public String checkAll()
+ {
+ return checkAndRepair(new DataStorage[]{DataStorage.DB, DataStorage.VALUE_STORAGE,
+ DataStorage.LUCENE_INDEX}, false);
+ }
+
+ @Managed
+ @ManagedDescription("Check repository database consistency.")
+ public String checkDataBase()
+ {
+ return checkAndRepair(new DataStorage[]{DataStorage.DB}, false);
+ }
+
+ @Managed
+ @ManagedDescription("Check repository value storage consistency.")
+ public String checkValueStorage()
+ {
+ return checkAndRepair(new DataStorage[]{DataStorage.VALUE_STORAGE}, false);
+ }
+
+ @Managed
+ @ManagedDescription("Check repository search index consistency.")
+ public String checkIndex()
+ {
+ return checkAndRepair(new DataStorage[]{DataStorage.LUCENE_INDEX}, false);
+ }
+
+ @Managed
+ @ManagedDescription("Auto-repair inconsistencies for value storage. "
+ + "Don't forget to backup your data first. Set parameter to \"YES\" for enabling auto-repair feature")
+ public String repairValueStorage(String confirmation)
+ {
+ if (confirmation.equalsIgnoreCase("YES"))
+ {
+ return checkAndRepair(new DataStorage[]{DataStorage.VALUE_STORAGE}, true);
+ }
+ else
+ {
+ return CONFIRMATION_FAILED_MESSAGE;
+ }
+ }
+
+ @Managed
+ @ManagedDescription("Auto-repair inconsistencies for database. "
+ + "Don't forget to backup your data first. Set parameter to \"YES\" for enabling auto-repair feature")
+ public String repairDataBase(String confirmation)
+ {
+ if (confirmation.equalsIgnoreCase("YES"))
+ {
+ return checkAndRepair(new DataStorage[]{DataStorage.DB}, true);
+ }
+ else
+ {
+ return CONFIRMATION_FAILED_MESSAGE;
+ }
+ }
+
+ public String checkAndRepair(final DataStorage[] storages, final boolean autoRepair)
+ {
+ return SecurityHelper.doPrivilegedAction(new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return checkAndRepairAction(storages, autoRepair);
+ }
+ });
+ }
+
+ protected String checkAndRepairAction(DataStorage[] storages, boolean autoRepair)
+ {
+ try
+ {
+ createNewReport();
+ }
+ catch (IOException e)
+ {
+ return getExceptionDuringCheckingMessage(e);
+ }
+
+ try
+ {
+ suspendRepository();
+
+ return doCheckAndRepair(storages, autoRepair);
+ }
+ catch (RepositoryException e)
+ {
+ return getExceptionDuringCheckingMessage(e);
+ }
+ finally
+ {
+ resumeRepository();
+ closeReport();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void resumeRepository()
+ {
+ try
+ {
+ super.resumeRepository();
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error("Can not resume repository. Error: " + e.getMessage(), e);
+ }
+ }
+
+ private String doCheckAndRepair(DataStorage[] storages, boolean autoRepair)
+ {
+ try
+ {
+ for (DataStorage storage : storages)
+ {
+ switch (storage)
+ {
+ case DB :
+ doCheckDataBase(autoRepair);
+ break;
+
+ case VALUE_STORAGE :
+ doCheckValueStorage(autoRepair);
+ break;
+
+ case LUCENE_INDEX :
+ doCheckIndex(autoRepair);
+ break;
+ }
+ }
+
+ return logAndGetCheckingResultMessage();
+ }
+ catch (Throwable e)
+ {
+ return logAndGetExceptionDuringCheckingMessage(e);
+ }
+ }
+
+ private String logAndGetCheckingResultMessage()
+ {
+ if (lastReport.hasInconsistency())
+ {
+ logComment(REPORT_NOT_CONSISTENT_MESSAGE);
+ return REPORT_NOT_CONSISTENT_MESSAGE + getPathToReportMessage();
+ }
+ else
+ {
+ logComment(REPORT_CONSISTENT_MESSAGE);
+ return REPORT_CONSISTENT_MESSAGE + getPathToReportMessage();
+ }
+ }
+
+ private String logAndGetExceptionDuringCheckingMessage(Throwable e)
+ {
+ logExceptionAndSetInconsistency(EXCEPTION_DURING_CHECKING_MESSAGE, e);
+ return getExceptionDuringCheckingMessage(e) + getPathToReportMessage();
+ }
+
+ private String getExceptionDuringCheckingMessage(Throwable e)
+ {
+ return EXCEPTION_DURING_CHECKING_MESSAGE + ": " + e.getMessage();
+ }
+
+ private void logComment(String message)
+ {
+ try
+ {
+ lastReport.logComment(message);
+ }
+ catch (IOException e)
+ {
+ LOG.error(e.getMessage(), e);
+ }
+ }
+
+ private void logExceptionAndSetInconsistency(String message, Throwable e)
+ {
+ try
+ {
+ lastReport.logExceptionAndSetInconsistency(message, e);
+ }
+ catch (IOException e1)
+ {
+ LOG.error(e1.getMessage(), e1);
+ }
+ }
+
+ private void createNewReport() throws IOException
+ {
+ lastReport = new InspectionReport(repository.getConfiguration().getName());
+ }
+
+ private void closeReport()
+ {
+ try
+ {
+ lastReport.close();
+ }
+ catch (IOException e)
+ {
+ LOG.error(e.getMessage(), e);
+ }
+ }
+
+ private void doCheckDataBase(boolean autoRepair) throws RepositoryException, IOException,
+ RepositoryConfigurationException
+ {
+ for (String wsName : repository.getWorkspaceNames())
+ {
+ logComment("Check DB consistency. Workspace " + wsName);
+
+ JDBCWorkspaceDataContainerChecker jdbcChecker = getJDBCChecker(wsName);
+ jdbcChecker.checkDataBase();
+ jdbcChecker.checkLocksInDataBase(autoRepair);
+ }
+ }
+
+ private void doCheckValueStorage(boolean autoRepair)
+ {
+ for (String wsName : repository.getWorkspaceNames())
+ {
+ logComment("Check ValueStorage consistency. Workspace " + wsName);
+ getJDBCChecker(wsName).checkValueStorage(autoRepair);
+ }
+ }
+
+ private void doCheckIndex(boolean autoRepair) throws RepositoryException, IOException
+ {
+ final String systemWS = repository.getConfiguration().getSystemWorkspaceName();
+ for (String wsName : repository.getWorkspaceNames())
+ {
+ logComment("Check SearchIndex consistency. Workspace " + wsName);
+
+ SearchManager searchManager = (SearchManager)getComponent(SearchManager.class, wsName);
+
+ searchManager.checkIndex(lastReport, systemWS.equals(wsName));
+ }
+ }
+
+ private JDBCWorkspaceDataContainerChecker getJDBCChecker(String wsName)
+ {
+ JDBCWorkspaceDataContainer dataContainer =
+ (JDBCWorkspaceDataContainer)getComponent(JDBCWorkspaceDataContainer.class, wsName);
+
+ ValueStoragePluginProvider vsPlugin =
+ (ValueStoragePluginProvider)getComponent(ValueStoragePluginProvider.class, wsName);
+
+ WorkspaceEntry wsEntry = (WorkspaceEntry)getComponent(WorkspaceEntry.class, wsName);
+
+ return new JDBCWorkspaceDataContainerChecker(dataContainer, vsPlugin, wsEntry, lastReport);
+ }
+
+ private Object getComponent(Class forClass, String wsName)
+ {
+ return repository.getWorkspaceContainer(wsName).getComponent(forClass);
+ }
+
+ private String getPathToReportMessage()
+ {
+ return ". See full report by path " + lastReport.getReportPath();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void start()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void stop()
+ {
+ }
+}
12 years, 1 month