jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r517150 [2/4] - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: persistence/bundle/ persistence/bundle/util/ state/
Date Mon, 12 Mar 2007 09:42:13 GMT
Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleFsPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleFsPersistenceManager.java?view=auto&rev=517150
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleFsPersistenceManager.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleFsPersistenceManager.java Mon Mar 12 02:42:12 2007
@@ -0,0 +1,680 @@
+/*
+ * 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.persistence.bundle;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.core.fs.FileSystem;
+import org.apache.jackrabbit.core.fs.BasedFileSystem;
+import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
+import org.apache.jackrabbit.core.persistence.PMContext;
+import org.apache.jackrabbit.core.persistence.bundle.util.NodePropBundle;
+import org.apache.jackrabbit.core.persistence.bundle.util.ErrorHandling;
+import org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding;
+import org.apache.jackrabbit.core.persistence.bundle.util.TrackingInputStream;
+import org.apache.jackrabbit.core.persistence.util.Serializer;
+import org.apache.jackrabbit.core.persistence.util.BLOBStore;
+import org.apache.jackrabbit.core.persistence.util.FileSystemBLOBStore;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NodeReferencesId;
+import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+import org.apache.jackrabbit.core.state.NodeReferences;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.sql.SQLException;
+
+/**
+ * This is a generic persistence manager that stores the {@link NodePropBundle}s
+ * in a filesystem.
+ * <p/>
+ * Configuration:<br>
+ * <ul>
+ * <li>&lt;param name="{@link #setBundleCacheSize(String) bundleCacheSize}" value="8"/>
+ * <li>&lt;param name="{@link #setBlobFSBlockSize(String) blobFSBlockSize}" value="0"/>
+ * <li>&lt;param name="{@link #setBlobFSInitialCacheSize(String) blobFSInitialCacheSize}" value="100"/>
+ * <li>&lt;param name="{@link #setBlobFSMaximumCacheSize(String) blobFSMaximumCacheSize}" value="4000"/>
+ * <li>&lt;param name="{@link #setItemFSBlockSize(String) blobFSBlockSize}" value="0"/>
+ * <li>&lt;param name="{@link #setItemFSInitialCacheSize(String) blobFSInitialCacheSize}" value="100"/>
+ * <li>&lt;param name="{@link #setItemFSMaximumCacheSize(String) blobFSMaximumCacheSize}" value="4000"/>
+ * <li>&lt;param name="{@link #setMinBlobSize(String) minBlobSize}" value="4096"/>
+ * <li>&lt;param name="{@link #setErrorHandling(String) errorHandling}" value=""/>
+ * </ul>
+ */
+public class BundleFsPersistenceManager extends AbstractBundlePersistenceManager {
+
+    /** the cvs/svn id */
+    static final String CVS_ID = "$URL$ $Rev$ $Date$";
+
+    /** the default logger */
+    private static Logger log = LoggerFactory.getLogger(BundleFsPersistenceManager.class);
+
+    /** flag indicating if this manager was initialized */
+    protected boolean initialized = false;
+
+    /** initial size of buffer used to serialize objects */
+    protected static final int INITIAL_BUFFER_SIZE = 1024;
+
+    /** file system where BLOB data is stored */
+    protected BundleFsPersistenceManager.CloseableBLOBStore blobStore;
+
+    /**
+     * Default blocksize for BLOB filesystem:
+     * @see #setBlobFSBlockSize(String)
+     */
+    private int blobFSBlockSize = 0;
+
+    /**
+     * Default initial cache size for BLOB filesystem: 100, req. 25KB
+     * @see #setBlobFSInitialCacheSize(String)
+     */
+    private int blobFSInitialCache = 100;
+
+    /**
+     * Default max cache size for BLOB filesystem: 4000, req. 1000KB
+     * @see #setBlobFSMaximumCacheSize(String)
+     */
+    private int blobFSMaximumCache = 4000;
+
+    /**
+     * Default blocksize for item filesystem:
+     * @see #setItemFSBlockSize(String)
+     */
+    private int itemFSBlockSize = 0;
+
+    /**
+     * Default initial cache size for item filesystem: 100, req. 25KB
+     * @see #setItemFSInitialCacheSize(String)
+     */
+    private int itemFSInitialCache = 100;
+
+    /**
+     * Default max cache size for item filesystem: 4000, req. 1000KB
+     * @see #setItemFSMaximumCacheSize(String)
+     */
+    private int itemFSMaximumCache = 4000;
+
+    /**
+     * the minimum size of a property until it gets written to the blob store
+     * @see #setMinBlobSize(String)
+     */
+    private int minBlobSize = 0x1000;
+
+    /**
+     * the filesystem where the items are stored
+     */
+    private FileSystem itemFs;
+
+    /**
+     * flag for error handling
+     */
+    protected ErrorHandling errorHandling = new ErrorHandling();
+
+    /**
+     * the bundle binding
+     */
+    protected BundleBinding binding;
+
+    /**
+     * the name of this persistence manager
+     */
+    private String name = super.toString();
+
+
+    /**
+     * Returns the configured block size of the blob cqfs
+     * @return the block size.
+     */
+    public String getBlobFSBlockSize() {
+        return String.valueOf(blobFSBlockSize);
+    }
+
+    /**
+     * Sets the block size of the blob fs and controlls how blobs are handled.
+     * <br>
+     * If the size is > 0, it must be a power of 2 and is used as blocksize
+     * for the cqfs. blobs are then stored within that cqfs. A call to
+     * {@link #useCqFsBlobStore()} will return <code>true</code>.
+     * <br>
+     * If the size is 0, the cqfs is not used at all, and the blobs are stored
+     * within the workspace's physical filesystem. A call to
+     * {@link #useLocalFsBlobStore()} will return <code>true</code>.
+     * <br>
+     * If the size is &lt; 0, the cqfs is not used at all, and the blobls are
+     * stored within the item filesystem. A call to
+     * {@link #useItemBlobStore()} will return <code>true</code>.
+     * <br>
+     * Please note that not all binary properties are considered as blobs. They
+     * are only stored in the respective blob store, if their size exceeds
+     * {@link #getMinBlobSize()}.
+     *
+     * @param size the block size
+     */
+    public void setBlobFSBlockSize(String size) {
+        this.blobFSBlockSize = Integer.decode(size).intValue();
+    }
+
+    /**
+     * Returns <code>true</code> if the blobs are stored in the DB.
+     * @return <code>true</code> if the blobs are stored in the DB.
+     */
+    public boolean useItemBlobStore() {
+        return blobFSBlockSize < 0;
+    }
+
+    /**
+     * Returns <code>true</code> if the blobs are stored in the local fs.
+     * @return <code>true</code> if the blobs are stored in the local fs.
+     */
+    public boolean useLocalFsBlobStore() {
+        return blobFSBlockSize == 0;
+    }
+
+    /**
+     * Returns <code>true</code> if the blobs are stored in the cqfs.
+     * @return <code>true</code> if the blobs are stored in the cqfs.
+     */
+    public boolean useCqFsBlobStore() {
+        return blobFSBlockSize > 0;
+    }
+
+    /**
+     * Returns the configured inital cache size of the blobfs.
+     * @return the configured inital cache size of the blobfs.
+     */
+    public String getBlobFSInitialCacheSize() {
+        return String.valueOf(blobFSInitialCache);
+    }
+
+    /**
+     * Sets the initial cache size of the blob fs. This only applies to cqfs
+     * base blobstores, i.e. if {@link #useCqFsBlobStore()} returns
+     * <code>true</code>.
+     * @param size the initial size
+     */
+    public void setBlobFSInitialCacheSize(String size) {
+        this.blobFSInitialCache = Integer.decode(size).intValue();
+    }
+
+    /**
+     * Returns the configured maximal size of the blobfs.
+     * @return the configured maximal size of the blobfs.
+     */
+    public String getBlobFSMaximumCacheSize() {
+        return String.valueOf(blobFSMaximumCache);
+    }
+
+    /**
+     * Sets the maximal cache size of the blob fs. This only applies to cqfs
+     * base blobstores, i.e. if {@link #useCqFsBlobStore()} returns
+     * <code>true</code>.
+     * @param size the maximal size
+     */
+    public void setBlobFSMaximumCacheSize(String size) {
+        this.blobFSMaximumCache = Integer.decode(size).intValue();
+    }
+
+
+    /**
+     * Returns the configured block size of the item cqfs
+     * @return the block size.
+     */
+    public String getItemFSBlockSize() {
+        return String.valueOf(itemFSBlockSize);
+    }
+
+    /**
+     * Sets the block size of the item fs.
+     * <br>
+     * If the size is > 0, it must be a power of 2 and is used as blocksize
+     * for the cqfs. items are then stored within that cqfs.
+     * <br>
+     * If the size is 0, the cqfs is not used at all, and the items are stored
+     * within the workspace's physical filesystem.
+     *
+     * @param size the block size
+     */
+    public void setItemFSBlockSize(String size) {
+        this.itemFSBlockSize = Integer.decode(size).intValue();
+    }
+
+    /**
+     * Returns the configured inital cache size of the itemfs.
+     * @return the configured inital cache size of the itemfs.
+     */
+    public String getItemFSInitialCacheSize() {
+        return String.valueOf(itemFSInitialCache);
+    }
+
+    /**
+     * Sets the initial cache size of the item fs. This only applies to cqfs
+     * based item stores.
+     *
+     * @param size the initial size
+     */
+    public void setItemFSInitialCacheSize(String size) {
+        this.itemFSInitialCache = Integer.decode(size).intValue();
+    }
+
+    /**
+     * Returns the configured maximal size of the itemfs.
+     * @return the configured maximal size of the itemfs.
+     */
+    public String getItemFSMaximumCacheSize() {
+        return String.valueOf(itemFSMaximumCache);
+    }
+
+    /**
+     * Sets the maximal cache size of the item fs. This only applies to cqfs
+     * base item storea.
+     * @param size the maximal size
+     */
+    public void setItemFSMaximumCacheSize(String size) {
+        this.itemFSMaximumCache = Integer.decode(size).intValue();
+    }
+
+    /**
+     * Returns the miminum blob size.
+     * @return the miminum blob size.
+     */
+    public int getMinBlobSize() {
+        return minBlobSize;
+    }
+
+    /**
+     * Sets the minumum blob size. This size defines the threshhold of which
+     * size a property is included in the bundle or is stored in the blob store.
+     *
+     * @param minBlobSize
+     */
+    public void setMinBlobSize(String minBlobSize) {
+        this.minBlobSize = Integer.decode(minBlobSize).intValue();
+    }
+
+    /**
+     * Sets the error handling behaviour of this manager. See {@link ErrorHandling}
+     * for details about the flags.
+     *
+     * @param errorHandling
+     */
+    public void setErrorHandling(String errorHandling) {
+        this.errorHandling = new ErrorHandling(errorHandling);
+    }
+
+    /**
+     * Returns the error handling configuration of this manager
+     * @return the error handling configuration of this manager
+     */
+    public String getErrorHandling() {
+        return errorHandling.toString();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void init(PMContext context) throws Exception {
+        if (initialized) {
+            throw new IllegalStateException("already initialized");
+        }
+        super.init(context);
+
+        this.name = context.getHomeDir().getName();
+
+        // create item fs
+        if (itemFSBlockSize == 0) {
+            itemFs = new BasedFileSystem(context.getFileSystem(), "items");
+        } else {
+            /*
+            CQFileSystem cqfs = new CQFileSystem();
+            cqfs.setPath(new File(context.getHomeDir(), "items.dat").getCanonicalPath());
+            cqfs.setAutoRepair(false);
+            cqfs.setAutoSync(false);
+            cqfs.setBlockSize(itemFSBlockSize);
+            cqfs.setCacheInitialBlocks(itemFSInitialCache);
+            cqfs.setCacheMaximumBlocks(itemFSMaximumCache);
+            cqfs.init();
+            itemFs = cqfs;
+            */
+        }
+
+        // create correct blob store
+        if (useLocalFsBlobStore()) {
+            LocalFileSystem blobFS = new LocalFileSystem();
+            blobFS.setRoot(new File(context.getHomeDir(), "blobs"));
+            blobFS.init();
+            blobStore = new BundleFsPersistenceManager.FSBlobStore(blobFS);
+        } else if (useItemBlobStore()) {
+            blobStore = new BundleFsPersistenceManager.FSBlobStore(itemFs);
+        } else /* useCqFsBlobStore() */ {
+//blobStore = createCQFSBlobStore(context);
+        }
+
+        // load namespaces
+        binding = new BundleBinding(errorHandling, blobStore, getNsIndex(), getNameIndex());
+        binding.setMinBlobSize(minBlobSize);
+
+        initialized = true;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public synchronized void close() throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
+        try {
+            // close blob store
+            blobStore.close();
+            blobStore = null;
+            itemFs.close();
+            itemFs = null;
+        } finally {
+            initialized = false;
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected synchronized NodePropBundle loadBundle(NodeId id)
+            throws ItemStateException {
+        DataInputStream din = null;
+        try {
+            String path = buildNodeFilePath(null, id).toString();
+            if (!itemFs.exists(path)) {
+                return null;
+            }
+            InputStream in = itemFs.getInputStream(path);
+            TrackingInputStream cin = new TrackingInputStream(in);
+            din = new DataInputStream(cin);
+            NodePropBundle bundle = binding.readBundle(din, id);
+            bundle.setSize(cin.getPosition());
+            return bundle;
+        } catch (Exception e) {
+            String msg = "failed to read bundle: " + id + ": " + e;
+            log.error(msg);
+            throw new ItemStateException(msg, e);
+        } finally {
+            closeStream(din);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected synchronized boolean existsBundle(NodeId id) throws ItemStateException {
+        try {
+            StringBuffer buf = buildNodeFilePath(null, id);
+            return itemFs.exists(buf.toString());
+        } catch (Exception e) {
+            String msg = "failed to check existence of bundle: " + id;
+            BundleFsPersistenceManager.log.error(msg, e);
+            throw new ItemStateException(msg, e);
+        }
+    }
+    
+    /**
+     * Creates the file path for the given node id that is
+     * suitable for storing node states in a filesystem.
+     *
+     * @param buf buffer to append to or <code>null</code>
+     * @param id the id of the node
+     * @return the buffer with the appended data.
+     */
+    protected StringBuffer buildNodeFilePath(StringBuffer buf, NodeId id) {
+        if (buf == null) {
+            buf = new StringBuffer();
+        }
+        buildNodeFolderPath(buf, id);
+        buf.append('.');
+        buf.append(NODEFILENAME);
+        return buf;
+    }    
+    
+    /**
+     * Creates the file path for the given references id that is
+     * suitable for storing reference states in a filesystem.
+     *
+     * @param buf buffer to append to or <code>null</code>
+     * @param id the id of the node
+     * @return the buffer with the appended data.
+     */
+    protected StringBuffer buildNodeReferencesFilePath(StringBuffer buf,
+                                                       NodeReferencesId id) {
+        if (buf == null) {
+            buf = new StringBuffer();
+        }
+        buildNodeFolderPath(buf, id.getTargetId());
+        buf.append('.');
+        buf.append(NODEREFSFILENAME);
+        return buf;
+    }    
+
+    /**
+     * {@inheritDoc}
+     */
+    protected synchronized void storeBundle(NodePropBundle bundle) throws ItemStateException {
+        try {
+            StringBuffer buf = buildNodeFolderPath(null, bundle.getId());
+            buf.append('.');
+            buf.append(NODEFILENAME);
+            String fileName = buf.toString();
+            String dir = fileName.substring(0, fileName.lastIndexOf(FileSystem.SEPARATOR_CHAR));
+            if (!itemFs.exists(dir)) {
+                itemFs.createFolder(dir);
+            }
+            OutputStream out = itemFs.getOutputStream(fileName);
+            DataOutputStream dout = new DataOutputStream(out);
+            binding.writeBundle(dout, bundle);
+            dout.close();
+        } catch (Exception e) {
+            String msg = "failed to write bundle: " + bundle.getId();
+            BundleFsPersistenceManager.log.error(msg, e);
+            throw new ItemStateException(msg, e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected synchronized void destroyBundle(NodePropBundle bundle) throws ItemStateException {
+        try {
+            StringBuffer buf = buildNodeFilePath(null, bundle.getId());
+            itemFs.deleteFile(buf.toString());
+        } catch (Exception e) {
+            if (e instanceof NoSuchItemStateException) {
+                throw (NoSuchItemStateException) e;
+            }
+            String msg = "failed to delete bundle: " + bundle.getId();
+            BundleFsPersistenceManager.log.error(msg, e);
+            throw new ItemStateException(msg, e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public synchronized NodeReferences load(NodeReferencesId targetId)
+            throws NoSuchItemStateException, ItemStateException {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+        InputStream in = null;
+        try {
+            String path = buildNodeReferencesFilePath(null, targetId).toString();
+            if (!itemFs.exists(path)) {
+                // special case
+                throw new NoSuchItemStateException(targetId.toString());
+            }
+            in = itemFs.getInputStream(path);
+            NodeReferences refs = new NodeReferences(targetId);
+            Serializer.deserialize(refs, in);
+            return refs;
+        } catch (NoSuchItemStateException e) {
+            throw e;
+        } catch (Exception e) {
+            String msg = "failed to read references: " + targetId;
+            BundleFsPersistenceManager.log.error(msg, e);
+            throw new ItemStateException(msg, e);
+        } finally {
+            closeStream(in);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public synchronized void store(NodeReferences refs)
+            throws ItemStateException {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+        try {
+            StringBuffer buf = buildNodeFolderPath(null, refs.getTargetId());
+            buf.append('.');
+            buf.append(NODEREFSFILENAME);
+            String fileName = buf.toString();
+            String dir = fileName.substring(0, fileName.lastIndexOf(FileSystem.SEPARATOR_CHAR));
+            if (!itemFs.exists(dir)) {
+                itemFs.createFolder(dir);
+            }
+            OutputStream out = itemFs.getOutputStream(fileName);
+            Serializer.serialize(refs, out);
+            out.close();
+        } catch (Exception e) {
+            String msg = "failed to write property state: " + refs.getTargetId();
+            BundleFsPersistenceManager.log.error(msg, e);
+            throw new ItemStateException(msg, e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public synchronized void destroy(NodeReferences refs) throws ItemStateException {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+        try {
+            StringBuffer buf = buildNodeReferencesFilePath(null, refs.getId());
+            itemFs.deleteFile(buf.toString());
+        } catch (Exception e) {
+            if (e instanceof NoSuchItemStateException) {
+                throw (NoSuchItemStateException) e;
+            }
+            String msg = "failed to delete references: " + refs.getTargetId();
+            BundleFsPersistenceManager.log.error(msg, e);
+            throw new ItemStateException(msg, e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public synchronized boolean exists(NodeReferencesId targetId) throws ItemStateException {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+        try {
+            StringBuffer buf = buildNodeReferencesFilePath(null, targetId);
+            return itemFs.exists(buf.toString());
+        } catch (Exception e) {
+            String msg = "failed to check existence of node references: " + targetId;
+            BundleFsPersistenceManager.log.error(msg, e);
+            throw new ItemStateException(msg, e);
+        }
+    }
+
+    /**
+     * closes the input stream
+     * @param ins
+     */
+    protected void closeStream(InputStream ins) {
+        if (ins != null) {
+            try {
+                ins.close();
+            } catch (IOException ignore) {
+                // ignore
+            }
+        }
+    }
+
+    /**
+     * logs an sql exception
+     * @param message
+     * @param se
+     */
+    protected void logException(String message, SQLException se) {
+        if (message != null) {
+            BundleFsPersistenceManager.log.error(message);
+        }
+        BundleFsPersistenceManager.log.error("       Reason: " + se.getMessage());
+        BundleFsPersistenceManager.log.error("   State/Code: " + se.getSQLState() + "/" +
+                se.getErrorCode());
+        BundleFsPersistenceManager.log.debug("   dump:", se);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public String toString() {
+        return name;
+    }
+
+    /**
+     * Helper interface for closeable stores
+     */
+    protected static interface CloseableBLOBStore extends BLOBStore {
+        void close();
+    }
+
+    /**
+     * own implementation of the filesystem blob store that uses a different
+     * blob-id scheme.
+     */
+    private class FSBlobStore extends FileSystemBLOBStore implements BundleFsPersistenceManager.CloseableBLOBStore {
+
+        private FileSystem fs;
+
+        public FSBlobStore(FileSystem fs) {
+            super(fs);
+            this.fs = fs;
+        }
+
+        public String createId(PropertyId id, int index) {
+            return buildBlobFilePath(null, id, index).toString();
+        }
+
+        public void close() {
+            try {
+                fs.close();
+                fs = null;
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+    }
+
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleFsPersistenceManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleFsPersistenceManager.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url rev

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/CachingPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/CachingPersistenceManager.java?view=auto&rev=517150
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/CachingPersistenceManager.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/CachingPersistenceManager.java Mon Mar 12 02:42:12 2007
@@ -0,0 +1,35 @@
+/*
+ * 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.persistence.bundle;
+
+import org.apache.jackrabbit.core.state.ChangeLog;
+
+/**
+ * Marker interface that is used by the shared item state manager for invalidate
+ * persistence manager caches as result of an external (cluster) modification.
+ */
+public interface CachingPersistenceManager {
+
+    /**
+     * Notifies the persistence manager that an external (cluster) modification
+     * occured.
+     *
+     * @param changes the set of changes of the external modification.
+     */
+    public void onExternalUpdate(ChangeLog changes);
+
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/CachingPersistenceManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/CachingPersistenceManager.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url rev

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java?view=auto&rev=517150
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java Mon Mar 12 02:42:12 2007
@@ -0,0 +1,350 @@
+/*
+ * 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.persistence.bundle;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.core.persistence.PMContext;
+import org.apache.jackrabbit.core.persistence.db.DatabasePersistenceManager;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Extends the {@link BundleDbPersistenceManager} by derby specific code.
+ * <p/>
+ * Configuration:<br>
+ * <ul>
+ * <li>&lt;param name="{@link #setBundleCacheSize(String) bundleCacheSize}" value="8"/>
+ * <li>&lt;param name="{@link #setBlobFSBlockSize(String) blobFSBlockSize}" value="0"/>
+ * <li>&lt;param name="{@link #setBlobFSInitialCacheSize(String) blobFSInitialCacheSize}" value="100"/>
+ * <li>&lt;param name="{@link #setBlobFSMaximumCacheSize(String) blobFSMaximumCacheSize}" value="4000"/>
+ * <li>&lt;param name="{@link #setBlobFSLogBufferCache(String) blobFSLogBufferCache}" value="false"/>
+ * <li>&lt;param name="{@link #setBlobFSLogIOCalls(String) blobFSLogIOCalls}" value="false"/>
+ * <li>&lt;param name="{@link #setBlobFSLogSYSCalls(String) blobFSLogSYSCalls}" value="false"/>
+ * <li>&lt;param name="{@link #setConsistencyCheck(String) consistencyCheck}" value="false"/>
+ * <li>&lt;param name="{@link #setMinBlobSize(String) minBlobSize}" value="16384"/>
+ * <li>&lt;param name="{@link #setDriver(String) driver}" value="org.apache.derby.jdbc.EmbeddedDriver"/>
+ * <li>&lt;param name="{@link #setUrl(String) url}" value="jdbc:derby:${wsp.home}/db/itemState;create=true"/>
+ * <li>&lt;param name="{@link #setUser(String) user}" value=""/>
+ * <li>&lt;param name="{@link #setPassword(String) password}" value=""/>
+ * <li>&lt;param name="{@link #setSchema(String) schema}" value="derby"/>
+ * <li>&lt;param name="{@link #setSchemaObjectPrefix(String) schemaObjectPrefix}" value=""/>
+ * <li>&lt;param name="{@link #setErrorHandling(String) errorHandling}" value=""/>
+ * <!-- derby related -->
+ * <li>&lt;param name="{@link #setDerbyStorageInitialPages(String) derbyStorageInitialPages}" value="16"/>
+ * <li>&lt;param name="{@link #setDerbyStorageMinimumRecordSize(String) derbyStorageMinimumRecordSize}" value="256"/>
+ * <li>&lt;param name="{@link #setDerbyStoragePageCacheSize(String) derbyStoragePageCacheSize}" value="1024"/>
+ * <li>&lt;param name="{@link #setDerbyStoragePageReservedSpace(String) derbyStoragePageReservedSpace}" value="20"/>
+ * <li>&lt;param name="{@link #setDerbyStoragePageSize(String) derbyStoragePageSize}" value="16384"/>
+ * </ul>
+ */
+public class DerbyPersistenceManager extends BundleDbPersistenceManager {
+
+    /** the cvs/svn id */
+    static final String CVS_ID = "$URL$ $Rev$ $Date$";
+
+    /** name of the embedded driver */
+    public static final String DERBY_EMBEDDED_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
+    
+    /** the default logger */
+    private static Logger log = LoggerFactory.getLogger(DerbyPersistenceManager.class);
+
+    /** @see #setDerbyStorageInitialPages(String) */
+    private int derbyStorageInitialPages = 16;
+
+    /** @see #setDerbyStorageMinimumRecordSize(String) */
+    private int derbyStorageMinimumRecordSize = 512;
+
+    /** @see #setDerbyStoragePageCacheSize(String) */
+    private int derbyStoragePageCacheSize = 1024;
+
+    /** @see #setDerbyStoragePageReservedSpace(String) */
+    private int derbyStoragePageReservedSpace = 20;
+
+    /** @see #setDerbyStoragePageSize(String) */
+    private int derbyStoragePageSize = 16384;
+
+    /**
+     * @see #setDerbyStorageInitialPages
+     * @return the initial pages property
+     */
+    public String getDerbyStorageInitialPages() {
+        return String.valueOf(derbyStorageInitialPages);
+    }
+
+    /**
+     * The on-disk size of a Derby table grows by one page at a time until eight
+     * pages of user data (or nine pages of total disk use, one is used for
+     * overhead) have been allocated. Then it will grow by eight pages at a time
+     * if possible.
+     * <p/>
+     * A Derby table or index can be created with a number of pages already
+     * pre-allocated. To do so, specify the property prior to the CREATE TABLE
+     * or CREATE INDEX statement.
+     * <p/>
+     * Define the number of user pages the table or index is to be created with.
+     * The purpose of this property is to preallocate a table or index of
+     * reasonable size if the user expects that a large amount of data will be
+     * inserted into the table or index. A table or index that has the
+     * pre-allocated pages will enjoy a small performance improvement over a
+     * table or index that has no pre-allocated pages when the data are loaded.
+     * <p/>
+     * The total desired size of the table or index should be
+     * <p/>
+     * <strong>(1+derby.storage.initialPages) * derby.storage.pageSize bytes.</strong>
+     * <p/>
+     * When you create a table or an index after setting this property, Derby
+     * attempts to preallocate the requested number of user pages. However, the
+     * operations do not fail even if they are unable to preallocate the
+     * requested number of pages, as long as they allocate at least one page.
+     * <p/>
+     * Default is <code>16</code>
+     * @param derbyStorageInitialPages
+     */
+    public void setDerbyStorageInitialPages(String derbyStorageInitialPages) {
+        this.derbyStorageInitialPages =
+                Integer.decode(derbyStorageInitialPages).intValue();
+    }
+
+    /**
+     * @see #setDerbyStorageMinimumRecordSize
+     * @return the minimum record size
+     */
+    public String getDerbyStorageMinimumRecordSize() {
+        return String.valueOf(derbyStorageMinimumRecordSize);
+    }
+
+    /**
+     * Indicates the minimum user row size in bytes for on-disk database pages
+     * for tables when you are creating a table. This property ensures that
+     * there is enough room for a row to grow on a page when updated without
+     * having to overflow. This is generally most useful for VARCHAR and
+     * VARCHAR FOR BIT DATA data types and for tables that are updated a lot,
+     * in which the rows start small and grow due to updates. Reserving the
+     * space at the time of insertion minimizes row overflow due to updates,
+     * but it can result in wasted space. Set the property prior to issuing the
+     * CREATE TABLE statement.
+     * <p/>
+     * Default is <code>256</code>
+     *
+     * @param derbyStorageMinimumRecordSize
+     */
+    public void setDerbyStorageMinimumRecordSize(String derbyStorageMinimumRecordSize) {
+        this.derbyStorageMinimumRecordSize =
+                Integer.decode(derbyStorageMinimumRecordSize).intValue();
+    }
+
+    /**
+     * @see #setDerbyStoragePageCacheSize
+     * @return the page cache size
+     */
+    public String getDerbyStoragePageCacheSize() {
+        return String.valueOf(derbyStoragePageCacheSize);
+    }
+
+    /**
+     * Defines the size, in number of pages, of the database's data page cache
+     * (data pages kept in memory). The actual amount of memory the page cache
+     * will use depends on the following:
+     * <ul>
+     * <li> the size of the cache (configured with {@link #setDerbyStoragePageCacheSize})
+     * <li> the size of the pages (configured with {@link #setDerbyStoragePageSize})
+     * <li> overhead (varies with JVMs)
+     * </ul>
+     * When increasing the size of the page cache, you typically have to allow
+     * more memory for the Java heap when starting the embedding application
+     * (taking into consideration, of course, the memory needs of the embedding
+     * application as well). For example, using the default page size of 4K, a
+     * page cache size of 2000 pages will require at least 8 MB of memory (and
+     * probably more, given the overhead).
+     * <p/>
+     * The minimum value is 40 pages. If you specify a lower value, Derby uses
+     * the default value.
+     * <p/>
+     * Default is <code>1024</code> (which gives about 16mb memory usage given
+     * the default of 16384 as page size).
+     *
+     * @param derbyStoragePageCacheSize
+     */
+    public void setDerbyStoragePageCacheSize(String derbyStoragePageCacheSize) {
+        this.derbyStoragePageCacheSize =
+                Integer.decode(derbyStoragePageCacheSize).intValue();
+    }
+
+
+    /**
+     * @see #setDerbyStoragePageReservedSpace
+     * @return the page reserved space
+     */
+    public String getDerbyStoragePageReservedSpace() {
+        return String.valueOf(derbyStoragePageReservedSpace);
+    }
+
+    /**
+     * Defines the percentage of space reserved for updates on an on-disk
+     * database page for tables only (not indexes); indicates the percentage of
+     * space to keep free on a page when inserting. Leaving reserved space on a
+     * page can minimize row overflow (and the associated performance hit)
+     * during updates. Once a page has been filled up to the reserved-space
+     * threshold, no new rows are allowed on the page. This reserved space is
+     * used only for rows that increase in size when updated, not for new
+     * inserts. Set this property prior to issuing the CREATE TABLE statement.
+     * <p/>
+     * Regardless of the value of derby.storage.pageReservedSpace, an empty page
+     * always accepts at least one row.
+     * <p/>
+     * Default is <code>20%</code>
+     *
+     * @param derbyStoragePageReservedSpace
+     */
+    public void setDerbyStoragePageReservedSpace(String derbyStoragePageReservedSpace) {
+        this.derbyStoragePageReservedSpace =
+                Integer.decode(derbyStoragePageReservedSpace).intValue();
+    }
+
+    /**
+     * @see #setDerbyStoragePageSize
+     * @return the page size
+     */
+    public String getDerbyStoragePageSize() {
+        return String.valueOf(derbyStoragePageSize);
+    }
+
+    /**
+     * Defines the page size, in bytes, for on-disk database pages for tables or
+     * indexes used during table or index creation. Page size can only be one
+     * the following values: 4096, 8192, 16384, or 32768. Set this property
+     * prior to issuing the CREATE TABLE or CREATE INDEX statement. This value
+     * will be used for the lifetime of the newly created conglomerates.
+     * <p/>
+     * Default is <code>16384</code>
+     *
+     * @param derbyStoragePageSize
+     */
+    public void setDerbyStoragePageSize(String derbyStoragePageSize) {
+        this.derbyStoragePageSize = Integer.decode(derbyStoragePageSize).intValue();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void init(PMContext context) throws Exception {
+        // init default values
+        if (getDriver() == null) {
+            setDriver(DERBY_EMBEDDED_DRIVER);
+        }
+        if (getSchema() == null) {
+            setSchema("derby");
+        }
+        if (getUrl() == null) {
+            setUrl("jdbc:derby:"+ context.getHomeDir().getPath() +"/db/itemState;create=true");
+        }
+        if (getUser() == null) {
+            setUser("");
+        }
+        if (getPassword() == null) {
+            setPassword("");
+        }
+        if (getSchemaObjectPrefix() == null) {
+            setSchemaObjectPrefix("");
+        }
+        super.init(context);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void checkSchema() throws SQLException, RepositoryException {
+        // set properties
+        if (DERBY_EMBEDDED_DRIVER.equals(getDriver())) {
+            Statement stmt = con.createStatement();
+            try {
+                stmt.execute("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY " +
+                        "('derby.storage.initialPages', '" + derbyStorageInitialPages + "')");
+                stmt.execute("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY " +
+                        "('derby.storage.minimumRecordSize', '" + derbyStorageMinimumRecordSize + "')");
+                stmt.execute("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY " +
+                        "('derby.storage.pageCacheSize', '" + derbyStoragePageCacheSize + "')");
+                stmt.execute("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY " +
+                        "('derby.storage.pageReservedSpace', '" + derbyStoragePageReservedSpace + "')");
+                stmt.execute("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY " +
+                        "('derby.storage.pageSize', '" + derbyStoragePageSize + "')");
+
+            } finally {
+                stmt.close();
+            }
+        }
+        super.checkSchema();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     *
+     * Since Derby cannot handle binary indexes, we use long-long keys.
+     *
+     * @return {@link BundleDbPersistenceManager#SM_LONGLONG_KEYS}
+     */
+    public int getStorageModel() {
+        return BundleDbPersistenceManager.SM_LONGLONG_KEYS;
+    }
+
+    /**
+     * Closes the given connection by shutting down the embedded Derby
+     * database.
+     *
+     * @throws SQLException if an error occurs
+     * @see DatabasePersistenceManager#closeConnection(Connection)
+     */
+    public void close() throws Exception {
+        // check for embedded driver
+        if (!DERBY_EMBEDDED_DRIVER.equals(getDriver())) {
+            return;
+        }
+
+        // prepare connection url for issuing shutdown command
+        String url = con.getMetaData().getURL();
+        int pos = url.lastIndexOf(';');
+        if (pos != -1) {
+            // strip any attributes from connection url
+            url = url.substring(0, pos);
+        }
+        url += ";shutdown=true";
+
+        // we have to reset the connection to 'autoCommit=true' before closing it;
+        // otherwise Derby would mysteriously complain about some pending uncommitted
+        // changes which can't possibly be true.
+        // @todo further investigate
+        con.setAutoCommit(true);
+
+        // now it's safe to shutdown the embedded Derby database
+        try {
+            DriverManager.getConnection(url);
+        } catch (SQLException e) {
+            // a shutdown command always raises a SQLException
+            log.info(e.getMessage());
+        }
+
+        super.close();
+    }
+
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url rev

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/H2PersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/H2PersistenceManager.java?view=auto&rev=517150
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/H2PersistenceManager.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/H2PersistenceManager.java Mon Mar 12 02:42:12 2007
@@ -0,0 +1,145 @@
+/*
+ * 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.persistence.bundle;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.core.persistence.PMContext;
+import org.apache.jackrabbit.core.persistence.PersistenceManager;
+
+import java.sql.Statement;
+import java.sql.SQLException;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Extends the {@link BundleDbPersistenceManager} by H2 specific code.
+ * <p/>
+ * Configuration:<br>
+ * <ul>
+ * <li>&lt;param name="{@link #setBundleCacheSize(String) bundleCacheSize}" value="8"/>
+ * <li>&lt;param name="{@link #setBlobFSBlockSize(String) blobFSBlockSize}" value="0"/>
+ * <li>&lt;param name="{@link #setBlobFSInitialCacheSize(String) blobFSInitialCacheSize}" value="100"/>
+ * <li>&lt;param name="{@link #setBlobFSMaximumCacheSize(String) blobFSMaximumCacheSize}" value="4000"/>
+ * <li>&lt;param name="{@link #setBlobFSLogBufferCache(String) blobFSLogBufferCache}" value="false"/>
+ * <li>&lt;param name="{@link #setBlobFSLogIOCalls(String) blobFSLogIOCalls}" value="false"/>
+ * <li>&lt;param name="{@link #setBlobFSLogSYSCalls(String) blobFSLogSYSCalls}" value="false"/>
+ * <li>&lt;param name="{@link #setConsistencyCheck(String) consistencyCheck}" value="false"/>
+ * <li>&lt;param name="{@link #setMinBlobSize(String) minBlobSize}" value="16384"/>
+ * <li>&lt;param name="{@link #setDriver(String) driver}" value="org.hsqldb.jdbcDriver"/>
+ * <li>&lt;param name="{@link #setUrl(String) url}" value="jdbc:hsqldb:file:${wsp.home}/db/itemState"/>
+ * <li>&lt;param name="{@link #setUser(String) user}" value="sa"/>
+ * <li>&lt;param name="{@link #setPassword(String) password}" value=""/>
+ * <li>&lt;param name="{@link #setSchema(String) schema}" value="native"/>
+ * <li>&lt;param name="{@link #setSchemaObjectPrefix(String) schemaObjectPrefix}" value=""/>
+ * <li>&lt;param name="{@link #setErrorHandling(String) errorHandling}" value=""/>
+ * <li>&lt;param name="{@link #setLockTimeout(String)} (String) lockTimeout}" value="10000"/>
+ * </ul>
+ */
+public class H2PersistenceManager extends BundleDbPersistenceManager {
+
+    /** the cvs/svn id */
+    static final String CVS_ID = "$URL$ $Rev$ $Date$";
+
+    /**
+     * the default logger
+     */
+    private static Logger log = LoggerFactory.getLogger(H2PersistenceManager.class);
+
+    /** the lock time out. see*/
+    private long lockTimeout = 10000;
+
+    /**
+     * Returns the lock timeout.
+     * @return the lock timeout
+     */
+    public String getLockTimeout() {
+        return String.valueOf(lockTimeout);
+    }
+
+    /**
+     * Sets the lock timeout in milliseconds.
+     * @param lockTimeout the lock timeout.
+     */
+    public void setLockTimeout(String lockTimeout) {
+        this.lockTimeout = Long.parseLong(lockTimeout);
+    }
+
+    /**
+     * Creates a new h2 persistence manager.
+     */
+    public H2PersistenceManager() {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+   public void init(PMContext context) throws Exception {
+        // init default values
+        if (getDriver() == null) {
+            setDriver("org.h2.Driver");
+        }
+        if (getUrl() == null) {
+            setUrl("jdbc:h2:file:"+ context.getHomeDir().getPath() +"/db/itemState");
+        }
+        if (getUser() == null) {
+            setUser("sa");
+        }
+        if (getPassword() == null) {
+            setPassword("sa");
+        }
+        if (getSchema() == null) {
+            setSchema("h2");
+        }
+        if (getSchemaObjectPrefix() == null) {
+            setSchemaObjectPrefix("");
+        }
+
+        super.init(context);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void checkSchema() throws SQLException, RepositoryException {
+        Statement stmt = con.createStatement();
+        try {
+            stmt.execute("SET LOCK_TIMEOUT " + lockTimeout);
+        } finally {
+            stmt.close();
+        }
+        super.checkSchema();
+    }
+
+    /**
+     * @see PersistenceManager#close
+     */
+    public synchronized void close() throws Exception {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+        if (getUrl().startsWith("jdbc:h2:file:")) {
+            // have to explicitly shutdown in-proc h2
+            Statement stmt = con.createStatement();
+            stmt.execute("shutdown");
+            stmt.close();
+        }
+        // call base class implementation
+        super.close();
+    }
+
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/H2PersistenceManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/H2PersistenceManager.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url rev

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MSSqlPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MSSqlPersistenceManager.java?view=auto&rev=517150
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MSSqlPersistenceManager.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MSSqlPersistenceManager.java Mon Mar 12 02:42:12 2007
@@ -0,0 +1,63 @@
+/*
+ * 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.persistence.bundle;
+
+import org.apache.jackrabbit.core.persistence.PMContext;
+
+/**
+ * Extends the {@link BundleDbPersistenceManager} by MS-SQL specific code.
+ * <p/>
+ * Configuration:<br>
+ * <ul>
+ * <li>&lt;param name="{@link #setBundleCacheSize(String) bundleCacheSize}" value="8"/>
+ * <li>&lt;param name="{@link #setBlobFSBlockSize(String) blobFSBlockSize}" value="0"/>
+ * <li>&lt;param name="{@link #setBlobFSInitialCacheSize(String) blobFSInitialCacheSize}" value="100"/>
+ * <li>&lt;param name="{@link #setBlobFSMaximumCacheSize(String) blobFSMaximumCacheSize}" value="4000"/>
+ * <li>&lt;param name="{@link #setBlobFSLogBufferCache(String) blobFSLogBufferCache}" value="false"/>
+ * <li>&lt;param name="{@link #setBlobFSLogIOCalls(String) blobFSLogIOCalls}" value="false"/>
+ * <li>&lt;param name="{@link #setBlobFSLogSYSCalls(String) blobFSLogSYSCalls}" value="false"/>
+ * <li>&lt;param name="{@link #setConsistencyCheck(String) consistencyCheck}" value="false"/>
+ * <li>&lt;param name="{@link #setMinBlobSize(String) minBlobSize}" value="16384"/>
+ * <li>&lt;param name="{@link #setDriver(String) driver}" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
+ * <li>&lt;param name="{@link #setUrl(String) url}" value=""/>
+ * <li>&lt;param name="{@link #setUser(String) user}" value=""/>
+ * <li>&lt;param name="{@link #setPassword(String) password}" value=""/>
+ * <li>&lt;param name="{@link #setSchema(String) schema}" value="mssql"/>
+ * <li>&lt;param name="{@link #setSchemaObjectPrefix(String) schemaObjectPrefix}" value=""/>
+ * <li>&lt;param name="{@link #setErrorHandling(String) errorHandling}" value=""/>
+ * </ul>
+ */
+public class MSSqlPersistenceManager extends BundleDbPersistenceManager {
+
+    /** the cvs/svn id */
+    static final String CVS_ID = "$URL$ $Rev$ $Date$";
+
+    /**
+     * {@inheritDoc}
+     */
+    public void init(PMContext context) throws Exception {
+        // init default values
+        if (getDriver() == null) {
+            setDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver");
+        }
+        if (getSchema() == null) {
+            setSchema("mssql");
+        }
+        super.init(context);
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MSSqlPersistenceManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MSSqlPersistenceManager.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url rev

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MySqlPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MySqlPersistenceManager.java?view=auto&rev=517150
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MySqlPersistenceManager.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MySqlPersistenceManager.java Mon Mar 12 02:42:12 2007
@@ -0,0 +1,63 @@
+/*
+ * 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.persistence.bundle;
+
+import org.apache.jackrabbit.core.persistence.PMContext;
+
+/**
+ * Extends the {@link BundleDbPersistenceManager} by mysql specific code.
+ * <p/>
+ * Configuration:<br>
+ * <ul>
+ * <li>&lt;param name="{@link #setBundleCacheSize(String) bundleCacheSize}" value="8"/>
+ * <li>&lt;param name="{@link #setBlobFSBlockSize(String) blobFSBlockSize}" value="0"/>
+ * <li>&lt;param name="{@link #setBlobFSInitialCacheSize(String) blobFSInitialCacheSize}" value="100"/>
+ * <li>&lt;param name="{@link #setBlobFSMaximumCacheSize(String) blobFSMaximumCacheSize}" value="4000"/>
+ * <li>&lt;param name="{@link #setBlobFSLogBufferCache(String) blobFSLogBufferCache}" value="false"/>
+ * <li>&lt;param name="{@link #setBlobFSLogIOCalls(String) blobFSLogIOCalls}" value="false"/>
+ * <li>&lt;param name="{@link #setBlobFSLogSYSCalls(String) blobFSLogSYSCalls}" value="false"/>
+ * <li>&lt;param name="{@link #setConsistencyCheck(String) consistencyCheck}" value="false"/>
+ * <li>&lt;param name="{@link #setMinBlobSize(String) minBlobSize}" value="16384"/>
+ * <li>&lt;param name="{@link #setDriver(String) driver}" value="org.gjt.mm.mysql.Drive"/>
+ * <li>&lt;param name="{@link #setUrl(String) url}" value=""/>
+ * <li>&lt;param name="{@link #setUser(String) user}" value=""/>
+ * <li>&lt;param name="{@link #setPassword(String) password}" value=""/>
+ * <li>&lt;param name="{@link #setSchema(String) schema}" value="mysql"/>
+ * <li>&lt;param name="{@link #setSchemaObjectPrefix(String) schemaObjectPrefix}" value=""/>
+ * <li>&lt;param name="{@link #setErrorHandling(String) errorHandling}" value=""/>
+ * </ul>
+ */
+public class MySqlPersistenceManager extends BundleDbPersistenceManager {
+
+    /** the cvs/svn id */
+    static final String CVS_ID = "$URL$ $Rev$ $Date$";
+
+    /**
+     * {@inheritDoc}
+     */
+    public void init(PMContext context) throws Exception {
+        // init default values
+        if (getDriver() == null) {
+            setDriver("org.gjt.mm.mysql.Driver");
+        }
+        if (getSchema() == null) {
+            setSchema("mysql");
+        }
+        super.init(context);
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MySqlPersistenceManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/MySqlPersistenceManager.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url rev

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java?view=auto&rev=517150
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java Mon Mar 12 02:42:12 2007
@@ -0,0 +1,124 @@
+/*
+ * 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.persistence.bundle;
+
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+
+import org.apache.jackrabbit.core.persistence.PMContext;
+import org.apache.jackrabbit.core.persistence.bundle.util.NGKDbNameIndex;
+import org.apache.jackrabbit.core.persistence.bundle.util.DbNameIndex;
+
+/**
+ * Extends the {@link BundleDbPersistenceManager} by Oracle specific code.
+ * <p/>
+ * Configuration:<br>
+ * <ul>
+ * <li>&lt;param name="{@link #setExternalBLOBs(String)} externalBLOBs}" value="false"/>
+ * <li>&lt;param name="{@link #setBundleCacheSize(String) bundleCacheSize}" value="8"/>
+ * <li>&lt;param name="{@link #setConsistencyCheck(String) consistencyCheck}" value="false"/>
+ * <li>&lt;param name="{@link #setMinBlobSize(String) minBlobSize}" value="16384"/>
+ * <li>&lt;param name="{@link #setDriver(String) driver}" value="oracle.jdbc.OracleDriverr"/>
+ * <li>&lt;param name="{@link #setUrl(String) url}" value="jdbc:oracle:thin:@127.0.0.1:1521:xe"/>
+ * <li>&lt;param name="{@link #setUser(String) user}" value="crx"/>
+ * <li>&lt;param name="{@link #setPassword(String) password}" value="crx"/>
+ * <li>&lt;param name="{@link #setSchema(String) schema}" value="oracle"/>
+ * <li>&lt;param name="{@link #setSchemaObjectPrefix(String) schemaObjectPrefix}" value="${wsp.name}_"/>
+ * <li>&lt;param name="{@link #setErrorHandling(String) errorHandling}" value=""/>
+ * </ul>
+ */
+public class OraclePersistenceManager extends BundleDbPersistenceManager {
+
+    /** the cvs/svn id */
+    static final String CVS_ID = "$URL$ $Rev$ $Date$";
+
+    /**
+     * Creates a new oracle persistence manager
+     */
+    public OraclePersistenceManager() {
+        // enable db blob support
+        setExternalBLOBs("false");
+    }
+
+    public void init(PMContext context) throws Exception {
+        // init default values
+        if (getDriver() == null) {
+            setDriver("oracle.jdbc.OracleDriver");
+        }
+        if (getUrl() == null) {
+            setUrl("jdbc:oracle:thin:@127.0.0.1:1521:xe");
+        }
+        if (getUser() == null) {
+            setUser("crx");
+        }
+        if (getPassword() == null) {
+            setPassword("crx");
+        }
+        if (getSchema() == null) {
+            setSchema("oracle");
+        }
+        if (getSchemaObjectPrefix() == null) {
+            setSchemaObjectPrefix(context.getHomeDir().getName() + "_");
+        }
+        super.init(context);
+/*
+        // check driver version
+        DatabaseMetaData metaData = con.getMetaData();
+        if (metaData.getDriverMajorVersion() < 10) {
+            // oracle drivers prior to version 10 only support
+            // writing BLOBs up to 32k in size...
+            log.warn("unsupported driver version detected: "
+                    + metaData.getDriverName()
+                    + " v" + metaData.getDriverVersion());
+        }
+*/
+    }
+
+    /**
+     * Retruns a new instance of a NGKDbNameIndex.
+     * @return a new instance of a NGKDbNameIndex.
+     * @throws SQLException if an SQL error occurs.
+     */
+    protected DbNameIndex createDbNameIndex() throws SQLException {
+        return new NGKDbNameIndex(con, schemaObjectPrefix);
+    }
+    
+    /**
+     * Since Oracle only supports table names up to 30 characters in
+     * length illegal characters are simply replaced with "_" rather than
+     * escaping them with "_x0000_".
+     *
+     * @inheritDoc
+     */
+    protected void prepareSchemaObjectPrefix() throws Exception {
+        DatabaseMetaData metaData = con.getMetaData();
+        String legalChars = metaData.getExtraNameCharacters();
+        legalChars += "ABCDEFGHIJKLMNOPQRSTUVWXZY0123456789_";
+
+        String prefix = schemaObjectPrefix.toUpperCase();
+        StringBuffer escaped = new StringBuffer();
+        for (int i = 0; i < prefix.length(); i++) {
+            char c = prefix.charAt(i);
+            if (legalChars.indexOf(c) == -1) {
+                escaped.append('_');
+            } else {
+                escaped.append(c);
+            }
+        }
+        schemaObjectPrefix = escaped.toString();
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url rev

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/derby.ddl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/derby.ddl?view=auto&rev=517150
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/derby.ddl (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/derby.ddl Mon Mar 12 02:42:12 2007
@@ -0,0 +1,4 @@
+create table ${schemaObjectPrefix}BUNDLE (NODE_ID_HI bigint not null, NODE_ID_LO bigint not null, BUNDLE_DATA blob(2G) not null, PRIMARY KEY (NODE_ID_HI, NODE_ID_LO))
+create table ${schemaObjectPrefix}REFS (NODE_ID_HI bigint not null, NODE_ID_LO bigint not null, REFS_DATA blob(2G) not null, PRIMARY KEY (NODE_ID_HI, NODE_ID_LO))
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID char(64) PRIMARY KEY, BINVAL_DATA blob(2G) not null)
+create table ${schemaObjectPrefix}NAMES (ID INTEGER GENERATED ALWAYS AS IDENTITY, NAME varchar(255) not null, PRIMARY KEY (ID, NAME))

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/h2.ddl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/h2.ddl?view=auto&rev=517150
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/h2.ddl (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/h2.ddl Mon Mar 12 02:42:12 2007
@@ -0,0 +1,4 @@
+create cached table ${schemaObjectPrefix}BUNDLE (NODE_ID binary(16) PRIMARY KEY, BUNDLE_DATA varbinary not null)
+create cached table ${schemaObjectPrefix}REFS (NODE_ID binary(16) PRIMARY KEY, REFS_DATA varbinary not null)
+create cached table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(64) PRIMARY KEY, BINVAL_DATA blob not null)
+create cached table ${schemaObjectPrefix}NAMES (ID INTEGER AUTO_INCREMENT PRIMARY KEY, NAME varchar(255) not null)
\ No newline at end of file

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/mssql.ddl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/mssql.ddl?view=auto&rev=517150
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/mssql.ddl (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/mssql.ddl Mon Mar 12 02:42:12 2007
@@ -0,0 +1,6 @@
+create table ${schemaObjectPrefix}BUNDLE (NODE_ID binary(16) not null, BUNDLE_DATA image not null)
+create unique index ${schemaObjectPrefix}BUNDLE_IDX on ${schemaObjectPrefix}BUNDLE (NODE_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID binary(16) not null, REFS_DATA image not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(64) not null, BINVAL_DATA image not null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/mysql.ddl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/mysql.ddl?view=auto&rev=517150
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/mysql.ddl (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/mysql.ddl Mon Mar 12 02:42:12 2007
@@ -0,0 +1,6 @@
+create table ${schemaObjectPrefix}BUNDLE (NODE_ID binary(16) not null, BUNDLE_DATA longblob not null)
+create unique index ${schemaObjectPrefix}BUNDLE_IDX on ${schemaObjectPrefix}BUNDLE (NODE_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID binary(16) not null, REFS_DATA longblob not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(64) not null, BINVAL_DATA longblob not null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/oracle.ddl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/oracle.ddl?view=auto&rev=517150
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/oracle.ddl (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/oracle.ddl Mon Mar 12 02:42:12 2007
@@ -0,0 +1,13 @@
+create table ${schemaObjectPrefix}BUNDLE (NODE_ID raw(16) not null, BUNDLE_DATA blob not null)
+create unique index ${schemaObjectPrefix}BUNDLE_IDX on ${schemaObjectPrefix}BUNDLE (NODE_ID)
+
+create table ${schemaObjectPrefix}REFS (NODE_ID raw(16) not null, REFS_DATA blob not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar2(64) not null, BINVAL_DATA blob null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
+
+create table ${schemaObjectPrefix}NAMES (ID INTEGER primary key, NAME varchar2(255) not null)
+create unique index ${schemaObjectPrefix}NAMES_IDX on ${schemaObjectPrefix}NAMES (NAME)
+create sequence ${schemaObjectPrefix}seq_names_id
+create trigger ${schemaObjectPrefix}t1 before insert on ${schemaObjectPrefix}NAMES for each row begin select ${schemaObjectPrefix}seq_names_id.nextval into :new.id from dual; end;
\ No newline at end of file



Mime
View raw message