jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r800807 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: RepositoryCopier.java persistence/PersistenceCopier.java value/InternalValue.java
Date Tue, 04 Aug 2009 14:08:09 GMT
Author: jukka
Date: Tue Aug  4 14:08:08 2009
New Revision: 800807

URL: http://svn.apache.org/viewvc?rev=800807&view=rev
Log:
JCR-442: Implement a backup tool

Support for binary values and the data store in RepositoryCopier.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryCopier.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryCopier.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryCopier.java?rev=800807&r1=800806&r2=800807&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryCopier.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryCopier.java
Tue Aug  4 14:08:08 2009
@@ -27,11 +27,11 @@
 
 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.state.ItemStateException;
 import org.apache.jackrabbit.core.version.InternalVersionManagerImpl;
 import org.apache.jackrabbit.spi.Name;
 import org.slf4j.Logger;
@@ -119,12 +119,11 @@
                         target.getNodeTypeRegistry());
                 copyVersionStore(
                         source.getVersionManagerImpl(),
-                        target.getVersionManagerImpl());
+                        target.getVersionManagerImpl(),
+                        target.getDataStore());
                 copyWorkspaces(source, target);
-            } catch (InvalidNodeTypeDefException e) {
-                throw new RepositoryException("Failed to copy node types", e);
-            } catch (ItemStateException e) {
-                throw new RepositoryException("Failed to copy item states", e);
+            } catch (Exception e) {
+                throw new RepositoryException("Failed to copy content", e);
             } finally {
                 target.shutdown();
             }
@@ -176,18 +175,19 @@
     }
 
     private void copyVersionStore(
-            InternalVersionManagerImpl source, InternalVersionManagerImpl target)
-            throws RepositoryException, ItemStateException {
+            InternalVersionManagerImpl source,
+            InternalVersionManagerImpl target, DataStore store)
+            throws Exception {
         logger.info("Copying version histories");
 
         PersistenceCopier copier = new PersistenceCopier(
                 source.getPersistenceManager(),
-                target.getPersistenceManager());
+                target.getPersistenceManager(), store);
         copier.copy(RepositoryImpl.VERSION_STORAGE_NODE_ID);
     }
 
     private void copyWorkspaces(RepositoryImpl source, RepositoryImpl target)
-            throws RepositoryException, ItemStateException {
+            throws Exception {
         Collection<String> existing = Arrays.asList(target.getWorkspaceNames());
         for (String name : source.getWorkspaceNames()) {
             logger.info("Copying workspace {}" , name);
@@ -198,7 +198,8 @@
 
             PersistenceCopier copier = new PersistenceCopier(
                     source.getWorkspaceInfo(name).getPersistenceManager(),
-                    target.getWorkspaceInfo(name).getPersistenceManager());
+                    target.getWorkspaceInfo(name).getPersistenceManager(),
+                    target.getDataStore());
             copier.excludeNode(RepositoryImpl.SYSTEM_ROOT_NODE_ID);
             copier.copy(RepositoryImpl.ROOT_NODE_ID);
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java?rev=800807&r1=800806&r2=800807&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/PersistenceCopier.java
Tue Aug  4 14:08:08 2009
@@ -16,17 +16,21 @@
  */
 package org.apache.jackrabbit.core.persistence;
 
+import java.io.InputStream;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.jcr.PropertyType;
+
+import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.id.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.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
 
 /**
@@ -48,6 +52,11 @@
     private final PersistenceManager target;
 
     /**
+     * Target data store, possibly <code>null</code>.
+     */
+    private final DataStore store;
+
+    /**
      * Identifiers of the nodes that have already been copied or that
      * should explicitly not be copied. Used to avoid duplicate copies
      * of shareable nodes and to avoid trying to copy "missing" nodes
@@ -61,11 +70,14 @@
      *
      * @param source source persistence manager
      * @param target target persistence manager
+     * @param store target data store
      */
     public PersistenceCopier(
-            PersistenceManager source, PersistenceManager target) {
+            PersistenceManager source,  PersistenceManager target,
+            DataStore store) {
         this.source = source;
         this.target = target;
+        this.store = store;
     }
 
     /**
@@ -84,9 +96,9 @@
      * are automatically skipped.
      *
      * @param id identifier of the node to be copied
-     * @throws ItemStateException if the copy operation fails
+     * @throws Exception if the copy operation fails
      */
-    public void copy(NodeId id) throws ItemStateException {
+    public void copy(NodeId id) throws Exception {
         if (!exclude.contains(id)) {
             NodeState node = source.load(id);
 
@@ -104,9 +116,9 @@
      * to the target persistence manager.
      *
      * @param sourceNode source node state
-     * @throws ItemStateException if the copy operation fails
+     * @throws Exception if the copy operation fails
      */
-    private void copy(NodeState sourceNode) throws ItemStateException {
+    private void copy(NodeState sourceNode) throws Exception {
         ChangeLog changes = new ChangeLog();
 
         // Copy the node state
@@ -131,8 +143,19 @@
             targetState.setDefinitionId(sourceState.getDefinitionId());
             targetState.setType(sourceState.getType());
             targetState.setMultiValued(sourceState.isMultiValued());
-            // TODO: Copy binaries?
-            targetState.setValues(sourceState.getValues());
+            if (sourceState.getType() != PropertyType.BINARY) {
+                targetState.setValues(sourceState.getValues());
+            } else {
+                InternalValue[] values = sourceState.getValues();
+                for (int i = 0; i < values.length; i++) {
+                    InputStream stream = values[i].getStream();
+                    try {
+                        values[i] = InternalValue.create(stream, store);
+                    } finally {
+                        stream.close();
+                    }
+                }
+            }
             if (target.exists(targetState.getPropertyId())) {
                 changes.modified(targetState);
             } else {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java?rev=800807&r1=800806&r2=800807&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
Tue Aug  4 14:08:08 2009
@@ -323,7 +323,7 @@
      * @return the internal value
      * @throws RepositoryException
      */
-    static InternalValue create(InputStream value, DataStore store) throws RepositoryException
{
+    public static InternalValue create(InputStream value, DataStore store) throws RepositoryException
{
         return new InternalValue(getBLOBFileValue(store, value, false));
     }
 



Mime
View raw message