From 24792204ba4eadbb51ed6d13348a0bb1637992e0 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Tue, 20 Oct 2009 13:48:04 +0000 Subject: [PATCH] Minor collection size tweaks, removal of unused oncreate node policy handler, cleanup. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@17046 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../security/authority/AuthorityDAOImpl.java | 38 ++++++------------- .../authority/AuthorityServiceImpl.java | 2 +- .../impl/PermissionServiceImpl.java | 5 +-- 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java b/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java index 2e8720aeeb..fc7b15d3fe 100644 --- a/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java +++ b/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java @@ -60,8 +60,7 @@ import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.util.EqualsHelper; import org.alfresco.util.SearchLanguageConversion; -public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.OnCreateNodePolicy, NodeServicePolicies.BeforeDeleteNodePolicy, - NodeServicePolicies.OnUpdatePropertiesPolicy +public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.BeforeDeleteNodePolicy, NodeServicePolicies.OnUpdatePropertiesPolicy { private StoreRef storeRef; @@ -81,16 +80,16 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.OnCre private TenantService tenantService; - private SimpleCache> authorityLookupCache; + private SimpleCache> authorityLookupCache; /** System Container ref cache (Tennant aware) */ private Map systemContainerRefs = new ConcurrentHashMap(4); - private AclDaoComponent aclDao; private PolicyComponent policyComponent; + public AuthorityDAOImpl() { super(); @@ -119,7 +118,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.OnCre this.nodeService = nodeService; } - public void setUserToAuthorityCache(SimpleCache> userToAuthorityCache) + public void setUserToAuthorityCache(SimpleCache> userToAuthorityCache) { this.authorityLookupCache = userToAuthorityCache; } @@ -287,11 +286,12 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.OnCre CacheKey key = new CacheKey(type, name, tenantService.getCurrentUserDomain(), false, !immediate); - HashSet authorities = authorityLookupCache.get(key); + Set authorities = authorityLookupCache.get(key); if (authorities == null) { - authorities = new HashSet(); + authorities = new HashSet(64); findAuthorities(type, null, nodeRef, authorities, false, !immediate, false); + authorities = (Set)Collections.unmodifiableSet(authorities); authorityLookupCache.put(key, authorities); } return authorities; @@ -318,15 +318,15 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.OnCre { CacheKey key = new CacheKey(type, name, tenantService.getCurrentUserDomain(), true, !immediate); - HashSet authorities = authorityLookupCache.get(key); + Set authorities = authorityLookupCache.get(key); if (authorities == null) { - authorities = new HashSet(); + authorities = new HashSet(64); findAuthorities(type, name, authorities, true, !immediate); + authorities = (Set)Collections.unmodifiableSet(authorities); authorityLookupCache.put(key, authorities); } return authorities; - } private void addAuthorityNameIfMatches(Set authorities, String authorityName, AuthorityType type, Pattern pattern) @@ -659,7 +659,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.OnCre return Collections. emptySet(); } Collection childRefs = nodeService.getChildAssocsWithoutParentAssocsOfType(container, ContentModel.ASSOC_MEMBER); - Set authorities = new HashSet(childRefs.size() * 2); + Set authorities = new HashSet(childRefs.size() << 1); for (ChildAssociationRef childRef : childRefs) { addAuthorityNameIfMatches(authorities, childRef.getQName().getLocalName(), type, null); @@ -671,7 +671,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.OnCre /** * CacheKey class for getContainedAuthorities() parent Group cache. */ - private static class CacheKey implements Serializable + private final static class CacheKey implements Serializable { private static final long serialVersionUID = -3787608436067567757L; @@ -741,16 +741,6 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.OnCre } } - public void onCreateNode(ChildAssociationRef childAssocRef) - { - NodeRef authRef = childAssocRef.getChildRef(); - String authority = (String) this.nodeService.getProperty(authRef, ContentModel.PROP_AUTHORITY_NAME); - - // Make sure there is an authority entry - with a DB constraint for uniqueness - // aclDao.createAuthority(authority); - - } - public void beforeDeleteNode(NodeRef nodeRef) { authorityLookupCache.clear(); @@ -779,17 +769,13 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.OnCre throw new UnsupportedOperationException("The name of an authority can not be changed"); } } - } public void init() { - this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"), ContentModel.TYPE_AUTHORITY_CONTAINER, new JavaBehaviour(this, - "onCreateNode")); this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"), ContentModel.TYPE_AUTHORITY_CONTAINER, new JavaBehaviour( this, "beforeDeleteNode")); this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"), ContentModel.TYPE_AUTHORITY_CONTAINER, new JavaBehaviour( this, "onUpdateProperties")); } - } diff --git a/source/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java b/source/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java index c50be96ffb..f188ae3fbd 100644 --- a/source/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java +++ b/source/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java @@ -196,7 +196,7 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean public Set getAuthoritiesForUser(String currentUserName) { - Set authorities = new HashSet(); + Set authorities = new HashSet(64); authorities.addAll(getContainingAuthorities(null, currentUserName, false)); diff --git a/source/java/org/alfresco/repo/security/permissions/impl/PermissionServiceImpl.java b/source/java/org/alfresco/repo/security/permissions/impl/PermissionServiceImpl.java index 3b7fc0bb85..cf907eed7a 100644 --- a/source/java/org/alfresco/repo/security/permissions/impl/PermissionServiceImpl.java +++ b/source/java/org/alfresco/repo/security/permissions/impl/PermissionServiceImpl.java @@ -748,7 +748,7 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing private Set getDynamicAuthorities(Authentication auth, NodeRef nodeRef, PermissionReference required) { - HashSet auths = new HashSet(); + HashSet auths = new HashSet(64); if (auth == null) { @@ -824,7 +824,6 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing { permissionsDaoComponent.deletePermissions(storeRef, authority); accessCache.clear(); - } public void deletePermission(StoreRef storeRef, String authority, String perm) @@ -832,7 +831,6 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing deletePermission(storeRef, authority, getPermissionReference(perm)); } - private void deletePermission(StoreRef storeRef, String authority, PermissionReference perm) { permissionsDaoComponent.deletePermission(storeRef, authority, perm); @@ -843,7 +841,6 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing { permissionsDaoComponent.deletePermissions(storeRef); accessCache.clear(); - } public void setPermission(StoreRef storeRef, String authority, String perm, boolean allow)