Author: dkuleshov
Date: 2012-03-12 10:19:33 -0400 (Mon, 12 Mar 2012)
New Revision: 5843
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
Log:
EXOJCR-1773: adopted RepositoryCheckController to new table names
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-03-12
12:51:13 UTC (rev 5842)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-03-12
14:19:33 UTC (rev 5843)
@@ -40,6 +40,7 @@
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.jdbc.JDBCDataContainerConfig.DatabaseStructureType;
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;
@@ -471,61 +472,68 @@
private void initInspectionQueries()
{
+ String itemTableSuffix =
getItemTableSuffix(jdbcDataContainer.containerConfig.dbStructureType);
+ String valueTableSuffix =
getValueTableSuffix(jdbcDataContainer.containerConfig.dbStructureType);
+ String referenceTableSuffix =
getReferenceTableSuffix(jdbcDataContainer.containerConfig.dbStructureType);
+
+ boolean singleDatabase =
+ jdbcDataContainer.containerConfig.dbStructureType ==
JDBCDataContainerConfig.DatabaseStructureType.SINGLE;
+
vsInspectionQuery =
- new InspectionQuery(jdbcDataContainer.containerConfig.multiDb
- ? "select PROPERTY_ID, ORDER_NUM, STORAGE_DESC from JCR_MVALUE where
STORAGE_DESC is not null"
- : "select V.PROPERTY_ID, V.ORDER_NUM, V.STORAGE_DESC from JCR_SVALUE V,
JCR_SITEM I"
- + " where I.CONTAINER_NAME='" +
jdbcDataContainer.containerConfig.containerName
- + "' and V.PROPERTY_ID = I.ID and STORAGE_DESC is not null",
new String[]{
+ new InspectionQuery(singleDatabase ? "select V.PROPERTY_ID, V.ORDER_NUM,
V.STORAGE_DESC from JCR_"
+ + valueTableSuffix + " V, JCR_" + itemTableSuffix + " I"
+ " where I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerConfig.containerName
+ + "' and V.PROPERTY_ID = I.ID and STORAGE_DESC is not null"
+ : "select PROPERTY_ID, ORDER_NUM, STORAGE_DESC from JCR_" +
valueTableSuffix
+ + " where STORAGE_DESC is not null", new String[]{
DBConstants.COLUMN_VPROPERTY_ID, DBConstants.COLUMN_VORDERNUM,
DBConstants.COLUMN_VSTORAGE_DESC},
"Items with value data stored in value storage", new
DummyRepair());
lockInspectionQuery =
- new InspectionQuery(jdbcDataContainer.containerConfig.multiDb
- ? "select distinct PARENT_ID from JCR_MITEM where I_CLASS=2 AND"
- + " (
NAME='[http://www.jcp.org/jcr/1.0]lockOwner' OR
NAME='[http://www.jcp.org/jcr/1.0]lockIsDeep')"
- : "select distinct PARENT_ID from JCR_SITEM WHERE
CONTAINER_NAME='"
- + jdbcDataContainer.containerConfig.containerName + "'"
- + " AND I_CLASS=2 and
(
NAME='[http://www.jcp.org/jcr/1.0]lockOwner'"
- + " OR
NAME='[http://www.jcp.org/jcr/1.0]lockIsDeep')",
new String[]{DBConstants.COLUMN_PARENTID},
- "Items which have jcr:lockOwner and jcr:lockIsDeep properties", new
DummyRepair());
+ new InspectionQuery(singleDatabase ? "select distinct PARENT_ID from
JCR_" + itemTableSuffix
+ + " WHERE CONTAINER_NAME='" +
jdbcDataContainer.containerConfig.containerName + "'"
+ + " AND I_CLASS=2 and
(
NAME='[http://www.jcp.org/jcr/1.0]lockOwner'"
+ + " OR
NAME='[http://www.jcp.org/jcr/1.0]lockIsDeep')" :
"select distinct PARENT_ID from JCR_"
+ + itemTableSuffix + " where I_CLASS=2 AND"
+ + " (
NAME='[http://www.jcp.org/jcr/1.0]lockOwner' OR
NAME='[http://www.jcp.org/jcr/1.0]lockIsDeep')",
+ new String[]{DBConstants.COLUMN_PARENTID}, "Items which have
jcr:lockOwner and jcr:lockIsDeep properties",
+ new DummyRepair());
// ITEM tables
- itemsInspectionQuery.add(new
InspectionQuery(jdbcDataContainer.containerConfig.multiDb
- ? "select * from JCR_MITEM I where NOT EXISTS(select * from JCR_MITEM P
where P.ID = I.PARENT_ID)"
- : "select * from JCR_SITEM I where I.CONTAINER_NAME='" +
jdbcDataContainer.containerConfig.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
RootAsParentAssigner(jdbcDataContainer.getConnectionFactory())));
+ itemsInspectionQuery.add(new InspectionQuery(singleDatabase ? "select * from
JCR_" + itemTableSuffix
+ + " I where I.CONTAINER_NAME='" +
jdbcDataContainer.containerConfig.containerName
+ + "' and NOT EXISTS(select * from JCR_" + itemTableSuffix + "
P where P.ID = I.PARENT_ID)"
+ : "select * from JCR_" + itemTableSuffix + " I where NOT
EXISTS(select * from JCR_" + itemTableSuffix
+ + " 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 RootAsParentAssigner(jdbcDataContainer.getConnectionFactory())));
- itemsInspectionQuery
- .add(new InspectionQueryFilteredMultivaluedProperties(
- jdbcDataContainer.containerConfig.multiDb
- ? "select * from JCR_MITEM P where P.I_CLASS=2 and P.P_MULTIVALUED=?
and NOT EXISTS( select * from JCR_MVALUE V "
- + "where V.PROPERTY_ID=P.ID)" : "select * from JCR_SITEM
P where P.CONTAINER_NAME='"
- + jdbcDataContainer.containerConfig.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 PropertyRemover(jdbcDataContainer.getConnectionFactory(),
nodeTypeManager)));
+ itemsInspectionQuery.add(new
InspectionQueryFilteredMultivaluedProperties(singleDatabase ? "select * from
JCR_"
+ + itemTableSuffix + " P where P.CONTAINER_NAME='" +
jdbcDataContainer.containerConfig.containerName
+ + "' and P.I_CLASS=2" + " and P.P_MULTIVALUED=? and NOT
EXISTS( select * from JCR_" + valueTableSuffix
+ + " V where V.PROPERTY_ID=P.ID)" : "select * from JCR_" +
itemTableSuffix
+ + " P where P.I_CLASS=2 and P.P_MULTIVALUED=? and NOT EXISTS( select * from
JCR_" + valueTableSuffix + " 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 PropertyRemover(
+ jdbcDataContainer.getConnectionFactory(), nodeTypeManager)));
- itemsInspectionQuery.add(new
InspectionQuery(jdbcDataContainer.containerConfig.multiDb
- ? "select * from JCR_MITEM N where N.I_CLASS=1 and NOT EXISTS "
- + "(select * from JCR_MITEM P where P.I_CLASS=2 and P.PARENT_ID=N.ID
"
- + "and
P.NAME='[http://www.jcp.org/jcr/1.0]primaryType')"
- : "select * from JCR_SITEM N where N.CONTAINER_NAME='" +
jdbcDataContainer.containerConfig.containerName
- + "' and N.I_CLASS=1 and NOT EXISTS (select * from JCR_SITEM P
"
- + "where P.I_CLASS=2 and P.PARENT_ID=N.ID and
P.NAME='[http://www.jcp.org/jcr/1.0]primaryType' "
- + "and P.CONTAINER_NAME='" +
jdbcDataContainer.containerConfig.containerName + "')", new String[]{
- DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME},
+ itemsInspectionQuery.add(new InspectionQuery(singleDatabase ? "select * from
JCR_" + itemTableSuffix
+ + " N where N.CONTAINER_NAME='" +
jdbcDataContainer.containerConfig.containerName
+ + "' and N.I_CLASS=1 and NOT EXISTS (select * from JCR_" +
itemTableSuffix + " P "
+ + "where P.I_CLASS=2 and P.PARENT_ID=N.ID and
P.NAME='[http://www.jcp.org/jcr/1.0]primaryType' "
+ + "and P.CONTAINER_NAME='" +
jdbcDataContainer.containerConfig.containerName + "')" : "select * from
JCR_"
+ + itemTableSuffix + " N where N.I_CLASS=1 and NOT EXISTS " +
"(select * from JCR_" + itemTableSuffix
+ + " P where P.I_CLASS=2 and P.PARENT_ID=N.ID " + "and
P.NAME='[http://www.jcp.org/jcr/1.0]primaryType')",
+ new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID,
DBConstants.COLUMN_NAME},
"A node that doesn't have primary type property", new
NodeRemover(jdbcDataContainer.getConnectionFactory(),
nodeTypeManager)));
- itemsInspectionQuery.add(new
InspectionQuery(jdbcDataContainer.containerConfig.multiDb
- ? "select * from JCR_MVALUE V where NOT EXISTS(select * from JCR_MITEM P
"
- + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)"
- : "select * from JCR_SVALUE V where NOT EXISTS(select * from JCR_SITEM P
"
- + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)", new
String[]{DBConstants.COLUMN_ID,
+ itemsInspectionQuery.add(new InspectionQuery(singleDatabase ? "select * from
JCR_" + valueTableSuffix
+ + " V where NOT EXISTS(select * from JCR_" + itemTableSuffix + "
P "
+ + "where V.PROPERTY_ID = P.ID and P.I_CLASS=2)" : "select * from
JCR_" + valueTableSuffix
+ + " V where NOT EXISTS(select * from JCR_" + itemTableSuffix + "
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 ValueRecordsRemover(jdbcDataContainer.getConnectionFactory(),
jdbcDataContainer.containerConfig.containerName,
jdbcDataContainer.containerConfig.multiDb)));
@@ -535,64 +543,107 @@
if
(jdbcDataContainer.containerConfig.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE))
{
statement =
- jdbcDataContainer.containerConfig.multiDb
- ? "select * from JCR_MVALUE where (STORAGE_DESC is not null and not
DATA like null)"
- : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID =
I.ID and I.CONTAINER_NAME='"
- + jdbcDataContainer.containerConfig.containerName
- + "' AND ((STORAGE_DESC is not null and not DATA like
null))";
+ singleDatabase ? "select V.* from JCR_" + valueTableSuffix + "
V, JCR_" + itemTableSuffix
+ + " I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerConfig.containerName
+ + "' AND ((STORAGE_DESC is not null and not DATA like
null))" : "select * from JCR_" + valueTableSuffix
+ + " where (STORAGE_DESC is not null and not DATA like null)";
}
else if
(jdbcDataContainer.containerConfig.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLE)
||
jdbcDataContainer.containerConfig.dbDialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLEOCI))
{
statement =
- jdbcDataContainer.containerConfig.multiDb
- ? "select * from JCR_MVALUE where (STORAGE_DESC is not null and DATA
is not null)"
- : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID =
I.ID and I.CONTAINER_NAME='"
- + jdbcDataContainer.containerConfig.containerName
- + "' AND (STORAGE_DESC is not null and DATA is not
null)";
+ singleDatabase ? "select V.* from JCR_" + valueTableSuffix + "
V, JCR_" + itemTableSuffix
+ + " I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerConfig.containerName
+ + "' AND (STORAGE_DESC is not null and DATA is not null)" :
"select * from JCR_" + valueTableSuffix
+ + " where (STORAGE_DESC is not null and DATA is not null)";
}
else
{
statement =
- jdbcDataContainer.containerConfig.multiDb
- ? "select * from JCR_MVALUE where (STORAGE_DESC is not null and DATA
is not null)"
- : "select V.* from JCR_SVALUE V, JCR_SITEM I where V.PROPERTY_ID =
I.ID and I.CONTAINER_NAME='"
- + jdbcDataContainer.containerConfig.containerName
- + "' AND ((STORAGE_DESC is not null and DATA is not
null))";
+ singleDatabase ? "select V.* from JCR_" + valueTableSuffix + "
V, JCR_" + itemTableSuffix
+ + " I where V.PROPERTY_ID = I.ID and I.CONTAINER_NAME='"
+ + jdbcDataContainer.containerConfig.containerName
+ + "' AND ((STORAGE_DESC is not null and DATA is not null))"
: "select * from JCR_" + valueTableSuffix
+ + " where (STORAGE_DESC is not null and DATA is not null)";
}
itemsInspectionQuery.add(new InspectionQuery(statement, new
String[]{DBConstants.COLUMN_ID},
"Incorrect VALUE records. Both fields STORAGE_DESC and DATA contain not
null value.", new DummyRepair()));
- itemsInspectionQuery.add(new
InspectionQuery(jdbcDataContainer.containerConfig.multiDb
- ? "select * from JCR_MITEM I where I.ID = I.PARENT_ID and I.NAME <>
'" + Constants.ROOT_PARENT_NAME + "'"
- : "select * from JCR_SITEM I where I.ID = I.PARENT_ID and
I.CONTAINER_NAME='"
- + jdbcDataContainer.containerConfig.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
RootAsParentAssigner(jdbcDataContainer.getConnectionFactory())));
+ itemsInspectionQuery.add(new InspectionQuery(singleDatabase ? "select * from
JCR_" + itemTableSuffix
+ + " I where I.ID = I.PARENT_ID and I.CONTAINER_NAME='" +
jdbcDataContainer.containerConfig.containerName
+ + "' and I.NAME <> '" + Constants.ROOT_PARENT_NAME +
"'" : "select * from JCR_" + itemTableSuffix
+ + " I where I.ID = I.PARENT_ID 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 RootAsParentAssigner(jdbcDataContainer.getConnectionFactory())));
- itemsInspectionQuery
- .add(new InspectionQuery(
- jdbcDataContainer.containerConfig.multiDb
- ? "select * from JCR_MITEM I where EXISTS (select * from JCR_MITEM
J"
- + " WHERE I.PARENT_ID = J.PARENT_ID AND I.NAME = J.NAME and
I.I_INDEX = J.I_INDEX and I.I_CLASS = J.I_CLASS"
- + " and I.VERSION != J.VERSION)"
- : "select * from JCR_SITEM I where I.CONTAINER_NAME='"
- + jdbcDataContainer.containerConfig.containerName
- + "' and EXISTS (select * from JCR_SITEM J WHERE
I.CONTAINER_NAME = J.CONTAINER_NAME and"
- + " I.PARENT_ID = J.PARENT_ID AND I.NAME = J.NAME and I.I_INDEX =
J.I_INDEX and I.I_CLASS = J.I_CLASS"
- + " and I.VERSION != J.VERSION)",
- new String[]{DBConstants.COLUMN_ID, DBConstants.COLUMN_PARENTID,
DBConstants.COLUMN_NAME,
- DBConstants.COLUMN_VERSION, DBConstants.COLUMN_CLASS,
DBConstants.COLUMN_INDEX},
- "Several versions of same item.", new
EarlierVersionsRemover(jdbcDataContainer.getConnectionFactory())));
+ itemsInspectionQuery.add(new InspectionQuery(singleDatabase ? "select * from
JCR_" + itemTableSuffix
+ + " I where I.CONTAINER_NAME='" +
jdbcDataContainer.containerConfig.containerName
+ + "' and EXISTS (select * from JCR_" + itemTableSuffix + " J
WHERE I.CONTAINER_NAME = J.CONTAINER_NAME and"
+ + " I.PARENT_ID = J.PARENT_ID AND I.NAME = J.NAME and I.I_INDEX = J.I_INDEX
and I.I_CLASS = J.I_CLASS"
+ + " and I.VERSION != J.VERSION)" : "select * from JCR_" +
itemTableSuffix
+ + " I where EXISTS (select * from JCR_" + itemTableSuffix + "
J"
+ + " WHERE I.PARENT_ID = J.PARENT_ID AND I.NAME = J.NAME and I.I_INDEX =
J.I_INDEX and I.I_CLASS = J.I_CLASS"
+ + " and I.VERSION != J.VERSION)", 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
EarlierVersionsRemover(jdbcDataContainer.getConnectionFactory())));
- itemsInspectionQuery.add(new
InspectionQuery(jdbcDataContainer.containerConfig.multiDb
- ? "select * from JCR_MITEM P, JCR_MVALUE V where P.ID=V.PROPERTY_ID and
P.P_TYPE=9 and NOT EXISTS "
- + "(select * from JCR_MREF R where P.ID=R.PROPERTY_ID)"
- : "select * from JCR_SITEM P, JCR_SVALUE V where P.ID=V.PROPERTY_ID and
P.CONTAINER_NAME='"
- + jdbcDataContainer.containerConfig.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
PropertyRemover(
- jdbcDataContainer.getConnectionFactory(), nodeTypeManager)));
+ itemsInspectionQuery.add(new InspectionQuery(singleDatabase ? "select * from
JCR_" + itemTableSuffix + " P, JCR_"
+ + valueTableSuffix + " V where P.ID=V.PROPERTY_ID and
P.CONTAINER_NAME='"
+ + jdbcDataContainer.containerConfig.containerName + "' and P.P_TYPE=9
and NOT EXISTS (select * from JCR_"
+ + referenceTableSuffix + " R where P.ID=R.PROPERTY_ID)" : "select
* from JCR_" + itemTableSuffix + " P, JCR_"
+ + valueTableSuffix + " V where P.ID=V.PROPERTY_ID and P.P_TYPE=9 and NOT
EXISTS " + "(select * from JCR_"
+ + referenceTableSuffix + " R where P.ID=R.PROPERTY_ID)", new
String[]{DBConstants.COLUMN_ID,
+ DBConstants.COLUMN_PARENTID, DBConstants.COLUMN_NAME}, "Reference
properties without reference records",
+ new PropertyRemover(jdbcDataContainer.getConnectionFactory(),
nodeTypeManager)));
}
+
+ private String getItemTableSuffix(DatabaseStructureType dbStructureType)
+ {
+ if (dbStructureType == DatabaseStructureType.MULTI)
+ {
+ return "MITEM";
+ }
+ else if (dbStructureType == DatabaseStructureType.SINGLE)
+ {
+ return "SITEM";
+ }
+ else
+ {
+ return "I" + jdbcDataContainer.containerConfig.dbTableSuffix;
+ }
+ }
+
+ private String getValueTableSuffix(DatabaseStructureType dbStructureType)
+ {
+ if (dbStructureType == DatabaseStructureType.MULTI)
+ {
+ return "MVALUE";
+ }
+ else if (dbStructureType == DatabaseStructureType.SINGLE)
+ {
+ return "SVALUE";
+ }
+ else
+ {
+ return "V" + jdbcDataContainer.containerConfig.dbTableSuffix;
+ }
+ }
+
+ private String getReferenceTableSuffix(DatabaseStructureType dbStructureType)
+ {
+ if (dbStructureType == DatabaseStructureType.MULTI)
+ {
+ return "MREF";
+ }
+ else if (dbStructureType == DatabaseStructureType.SINGLE)
+ {
+ return "SREF";
+ }
+ else
+ {
+ return "R" + jdbcDataContainer.containerConfig.dbTableSuffix;
+ }
+ }
}