jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r915810 [2/2] - in /jackrabbit/trunk: jackrabbit-jcr-client/src/test/java/org/apache/jackrabbit/client/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy...
Date Wed, 24 Feb 2010 14:49:13 GMT
Added: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/ItemInfoCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/ItemInfoCache.java?rev=915810&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/ItemInfoCache.java
(added)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/ItemInfoCache.java
Wed Feb 24 14:49:12 2010
@@ -0,0 +1,112 @@
+/*
+ * 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.spi;
+
+/**
+ * <code>ItemInfoCache</code> instances are responsible for caching {@link ItemInfo}s
along with an
+ * opaque generation counter. Implementors are free on the particular caching policy. That
is, how
+ * long (if at all) item infos are cached.
+ *
+ * An <code>ItemInfoCache</code> is supplied per session from the {@link RepositoryService}.
It is used
+ * to cache <code>ItemInfo</code>s read from the <code>RepositoryService</code>.
+ *
+ * @see RepositoryService#getItemInfos(SessionInfo, NodeId)
+ * @see org.apache.jackrabbit.spi.commons.ItemInfoCacheImpl
+ */
+public interface ItemInfoCache {
+
+    /**
+     * This class represents a cache entry.
+     * @param <T>  Wither a {@link NodeInfo} or a {@link PropertyInfo}.
+     */
+    class Entry<T extends ItemInfo> {
+
+        /**
+         * The {@link ItemInfo}
+         */
+        public final T info;
+
+        /**
+         * The generation
+         */
+        public final long generation;
+
+        /**
+         * Create a new cache entry containing <code>info</code> with a given
<code>generation</code>.
+         * @param info
+         * @param generation
+         */
+        public Entry(T info, long generation) {
+            this.info = info;
+            this.generation = generation;
+        }
+
+        @Override
+        public int hashCode() {
+            return info.hashCode() + (int) generation;
+        }
+
+        @Override
+        public boolean equals(Object that) {
+            if (that == null) {
+                return false;
+            }
+
+            if (that == this) {
+                return true;
+            }
+
+            if (that instanceof ItemInfoCache.Entry) {
+                ItemInfoCache.Entry other = (ItemInfoCache.Entry) that;
+                return generation == other.generation && info.equals(other.info);
+            }
+
+            return false;
+        }
+    }
+
+    /**
+     * Retreive a cache entry for the given <code>nodeId</code> or <code>null</code>
+     * if no such entry is in the cache.
+     *
+     * @param nodeId  id of the entry to lookup
+     * @return  a <code>Entry&lt;NodeInfo&gt;</code> instance or <code>null</code>
if not found
+     */
+    ItemInfoCache.Entry<NodeInfo> getNodeInfo(NodeId nodeId);
+
+    /**
+     * Retreive a cache entry for the given <code>propertyId</code> or <code>null</code>
+     * if no such entry is in the cache.
+     *
+     * @param propertyId  id of the entry to lookup
+     * @return  a <code>Entry&lt;PropertyInfo&gt;</code> instance or
<code>null</code> if not found
+     */
+    ItemInfoCache.Entry<PropertyInfo> getPropertyInfo(PropertyId propertyId);
+
+    /**
+     * Create a {@link Entry} for <code>info</code> and <code>generation</code>
and put it into
+     * the cache.
+     * @param info
+     * @param generation
+     */
+    void put(ItemInfo info, long generation);
+
+    /**
+     * Clear the cache and dispose all entries.
+     */
+    void dispose();
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/ItemInfoCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java?rev=915810&r1=915809&r2=915810&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
Wed Feb 24 14:49:12 2010
@@ -110,6 +110,14 @@
      */
     public QValueFactory getQValueFactory() throws RepositoryException;
 
+    /**
+     * Returns a {@link ItemInfoCache} for the given <code>SessionInfo</code>.
+     * @param sessionInfo
+     * @return
+     * @throws RepositoryException
+     */
+    public ItemInfoCache getItemInfoCache(SessionInfo sessionInfo) throws RepositoryException;
+
     //--------------------------------------------------------------------------
     /**
      * Returns all property descriptors that can be exposed with the
@@ -1256,4 +1264,5 @@
      * @since JCR 2.0
      */
     public void deleteWorkspace(SessionInfo sessionInfo, String name) throws AccessDeniedException,
UnsupportedRepositoryOperationException, NoSuchWorkspaceException, RepositoryException;
+
 }

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?rev=915810&r1=915809&r2=915810&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
Wed Feb 24 14:49:12 2010
@@ -16,6 +16,46 @@
  */
 package org.apache.jackrabbit.spi2dav;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.Credentials;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.LoginException;
