jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1460703 - in /jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav: IdPathCache.java IdURICache.java URIResolverImpl.java
Date Mon, 25 Mar 2013 15:03:26 GMT
Author: reschke
Date: Mon Mar 25 15:03:26 2013
New Revision: 1460703

URL: http://svn.apache.org/r1460703
Log:
JCR-3535: backout incorrect/incomplete change 1459743

Added:
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java
      - copied unchanged from r1459742, jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java
Removed:
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdPathCache.java
Modified:
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java?rev=1460703&r1=1460702&r2=1460703&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java
Mon Mar 25 15:03:26 2013
@@ -40,14 +40,11 @@ import org.apache.jackrabbit.webdav.prop
 import org.apache.jackrabbit.webdav.property.DavPropertySet;
 import org.apache.jackrabbit.webdav.version.report.ReportInfo;
 import org.apache.jackrabbit.webdav.xml.DomUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.RepositoryException;
 import java.io.IOException;
-import java.net.URISyntaxException;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -56,20 +53,13 @@ import java.util.Map;
  */
 class URIResolverImpl implements URIResolver {
 
-    private static Logger log = LoggerFactory.getLogger(URIResolverImpl.class);
-
-    /**
-     * @see <a href="https://issues.apache.org/jira/browse/JCR-3305">JCR-3305</a>:
limit cache size
-     */
-    private static final int CACHESIZE = 10000;
-
     private final URI repositoryUri;
     private final RepositoryServiceImpl service;
     private final Document domFactory;
 
     // TODO: to-be-fixed. uri/id-caches don't get updated
     // for each workspace a separate idUri-cache is created
-    private final Map<String, IdPathCache> idPathCaches = new HashMap<String, IdPathCache>();
+    private final Map<String, IdURICache> idURICaches = new HashMap<String, IdURICache>();
 
     URIResolverImpl(URI repositoryUri, RepositoryServiceImpl service, Document domFactory)
{
         this.repositoryUri = repositoryUri;
@@ -77,14 +67,13 @@ class URIResolverImpl implements URIReso
         this.domFactory = domFactory;
     }
 
-    private IdPathCache getCache(String workspaceName) {
-        IdPathCache cache = idPathCaches.get(workspaceName);
-        if (cache != null) {
-            return cache;
+    private IdURICache getCache(String workspaceName) {
+        if (idURICaches.containsKey(workspaceName)) {
+            return idURICaches.get(workspaceName);
         } else {
-            IdPathCache emptyCache = new IdPathCache(CACHESIZE);
-            idPathCaches.put(workspaceName, emptyCache);
-            return emptyCache;
+            IdURICache c = new IdURICache(getWorkspaceUri(workspaceName));
+            idURICaches.put(workspaceName, c);
+            return c;
         }
     }
 
@@ -106,10 +95,10 @@ class URIResolverImpl implements URIReso
 
     String getItemUri(ItemId itemId, String workspaceName, SessionInfo sessionInfo)
             throws RepositoryException {
-        IdPathCache cache = getCache(workspaceName);
+        IdURICache cache = getCache(workspaceName);
         // check if uri is available from cache
         if (cache.containsItemId(itemId)) {
-            return getUri(cache.getPath(itemId));
+            return cache.getUri(itemId);
         } else {
             StringBuffer uriBuffer = new StringBuffer();
 
@@ -121,7 +110,7 @@ class URIResolverImpl implements URIReso
                 ItemId uuidId = (path == null) ? itemId : service.getIdFactory().createNodeId(uniqueID);
                 if (path != null && cache.containsItemId(uuidId)) {
                     // append uri of parent node, that is already cached
-                    uriBuffer.append(getUri(cache.getPath(uuidId)));
+                    uriBuffer.append(cache.getUri(uuidId));
                 } else {
                     // try to request locate-by-uuid report to build the uri
                     ReportInfo rInfo = new ReportInfo(JcrRemotingConstants.REPORT_LOCATE_BY_UUID,
ItemResourceConstants.NAMESPACE);
@@ -137,7 +126,7 @@ class URIResolverImpl implements URIReso
                         MultiStatus ms = rm.getResponseBodyAsMultiStatus();
                         if (ms.getResponses().length == 1) {
                             uriBuffer.append(ms.getResponses()[0].getHref());
-                            cache.add(getPath(ms.getResponses()[0].getHref()), uuidId);
+                            cache.add(ms.getResponses()[0].getHref(), uuidId);
                         } else {
                             throw new ItemNotFoundException("Cannot identify item with uniqueID
" + uniqueID);
                         }
@@ -166,7 +155,7 @@ class URIResolverImpl implements URIReso
             }
             String itemUri = uriBuffer.toString();
             if (!cache.containsItemId(itemId)) {
-                cache.add(getPath(itemUri), itemId);
+                cache.add(itemUri, itemId);
             }
             return itemUri;
         }
@@ -174,7 +163,7 @@ class URIResolverImpl implements URIReso
 
     NodeId buildNodeId(NodeId parentId, MultiStatusResponse response,
                        String workspaceName, NamePathResolver resolver) throws RepositoryException
{
-        IdPathCache cache = getCache(workspaceName);
+        IdURICache cache = getCache(workspaceName);
         
         NodeId nodeId;
         DavPropertySet propSet = response.getProperties(DavServletResponse.SC_OK);
@@ -192,16 +181,15 @@ class URIResolverImpl implements URIReso
             }
         }
         // cache
-        cache.add(getPath(response.getHref()), nodeId);
+        cache.add(response.getHref(), nodeId);
         return nodeId;
     }
 
     PropertyId buildPropertyId(NodeId parentId, MultiStatusResponse response,
                                String workspaceName, NamePathResolver resolver) throws RepositoryException
{
-        IdPathCache cache = getCache(workspaceName);
-        String path = getPath(response.getHref());
-        if (cache.containsPath(path)) {
-            ItemId id = cache.getItemId(path);
+        IdURICache cache = getCache(workspaceName);
+        if (cache.containsUri(response.getHref())) {
+            ItemId id = cache.getItemId(response.getHref());
             if (!id.denotesNode()) {
                 return (PropertyId) id;
             }
@@ -212,15 +200,22 @@ class URIResolverImpl implements URIReso
             Name name = resolver.getQName(propSet.get(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE).getValue().toString());
             PropertyId propertyId = service.getIdFactory().createPropertyId(parentId, name);
 
-            cache.add(getPath(response.getHref()), propertyId);
+            cache.add(response.getHref(), propertyId);
             return propertyId;
         } catch (NameException e) {
             throw new RepositoryException(e);
         }
     }
 
+    void clearCacheEntries(ItemId itemId, SessionInfo sessionInfo) {
+        IdURICache cache = getCache(sessionInfo.getWorkspaceName());
+        if (cache.containsItemId(itemId)) {
+            cache.remove(itemId);
+        }
+    }
+
     void clearCacheEntries(SessionInfo sessionInfo) {
-        IdPathCache cache = getCache(sessionInfo.getWorkspaceName());
+        IdURICache cache = getCache(sessionInfo.getWorkspaceName());
         cache.clear();
     }
 
@@ -238,11 +233,10 @@ class URIResolverImpl implements URIReso
     }
 
     private NodeId getNodeId(String uri, SessionInfo sessionInfo, boolean nodeIsGone) throws
RepositoryException {
-        IdPathCache cache = getCache(sessionInfo.getWorkspaceName());
-        String path = getPath(uri);
-        if (cache.containsPath(path)) {
+        IdURICache cache = getCache(sessionInfo.getWorkspaceName());
+        if (cache.containsUri(uri)) {
             // id has been accessed before and is cached
-            ItemId id = cache.getItemId(path);
+            ItemId id = cache.getItemId(uri);
             if (id.denotesNode()) {
                 return (NodeId) id;
             }
@@ -287,32 +281,6 @@ class URIResolverImpl implements URIReso
         }
     }
 
-    /**
-     * @param uri the uri to be parsed
-     * @return the path (trailing slash removed) extracted from the given uri or <code>null</code>
if the uri could not
-     *         be parsed.
-     */
-    private String getPath(String uri) {
-        try {
-            String path = new java.net.URI(uri).getPath();
-            if (path.endsWith("/") && ! "/".equals(path)) {
-                return path.substring(0, path.length() - 1);
-            }
-            return path;
-        } catch (URISyntaxException e) {
-            log.warn("Failed to parse the URI = {}", uri);
-        }
-        return null;
-    }
-
-    private String getUri(String path) {
-        String baseUri = getRepositoryUri();
-        if (baseUri.endsWith("/")) {
-            return baseUri.substring(0, baseUri.length() - 1) + Text.escapePath(path);
-        }
-        return baseUri + Text.escapePath(path);
-    }
-
     //-------------------------------------------------------< URI resolver >---
     /**
      * @inheritDoc
@@ -351,10 +319,9 @@ class URIResolverImpl implements URIReso
      * @inheritDoc
      */
     public PropertyId getPropertyId(String uri, SessionInfo sessionInfo) throws RepositoryException
{
-        IdPathCache cache = getCache(sessionInfo.getWorkspaceName());
-        String path = getPath(uri);
-        if (cache.containsPath(path)) {
-            ItemId id = cache.getItemId(path);
+        IdURICache cache = getCache(sessionInfo.getWorkspaceName());
+        if (cache.containsUri(uri)) {
+            ItemId id = cache.getItemId(uri);
             if (!id.denotesNode()) {
                 return (PropertyId) id;
             }
@@ -370,7 +337,7 @@ class URIResolverImpl implements URIReso
         try {
             Name name = service.getNamePathResolver(sessionInfo).getQName(propName);
             PropertyId propertyId = service.getIdFactory().createPropertyId(parentId, name);
-            cache.add(getPath(uri), propertyId);
+            cache.add(uri, propertyId);
 
             return propertyId;
         } catch (NameException e) {



Mime
View raw message