From do-not-reply at jboss.org Wed Feb 29 08:32:40 2012 Content-Type: multipart/mixed; boundary="===============3061239509747095090==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: exo-jcr-commits at lists.jboss.org Subject: [exo-jcr-commits] exo-jcr SVN: r5714 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: storage/jdbc and 1 other directory. Date: Wed, 29 Feb 2012 08:32:37 -0500 Message-ID: <201202291332.q1TDWbS0027009@svn01.web.mwc.hst.phx2.redhat.com> --===============3061239509747095090== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: tolusha Date: 2012-02-29 08:32:36 -0500 (Wed, 29 Feb 2012) New Revision: 5714 Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/= jcr/impl/checker/AbstractInconsistencyRepair.java jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/= jcr/impl/checker/AssignerRootAsParent.java jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/= jcr/impl/checker/RemoverEarlierVersions.java Removed: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/= jcr/impl/checker/AssignRootAsParentRepair.java Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/= jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java Log: EXOJCR-1762: auto-repair for DB inconsistency Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/servi= ces/jcr/impl/checker/AbstractInconsistencyRepair.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services= /jcr/impl/checker/AbstractInconsistencyRepair.java = (rev 0) +++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services= /jcr/impl/checker/AbstractInconsistencyRepair.java 2012-02-29 13:32:36 UTC = (rev 5714) @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2012 eXo Platform SAS. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.exoplatform.services.jcr.impl.checker; + +import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnectio= n; +import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageC= onnectionFactory; +import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection; +import org.exoplatform.services.log.ExoLogger; +import org.exoplatform.services.log.Log; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import javax.jcr.RepositoryException; + + +/** + * @author Anatoliy Bazko + * @version $Id: AbstractInconsistencyRepair.java 34360 2009-07-22 23:58:5= 9Z tolusha $ + */ +public abstract class AbstractInconsistencyRepair implements Inconsistency= Repair +{ + protected static final Log LOG =3D ExoLogger.getLogger("exo.jcr.compone= nt.core.AbstractInconsistencyRepair"); + + protected final WorkspaceStorageConnectionFactory connFactory; + + AbstractInconsistencyRepair(WorkspaceStorageConnectionFactory connFacto= ry) + { + this.connFactory =3D connFactory; + } + + /** + * {@inheritDoc} + */ + public void doRepair(ResultSet resultSet) throws SQLException + { + WorkspaceStorageConnection conn =3D null; + try + { + conn =3D connFactory.openConnection(); + if (!(conn instanceof JDBCStorageConnection)) + { + throw new SQLException("Connection is instance of " + conn); + } + + repairInternally((JDBCStorageConnection)conn, resultSet); + + conn.commit(); + } + catch (RepositoryException e) + { + rollback(conn); + throw new SQLException(e); + } + catch (SQLException e) + { + rollback(conn); + throw e; + } + finally + { + closeConnection(conn); + } + } + + abstract void repairInternally(JDBCStorageConnection conn, ResultSet re= sultSet) throws SQLException; + + protected void closeConnection(WorkspaceStorageConnection conn) + { + try + { + conn.close(); + } + catch (IllegalStateException e) + { + LOG.error("Can not close connection", e); + } + catch (RepositoryException e) + { + LOG.error("Can not close connection", e); + } + } + + protected void rollback(WorkspaceStorageConnection conn) + { + try + { + if (conn !=3D null) + { + conn.rollback(); + } + } + catch (IllegalStateException e) + { + LOG.error("Can not rollback connection", e); + } + catch (RepositoryException e) + { + LOG.error("Can not rollback connection", e); + } + } + +} Deleted: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/ser= vices/jcr/impl/checker/AssignRootAsParentRepair.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services= /jcr/impl/checker/AssignRootAsParentRepair.java 2012-02-29 12:52:01 UTC (re= v 5713) +++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services= /jcr/impl/checker/AssignRootAsParentRepair.java 2012-02-29 13:32:36 UTC (re= v 5714) @@ -1,220 +0,0 @@ -/* - * Copyright (C) 2012 eXo Platform SAS. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.exoplatform.services.jcr.impl.checker; - -import org.exoplatform.services.jcr.datamodel.IllegalNameException; -import org.exoplatform.services.jcr.datamodel.InternalQName; -import org.exoplatform.services.jcr.datamodel.NodeData; -import org.exoplatform.services.jcr.datamodel.PropertyData; -import org.exoplatform.services.jcr.datamodel.QPath; -import org.exoplatform.services.jcr.datamodel.QPathEntry; -import org.exoplatform.services.jcr.datamodel.ValueData; -import org.exoplatform.services.jcr.impl.Constants; -import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData; -import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData; -import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants; -import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnectio= n; -import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageC= onnectionFactory; -import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection; -import org.exoplatform.services.log.ExoLogger; -import org.exoplatform.services.log.Log; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; - -import javax.jcr.InvalidItemStateException; -import javax.jcr.RepositoryException; - -/** - * @author Anatoliy Bazko - * @version $Id: AssignRootAsParentRepair.java 34360 2009-07-22 23:58:59Z = tolusha $ - */ -public class AssignRootAsParentRepair implements InconsistencyRepair -{ - - protected static final Log LOG =3D ExoLogger.getLogger("exo.jcr.compone= nt.core.AssignRootAsParentRepair"); - - protected final WorkspaceStorageConnectionFactory connFactory; - - public AssignRootAsParentRepair(WorkspaceStorageConnectionFactory connF= actory) - { - this.connFactory =3D connFactory; - } - - /** - * {@inheritDoc} - */ - public void doRepair(ResultSet resultSet) throws SQLException - { - WorkspaceStorageConnection conn =3D null; - try - { - conn =3D connFactory.openConnection(); - if (!(conn instanceof JDBCStorageConnection)) - { - throw new SQLException("Connection is instance of " + conn); - } - - if (resultSet.getInt(DBConstants.COLUMN_CLASS) =3D=3D 1) - { - repairNode((JDBCStorageConnection)conn, resultSet); - } - else - { - repairProperty((JDBCStorageConnection)conn, resultSet); - } - - conn.commit(); - } - catch (RepositoryException e) - { - rollback(conn); - throw new SQLException(e); - } - finally - { - closeConnection(conn); - } - } - - private void repairProperty(JDBCStorageConnection conn, ResultSet resul= tSet) throws SQLException - { - try - { - String propertyId =3D exctractId(resultSet); - QPath path =3D QPath.parse(resultSet.getString(DBConstants.COLUMN= _NAME)); - - PropertyData data =3D new TransientPropertyData(path, propertyId,= 0, 0, null, false, new ArrayList()); - - 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 =3D exctractId(resultSet); - int orderNum =3D resultSet.getInt(DBConstants.COLUMN_NORDERNUM); - int version =3D resultSet.getInt(DBConstants.COLUMN_VERSION); - QPath path =3D - new QPath(new QPathEntry[]{new QPathEntry( - InternalQName.parse(resultSet.getString(DBConstants.COLUMN_= NAME)), - resultSet.getInt(DBConstants.COLUMN_INDEX))}); - - NodeData data =3D - new TransientNodeData(path, nodeId, version, null, null, order= Num, Constants.ROOT_UUID, null); - = - conn.rename(data); - } - catch (IllegalStateException e) - { - throw new SQLException(e); - } - catch (RepositoryException e) - { - throw new SQLException(e); - } - catch (IllegalNameException e) - { - throw new SQLException(e); - } - } - - private void closeConnection(WorkspaceStorageConnection conn) throws SQ= LException - { - try - { - conn.close(); - } - catch (IllegalStateException e) - { - throw new SQLException(e); - } - catch (RepositoryException e) - { - throw new SQLException(e); - } - } - - private void rollback(WorkspaceStorageConnection conn) - { - try - { - if (conn !=3D null) - { - conn.rollback(); - } - } - catch (IllegalStateException e) - { - LOG.error("Can not rollback", e); - } - catch (RepositoryException e) - { - LOG.error("Can not rollback", e); - } - } - - private String exctractId(ResultSet resultSet) throws SQLException - { - String containerName =3D ""; - try - { - containerName =3D resultSet.getString(DBConstants.CONTAINER_NAME); - } - catch (SQLException e) - { - } - - return resultSet.getString(DBConstants.COLUMN_ID).substring(containe= rName.length()); - } - - private String concatId(ResultSet resultSet, String id) throws SQLExcep= tion - { - String containerName =3D ""; - try - { - containerName =3D resultSet.getString(DBConstants.CONTAINER_NAME); - } - catch (SQLException e) - { - } - - return containerName + id; - } - -} Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/servi= ces/jcr/impl/checker/AssignerRootAsParent.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services= /jcr/impl/checker/AssignerRootAsParent.java (rev 0) +++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services= /jcr/impl/checker/AssignerRootAsParent.java 2012-02-29 13:32:36 UTC (rev 57= 14) @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2012 eXo Platform SAS. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.exoplatform.services.jcr.impl.checker; + +import org.exoplatform.services.jcr.datamodel.IllegalNameException; +import org.exoplatform.services.jcr.datamodel.InternalQName; +import org.exoplatform.services.jcr.datamodel.NodeData; +import org.exoplatform.services.jcr.datamodel.PropertyData; +import org.exoplatform.services.jcr.datamodel.QPath; +import org.exoplatform.services.jcr.datamodel.QPathEntry; +import org.exoplatform.services.jcr.datamodel.ValueData; +import org.exoplatform.services.jcr.impl.Constants; +import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData; +import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData; +import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants; +import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnectio= n; +import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageC= onnectionFactory; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +import javax.jcr.InvalidItemStateException; +import javax.jcr.RepositoryException; + +/** + * @author Anatoliy Bazko + * @version $Id: AssignRootAsParentRepair.java 34360 2009-07-22 23:58:59Z = tolusha $ + */ +public class AssignerRootAsParent extends AbstractInconsistencyRepair +{ + + public AssignerRootAsParent(WorkspaceStorageConnectionFactory connFacto= ry) + { + super(connFactory); + } + + /** + * {@inheritDoc} + */ + protected void repairInternally(JDBCStorageConnection conn, ResultSet r= esultSet) throws SQLException + { + if (resultSet.getInt(DBConstants.COLUMN_CLASS) =3D=3D 1) + { + repairNode(conn, resultSet); + } + else + { + repairProperty(conn, resultSet); + } + } + + private void repairProperty(JDBCStorageConnection conn, ResultSet resul= tSet) throws SQLException + { + try + { + String propertyId =3D exctractId(resultSet); + QPath path =3D QPath.parse(resultSet.getString(DBConstants.COLUMN= _NAME)); + + PropertyData data =3D new TransientPropertyData(path, propertyId,= 0, 0, null, false, new ArrayList()); + + 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 =3D exctractId(resultSet); + int orderNum =3D resultSet.getInt(DBConstants.COLUMN_NORDERNUM); + int version =3D resultSet.getInt(DBConstants.COLUMN_VERSION); + QPath path =3D + new QPath(new QPathEntry[]{new QPathEntry( + InternalQName.parse(resultSet.getString(DBConstants.COLUMN_= NAME)), + resultSet.getInt(DBConstants.COLUMN_INDEX))}); + + NodeData data =3D + new TransientNodeData(path, nodeId, version, null, null, order= Num, Constants.ROOT_UUID, null); + = + conn.rename(data); + } + catch (IllegalStateException e) + { + throw new SQLException(e); + } + catch (RepositoryException e) + { + throw new SQLException(e); + } + catch (IllegalNameException e) + { + throw new SQLException(e); + } + } + + private String exctractId(ResultSet resultSet) throws SQLException + { + String containerName =3D ""; + try + { + containerName =3D resultSet.getString(DBConstants.CONTAINER_NAME); + } + catch (SQLException e) + { + } + + return resultSet.getString(DBConstants.COLUMN_ID).substring(containe= rName.length()); + } + + private String concatId(ResultSet resultSet, String id) throws SQLExcep= tion + { + String containerName =3D ""; + try + { + containerName =3D resultSet.getString(DBConstants.CONTAINER_NAME); + } + catch (SQLException e) + { + } + + return containerName + id; + } + +} Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/servi= ces/jcr/impl/checker/RemoverEarlierVersions.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services= /jcr/impl/checker/RemoverEarlierVersions.java (rev = 0) +++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services= /jcr/impl/checker/RemoverEarlierVersions.java 2012-02-29 13:32:36 UTC (rev = 5714) @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2012 eXo Platform SAS. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.exoplatform.services.jcr.impl.checker; + +import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnectio= n; +import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageC= onnectionFactory; + +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * @author Anatoliy Bazko + * @version $Id: RemoveEarlierVersions.java 34360 2009-07-22 23:58:59Z tol= usha $ + */ +public class RemoverEarlierVersions extends AbstractInconsistencyRepair +{ + + /** + * RemoveEarlierVersions constructor. + */ + public RemoverEarlierVersions(WorkspaceStorageConnectionFactory connFac= tory) + { + super(connFactory); + } + + /** + * {@inheritDoc} + */ + protected void repairInternally(JDBCStorageConnection conn, ResultSet r= esultSet) throws SQLException + { + } +} Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/se= rvices/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services= /jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 12= :52:01 UTC (rev 5713) +++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services= /jcr/impl/storage/jdbc/JDBCWorkspaceDataContainerChecker.java 2012-02-29 13= :32:36 UTC (rev 5714) @@ -224,8 +224,19 @@ logBrokenObjectAndSetInconsistency(getBrokenObject(re= sultSet, query.getFieldNames())); if (autoRepair) { - query.getRepair().doRepair(resultSet); - logComment("Inconsistency has been fixed"); + try + { + query.getRepair().doRepair(resultSet); + logComment("Inconsistency has been fixed"); + } + catch (SQLException e) + { + if (LOG.isTraceEnabled()) + { + LOG.trace(e.getMessage(), e); + } + } + } } while (resultSet.next()); --===============3061239509747095090==--