+import javax.jcr.MergeException;
+import javax.jcr.NamespaceException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.InvalidNodeTypeDefinitionException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeTypeExistsException;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.version.VersionException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HostConfiguration;
 import org.apache.commons.httpclient.HttpClient;
@@ -35,6 +75,8 @@
 import org.apache.jackrabbit.spi.EventFilter;
 import org.apache.jackrabbit.spi.IdFactory;
 import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.ItemInfo;
+import org.apache.jackrabbit.spi.ItemInfoCache;
 import org.apache.jackrabbit.spi.LockInfo;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NameFactory;
@@ -54,10 +96,11 @@
 import org.apache.jackrabbit.spi.RepositoryService;
 import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.spi.Subscription;
-import org.apache.jackrabbit.spi.ItemInfo;
 import org.apache.jackrabbit.spi.commons.ChildInfoImpl;
 import org.apache.jackrabbit.spi.commons.EventBundleImpl;
 import org.apache.jackrabbit.spi.commons.EventFilterImpl;
+import org.apache.jackrabbit.spi.commons.ItemInfoCacheImpl;
+import org.apache.jackrabbit.spi.commons.conversion.IdentifierResolver;
 import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
 import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
@@ -66,7 +109,6 @@
 import org.apache.jackrabbit.spi.commons.conversion.ParsingNameResolver;
 import org.apache.jackrabbit.spi.commons.conversion.ParsingPathResolver;
 import org.apache.jackrabbit.spi.commons.conversion.PathResolver;
-import org.apache.jackrabbit.spi.commons.conversion.IdentifierResolver;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.namespace.AbstractNamespaceResolver;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
@@ -154,45 +196,6 @@
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
-import javax.jcr.AccessDeniedException;
-import javax.jcr.Credentials;
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.LoginException;
-import javax.jcr.MergeException;
-import javax.jcr.NamespaceException;
-import javax.jcr.NoSuchWorkspaceException;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
-import javax.jcr.ValueFormatException;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.nodetype.InvalidNodeTypeDefinitionException;
-import javax.jcr.nodetype.NodeTypeExistsException;
-import javax.jcr.query.InvalidQueryException;
-import javax.jcr.version.VersionException;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-
 /**
  * <code>RepositoryServiceImpl</code>...
  */
@@ -220,6 +223,8 @@
     private final QValueFactory qValueFactory;
     private final ValueFactory valueFactory;
 
+    private final int itemInfoCacheSize;
+
     private final Document domFactory;
     private final NamespaceCache nsCache;
     private final URIResolverImpl uriResolver;
@@ -233,9 +238,18 @@
     private Map<String, QValue[]> descriptors;
 
     public RepositoryServiceImpl(String uri, IdFactory idFactory,
+            NameFactory nameFactory,
+            PathFactory pathFactory,
+            QValueFactory qValueFactory) throws RepositoryException {
+
+        this(uri, idFactory, nameFactory, pathFactory, qValueFactory, ItemInfoCacheImpl.DEFAULT_CACHE_SIZE);
+    }
+
+    public RepositoryServiceImpl(String uri, IdFactory idFactory,
                                  NameFactory nameFactory,
                                  PathFactory pathFactory,
-                                 QValueFactory qValueFactory) throws RepositoryException
{
+                                 QValueFactory qValueFactory,
+                                 int itemInfoCacheSize) throws RepositoryException {
         if (uri == null || "".equals(uri)) {
             throw new RepositoryException("Invalid repository uri '" + uri + "'.");
         }
@@ -247,6 +261,7 @@
         this.nameFactory = nameFactory;
         this.pathFactory = pathFactory;
         this.qValueFactory = qValueFactory;
+        this.itemInfoCacheSize = itemInfoCacheSize;
 
         try {
             domFactory = DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument();
@@ -263,7 +278,7 @@
             uriResolver = new URIResolverImpl(repositoryUri, this, domFactory);
             NamePathResolver resolver = new NamePathResolverImpl(nsCache);
             valueFactory = new ValueFactoryQImpl(qValueFactory, resolver);
-            
+
         } catch (URIException e) {
             throw new RepositoryException(e);
         }
@@ -359,7 +374,7 @@
         }
         return resolver;
     }
