jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r937946 - in /jackrabbit/sandbox/jackrabbit-j3/src: main/java/org/apache/jackrabbit/j3/ main/java/org/apache/jackrabbit/j3/mc/ main/java/org/apache/jackrabbit/j3/tools/ test/java/org/apache/jackrabbit/j3/
Date Mon, 26 Apr 2010 07:24:59 GMT
Author: thomasm
Date: Mon Apr 26 07:24:59 2010
New Revision: 937946

URL: http://svn.apache.org/viewvc?rev=937946&view=rev
Log:
RepositoryCopier

Added:
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/tools/
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/tools/RepositoryCopier.java
Modified:
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeImpl.java
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/ValueImpl.java
    jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/Bundle.java
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/Profiler.java
    jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeImpl.java?rev=937946&r1=937945&r2=937946&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/NodeImpl.java
Mon Apr 26 07:24:59 2010
@@ -98,7 +98,7 @@ public class NodeImpl implements Node, L
     private NodeImpl addNode(String relPath, NodeTypeImpl nt) throws RepositoryException
{
         SessionImpl s = state.getSession();
         synchronized (s) {
-            Val p = Val.get(relPath);
+            Val p = s.parseName(relPath);
             Val nodeId = s.getStorageSession().newNodeId(state.getId(), s.getWorkspaceId(),
p);
             EventAddNode event = new EventAddNode(s.getTransientChanges(), this, p, nodeId);
             event.applyAndAdd();
@@ -161,7 +161,7 @@ public class NodeImpl implements Node, L
 
     private PropertyImpl setProperty(String name, Val value) throws RepositoryException {
         SessionImpl s = state.getSession();
-        Val propertyName = Val.get(name);
+        Val propertyName = s.parseName(name);
         if (state.getPropertyInternal(propertyName) != null) {
             EventModifyProperty event = new EventModifyProperty(s.getTransientChanges(),
this, propertyName, value);
             synchronized (s) {
@@ -184,7 +184,7 @@ public class NodeImpl implements Node, L
     }
 
     public Property getProperty(String relPath) throws PathNotFoundException, RepositoryException
{
-        Val propertyName = Val.get(relPath);
+        Val propertyName = getSession().parseName(relPath);
         // just verify that the property exists for now
         state.getPropertyInternal(propertyName);
         PropertyImpl prop = new PropertyImpl(this, propertyName);
@@ -239,12 +239,13 @@ public class NodeImpl implements Node, L
     }
 
     NodeImpl getNodeImpl(String relPath) throws PathNotFoundException, RepositoryException
{
-        Val childName = Val.get(relPath);
+        SessionImpl s = getSession();
+        Val childName = s.parseName(relPath);
         Val childId = state.getNodeData().getChildId(childName);
         if (childId == null) {
             throw ExceptionFactory.pathNotFound("Path: {0}", relPath);
         }
-        return state.getSession().getNode(this, childId);
+        return s.getNode(this, childId);
     }
 
     public String getName() throws RepositoryException {
@@ -257,7 +258,7 @@ public class NodeImpl implements Node, L
 
     public boolean hasNode(String relPath) throws RepositoryException {
         log.code(this, "hasNode", relPath);
-        Val childName = Val.get(relPath);
+        Val childName = getSession().parseName(relPath);
         Val childId = state.getNodeData().getChildId(childName);
         return childId != null;
     }
@@ -515,6 +516,33 @@ public class NodeImpl implements Node, L
         return isNodeType(nt);
     }
 
+    public Property setProperty(String name, Value value) throws ValueFormatException, VersionException,
LockException,
+            ConstraintViolationException, RepositoryException {
+        if (!(value instanceof ValueImpl)) {
+            throw ExceptionFactory.illegalArgument("Not a ValueImpl: {0}", value);
+        }
+        Val v = ((ValueImpl) value).getVal();
+        PropertyImpl p = setProperty(name, v);
+        log.codeAssign(p, this, "setProperty", name, value);
+        return p;
+    }
+
+    public Property setProperty(String name, Value[] values) throws ValueFormatException,
VersionException,
+            LockException, ConstraintViolationException, RepositoryException {
+        Val[] array = new Val[values.length];
+        for (int i = 0; i < values.length; i++) {
+            Value value = values[i];
+            if (!(value instanceof ValueImpl)) {
+                throw ExceptionFactory.illegalArgument("Not a ValueImpl: {0}", value);
+            }
+            array[i] = ((ValueImpl) value).getVal();
+        }
+        Val v = Val.get(array);
+        PropertyImpl p = setProperty(name, v);
+        log.codeAssign(p, this, "setProperty", name, values);
+        return p;
+    }
+
     public void save() throws AccessDeniedException, ItemExistsException, ConstraintViolationException,
             InvalidItemStateException, ReferentialIntegrityException, VersionException, LockException,
             NoSuchNodeTypeException, RepositoryException {
@@ -783,20 +811,6 @@ public class NodeImpl implements Node, L
 
     }
 
-    public Property setProperty(String name, Value value) throws ValueFormatException, VersionException,
LockException,
-            ConstraintViolationException, RepositoryException {
-        log.codeTodo(this, "setProperty", name, value);
-        // TODO
-        return null;
-    }
-
-    public Property setProperty(String name, Value[] values) throws ValueFormatException,
VersionException,
-            LockException, ConstraintViolationException, RepositoryException {
-        log.codeTodo(this, "setProperty", name, values);
-        // TODO
-        return null;
-    }
-
     public Property setProperty(String name, String[] values) throws ValueFormatException,
VersionException,
             LockException, ConstraintViolationException, RepositoryException {
         log.codeTodo(this, "setProperty", name, values);

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/ValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/ValueImpl.java?rev=937946&r1=937945&r2=937946&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/ValueImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/ValueImpl.java
Mon Apr 26 07:24:59 2010
@@ -129,4 +129,8 @@ public class ValueImpl implements Value,
         return "ValueImpl: " + value.toString();
     }
 
+    Val getVal() {
+        return value;
+    }
+
 }

Modified: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/Bundle.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/Bundle.java?rev=937946&r1=937945&r2=937946&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/Bundle.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/mc/Bundle.java
Mon Apr 26 07:24:59 2010
@@ -117,12 +117,12 @@ public class Bundle {
      */
     private void writeString(String s) {
         int len = s.length();
-        checkCapacity(5 + len * 3);
         writeVarInt(len);
         writeStringWithoutLength(s, len);
     }
 
     private void writeStringWithoutLength(String s, int len) {
+        checkCapacity(5 + len * 3);
         int p = pos;
         byte[] buff = data;
         for (int i = 0; i < len; i++) {

Added: jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/tools/RepositoryCopier.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/tools/RepositoryCopier.java?rev=937946&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/tools/RepositoryCopier.java
(added)
+++ jackrabbit/sandbox/jackrabbit-j3/src/main/java/org/apache/jackrabbit/j3/tools/RepositoryCopier.java
Mon Apr 26 07:24:59 2010
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.jackrabbit.j3.tools;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import org.apache.jackrabbit.j3.util.ExceptionFactory;
+
+/**
+ * This class can copy a repository to
+ * a new repository.
+ */
+public class RepositoryCopier {
+
+    private static final int MAX_TRANSIENT_SIZE = 1000;
+    private final Session source, target;
+    private final ValueFactory valueFactory;
+    private int transientSize;
+
+    /**
+     * Create a copier class
+     *
+     * @param source the source session
+     * @param target the target session
+     * @throws RepositoryException
+     */
+    public RepositoryCopier(Session source, Session target) throws RepositoryException {
+        this.source = source;
+        this.target = target;
+        valueFactory = target.getValueFactory();
+    }
+
+    /**
+     * Copies the full content from the source to the target repository.
+     * <p>
+     * The source repository must not be modified while
+     * the copy operation is running to avoid an inconsistent copy.
+     */
+    public void copyAll() throws RepositoryException {
+        copyNamespaces();
+        copyNodeTypes();
+        copyNodes();
+    }
+
+    /**
+     * Copy the workspaces.
+     */
+    public void copyNamespaces() throws RepositoryException {
+        NamespaceRegistry sourceRegistry = source.getWorkspace().getNamespaceRegistry();
+        NamespaceRegistry targetRegistry = target.getWorkspace().getNamespaceRegistry();
+        HashSet<String> existing = new HashSet<String>(Arrays.asList(targetRegistry.getURIs()));
+        for (String uri : sourceRegistry.getURIs()) {
+            if (!existing.contains(uri)) {
+                targetRegistry.registerNamespace(
+                        sourceRegistry.getPrefix(uri), uri);
+            }
+        }
+    }
+
+    /**
+     * Copy the node types.
+     */
+    public void copyNodeTypes() throws RepositoryException {
+    }
+
+    /**
+     * Copy the nodes.
+     */
+    private void copyNodes() throws RepositoryException {
+        Node sourceNode = source.getRootNode();
+        Node targetNode = target.getRootNode();
+        copyNodes(sourceNode, targetNode);
+        target.save();
+        transientSize = 0;
+    }
+
+    private void copyNodes(Node sourceNode, Node targetNode) throws RepositoryException {
+        // System.out.println(sourceNode.getPath());
+        for (PropertyIterator it = sourceNode.getProperties(); it.hasNext();) {
+            Property p = it.nextProperty();
+            String name = p.getName();
+            if (p.getDefinition().isProtected()) {
+                continue;
+            }
+            // System.out.println(sourceNode.getPath() + " " + name);
+            int type = p.getType();
+            boolean multiple = p.isMultiple();
+            if (multiple) {
+                Value[] sourceValues = p.getValues();
+                int len = sourceValues.length;
+                Value[] targetValues = new Value[len];
+                for (int i = 0; i < len; i++) {
+                    targetValues[i] = copyValue(sourceValues[i], type);
+                }
+                targetNode.setProperty(name, targetValues);
+            } else {
+                Value sourceValue = p.getValue();
+                Value targetValue = copyValue(sourceValue, type);
+                targetNode.setProperty(name, targetValue);
+            }
+        }
+        for (NodeIterator it = sourceNode.getNodes(); it.hasNext();) {
+            Node n = it.nextNode();
+            String name = n.getName();
+            if ("jcr:system".equals(name)) {
+                continue;
+            }
+            Node target = targetNode.addNode(name);
+            copyNodes(n, target);
+        }
+        transientSize++;
+        if (transientSize > MAX_TRANSIENT_SIZE) {
+            target.save();
+            transientSize = 0;
+        }
+    }
+
+    private Value copyValue(Value value, int type) throws RepositoryException {
+        switch (type) {
+        case PropertyType.BINARY:
+            return valueFactory.createValue(1);
+            // TODO
+            // return valueFactory.createValue(valueFactory.createBinary(value.getBinary().getStream()));
+        case PropertyType.BOOLEAN:
+            return valueFactory.createValue(value.getBoolean());
+        case PropertyType.DATE:
+            return valueFactory.createValue(value.getDate());
+        case PropertyType.DECIMAL:
+            return valueFactory.createValue(value.getDecimal());
+        case PropertyType.DOUBLE:
+            return valueFactory.createValue(value.getDouble());
+        case PropertyType.LONG:
+            return valueFactory.createValue(value.getLong());
+        case PropertyType.NAME:
+        case PropertyType.PATH:
+        case PropertyType.REFERENCE:
+        case PropertyType.URI:
+        case PropertyType.WEAKREFERENCE:
+            return valueFactory.createValue(value.getString(), type);
+        case PropertyType.STRING:
+            return valueFactory.createValue(value.getString());
+        default:
+            throw ExceptionFactory.illegalArgument("Type {0}", type);
+        }
+    }
+
+}

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/Profiler.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/Profiler.java?rev=937946&r1=937945&r2=937946&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/Profiler.java
(original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/Profiler.java
Mon Apr 26 07:24:59 2010
@@ -20,8 +20,6 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import org.h2.engine.Constants;
-import org.h2.util.New;
 
 /**
  * A simple CPU profiling tool similar to java -Xrunhprof.
@@ -169,7 +167,7 @@ public class Profiler implements Runnabl
     public String getTop(int count) {
         StringBuilder buff = new StringBuilder();
         buff.append("Profiler: top ").append(count).append(" stack trace(s) of ").append(time).
-            append(" ms [build-").append(Constants.BUILD_ID).append("]\n");
+            append(" ms\n");
         for (int x = 0, min = 0;;) {
             int highest = 0;
             Map.Entry<String, Integer> best = null;
@@ -213,7 +211,7 @@ public class Profiler implements Runnabl
         if (s.length() == 0) {
             return new String[0];
         }
-        ArrayList<String> list = New.arrayList();
+        ArrayList<String> list = new ArrayList<String>();
         StringBuilder buff = new StringBuilder(s.length());
         for (int i = 0; i < s.length(); i++) {
             char c = s.charAt(i);

Modified: jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java?rev=937946&r1=937945&r2=937946&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java (original)
+++ jackrabbit/sandbox/jackrabbit-j3/src/test/java/org/apache/jackrabbit/j3/TestAll.java Mon
Apr 26 07:24:59 2010
@@ -35,6 +35,7 @@ public class TestAll {
         TestSuite suite = new TestSuite("org.apache.jackrabbit.j3");
 
         int todo;
+        // ability to disable the even journal (for each session?)
         // XA API
         // integrated lob storage
         // virtual repository
@@ -42,11 +43,16 @@ public class TestAll {
         // Repository.OPTION_JOURNALED_OBSERVATION_SUPPORTED
         // external events
         // ability to auto-delete old event journal entries
-        // ability to disable the even journal (for each session?)
         // try supporting path as the node id
 
         // events: save space for n=addNode+n.setProperty+... or n.setProperty+n.setProperty+...
 
+        // API improvements:
+        // change RepositoryException to RuntimeException
+        // remove weird exceptions from throws clauses
+        // get rid of Binary and de-deprecate InputStream methods
+        // make namespace registry global
+
         suite.addTestSuite(TestBundle.class);
         suite.addTestSuite(TestNamespaceRegistry.class);
         suite.addTestSuite(TestNodeTypeRegistry.class);



Mime
View raw message