jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r800869 - 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/
Date Tue, 04 Aug 2009 16:40:25 GMT
Author: jukka
Date: Tue Aug  4 16:40:24 2009
New Revision: 800869

URL: http://svn.apache.org/viewvc?rev=800869&view=rev
Log:
1.x: Merged revisions 800807-800863 (JCR-442)

Added:
    jackrabbit/branches/1.x/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java
      - copied, changed from r800829, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java
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

Propchange: jackrabbit/branches/1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug  4 16:40:24 2009
@@ -1,2 +1,2 @@
 /incubator/jackrabbit/trunk:78926
-/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,783278,783304,78331
 9-783321,783324,783326-783327,783330-783333,783337-783338,783340-783341,783343,783345-783346,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,785594,785597,785602,785627,785629,785631,785635,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,791505,791520,791527,791737,791832,791884,791906,792102,792118,792138,792152,792155-792156,792160,792167-792168,792175,792180-792181,792211,792214,792218,792437,792453,792464,792467,792469,792485,792488,792496,792498,792509,792547-792548,792588-792589,793012-793013,793015-793016,793018,793046-793047,793072,793180,793238,793243,793283,793485,793507,793559,794162,796757
+/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,783278,783304,78331
 9-783321,783324,783326-783327,783330-783333,783337-783338,783340-783341,783343,783345-783346,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,785594,785597,785602,785627,785629,785631,785635,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,791505,791520,791527,791737,791832,791884,791906,792102,792118,792138,792152,792155-792156,792160,792167-792168,792175,792180-792181,792211,792214,792218,792437,792453,792464,792467,792469,792485,792488,792496,792498,792509,792547-792548,792588-792589,793012-793013,793015-793016,793018,793046-793047,793072,793180,793238,793243,793283,793485,793507,793559,794162,796757,800807,800829,800854,800862-800863

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=800869&r1=800868&r2=800869&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
Tue Aug  4 16:40:24 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.VersionManagerImpl;
 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,17 +175,18 @@
 
     private void copyVersionStore(
             VersionManagerImpl source, VersionManagerImpl target)
-            throws RepositoryException, ItemStateException {
+            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 existing = Arrays.asList(target.getWorkspaceNames());
         String[] names = source.getWorkspaceNames();
         for (int i = 0; i < names.length; i++) {
@@ -199,6 +199,7 @@
             PersistenceCopier copier = new PersistenceCopier(
                     source.getWorkspaceInfo(names[i]).getPersistenceManager(),
                     target.getWorkspaceInfo(names[i]).getPersistenceManager());
+                    target.getDataStore());
             copier.excludeNode(RepositoryImpl.SYSTEM_ROOT_NODE_ID);
             copier.copy(RepositoryImpl.ROOT_NODE_ID);
         }

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=800869&r1=800868&r2=800869&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
Tue Aug  4 16:40:24 2009
@@ -16,19 +16,23 @@
  */
 package org.apache.jackrabbit.core.persistence;
 
+import java.io.InputStream;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
+import javax.jcr.PropertyType;
+
+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;
 import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
 
 /**
@@ -50,6 +54,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
@@ -63,11 +72,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;
     }
 
     /**
@@ -86,9 +98,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);
 
@@ -108,9 +120,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
@@ -137,8 +149,18 @@
             targetState.setDefinitionId(sourceState.getDefinitionId());
             targetState.setType(sourceState.getType());
             targetState.setMultiValued(sourceState.isMultiValued());
-            // TODO: Copy binaries?
-            targetState.setValues(sourceState.getValues());
+            InternalValue[] values = sourceState.getValues();
+            if (sourceState.getType() == PropertyType.BINARY) {
+                for (int i = 0; i < values.length; i++) {
+                    InputStream stream = values[i].getStream();
+                    try {
+                        values[i] = InternalValue.create(stream, store);
+                    } finally {
+                        stream.close();
+                    }
+                }
+            }
+            targetState.setValues(values);
             if (target.exists(targetState.getPropertyId())) {
                 changes.modified(targetState);
             } else {

Copied: jackrabbit/branches/1.x/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java
(from r800829, jackrabbit/trunk/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?p2=jackrabbit/branches/1.x/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java&p1=jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/RepositoryCopierTest.java&r1=800829&r2=800869&rev=800869&view=diff
==============================================================================
--- jackrabbit/trunk/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
Tue Aug  4 16:40:24 2009
@@ -16,20 +16,28 @@
  */
 package org.apache.jackrabbit.core;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.Random;
 
+import javax.jcr.Binary;
 import javax.jcr.Credentials;
+import javax.jcr.NamespaceRegistry;
 import javax.jcr.Node;
-import javax.jcr.Property;
 import javax.jcr.PropertyType;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeTypeTemplate;
 
 import junit.framework.TestCase;
 
 import org.apache.commons.io.FileUtils;
