jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r357013 - in /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: RepositoryImpl.java state/util/Serializer.java state/xml/XMLPersistenceManager.java value/BLOBFileValue.java value/InternalValue.java
Date Thu, 15 Dec 2005 14:03:18 GMT
Author: stefan
Date: Thu Dec 15 06:03:11 2005
New Revision: 357013

URL: http://svn.apache.org/viewcvs?rev=357013&view=rev
Log:
JCR-293 Property.setValue(InputStream) closes stream

Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=357013&r1=357012&r2=357013&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Thu Dec 15 06:03:11 2005
@@ -230,8 +230,11 @@
             throw e;
         }
 
-        // after the workspaces are initialized, we setup a system session for
-        // the virtual nodetype manager
+        // after the workspaces are initialized we pass a system session to
+        // the virtual node type manager
+
+        // todo FIXME it seems odd that the *global* virtual node type manager 
+        // is using a session that is bound to a single specific workspace
         virtNTMgr.setSession(getSystemSession(repConfig.getDefaultWorkspaceName()));
     }
 

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java?rev=357013&r1=357012&r2=357013&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/util/Serializer.java
Thu Dec 15 06:03:11 2005
@@ -207,11 +207,30 @@
                 out.writeUTF(blobId);   // value
                 // replace value instance with value backed by resource
                 // in BLOB store and discard old value instance (e.g. temp file)
-                values[i] = InternalValue.create(blobStore.get(blobId));
+                if (blobStore instanceof ResourceBasedBLOBStore) {
+                    // optimization: if the BLOB store is resource-based
+                    // retrieve the resource directly rather than having
+                    // to read the BLOB from an input stream
+                    FileSystemResource fsRes =
+                            ((ResourceBasedBLOBStore) blobStore).getResource(blobId);
+                    values[i] = InternalValue.create(fsRes);
+                } else {
+                    in = blobStore.get(blobId);
+                    try {
+                        values[i] = InternalValue.create(in);
+                    } finally {
+                        try {
+                            in.close();
+                        } catch (IOException e) {
+                            // ignore
+                        }
+                    }
+                }
                 blobVal.discard();
             } else {
                 /**
                  * because writeUTF(String) has a size limit of 65k,
+                 * Strings are serialized as <length><byte[]>
                  */
                 //out.writeUTF(val.toString());   // value
                 byte[] bytes = val.toString().getBytes(ENCODING);
@@ -269,7 +288,16 @@
                             ((ResourceBasedBLOBStore) blobStore).getResource(s);
                     val = InternalValue.create(fsRes);
                 } else {
-                    val = InternalValue.create(blobStore.get(s));
+                    InputStream is = blobStore.get(s);
+                    try {
+                        val = InternalValue.create(is);
+                    } finally {
+                        try {
+                            is.close();
+                        } catch (IOException e) {
+                            // ignore
+                        }
+                    }
                 }
             } else {
                 /**

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java?rev=357013&r1=357012&r2=357013&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
Thu Dec 15 06:03:11 2005
@@ -319,7 +319,16 @@
                                         ((ResourceBasedBLOBStore) blobStore).getResource(content);
                                 values.add(InternalValue.create(fsRes));
                             } else {
-                                values.add(InternalValue.create(blobStore.get(content)));
+                                InputStream in = blobStore.get(content);
+                                try {
+                                    values.add(InternalValue.create(in));
+                                } finally {
+                                    try {
+                                        in.close();
+                                    } catch (IOException e) {
+                                        // ignore
+                                    }
+                                }
                             }
                         } catch (Exception e) {
                             String msg = "error while reading serialized binary value";
@@ -641,7 +650,25 @@
                                 writer.write(blobId);
                                 // replace value instance with value backed by resource
                                 // in BLOB store and discard old value instance (e.g. temp
file)
-                                values[i] = InternalValue.create(blobStore.get(blobId));
+                                if (blobStore instanceof ResourceBasedBLOBStore) {
+                                    // optimization: if the BLOB store is resource-based
+                                    // retrieve the resource directly rather than having
+                                    // to read the BLOB from an input stream
+                                    FileSystemResource fsRes =
+                                            ((ResourceBasedBLOBStore) blobStore).getResource(blobId);
+                                    values[i] = InternalValue.create(fsRes);
+                                } else {
+                                    in = blobStore.get(blobId);
+                                    try {
+                                        values[i] = InternalValue.create(in);
+                                    } finally {
+                                        try {
+                                            in.close();
+                                        } catch (IOException e) {
+                                            // ignore
+                                        }
+                                    }
+                                }
                                 blobVal.discard();
                             } else {
                                 writer.write(Text.encodeIllegalXMLCharacters(val.toString()));

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java?rev=357013&r1=357012&r2=357013&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
Thu Dec 15 06:03:11 2005
@@ -143,7 +143,6 @@
                 }
             }
         } finally {
-            in.close();
             if (out != null) {
                 out.close();
             }

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java?rev=357013&r1=357012&r2=357013&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
Thu Dec 15 06:03:11 2005
@@ -92,7 +92,16 @@
                     if (value instanceof BLOBFileValue) {
                         return new InternalValue((BLOBFileValue) value);
                     } else {
-                        return new InternalValue(new BLOBFileValue(value.getStream()));
+                        InputStream stream = value.getStream();
+                        try {
+                            return new InternalValue(new BLOBFileValue(stream));
+                        } finally {
+                            try {
+                                stream.close();
+                            } catch (IOException e) {
+                                // ignore
+                            }
+                        }
                     }
                 } catch (IOException ioe) {
                     throw new ValueFormatException(ioe.getMessage());
@@ -363,7 +372,16 @@
         switch (type) {
             case PropertyType.BINARY:
                 try {
-                    return new InternalValue(new BLOBFileValue(((BLOBFileValue) val).getStream()));
+                    InputStream stream = ((BLOBFileValue) val).getStream();
+                    try {
+                        return new InternalValue(new BLOBFileValue(stream));
+                    } finally {
+                        try {
+                            stream.close();
+                        } catch (IOException e) {
+                            // ignore
+                        }
+                    }
                 } catch (IOException ioe) {
                     throw new RepositoryException("failed to copy binary value", ioe);
                 }



Mime
View raw message