jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r801983 - in /jackrabbit/branches/1.x: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/ jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ jackrabbit-s...
Date Fri, 07 Aug 2009 13:05:18 GMT
Author: jukka
Date: Fri Aug  7 13:05:18 2009
New Revision: 801983

URL: http://svn.apache.org/viewvc?rev=801983&view=rev
Log:
1.x: Merged revisions 801968 and 801973 (JCR-442)

Modified:
    jackrabbit/branches/1.x/   (props changed)
    jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryCopier.java
    jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java
    jackrabbit/branches/1.x/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java
    jackrabbit/branches/1.x/jackrabbit-standalone/src/main/java/org/apache/jackrabbit/standalone/Main.java

Propchange: jackrabbit/branches/1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug  7 13:05:18 2009
@@ -1,3 +1,3 @@
 /incubator/jackrabbit/trunk:78926
 /jackrabbit/branches/1.5:794012,794100,794102
-/jackrabbit/trunk:770143-773197,773483,773525-773555,773584,773588,773828,773835-775756,775833,775836,775840,775868,775981,775986,776036,776256,776310,776313,776321-776322,776332,776356-776357,776362,776373,776650-776693,776737,776757,776776-776777,777024,777029,777034,777478,777509,777541,777548,777936,778445,778613,778616,778621,778645,778720,778802,779032,779040,779068-779071,779074,779076,779081,779084,779086-779088,779090-779092,779094-779096,779101,779223,779225,779227-779228,779230,779233-779234,779460,779475-779476,779504,779550,779552,779555,779561,779563,779583,779590,779618,779621-779622,779624,779642,779654,779657-779659,779661,779936,780006,780010,780025,780085,780985,780989,780993,781017,781051,781054,781294-781300,781305-781311,781318,781328,781338,781344,781347,781369,781372,781377,781416-781417,781423,782621-782622,782644,782646,782652,782669,782675,782677,782683,782694,782921,782925,782930,782936,783002,783004-783005,783042-783043,783239,783243,783245,78327
 8,783304,783319-783321,783324,783326-783327,783330-783333,783337-783338,783340-783341,783343,783345-783347,783356,783359,783383,783386,783412,783435,783444,783447,783523,783688,783703,783708,783710,783719,783757,783759,783761,783786,783809,784011,784013,784039,784058,784060-784061,784090-784091,784106,784108-784109,784111,784117-784120,784124,784163,784261,784680,784691,784696,784760,784824,785112,785116,785157,785169,785209,785492,785517,785519,785529,785533,785535,785539-785540,785545,785580,785589-785590,785592,785594,785597,785602,785627,785629,785631,785635,785645,785668,785711,785725,785777,785863,785981,786003,786019,786028,786062,786075,786089-786090,786093-786094,786144,786146-786147,786149,786167,786280,786295,786319,786329-786330,786336,786409,786419,786423,786480,786485,786492,786513,786562,786565,786680,786685,787183,787219,787241,787942,787952,787964,787996,788002,788012-788013,788350-788351,788443,788446,788450,789245,789257,789269-789270,789279,789307,789312,
 789324,789338,789347,789485,789629,789809,789986,790054,790056,790065-790066,790068,790070-790071,790118,790127,790153,790235-790236,790528,790537,790541,790557-790558,790568,790590,790600,790603,790629,790814,790826,790834,790887,790892,790901,790930,790939,791180,791253,791255,791438-791439,791441,791452,791457,791475,791492,791505,791520,791527,791737,791832,791884,791906,792102,792109,792118,792138,792152,792155-792156,792160,792162,792167-792168,792175,792180-792181,792211,792214,792218,792437,792453,792464,792467,792469,792485,792488,792496,792498,792508-792509,792547-792548,792588-792589,792849,792894-792895,792912,792932,792934,792968,793012-793013,793015-793016,793018,793046-793047,793072,793180,793238,793240,793243,793283,793484-793485,793507,793559,793571,793830,793836,793840,794162,794190,794193,794253,794278,794293-794294,794302,794304,794323,794329,794600,794617,794633,794641,794644,794652,794674,794702,794718,794743,794783,794994,795046,795049,795082,795096,79
 5136,795138,795841-795842,795854,795866,796584,796586,796757,796845,796855,796876,796899,796955,796957,797094,797139,797158,797386,797399,797410,797414,797416-797417,797424,797470,797484,797488-797489,797539,797549,797634,797662,797836,798141,798183,798196,798209,798306,798834,798844,798847-798848,798889-798890,798940,798958,799188,799284,799550,799595,799599,799610,800269,800464,800466,800478,800483,800715,800807,800829,800854,800862-800863,801104,801125-801126,801128,801135,801169,801210,801213,801226,801241
