jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r570336 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ data/ persistence/bundle/util/ persistence/util/ persistence/xml/ query/lucene/ state/ value/
Date Tue, 28 Aug 2007 06:52:31 GMT
Author: thomasm
Date: Mon Aug 27 23:52:30 2007
New Revision: 570336

URL: http://svn.apache.org/viewvc?rev=570336&view=rev
Log:
JCR-926: BLOBFileValue and InternalValue refactoring, improved garbage collector for the global
data store

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextFilterExtractor.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.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/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java?rev=570336&r1=570335&r2=570336&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
Mon Aug 27 23:52:30 2007
@@ -740,15 +740,13 @@
 
         InternalValue value;
         try {
+            value = InternalValue.createTemporary(stream);
             if (reqType != PropertyType.BINARY) {
                 // type conversion required
+                Value jcrValue = value.toJCRValue(session.getNamespaceResolver());
                 Value targetVal = ValueHelper.convert(
-                        new BLOBFileValue(stream), reqType,
-                        ValueFactoryImpl.getInstance());
-                value = InternalValue.create(targetVal, session.getNamespaceResolver());
-            } else {
-                // no type conversion required
-                value = InternalValue.create(stream);
+                        jcrValue, reqType, ValueFactoryImpl.getInstance());
+                value = InternalValue.create(targetVal, session.getNamespaceResolver(), rep.getDataStore());
             }
         } catch (IOException ioe) {
             String msg = "failed to spool stream to internal storage";

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java?rev=570336&r1=570335&r2=570336&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
Mon Aug 27 23:52:30 2007
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.data;
 
 import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.observation.SynchronousEventListener;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -35,7 +36,6 @@
 import javax.jcr.Workspace;
 import javax.jcr.observation.Event;
 import javax.jcr.observation.EventIterator;
-import javax.jcr.observation.EventListener;
 import javax.jcr.observation.ObservationManager;
 
 /**
@@ -50,11 +50,11 @@
  */
 public class GarbageCollector {
 
-    private static final int WAIT_FOR_EVENT_LISTENERS = 5000;
-
     private final ScanEventListener callback;
 
     private final int sleepBetweenNodes;
+    
+    private final int sleepBetweenEvents;
 
     private DataStore store;
 
@@ -64,12 +64,20 @@
 
     // TODO Observation: it is up to the implementation whether changes made to
     // the subtree below jcr:system trigger events.
-    // TODO How long do we have to wait for the observation listeners?
     // TODO It should be possible to stop and restart a garbage collection scan.
     // TODO It may be possible to delete files early, see rememberNode()
 
-    public GarbageCollector(int sleepBetweenNodes, ScanEventListener callback) {
+    /**
+     * Create a new garbage collector. 
+     * To display the progress, a callback object may be used.
+     * 
+     * @param callback if set, this is called while scanning
+     * @param sleepBetweenNodes the number of milliseconds to sleep in the main scan loop
(0 if the scan should run at full speed)
+     * @param sleepBetweenEvents the number of milliseconds to sleep while processing events
(0 to avoid delays in the application)
+     */
+    public GarbageCollector(ScanEventListener callback, int sleepBetweenNodes, int sleepBetweenEvents)
{
         this.sleepBetweenNodes = sleepBetweenNodes;
+        this.sleepBetweenEvents = sleepBetweenEvents;
         this.callback = callback;
     }
 
@@ -89,16 +97,11 @@
 
         // adding a link to a BLOB updates the modified date
         // reading usually doesn't, but when scanning, it does
-        recurse(session.getRootNode());
+        recurse(session.getRootNode(), sleepBetweenNodes);
     }
 
     public void stopScan() throws RepositoryException {
         checkScanStarted();
-        try {
-            Thread.sleep(WAIT_FOR_EVENT_LISTENERS);
-        } catch (InterruptedException e) {
-            // ignore
-        }
         for (int i = 0; i < listeners.size(); i++) {
             Listener listener = (Listener) listeners.get(i);
             try {
@@ -132,11 +135,11 @@
         return store;
     }
 
-    private void recurse(final Node n) throws RepositoryException,
+    private void recurse(final Node n, int sleep) throws RepositoryException,
             IllegalStateException, IOException {
-        if (sleepBetweenNodes > 0) {
+        if (sleep > 0) {
             try {
-                Thread.sleep(sleepBetweenNodes);
+                Thread.sleep(sleep);
             } catch (InterruptedException e) {
                 // ignore
             }
@@ -166,7 +169,7 @@
             callback.afterScanning(n);
         }
         for (NodeIterator it = n.getNodes(); it.hasNext();) {
-            recurse(it.nextNode());
+            recurse(it.nextNode(), sleep);
         }
     }
 
@@ -204,8 +207,9 @@
 
     /**
      * Event listener to detect moved nodes.
+     * A SynchronousEventListener is used to make sure this method is called before the main
iteration ends.
      */
-    class Listener implements EventListener {
+    class Listener implements SynchronousEventListener {
 
         private final Session session;
 
@@ -231,6 +235,13 @@
         }
 
         public void onEvent(EventIterator events) {
+            if(sleepBetweenEvents > 0) {
+                try {
+                    Thread.sleep(sleepBetweenEvents);
+                } catch (InterruptedException e) {
+                    // ignore
+                }
+            }
             while (events.hasNext()) {
                 Event event = events.nextEvent();
                 try {
@@ -239,7 +250,7 @@
                         Item item = session.getItem(path);
                         if (item.isNode()) {
                             Node n = (Node) item;
-                            recurse(n);
+                            recurse(n, sleepBetweenEvents);
                         }
                     } catch (PathNotFoundException e) {
                         // ignore

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java?rev=570336&r1=570335&r2=570336&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
Mon Aug 27 23:52:30 2007
@@ -326,7 +326,7 @@
                             if (blobStore instanceof ResourceBasedBLOBStore) {
                                 val = InternalValue.create(((ResourceBasedBLOBStore) blobStore).getResource(blobIds[i]));
                             } else {
-                                val = InternalValue.create(blobStore.get(blobIds[i]), false);
+                                val = InternalValue.create(blobStore.get(blobIds[i]));
                             }
                         } catch (IOException e) {
                             if (errorHandling.ignoreMissingBlobs()) {
@@ -586,7 +586,7 @@
                                 if (blobStore instanceof ResourceBasedBLOBStore) {
                                     values[i] = InternalValue.create(((ResourceBasedBLOBStore)
blobStore).getResource(blobId));
                                 } else {
-                                    values[i] = InternalValue.create(blobStore.get(blobId),
false);
+                                    values[i] = InternalValue.create(blobStore.get(blobId));
                                 }
                             } catch (Exception e) {
                                 log.error("Error while reloading blob. truncating. id=" +
state.getId() +

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java?rev=570336&r1=570335&r2=570336&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
Mon Aug 27 23:52:30 2007
@@ -146,7 +146,7 @@
             throws IOException {
         NodeReferences state = new NodeReferences(id);
         int count = in.readInt();   // count & version
-        int version = (count >> 24) | 0x0ff;
+        // int version = (count >> 24) | 0x0ff;
         count &= 0x00ffffff;
         for (int i = 0; i < count; i++) {
             state.addReference(readPropertyId(in));    // propertyId
@@ -302,7 +302,7 @@
                                 val = InternalValue.create(
                                         ((ResourceBasedBLOBStore) blobStore).getResource(s));
                             } else {
-                                val = InternalValue.create(blobStore.get(s), false);
+                                val = InternalValue.create(blobStore.get(s));
                             }
                         } catch (IOException e) {
                             if (errorHandling.ignoreMissingBlobs()) {
@@ -399,7 +399,7 @@
                             if (blobStore instanceof ResourceBasedBLOBStore) {
                                 values[i] = InternalValue.create(((ResourceBasedBLOBStore)
blobStore).getResource(blobId));
                             } else {
-                                values[i] = InternalValue.create(blobStore.get(blobId), false);
+                                values[i] = InternalValue.create(blobStore.get(blobId));
                             }
                             blobVal.discard();
                         } else {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java?rev=570336&r1=570335&r2=570336&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java
Mon Aug 27 23:52:30 2007
@@ -219,7 +219,7 @@
                 } else {
                     in = blobStore.get(blobId);
                     try {
-                        values[i] = InternalValue.create(in, false);
+                        values[i] = InternalValue.create(in);
                     } finally {
                         try {
                             in.close();
@@ -292,7 +292,7 @@
                 } else {
                     InputStream is = blobStore.get(s);
                     try {
-                        val = InternalValue.create(is, false);
+                        val = InternalValue.create(is);
                     } finally {
                         try {
                             is.close();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java?rev=570336&r1=570335&r2=570336&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java
Mon Aug 27 23:52:30 2007
@@ -354,7 +354,7 @@
                             } else {
                                 InputStream in = blobStore.get(content);
                                 try {
-                                    values.add(InternalValue.create(in, false));
+                                    values.add(InternalValue.create(in));
                                 } finally {
                                     try {
                                         in.close();
@@ -693,7 +693,7 @@
                                 } else {
                                     in = blobStore.get(blobId);
                                     try {
-                                        values[i] = InternalValue.create(in, false);
+                                        values[i] = InternalValue.create(in);
                                     } finally {
                                         try {
                                             in.close();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextFilterExtractor.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextFilterExtractor.java?rev=570336&r1=570335&r2=570336&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextFilterExtractor.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextFilterExtractor.java
Mon Aug 27 23:52:30 2007
@@ -97,7 +97,7 @@
      */
     public Reader extractText(InputStream stream, String type, String encoding)
             throws IOException {
-        final InternalValue value = InternalValue.create(stream);
+        final InternalValue value = InternalValue.createTemporary(stream);
         try {
             PropertyState state = new PropertyState(
                     (PropertyId) null, ItemState.STATUS_EXISTING, true);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java?rev=570336&r1=570335&r2=570336&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
Mon Aug 27 23:52:30 2007
@@ -345,7 +345,7 @@
                         public void close() {
                             // nop
                         }
-                    }, false);
+                    });
                 } else {
                     values[i] = InternalValue.valueOf(in.readUTF(), type);
                 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java?rev=570336&r1=570335&r2=570336&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
Mon Aug 27 23:52:30 2007
@@ -18,17 +18,11 @@
 
 import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
-import org.apache.jackrabbit.util.ISO8601;
 import org.apache.jackrabbit.util.TransientFileFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -36,9 +30,9 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
 import java.util.Arrays;
-import java.util.Calendar;
+
+import javax.jcr.RepositoryException;
 
 /**
  * <code>BLOBFileValue</code> represents a binary <code>Value</code>
which is
@@ -50,7 +44,7 @@
  * This is class is for Jackrabbit-internal use only. Applications should
  * use <code>javax.jcr.ValueFactory</code> to create binary values.
  */
-public class BLOBFileValue implements Value {
+public class BLOBFileValue {
 
     /**
      * The default logger
@@ -58,16 +52,6 @@
     private static Logger log = LoggerFactory.getLogger(BLOBFileValue.class);
 
     /**
-     * the property type
-     */
-    public static final int TYPE = PropertyType.BINARY;
-
-    /**
-     * the default encoding
-     */
-    protected static final String DEFAULT_ENCODING = "UTF-8";
-
-    /**
      * empty array
      */
     private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
@@ -100,28 +84,6 @@
     private final FileSystemResource fsResource;
 
     /**
-     * converted text
-     */
-    private String text = null;
-
-    /**
-     * Creates a new <code>BLOBFileValue</code> instance from an
-     * <code>InputStream</code>. The contents of the stream is spooled
-     * to a temporary file or to a byte buffer if its size is smaller than
-     * {@link #MAX_BUFFER_SIZE}.
-     * <p/>
-     * The new instance represents a <i>temporary</i> value whose dynamically
-     * allocated resources will be freed explicitly on {@link #discard()}.
-     *
-     * @param in stream to be represented as a <code>BLOBFileValue</code> instance
-     * @throws IOException if an error occurs while reading from the stream or
-     *                     writing to the temporary file
-     */
-    public BLOBFileValue(InputStream in) throws IOException {
-        this(in, true);
-    }
-
-    /**
      * Creates a new <code>BLOBFileValue</code> instance from an
      * <code>InputStream</code>. The contents of the stream is spooled
      * to a temporary file or to a byte buffer if its size is smaller than
@@ -139,7 +101,7 @@
      * @throws IOException if an error occurs while reading from the stream or
      *                     writing to the temporary file
      */
-    public BLOBFileValue(InputStream in, boolean temp) throws IOException {
+    BLOBFileValue(InputStream in, boolean temp) throws IOException {
         byte[] spoolBuffer = new byte[0x2000];
         int read;
         int len = 0;
@@ -189,7 +151,7 @@
      * @param bytes byte array to be represented as a <code>BLOBFileValue</code>
      *              instance
      */
-    public BLOBFileValue(byte[] bytes) {
+    BLOBFileValue(byte[] bytes) {
         buffer = bytes;
         file = null;
         fsResource = null;
@@ -203,7 +165,7 @@
      * @param file file to be represented as a <code>BLOBFileValue</code> instance
      * @throws IOException if the file can not be read
      */
-    public BLOBFileValue(File file) throws IOException {
+    BLOBFileValue(File file) throws IOException {
         String path = file.getCanonicalPath();
         if (!file.isFile()) {
             throw new IOException(path + ": the specified file does not exist");
@@ -225,7 +187,7 @@
      * @param fsResource resource in virtual file system
      * @throws IOException if the resource can not be read
      */
-    public BLOBFileValue(FileSystemResource fsResource) throws IOException {
+    BLOBFileValue(FileSystemResource fsResource) throws IOException {
         try {
             if (!fsResource.exists()) {
                 throw new IOException(fsResource.getPath()
@@ -302,7 +264,7 @@
      *
      * @see #discard()
      */
-    public void delete() {
+    private void delete() {
         if (!temp) {
             delete(false);
         }
@@ -339,51 +301,6 @@
         }
     }
 
-    /**
-     * Spools the contents of this <code>BLOBFileValue</code> to the given
-     * output stream.
-     *
-     * @param out output stream
-     * @throws RepositoryException if the input stream for this
-     *                             <code>BLOBFileValue</code> could not be obtained
-     * @throws IOException         if an error occurs while while spooling
-     */
-    public void spool(OutputStream out) throws RepositoryException, IOException {
-        InputStream in;
-        if (file != null) {
-            // this instance is backed by a 'real' file
-            try {
-                in = new FileInputStream(file);
-            } catch (FileNotFoundException fnfe) {
-                throw new RepositoryException("file backing binary value not found",
-                        fnfe);
-            }
-        } else if (fsResource != null) {
-            // this instance is backed by a resource in the virtual file system
-            try {
-                in = fsResource.getInputStream();
-            } catch (FileSystemException fse) {
-                throw new RepositoryException(fsResource.getPath()
-                        + ": the specified resource does not exist", fse);
-            }
-        } else {
-            // this instance is backed by an in-memory buffer
-            in = new ByteArrayInputStream(buffer);
-        }
-        try {
-            byte[] buffer = new byte[0x2000];
-            int read;
-            while ((read = in.read(buffer)) > 0) {
-                out.write(buffer, 0, read);
-            }
-        } finally {
-            try {
-                in.close();
-            } catch (IOException ignore) {
-            }
-        }
-    }
-
     //-------------------------------------------< java.lang.Object overrides >
     /**
      * Returns a string representation of this <code>BLOBFileValue</code>
@@ -434,42 +351,6 @@
         return 0;
     }
 
-    //----------------------------------------------------------------< Value >
-    /**
-     * {@inheritDoc}
-     */
-    public int getType() {
-        return TYPE;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String getString()
-            throws ValueFormatException, IllegalStateException,
-            RepositoryException {
-        if (text == null) {
-            ByteArrayOutputStream out = new ByteArrayOutputStream();
-            try {
-                spool(out);
-                byte[] data = out.toByteArray();
-                text = new String(data, DEFAULT_ENCODING);
-            } catch (UnsupportedEncodingException e) {
-                throw new RepositoryException(DEFAULT_ENCODING
-                        + " not supported on this platform", e);
-            } catch (IOException e) {
-                throw new ValueFormatException("conversion from stream to string failed",
e);
-            } finally {
-                try {
-                    out.close();
-                } catch (IOException e) {
-                    // ignore
-                }
-            }
-        }
-        return text;
-    }
-
     /**
      * {@inheritDoc}
      */
@@ -497,52 +378,4 @@
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public double getDouble()
-            throws ValueFormatException, IllegalStateException,
-            RepositoryException {
-        try {
-            return Double.parseDouble(getString());
-        } catch (NumberFormatException e) {
-            throw new ValueFormatException("conversion to double failed", e);
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Calendar getDate()
-            throws ValueFormatException, IllegalStateException,
-            RepositoryException {
-        Calendar cal = ISO8601.parse(getString());
-        if (cal != null) {
-            return cal;
-        } else {
-            throw new ValueFormatException("not a valid date format");
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public long getLong()
-            throws ValueFormatException, IllegalStateException,
-            RepositoryException {
-        try {
-            return Long.parseLong(getString());
-        } catch (NumberFormatException e) {
-            throw new ValueFormatException("conversion to long failed", e);
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean getBoolean()
-            throws ValueFormatException, IllegalStateException,
-            RepositoryException {
-        return Boolean.valueOf(getString()).booleanValue();
-    }
 }

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=570336&r1=570335&r2=570336&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
Mon Aug 27 23:52:30 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.value;
 
+import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.name.NameException;
@@ -69,9 +70,14 @@
 
     public static final InternalValue[] EMPTY_ARRAY = new InternalValue[0];
 
-    public static final InternalValue BOOLEAN_TRUE = create(true);
+    private static final InternalValue BOOLEAN_TRUE = new InternalValue(true);
 
-    public static final InternalValue BOOLEAN_FALSE = create(false);
+    private static final InternalValue BOOLEAN_FALSE = new InternalValue(false);
+    
+    /**
+     * If set to 'true', the new global data store will be used, otherwise the old blob store
implementation
+     */
+    public static final boolean USE_DATA_STORE = Boolean.valueOf(System.getProperty("org.jackrabbit.useDataStore",
"false")).booleanValue();
 
     private final Object val;
     private final int type;
@@ -84,6 +90,18 @@
      * @throws ValueFormatException
      * @throws RepositoryException
      */
+    public static InternalValue create(Value value, NamespaceResolver nsResolver, DataStore
store)
+            throws ValueFormatException, RepositoryException {
+        return create(value, nsResolver);
+    }
+
+    /**
+     * @param value
+     * @param nsResolver
+     * @return
+     * @throws ValueFormatException
+     * @throws RepositoryException
+     */
     public static InternalValue create(Value value, NamespaceResolver nsResolver)
             throws ValueFormatException, RepositoryException {
         if (value == null) {
@@ -98,7 +116,7 @@
                     } else {
                         InputStream stream = value.getStream();
                         try {
-                            return new InternalValue(new BLOBFileValue(stream));
+                            return createTemporary(stream);
                         } finally {
                             try {
                                 stream.close();
@@ -177,7 +195,7 @@
      * @return the created value
      */
     public static InternalValue create(boolean value) {
-        return new InternalValue(value);
+        return value ? BOOLEAN_TRUE : BOOLEAN_FALSE;
     }
 
     /**
@@ -193,9 +211,9 @@
      * @return
      * @throws IOException
      */
-    public static InternalValue create(InputStream value) throws IOException {
-        return new InternalValue(new BLOBFileValue(value));
-    }
+    public static InternalValue createTemporary(InputStream value) throws IOException {
+        return new InternalValue(new BLOBFileValue(value, true));
+    }    
 
     /**
      * @param value
@@ -203,8 +221,8 @@
      * @return
      * @throws IOException
      */
-    public static InternalValue create(InputStream value, boolean temp) throws IOException
{
-        return new InternalValue(new BLOBFileValue(value, temp));
+    public static InternalValue create(InputStream value) throws IOException {
+        return new InternalValue(new BLOBFileValue(value, false));
     }
 
     /**
@@ -247,30 +265,6 @@
     }
 
     /**
-     * @param values
-     * @return the created value
-     */
-    public static InternalValue[] create(String[] values) {
-        InternalValue[] ret = new InternalValue[values.length];
-        for (int i = 0; i < values.length; i++) {
-            ret[i] = new InternalValue(values[i]);
-        }
-        return ret;
-    }
-
-    /**
-     * @param values
-     * @return the created value
-     */
-    public static InternalValue[] create(Calendar[] values) {
-        InternalValue[] ret = new InternalValue[values.length];
-        for (int i = 0; i < values.length; i++) {
-            ret[i] = new InternalValue(values[i]);
-        }
-        return ret;
-    }
-
-    /**
      * @param value
      * @return the created value
      */
@@ -393,7 +387,7 @@
             try {
                 InputStream stream = ((BLOBFileValue) val).getStream();
                 try {
-                    return new InternalValue(new BLOBFileValue(stream));
+                    return createTemporary(stream);
                 } finally {
                     try {
                         stream.close();
@@ -428,7 +422,7 @@
     public static InternalValue valueOf(String s, int type) {
         switch (type) {
             case PropertyType.BOOLEAN:
-                return new InternalValue(Boolean.valueOf(s).booleanValue());
+                return create(Boolean.valueOf(s).booleanValue());
             case PropertyType.DATE:
                 return new InternalValue(ISO8601.parse(s));
             case PropertyType.DOUBLE:
@@ -448,7 +442,7 @@
                 throw new IllegalArgumentException(
                         "this method does not support the type PropertyType.BINARY");
             default:
-                throw new IllegalArgumentException("illegal type");
+                throw new IllegalArgumentException("illegal type: " + type);
         }
     }
 



Mime
View raw message