Author: tolusha
Date: 2012-03-02 02:57:14 -0500 (Fri, 02 Mar 2012)
New Revision: 5743
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/EarlierVersionsRemover.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/NodeRemover.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RootAsParentAssigner.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/ValueRecordsRemover.java
Removed:
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/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/DummyRepair.java
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/RepositoryCheckController.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
jcr/trunk/exo.jcr.component.core/src/test/resources/tsm-excludes.properties
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-03-02
04:08:02 UTC (rev 5742)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AbstractInconsistencyRepair.java 2012-03-02
07:57:14 UTC (rev 5743)
@@ -18,6 +18,9 @@
*/
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.QPathEntry;
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;
@@ -41,6 +44,9 @@
protected final WorkspaceStorageConnectionFactory connFactory;
+ /**
+ * AbstractInconsistencyRepair constructor.
+ */
AbstractInconsistencyRepair(WorkspaceStorageConnectionFactory connFactory)
{
this.connFactory = connFactory;
@@ -60,7 +66,7 @@
throw new SQLException("Connection is instance of " + conn);
}
- repairInternally((JDBCStorageConnection)conn, resultSet);
+ repairRow((JDBCStorageConnection)conn, resultSet);
conn.commit();
}
@@ -76,7 +82,7 @@
}
}
- abstract void repairInternally(JDBCStorageConnection conn, ResultSet resultSet) throws
SQLException;
+ abstract void repairRow(JDBCStorageConnection conn, ResultSet resultSet) throws
SQLException;
protected void rollback(WorkspaceStorageConnection conn)
{
@@ -97,7 +103,7 @@
}
}
- protected String exctractId(ResultSet resultSet) throws SQLException
+ protected String exctractId(ResultSet resultSet, String column) throws SQLException
{
String containerName = "";
try
@@ -108,6 +114,12 @@
{
}
- return
resultSet.getString(DBConstants.COLUMN_ID).substring(containerName.length());
+ return resultSet.getString(column).substring(containerName.length());
}
+
+ protected QPathEntry extractName(ResultSet resultSet) throws SQLException,
IllegalNameException
+ {
+ return new
QPathEntry(InternalQName.parse(resultSet.getString(DBConstants.COLUMN_NAME)),
+ resultSet.getInt(DBConstants.COLUMN_INDEX));
+ }
}
Deleted:
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-03-02
04:08:02 UTC (rev 5742)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/AssignerRootAsParent.java 2012-03-02
07:57:14 UTC (rev 5743)
@@ -1,128 +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 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);
- }
- }
-}
Modified:
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 2012-03-02
04:08:02 UTC (rev 5742)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/DummyRepair.java 2012-03-02
07:57:14 UTC (rev 5743)
@@ -33,6 +33,6 @@
*/
public void doRepair(ResultSet resultSet) throws SQLException
{
- // do nothing
+ throw new SQLException("Inconsistency can not be fixed automatically");
}
}
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/EarlierVersionsRemover.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/EarlierVersionsRemover.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/EarlierVersionsRemover.java 2012-03-02
07:57:14 UTC (rev 5743)
@@ -0,0 +1,70 @@
+/*
+ * 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.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: EarlierVersionsRemover.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class EarlierVersionsRemover extends AbstractInconsistencyRepair
+{
+
+ /**
+ * RemoveEarlierVersions constructor.
+ */
+ public EarlierVersionsRemover(WorkspaceStorageConnectionFactory connFactory)
+ {
+ super(connFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void repairRow(JDBCStorageConnection conn, ResultSet resultSet) throws
SQLException
+ {
+ try
+ {
+ PropertyData data = (PropertyData)conn.getItemData(exctractId(resultSet,
DBConstants.COLUMN_ID));
+ 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);
+ }
+ }
+}
Modified:
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 2012-03-02
04:08:02 UTC (rev 5742)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/InconsistencyRepair.java 2012-03-02
07:57:14 UTC (rev 5743)
@@ -28,7 +28,7 @@
public interface InconsistencyRepair
{
/**
- * Repair inconsistency based on resultSet.
+ * Repair inconsistency represented in row of resultSet.
*
* @param resultSet
* @throws SQLException
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/NodeRemover.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/NodeRemover.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/NodeRemover.java 2012-03-02
07:57:14 UTC (rev 5743)
@@ -0,0 +1,118 @@
+/*
+ * 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.core.nodetype.NodeDefinitionData;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
+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.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+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: NodeRemover.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class NodeRemover extends AbstractInconsistencyRepair
+{
+ private final NodeTypeDataManager nodeTypeManager;
+
+ /**
+ * NodeRemover constructor.
+ */
+ public NodeRemover(WorkspaceStorageConnectionFactory connFactory, NodeTypeDataManager
nodeTypeManager)
+ {
+ super(connFactory);
+ this.nodeTypeManager = nodeTypeManager;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ void repairRow(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ try
+ {
+ String parentId = exctractId(resultSet, DBConstants.COLUMN_PARENTID);
+ InternalQName nodeName =
InternalQName.parse(resultSet.getString(DBConstants.COLUMN_NAME));
+
+ NodeData parent = (NodeData)conn.getItemData(parentId);
+
+ NodeDefinitionData def =
+ nodeTypeManager.getChildNodeDefinition(nodeName,
parent.getPrimaryTypeName(),
+ parent.getMixinTypeNames());
+
+ if (def == null || def.isResidualSet())
+ {
+ String nodeId = exctractId(resultSet, DBConstants.COLUMN_ID);
+ int orderNum = resultSet.getInt(DBConstants.COLUMN_NORDERNUM);
+ int version = resultSet.getInt(DBConstants.COLUMN_VERSION);
+ QPath path = QPath.makeChildPath(parent.getQPath(), extractName(resultSet));
+
+ NodeData data =
+ new TransientNodeData(path, nodeId, version, null, null, orderNum,
Constants.ROOT_UUID, null);
+
+ deleteTree(conn, data);
+ }
+ else
+ {
+ throw new SQLException("Node is required by its parent.");
+ }
+ }
+ catch (IllegalStateException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (RepositoryException e)
+ {
+ throw new SQLException(e);
+ }
+ catch (IllegalNameException e)
+ {
+ throw new SQLException(e);
+ }
+ }
+
+ private void deleteTree(JDBCStorageConnection conn, NodeData data) throws
IllegalStateException,
+ RepositoryException
+ {
+ for (NodeData child : conn.getChildNodesData(data))
+ {
+ deleteTree(conn, child);
+ }
+
+ for (PropertyData prop : conn.getChildPropertiesData(data))
+ {
+ conn.delete(prop);
+ }
+
+ conn.delete(data);
+ }
+}
Deleted:
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-03-02
04:08:02 UTC (rev 5742)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverEarlierVersions.java 2012-03-02
07:57:14 UTC (rev 5743)
@@ -1,70 +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.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 $
- */
-public class RemoverEarlierVersions extends AbstractInconsistencyRepair
-{
-
- /**
- * RemoveEarlierVersions constructor.
- */
- public RemoverEarlierVersions(WorkspaceStorageConnectionFactory connFactory)
- {
- super(connFactory);
- }
-
- /**
- * {@inheritDoc}
- */
- 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);
- }
- }
-}
Deleted:
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 2012-03-02
04:08:02 UTC (rev 5742)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RemoverValueRecords.java 2012-03-02
07:57:14 UTC (rev 5743)
@@ -1,100 +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.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/checker/RepositoryCheckController.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java 2012-03-02
04:08:02 UTC (rev 5742)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RepositoryCheckController.java 2012-03-02
07:57:14 UTC (rev 5743)
@@ -26,6 +26,7 @@
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.nodetype.NodeTypeDataManagerImpl;
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;
@@ -353,7 +354,9 @@
WorkspaceEntry wsEntry = (WorkspaceEntry)getComponent(WorkspaceEntry.class,
wsName);
- return new JDBCWorkspaceDataContainerChecker(dataContainer, vsPlugin, wsEntry,
lastReport);
+ NodeTypeDataManagerImpl nodeTypeManager =
(NodeTypeDataManagerImpl)getComponent(NodeTypeDataManagerImpl.class, wsName);
+
+ return new JDBCWorkspaceDataContainerChecker(dataContainer, vsPlugin, wsEntry,
nodeTypeManager, lastReport);
}
private Object getComponent(Class forClass, String wsName)
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RootAsParentAssigner.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RootAsParentAssigner.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/RootAsParentAssigner.java 2012-03-02
07:57:14 UTC (rev 5743)
@@ -0,0 +1,123 @@
+/*
+ * 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.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 RootAsParentAssigner extends AbstractInconsistencyRepair
+{
+
+ public RootAsParentAssigner(WorkspaceStorageConnectionFactory connFactory)
+ {
+ super(connFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void repairRow(JDBCStorageConnection conn, ResultSet resultSet) throws
SQLException
+ {
+ if (resultSet.getInt(DBConstants.COLUMN_CLASS) == 1)
+ {
+ assignRootAsParent(conn, resultSet);
+ }
+ else
+ {
+ deleteProperty(conn, resultSet);
+ }
+ }
+
+ private void deleteProperty(JDBCStorageConnection conn, ResultSet resultSet) throws
SQLException
+ {
+ try
+ {
+ String propertyId = exctractId(resultSet, DBConstants.COLUMN_ID);
+ 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 assignRootAsParent(JDBCStorageConnection conn, ResultSet resultSet)
throws SQLException
+ {
+ try
+ {
+ String nodeId = exctractId(resultSet, DBConstants.COLUMN_ID);
+ int orderNum = resultSet.getInt(DBConstants.COLUMN_NORDERNUM);
+ int version = resultSet.getInt(DBConstants.COLUMN_VERSION);
+ QPath path = new QPath(new QPathEntry[]{extractName(resultSet)});
+
+ 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);
+ }
+ }
+}
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/ValueRecordsRemover.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/ValueRecordsRemover.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/checker/ValueRecordsRemover.java 2012-03-02
07:57:14 UTC (rev 5743)
@@ -0,0 +1,103 @@
+/*
+ * 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: ValueRecordsRemover.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class ValueRecordsRemover extends AbstractInconsistencyRepair
+{
+
+ private final String containerName;
+
+ private final boolean multiDb;
+
+ /**
+ * ValueRecordsRemover constructor.
+ */
+ public ValueRecordsRemover(WorkspaceStorageConnectionFactory connFactory, String
containerName, boolean multiDb)
+ {
+ super(connFactory);
+ this.containerName = containerName;
+ this.multiDb = multiDb;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ void repairRow(JDBCStorageConnection conn, ResultSet resultSet) throws SQLException
+ {
+ try
+ {
+ String propertyId = exctractId(resultSet, DBConstants.COLUMN_VPROPERTY_ID);
+ 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, String column) throws SQLException
+ {
+ return resultSet.getString(column).substring(multiDb ? 0 :
containerName.length());
+ }
+}
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-03-02
04:08:02 UTC (rev 5742)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-03-02
07:57:14 UTC (rev 5743)
@@ -23,15 +23,18 @@
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.AssignerRootAsParent;
import org.exoplatform.services.jcr.impl.checker.DummyRepair;
+import org.exoplatform.services.jcr.impl.checker.EarlierVersionsRemover;
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.checker.NodeRemover;
+import org.exoplatform.services.jcr.impl.checker.PropertyRemover;
+import org.exoplatform.services.jcr.impl.checker.ValueRecordsRemover;
+import org.exoplatform.services.jcr.impl.checker.RootAsParentAssigner;
import org.exoplatform.services.jcr.impl.core.lock.LockTableHandler;
import org.exoplatform.services.jcr.impl.core.lock.LockTableHandlerFactory;
+import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeDataManagerImpl;
import org.exoplatform.services.jcr.impl.storage.value.ValueDataNotFoundException;
import org.exoplatform.services.jcr.impl.storage.value.ValueStorageNotFoundException;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
@@ -78,17 +81,21 @@
private LockTableHandler lockHandler;
+ private NodeTypeDataManagerImpl nodeTypeManager;
+
/**
* JDBCWorkspaceDataContainerChecker constructor.
*/
public JDBCWorkspaceDataContainerChecker(JDBCWorkspaceDataContainer
jdbcDataContainer,
- ValueStoragePluginProvider vsPlugin, WorkspaceEntry workspaceEntry,
InspectionReport report)
+ ValueStoragePluginProvider vsPlugin, WorkspaceEntry workspaceEntry,
NodeTypeDataManagerImpl nodeTypeManager,
+ InspectionReport report)
{
this.jdbcDataContainer = jdbcDataContainer;
this.vsPlugin = vsPlugin;
this.workspaceEntry = workspaceEntry;
this.report = report;
this.lockHandler = LockTableHandlerFactory.getHandler(workspaceEntry);
+ this.nodeTypeManager = nodeTypeManager;
initInspectionQueries();
}
@@ -164,13 +171,19 @@
{
((JDBCStorageConnection)conn).deleteLockProperties(nodeId);
}
-
+ conn.commit();
logComment("Lock has been removed form ITEM table. Node UUID:
" + nodeId);
}
- finally
+ catch (RepositoryException e)
{
- conn.close();
+ conn.rollback();
+ throw e;
}
+ catch (SQLException e)
+ {
+ conn.rollback();
+ throw e;
+ }
}
}
}
@@ -221,6 +234,7 @@
if (resultSet.next())
{
logDescription(query.getDescription());
+
do
{
logBrokenObjectAndSetInconsistency(getBrokenObject(resultSet,
query.getFieldNames()));
@@ -233,12 +247,8 @@
}
catch (SQLException e)
{
- if (LOG.isTraceEnabled())
- {
- LOG.trace(e.getMessage(), e);
- }
+ logExceptionAndSetInconsistency("Inconsistency can not
been fixed", e);
}
-
}
}
while (resultSet.next());
@@ -287,24 +297,26 @@
if (resultSet.next())
{
+ logDescription("ValueData not found inconsistency");
+
do
{
- String propertyId =
removeWorkspacePrefix(resultSet.getString(DBConstants.COLUMN_VPROPERTY_ID));
- int orderNumber = resultSet.getInt(DBConstants.COLUMN_VORDERNUM);
String storageDesc =
resultSet.getString(DBConstants.COLUMN_VSTORAGE_DESC);
ValueIOChannel channel = null;
try
{
channel = getIOChannel(storageDesc);
- doCheckAndRepairValueData(channel, resultSet, propertyId, orderNumber,
autoRepair);
+ doCheckAndRepairValueData(channel, resultSet, autoRepair);
}
catch (IOException e)
{
- logDescription("Unexpected exception during checking");
- logBrokenObjectAndSetInconsistency(getBrokenObject(resultSet,
vsInspectionQuery.getFieldNames()));
- logExceptionAndSetInconsistency(e.getMessage(), e);
+ logExceptionAndSetInconsistency("Unexpected exception during
checking.", e);
}
+ catch (SQLException e)
+ {
+ logExceptionAndSetInconsistency("Unexpected exception during
checking.", e);
+ }
finally
{
if (channel != null)
@@ -339,32 +351,37 @@
}
catch (ValueStorageNotFoundException e)
{
- logDescription("ValueStorage " + storageDesc + " not
found");
- logExceptionAndSetInconsistency(e.getMessage(), e);
+ logExceptionAndSetInconsistency("ValueStorage " + storageDesc + "
not found: " + e.getMessage(), e);
}
return channel;
}
- private void doCheckAndRepairValueData(ValueIOChannel channel, ResultSet resultSet,
String propertyId,
- int orderNumber, boolean autoRepair) throws IOException
+ private void doCheckAndRepairValueData(ValueIOChannel channel, ResultSet resultSet,
boolean autoRepair)
+ throws IOException, SQLException
{
+ String propertyId =
removeWorkspacePrefix(resultSet.getString(DBConstants.COLUMN_VPROPERTY_ID));
+ int orderNumber = resultSet.getInt(DBConstants.COLUMN_VORDERNUM);
+
try
{
channel.checkValueData(propertyId, orderNumber);
}
catch (ValueDataNotFoundException e)
{
- String brokenObject = getBrokenObject(resultSet,
vsInspectionQuery.getFieldNames());
+ logBrokenObjectAndSetInconsistency(getBrokenObject(resultSet,
vsInspectionQuery.getFieldNames()));
- logDescription("ValueData not found");
- logBrokenObjectAndSetInconsistency(brokenObject);
- logExceptionAndSetInconsistency(e.getMessage(), e);
-
if (autoRepair)
{
- channel.repairValueData(propertyId, orderNumber);
- logComment("ValueData corresponding to " + brokenObject + "
has been repaired. New empty file is created.");
+ try
+ {
+ channel.repairValueData(propertyId, orderNumber);
+ logComment("ValueData has been repaired. New empty file is
created.");
+ }
+ catch (IOException e2)
+ {
+ logExceptionAndSetInconsistency("Can not repair value data: " +
e.getMessage(), e);
+ }
}
}
}
@@ -469,7 +486,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
AssignerRootAsParent(jdbcDataContainer
+ "Items that do not have parent nodes", new
RootAsParentAssigner(jdbcDataContainer
.getConnectionFactory())));
itemsInspectionQuery
@@ -480,7 +497,8 @@
+ 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()));
+ "A node that has a single valued properties with nothing declared in the
VALUE table.",
+ new PropertyRemover(jdbcDataContainer.getConnectionFactory(),
nodeTypeManager)));
itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
? "select * from JCR_MITEM N where N.I_CLASS=1 and NOT EXISTS "
@@ -491,7 +509,7 @@
+ "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()));
+ new NodeRemover(jdbcDataContainer.getConnectionFactory(), nodeTypeManager)));
itemsInspectionQuery.add(new InspectionQuery(jdbcDataContainer.multiDb
? "select * from JCR_MVALUE V where NOT EXISTS(select * from JCR_MITEM P
"
@@ -499,7 +517,7 @@
: "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,
+ new ValueRecordsRemover(jdbcDataContainer.getConnectionFactory(),
jdbcDataContainer.containerName,
jdbcDataContainer.multiDb)));
// The differences in the queries by DB dialect.
@@ -537,7 +555,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 AssignerRootAsParent(jdbcDataContainer.getConnectionFactory())));
+ new RootAsParentAssigner(jdbcDataContainer.getConnectionFactory())));
itemsInspectionQuery
.add(new InspectionQuery(
@@ -552,7 +570,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
RemoverEarlierVersions(jdbcDataContainer.getConnectionFactory())));
+ "Several versions of same item.", new
EarlierVersionsRemover(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 "
@@ -561,6 +579,7 @@
+ 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()));
+ "Reference properties without reference records", new
PropertyRemover(jdbcDataContainer
+ .getConnectionFactory(), nodeTypeManager)));
}
}
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-03-02
04:08:02 UTC (rev 5742)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/TestRepositoryCheckController.java 2012-03-02
07:57:14 UTC (rev 5743)
@@ -21,6 +21,7 @@
import org.exoplatform.services.jcr.BaseStandaloneTest;
import org.exoplatform.services.jcr.access.AccessControlList;
import org.exoplatform.services.jcr.config.LockManagerEntry;
+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.dataflow.ItemState;
@@ -30,7 +31,7 @@
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.impl.checker.RepositoryCheckController;
-import org.exoplatform.services.jcr.impl.checker.RepositoryCheckController.DataStorage;
+import org.exoplatform.services.jcr.impl.core.ItemImpl;
import org.exoplatform.services.jcr.impl.core.NodeImpl;
import org.exoplatform.services.jcr.impl.core.PropertyImpl;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
@@ -40,6 +41,7 @@
import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
import org.exoplatform.services.jcr.impl.storage.value.fs.FileValueStorage;
import org.exoplatform.services.jcr.util.IdGenerator;
@@ -47,14 +49,20 @@
import java.io.File;
import java.io.FileInputStream;
-import java.io.InputStream;
import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.List;
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
import javax.jcr.Node;
-import javax.jcr.PropertyIterator;
+import javax.jcr.Property;
import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
import javax.naming.InitialContext;
+import javax.naming.NamingException;
import javax.sql.DataSource;
/**
@@ -74,27 +82,18 @@
private static boolean CACHE_ENABLED = true;
+ private static boolean CACHE_DISABLED = false;
+
private final TesterConfigurationHelper helper =
TesterConfigurationHelper.getInstance();
- /**
- * @see org.exoplatform.services.jcr.BaseStandaloneTest#getRepositoryName()
- */
- @Override
protected String getRepositoryName()
{
- String repName = System.getProperty("test.repository");
- if (repName == null)
- {
- throw new RuntimeException(
- "Test repository is undefined. Set test.repository system property
"
- + "(For maven: in project.properties:
maven.junit.sysproperties=test.repository\ntest.repository=<rep-name>)");
- }
- return repName;
-
+ return null;
}
public void tearDown() throws Exception
{
+ // remove generated reports
for (File file : new File(".").listFiles())
{
if (file.getName().startsWith("report"))
@@ -106,270 +105,96 @@
super.tearDown();
}
- public void testDB() throws Exception
+ public void testCheckDataBase() throws Exception
{
TesterRepositoryCheckController checkController =
new
TesterRepositoryCheckController(repositoryService.getRepository("db1"));
- String result = checkController.checkAndRepair(new DataStorage[]{DataStorage.DB},
false);
- assertNotNull(result);
- assertTrue("Repository data is not consistent, result: " + result,
- result.startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
- public void testConsistentLocksInDataBase() throws Exception
+ public void testLockUsecases() throws Exception
{
- checkConsistentLocksInDataBase(NOT_SHARED_CACHE, SINGLE_DB);
- checkConsistentLocksInDataBase(NOT_SHARED_CACHE, MULTI_DB);
- }
+ checkConsistentLocksInDataBase(helper.createRepository(container, SINGLE_DB,
CACHE_ENABLED, NOT_SHARED_CACHE));
+ checkConsistentLocksInDataBase(helper.createRepository(container, MULTI_DB,
CACHE_ENABLED, NOT_SHARED_CACHE));
+ checkConsistentLocksInDataBase(helper.createRepository(container, SINGLE_DB,
CACHE_ENABLED, SHARED_CACHE));
+ checkConsistentLocksInDataBase(helper.createRepository(container, MULTI_DB,
CACHE_ENABLED, SHARED_CACHE));
- public void testConsistentLocksInDataBaseSharedCache() throws Exception
- {
- checkConsistentLocksInDataBase(SHARED_CACHE, SINGLE_DB);
- checkConsistentLocksInDataBase(SHARED_CACHE, MULTI_DB);
+ checkInconsistentLocksInLockTable(helper.createRepository(container, SINGLE_DB,
CACHE_ENABLED, NOT_SHARED_CACHE));
+ checkInconsistentLocksInLockTable(helper.createRepository(container, MULTI_DB,
CACHE_ENABLED, NOT_SHARED_CACHE));
+ checkInconsistentLocksInLockTable(helper.createRepository(container, SINGLE_DB,
CACHE_ENABLED, SHARED_CACHE));
+ checkInconsistentLocksInLockTable(helper.createRepository(container, MULTI_DB,
CACHE_ENABLED, SHARED_CACHE));
}
- private void checkConsistentLocksInDataBase(boolean isCacheShared, boolean isMultiDb)
throws Exception
+ private void checkConsistentLocksInDataBase(ManageableRepository repository) throws
Exception
{
- ManageableRepository repository = helper.createRepository(container, isMultiDb,
CACHE_ENABLED, isCacheShared);
- SessionImpl session =
- (SessionImpl)repository.login(credentials,
repository.getConfiguration().getSystemWorkspaceName());
- NodeImpl node = (NodeImpl)session.getRootNode().addNode("testNode");
- node.addMixin("mix:lockable");
- session.save();
- node.lock(false, false);
-
TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
- String result = checkController.checkAndRepair(new DataStorage[]{DataStorage.DB},
false);
- assertNotNull(result);
- assertTrue("Repository data is not consistent, result: " + result,
- result.startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- }
+ Node node = addTestNode(repository);
+ lockNode(node);
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- public void testInconsistentLocksInDataBase() throws Exception
- {
- checkInconsistentLocksInItemTable(NOT_SHARED_CACHE, SINGLE_DB);
- checkInconsistentLocksInItemTable(NOT_SHARED_CACHE, MULTI_DB);
+ removePropertyInDB(repository,
(PropertyImpl)node.getProperty("jcr:lockIsDeep"));
+ removePropertyInDB(repository,
(PropertyImpl)node.getProperty("jcr:lockOwner"));
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
- checkInconsistentLocksInLockTable(NOT_SHARED_CACHE, SINGLE_DB);
- checkInconsistentLocksInLockTable(NOT_SHARED_CACHE, MULTI_DB);
+ checkController.repairDataBase("yes");
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
- public void testInconsistentLocksInDataBaseWithSharedCache() throws Exception
+ private void checkInconsistentLocksInLockTable(ManageableRepository repository) throws
Exception
{
- checkInconsistentLocksInItemTable(SHARED_CACHE, SINGLE_DB);
- checkInconsistentLocksInItemTable(SHARED_CACHE, MULTI_DB);
-
- checkInconsistentLocksInLockTable(SHARED_CACHE, SINGLE_DB);
- checkInconsistentLocksInLockTable(SHARED_CACHE, MULTI_DB);
- }
-
- private void checkInconsistentLocksInItemTable(boolean cacheShared, boolean isMultiDb)
throws Exception
- {
- ManageableRepository repository = helper.createRepository(container, isMultiDb,
CACHE_ENABLED, cacheShared);
- SessionImpl session =
- (SessionImpl)repository.login(credentials,
repository.getConfiguration().getSystemWorkspaceName());
- NodeImpl node = (NodeImpl)session.getRootNode().addNode("testNode");
- node.addMixin("mix:lockable");
- session.save();
- node.lock(false, false);
-
TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
- WorkspaceEntry workspaceEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
- String sourceName =
workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
+ Node node = addTestNode(repository);
+ lockNode(node);
- String multiDbQueryStatement =
- "DELETE 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')";
- String singleDbQueryStatement =
- "DELETE FROM JCR_SITEM WHERE CONTAINER_NAME='"
- + workspaceEntry.getName()
- + "' AND I_CLASS=2 AND
(
NAME='[http://www.jcp.org/jcr/1.0]lockOwner' OR
NAME='[http://www.jcp.org/jcr/1.0]lockIsDeep')";
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
-
- // remove constraint
- conn.prepareStatement(
- "ALTER TABLE JCR_" + (isMultiDb ? "M" : "S") +
"ITEM DROP CONSTRAINT JCR_FK_" + (isMultiDb ? "M" : "S")
- + "VALUE_PROPERTY").execute();
- // delete properties (this should cause inconsistency)
- conn.prepareStatement(isMultiDb ? multiDbQueryStatement :
singleDbQueryStatement).execute();
-
- // remove constriant
- conn.prepareStatement(
- "ALTER TABLE JCR_" + (isMultiDb ? "M" : "S") +
"VALUE DROP CONSTRAINT JCR_PK_" + (isMultiDb ? "M" : "S")
- + "VALUE").execute();
-
- // clean up properties value to avoid another (except needed) cause of
inconsistency
- String lockOwnerPropertyId =
- (isMultiDb ? "" : workspaceEntry.getName())
- +
((PropertyImpl)node.getProperty("jcr:lockIsDeep")).getInternalIdentifier();
- String lockIsDeepPropertyId =
- (isMultiDb ? "" : workspaceEntry.getName())
- +
((PropertyImpl)node.getProperty("jcr:lockOwner")).getInternalIdentifier();
-
- conn.prepareStatement(
- "DELETE FROM JCR_" + (isMultiDb ? "M" : "S") +
"VALUE WHERE PROPERTY_ID = '" + lockOwnerPropertyId
- + "' OR PROPERTY_ID = '" + lockIsDeepPropertyId +
"'").execute();
- conn.commit();
- conn.close();
-
+ clearLockTable(repository);
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
checkController.repairDataBase("yes");
-
assertTrue(checkController.checkValueStorage().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
- private void checkInconsistentLocksInLockTable(boolean cacheShared, boolean isMultiDb)
throws Exception
+ public void testCheckValueStorage() throws Exception
{
- ManageableRepository repository = helper.createRepository(container, isMultiDb,
true, cacheShared);
- SessionImpl session =
- (SessionImpl)repository.login(credentials,
repository.getConfiguration().getSystemWorkspaceName());
- NodeImpl node = (NodeImpl)session.getRootNode().addNode("testNode");
- node.addMixin("mix:lockable");
- session.save();
- node.lock(false, false);
+ TesterRepositoryCheckController checkController =
+ new
TesterRepositoryCheckController(repositoryService.getRepository("db1"));
- WorkspaceEntry workspaceEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
- LockManagerEntry lockManagerEntry = workspaceEntry.getLockManager();
-
- String sourceName = null;
- String queryStatement = null;
-
- if (helper.ispnCacheEnabled())
- {
- sourceName =
lockManagerEntry.getParameterValue("infinispan-cl-cache.jdbc.datasource");
-
- queryStatement =
- "DELETE FROM " +
lockManagerEntry.getParameterValue("infinispan-cl-cache.jdbc.table.name") +
"_" + "L"
- + workspaceEntry.getUniqueName().replace("_",
"").replace("-", "_");
- }
- else
- {
- sourceName =
lockManagerEntry.getParameterValue(CacheableLockManagerImpl.JBOSSCACHE_JDBC_CL_DATASOURCE);
-
- if (cacheShared)
- {
- queryStatement =
- "DELETE FROM " +
lockManagerEntry.getParameterValue(CacheableLockManagerImpl.JBOSSCACHE_JDBC_TABLE_NAME)
- + " WHERE PARENT='/" + workspaceEntry.getUniqueName() +
"/" + CacheableLockManagerImpl.LOCKS + "'";
- }
- else
- {
- queryStatement =
- "DELETE FROM " +
lockManagerEntry.getParameterValue(CacheableLockManagerImpl.JBOSSCACHE_JDBC_TABLE_NAME)
- + " WHERE PARENT='/" + CacheableLockManagerImpl.LOCKS +
"'";
- }
-
- }
-
- Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
-
- conn.prepareStatement(queryStatement).execute();
- conn.commit();
- conn.close();
-
- TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
- String result = checkController.checkAndRepair(new DataStorage[]{DataStorage.DB},
false);
- assertNotNull(result);
- assertTrue("Repository data is consistent, result: " + result,
- result.startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
-
+
assertTrue(checkController.checkValueStorage().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
- public void testValueStorage() throws Exception
+ public void testCheckIndex() throws Exception
{
- TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
+ TesterRepositoryCheckController checkController =
+ new
TesterRepositoryCheckController(repositoryService.getRepository("db1"));
- File f = this.createBLOBTempFile(20);
- InputStream is = new FileInputStream(f);
- try
- {
- Node n = root.addNode("node");
- n.setProperty("prop", is);
-
- root.save();
-
- String result = checkController.checkAndRepair(new
DataStorage[]{DataStorage.VALUE_STORAGE}, false);
- assertNotNull(result);
- assertTrue("Repository data is not consistent, result: " + result,
- result.startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- }
- finally
- {
- is.close();
- f.delete();
- }
+
assertTrue(checkController.checkIndex().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
- public void testSearchIndex() throws Exception
+ public void testCheckAll() throws Exception
{
- TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
+ TesterRepositoryCheckController checkController =
+ new
TesterRepositoryCheckController(repositoryService.getRepository("db1"));
- String result = checkController.checkAndRepair(new
DataStorage[]{DataStorage.LUCENE_INDEX}, false);
- assertNotNull(result);
- assertTrue("Repository data is not consistent, result: " + result,
- result.startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+
assertTrue(checkController.checkAll().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
- public void testAll() throws Exception
- {
- TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
-
- String result =
- checkController.checkAndRepair(new DataStorage[]{DataStorage.DB,
DataStorage.VALUE_STORAGE,
- DataStorage.LUCENE_INDEX}, false);
-
-
- assertNotNull(result);
- assertTrue("Repository data is not consistent, result: " + result,
- result.startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- }
-
/**
* Index contains documents that was already removed from DB.
*/
public void testIndexUsecaseWrongDocumentId() throws Exception
{
- ManageableRepository repository = helper.createRepository(container, false,
false);
-
- // create repository and add property
- SessionImpl session =
- (SessionImpl)repository.login(credentials,
repository.getConfiguration().getSystemWorkspaceName());
- NodeImpl node = (NodeImpl)session.getRootNode().addNode("testNode");
- session.save();
- session.logout();
-
- // repository is consistent
+ ManageableRepository repository = helper.createRepository(container, SINGLE_DB,
CACHE_DISABLED);
TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
- assertTrue(checkController.checkIndex().startsWith(
- RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+
+ Node node = addTestNode(repository);
+
assertTrue(checkController.checkIndex().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
-
- WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
- boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
-
- // Remove node from DB
- String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
-
- Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
-
- conn.prepareStatement(
- "ALTER TABLE JCR_" + (isMultiDb ? "M" : "S") +
"ITEM DROP CONSTRAINT JCR_FK_" + (isMultiDb ? "M" : "S")
- + "ITEM_PARENT").execute();
- conn.prepareStatement(
- "DELETE FROM JCR_" + (isMultiDb ? "M" : "S") +
"ITEM WHERE ID = '" + (isMultiDb ? "" : wsEntry.getName())
- + node.getInternalIdentifier() + "'").execute();
-
- conn.commit();
- conn.close();
-
- // repository is inconsistent
- assertTrue(checkController.checkIndex().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
-
+ removeNodeInDB(repository, node);
+
assertTrue(checkController.checkIndex().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
}
/**
@@ -377,60 +202,14 @@
*/
public void testIndexUsecaseMultipleDocuments() throws Exception
{
- ManageableRepository repository = helper.createRepository(container, false,
false);
-
- // create repository and add property
- SessionImpl session =
- (SessionImpl)repository.login(credentials,
repository.getConfiguration().getSystemWorkspaceName());
- NodeImpl node = (NodeImpl)session.getRootNode().addNode("testNode");
- session.save();
- session.logout();
-
- // repository is consistent
+ ManageableRepository repository = helper.createRepository(container, SINGLE_DB,
CACHE_DISABLED);
TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
- assertTrue(checkController.checkIndex().startsWith(
- RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+ Node node = addTestNode(repository);
+
assertTrue(checkController.checkIndex().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
- boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
-
- // Indexing one more document with same UUID
- List<SearchManager> searchManagers =
-
repository.getWorkspaceContainer(repository.getConfiguration().getSystemWorkspaceName())
- .getComponentInstancesOfType(SearchManager.class);
-
- PlainChangesLog log = new PlainChangesLogImpl();
-
- NodeData data =
- new TransientNodeData(QPath.makeChildPath(Constants.ROOT_PATH, new
InternalQName("", "testNode")),
- node.getIdentifier(), -1, Constants.NT_UNSTRUCTURED, null, 0, null, new
AccessControlList());
-
- TransientPropertyData primaryType =
- new TransientPropertyData(QPath.makeChildPath(data.getQPath(),
Constants.JCR_PRIMARYTYPE),
- IdGenerator.generate(), -1, PropertyType.NAME, data.getIdentifier(), false,
new TransientValueData(
- Constants.NT_UNSTRUCTURED));
-
- log.add(new ItemState(data, ItemState.ADDED, false, null));
- log.add(new ItemState(primaryType, ItemState.ADDED, false, null));
-
- SearchManager sm = null;
- for (SearchManager searchManager : searchManagers)
- {
- if (!(searchManager instanceof SystemSearchManager))
- {
- sm = searchManager;
- break;
- }
- }
-
- assertNotNull(sm);
- sm.onSaveItems(log);
-
- // repository is inconsistent
- assertTrue(checkController.checkIndex().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
-
+ indexNode(repository, node, ItemState.ADDED);
+
assertTrue(checkController.checkIndex().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
}
/**
@@ -438,114 +217,36 @@
*/
public void testIndexUsecaseDocumentNotExists() throws Exception
{
- ManageableRepository repository = helper.createRepository(container, false,
false);
-
- // create repository and add property
- SessionImpl session =
- (SessionImpl)repository.login(credentials,
repository.getConfiguration().getSystemWorkspaceName());
- NodeImpl node = (NodeImpl)session.getRootNode().addNode("testNode");
- session.save();
- session.logout();
-
- // repository is consistent
+ ManageableRepository repository = helper.createRepository(container, SINGLE_DB,
CACHE_DISABLED);
TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
- assertTrue(checkController.checkIndex().startsWith(
- RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+ Node node = addTestNode(repository);
+
assertTrue(checkController.checkIndex().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
- boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
-
- // Indexing one more document with same UUID
- List<SearchManager> searchManagers =
-
repository.getWorkspaceContainer(repository.getConfiguration().getSystemWorkspaceName())
- .getComponentInstancesOfType(SearchManager.class);
-
- PlainChangesLog log = new PlainChangesLogImpl();
-
- NodeData data =
- new TransientNodeData(QPath.makeChildPath(Constants.ROOT_PATH, new
InternalQName("", "testNode")),
- node.getIdentifier(), -1, Constants.NT_UNSTRUCTURED, null, 0, null, new
AccessControlList());
-
- TransientPropertyData primaryType =
- new TransientPropertyData(QPath.makeChildPath(data.getQPath(),
Constants.JCR_PRIMARYTYPE),
- IdGenerator.generate(), -1, PropertyType.NAME, data.getIdentifier(), false,
new TransientValueData(
- Constants.NT_UNSTRUCTURED));
-
- log.add(new ItemState(primaryType, ItemState.DELETED, false, null));
- log.add(new ItemState(data, ItemState.DELETED, false, null));
-
- SearchManager sm = null;
- for (SearchManager searchManager : searchManagers)
- {
- if (!(searchManager instanceof SystemSearchManager))
- {
- sm = searchManager;
- break;
- }
- }
-
- assertNotNull(sm);
- sm.onSaveItems(log);
-
- // repository is inconsistent
- assertTrue(checkController.checkIndex().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
-
+ indexNode(repository, node, ItemState.DELETED);
+
assertTrue(checkController.checkIndex().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
}
/**
* Usecase: property doens't have have parent node.
*/
- public void testDBUsecasesTheParentIdIsIdOfThisNodeSingleDB() throws Exception
+ public void testDBUsecasesTheParentIdIsIdOfThisNode() throws Exception
{
- checkDBUsecasesTheParentIdIsIdOfThisNode(helper.createRepository(container, false,
false));
- checkDBUsecasesTheParentIdIsIdOfThisNode2(helper.createRepository(container, false,
false));
- }
+ checkDBUsecasesTheParentIdIsIdOfThisNode(helper.createRepository(container,
SINGLE_DB, CACHE_DISABLED));
+ checkDBUsecasesTheParentIdIsIdOfThisNode2(helper.createRepository(container,
SINGLE_DB, CACHE_DISABLED));
- /**
- * Usecase: property doens't have have parent node.
- */
- public void testDBUsecasesTheParentIdIsIdOfThisNodeMultiDB() throws Exception
- {
- checkDBUsecasesTheParentIdIsIdOfThisNode(helper.createRepository(container, true,
false));
- checkDBUsecasesTheParentIdIsIdOfThisNode2(helper.createRepository(container, true,
false));
+ checkDBUsecasesTheParentIdIsIdOfThisNode(helper.createRepository(container,
MULTI_DB, CACHE_DISABLED));
+ checkDBUsecasesTheParentIdIsIdOfThisNode2(helper.createRepository(container,
MULTI_DB, CACHE_DISABLED));
}
private void checkDBUsecasesTheParentIdIsIdOfThisNode(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));
+ Node node = addTestNode(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())
- + node.getInternalIdentifier() + "' WHERE ID='" +
(isMultiDb ? "" : wsEntry.getName())
- + node.getInternalIdentifier() + "'").execute();
-
- conn.commit();
- conn.close();
-
+ assingItsOwnParent(repository, (ItemImpl)node);
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
checkController.repairDataBase("yes");
@@ -555,106 +256,39 @@
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);
+ Node node = addTestNode(repository);
+ Property prop = addTestProperty(repository, node);
- // change ITEM table
- String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- 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();
-
+ assingItsOwnParent(repository, (ItemImpl)prop);
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.
*/
- public void testDBUsecasesSeveralVersionsOfSameItemSingleDB() throws Exception
+ public void testDBUsecasesSeveralVersionsOfSameItem() throws Exception
{
- checkSeveralVersionsOfSameItem(helper.createRepository(container, false, false));
+ checkSeveralVersionsOfSameItem(helper.createRepository(container, SINGLE_DB,
CACHE_DISABLED));
+ checkSeveralVersionsOfSameItem(helper.createRepository(container, MULTI_DB,
CACHE_DISABLED));
}
- /**
- * Usecase: property doens't have have parent node.
- */
- public void testDBUsecasesSeveralVersionsOfSameItemMultiDB() throws Exception
- {
- checkSeveralVersionsOfSameItem(helper.createRepository(container, true, false));
- }
-
private void checkSeveralVersionsOfSameItem(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));
+ Node node = addTestNode(repository);
+ PropertyImpl prop = (PropertyImpl)addTestProperty(repository, node);
- WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
- boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- // change ITEM table
- String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
-
- Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
-
- // add another item with new persisted version
- if (isMultiDb)
- {
- String propId = IdGenerator.generate();
- conn.prepareStatement(
- "INSERT INTO JCR_MITEM VALUES ('" + propId +
"','" + prop.getParentIdentifier()
- + "','[]prop',1,2,1,NULL,1,FALSE)").execute();
- conn.prepareStatement("ALTER TABLE JCR_MVALUE DROP CONSTRAINT
JCR_PK_MVALUE").execute();
- conn.prepareStatement("INSERT INTO JCR_MVALUE VALUES
('100','data','1','" + propId +
"',NULL)").execute();
- }
- else
- {
- String propId = wsEntry.getName() + IdGenerator.generate();
- conn.prepareStatement(
- "INSERT INTO JCR_SITEM VALUES ('" + propId +
"','" + wsEntry.getName() + prop.getParentIdentifier()
- + "','[]prop',1,'" + wsEntry.getName() +
"',2,1,NULL,1,FALSE)").execute();
- conn.prepareStatement("ALTER TABLE JCR_SVALUE DROP CONSTRAINT
JCR_PK_SVALUE").execute();
- conn.prepareStatement("INSERT INTO JCR_SVALUE VALUES
('100','data','1','" + propId +
"',NULL)").execute();
- }
-
- conn.commit();
- conn.close();
-
+ insertPropertyRecord(repository, prop.getInternalIdentifier(),
prop.getParentIdentifier(), prop.getName());
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
checkController.repairDataBase("yes");
@@ -664,159 +298,68 @@
/**
* Usecase: property doens't have have parent node.
*/
- public void testDBUsecasesPropertyWithoutParentSingleDB() throws Exception
+ public void testDBUsecasesPropertyWithoutParent() throws Exception
{
- checkDBUsecasesPropertyWithoutParent(helper.createRepository(container, false,
false));
+ checkDBUsecasesPropertyWithoutParent(helper.createRepository(container, SINGLE_DB,
CACHE_DISABLED));
+ checkDBUsecasesPropertyWithoutParent(helper.createRepository(container, MULTI_DB,
CACHE_DISABLED));
}
- /**
- * Usecase: property doens't have have parent node.
- */
- public void testDBUsecasesPropertyWithoutParentMultiDB() throws Exception
- {
- checkDBUsecasesPropertyWithoutParent(helper.createRepository(container, true,
false));
- }
-
private void checkDBUsecasesPropertyWithoutParent(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));
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+ insertPropertyRecord(repository, IdGenerator.generate(), IdGenerator.generate(),
"testName");
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_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(
- "ALTER TABLE JCR_" + (isMultiDb ? "M" : "S") +
"ITEM DROP CONSTRAINT JCR_FK_" + (isMultiDb ? "M" : "S")
- + "ITEM_PARENT").execute();
- conn.prepareStatement(
- "DELETE FROM JCR_" + (isMultiDb ? "M" : "S") +
"ITEM WHERE ID = '" + (isMultiDb ? "" : wsEntry.getName())
- + node.getInternalIdentifier() + "'").execute();
-
- conn.commit();
- conn.close();
-
- // repository is inconsistent
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
-
+ checkController.repairDataBase("yes");
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
/**
* Usecase: Incorrect JCR_VALUE records.
*/
- public void testDBUsecasesIncorrectValueRecordsSingleDB() throws Exception
+ public void testDBUsecasesIncorrectValueRecords() throws Exception
{
- checkDBUsecasesIncorrectValueRecords(helper.createRepository(container, false,
false));
+ checkDBUsecasesIncorrectValueRecords(helper.createRepository(container, SINGLE_DB,
CACHE_DISABLED));
+ checkDBUsecasesIncorrectValueRecords(helper.createRepository(container, MULTI_DB,
CACHE_DISABLED));
}
- /**
- * Usecase: Incorrect JCR_VALUE records.
- */
- public void testDBUsecasesIncorrectValueRecordsMultiDB() throws Exception
- {
- checkDBUsecasesIncorrectValueRecords(helper.createRepository(container, true,
false));
- }
-
private void checkDBUsecasesIncorrectValueRecords(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));
+ Node node = addTestNode(repository);
+ PropertyImpl prop = (PropertyImpl)addTestProperty(repository, node);
- WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
- boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- // change VALUE table
- String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
+ updateValueRecord(repository, prop.getInternalIdentifier());
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
- Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
- conn.prepareStatement(
- "UPDATE JCR_" + (isMultiDb ? "M" : "S") +
"VALUE SET STORAGE_DESC = 'unexisted-desc' 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));
-
+ checkController.repairDataBase("yes");
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
}
/**
* Usecase: value records has no item record.
*/
- public void testDBUsecasesValueRecordHasNoItemRecordSingleDB() throws Exception
+ public void testDBUsecasesValueRecordHasNoItemRecord() throws Exception
{
- checkDBUsecasesValueRecordHasNoItemRecord(helper.createRepository(container, false,
false));
+ checkDBUsecasesValueRecordHasNoItemRecord(helper.createRepository(container,
SINGLE_DB, CACHE_DISABLED));
+ checkDBUsecasesValueRecordHasNoItemRecord(helper.createRepository(container,
MULTI_DB, CACHE_DISABLED));
}
- /**
- * Usecase: value records has no item record.
- */
- public void testDBUsecasesValueRecordHasNoItemRecordMultiDB() throws Exception
- {
- checkDBUsecasesValueRecordHasNoItemRecord(helper.createRepository(container, true,
false));
- }
-
private void checkDBUsecasesValueRecordHasNoItemRecord(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));
+ Node node = addTestNode(repository);
+ PropertyImpl prop = (PropertyImpl)addTestProperty(repository, node);
- WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
- boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- // remove records from item table
- String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
-
- Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
- conn.prepareStatement(
- "ALTER TABLE JCR_" + (isMultiDb ? "M" : "S") +
"VALUE DROP CONSTRAINT JCR_FK_" + (isMultiDb ? "M" : "S")
- + "VALUE_PROPERTY").execute();
- conn.prepareStatement(
- "DELETE FROM JCR_" + (isMultiDb ? "M" : "S") +
"ITEM WHERE ID = '" + (isMultiDb ? "" : wsEntry.getName())
- + prop.getInternalIdentifier() + "'").execute();
-
- conn.commit();
- conn.close();
-
- // repository is inconsistent
+ removeItemRecord(repository, prop.getInternalIdentifier());
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
checkController.repairDataBase("yes");
@@ -826,289 +369,437 @@
/**
* Usecase: properties that have not value record.
*/
- public void testDBUsecasesPropertiesHasNoValueRecordSingleDB() throws Exception
+ public void testDBUsecasesPropertiesHasNoValueRecord() throws Exception
{
- checkDBUsecasesPropertiesHasNoSingleValueRecord(helper.createRepository(container,
false, false));
-
checkDBUsecasesPropertiesHasEmptyMultiValueRecord(helper.createRepository(container,
false, false));
- }
+ checkDBUsecasesPropertiesHasNoSingleValueRecord(helper.createRepository(container,
SINGLE_DB, CACHE_DISABLED));
+
checkDBUsecasesPropertiesHasEmptyMultiValueRecord(helper.createRepository(container,
SINGLE_DB, CACHE_DISABLED));
- /**
- * Usecase: properties that have not value record.
- */
- public void testDBUsecasesPropertiesHasNoValueRecordMultiDB() throws Exception
- {
- checkDBUsecasesPropertiesHasNoSingleValueRecord(helper.createRepository(container,
true, false));
-
checkDBUsecasesPropertiesHasEmptyMultiValueRecord(helper.createRepository(container,
false, false));
+ checkDBUsecasesPropertiesHasNoSingleValueRecord(helper.createRepository(container,
MULTI_DB, CACHE_DISABLED));
+
checkDBUsecasesPropertiesHasEmptyMultiValueRecord(helper.createRepository(container,
MULTI_DB, CACHE_DISABLED));
}
private void checkDBUsecasesPropertiesHasNoSingleValueRecord(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));
+ Node node = addTestNode(repository);
+ PropertyImpl prop = (PropertyImpl)addTestProperty(repository, node);
- WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
- boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- // remove records from value table
- String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
+ removeValueRecord(repository, prop.getInternalIdentifier());
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
- Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
- conn.prepareStatement(
- "DELETE FROM JCR_" + (isMultiDb ? "M" : "S") +
"VALUE WHERE PROPERTY_ID = '"
- + (isMultiDb ? "" : wsEntry.getName()) +
prop.getInternalIdentifier() + "'").execute();
+ checkController.repairDataBase("yes");
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- conn.commit();
- conn.close();
-
- // repository is inconsistent
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
-
}
private void checkDBUsecasesPropertiesHasEmptyMultiValueRecord(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",
new String[]{});
- session.save();
- session.logout();
-
- // repository is consistent
TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- }
+ Node node = addTestNode(repository);
+ node.setProperty("prop", new String[]{});
+ node.save();
- /**
- * Usecase: reference properties without reference records.
- */
- public void testDBUsecasesReferencePropertyWithoutReferenceRecordSingleDB() throws
Exception
- {
-
checkDBUsecasesReferencePropertyWithoutReferenceRecord(helper.createRepository(container,
false, false));
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
/**
* Usecase: reference properties without reference records.
*/
- public void testDBUsecasesReferencePropertyWithoutReferenceRecordMultiDB() throws
Exception
+ public void testDBUsecasesReferencePropertyWithoutReferenceRecord() throws Exception
{
-
checkDBUsecasesReferencePropertyWithoutReferenceRecord(helper.createRepository(container,
true, false));
+
checkDBUsecasesReferencePropertyWithoutReferenceRecord(helper.createRepository(container,
SINGLE_DB,
+ CACHE_DISABLED));
+
checkDBUsecasesReferencePropertyWithoutReferenceRecord(helper.createRepository(container,
MULTI_DB,
+ CACHE_DISABLED));
}
private void
checkDBUsecasesReferencePropertyWithoutReferenceRecord(ManageableRepository repository)
throws Exception
{
- // create repository and add ref property
- SessionImpl session =
- (SessionImpl)repository.login(credentials,
repository.getConfiguration().getSystemWorkspaceName());
- NodeImpl refNode = (NodeImpl)session.getRootNode().addNode("refNode");
- refNode.addMixin("mix:referenceable");
- NodeImpl node = (NodeImpl)session.getRootNode().addNode("testNode");
- PropertyImpl prop = (PropertyImpl)node.setProperty("refProp", refNode);
- session.save();
- session.logout();
-
- // repository is consistent
TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+ Node node = addTestNode(repository);
+ Node node2 = addTestNode(repository);
+ PropertyImpl prop = (PropertyImpl)node2.setProperty("prop", node);
+ node2.save();
- WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
- boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- // remove records from ref table
- String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
+ removeReferenceRecord(repository, prop.getInternalIdentifier());
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
- Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
- conn.prepareStatement(
- "DELETE FROM JCR_" + (isMultiDb ? "M" : "S") +
"REF WHERE PROPERTY_ID = '"
- + (isMultiDb ? "" : wsEntry.getName()) +
prop.getInternalIdentifier() + "'").execute();
+ checkController.repairDataBase("yes");
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+ }
- conn.commit();
- conn.close();
+ /**
+ * Usecase when node doesn't have at primary type property.
+ */
+ public void testDBUsecasesNodeHasNoProperties() throws Exception
+ {
+ checkDBUsecasesNodeHasNotPrimaryTypeProperties(helper.createRepository(container,
SINGLE_DB, CACHE_DISABLED));
+ checkDBUsecasesNodeHasNotPrimaryTypeProperties(helper.createRepository(container,
MULTI_DB, CACHE_DISABLED));
+ }
- // repository is inconsistent
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ private void checkDBUsecasesNodeHasNotPrimaryTypeProperties(ManageableRepository
repository) throws Exception
+ {
+ TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
+ Node node = addTestNode(repository);
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+
+ removePropertyInDB(repository,
(PropertyImpl)node.getProperty("jcr:primaryType"));
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+
+ checkController.repairDataBase("yes");
+
assertTrue(checkController.checkDataBase().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
/**
- * Usecase when node doesn't have at least one property.
+ * Usescase when STORAGE_DESC field in VALUE table is not empty but there is no file
in the value storage.
*/
- public void testDBUsecasesNodeHasNoPropertiesSingleDB() throws Exception
+ public void testValueStorageUsecases() throws Exception
{
- checkDBUsecasesNodeHasNoProperties(helper.createRepository(container, false,
false));
- checkDBUsecasesNodeHasPrimaryTypeProperties(helper.createRepository(container,
false, false));
+ checkValueStorageUsecases(helper.createRepository(container, SINGLE_DB,
CACHE_DISABLED));
+ checkValueStorageUsecases(helper.createRepository(container, MULTI_DB,
CACHE_DISABLED));
}
- /**
- * Usecase when node doesn't have at least one property.
- */
- public void testDBUsecasesNodeHasNoPropertiesMultiDB() throws Exception
+ private void checkValueStorageUsecases(ManageableRepository repository) throws
Exception
{
- checkDBUsecasesNodeHasNoProperties(helper.createRepository(container, true,
false));
- checkDBUsecasesNodeHasPrimaryTypeProperties(helper.createRepository(container,
false, false));
+ TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
+
+ Node node = addTestNode(repository);
+ PropertyImpl prop = (PropertyImpl)node.setProperty("prop", new
FileInputStream(createBLOBTempFile(300)));
+ node.save();
+
+
assertTrue(checkController.checkValueStorage().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+
+ removeFileFromVS(repository, prop.getInternalIdentifier());
+ assertTrue(checkController.checkValueStorage()
+ .startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+
+ checkController.repairValueStorage("yes");
+
assertTrue(checkController.checkValueStorage().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
- private void checkDBUsecasesNodeHasNoProperties(ManageableRepository repository)
throws Exception
+ private Node addTestNode(ManageableRepository repository) throws LoginException,
NoSuchWorkspaceException,
+ RepositoryException
{
- // create repository and add node
SessionImpl session =
(SessionImpl)repository.login(credentials,
repository.getConfiguration().getSystemWorkspaceName());
+
NodeImpl node = (NodeImpl)session.getRootNode().addNode("testNode");
+ node.addMixin("mix:referenceable");
session.save();
- PropertyIterator iter = node.getProperties();
+ return node;
+ }
- // repository is consistent
- TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+ private Property addTestProperty(ManageableRepository repository, Node node) throws
LoginException,
+ NoSuchWorkspaceException, RepositoryException
+ {
+ Property prop = node.setProperty("testProp", "value");
+ node.save();
+ return prop;
+ }
+ private void lockNode(Node node) throws LoginException, NoSuchWorkspaceException,
RepositoryException
+ {
+ node.addMixin("mix:lockable");
+ node.save();
+
+ node.lock(false, false);
+ }
+
+ private void removeNodeInDB(ManageableRepository repository, Node node) throws
SQLException,
+ RepositoryConfigurationException, NamingException,
UnsupportedRepositoryOperationException, RepositoryException
+ {
WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
- boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
- // remove all properties
+ boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
+ String vTable = "JCR_" + (isMultiDb ? "M" : "S") +
"VALUE";
+ String iTable = "JCR_" + (isMultiDb ? "M" : "S") +
"ITEM";
+
+ String nodeId = (isMultiDb ? "" : wsEntry.getName()) + node.getUUID();
+
Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
- while (iter.hasNext())
+
+ ResultSet resultSet =
+ conn.prepareStatement("SELECT * FROM " + iTable + " WHERE
PARENT_ID='" + nodeId + "'").executeQuery();
+ while (resultSet.next())
{
- PropertyImpl prop = (PropertyImpl)iter.nextProperty();
+ String propertyId = resultSet.getString(DBConstants.COLUMN_ID);
- conn.prepareStatement(
- "DELETE FROM JCR_" + (isMultiDb ? "M" : "S") +
"VALUE WHERE PROPERTY_ID = '"
- + (isMultiDb ? "" : wsEntry.getName()) +
prop.getInternalIdentifier() + "'").execute();
- conn.prepareStatement(
- "DELETE FROM JCR_" + (isMultiDb ? "M" : "S") +
"ITEM WHERE ID = '" + (isMultiDb ? "" : wsEntry.getName())
- + prop.getInternalIdentifier() + "'").execute();
+ conn.prepareStatement("DELETE FROM " + vTable + " WHERE
PROPERTY_ID = '" + propertyId + "'").execute();
+ conn.prepareStatement("DELETE FROM " + iTable + " WHERE ID =
'" + propertyId + "'").execute();
}
+ conn.prepareStatement("DELETE FROM " + iTable + " WHERE
ID='" + nodeId + "'").execute();
+
conn.commit();
conn.close();
+ }
- assertFalse(node.getProperties().hasNext());
+ private void removePropertyInDB(ManageableRepository repository, PropertyImpl
property) throws SQLException,
+ RepositoryConfigurationException, NamingException
+ {
+ WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
- session.logout();
+ boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
+ String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
- // repository is inconsistent
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
+ String vTable = "JCR_" + (isMultiDb ? "M" : "S") +
"VALUE";
+ String iTable = "JCR_" + (isMultiDb ? "M" : "S") +
"ITEM";
+
+ String propertyId = (isMultiDb ? "" : wsEntry.getName()) +
property.getInternalIdentifier();
+
+ Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
+
+ conn.prepareStatement("DELETE FROM " + vTable + " WHERE PROPERTY_ID
= '" + propertyId + "'").execute();
+ conn.prepareStatement("DELETE FROM " + iTable + " WHERE ID =
'" + propertyId + "'").execute();
+
+ conn.commit();
+ conn.close();
}
- private void checkDBUsecasesNodeHasPrimaryTypeProperties(ManageableRepository
repository) throws Exception
+ private void removeValueRecord(ManageableRepository repository, String propId) throws
SQLException,
+ RepositoryConfigurationException, NamingException
{
- // create repository and add node
- SessionImpl session =
- (SessionImpl)repository.login(credentials,
repository.getConfiguration().getSystemWorkspaceName());
- NodeImpl node = (NodeImpl)session.getRootNode().addNode("testNode");
- session.save();
+ WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
- PropertyIterator iter = node.getProperties();
+ boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
+ String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
- // repository is consistent
- TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+ String vTable = "JCR_" + (isMultiDb ? "M" : "S") +
"VALUE";
+ propId = (isMultiDb ? "" : wsEntry.getName()) + propId;
+ Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
+
+ conn.prepareStatement("DELETE FROM " + vTable + " WHERE PROPERTY_ID
= '" + propId + "'").execute();
+ conn.prepareStatement(
+ "ALTER TABLE " + vTable + " DROP CONSTRAINT JCR_FK_" +
(isMultiDb ? "M" : "S") + "VALUE_PROPERTY").execute();
+
+ conn.commit();
+ conn.close();
+ }
+
+ private void removeReferenceRecord(ManageableRepository repository, String propId)
throws SQLException,
+ RepositoryConfigurationException, NamingException
+ {
WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
+
boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
+ String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
- // remove all properties
+ String rTable = "JCR_" + (isMultiDb ? "M" : "S") +
"REF";
+
+ propId = (isMultiDb ? "" : wsEntry.getName()) + propId;
+
+ Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
+
+ conn.prepareStatement("DELETE FROM " + rTable + " WHERE PROPERTY_ID
= '" + propId + "'").execute();
+
+ conn.commit();
+ conn.close();
+ }
+
+ private void removeItemRecord(ManageableRepository repository, String propId) throws
SQLException,
+ RepositoryConfigurationException, NamingException
+ {
+ WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
+
+ boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
+ String vTable = "JCR_" + (isMultiDb ? "M" : "S") +
"VALUE";
+ String iTable = "JCR_" + (isMultiDb ? "M" : "S") +
"ITEM";
+
+ propId = (isMultiDb ? "" : wsEntry.getName()) + propId;
+
Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
- while (iter.hasNext())
+
+ conn.prepareStatement(
+ "ALTER TABLE " + vTable + " DROP CONSTRAINT JCR_FK_" +
(isMultiDb ? "M" : "S") + "VALUE_PROPERTY").execute();
+ conn.prepareStatement(
+ "ALTER TABLE " + iTable + " DROP CONSTRAINT JCR_FK_" +
(isMultiDb ? "M" : "S") + "ITEM_PARENT").execute();
+
+ conn.prepareStatement("DELETE FROM " + iTable + " WHERE ID =
'" + propId + "'").execute();
+
+ conn.commit();
+ conn.close();
+ }
+
+ private void assingItsOwnParent(ManageableRepository repository, ItemImpl item) throws
SQLException,
+ RepositoryConfigurationException, NamingException
+ {
+ WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
+ boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
+
+ String iTable = "JCR_" + (isMultiDb ? "M" : "S") +
"ITEM";
+ String itemId = (isMultiDb ? "" : wsEntry.getName()) +
item.getInternalIdentifier();
+
+ 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 " + iTable + " SET
PARENT_ID='" + itemId + "' WHERE ID='" + itemId +
"'").execute();
+
+ conn.commit();
+ conn.close();
+
+ }
+
+ private void clearLockTable(ManageableRepository repository) throws
RepositoryConfigurationException, SQLException,
+ NamingException
+ {
+ WorkspaceEntry workspaceEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
+ LockManagerEntry lockManagerEntry = workspaceEntry.getLockManager();
+
+ String sourceName = null;
+ String queryStatement = null;
+
+ if (helper.ispnCacheEnabled())
{
- PropertyImpl prop = (PropertyImpl)iter.nextProperty();
+ sourceName =
lockManagerEntry.getParameterValue("infinispan-cl-cache.jdbc.datasource");
- if (!prop.getName().equals("jcr:primaryType"))
- {
- conn.prepareStatement(
- "DELETE FROM JCR_" + (isMultiDb ? "M" : "S")
+ "VALUE WHERE PROPERTY_ID = '"
- + (isMultiDb ? "" : wsEntry.getName()) +
prop.getInternalIdentifier() + "'").execute();
+ queryStatement =
+ "DELETE FROM " +
lockManagerEntry.getParameterValue("infinispan-cl-cache.jdbc.table.name") +
"_" + "L"
+ + workspaceEntry.getUniqueName().replace("_",
"").replace("-", "_");
+ }
+ else
+ {
+ sourceName =
lockManagerEntry.getParameterValue(CacheableLockManagerImpl.JBOSSCACHE_JDBC_CL_DATASOURCE);
- conn.prepareStatement(
- "DELETE FROM JCR_" + (isMultiDb ? "M" : "S")
+ "ITEM WHERE ID = '"
- + (isMultiDb ? "" : wsEntry.getName()) +
prop.getInternalIdentifier() + "'").execute();
+ if (lockManagerEntry.getParameterBoolean("jbosscache-shareable"))
+ {
+ queryStatement =
+ "DELETE FROM " +
lockManagerEntry.getParameterValue(CacheableLockManagerImpl.JBOSSCACHE_JDBC_TABLE_NAME)
+ + " WHERE PARENT='/" + workspaceEntry.getUniqueName() +
"/" + CacheableLockManagerImpl.LOCKS + "'";
}
+ else
+ {
+ queryStatement =
+ "DELETE FROM " +
lockManagerEntry.getParameterValue(CacheableLockManagerImpl.JBOSSCACHE_JDBC_TABLE_NAME)
+ + " WHERE PARENT='/" + CacheableLockManagerImpl.LOCKS +
"'";
+ }
}
+ Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
+
+ conn.prepareStatement(queryStatement).execute();
conn.commit();
conn.close();
+ }
- assertTrue(node.getProperties().hasNext());
+ private void indexNode(ManageableRepository repository, Node node, int state)
+ throws UnsupportedRepositoryOperationException, RepositoryException
+ {
+ // Indexing one more document with same UUID
+ List<SearchManager> searchManagers =
+
repository.getWorkspaceContainer(repository.getConfiguration().getSystemWorkspaceName())
+ .getComponentInstancesOfType(SearchManager.class);
- session.logout();
+ PlainChangesLog log = new PlainChangesLogImpl();
- // repository is inconsistent
- assertTrue(checkController.checkDataBase().startsWith(
- RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
- }
+ NodeData data =
+ new TransientNodeData(QPath.makeChildPath(Constants.ROOT_PATH, new
InternalQName("", "testNode")),
+ node.getUUID(), -1, Constants.NT_UNSTRUCTURED, null, 0, null, new
AccessControlList());
- /**
- * Usescase when STORAGE_DESC field in JCR_SVALUE table is not empty but there is no
file in the value storage.
- */
- public void testValueStorageUsecasesSingleDb() throws Exception
- {
- checkValueStorageUsecases(helper.createRepository(container, false, false));
+ TransientPropertyData primaryType =
+ new TransientPropertyData(QPath.makeChildPath(data.getQPath(),
Constants.JCR_PRIMARYTYPE),
+ IdGenerator.generate(), -1, PropertyType.NAME, data.getIdentifier(), false,
new TransientValueData(
+ Constants.NT_UNSTRUCTURED));
+
+ log.add(new ItemState(data, ItemState.ADDED, false, null));
+ log.add(new ItemState(primaryType, ItemState.ADDED, false, null));
+
+ for (SearchManager searchManager : searchManagers)
+ {
+ if (!(searchManager instanceof SystemSearchManager))
+ {
+ searchManager.onSaveItems(log);
+ break;
+ }
+ }
}
- /**
- * Usescase when STORAGE_DESC field in JCR_MVALUE table is not empty but there is no
file in the value storage.
- */
- public void testValueStorageUsecasesMultiDb() throws Exception
+ private void insertPropertyRecord(ManageableRepository repository, String id, String
parentId, String name)
+ throws RepositoryConfigurationException, SQLException, NamingException,
RepositoryException
{
- checkValueStorageUsecases(helper.createRepository(container, true, false));
+ WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
+ boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
+
+ String iTable = "JCR_" + (isMultiDb ? "M" : "S") +
"ITEM";
+ String vTable = "JCR_" + (isMultiDb ? "M" : "S") +
"VALUE";
+
+ String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
+
+ Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
+
+ // add another item with new persisted version
+ String propId = (isMultiDb ? "" : wsEntry.getName()) +
IdGenerator.generate();
+ parentId = (isMultiDb ? "" : wsEntry.getName()) + parentId;
+
+ conn.prepareStatement(
+ "ALTER TABLE " + iTable + " DROP CONSTRAINT JCR_FK_" +
(isMultiDb ? "M" : "S") + "ITEM_PARENT").execute();
+
+ if (isMultiDb)
+ {
+ conn.prepareStatement(
+ "INSERT INTO " + iTable + " VALUES ('" + propId +
"','" + parentId + "','[]" + name
+ + "',1,2,1,NULL,1,FALSE)").execute();
+ }
+ else
+ {
+ conn.prepareStatement(
+ "INSERT INTO " + iTable + " VALUES ('" + propId +
"','" + parentId + "','[]" + name +
"',1,'"
+ + wsEntry.getName() + "',2,1,NULL,1,FALSE)").execute();
+ }
+ conn.prepareStatement("INSERT INTO " + vTable + " VALUES
('10000','data','1','" + propId +
"',NULL)").execute();
+
+ conn.commit();
+ conn.close();
}
- private void checkValueStorageUsecases(ManageableRepository repository) throws
Exception
+ private void updateValueRecord(ManageableRepository repository, String propId)
+ throws RepositoryConfigurationException, SQLException, NamingException
{
- // create repository and add property
- SessionImpl session =
- (SessionImpl)repository.login(credentials,
repository.getConfiguration().getSystemWorkspaceName());
- InputStream in = new FileInputStream(createBLOBTempFile(300));
- PropertyImpl prop =
(PropertyImpl)session.getRootNode().addNode("testNode").setProperty("testProperty",
in);
- session.save();
- in.close();
+ WorkspaceEntry wsEntry =
repository.getConfiguration().getWorkspaceEntries().get(0);
+ boolean isMultiDb =
wsEntry.getContainer().getParameterBoolean(JDBCWorkspaceDataContainer.MULTIDB);
- session.logout();
+ String sourceName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
- // repository is consistent
- TesterRepositoryCheckController checkController = new
TesterRepositoryCheckController(repository);
- assertTrue(checkController.checkValueStorage().startsWith(
- RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
+ String vTable = "JCR_" + (isMultiDb ? "M" : "S") +
"VALUE";
+ propId = (isMultiDb ? "" : wsEntry.getName()) + propId;
- // remove the file from the value storage
+ Connection conn = ((DataSource)new
InitialContext().lookup(sourceName)).getConnection();
+ conn.prepareStatement(
+ "UPDATE " + vTable + " SET STORAGE_DESC =
'unexisted-desc' WHERE PROPERTY_ID = '" + propId +
"'").execute();
+
+ conn.commit();
+ conn.close();
+ }
+
+ private void removeFileFromVS(ManageableRepository repository, String propId)
+ throws RepositoryConfigurationException
+ {
String vsPath =
repository.getConfiguration().getWorkspaceEntries().get(0).getContainer().getValueStorages().get(0)
.getParameterValue(FileValueStorage.PATH);
- File vsFile = new File(vsPath, prop.getInternalIdentifier() + "0");
+ File vsFile = new File(vsPath, propId + "0");
assertTrue(vsFile.exists());
assertTrue(vsFile.delete());
-
- assertTrue(checkController.checkValueStorage()
- .startsWith(RepositoryCheckController.REPORT_NOT_CONSISTENT_MESSAGE));
-
- checkController.repairValueStorage("yes");
-
assertTrue(checkController.checkValueStorage().startsWith(RepositoryCheckController.REPORT_CONSISTENT_MESSAGE));
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/tsm-excludes.properties
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/tsm-excludes.properties 2012-03-02
04:08:02 UTC (rev 5742)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/tsm-excludes.properties 2012-03-02
07:57:14 UTC (rev 5743)
@@ -42,3 +42,4 @@
org.exoplatform.services.jcr.impl.utils.io.TestDirectoryHelper.testCompressEmptyDirectory=compressDirectory
org.exoplatform.services.jcr.impl.utils.io.TestDirectoryHelper.testCompressDirectory=compressDirectory,uncompressDirectory
org.exoplatform.services.jcr.impl.utils.io.TestDirectoryHelper.testCompressFile=compressDirectory,uncompressDirectory
+org.exoplatform.services.jcr.impl.TestRepositoryCheckController.indexNode=onSaveItems
\ No newline at end of file