+/jackrabbit/trunk:770143-773197,773483,773525-773555,773584,773588,773828,773835-775756,775833,775836,775840,775868,775981,775986,776036,776256,776310,776313,776321-776322,776332,776356-776357,776362,776373,776650-776693,776737,776757,776776-776777,777024,777029,777034,777478,777509,777541,777548,777936,778445,778613,778616,778621,778645,778720,778802,779032,779040,779068-779071,779074,779076,779081,779084,779086-779088,779090-779092,779094-779096,779101,779223,779225,779227-779228,779230,779233-779234,779460,779475-779476,779504,779550,779552,779555,779561,779563,779583,779590,779618,779621-779622,779624,779642,779654,779657-779659,779661,779936,780006,780010,780025,780085,780985,780989,780993,781017,781051,781054,781294-781300,781305-781311,781318,781328,781338,781344,781347,781369,781372,781377,781416-781417,781423,782621-782622,782644,782646,782652,782669,782675,782677,782683,782694,782921,782925,782930,782936,783002,783004-783005,783042-783043,783239,783243,783245,78327
 8,783304,783319-783321,783324,783326-783327,783330-783333,783337-783338,783340-783341,783343,783345-783347,783356,783359,783383,783386,783412,783435,783444,783447,783523,783688,783703,783708,783710,783719,783757,783759,783761,783786,783809,784011,784013,784039,784058,784060-784061,784090-784091,784106,784108-784109,784111,784117-784120,784124,784163,784261,784680,784691,784696,784760,784824,785112,785116,785157,785169,785209,785492,785517,785519,785529,785533,785535,785539-785540,785545,785580,785589-785590,785592,785594,785597,785602,785627,785629,785631,785635,785645,785668,785711,785725,785777,785863,785981,786003,786019,786028,786062,786075,786089-786090,786093-786094,786144,786146-786147,786149,786167,786280,786295,786319,786329-786330,786336,786409,786419,786423,786480,786485,786492,786513,786562,786565,786680,786685,787183,787219,787241,787942,787952,787964,787996,788002,788012-788013,788350-788351,788443,788446,788450,789245,789257,789269-789270,789279,789307,789312,
 789324,789338,789347,789485,789629,789809,789986,790054,790056,790065-790066,790068,790070-790071,790118,790127,790153,790235-790236,790528,790537,790541,790557-790558,790568,790590,790600,790603,790629,790814,790826,790834,790887,790892,790901,790930,790939,791180,791253,791255,791438-791439,791441,791452,791457,791475,791492,791505,791520,791527,791737,791832,791884,791906,792102,792109,792118,792138,792152,792155-792156,792160,792162,792167-792168,792175,792180-792181,792211,792214,792218,792437,792453,792464,792467,792469,792485,792488,792496,792498,792508-792509,792547-792548,792588-792589,792849,792894-792895,792912,792932,792934,792968,793012-793013,793015-793016,793018,793046-793047,793072,793180,793238,793240,793243,793283,793484-793485,793507,793559,793571,793830,793836,793840,794162,794190,794193,794253,794278,794293-794294,794302,794304,794323,794329,794600,794617,794633,794641,794644,794652,794674,794702,794718,794743,794783,794994,795046,795049,795082,795096,79
 5136,795138,795841-795842,795854,795866,796584,796586,796757,796845,796855,796876,796899,796955,796957,797094,797139,797158,797386,797399,797410,797414,797416-797417,797424,797470,797484,797488-797489,797539,797549,797634,797662,797836,798141,798183,798196,798209,798306,798834,798844,798847-798848,798889-798890,798940,798958,799188,799284,799550,799595,799599,799610,800269,800464,800466,800478,800483,800715,800807,800829,800854,800862-800863,801104,801125-801126,801128,801135,801169,801210,801213,801226,801241,801968,801973

