mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Check point of Lookup Caching.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4401 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -123,6 +123,12 @@
|
|||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="lookupCache" class="org.alfresco.repo.avm.LookupCache">
|
||||||
|
<property name="avmNodeDAO">
|
||||||
|
<ref bean="avmNodeDAO"/>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
<bean id="rawServices" class="org.alfresco.repo.avm.util.RawServices"/>
|
<bean id="rawServices" class="org.alfresco.repo.avm.util.RawServices"/>
|
||||||
|
|
||||||
<bean id="orphanReaper" class="org.alfresco.repo.avm.OrphanReaper"
|
<bean id="orphanReaper" class="org.alfresco.repo.avm.OrphanReaper"
|
||||||
|
@@ -31,6 +31,7 @@ import java.util.TreeMap;
|
|||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.avm.util.RawServices;
|
import org.alfresco.repo.avm.util.RawServices;
|
||||||
|
import org.alfresco.repo.avm.util.SimplePath;
|
||||||
import org.alfresco.repo.domain.DbAccessControlList;
|
import org.alfresco.repo.domain.DbAccessControlList;
|
||||||
import org.alfresco.repo.domain.PropertyValue;
|
import org.alfresco.repo.domain.PropertyValue;
|
||||||
import org.alfresco.service.cmr.avm.AVMBadArgumentException;
|
import org.alfresco.service.cmr.avm.AVMBadArgumentException;
|
||||||
@@ -583,70 +584,8 @@ public class AVMStoreImpl implements AVMStore, Serializable
|
|||||||
*/
|
*/
|
||||||
public Lookup lookup(int version, String path, boolean write, boolean includeDeleted)
|
public Lookup lookup(int version, String path, boolean write, boolean includeDeleted)
|
||||||
{
|
{
|
||||||
// Make up a Lookup to hold the results.
|
SimplePath sPath = new SimplePath(path);
|
||||||
Lookup result = new Lookup(this, fName);
|
return RawServices.Instance().getLookupCache().lookup(this, version, sPath, write, includeDeleted);
|
||||||
if (path.length() == 0)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
while (path.startsWith("/"))
|
|
||||||
{
|
|
||||||
path = path.substring(1);
|
|
||||||
}
|
|
||||||
while (path.endsWith("/"))
|
|
||||||
{
|
|
||||||
path = path.substring(0, path.length() - 1);
|
|
||||||
}
|
|
||||||
String[] pathElements = path.split("/+");
|
|
||||||
// Grab the root node to start the lookup.
|
|
||||||
DirectoryNode dir = null;
|
|
||||||
// Versions less than 0 mean get current.
|
|
||||||
if (version < 0)
|
|
||||||
{
|
|
||||||
dir = fRoot;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dir = AVMDAOs.Instance().fAVMNodeDAO.getAVMStoreRoot(this, version);
|
|
||||||
}
|
|
||||||
if (dir == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// Add an entry for the root.
|
|
||||||
result.add(dir, "", write);
|
|
||||||
dir = (DirectoryNode)result.getCurrentNode();
|
|
||||||
if (pathElements.length == 1 && pathElements[0].equals(""))
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
// Now look up each path element in sequence up to one
|
|
||||||
// before the end.
|
|
||||||
for (int i = 0; i < pathElements.length - 1; i++)
|
|
||||||
{
|
|
||||||
AVMNode child = dir.lookupChild(result, pathElements[i], includeDeleted);
|
|
||||||
if (child == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// Every element that is not the last needs to be a directory.
|
|
||||||
if (child.getType() != AVMNodeType.PLAIN_DIRECTORY &&
|
|
||||||
child.getType() != AVMNodeType.LAYERED_DIRECTORY)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
result.add(child, pathElements[i], write);
|
|
||||||
dir = (DirectoryNode)result.getCurrentNode();
|
|
||||||
}
|
|
||||||
// Now look up the last element.
|
|
||||||
AVMNode child = dir.lookupChild(result, pathElements[pathElements.length - 1],
|
|
||||||
includeDeleted);
|
|
||||||
if (child == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
result.add(child, pathElements[pathElements.length - 1], write);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
94
source/java/org/alfresco/repo/avm/LookupCache.java
Normal file
94
source/java/org/alfresco/repo/avm/LookupCache.java
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.avm;
|
||||||
|
|
||||||
|
import org.alfresco.repo.avm.util.SimplePath;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All lookup traffic goes through here.
|
||||||
|
* @author britt
|
||||||
|
*/
|
||||||
|
public class LookupCache
|
||||||
|
{
|
||||||
|
private static Logger fgLogger = Logger.getLogger(LookupCache.class);
|
||||||
|
|
||||||
|
private AVMNodeDAO fAVMNodeDAO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make one up.
|
||||||
|
*/
|
||||||
|
public LookupCache()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the node dao.
|
||||||
|
* @param dao The dao to set.
|
||||||
|
*/
|
||||||
|
public void setAvmNodeDAO(AVMNodeDAO dao)
|
||||||
|
{
|
||||||
|
fAVMNodeDAO = dao;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Lookup lookup(AVMStore store, int version, SimplePath path,
|
||||||
|
boolean write, boolean includeDeleted)
|
||||||
|
{
|
||||||
|
// Make up a Lookup to hold the results.
|
||||||
|
if (path.size() == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Lookup result = new Lookup(store, store.getName());
|
||||||
|
// Grab the root node to start the lookup.
|
||||||
|
DirectoryNode dir = null;
|
||||||
|
// Versions less than 0 mean get current.
|
||||||
|
if (version < 0)
|
||||||
|
{
|
||||||
|
dir = store.getRoot();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dir = fAVMNodeDAO.getAVMStoreRoot(store, version);
|
||||||
|
}
|
||||||
|
if (dir == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Add an entry for the root.
|
||||||
|
result.add(dir, "", write);
|
||||||
|
dir = (DirectoryNode)result.getCurrentNode();
|
||||||
|
if (path.size() == 1 && path.get(0).equals(""))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
// Now look up each path element in sequence up to one
|
||||||
|
// before the end.
|
||||||
|
for (int i = 0; i < path.size() - 1; i++)
|
||||||
|
{
|
||||||
|
AVMNode child = dir.lookupChild(result, path.get(i), includeDeleted);
|
||||||
|
if (child == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Every element that is not the last needs to be a directory.
|
||||||
|
if (child.getType() != AVMNodeType.PLAIN_DIRECTORY &&
|
||||||
|
child.getType() != AVMNodeType.LAYERED_DIRECTORY)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
result.add(child, path.get(i), write);
|
||||||
|
dir = (DirectoryNode)result.getCurrentNode();
|
||||||
|
}
|
||||||
|
// Now look up the last element.
|
||||||
|
AVMNode child = dir.lookupChild(result, path.get(path.size() - 1),
|
||||||
|
includeDeleted);
|
||||||
|
if (child == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
result.add(child, path.get(path.size() - 1), write);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.avm.util;
|
package org.alfresco.repo.avm.util;
|
||||||
|
|
||||||
|
import org.alfresco.repo.avm.LookupCache;
|
||||||
import org.alfresco.repo.content.ContentStore;
|
import org.alfresco.repo.content.ContentStore;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
@@ -52,6 +53,11 @@ public class RawServices implements ApplicationContextAware
|
|||||||
*/
|
*/
|
||||||
private ContentStore fContentStore;
|
private ContentStore fContentStore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The LookupCache.
|
||||||
|
*/
|
||||||
|
private LookupCache fLookupCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
@@ -120,6 +126,15 @@ public class RawServices implements ApplicationContextAware
|
|||||||
return fContentStore;
|
return fContentStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LookupCache getLookupCache()
|
||||||
|
{
|
||||||
|
if (fLookupCache == null)
|
||||||
|
{
|
||||||
|
fLookupCache = (LookupCache)fContext.getBean("lookupCache");
|
||||||
|
}
|
||||||
|
return fLookupCache;
|
||||||
|
}
|
||||||
|
|
||||||
public ApplicationContext getContext()
|
public ApplicationContext getContext()
|
||||||
{
|
{
|
||||||
return fContext;
|
return fContext;
|
||||||
|
115
source/java/org/alfresco/repo/avm/util/SimplePath.java
Normal file
115
source/java/org/alfresco/repo/avm/util/SimplePath.java
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.avm.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds a simple path.
|
||||||
|
* @author britt
|
||||||
|
*/
|
||||||
|
public class SimplePath
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The names of the path's components.
|
||||||
|
*/
|
||||||
|
private String [] fNames;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new one from a string.
|
||||||
|
* @param path The String representation of the path.
|
||||||
|
*/
|
||||||
|
public SimplePath(String path)
|
||||||
|
{
|
||||||
|
if (path.length() == 0)
|
||||||
|
{
|
||||||
|
fNames = new String[0];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while (path.startsWith("/"))
|
||||||
|
{
|
||||||
|
path = path.substring(1);
|
||||||
|
}
|
||||||
|
while (path.endsWith("/"))
|
||||||
|
{
|
||||||
|
path = path.substring(0, path.length() - 1);
|
||||||
|
}
|
||||||
|
fNames = path.split("/+");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the component name at index.
|
||||||
|
* @param index The index of the component to get.
|
||||||
|
* @return The name of the component.
|
||||||
|
*/
|
||||||
|
public String get(int index)
|
||||||
|
{
|
||||||
|
return fNames[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of components in this path.
|
||||||
|
* @return The number of components.
|
||||||
|
*/
|
||||||
|
public int size()
|
||||||
|
{
|
||||||
|
return fNames.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj)
|
||||||
|
{
|
||||||
|
if (this == obj)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(obj instanceof SimplePath))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SimplePath o = (SimplePath)obj;
|
||||||
|
if (fNames.length != o.fNames.length)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < fNames.length; i++)
|
||||||
|
{
|
||||||
|
if (!fNames[i].equals(o.fNames[i]))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#hashCode()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
int hash = 0;
|
||||||
|
for (String name : fNames)
|
||||||
|
{
|
||||||
|
hash += name.hashCode();
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Object#toString()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (String name : fNames)
|
||||||
|
{
|
||||||
|
builder.append('/');
|
||||||
|
builder.append(name);
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user