jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1146661 - in /jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel: RepositoryServiceImpl.java util/Function1.java util/Values.java
Date Thu, 14 Jul 2011 12:01:22 GMT
Author: mduerig
Date: Thu Jul 14 12:01:22 2011
New Revision: 1146661

URL: http://svn.apache.org/viewvc?rev=1146661&view=rev
Log:
spi2microkernel (WIP)
- use data store for big binaries (WIP)

Added:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Function1.java
Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1146661&r1=1146660&r2=1146661&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Thu Jul 14 12:01:22 2011
@@ -46,6 +46,7 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.QNodeDefinitionImpl;
 import org.apache.jackrabbit.spi.commons.SessionInfoImpl;
 import org.apache.jackrabbit.spi.commons.batch.ConsolidatingChangeLog;
+import org.apache.jackrabbit.spi2microkernel.util.Function1;
 import org.apache.jackrabbit.spi2microkernel.util.JsonHandlerBase;
 import org.apache.jackrabbit.spi2microkernel.util.NodeTypes;
 import org.apache.jackrabbit.spi2microkernel.util.Paths;
@@ -60,6 +61,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.version.OnParentVersionAction;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -488,19 +490,19 @@ public class RepositoryServiceImpl exten
         }
 
         public void addProperty(NodeId parentId, Name propertyName, QValue value) throws
RepositoryException {
-            setProperty(parentId, propertyName, Values.valueToString(value));
+            setProperty(parentId, propertyName, Values.valueToString(value, saveToDataStore));
         }
 
         public void addProperty(NodeId parentId, Name propertyName, QValue[] values) throws
RepositoryException {
-            setProperty(parentId, propertyName, Values.valuesToString(values));
+            setProperty(parentId, propertyName, Values.valuesToString(values, saveToDataStore));
         }
 
         public void setValue(PropertyId propertyId, QValue value) throws RepositoryException
{
-            setProperty(propertyId.getParentId(), propertyId.getName(), Values.valueToString(value));
+            setProperty(propertyId.getParentId(), propertyId.getName(), Values.valueToString(value,
saveToDataStore));
         }
 
         public void setValue(PropertyId propertyId, QValue[] values) throws RepositoryException
{
-            setProperty(propertyId.getParentId(), propertyId.getName(), Values.valuesToString(values));
+            setProperty(propertyId.getParentId(), propertyId.getName(), Values.valuesToString(values,
saveToDataStore));
         }
 
         public void remove(ItemId itemId) throws RepositoryException {
@@ -551,11 +553,32 @@ public class RepositoryServiceImpl exten
             sessionState(sessionInfo).commitWithLock(new Callable<String>() {
                 public String call() throws RepositoryException {
                     String rev = sessionState(sessionInfo).getHeadRevision();
-                    return microKernel.commit("/", jsop.toString(), rev, ((SessionInfoImpl)
sessionInfo).getUserData());  
+                    return microKernel.commit("/", jsop.toString(), rev, ((SessionInfoImpl)
sessionInfo).getUserData());
                 }
             });
         }
 
+        private final Function1<QValue, String> saveToDataStore = new Function1<QValue,
String>() {
+            public String apply(QValue value) throws Exception {
+                return saveToDataStore(value);
+            }
+        };
+
+        private String saveToDataStore(QValue value) throws RepositoryException {
+            InputStream is = value.getStream();
+            try {
+                try {
+                    return microKernel.write(is);
+                }
+                finally {
+                    is.close();
+                }
+            }
+            catch (IOException e) {
+                throw new RepositoryException(e.getMessage(), e);
+            }
+        }
+
         private String target(NodeId nodeId) throws RepositoryException {
             return '\"' + JsonBuilder.escape(
                 PathUtils.relativize("/", Paths.pathToString(sessionInfo.getWorkspaceName(),
nodeId.getPath()))) + '\"';

Added: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Function1.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Function1.java?rev=1146661&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Function1.java
(added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Function1.java
Thu Jul 14 12:01:22 2011
@@ -0,0 +1,24 @@
+/*
+ * 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.spi2microkernel.util;
+
+public interface Function1<T, R> {
+    R apply(T arg) throws Exception;
+}

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java?rev=1146661&r1=1146660&r2=1146661&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
Thu Jul 14 12:01:22 2011
@@ -27,6 +27,7 @@ import org.apache.jackrabbit.spi.QValueF
 import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
 
 import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -234,7 +235,7 @@ public final class Values {
         }
     }
 
-    public static String valueToString(QValue value) throws RepositoryException {
+    public static String valueToString(QValue value, Function1<QValue, String> binaryHandler)
throws RepositoryException {
         int type = value.getType();
         
         switch(type) {
@@ -263,7 +264,22 @@ public final class Values {
                 return typeEncode(type, JsonBuilder.escape(value.getString()));
             
             case BINARY:
-                return typeEncode(type, JsonBuilder.escape(value.getString()));  // todo
improve handling of binary values
+                if (value.getLength() > 0xffff) {
+                    try {
+                        String blobId = binaryHandler.apply(value);
+                        // fixme encode blobId
+                        throw new UnsupportedRepositoryOperationException();
+                    }
+                    catch (RepositoryException e) {
+                        throw e;
+                    }
+                    catch (Exception e) {
+                        throw new RepositoryException(e.getMessage(), e);
+                    }
+                }
+                else {
+                    return typeEncode(type, JsonBuilder.escape(value.getString()));
+                }
 
             case REFERENCE:
             case WEAKREFERENCE:
@@ -275,16 +291,16 @@ public final class Values {
         }
     }
 
-    public static String valuesToString(QValue[] values) throws RepositoryException {
+    public static String valuesToString(QValue[] values, Function1<QValue, String>
binaryHandler) throws RepositoryException {
         if (values.length == 0) {
             return "[]";
         }
 
         StringBuilder sb = new StringBuilder("[");
-        sb.append(valueToString(values[0]));
+        sb.append(valueToString(values[0], binaryHandler));
 
         for (int k = 1; k < values.length; k++) {
-            sb.append(',').append(valueToString(values[k]));
+            sb.append(',').append(valueToString(values[k], binaryHandler));
         }
         sb.append(']');
 



Mime
View raw message