Modified: jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryCopier.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryCopier.java?rev=801983&r1=801982&r2=801983&view=diff
==============================================================================
--- jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryCopier.java
(original)
+++ jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryCopier.java
Fri Aug  7 13:05:18 2009
@@ -27,12 +27,10 @@
 
 import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
-import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.nodetype.InvalidNodeTypeDefException;
 import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.persistence.PersistenceCopier;
-import org.apache.jackrabbit.core.version.VersionManagerImpl;
 import org.apache.jackrabbit.spi.Name;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -41,6 +39,14 @@
  * Tool for backing up or migrating the entire contents (workspaces,
  * version histories, namespaces, node types, etc.) of a repository to
  * a new repository. The target repository (if it exists) is overwritten.
+ * <p>
+ * No cluster journal records are written in the target repository. If the
+ * target repository is clustered, it should be the only node in the cluster.
+ * <p>
+ * The target repository needs to be fully reindexed after the copy operation.
+ * The static copy() methods will remove the target search index folders from
+ * their default locations to trigger automatic reindexing when the repository
+ * is next started.
  *
  * @since Apache Jackrabbit 1.6
  */
@@ -53,30 +59,110 @@
         LoggerFactory.getLogger(RepositoryCopier.class);
 
     /**
-     * Source repository configuration
+     * Source repository.
      */
-    private final RepositoryConfig sourceConfig;
+    private final RepositoryImpl source;
 
     /**
-     * Target repository configuration
+     * Target repository.
      */
-    private final RepositoryConfig targetConfig;
+    private final RepositoryImpl target;
 
     /**
-     * Creates a tool for copying the full contents of the source repository.
-     * The given source repository directory is expected to contain the
-     * repository configuration as a <code>repository.xml</code> file.
-     * The target repository directory should not already exist. It will be
-     * automatically created with default repository configuration.
+     * Copies the contents of the repository in the given source directory
+     * to a repository in the given target directory.
      *
      * @param source source repository directory
      * @param target target repository directory
-     * @throws RepositoryException if the repositories can not be accessed
+     * @throws RepositoryException if the copy operation fails
+     * @throws IOException if the target repository can not be initialized
+     */
+    public static void copy(File source, File target)
+            throws RepositoryException, IOException {
+        copy(RepositoryConfig.create(source), RepositoryConfig.install(target));
+    }
+
+    /**
+     * Copies the contents of the repository with the given configuration
+     * to a repository in the given target directory.
+     *
+     * @param source source repository configuration
+     * @param target target repository directory
+     * @throws RepositoryException if the copy operation fails
+     * @throws IOException if the target repository can not be initialized
+     */
+    public static void copy(RepositoryConfig source, File target)
+            throws RepositoryException, IOException {
+        copy(source, RepositoryConfig.install(target));
+    }
+
+    /**
+     * Copies the contents of the source repository with the given
+     * configuration to a target repository with the given configuration.
+     *
+     * @param source source repository configuration
+     * @param target target repository directory
+     * @throws RepositoryException if the copy operation fails
+     */
+    public static void copy(RepositoryConfig source, RepositoryConfig target)
+            throws RepositoryException {
+        RepositoryImpl repository = RepositoryImpl.create(source);
+        try {
+            copy(repository, target);
+        } finally {
+            repository.shutdown();
+        }
+    }
+
+    /**
+     * Copies the contents of the given source repository to a repository in
+     * the given target directory.
+     * <p>
+     * The source repository <strong>must not be modified</strong> while
+     * the copy operation is running to avoid an inconsistent copy.
+     *
+     * @param source source repository directory
+     * @param target target repository directory
+     * @throws RepositoryException if the copy operation fails
      * @throws IOException if the target repository can not be initialized
      */
