jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1576690 [8/10] - in /jackrabbit/trunk: examples/jackrabbit-firsthops/ examples/jackrabbit-firsthops/src/main/resources/ jackrabbit-aws-ext/ jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ jackrabbit-aws-ext/src/main/java/or...
Date Wed, 12 Mar 2014 11:05:08 GMT
Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/FileUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/FileUtil.java?rev=1576690&r1=1576689&r2=1576690&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/FileUtil.java (original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/FileUtil.java Wed Mar 12 11:05:06 2014
@@ -1,99 +1,99 @@
-/*
- * 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.core.fs.local;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.commons.io.FileUtils;
-
-/**
- * Static utility methods for recursively copying and deleting files and
- * directories.
- */
-public final class FileUtil {
-
-    /**
-     * private constructor
-     */
-    private FileUtil() {
-    }
-
-    /**
-     * Recursively copies the given file or directory to the
-     * given destination.
-     *
-     * @param src source file or directory
-     * @param dest destination file or directory
-     * @throws IOException if the file or directory cannot be copied
-     */
-    public static void copy(File src, File dest) throws IOException {
-        if (!src.canRead()) {
-            throw new IOException(src.getPath() + " can't be read from.");
-        }
-        if (src.isDirectory()) {
-            // src is a folder
-            if (dest.isFile()) {
-                throw new IOException("can't copy a folder to a file");
-            }
-            if (!dest.exists()) {
-                dest.mkdirs();
-            }
-            if (!dest.canWrite()) {
-                throw new IOException("can't write to " + dest.getPath());
-            }
-            File[] children = src.listFiles();
-            for (int i = 0; i < children.length; i++) {
-                copy(children[i], new File(dest, children[i].getName()));
-            }
-        } else {
-            // src is a file
-            File destParent;
-            if (dest.isDirectory()) {
-                // dest is a folder
-                destParent = dest;
-                dest = new File(destParent, src.getName());
-            } else {
-                destParent = dest.getParentFile();
-            }
-            if (!destParent.canWrite()) {
-                throw new IOException("can't write to " + destParent.getPath());
-            }
-
-            FileUtils.copyFile(src, dest);
-        }
-    }
-
-    /**
-     * Recursively deletes the given file or directory.
-     *
-     * @param f file or directory
-     * @throws IOException if the file or directory cannot be deleted
-     */
-    public static void delete(File f) throws IOException {
-        if (f.isDirectory()) {
-            // it's a folder, list children first
-            File[] children = f.listFiles();
-            for (int i = 0; i < children.length; i++) {
-                delete(children[i]);
-            }
-        }
-        if (!f.delete()) {
-            throw new IOException("Unable to delete " + f.getPath());
-        }
-    }
-}
+/*
+ * 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.core.fs.local;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Static utility methods for recursively copying and deleting files and
+ * directories.
+ */
+public final class FileUtil {
+
+    /**
+     * private constructor
+     */
+    private FileUtil() {
+    }
+
+    /**
+     * Recursively copies the given file or directory to the
+     * given destination.
+     *
+     * @param src source file or directory
+     * @param dest destination file or directory
+     * @throws IOException if the file or directory cannot be copied
+     */
+    public static void copy(File src, File dest) throws IOException {
+        if (!src.canRead()) {
+            throw new IOException(src.getPath() + " can't be read from.");
+        }
+        if (src.isDirectory()) {
+            // src is a folder
+            if (dest.isFile()) {
+                throw new IOException("can't copy a folder to a file");
+            }
+            if (!dest.exists()) {
+                dest.mkdirs();
+            }
+            if (!dest.canWrite()) {
+                throw new IOException("can't write to " + dest.getPath());
+            }
+            File[] children = src.listFiles();
+            for (int i = 0; i < children.length; i++) {
+                copy(children[i], new File(dest, children[i].getName()));
+            }
+        } else {
+            // src is a file
+            File destParent;
+            if (dest.isDirectory()) {
+                // dest is a folder
+                destParent = dest;
+                dest = new File(destParent, src.getName());
+            } else {
+                destParent = dest.getParentFile();
+            }
+            if (!destParent.canWrite()) {
+                throw new IOException("can't write to " + destParent.getPath());
+            }
+
+            FileUtils.copyFile(src, dest);
+        }
+    }
+
+    /**
+     * Recursively deletes the given file or directory.
+     *
+     * @param f file or directory
+     * @throws IOException if the file or directory cannot be deleted
+     */
+    public static void delete(File f) throws IOException {
+        if (f.isDirectory()) {
+            // it's a folder, list children first
+            File[] children = f.listFiles();
+            for (int i = 0; i < children.length; i++) {
+                delete(children[i]);
+            }
+        }
+        if (!f.delete()) {
+            throw new IOException("Unable to delete " + f.getPath());
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/FileUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/HandleMonitor.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/HandleMonitor.java?rev=1576690&r1=1576689&r2=1576690&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/HandleMonitor.java (original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/HandleMonitor.java Wed Mar 12 11:05:06 2014
@@ -1,217 +1,217 @@
-/*
- * 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.core.fs.local;
-
-import org.apache.jackrabbit.util.LazyFileInputStream;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.HashSet;
-
-/**
- * This Class implements a very simple open handle monitor for the local
- * file system. This is usefull, if the list of open handles, referenced by
- * an open FileInputStream() should be tracked. This can cause problems on
- * windows filesystems where open files cannot be deleted.
- */
-public class HandleMonitor {
-
-    /**
-     * The default logger
-     */
-    private static Logger log = LoggerFactory.getLogger(HandleMonitor.class);
-
-    /**
-     * the map of open handles (key=File, value=Handle)
-     */
-    private HashMap<File, Handle> openHandles = new HashMap<File, Handle>();
-
-    /**
-     * Opens a file and returns an InputStream
-     *
-     * @param file
-     * @return
-     * @throws FileNotFoundException
-     */
-    public InputStream open(File file) throws FileNotFoundException {
-        Handle handle = getHandle(file);
-        InputStream in = handle.open();
-        return in;
-    }
-
-    /**
-     * Checks, if the file is open
-     * @param file
-     * @return
-     */
-    public boolean isOpen(File file) {
-        return openHandles.containsKey(file);
-    }
-
-    /**
-     * Closes a file
-     * @param file
-     */
-    private void close(File file) {
-        openHandles.remove(file);
-    }
-
-    /**
-     * Returns the handle for a file.
-     * @param file
-     * @return
-     */
-    private Handle getHandle(File file) {
-        Handle handle = openHandles.get(file);
-        if (handle == null) {
-            handle = new Handle(file);
-            openHandles.put(file, handle);
-        }
-        return handle;
-    }
-
-    /**
-     * Dumps the contents of this monitor
-     */
-    public void dump() {
-        log.info("Number of open files: " + openHandles.size());
-        for (File file : openHandles.keySet()) {
-            Handle handle = openHandles.get(file);
-            handle.dump();
-        }
-    }
-
-    /**
-     * Dumps the information for a file
-     * @param file
-     */
-    public void dump(File file) {
-        Handle handle = openHandles.get(file);
-        if (handle != null) {
-            handle.dump(true);
-        }
-    }
-
-    /**
-     * Class representing all open handles to a file
-     */
-    private class Handle {
-
-        /**
-         * the file of this handle
-         */
-        private File file;
-
-        /**
-         * all open streams of this handle
-         */
-        private HashSet<Handle.MonitoredInputStream> streams = new HashSet<Handle.MonitoredInputStream>();
-
-        /**
-         * Creates a new handle for a file
-         * @param file
-         */
-        private Handle(File file) {
-            this.file = file;
-        }
-
-        /**
-         * opens a stream for this handle
-         * @return
-         * @throws FileNotFoundException
-         */
-        private InputStream open() throws FileNotFoundException {
-            Handle.MonitoredInputStream in = new Handle.MonitoredInputStream(file);
-            streams.add(in);
-            return in;
-        }
-
-        /**
-         * Closes a stream
-         * @param in
-         */
-        private void close(MonitoredInputStream in) {
-            streams.remove(in);
-            if (streams.isEmpty()) {
-                HandleMonitor.this.close(file);
-            }
-        }
-
-        /**
-         * Dumps this handle
-         */
-        private void dump() {
-            dump(false);
-        }
-
-        /**
-         * Dumps this handle
-         */
-        private void dump(boolean detailed) {
-            if (detailed) {
-                log.info("- " + file.getPath() + ", " + streams.size());
-                for (Handle.MonitoredInputStream in : streams) {
-                    in.dump();
-                }
-            } else {
-                log.info("- " + file.getPath() + ", " + streams.size());
-            }
-        }
-
-        /**
-         * Delegating input stream that registers/unregisters itself from the
-         * handle.
-         */
-        private class MonitoredInputStream extends LazyFileInputStream {
-
-            /**
-             * throwable of the time, the stream was created
-             */
-            private final Throwable throwable = new Exception();
-
-            /**
-             * {@inheritDoc}
-             */
-            private MonitoredInputStream(File file) throws FileNotFoundException {
-                super(file);
-            }
-
-            /**
-             * dumps this stream
-             */
-            private void dump() {
-                log.info("- opened by : ", throwable);
-            }
-
-            /**
-             * {@inheritDoc}
-             */
-            public void close() throws IOException {
-                // remove myself from the set
-                Handle.this.close(this);
-                super.close();
-            }
-
-        }
-    }
-
-}
+/*
+ * 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.core.fs.local;
+
+import org.apache.jackrabbit.util.LazyFileInputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.HashSet;
+
+/**
+ * This Class implements a very simple open handle monitor for the local
+ * file system. This is usefull, if the list of open handles, referenced by
+ * an open FileInputStream() should be tracked. This can cause problems on
+ * windows filesystems where open files cannot be deleted.
+ */
+public class HandleMonitor {
+
+    /**
+     * The default logger
+     */
+    private static Logger log = LoggerFactory.getLogger(HandleMonitor.class);
+
+    /**
+     * the map of open handles (key=File, value=Handle)
+     */
+    private HashMap<File, Handle> openHandles = new HashMap<File, Handle>();
+
+    /**
+     * Opens a file and returns an InputStream
+     *
+     * @param file
+     * @return
+     * @throws FileNotFoundException
+     */
+    public InputStream open(File file) throws FileNotFoundException {
+        Handle handle = getHandle(file);
+        InputStream in = handle.open();
+        return in;
+    }
+
+    /**
+     * Checks, if the file is open
+     * @param file
+     * @return
+     */
+    public boolean isOpen(File file) {
+        return openHandles.containsKey(file);
+    }
+
+    /**
+     * Closes a file
+     * @param file
+     */
+    private void close(File file) {
+        openHandles.remove(file);
+    }
+
+    /**
+     * Returns the handle for a file.
+     * @param file
+     * @return
+     */
+    private Handle getHandle(File file) {
+        Handle handle = openHandles.get(file);
+        if (handle == null) {
+            handle = new Handle(file);
+            openHandles.put(file, handle);
+        }
+        return handle;
+    }
+
+    /**
+     * Dumps the contents of this monitor
+     */
+    public void dump() {
+        log.info("Number of open files: " + openHandles.size());
+        for (File file : openHandles.keySet()) {
+            Handle handle = openHandles.get(file);
+            handle.dump();
+        }
+    }
+
+    /**
+     * Dumps the information for a file
+     * @param file
+     */
+    public void dump(File file) {
+        Handle handle = openHandles.get(file);
+        if (handle != null) {
+            handle.dump(true);
+        }
+    }
+
+    /**
+     * Class representing all open handles to a file
+     */
+    private class Handle {
+
+        /**
+         * the file of this handle
+         */
+        private File file;
+
+        /**
+         * all open streams of this handle
+         */
+        private HashSet<Handle.MonitoredInputStream> streams = new HashSet<Handle.MonitoredInputStream>();
+
+        /**
+         * Creates a new handle for a file
+         * @param file
+         */
+        private Handle(File file) {
+            this.file = file;
+        }
+
+        /**
+         * opens a stream for this handle
+         * @return
+         * @throws FileNotFoundException
+         */
+        private InputStream open() throws FileNotFoundException {
+            Handle.MonitoredInputStream in = new Handle.MonitoredInputStream(file);
+            streams.add(in);
+            return in;
+        }
+
+        /**
+         * Closes a stream
+         * @param in
+         */
+        private void close(MonitoredInputStream in) {
+            streams.remove(in);
+            if (streams.isEmpty()) {
+                HandleMonitor.this.close(file);
+            }
+        }
+
+        /**
+         * Dumps this handle
+         */
+        private void dump() {
+            dump(false);
+        }
+
+        /**
+         * Dumps this handle
+         */
+        private void dump(boolean detailed) {
+            if (detailed) {
+                log.info("- " + file.getPath() + ", " + streams.size());
+                for (Handle.MonitoredInputStream in : streams) {
+                    in.dump();
+                }
+            } else {
+                log.info("- " + file.getPath() + ", " + streams.size());
+            }
+        }
+
+        /**
+         * Delegating input stream that registers/unregisters itself from the
+         * handle.
+         */
+        private class MonitoredInputStream extends LazyFileInputStream {
+
+            /**
+             * throwable of the time, the stream was created
+             */
+            private final Throwable throwable = new Exception();
+
+            /**
+             * {@inheritDoc}
+             */
+            private MonitoredInputStream(File file) throws FileNotFoundException {
+                super(file);
+            }
+
+            /**
+             * dumps this stream
+             */
+            private void dump() {
+                log.info("- opened by : ", throwable);
+            }
+
+            /**
+             * {@inheritDoc}
+             */
+            public void close() throws IOException {
+                // remove myself from the set
+                Handle.this.close(this);
+                super.close();
+            }
+
+        }
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/HandleMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/LocalFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/LocalFileSystem.java?rev=1576690&r1=1576689&r2=1576690&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/LocalFileSystem.java (original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/LocalFileSystem.java Wed Mar 12 11:05:06 2014
@@ -1,388 +1,388 @@
-/*
- * 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.core.fs.local;
-
-import org.apache.jackrabbit.core.fs.FileSystem;
-import org.apache.jackrabbit.core.fs.FileSystemException;
-import org.apache.jackrabbit.core.fs.local.FileUtil;
-import org.apache.jackrabbit.core.fs.local.HandleMonitor;
-import org.apache.jackrabbit.util.LazyFileInputStream;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * A <code>LocalFileSystem</code> ...
- */
-public class LocalFileSystem implements FileSystem {
-
-    private static Logger log = LoggerFactory.getLogger(LocalFileSystem.class);
-
-    private File root;
-
-    private HandleMonitor monitor;
-
-    /**
-     * Default constructor
-     */
-    public LocalFileSystem() {
-    }
-
-    public String getPath() {
-        if (root != null) {
-            return root.getPath();
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * Sets the path to the root directory of this local filesystem. please note
-     * that this method can be called via reflection during initialization and
-     * must not be altered.
-     *
-     * @param rootPath the path to the root directory
-     */
-    public void setPath(String rootPath) {
-        setRoot(new File(osPath(rootPath)));
-    }
-
-    public void setRoot(File root) {
-        this.root = root;
-    }
-
-    /**
-     * Enables/Disables the use of the handle monitor.
-     *
-     * @param enable
-     */
-    public void setEnableHandleMonitor(String enable) {
-        setEnableHandleMonitor(Boolean.valueOf(enable).booleanValue());
-    }
-
-    /**
-     * Enables/Disables the use of the handle monitor.
-     *
-     * @param enable flag
-     */
-    public void setEnableHandleMonitor(boolean enable) {
-        if (enable && monitor == null) {
-            monitor = new HandleMonitor();
-        }
-        if (!enable && monitor != null) {
-            monitor = null;
-        }
-    }
-
-    /**
-     * Returns <code>true</code> if use of the handle monitor is currently
-     * enabled, otherwise returns <code>false</code>.
-     *
-     * @see #setEnableHandleMonitor(boolean)
-     */
-    public String getEnableHandleMonitor() {
-        return monitor == null ? "false" : "true";
-    }
-
-    private String osPath(String genericPath) {
-        if (File.separator.equals(SEPARATOR)) {
-            return genericPath;
-        }
-        return genericPath.replace(SEPARATOR_CHAR, File.separatorChar);
-    }
-
-    //-------------------------------------------< java.lang.Object overrides >
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj instanceof LocalFileSystem) {
-            LocalFileSystem other = (LocalFileSystem) obj;
-            if (root == null) {
-                return other.root == null;
-            } else {
-                return root.equals(other.root);
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Returns zero to satisfy the Object equals/hashCode contract.
-     * This class is mutable and not meant to be used as a hash key.
-     *
-     * @return always zero
-     * @see Object#hashCode()
-     */
-    public int hashCode() {
-        return 0;
-    }
-
-    //-----------------------------------------------------------< FileSystem >
-    /**
-     * {@inheritDoc}
-     */
-    public void init() throws FileSystemException {
-        if (root == null) {
-            String msg = "root directory not set";
-            log.debug(msg);
-            throw new FileSystemException(msg);
-        }
-
-        if (root.exists()) {
-            if (!root.isDirectory()) {
-                String msg = "path does not denote a folder";
-                log.debug(msg);
-                throw new FileSystemException(msg);
-            }
-        } else {
-            if (!root.mkdirs()) {
-                String msg = "failed to create root";
-                log.debug(msg);
-                throw new FileSystemException(msg);
-            }
-        }
-        log.info("LocalFileSystem initialized at path " + root.getPath());
-        if (monitor != null) {
-            log.info("LocalFileSystem using handle monitor");
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void close() throws FileSystemException {
-        root = null;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void createFolder(String folderPath) throws FileSystemException {
-        File f = new File(root, osPath(folderPath));
-        if (f.exists()) {
-            String msg = f.getPath() + " already exists";
-            log.debug(msg);
-            throw new FileSystemException(msg);
-        }
-        if (!f.mkdirs()) {
-            String msg = "failed to create folder " + f.getPath();
-            log.debug(msg);
-            throw new FileSystemException(msg);
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void deleteFile(String filePath) throws FileSystemException {
-        File f = new File(root, osPath(filePath));
-        if (!f.isFile()) {
-            String msg = f.getPath() + " does not denote an existing file";
-            throw new FileSystemException(msg);
-        }
-        try {
-            FileUtil.delete(f);
-        } catch (IOException ioe) {
-            String msg = "failed to delete " + f.getPath();
-            if (monitor != null && monitor.isOpen(f)) {
-                log.error("Unable to delete. There are still open streams.");
-                monitor.dump(f);
-            }
-
-            throw new FileSystemException(msg, ioe);
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void deleteFolder(String folderPath) throws FileSystemException {
-        File f = new File(root, osPath(folderPath));
-        if (!f.isDirectory()) {
-            String msg = f.getPath() + " does not denote an existing folder";
-            log.debug(msg);
-            throw new FileSystemException(msg);
-        }
-        try {
-            FileUtil.delete(f);
-        } catch (IOException ioe) {
-            String msg = "failed to delete " + f.getPath();
-            log.debug(msg);
-            throw new FileSystemException(msg, ioe);
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean exists(String path) throws FileSystemException {
-        File f = new File(root, osPath(path));
-        return f.exists();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public InputStream getInputStream(String filePath)
-            throws FileSystemException {
-        File f = new File(root, osPath(filePath));
-        try {
-            if (monitor == null) {
-                return new LazyFileInputStream(f);
-            } else {
-                return monitor.open(f);
-            }
-        } catch (FileNotFoundException fnfe) {
-            String msg = f.getPath() + " does not denote an existing file";
-            log.debug(msg);
-            throw new FileSystemException(msg, fnfe);
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public OutputStream getOutputStream(String filePath)
-            throws FileSystemException {
-        File f = new File(root, osPath(filePath));
-        try {
-            return new FileOutputStream(f);
-        } catch (FileNotFoundException fnfe) {
-            String msg = "failed to get output stream for " + f.getPath();
-            log.debug(msg);
-            throw new FileSystemException(msg, fnfe);
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean hasChildren(String path) throws FileSystemException {
-        File f = new File(root, osPath(path));
-        if (!f.exists()) {
-            String msg = f.getPath() + " does not exist";
-            log.debug(msg);
-            throw new FileSystemException(msg);
-        }
-        if (f.isFile()) {
-            return false;
-        }
-        return (f.list().length > 0);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isFile(String path) throws FileSystemException {
-        File f = new File(root, osPath(path));
-        return f.isFile();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isFolder(String path) throws FileSystemException {
-        File f = new File(root, osPath(path));
-        return f.isDirectory();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public long lastModified(String path) throws FileSystemException {
-        File f = new File(root, osPath(path));
-        return f.lastModified();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public long length(String filePath) throws FileSystemException {
-        File f = new File(root, osPath(filePath));
-        if (!f.exists()) {
-            return -1;
-        }
-        return f.length();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String[] list(String folderPath) throws FileSystemException {
-        File f = new File(root, osPath(folderPath));
-        String[] entries = f.list();
-        if (entries == null) {
-            String msg = folderPath + " does not denote a folder";
-            log.debug(msg);
-            throw new FileSystemException(msg);
-        }
-        return entries;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String[] listFiles(String folderPath) throws FileSystemException {
-        File folder = new File(root, osPath(folderPath));
-        File[] files = folder.listFiles(new FileFilter() {
-            public boolean accept(File f) {
-                return f.isFile();
-            }
-        });
-        if (files == null) {
-            String msg = folderPath + " does not denote a folder";
-            log.debug(msg);
-            throw new FileSystemException(msg);
-        }
-        String[] entries = new String[files.length];
-        for (int i = 0; i < files.length; i++) {
-            entries[i] = files[i].getName();
-        }
-        return entries;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String[] listFolders(String folderPath) throws FileSystemException {
-        File file = new File(root, osPath(folderPath));
-        File[] folders = file.listFiles(new FileFilter() {
-            public boolean accept(File f) {
-                return f.isDirectory();
-            }
-        });
-        if (folders == null) {
-            String msg = folderPath + " does not denote a folder";
-            log.debug(msg);
-            throw new FileSystemException(msg);
-        }
-        String[] entries = new String[folders.length];
-        for (int i = 0; i < folders.length; i++) {
-            entries[i] = folders[i].getName();
-        }
-        return entries;
-    }
-
-}
+/*
+ * 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.core.fs.local;
+
+import org.apache.jackrabbit.core.fs.FileSystem;
+import org.apache.jackrabbit.core.fs.FileSystemException;
+import org.apache.jackrabbit.core.fs.local.FileUtil;
+import org.apache.jackrabbit.core.fs.local.HandleMonitor;
+import org.apache.jackrabbit.util.LazyFileInputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * A <code>LocalFileSystem</code> ...
+ */
+public class LocalFileSystem implements FileSystem {
+
+    private static Logger log = LoggerFactory.getLogger(LocalFileSystem.class);
+
+    private File root;
+
+    private HandleMonitor monitor;
+
+    /**
+     * Default constructor
+     */
+    public LocalFileSystem() {
+    }
+
+    public String getPath() {
+        if (root != null) {
+            return root.getPath();
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Sets the path to the root directory of this local filesystem. please note
+     * that this method can be called via reflection during initialization and
+     * must not be altered.
+     *
+     * @param rootPath the path to the root directory
+     */
+    public void setPath(String rootPath) {
+        setRoot(new File(osPath(rootPath)));
+    }
+
+    public void setRoot(File root) {
+        this.root = root;
+    }
+
+    /**
+     * Enables/Disables the use of the handle monitor.
+     *
+     * @param enable
+     */
+    public void setEnableHandleMonitor(String enable) {
+        setEnableHandleMonitor(Boolean.valueOf(enable).booleanValue());
+    }
+
+    /**
+     * Enables/Disables the use of the handle monitor.
+     *
+     * @param enable flag
+     */
+    public void setEnableHandleMonitor(boolean enable) {
+        if (enable && monitor == null) {
+            monitor = new HandleMonitor();
+        }
+        if (!enable && monitor != null) {
+            monitor = null;
+        }
+    }
+
+    /**
+     * Returns <code>true</code> if use of the handle monitor is currently
+     * enabled, otherwise returns <code>false</code>.
+     *
+     * @see #setEnableHandleMonitor(boolean)
+     */
+    public String getEnableHandleMonitor() {
+        return monitor == null ? "false" : "true";
+    }
+
+    private String osPath(String genericPath) {
+        if (File.separator.equals(SEPARATOR)) {
+            return genericPath;
+        }
+        return genericPath.replace(SEPARATOR_CHAR, File.separatorChar);
+    }
+
+    //-------------------------------------------< java.lang.Object overrides >
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof LocalFileSystem) {
+            LocalFileSystem other = (LocalFileSystem) obj;
+            if (root == null) {
+                return other.root == null;
+            } else {
+                return root.equals(other.root);
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Returns zero to satisfy the Object equals/hashCode contract.
+     * This class is mutable and not meant to be used as a hash key.
+     *
+     * @return always zero
+     * @see Object#hashCode()
+     */
+    public int hashCode() {
+        return 0;
+    }
+
+    //-----------------------------------------------------------< FileSystem >
+    /**
+     * {@inheritDoc}
+     */
+    public void init() throws FileSystemException {
+        if (root == null) {
+            String msg = "root directory not set";
+            log.debug(msg);
+            throw new FileSystemException(msg);
+        }
+
+        if (root.exists()) {
+            if (!root.isDirectory()) {
+                String msg = "path does not denote a folder";
+                log.debug(msg);
+                throw new FileSystemException(msg);
+            }
+        } else {
+            if (!root.mkdirs()) {
+                String msg = "failed to create root";
+                log.debug(msg);
+                throw new FileSystemException(msg);
+            }
+        }
+        log.info("LocalFileSystem initialized at path " + root.getPath());
+        if (monitor != null) {
+            log.info("LocalFileSystem using handle monitor");
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void close() throws FileSystemException {
+        root = null;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void createFolder(String folderPath) throws FileSystemException {
+        File f = new File(root, osPath(folderPath));
+        if (f.exists()) {
+            String msg = f.getPath() + " already exists";
+            log.debug(msg);
+            throw new FileSystemException(msg);
+        }
+        if (!f.mkdirs()) {
+            String msg = "failed to create folder " + f.getPath();
+            log.debug(msg);
+            throw new FileSystemException(msg);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void deleteFile(String filePath) throws FileSystemException {
+        File f = new File(root, osPath(filePath));
+        if (!f.isFile()) {
+            String msg = f.getPath() + " does not denote an existing file";
+            throw new FileSystemException(msg);
+        }
+        try {
+            FileUtil.delete(f);
+        } catch (IOException ioe) {
+            String msg = "failed to delete " + f.getPath();
+            if (monitor != null && monitor.isOpen(f)) {
+                log.error("Unable to delete. There are still open streams.");
+                monitor.dump(f);
+            }
+
+            throw new FileSystemException(msg, ioe);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void deleteFolder(String folderPath) throws FileSystemException {
+        File f = new File(root, osPath(folderPath));
+        if (!f.isDirectory()) {
+            String msg = f.getPath() + " does not denote an existing folder";
+            log.debug(msg);
+            throw new FileSystemException(msg);
+        }
+        try {
+            FileUtil.delete(f);
+        } catch (IOException ioe) {
+            String msg = "failed to delete " + f.getPath();
+            log.debug(msg);
+            throw new FileSystemException(msg, ioe);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean exists(String path) throws FileSystemException {
+        File f = new File(root, osPath(path));
+        return f.exists();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public InputStream getInputStream(String filePath)
+            throws FileSystemException {
+        File f = new File(root, osPath(filePath));
+        try {
+            if (monitor == null) {
+                return new LazyFileInputStream(f);
+            } else {
+                return monitor.open(f);
+            }
+        } catch (FileNotFoundException fnfe) {
+            String msg = f.getPath() + " does not denote an existing file";
+            log.debug(msg);
+            throw new FileSystemException(msg, fnfe);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public OutputStream getOutputStream(String filePath)
+            throws FileSystemException {
+        File f = new File(root, osPath(filePath));
+        try {
+            return new FileOutputStream(f);
+        } catch (FileNotFoundException fnfe) {
+            String msg = "failed to get output stream for " + f.getPath();
+            log.debug(msg);
+            throw new FileSystemException(msg, fnfe);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasChildren(String path) throws FileSystemException {
+        File f = new File(root, osPath(path));
+        if (!f.exists()) {
+            String msg = f.getPath() + " does not exist";
+            log.debug(msg);
+            throw new FileSystemException(msg);
+        }
+        if (f.isFile()) {
+            return false;
+        }
+        return (f.list().length > 0);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isFile(String path) throws FileSystemException {
+        File f = new File(root, osPath(path));
+        return f.isFile();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isFolder(String path) throws FileSystemException {
+        File f = new File(root, osPath(path));
+        return f.isDirectory();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public long lastModified(String path) throws FileSystemException {
+        File f = new File(root, osPath(path));
+        return f.lastModified();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public long length(String filePath) throws FileSystemException {
+        File f = new File(root, osPath(filePath));
+        if (!f.exists()) {
+            return -1;
+        }
+        return f.length();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String[] list(String folderPath) throws FileSystemException {
+        File f = new File(root, osPath(folderPath));
+        String[] entries = f.list();
+        if (entries == null) {
+            String msg = folderPath + " does not denote a folder";
+            log.debug(msg);
+            throw new FileSystemException(msg);
+        }
+        return entries;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String[] listFiles(String folderPath) throws FileSystemException {
+        File folder = new File(root, osPath(folderPath));
+        File[] files = folder.listFiles(new FileFilter() {
+            public boolean accept(File f) {
+                return f.isFile();
+            }
+        });
+        if (files == null) {
+            String msg = folderPath + " does not denote a folder";
+            log.debug(msg);
+            throw new FileSystemException(msg);
+        }
+        String[] entries = new String[files.length];
+        for (int i = 0; i < files.length; i++) {
+            entries[i] = files[i].getName();
+        }
+        return entries;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String[] listFolders(String folderPath) throws FileSystemException {
+        File file = new File(root, osPath(folderPath));
+        File[] folders = file.listFiles(new FileFilter() {
+            public boolean accept(File f) {
+                return f.isDirectory();
+            }
+        });
+        if (folders == null) {
+            String msg = folderPath + " does not denote a folder";
+            log.debug(msg);
+            throw new FileSystemException(msg);
+        }
+        String[] entries = new String[folders.length];
+        for (int i = 0; i < folders.length; i++) {
+            entries[i] = folders[i].getName();
+        }
+        return entries;
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/fs/local/LocalFileSystem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/util/db/CheckSchemaOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/util/db/CheckSchemaOperation.java?rev=1576690&r1=1576689&r2=1576690&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/util/db/CheckSchemaOperation.java (original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/util/db/CheckSchemaOperation.java Wed Mar 12 11:05:06 2014
@@ -1,113 +1,113 @@
-/*
- * 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.core.util.db;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.jackrabbit.util.Text;
-
-/**
- * An operation which synchronously checks the DB schema in the {@link #run()} method. The
- * {@link #addVariableReplacement(String, String)} method return the instance to enable method chaining.
- */
-public class CheckSchemaOperation {
-
-    public static final String SCHEMA_OBJECT_PREFIX_VARIABLE = "${schemaObjectPrefix}";
-
-    public static final String TABLE_SPACE_VARIABLE = "${tableSpace}";
-
-    private final ConnectionHelper conHelper;
-
-    private final InputStream ddl;
-
-    private final String table;
-
-    private final Map<String, String> varReplacement = new HashMap<String, String>();
-
-    /**
-     * @param connectionhelper the connection helper
-     * @param ddlStream the stream of the DDL to use to create the schema if necessary (closed by the
-     *            {@link #run()} method)
-     * @param tableName the name of the table to use for the schema-existence-check
-     */
-    public CheckSchemaOperation(ConnectionHelper connectionhelper, InputStream ddlStream, String tableName) {
-        conHelper = connectionhelper;
-        ddl = ddlStream;
-        table = tableName;
-    }
-
-    /**
-     * Adds a variable replacement mapping.
-     * 
-     * @param var the variable
-     * @param replacement the replacement value
-     * @return this
-     */
-    public CheckSchemaOperation addVariableReplacement(String var, String replacement) {
-        varReplacement.put(var, replacement);
-        return this;
-    }
-
-    /**
-     * Checks if the required schema objects exist and creates them if they don't exist yet.
-     * 
-     * @throws SQLException if an error occurs
-     * @throws IOException if an error occurs
-     */
-    public void run() throws SQLException, IOException {
-        try {
-            if (!conHelper.tableExists(table)) {
-                BufferedReader reader = new BufferedReader(new InputStreamReader(ddl));
-                String sql = reader.readLine();
-                while (sql != null) {
-                    // Skip comments and empty lines
-                    if (!sql.startsWith("#") && sql.length() > 0) {
-                        // replace prefix variable
-                        sql = replace(sql);
-                        // execute sql stmt
-                        conHelper.exec(sql);
-                    }
-                    // read next sql stmt
-                    sql = reader.readLine();
-                }
-            }
-        } finally {
-            IOUtils.closeQuietly(ddl);
-        }
-    }
-
-    /**
-     * Applies the variable replacement to the given string.
-     * 
-     * @param sql the string in which to replace variables
-     * @return the new string
-     */
-    private String replace(String sql) {
-        String result = sql;
-        for (Map.Entry<String, String> entry : varReplacement.entrySet()) {
-            result = Text.replace(result, entry.getKey(), entry.getValue()).trim();
-        }
-        return result;
-    }
-}
+/*
+ * 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.core.util.db;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.util.Text;
+
+/**
+ * An operation which synchronously checks the DB schema in the {@link #run()} method. The
+ * {@link #addVariableReplacement(String, String)} method return the instance to enable method chaining.
+ */
+public class CheckSchemaOperation {
+
+    public static final String SCHEMA_OBJECT_PREFIX_VARIABLE = "${schemaObjectPrefix}";
+
+    public static final String TABLE_SPACE_VARIABLE = "${tableSpace}";
+
+    private final ConnectionHelper conHelper;
+
+    private final InputStream ddl;
+
+    private final String table;
+
+    private final Map<String, String> varReplacement = new HashMap<String, String>();
+
+    /**
+     * @param connectionhelper the connection helper
+     * @param ddlStream the stream of the DDL to use to create the schema if necessary (closed by the
+     *            {@link #run()} method)
+     * @param tableName the name of the table to use for the schema-existence-check
+     */
+    public CheckSchemaOperation(ConnectionHelper connectionhelper, InputStream ddlStream, String tableName) {
+        conHelper = connectionhelper;
+        ddl = ddlStream;
+        table = tableName;
+    }
+
+    /**
+     * Adds a variable replacement mapping.
+     * 
+     * @param var the variable
+     * @param replacement the replacement value
+     * @return this
+     */
+    public CheckSchemaOperation addVariableReplacement(String var, String replacement) {
+        varReplacement.put(var, replacement);
+        return this;
+    }
+
+    /**
+     * Checks if the required schema objects exist and creates them if they don't exist yet.
+     * 
+     * @throws SQLException if an error occurs
+     * @throws IOException if an error occurs
+     */
+    public void run() throws SQLException, IOException {
+        try {
+            if (!conHelper.tableExists(table)) {
+                BufferedReader reader = new BufferedReader(new InputStreamReader(ddl));
+                String sql = reader.readLine();
+                while (sql != null) {
+                    // Skip comments and empty lines
+                    if (!sql.startsWith("#") && sql.length() > 0) {
+                        // replace prefix variable
+                        sql = replace(sql);
+                        // execute sql stmt
+                        conHelper.exec(sql);
+                    }
+                    // read next sql stmt
+                    sql = reader.readLine();
+                }
+            }
+        } finally {
+            IOUtils.closeQuietly(ddl);
+        }
+    }
+
+    /**
+     * Applies the variable replacement to the given string.
+     * 
+     * @param sql the string in which to replace variables
+     * @return the new string
+     */
+    private String replace(String sql) {
+        String result = sql;
+        for (Map.Entry<String, String> entry : varReplacement.entrySet()) {
+            result = Text.replace(result, entry.getKey(), entry.getValue()).trim();
+        }
+        return result;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/util/db/CheckSchemaOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionFactory.java?rev=1576690&r1=1576689&r2=1576690&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionFactory.java (original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionFactory.java Wed Mar 12 11:05:06 2014
@@ -1,377 +1,377 @@
-/*
- * 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.core.util.db;
-
-import java.sql.Connection;
-import java.sql.Driver;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.jcr.RepositoryException;
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.sql.DataSource;
-
-import org.apache.commons.dbcp.BasicDataSource;
-import org.apache.commons.dbcp.DelegatingConnection;
-import org.apache.commons.pool.impl.GenericObjectPool;
-import org.apache.jackrabbit.core.config.DataSourceConfig;
-import org.apache.jackrabbit.core.config.DataSourceConfig.DataSourceDefinition;
-import org.apache.jackrabbit.core.util.db.DataSourceWrapper;
-import org.apache.jackrabbit.util.Base64;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A factory for new database connections.
- * Supported are regular JDBC drivers, as well as
- * JNDI resources.
- *
- * FIXME: the registry currently is ClassLoader wide. I.e., if you start two repositories
- * then you share the registered datasources...
- */
-public final class ConnectionFactory {
-
-    private static final Logger log = LoggerFactory.getLogger(ConnectionFactory.class);
-
-    /**
-     * The lock to protect the fields of this class.
-     */
-    private final Object lock = new Object();
-
-    /**
-     * The data sources without logical name. The keys in the map are based on driver-url-user combination.
-     */
-    private final Map<String, DataSource> keyToDataSource = new HashMap<String, DataSource>();
-
-    /**
-     * The configured data sources with logical name. The keys in the map are the logical name.
-     */
-    private final Map<String, DataSource> nameToDataSource = new HashMap<String, DataSource>();
-
-    /**
-     * The configured data source defs. The keys in the map are the logical name.
-     */
-    private final Map<String, DataSourceDefinition> nameToDataSourceDef = new HashMap<String, DataSourceDefinition>();
-
-    /**
-     * The list of data sources created by this factory.
-     */
-    private final List<BasicDataSource> created = new ArrayList<BasicDataSource>();
-
-    private boolean closed = false;
-
-    /**
-     * Registers a number of data sources.
-     *
-     * @param dsc the {@link DataSourceConfig} which contains the configuration
-     */
-    public void registerDataSources(DataSourceConfig dsc) throws RepositoryException {
-        synchronized (lock) {
-            sanityCheck();
-            for (DataSourceDefinition def : dsc.getDefinitions()) {
-                Class<?> driverClass = getDriverClass(def.getDriver());
-                if (driverClass != null
-                        && Context.class.isAssignableFrom(driverClass)) {
-                    DataSource ds = getJndiDataSource((Class<Context>) driverClass, def.getUrl());
-                    nameToDataSource.put(def.getLogicalName(), ds);
-                    nameToDataSourceDef.put(def.getLogicalName(), def);
-                } else {
-                    BasicDataSource bds =
-                        getDriverDataSource(driverClass, def.getUrl(), def.getUser(), def.getPassword());
-                    if (def.getMaxPoolSize() > 0) {
-                        bds.setMaxActive(def.getMaxPoolSize());
-                    }
-                    if (def.getValidationQuery() != null && !"".equals(def.getValidationQuery().trim())) {
-                        bds.setValidationQuery(def.getValidationQuery());
-                    }
-                    nameToDataSource.put(def.getLogicalName(), bds);
-                    nameToDataSourceDef.put(def.getLogicalName(), def);
-                }
-            }
-        }
-    }
-
-    /**
-     * Retrieves a configured data source by logical name.
-     *
-     * @param logicalName the name of the {@code DataSource}
-     * @return a {@code DataSource}
-     * @throws RepositoryException if there is no {@code DataSource} with the given name
-     */
-    public DataSource getDataSource(String logicalName) throws RepositoryException {
-        synchronized (lock) {
-            sanityCheck();
-            DataSource ds = nameToDataSource.get(logicalName);
-            if (ds == null) {
-                throw new RepositoryException("DataSource with logicalName " + logicalName
-                        + " has not been configured");
-            }
-            return ds;
-        }
-    }
-
-    /**
-     * @param logicalName the name of the {@code DataSource}
-     * @return the configured database type
-     * @throws RepositoryException if there is no {@code DataSource} with the given name
-     */
-    public String getDataBaseType(String logicalName) throws RepositoryException {
-        synchronized (lock) {
-            sanityCheck();
-            DataSourceDefinition def = nameToDataSourceDef.get(logicalName);
-            if (def == null) {
-                throw new RepositoryException("DataSource with logicalName " + logicalName
-                        + " has not been configured");
-            }
-            return def.getDbType();
-        }
-    }
-
-    /**
-     * Retrieve a {@code DataSource} for the specified properties.
-     * This can be a JNDI Data Source as well. To do that,
-     * the driver class name must reference a {@code javax.naming.Context} class
-     * (for example {@code javax.naming.InitialContext}), and the URL must be the JNDI URL
-     * (for example {@code java:comp/env/jdbc/Test}).
-     *
-     * @param driver the JDBC driver or the Context class
-     * @param url the database URL
-     * @param user the user name
-     * @param password the password
-     * @return the {@code DataSource}
-     * @throws RepositoryException if the driver could not be loaded
-     * @throws SQLException if the connection could not be established
-     */
-    public DataSource getDataSource(String driver, String url, String user, String password)
-            throws RepositoryException, SQLException    {
-        final String key = driver + url + user;
-        synchronized(lock) {
-            sanityCheck();
-            DataSource ds = keyToDataSource.get(key);
-            if (ds == null) {
-                ds = createDataSource(
-                        driver, url, user, Base64.decodeIfEncoded(password));
-                keyToDataSource.put(key, ds);
-            }
-            return ds;
-        }
-    }
-
-    /**
-     *
-     */
-    public void close() {
-        synchronized(lock) {
-            sanityCheck();
-            for (BasicDataSource ds : created) {
-                try {
-                    ds.close();
-                } catch (SQLException e) {
-                    log.error("failed to close " + ds, e);
-                }
-            }
-            keyToDataSource.clear();
-            nameToDataSource.clear();
-            nameToDataSourceDef.clear();
-            created.clear();
-            closed = true;
-        }
-    }
-
-    /**
-     * Needed for pre-10R2 Oracle blob support....:(
-     *
-     * This method actually assumes that we are using commons DBCP 1.2.2.
-     *
-     * @param con the commons-DBCP {@code DelegatingConnection} to unwrap
-     * @return the unwrapped connection
-     */
-    public static Connection unwrap(Connection con) throws SQLException {
-        if (con instanceof DelegatingConnection) {
-            return ((DelegatingConnection)con).getInnermostDelegate();
-        } else {
-            throw new SQLException("failed to unwrap connection of class " + con.getClass().getName() +
-                ", expected it to be a " + DelegatingConnection.class.getName());
-        }
-    }
-
-    private void sanityCheck() {
-        if (closed) {
-            throw new IllegalStateException("this factory has already been closed");
-        }
-    }
-
-    /**
-     * Create a new pooling data source or finds an existing JNDI data source (depends on driver).
-     *
-     * @param driver
-     * @param url
-     * @param user
-     * @param password
-     * @return
-     * @throws RepositoryException
-     */
-    private DataSource createDataSource(String driver, String url, String user, String password)
-            throws RepositoryException {
-        Class<?> driverClass = getDriverClass(driver);
-        if (driverClass != null
-                && Context.class.isAssignableFrom(driverClass)) {
-            @SuppressWarnings("unchecked")
-            DataSource database = getJndiDataSource((Class<Context>) driverClass, url);
-            if (user == null && password == null) {
-                return database;
-            } else {
-                return new DataSourceWrapper(database, user, password);
-            }
-        } else {
-            return getDriverDataSource(driverClass, url, user, password);
-        }
-    }
-
-    /**
-     * Loads and returns the given JDBC driver (or JNDI context) class.
-     * Returns <code>null</code> if a class name is not given.
-     *
-     * @param driver driver class name
-     * @return driver class, or <code>null</code>
-     * @throws RepositoryException if the class can not be loaded
-     */
-    private Class<?> getDriverClass(String driver)
-            throws RepositoryException {
-        try {
-            if (driver != null && driver.length() > 0) {
-                return Class.forName(driver);
-            } else {
-                return null;
-            }
-        } catch (ClassNotFoundException e) {
-            throw new RepositoryException(
-                    "Could not load JDBC driver class " + driver, e);
-        }
-    }
-
-    /**
-     * Returns the JDBC {@link DataSource} bound to the given name in
-     * the JNDI {@link Context} identified by the given class.
-     *
-     * @param contextClass class that is instantiated to get the JNDI context
-     * @param name name of the DataSource within the JNDI context
-     * @return the DataSource bound in JNDI
-     * @throws RepositoryException if the JNDI context can not be accessed,
-     *                             or if the named DataSource is not found
-     */
-    private DataSource getJndiDataSource(
-            Class<Context> contextClass, String name)
-            throws RepositoryException {
-        try {
-            Object object = contextClass.newInstance().lookup(name);
-            if (object instanceof DataSource) {
-                return (DataSource) object;
-            } else {
-                throw new RepositoryException(
-                        "Object " + object + " with JNDI name "
-                        + name + " is not a JDBC DataSource");
-            }
-        } catch (InstantiationException e) {
-            throw new RepositoryException(
-                    "Invalid JNDI context: " + contextClass.getName(), e);
-        } catch (IllegalAccessException e) {
-            throw new RepositoryException(
-                    "Invalid JNDI context: " + contextClass.getName(), e);
-        } catch (NamingException e) {
-            throw new RepositoryException(
-                    "JNDI name not found: " + name, e);
-        }
-    }
-
-    /**
-     * Creates and returns a pooling JDBC {@link DataSource} for accessing
-     * the database identified by the given driver class and JDBC
-     * connection URL. The driver class can be <code>null</code> if
-     * a specific driver has not been configured.
-     *
-     * @param driverClass the JDBC driver class, or <code>null</code>
-     * @param url the JDBC connection URL
-     * @return pooling DataSource for accessing the specified database
-     */
-    private BasicDataSource getDriverDataSource(
-            Class<?> driverClass, String url, String user, String password) {
-        BasicDataSource ds = new BasicDataSource();
-        created.add(ds);
-
-        if (driverClass != null) {
-        	Driver instance = null;
-            try {
-                // Workaround for Apache Derby:
-                // The JDBC specification recommends the Class.forName
-                // method without the .newInstance() method call,
-                // but it is required after a Derby 'shutdown'
-                instance = (Driver) driverClass.newInstance();
-            } catch (Throwable e) {
-                // Ignore exceptions as there's no requirement for
-                // a JDBC driver class to have a public default constructor
-            }
-            if (instance != null) {
-                if (instance.jdbcCompliant()) {
-                	// JCR-3445 At the moment the PostgreSQL isn't compliant because it doesn't implement this method...                	
-                    ds.setValidationQueryTimeout(3);
-                }
-            }
-            ds.setDriverClassName(driverClass.getName());
-        }
-
-        ds.setUrl(url);
-        ds.setUsername(user);
-        ds.setPassword(password);
-        ds.setDefaultAutoCommit(true);
-        ds.setTestOnBorrow(false);
-        ds.setTestWhileIdle(true);
-        ds.setTimeBetweenEvictionRunsMillis(600000); // 10 Minutes
-        ds.setMinEvictableIdleTimeMillis(60000); // 1 Minute
-        ds.setMaxActive(-1); // unlimited
-        ds.setMaxIdle(GenericObjectPool.DEFAULT_MAX_IDLE + 10);
-        ds.setValidationQuery(guessValidationQuery(url));
-        ds.setAccessToUnderlyingConnectionAllowed(true);
-        ds.setPoolPreparedStatements(true);
-        ds.setMaxOpenPreparedStatements(-1); // unlimited
-        return ds;
-    }
-
-    private String guessValidationQuery(String url) {
-        if (url.contains("derby")) {
-            return "values(1)";
-        } else if (url.contains("mysql")) {
-            return "select 1";
-        } else if (url.contains("sqlserver") || url.contains("jtds")) {
-            return "select 1";
-        } else if (url.contains("oracle")) {
-            return "select 'validationQuery' from dual";
-        } else if (url.contains("postgresql")) {
-            return "select 1";
-        } else if (url.contains("h2")) {
-            return "select 1";
-        } else if (url.contains("db2")) {
-            return "values(1)";
-        }
-        log.warn("Failed to guess validation query for URL " + url);
-        return null;
-    }
-}
+/*
+ * 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.core.util.db;
+
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.commons.dbcp.DelegatingConnection;
+import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.jackrabbit.core.config.DataSourceConfig;
+import org.apache.jackrabbit.core.config.DataSourceConfig.DataSourceDefinition;
+import org.apache.jackrabbit.core.util.db.DataSourceWrapper;
+import org.apache.jackrabbit.util.Base64;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A factory for new database connections.
+ * Supported are regular JDBC drivers, as well as
+ * JNDI resources.
+ *
+ * FIXME: the registry currently is ClassLoader wide. I.e., if you start two repositories
+ * then you share the registered datasources...
+ */
+public final class ConnectionFactory {
+
+    private static final Logger log = LoggerFactory.getLogger(ConnectionFactory.class);
+
+    /**
+     * The lock to protect the fields of this class.
+     */
+    private final Object lock = new Object();
+
+    /**
+     * The data sources without logical name. The keys in the map are based on driver-url-user combination.
+     */
+    private final Map<String, DataSource> keyToDataSource = new HashMap<String, DataSource>();
+
+    /**
+     * The configured data sources with logical name. The keys in the map are the logical name.
+     */
+    private final Map<String, DataSource> nameToDataSource = new HashMap<String, DataSource>();
+
+    /**
+     * The configured data source defs. The keys in the map are the logical name.
+     */
+    private final Map<String, DataSourceDefinition> nameToDataSourceDef = new HashMap<String, DataSourceDefinition>();
+
+    /**
+     * The list of data sources created by this factory.
+     */
+    private final List<BasicDataSource> created = new ArrayList<BasicDataSource>();
+
+    private boolean closed = false;
+
+    /**
+     * Registers a number of data sources.
+     *
+     * @param dsc the {@link DataSourceConfig} which contains the configuration
+     */
+    public void registerDataSources(DataSourceConfig dsc) throws RepositoryException {
+        synchronized (lock) {
+            sanityCheck();
+            for (DataSourceDefinition def : dsc.getDefinitions()) {
+                Class<?> driverClass = getDriverClass(def.getDriver());
+                if (driverClass != null
+                        && Context.class.isAssignableFrom(driverClass)) {
+                    DataSource ds = getJndiDataSource((Class<Context>) driverClass, def.getUrl());
+                    nameToDataSource.put(def.getLogicalName(), ds);
+                    nameToDataSourceDef.put(def.getLogicalName(), def);
+                } else {
+                    BasicDataSource bds =
+                        getDriverDataSource(driverClass, def.getUrl(), def.getUser(), def.getPassword());
+                    if (def.getMaxPoolSize() > 0) {
+                        bds.setMaxActive(def.getMaxPoolSize());
+                    }
+                    if (def.getValidationQuery() != null && !"".equals(def.getValidationQuery().trim())) {
+                        bds.setValidationQuery(def.getValidationQuery());
+                    }
+                    nameToDataSource.put(def.getLogicalName(), bds);
+                    nameToDataSourceDef.put(def.getLogicalName(), def);
+                }
+            }
+        }
+    }
+
+    /**
+     * Retrieves a configured data source by logical name.
+     *
+     * @param logicalName the name of the {@code DataSource}
+     * @return a {@code DataSource}
+     * @throws RepositoryException if there is no {@code DataSource} with the given name
+     */
+    public DataSource getDataSource(String logicalName) throws RepositoryException {
+        synchronized (lock) {
+            sanityCheck();
+            DataSource ds = nameToDataSource.get(logicalName);
+            if (ds == null) {
+                throw new RepositoryException("DataSource with logicalName " + logicalName
+                        + " has not been configured");
+            }
+            return ds;
+        }
+    }
+
+    /**
+     * @param logicalName the name of the {@code DataSource}
+     * @return the configured database type
+     * @throws RepositoryException if there is no {@code DataSource} with the given name
+     */
+    public String getDataBaseType(String logicalName) throws RepositoryException {
+        synchronized (lock) {
+            sanityCheck();
+            DataSourceDefinition def = nameToDataSourceDef.get(logicalName);
+            if (def == null) {
+                throw new RepositoryException("DataSource with logicalName " + logicalName
+                        + " has not been configured");
+            }
+            return def.getDbType();
+        }
+    }
+
+    /**
+     * Retrieve a {@code DataSource} for the specified properties.
+     * This can be a JNDI Data Source as well. To do that,
+     * the driver class name must reference a {@code javax.naming.Context} class
+     * (for example {@code javax.naming.InitialContext}), and the URL must be the JNDI URL
+     * (for example {@code java:comp/env/jdbc/Test}).
+     *
+     * @param driver the JDBC driver or the Context class
+     * @param url the database URL
+     * @param user the user name
+     * @param password the password
+     * @return the {@code DataSource}
+     * @throws RepositoryException if the driver could not be loaded
+     * @throws SQLException if the connection could not be established
+     */
+    public DataSource getDataSource(String driver, String url, String user, String password)
+            throws RepositoryException, SQLException    {
+        final String key = driver + url + user;
+        synchronized(lock) {
+            sanityCheck();
+            DataSource ds = keyToDataSource.get(key);
+            if (ds == null) {
+                ds = createDataSource(
+                        driver, url, user, Base64.decodeIfEncoded(password));
+                keyToDataSource.put(key, ds);
+            }
+            return ds;
+        }
+    }
+
+    /**
+     *
+     */
+    public void close() {
+        synchronized(lock) {
+            sanityCheck();
+            for (BasicDataSource ds : created) {
+                try {
+                    ds.close();
+                } catch (SQLException e) {
+                    log.error("failed to close " + ds, e);
+                }
+            }
+            keyToDataSource.clear();
+            nameToDataSource.clear();
+            nameToDataSourceDef.clear();
+            created.clear();
+            closed = true;
+        }
+    }
+
+    /**
+     * Needed for pre-10R2 Oracle blob support....:(
+     *
+     * This method actually assumes that we are using commons DBCP 1.2.2.
+     *
+     * @param con the commons-DBCP {@code DelegatingConnection} to unwrap
+     * @return the unwrapped connection
+     */
+    public static Connection unwrap(Connection con) throws SQLException {
+        if (con instanceof DelegatingConnection) {
+            return ((DelegatingConnection)con).getInnermostDelegate();
+        } else {
+            throw new SQLException("failed to unwrap connection of class " + con.getClass().getName() +
+                ", expected it to be a " + DelegatingConnection.class.getName());
+        }
+    }
+
+    private void sanityCheck() {
+        if (closed) {
+            throw new IllegalStateException("this factory has already been closed");
+        }
+    }
+
+    /**
+     * Create a new pooling data source or finds an existing JNDI data source (depends on driver).
+     *
+     * @param driver
+     * @param url
+     * @param user
+     * @param password
+     * @return
+     * @throws RepositoryException
+     */
+    private DataSource createDataSource(String driver, String url, String user, String password)
+            throws RepositoryException {
+        Class<?> driverClass = getDriverClass(driver);
+        if (driverClass != null
+                && Context.class.isAssignableFrom(driverClass)) {
+            @SuppressWarnings("unchecked")
+            DataSource database = getJndiDataSource((Class<Context>) driverClass, url);
+            if (user == null && password == null) {
+                return database;
+            } else {
+                return new DataSourceWrapper(database, user, password);
+            }
+        } else {
+            return getDriverDataSource(driverClass, url, user, password);
+        }
+    }
+
+    /**
+     * Loads and returns the given JDBC driver (or JNDI context) class.
+     * Returns <code>null</code> if a class name is not given.
+     *
+     * @param driver driver class name
+     * @return driver class, or <code>null</code>
+     * @throws RepositoryException if the class can not be loaded
+     */
+    private Class<?> getDriverClass(String driver)
+            throws RepositoryException {
+        try {
+            if (driver != null && driver.length() > 0) {
+                return Class.forName(driver);
+            } else {
+                return null;
+            }
+        } catch (ClassNotFoundException e) {
+            throw new RepositoryException(
+                    "Could not load JDBC driver class " + driver, e);
+        }
+    }
+
+    /**
+     * Returns the JDBC {@link DataSource} bound to the given name in
+     * the JNDI {@link Context} identified by the given class.
+     *
+     * @param contextClass class that is instantiated to get the JNDI context
+     * @param name name of the DataSource within the JNDI context
+     * @return the DataSource bound in JNDI
+     * @throws RepositoryException if the JNDI context can not be accessed,
+     *                             or if the named DataSource is not found
+     */
+    private DataSource getJndiDataSource(
+            Class<Context> contextClass, String name)
+            throws RepositoryException {
+        try {
+            Object object = contextClass.newInstance().lookup(name);
+            if (object instanceof DataSource) {
+                return (DataSource) object;
+            } else {
+                throw new RepositoryException(
+                        "Object " + object + " with JNDI name "
+                        + name + " is not a JDBC DataSource");
+            }
+        } catch (InstantiationException e) {
+            throw new RepositoryException(
+                    "Invalid JNDI context: " + contextClass.getName(), e);
+        } catch (IllegalAccessException e) {
+            throw new RepositoryException(
+                    "Invalid JNDI context: " + contextClass.getName(), e);
+        } catch (NamingException e) {
+            throw new RepositoryException(
+                    "JNDI name not found: " + name, e);
+        }
+    }
+
+    /**
+     * Creates and returns a pooling JDBC {@link DataSource} for accessing
+     * the database identified by the given driver class and JDBC
+     * connection URL. The driver class can be <code>null</code> if
+     * a specific driver has not been configured.
+     *
+     * @param driverClass the JDBC driver class, or <code>null</code>
+     * @param url the JDBC connection URL
+     * @return pooling DataSource for accessing the specified database
+     */
+    private BasicDataSource getDriverDataSource(
+            Class<?> driverClass, String url, String user, String password) {
+        BasicDataSource ds = new BasicDataSource();
+        created.add(ds);
+
+        if (driverClass != null) {
+        	Driver instance = null;
+            try {
+                // Workaround for Apache Derby:
+                // The JDBC specification recommends the Class.forName
+                // method without the .newInstance() method call,
+                // but it is required after a Derby 'shutdown'
+                instance = (Driver) driverClass.newInstance();
+            } catch (Throwable e) {
+                // Ignore exceptions as there's no requirement for
+                // a JDBC driver class to have a public default constructor
+            }
+            if (instance != null) {
+                if (instance.jdbcCompliant()) {
+                	// JCR-3445 At the moment the PostgreSQL isn't compliant because it doesn't implement this method...                	
+                    ds.setValidationQueryTimeout(3);
+                }
+            }
+            ds.setDriverClassName(driverClass.getName());
+        }
+
+        ds.setUrl(url);
+        ds.setUsername(user);
+        ds.setPassword(password);
+        ds.setDefaultAutoCommit(true);
+        ds.setTestOnBorrow(false);
+        ds.setTestWhileIdle(true);
+        ds.setTimeBetweenEvictionRunsMillis(600000); // 10 Minutes
+        ds.setMinEvictableIdleTimeMillis(60000); // 1 Minute
+        ds.setMaxActive(-1); // unlimited
+        ds.setMaxIdle(GenericObjectPool.DEFAULT_MAX_IDLE + 10);
+        ds.setValidationQuery(guessValidationQuery(url));
+        ds.setAccessToUnderlyingConnectionAllowed(true);
+        ds.setPoolPreparedStatements(true);
+        ds.setMaxOpenPreparedStatements(-1); // unlimited
+        return ds;
+    }
+
+    private String guessValidationQuery(String url) {
+        if (url.contains("derby")) {
+            return "values(1)";
+        } else if (url.contains("mysql")) {
+            return "select 1";
+        } else if (url.contains("sqlserver") || url.contains("jtds")) {
+            return "select 1";
+        } else if (url.contains("oracle")) {
+            return "select 'validationQuery' from dual";
+        } else if (url.contains("postgresql")) {
+            return "select 1";
+        } else if (url.contains("h2")) {
+            return "select 1";
+        } else if (url.contains("db2")) {
+            return "values(1)";
+        }
+        log.warn("Failed to guess validation query for URL " + url);
+        return null;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message