-import org.apache.jackrabbit.core.RepositoryCopier;
-import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
 
 public class RepositoryCopierTest extends TestCase {
@@ -37,11 +45,21 @@
     private static final Credentials CREDENTIALS =
         new SimpleCredentials("admin", "admin".toCharArray());
 
-    private final File BASE = new File("target", "RepositoryCopierTest");
+    private static final File BASE = new File("target", "RepositoryCopierTest");
 
-    private final File SOURCE = new File(BASE, "source");
+    private static final File SOURCE = new File(BASE, "source");
 
-    private final File TARGET = new File(BASE, "target");
+    private static final File TARGET = new File(BASE, "target");
+
+    private static final Calendar DATE = Calendar.getInstance();
+
+    private static final byte[] BINARY = new byte[64 * 1024];
+
+    static {
+        new Random().nextBytes(BINARY);
+    }
+
+    private String identifier;
 
     protected void setUp() {
         BASE.mkdirs();
@@ -63,9 +81,58 @@
         try {
             Session session = repository.login(CREDENTIALS);
             try {
-                Node test = session.getRootNode().addNode("test");
-                test.setProperty("foo", "bar");
+                NamespaceRegistry registry =
+                    session.getWorkspace().getNamespaceRegistry();
+                registry.registerNamespace("test", "http://www.example.org/");
+
+                NodeTypeManager manager =
+                    session.getWorkspace().getNodeTypeManager();
+                NodeTypeTemplate template = manager.createNodeTypeTemplate();
+                template.setName("test:unstructured");
+                template.setDeclaredSuperTypeNames(
+                        new String[] { "nt:unstructured" });
+                manager.registerNodeType(template, false);
+
+                Node root = session.getRootNode();
+
+                Node referenceable =
+                    root.addNode("referenceable", "test:unstructured");
+                referenceable.addMixin(NodeType.MIX_REFERENCEABLE);
                 session.save();
+                identifier = referenceable.getIdentifier();
+
+                Node properties = root.addNode("properties", "test:unstructured");
+                properties.setProperty("boolean", true);
+                Binary binary = session.getValueFactory().createBinary(
+                        new ByteArrayInputStream(BINARY));
+                try {
+                    properties.setProperty("binary", binary);
+                } finally {
+                    binary.dispose();
+                }
+                properties.setProperty("date", DATE);
+                properties.setProperty("decimal", new BigDecimal(123));
+                properties.setProperty("double", Math.PI);
+                properties.setProperty("long", 9876543210L);
+                properties.setProperty("reference", referenceable);
+                properties.setProperty("string", "test");
+                properties.setProperty("multiple", "a,b,c".split(","));
+                session.save();
+
+                binary = properties.getProperty("binary").getBinary();
+                try {
+                    InputStream stream = binary.getStream();
+                    try {
+                        for (int i = 0; i < BINARY.length; i++) {
+                            assertEquals(BINARY[i], (byte) stream.read());
+                        }
+                        assertEquals(-1, stream.read());
+                    } finally {
+                        stream.close();
+                    }
+                } finally {
+                    binary.dispose();
+                }
             } finally {
                 session.logout();
             }
@@ -80,12 +147,85 @@
         try {
             Session session = repository.login(CREDENTIALS);
             try {
-                assertTrue(session.nodeExists("/test"));
-                assertTrue(session.propertyExists("/test/foo"));
-
-                Property foo = session.getProperty("/test/foo");
-                assertEquals(PropertyType.STRING, foo.getType());
-                assertEquals("bar", foo.getString());
+                assertEquals(
+                        "http://www.example.org/",
+                        session.getNamespaceURI("test"));
+
+                NodeTypeManager manager =
+                    session.getWorkspace().getNodeTypeManager();
+                assertTrue(manager.hasNodeType("test:unstructured"));
+                NodeType type = manager.getNodeType("test:unstructured");
+                assertFalse(type.isMixin());
+                assertTrue(type.isNodeType("nt:unstructured"));
+
+                assertTrue(session.nodeExists("/properties"));
+                Node properties = session.getNode("/properties");
+                assertEquals(
+                        PropertyType.BOOLEAN,
+                        properties.getProperty("boolean").getType());
+                assertEquals(
+                        true, properties.getProperty("boolean").getBoolean());
+                assertEquals(
+                        PropertyType.BINARY,
+                        properties.getProperty("binary").getType());
+                Binary binary = properties.getProperty("binary").getBinary();
+                try {
+                    InputStream stream = binary.getStream();
+                    try {
+                        for (int i = 0; i < BINARY.length; i++) {
+                            assertEquals(BINARY[i], (byte) stream.read());
+                        }
+                        assertEquals(-1, stream.read());
+                    } finally {
+                        stream.close();
+                    }
+                } finally {
+                    binary.dispose();
+                }
+                assertEquals(
+                        PropertyType.DATE,
+                        properties.getProperty("date").getType());
+                assertEquals(
+                        DATE.getTimeInMillis(),
+                        properties.getProperty("date").getDate().getTimeInMillis());
+                assertEquals(
+                        PropertyType.DECIMAL,
+                        properties.getProperty("decimal").getType());
+                assertEquals(
+                        new BigDecimal(123),
+                        properties.getProperty("decimal").getDecimal());
+                assertEquals(
+                        PropertyType.DOUBLE,
+                        properties.getProperty("double").getType());
+                assertEquals(
+                        Math.PI, properties.getProperty("double").getDouble());
+                assertEquals(
+                        PropertyType.LONG,
+                        properties.getProperty("long").getType());
+                assertEquals(
+                        9876543210L, properties.getProperty("long").getLong());
+                assertEquals(
+                        PropertyType.REFERENCE,
+                        properties.getProperty("reference").getType());
+                assertEquals(
+                        identifier,
+                        properties.getProperty("reference").getString());
+                assertEquals(
+                        "/referenceable",
+                        properties.getProperty("reference").getNode().getPath());
+                assertEquals(
+                        PropertyType.STRING,
+                        properties.getProperty("string").getType());
+                assertEquals(
+                        "test", properties.getProperty("string").getString());
+                assertEquals(
+                        PropertyType.STRING,
+                        properties.getProperty("multiple").getType());
+                Value[] values = properties.getProperty("multiple").getValues();
+                assertEquals(3, values.length);
+                assertEquals("a", values[0].getString());
+                assertEquals("b", values[1].getString());
+                assertEquals("c", values[2].getString());
             } finally {
                 session.logout();
             }



Mime
View raw message