-    public RepositoryCopier(File source, File target)
+    public static void copy(RepositoryImpl source, File target)
             throws RepositoryException, IOException {
-        this(RepositoryConfig.create(source), RepositoryConfig.install(target));
+        copy(source, RepositoryConfig.install(target));
+    }
+
+    /**
+     * Copies the contents of the given source repository to a target
+     * repository with the given configuration.
+     * <p>
+     * The source repository <strong>must not be modified</strong> while
+     * the copy operation is running to avoid an inconsistent copy.
+     *
+     * @param source source repository directory
+     * @param target target repository directory
+     * @throws RepositoryException if the copy operation fails
+     * @throws IOException if the target repository can not be initialized
+     */
+    public static void copy(RepositoryImpl source, RepositoryConfig target)
+            throws RepositoryException {
+        RepositoryImpl repository = RepositoryImpl.create(target);
+        try {
+            new RepositoryCopier(source, repository).copy();
+        } finally {
+            repository.shutdown();
+        }
+
+        // Remove index directories to force re-indexing on next startup
+        // TODO: There should be a cleaner way to do this
+        File targetDir = new File(target.getHomeDir());
+        File repoDir = new File(targetDir, "repository");
+        FileUtils.deleteQuietly(new File(repoDir, "index"));
+        File[] workspaces = new File(targetDir, "workspaces").listFiles();
+        if (workspaces != null) {
+            for (int i = 0; i < workspaces.length; i++) {
+                FileUtils.deleteQuietly(new File(workspaces[i], "index"));
+            }
+        }
     }
 
     /**
@@ -84,18 +170,22 @@
      * to the given target repository. Any existing content in the target
      * repository will be overwritten.
      *
-     * @param source source repository configuration
-     * @param target target repository configuration
-     * @throws RepositoryException if the repositories can not be accessed
+     * @param source source repository
+     * @param target target repository
      */