-    
+
     protected HttpClient getClient(SessionInfo sessionInfo) throws RepositoryException {
         HttpClient client = clients.get(sessionInfo);
         if (client == null) {
@@ -393,7 +408,7 @@
     /**
      * Clear all URI mappings. This is required after hierarchy operations such
      * as e.g. MOVE.
-     * 
+     *
      * @param sessionInfo
      */
     protected void clearItemUriCache(SessionInfo sessionInfo) {
@@ -452,7 +467,7 @@
         }
         return index;
     }
-    
+
     //--------------------------------------------------------------------------
     /**
      * Execute a 'Workspace' operation.
@@ -505,6 +520,10 @@
         return qValueFactory;
     }
 
+    public ItemInfoCache getItemInfoCache(SessionInfo sessionInfo) throws RepositoryException
{
+        return new ItemInfoCacheImpl(itemInfoCacheSize);
+    }
+
     /**
      * @see RepositoryService#getRepositoryDescriptors()
      */
@@ -1786,7 +1805,7 @@
     }
 
     /**
-     * @see RepositoryService#getEvents(SessionInfo, EventFilter,long) 
+     * @see RepositoryService#getEvents(SessionInfo, EventFilter,long)
      */
     public EventBundle getEvents(SessionInfo sessionInfo, EventFilter filter,
                                    long after) throws
