X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.jcr%2Fsrc%2Forg%2Fargeo%2Fjackrabbit%2FJackrabbitDataModelMigration.java;h=838446d5cb355fe3c491b54d36f340dfcb0eb42d;hb=215480a865603e0090c43114541441ac1586b379;hp=8fedcf5217c886acb09ddbb3c70fc86d92e48ed8;hpb=77a5498dd5d10d2442127022efd6501a7dbddbae;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.jcr/src/org/argeo/jackrabbit/JackrabbitDataModelMigration.java b/org.argeo.jcr/src/org/argeo/jackrabbit/JackrabbitDataModelMigration.java index 8fedcf521..838446d5c 100644 --- a/org.argeo.jcr/src/org/argeo/jackrabbit/JackrabbitDataModelMigration.java +++ b/org.argeo.jcr/src/org/argeo/jackrabbit/JackrabbitDataModelMigration.java @@ -1,45 +1,29 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.argeo.jackrabbit; +import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; +import java.net.URL; +import javax.jcr.RepositoryException; import javax.jcr.Session; import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.jackrabbit.commons.cnd.CndImporter; +import org.apache.jackrabbit.commons.cnd.ParseException; import org.apache.jackrabbit.core.config.RepositoryConfig; -import org.argeo.jcr.ArgeoJcrException; +import org.argeo.jcr.JcrException; import org.argeo.jcr.JcrCallback; import org.argeo.jcr.JcrUtils; -import org.springframework.core.io.Resource; /** Migrate the data in a Jackrabbit repository. */ @Deprecated -public class JackrabbitDataModelMigration implements - Comparable { - private final static Log log = LogFactory - .getLog(JackrabbitDataModelMigration.class); +public class JackrabbitDataModelMigration implements Comparable { +// private final static Log log = LogFactory.getLog(JackrabbitDataModelMigration.class); private String dataModelNodePath; private String targetVersion; - private Resource migrationCnd; + private URL migrationCnd; private JcrCallback dataModification; /** @@ -55,8 +39,7 @@ public class JackrabbitDataModelMigration implements try { // check if already migrated if (!session.itemExists(dataModelNodePath)) { - log.warn("Node " + dataModelNodePath - + " does not exist: nothing to migrate."); +// log.warn("Node " + dataModelNodePath + " does not exist: nothing to migrate."); return false; } // Node dataModelNode = session.getNode(dataModelNodePath); @@ -72,10 +55,10 @@ public class JackrabbitDataModelMigration implements // apply transitional CND if (migrationCnd != null) { - reader = new InputStreamReader(migrationCnd.getInputStream()); + reader = new InputStreamReader(migrationCnd.openStream()); CndImporter.registerNodeTypes(reader, session, true); session.save(); - log.info("Registered migration node types from " + migrationCnd); +// log.info("Registered migration node types from " + migrationCnd); } // modify data @@ -85,14 +68,17 @@ public class JackrabbitDataModelMigration implements session.save(); long duration = System.currentTimeMillis() - begin; - log.info("Migration of data model " + dataModelNodePath + " to " - + targetVersion + " performed in " + duration + "ms"); +// log.info("Migration of data model " + dataModelNodePath + " to " + targetVersion + " performed in " +// + duration + "ms"); return true; - } catch (Exception e) { + } catch (RepositoryException e) { JcrUtils.discardQuietly(session); - throw new ArgeoJcrException("Migration of data model " - + dataModelNodePath + " to " + targetVersion + " failed.", - e); + throw new JcrException( + "Migration of data model " + dataModelNodePath + " to " + targetVersion + " failed.", e); + } catch (ParseException | IOException e) { + JcrUtils.discardQuietly(session); + throw new RuntimeException( + "Migration of data model " + dataModelNodePath + " to " + targetVersion + " failed.", e); } finally { JcrUtils.logoutQuietly(session); IOUtils.closeQuietly(reader); @@ -109,11 +95,11 @@ public class JackrabbitDataModelMigration implements try { String customeNodeTypesPath = "/nodetypes/custom_nodetypes.xml"; // FIXME causes weird error in Eclipse - //repositoryConfig.getFileSystem().deleteFile(customeNodeTypesPath); - if (log.isDebugEnabled()) - log.debug("Cleared " + customeNodeTypesPath); - } catch (Exception e) { - throw new ArgeoJcrException("Cannot clear caches", e); +// repositoryConfig.getFileSystem().deleteFile(customeNodeTypesPath); +// if (log.isDebugEnabled()) +// log.debug("Cleared " + customeNodeTypesPath); + } catch (RuntimeException e) { + throw e; } // File customNodeTypes = new File(home.getPath() @@ -134,11 +120,9 @@ public class JackrabbitDataModelMigration implements public int compareTo(JackrabbitDataModelMigration dataModelMigration) { // TODO make ordering smarter if (dataModelNodePath.equals(dataModelMigration.dataModelNodePath)) - return compareVersions(targetVersion, - dataModelMigration.targetVersion); + return compareVersions(targetVersion, dataModelMigration.targetVersion); else - return dataModelNodePath - .compareTo(dataModelMigration.dataModelNodePath); + return dataModelNodePath.compareTo(dataModelMigration.dataModelNodePath); } @Override @@ -163,7 +147,7 @@ public class JackrabbitDataModelMigration implements this.targetVersion = targetVersion; } - public void setMigrationCnd(Resource migrationCnd) { + public void setMigrationCnd(URL migrationCnd) { this.migrationCnd = migrationCnd; }