-    public RepositoryCopier(RepositoryConfig source, RepositoryConfig target)
-            throws RepositoryException {
-        sourceConfig = source;
-        targetConfig = target;
+    public RepositoryCopier(RepositoryImpl source, RepositoryImpl target) {
+        this.source = source;
+        this.target = target;
     }
 
     /**
      * Copies the full content from the source to the target repository.
+     * <p>
+     * The source repository <strong>must not be modified</strong> while
+     * the copy operation is running to avoid an inconsistent copy.
+     * <p>
+     * This method leaves the search indexes of the target repository in
+     * an 
      * Note that both the source and the target repository must be closed
      * during the copy operation as this method requires exclusive access
      * to the repositories.
@@ -105,88 +195,67 @@
     public void copy() throws RepositoryException {
         logger.info(
                 "Copying repository content from {} to {}",
-                sourceConfig.getHomeDir(), targetConfig.getHomeDir());
-
-        RepositoryImpl source = RepositoryImpl.create(sourceConfig);
+                source.repConfig.getHomeDir(),
+                target.repConfig.getHomeDir());
         try {
-            RepositoryImpl target = RepositoryImpl.create(targetConfig);
-            try {
-                copyNamespaces(
-                        source.getNamespaceRegistry(),
-                        target.getNamespaceRegistry());
-                copyNodeTypes(
-                        source.getNodeTypeRegistry(),
-                        target.getNodeTypeRegistry());
-                copyVersionStore(
-                        source.getVersionManagerImpl(),
-                        target.getVersionManagerImpl(),
-                        target.getDataStore());
-                copyWorkspaces(source, target);
-            } catch (Exception e) {
-                throw new RepositoryException("Failed to copy content", e);
-            } finally {
-                target.shutdown();
-            }
-
-            // Remove index directories to force re-indexing on next startup
-            // TODO: There should be a cleaner way to do this
-            File targetDir = new File(targetConfig.getHomeDir());
-            File repoDir = new File(targetDir, "repository");
-            FileUtils.deleteQuietly(new File(repoDir, "index"));
-            File[] workspaces = new File(targetDir, "workspaces").listFiles();
-            for (int i = 0; workspaces != null && i < workspaces.length; i++)
{
-                FileUtils.deleteQuietly(new File(workspaces[i], "index"));
-            }
-        } finally {
-            source.shutdown();
+            copyNamespaces();
+            copyNodeTypes();
+            copyVersionStore();
+            copyWorkspaces();
+        } catch (Exception e) {
+            throw new RepositoryException("Failed to copy content", e);
         }
     }
 
-    private void copyNamespaces(
-            NamespaceRegistry source, NamespaceRegistry target)
-            throws RepositoryException {
+    private void copyNamespaces() throws RepositoryException {
+        NamespaceRegistry sourceRegistry = source.getNamespaceRegistry();
+        NamespaceRegistry targetRegistry = target.getNamespaceRegistry();
+
         logger.info("Copying registered namespaces");
 
-        Collection existing = Arrays.asList(target.getURIs());
-        String[] uris = source.getURIs();
+        Collection existing = Arrays.asList(targetRegistry.getURIs());
+        String[] uris = sourceRegistry.getURIs();
         for (int i = 0; i < uris.length; i++) {
             if (!existing.contains(uris[i])) {
                 // TODO: what if the prefix is already taken?
-                target.registerNamespace(source.getPrefix(uris[i]), uris[i]);
+                targetRegistry.registerNamespace(
+                        sourceRegistry.getPrefix(uris[i]), uris[i]);
             }
         }
     }
 
-    private void copyNodeTypes(NodeTypeRegistry source, NodeTypeRegistry target)
-            throws RepositoryException, InvalidNodeTypeDefException {
-        logger.info("Copying registered node types");
+    private void copyNodeTypes() throws RepositoryException {
+        NodeTypeRegistry sourceRegistry = source.getNodeTypeRegistry();
+        NodeTypeRegistry targetRegistry = target.getNodeTypeRegistry();
 
-        Collection existing = Arrays.asList(target.getRegisteredNodeTypes());
+        logger.info("Copying registered node types");
+        Collection existing =
+            Arrays.asList(targetRegistry.getRegisteredNodeTypes());
         Collection register = new ArrayList();
-        Name[] names = source.getRegisteredNodeTypes();
+        Name[] names = sourceRegistry.getRegisteredNodeTypes();
         for (int i = 0; i < names.length; i++) {
             // TODO: what about modified node types?
             if (!existing.contains(names[i])) {
-                register.add(source.getNodeTypeDef(names[i]));
+                register.add(sourceRegistry.getNodeTypeDef(names[i]));
             }
         }
-        target.registerNodeTypes(register);
+        try {
+            targetRegistry.registerNodeTypes(register);
+        } catch (InvalidNodeTypeDefException e) {
+            throw new RepositoryException("Unable to copy node types", e);
+        }
     }
 
-    private void copyVersionStore(
-            VersionManagerImpl source, VersionManagerImpl target,
-            DataStore store)
-            throws Exception {
+    private void copyVersionStore() throws RepositoryException {
         logger.info("Copying version histories");
-
         PersistenceCopier copier = new PersistenceCopier(
-                source.getPersistenceManager(),
-                target.getPersistenceManager(), store);
+                source.getVersionManagerImpl().getPersistenceManager(),
+                target.getVersionManagerImpl().getPersistenceManager(),
+                target.getDataStore());
         copier.copy(RepositoryImpl.VERSION_STORAGE_NODE_ID);
     }
 
-    private void copyWorkspaces(RepositoryImpl source, RepositoryImpl target)
-            throws Exception {
+    private void copyWorkspaces() throws RepositoryException {
         Collection existing = Arrays.asList(target.getWorkspaceNames());
         String[] names = source.getWorkspaceNames();
         for (int i = 0; i < names.length; i++) {

Modified: jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java?rev=801983&r1=801982&r2=801983&view=diff
==============================================================================
--- jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java
(original)
+++ jackrabbit/branches/1.x/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java
Fri Aug  7 13:05:18 2009
@@ -16,18 +16,21 @@
  */
 package org.apache.jackrabbit.core.persistence;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
 import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.state.ChangeLog;
 import org.apache.jackrabbit.core.state.ChildNodeEntry;
+import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.NodeReferences;
 import org.apache.jackrabbit.core.state.NodeReferencesId;
 import org.apache.jackrabbit.core.state.NodeState;
@@ -98,20 +101,24 @@
      * are automatically skipped.
      *
      * @param id identifier of the node to be copied
-     * @throws Exception if the copy operation fails
+     * @throws RepositoryException if the copy operation fails
      */
-    public void copy(NodeId id) throws Exception {
+    public void copy(NodeId id) throws RepositoryException {
         if (!exclude.contains(id)) {
-            NodeState node = source.load(id);
+            try {
+                NodeState node = source.load(id);
 
-            Iterator iterator = node.getChildNodeEntries().iterator();
-            while (iterator.hasNext()) {
-                ChildNodeEntry entry = (ChildNodeEntry) iterator.next();
-                copy(entry.getId());
-            }
+                Iterator iterator = node.getChildNodeEntries().iterator();
+                while (iterator.hasNext()) {
+                    ChildNodeEntry entry = (ChildNodeEntry) iterator.next();
+                    copy(entry.getId());
+                }
 
-            copy(node);
-            exclude.add(id);
+                copy(node);
+                exclude.add(id);
+            } catch (ItemStateException e) {
+                throw new RepositoryException("Unable to copy " + id, e);
+            }
         }
     }
 
@@ -120,66 +127,73 @@
      * to the target persistence manager.
      *
      * @param sourceNode source node state
-     * @throws Exception if the copy operation fails
+     * @throws RepositoryException if the copy operation fails
      */
-    private void copy(NodeState sourceNode) throws Exception {
-        ChangeLog changes = new ChangeLog();
-
-        // Copy the node state
-        NodeState targetNode = target.createNew(sourceNode.getNodeId());
-        targetNode.setParentId(sourceNode.getParentId());
-        targetNode.setDefinitionId(sourceNode.getDefinitionId());
-        targetNode.setNodeTypeName(sourceNode.getNodeTypeName());
-        targetNode.setMixinTypeNames(sourceNode.getMixinTypeNames());
-        targetNode.setPropertyNames(sourceNode.getPropertyNames());
-        targetNode.setChildNodeEntries(sourceNode.getChildNodeEntries());
-        if (target.exists(targetNode.getNodeId())) {
-            changes.modified(targetNode);
-        } else {
-            changes.added(targetNode);
-        }
+    private void copy(NodeState sourceNode) throws RepositoryException {
+        try {
+            ChangeLog changes = new ChangeLog();
+
+            // Copy the node state
+            NodeState targetNode = target.createNew(sourceNode.getNodeId());
+            targetNode.setParentId(sourceNode.getParentId());
+            targetNode.setDefinitionId(sourceNode.getDefinitionId());
+            targetNode.setNodeTypeName(sourceNode.getNodeTypeName());
+            targetNode.setMixinTypeNames(sourceNode.getMixinTypeNames());
+            targetNode.setPropertyNames(sourceNode.getPropertyNames());
+            targetNode.setChildNodeEntries(sourceNode.getChildNodeEntries());
+            if (target.exists(targetNode.getNodeId())) {
+                changes.modified(targetNode);
+            } else {
+                changes.added(targetNode);
+            }
 
-        // Copy all associated property states
-        Iterator iterator = sourceNode.getPropertyNames().iterator();
-        while (iterator.hasNext()) {
-            Name name = (Name) iterator.next();
-            PropertyId id = new PropertyId(sourceNode.getNodeId(), name);
-            PropertyState sourceState = source.load(id);
-            PropertyState targetState = target.createNew(id);
-            targetState.setDefinitionId(sourceState.getDefinitionId());
-            targetState.setType(sourceState.getType());
-            targetState.setMultiValued(sourceState.isMultiValued());
-            InternalValue[] values = sourceState.getValues();
-            if (sourceState.getType() == PropertyType.BINARY) {
-                for (int i = 0; i < values.length; i++) {
-                    InputStream stream = values[i].getBLOBFileValue().getStream();
-                    try {
-                        values[i] = InternalValue.createTemporary(stream, store);
-                    } finally {
-                        stream.close();
+            // Copy all associated property states
+            Iterator iterator = sourceNode.getPropertyNames().iterator();
+            while (iterator.hasNext()) {
+                Name name = (Name) iterator.next();
+                PropertyId id = new PropertyId(sourceNode.getNodeId(), name);
+                PropertyState sourceState = source.load(id);
+                PropertyState targetState = target.createNew(id);
+                targetState.setDefinitionId(sourceState.getDefinitionId());
+                targetState.setType(sourceState.getType());
+                targetState.setMultiValued(sourceState.isMultiValued());
+                InternalValue[] values = sourceState.getValues();
+                if (sourceState.getType() == PropertyType.BINARY) {
+                    for (int i = 0; i < values.length; i++) {
+                        InputStream stream = values[i].getBLOBFileValue().getStream();
+                        try {
+                            values[i] = InternalValue.createTemporary(stream, store);
+                        } finally {
+                            stream.close();
+                        }
                     }
                 }
+                targetState.setValues(values);
+                if (target.exists(targetState.getPropertyId())) {
+                    changes.modified(targetState);
+                } else {
+                    changes.added(targetState);
+                }
             }
-            targetState.setValues(values);
-            if (target.exists(targetState.getPropertyId())) {
-                changes.modified(targetState);
-            } else {
-                changes.added(targetState);
+
+            // Copy all node references
+            NodeReferencesId refsId = new NodeReferencesId(sourceNode.getNodeId());
+            if (source.exists(refsId)) {
+                changes.modified(source.load(refsId));
+            } else if (target.exists(refsId)) {
+                 NodeReferences references = target.load(refsId);
+                references.clearAllReferences();
+                changes.modified(references);
             }
-        }
 
-        // Copy all node references
-        NodeReferencesId refsId = new NodeReferencesId(sourceNode.getNodeId());
-        if (source.exists(refsId)) {
-            changes.modified(source.load(refsId));
-        } else if (target.exists(refsId)) {
-            NodeReferences references = target.load(refsId);
-            references.clearAllReferences();
-            changes.modified(references);
+            // Persist the copied states
+            target.store(changes);
+        } catch (IOException e) {
+            throw new RepositoryException(
+                    "Unable to copy binary values of " + sourceNode, e);
+        } catch (ItemStateException e) {
+            throw new RepositoryException("Unable to copy " + sourceNode, e);
         }
-
-        // Persist the copied states
-        target.store(changes);
     }
 
 }

Modified: jackrabbit/branches/1.x/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.x/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java?rev=801983&r1=801982&r2=801983&view=diff
==============================================================================
--- jackrabbit/branches/1.x/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java
(original)
+++ jackrabbit/branches/1.x/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java
Fri Aug  7 13:05:18 2009
@@ -66,7 +66,7 @@
 
     public void testRepositoryCopy() throws Exception {
         createSourceRepository();
-        new RepositoryCopier(SOURCE, TARGET).copy();
+        RepositoryCopier.copy(SOURCE, TARGET);
         verifyTargetRepository();
     }
 

Modified: jackrabbit/branches/1.x/jackrabbit-standalone/src/main/java/org/apache/jackrabbit/standalone/Main.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.x/jackrabbit-standalone/src/main/java/org/apache/jackrabbit/standalone/Main.java?rev=801983&r1=801982&r2=801983&view=diff
==============================================================================
--- jackrabbit/branches/1.x/jackrabbit-standalone/src/main/java/org/apache/jackrabbit/standalone/Main.java
(original)
+++ jackrabbit/branches/1.x/jackrabbit-standalone/src/main/java/org/apache/jackrabbit/standalone/Main.java
Fri Aug  7 13:05:18 2009
@@ -185,10 +185,7 @@
         }
 
         message("Creating a repository copy in " + targetDir);
-
-        RepositoryCopier copier = new RepositoryCopier(source, target);
-        copier.copy();
-
+        RepositoryCopier.copy(source, target);
         message("The repository has been successfully copied.");
     }
 



Mime
View raw message