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));
}
/**