@@ -2631,7 +2650,7 @@
     private class IdentifierResolverImpl implements IdentifierResolver {
 
         private final SessionInfo sessionInfo;
-        
+
         private IdentifierResolverImpl(SessionInfo sessionInfo) {
             this.sessionInfo = sessionInfo;
         }
@@ -2644,7 +2663,7 @@
         private Path resolvePath(String jcrPath) throws RepositoryException {
             return ((SessionInfoImpl) sessionInfo).getNamePathResolver().getQPath(jcrPath);
         }
-        
+
         /**
          * @inheritDoc
          */

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/Spi2davRepositoryServiceFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/Spi2davRepositoryServiceFactory.java?rev=915810&r1=915809&r2=915810&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/Spi2davRepositoryServiceFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/Spi2davRepositoryServiceFactory.java
Wed Feb 24 14:49:12 2010
@@ -21,11 +21,13 @@
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.ItemInfoCache;
 import org.apache.jackrabbit.spi.NameFactory;
 import org.apache.jackrabbit.spi.PathFactory;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.RepositoryService;
 import org.apache.jackrabbit.spi.RepositoryServiceFactory;
+import org.apache.jackrabbit.spi.commons.ItemInfoCacheImpl;
 import org.apache.jackrabbit.spi.commons.identifier.IdFactoryImpl;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
@@ -69,6 +71,12 @@
      */
     public static final String PARAM_QVALUE_FACTORY = "org.apache.jackrabbit.spi2dav.QValueFactory";
 
+    /**
+     * Optional configuration parameter: It's value determines the size of the
+     * {@link ItemInfoCache} cache. Defaults to {@link ItemInfoCacheImpl#DEFAULT_CACHE_SIZE}.
+     */
+    public static final String PARAM_ITEMINFO_CACHE_SIZE = "org.apache.jackrabbit.spi2dav.ItemInfoCacheSize";
+
     public RepositoryService createRepositoryService(Map<?, ?> parameters) throws RepositoryException
{
         if (parameters == null) {
             throw new RepositoryException("Parameter " + PARAM_REPOSITORY_URI + " missing");
@@ -113,7 +121,18 @@
         } else {
             vFactory = QValueFactoryImpl.getInstance();
         }
-        return new RepositoryServiceImpl(uri, idFactory, nameFactory, pathFactory, vFactory);
+
+        int itemInfoCacheSize = ItemInfoCacheImpl.DEFAULT_CACHE_SIZE;
+        param = parameters.get(PARAM_ITEMINFO_CACHE_SIZE);
+        if (param != null) {
+            try {
+                itemInfoCacheSize = Integer.parseInt(param.toString());
+            }
+            catch (NumberFormatException e) {
+                // ignore, use default
+            }
+        }
+        return new RepositoryServiceImpl(uri, idFactory, nameFactory, pathFactory, vFactory,
itemInfoCacheSize);
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/RepositoryServiceImpl.java?rev=915810&r1=915809&r2=915810&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/RepositoryServiceImpl.java
Wed Feb 24 14:49:12 2010
@@ -16,6 +16,19 @@
  */
 package org.apache.jackrabbit.spi2davex;
 
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.Credentials;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpException;
 import org.apache.commons.httpclient.HttpMethod;
@@ -38,6 +51,7 @@
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.RepositoryService;
 import org.apache.jackrabbit.spi.SessionInfo;
+import org.apache.jackrabbit.spi.commons.ItemInfoCacheImpl;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.conversion.PathResolver;
 import org.apache.jackrabbit.spi.commons.identifier.IdFactoryImpl;
@@ -55,18 +69,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.Credentials;
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 /**
  * <code>RepositoryServiceImpl</code>...
  */
@@ -112,11 +114,14 @@
     private final Map<SessionInfo, QValueFactoryImpl> qvFactories = new HashMap<SessionInfo,
QValueFactoryImpl>();
 
     public RepositoryServiceImpl(String jcrServerURI, BatchReadConfig batchReadConfig) throws
RepositoryException {
-        this(jcrServerURI, null, batchReadConfig);
+        this(jcrServerURI, null, batchReadConfig, ItemInfoCacheImpl.DEFAULT_CACHE_SIZE);
     }
 
-    public RepositoryServiceImpl(String jcrServerURI, String defaultWorkspaceName, BatchReadConfig
batchReadConfig) throws RepositoryException {
-        super(jcrServerURI, IdFactoryImpl.getInstance(), NameFactoryImpl.getInstance(), PathFactoryImpl.getInstance(),
new QValueFactoryImpl());
+    public RepositoryServiceImpl(String jcrServerURI, String defaultWorkspaceName,
+            BatchReadConfig batchReadConfig, int itemInfoCacheSize) throws RepositoryException
{
+
+        super(jcrServerURI, IdFactoryImpl.getInstance(), NameFactoryImpl.getInstance(), PathFactoryImpl
+                .getInstance(), new QValueFactoryImpl(), itemInfoCacheSize);
 
         this.jcrServerURI = jcrServerURI.endsWith("/") ? jcrServerURI : jcrServerURI + "/";
         this.defaultWorkspaceName = defaultWorkspaceName;

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/Spi2davexRepositoryServiceFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/Spi2davexRepositoryServiceFactory.java?rev=915810&r1=915809&r2=915810&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/Spi2davexRepositoryServiceFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/Spi2davexRepositoryServiceFactory.java
Wed Feb 24 14:49:12 2010
@@ -18,13 +18,12 @@
 
 import java.util.Map;
 
-import javax.jcr.NamespaceException;
 import javax.jcr.RepositoryException;
 
-import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.ItemInfoCache;
 import org.apache.jackrabbit.spi.RepositoryService;
 import org.apache.jackrabbit.spi.RepositoryServiceFactory;
-import org.apache.jackrabbit.spi.commons.conversion.PathResolver;
+import org.apache.jackrabbit.spi.commons.ItemInfoCacheImpl;
 
 /**
  * This {@link RepositoryServiceFactory} implementation is responsible
@@ -52,7 +51,13 @@
      * Optional batch read configuration parameter: If present it's value is
      * expected to be an instance of {@link BatchReadConfig}
      */
-    public static final String PARAM_BATCHREAD_CONFIG = "org.apache.jackrabbit.spi2dav.BatchReadConfig";
+    public static final String PARAM_BATCHREAD_CONFIG = "org.apache.jackrabbit.spi2davex.BatchReadConfig";
+
+    /**
+     * Optional configuration parameter: It's value determines the size of the
+     * {@link ItemInfoCache} cache. Defaults to {@link ItemInfoCacheImpl#DEFAULT_CACHE_SIZE}.
+     */
+    public static final String PARAM_ITEMINFO_CACHE_SIZE = "org.apache.jackrabbit.spi2davex.ItemInfoCacheSize";
 
     public RepositoryService createRepositoryService(Map<?, ?> parameters) throws RepositoryException
{
         String uri;
@@ -77,7 +82,18 @@
             }
         }
 
-        return new RepositoryServiceImpl(uri, brc);
+        int itemInfoCacheSize = ItemInfoCacheImpl.DEFAULT_CACHE_SIZE;
+        Object param = parameters.get(PARAM_ITEMINFO_CACHE_SIZE);
+        if (param != null) {
+            try {
+                itemInfoCacheSize = Integer.parseInt(param.toString());
+            }
+            catch (NumberFormatException e) {
+                // ignore, use default
+            }
+        }
+
+        return new RepositoryServiceImpl(uri, null, brc, itemInfoCacheSize);
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java?rev=915810&r1=915809&r2=915810&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
Wed Feb 24 14:49:12 2010
@@ -16,112 +16,115 @@
  */
 package org.apache.jackrabbit.spi2jcr;
 
-import org.apache.jackrabbit.spi.RepositoryService;
-import org.apache.jackrabbit.spi.IdFactory;
-import org.apache.jackrabbit.spi.QValueFactory;
-import org.apache.jackrabbit.spi.SessionInfo;
-import org.apache.jackrabbit.spi.ItemId;
-import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.spi.QNodeDefinition;
-import org.apache.jackrabbit.spi.QPropertyDefinition;
-import org.apache.jackrabbit.spi.PropertyId;
-import org.apache.jackrabbit.spi.NodeInfo;
-import org.apache.jackrabbit.spi.PropertyInfo;
-import org.apache.jackrabbit.spi.Batch;
-import org.apache.jackrabbit.spi.LockInfo;
-import org.apache.jackrabbit.spi.QueryInfo;
-import org.apache.jackrabbit.spi.EventFilter;
-import org.apache.jackrabbit.spi.EventBundle;
-import org.apache.jackrabbit.spi.QValue;
-import org.apache.jackrabbit.spi.NameFactory;
-import org.apache.jackrabbit.spi.PathFactory;
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.Path;
-import org.apache.jackrabbit.spi.Subscription;
-import org.apache.jackrabbit.spi.QNodeTypeDefinition;
-import org.apache.jackrabbit.spi.Event;
-import org.apache.jackrabbit.spi.commons.EventFilterImpl;
-import org.apache.jackrabbit.spi.commons.EventBundleImpl;
-import org.apache.jackrabbit.spi.commons.QPropertyDefinitionImpl;
-import org.apache.jackrabbit.spi.commons.QNodeDefinitionImpl;
-import org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl;
-import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
-import org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefinitionImpl;
-import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
-import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
-import org.apache.jackrabbit.spi.commons.name.NameConstants;
-import org.apache.jackrabbit.spi.commons.name.PathBuilder;
-import org.apache.jackrabbit.spi.commons.conversion.NameException;
-import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
-import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
-import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
-import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
-import org.apache.jackrabbit.spi.commons.value.ValueFormat;
-import org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl;
-import org.apache.jackrabbit.JcrConstants;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.AccessControlException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
-import javax.jcr.RepositoryException;
+import javax.jcr.AccessDeniedException;
 import javax.jcr.Credentials;
+import javax.jcr.GuestCredentials;
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.ItemVisitor;
 import javax.jcr.LoginException;
+import javax.jcr.MergeException;
+import javax.jcr.NamespaceException;
+import javax.jcr.NamespaceRegistry;
 import javax.jcr.NoSuchWorkspaceException;
-import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.PathNotFoundException;
-import javax.jcr.ValueFormatException;
-import javax.jcr.AccessDeniedException;
-import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.ItemExistsException;
-import javax.jcr.InvalidItemStateException;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
 import javax.jcr.ReferentialIntegrityException;
-import javax.jcr.MergeException;
-import javax.jcr.NamespaceException;
 import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.NodeIterator;
-import javax.jcr.NamespaceRegistry;
-import javax.jcr.Workspace;
-import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
-import javax.jcr.ItemVisitor;
 import javax.jcr.ValueFactory;
-import javax.jcr.GuestCredentials;
-import javax.jcr.PropertyIterator;
-import javax.jcr.util.TraversingItemVisitor;
-import javax.jcr.observation.ObservationManager;
-import javax.jcr.observation.EventListener;
+import javax.jcr.ValueFormatException;
+import javax.jcr.Workspace;
+import javax.jcr.lock.Lock;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.InvalidNodeTypeDefinitionException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeDefinition;
+import javax.jcr.nodetype.NodeTypeExistsException;
+import javax.jcr.nodetype.NodeTypeIterator;
+import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.observation.EventJournal;
+import javax.jcr.observation.EventListener;
+import javax.jcr.observation.ObservationManager;
 import javax.jcr.query.InvalidQueryException;
-import javax.jcr.query.QueryManager;
 import javax.jcr.query.Query;
-import javax.jcr.lock.LockException;
-import javax.jcr.lock.Lock;
+import javax.jcr.query.QueryManager;
+import javax.jcr.util.TraversingItemVisitor;
+import javax.jcr.version.Version;
 import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
-import javax.jcr.version.Version;
 import javax.jcr.version.VersionManager;
-import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.NodeTypeManager;
-import javax.jcr.nodetype.NodeTypeIterator;
-import javax.jcr.nodetype.NodeType;
-import javax.jcr.nodetype.InvalidNodeTypeDefinitionException;
-import javax.jcr.nodetype.NodeTypeExistsException;
-import javax.jcr.nodetype.NodeTypeDefinition;
-import java.util.Map;
-import java.util.Iterator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Collection;
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.ByteArrayInputStream;
-import java.security.AccessControlException;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.spi.Batch;
+import org.apache.jackrabbit.spi.Event;
+import org.apache.jackrabbit.spi.EventBundle;
+import org.apache.jackrabbit.spi.EventFilter;
+import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.ItemInfoCache;
+import org.apache.jackrabbit.spi.LockInfo;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.NodeInfo;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.spi.PropertyInfo;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
+import org.apache.jackrabbit.spi.QueryInfo;
+import org.apache.jackrabbit.spi.RepositoryService;
+import org.apache.jackrabbit.spi.SessionInfo;
+import org.apache.jackrabbit.spi.Subscription;
+import org.apache.jackrabbit.spi.commons.EventBundleImpl;
+import org.apache.jackrabbit.spi.commons.EventFilterImpl;
+import org.apache.jackrabbit.spi.commons.ItemInfoCacheImpl;
+import org.apache.jackrabbit.spi.commons.QNodeDefinitionImpl;
+import org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl;
+import org.apache.jackrabbit.spi.commons.QPropertyDefinitionImpl;
+import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
+import org.apache.jackrabbit.spi.commons.conversion.NameException;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.name.PathBuilder;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
+import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
+import org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefinitionImpl;
+import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
+import org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl;
+import org.apache.jackrabbit.spi.commons.value.ValueFormat;
 
 /**
  * <code>RepositoryServiceImpl</code> implements a repository service on top
@@ -156,6 +159,12 @@
      */
     private final boolean supportsObservation;
 
+    private final int itemInfoCacheSize;
+
+    public RepositoryServiceImpl(Repository repository, BatchReadConfig batchReadConfig)
{
+        this(repository, batchReadConfig, ItemInfoCacheImpl.DEFAULT_CACHE_SIZE);
+    }
+
     /**
      * Creates a new repository service based on the given
      * <code>repository</code>.
@@ -164,10 +173,11 @@
      * @param batchReadConfig
      * {@link #getNodeInfo(SessionInfo, NodeId)}.
      */
-    public RepositoryServiceImpl(Repository repository, BatchReadConfig batchReadConfig)
{
+    public RepositoryServiceImpl(Repository repository, BatchReadConfig batchReadConfig,
int itemInfoCacheSize) {
         this.repository = repository;
         this.batchReadConfig = batchReadConfig;
         this.supportsObservation = "true".equals(repository.getDescriptor(Repository.OPTION_OBSERVATION_SUPPORTED));
+        this.itemInfoCacheSize = itemInfoCacheSize;
 
         try {
             Session s = repository.login(new GuestCredentials());
@@ -176,7 +186,7 @@
                 qValueFactory = ((ValueFactoryQImpl) vf).getQValueFactory();
             }
         } catch (RepositoryException e) {
-            // ignore            
+            // ignore
         }
     }
 
@@ -208,6 +218,10 @@
         return qValueFactory;
     }
 
+    public ItemInfoCache getItemInfoCache(SessionInfo sessionInfo) throws RepositoryException
{
+        return new ItemInfoCacheImpl(itemInfoCacheSize);
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -650,7 +664,7 @@
                 Lock lock;
                 // TODO: remove check once jsr283 is released
                 if (sInfo.getSession() instanceof javax.jcr.Session) {
-                    javax.jcr.lock.LockManager lMgr = (((javax.jcr.Workspace) sInfo.getSession().getWorkspace()).getLockManager());
+                    javax.jcr.lock.LockManager lMgr = ((sInfo.getSession().getWorkspace()).getLockManager());
                     lock = lMgr.lock(n.getPath(), deep, sessionScoped, timeoutHint, ownerHint);
                 } else {
                     lock = n.lock(deep, sessionScoped);
@@ -1259,7 +1273,7 @@
             try {
                 String ntName = sInfo.getNamePathResolver().getJCRName(nodetypeName);
                 NodeType nt = ntMgr.getNodeType(ntName);
-                defs.add(new QNodeTypeDefinitionImpl(nt, 
+                defs.add(new QNodeTypeDefinitionImpl(nt,
                         sInfo.getNamePathResolver(), getQValueFactory()));
 
                 // in addition pack all supertypes into the return value
@@ -1769,7 +1783,7 @@
     /**
      * Utility method that changes the namespace mappings of the
      * given sessions to include the given prefix to URI mappings.
-     * 
+     *
      * @param session current session
      * @param namespaces prefix to URI mappings
      * @return the previous namespace mappings that were modified

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/Spi2jcrRepositoryServiceFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/Spi2jcrRepositoryServiceFactory.java?rev=915810&r1=915809&r2=915810&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/Spi2jcrRepositoryServiceFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/Spi2jcrRepositoryServiceFactory.java
Wed Feb 24 14:49:12 2010
@@ -21,8 +21,10 @@
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 
+import org.apache.jackrabbit.spi.ItemInfoCache;
 import org.apache.jackrabbit.spi.RepositoryService;
 import org.apache.jackrabbit.spi.RepositoryServiceFactory;
+import org.apache.jackrabbit.spi.commons.ItemInfoCacheImpl;
 
 public class Spi2jcrRepositoryServiceFactory implements RepositoryServiceFactory {
 
@@ -37,6 +39,11 @@
      */
     public static final String PARAM_BATCH_READ_CONFIG = "org.apache.jackrabbit.spi2jcr.BatchReadConfig";
 
+    /**
+     * Optional configuration parameter: It's value determines the size of the
+     * {@link ItemInfoCache} cache. Defaults to {@link ItemInfoCacheImpl#DEFAULT_CACHE_SIZE}.
+     */
+    public static final String PARAM_ITEMINFO_CACHE_SIZE = "org.apache.jackrabbit.spi2jcr.ItemInfoCacheSize";
 
     public RepositoryService createRepositoryService(Map<?, ?> parameters) throws RepositoryException
{
         if (parameters == null) {
@@ -57,7 +64,18 @@
             brConfig = new BatchReadConfig();
         }
 
-        return new RepositoryServiceImpl((Repository) repo, brConfig);
+        int itemInfoCacheSize = ItemInfoCacheImpl.DEFAULT_CACHE_SIZE;
+        Object param = parameters.get(PARAM_ITEMINFO_CACHE_SIZE);
+        if (param != null) {
+            try {
+                itemInfoCacheSize = Integer.parseInt(param.toString());
+            }
+            catch (NumberFormatException e) {
+                // ignore, use default
+            }
+        }
+
+        return new RepositoryServiceImpl((Repository) repo, brConfig, itemInfoCacheSize);
     }
 
 }



Mime
View raw message