mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Dictionary optimisation: improve performance when getting sub classes and property defs
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6825 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -126,6 +126,15 @@ public class DictionaryComponent implements DictionaryService, TenantDeployer
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.dictionary.DictionaryService#getSubTypes(org.alfresco.service.namespace.QName, boolean)
|
||||
*/
|
||||
public Collection<QName> getSubTypes(QName superType, boolean follow)
|
||||
{
|
||||
return dictionaryDAO.getSubTypes(superType, follow);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getTypes(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
@@ -155,6 +164,15 @@ public class DictionaryComponent implements DictionaryService, TenantDeployer
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.dictionary.DictionaryService#getSubAspects(org.alfresco.service.namespace.QName, boolean)
|
||||
*/
|
||||
public Collection<QName> getSubAspects(QName superAspect, boolean follow)
|
||||
{
|
||||
return dictionaryDAO.getSubAspects(superAspect, follow);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryService#getAspects(org.alfresco.repo.ref.QName)
|
||||
*/
|
||||
@@ -278,6 +296,19 @@ public class DictionaryComponent implements DictionaryService, TenantDeployer
|
||||
}
|
||||
return propDef;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.dictionary.DictionaryService#getPropertyDefs(org.alfresco.service.namespace.QName)
|
||||
*/
|
||||
public Map<QName,PropertyDefinition> getPropertyDefs(QName className)
|
||||
{
|
||||
ClassDefinition classDef = dictionaryDAO.getClass(className);
|
||||
if (classDef != null)
|
||||
{
|
||||
return classDef.getProperties();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@@ -65,12 +65,26 @@ public interface DictionaryDAO extends ModelQuery
|
||||
* @return the types of the model
|
||||
*/
|
||||
public Collection<TypeDefinition> getTypes(QName model);
|
||||
|
||||
/**
|
||||
* @param superType
|
||||
* @param follow true => follow up the super-class hierarchy, false => immediate sub types only
|
||||
* @return
|
||||
*/
|
||||
public Collection<QName> getSubTypes(QName superType, boolean follow);
|
||||
|
||||
/**
|
||||
* @param model the model to retrieve aspects for
|
||||
* @return the aspects of the model
|
||||
*/
|
||||
public Collection<AspectDefinition> getAspects(QName model);
|
||||
|
||||
/**
|
||||
* @param superAspect
|
||||
* @param follow true => follow up the super-class hierarchy, false => immediate sub aspects only
|
||||
* @return
|
||||
*/
|
||||
public Collection<QName> getSubAspects(QName superAspect, boolean follow);
|
||||
|
||||
/**
|
||||
* @param model the model for which to get properties for
|
||||
|
@@ -511,6 +511,54 @@ public class DictionaryDAOImpl implements DictionaryDAO
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryDAO#getSubTypes(org.alfresco.service.namespace.QName, boolean)
|
||||
*/
|
||||
public Collection<QName> getSubTypes(QName superType, boolean follow)
|
||||
{
|
||||
// note: could be optimised further, if compiled into the model
|
||||
|
||||
// Get all types (with parent type) for all models
|
||||
Map<QName, QName> allTypesAndParents = new HashMap<QName, QName>(); // name, parent
|
||||
|
||||
for (CompiledModel model : getCompiledModels().values())
|
||||
{
|
||||
for (TypeDefinition type : model.getTypes())
|
||||
{
|
||||
allTypesAndParents.put(type.getName(), type.getParentName());
|
||||
}
|
||||
}
|
||||
|
||||
// Get sub types
|
||||
HashSet<QName> subTypes = new HashSet<QName>();
|
||||
for (QName type : allTypesAndParents.keySet())
|
||||
{
|
||||
if (follow)
|
||||
{
|
||||
// all sub types
|
||||
QName current = type;
|
||||
while ((current != null) && !current.equals(superType))
|
||||
{
|
||||
current = allTypesAndParents.get(current); // get parent
|
||||
}
|
||||
if (current != null)
|
||||
{
|
||||
subTypes.add(type);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// immediate sub types only
|
||||
if (allTypesAndParents.get(type).equals(superType))
|
||||
{
|
||||
subTypes.add(type);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return subTypes;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -529,6 +577,53 @@ public class DictionaryDAOImpl implements DictionaryDAO
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.dictionary.DictionaryDAO#getSubAspects(org.alfresco.service.namespace.QName, boolean)
|
||||
*/
|
||||
public Collection<QName> getSubAspects(QName superAspect, boolean follow)
|
||||
{
|
||||
// note: could be optimised further, if compiled into the model
|
||||
|
||||
// Get all aspects (with parent aspect) for all models
|
||||
Map<QName, QName> allAspectsAndParents = new HashMap<QName, QName>(); // name, parent
|
||||
|
||||
for (CompiledModel model : getCompiledModels().values())
|
||||
{
|
||||
for (AspectDefinition aspect : model.getAspects())
|
||||
{
|
||||
allAspectsAndParents.put(aspect.getName(), aspect.getParentName());
|
||||
}
|
||||
}
|
||||
|
||||
// Get sub aspects
|
||||
HashSet<QName> subAspects = new HashSet<QName>();
|
||||
for (QName aspect : allAspectsAndParents.keySet())
|
||||
{
|
||||
if (follow)
|
||||
{
|
||||
// all sub aspects
|
||||
QName current = aspect;
|
||||
while ((current != null) && !current.equals(superAspect))
|
||||
{
|
||||
current = allAspectsAndParents.get(current); // get parent
|
||||
}
|
||||
if (current != null)
|
||||
{
|
||||
subAspects.add(aspect);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// immediate sub aspects only
|
||||
if (allAspectsAndParents.get(aspect).equals(superAspect))
|
||||
{
|
||||
subAspects.add(aspect);
|
||||
}
|
||||
}
|
||||
}
|
||||
return subAspects;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -608,34 +703,32 @@ public class DictionaryDAOImpl implements DictionaryDAO
|
||||
* @see org.alfresco.repo.dictionary.impl.DictionaryDAO#getModels()
|
||||
*/
|
||||
public Collection<QName> getModels()
|
||||
{
|
||||
return getCompiledModels().keySet();
|
||||
}
|
||||
|
||||
// return all tenant-specific models and all shared (non-overridden) models
|
||||
private Map<QName,CompiledModel> getCompiledModels()
|
||||
{
|
||||
String tenantDomain = tenantService.getCurrentUserDomain();
|
||||
if (tenantDomain != "")
|
||||
{
|
||||
// return all tenant-specific models and all shared (non-overridden) models
|
||||
Collection<QName> filteredModels = new ArrayList<QName>();
|
||||
Collection<QName> tenantModels = new ArrayList<QName>();
|
||||
Collection<QName> nontenantModels = new ArrayList<QName>();
|
||||
|
||||
Map<QName, CompiledModel> filteredModels = new HashMap<QName, CompiledModel>();
|
||||
|
||||
// get tenant models (if any)
|
||||
for (QName key : getCompiledModels(tenantDomain).keySet())
|
||||
{
|
||||
tenantModels.add(key);
|
||||
}
|
||||
Map<QName,CompiledModel> tenantModels = getCompiledModels(tenantDomain);
|
||||
|
||||
// get non-tenant models (if any)
|
||||
// note: these will be shared, if not overridden - could be core/system model or additional custom model shared between tenants
|
||||
for (QName key : getCompiledModels("").keySet())
|
||||
{
|
||||
nontenantModels.add(key);
|
||||
}
|
||||
Map<QName,CompiledModel> nontenantModels = getCompiledModels("");
|
||||
|
||||
// check for overrides
|
||||
filteredModels.addAll(nontenantModels);
|
||||
|
||||
for (QName tenantModel : tenantModels)
|
||||
filteredModels.putAll(nontenantModels);
|
||||
|
||||
for (QName tenantModel : tenantModels.keySet())
|
||||
{
|
||||
for (QName nontenantModel : nontenantModels)
|
||||
for (QName nontenantModel : nontenantModels.keySet())
|
||||
{
|
||||
if (tenantModel.equals(nontenantModel))
|
||||
{
|
||||
@@ -646,12 +739,12 @@ public class DictionaryDAOImpl implements DictionaryDAO
|
||||
}
|
||||
}
|
||||
|
||||
filteredModels.addAll(tenantModels);
|
||||
filteredModels.putAll(tenantModels);
|
||||
return filteredModels;
|
||||
}
|
||||
else
|
||||
{
|
||||
return getCompiledModels("").keySet();
|
||||
return getCompiledModels("");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user