From: Olivier Lamy Date: Sat, 5 Jan 2013 22:21:47 +0000 (+0000) Subject: use cache with generics X-Git-Tag: redback-2.1~143 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=201e8c291d21d78cc101742a468a244e28cc51a9;p=archiva.git use cache with generics git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1429404 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/redback-keys/redback-keys-providers/redback-keys-cached/src/main/java/org/apache/archiva/redback/keys/cached/CachedKeyManager.java b/redback-keys/redback-keys-providers/redback-keys-cached/src/main/java/org/apache/archiva/redback/keys/cached/CachedKeyManager.java index f1c49c644..c5db8b653 100644 --- a/redback-keys/redback-keys-providers/redback-keys-cached/src/main/java/org/apache/archiva/redback/keys/cached/CachedKeyManager.java +++ b/redback-keys/redback-keys-providers/redback-keys-cached/src/main/java/org/apache/archiva/redback/keys/cached/CachedKeyManager.java @@ -33,21 +33,22 @@ import org.apache.archiva.redback.keys.KeyNotFoundException; import org.springframework.stereotype.Service; /** - * CachedKeyManager + * CachedKeyManager * * @author Joakim Erdfelt - * */ @Service("keyManager#cached") public class CachedKeyManager extends AbstractKeyManager implements KeyManager { - @Inject @Named(value="keyManager#jdo") + @Inject + @Named(value = "keyManager#jdo") private KeyManager keyImpl; - @Inject @Named(value="cache#keys") - private Cache keysCache; + @Inject + @Named(value = "cache#keys") + private Cache keysCache; public AuthenticationKey addKey( AuthenticationKey key ) { @@ -97,7 +98,7 @@ public class CachedKeyManager { try { - AuthenticationKey authkey = (AuthenticationKey) keysCache.get( key ); + AuthenticationKey authkey = keysCache.get( key ); if ( authkey != null ) { assertNotExpired( authkey ); @@ -106,7 +107,7 @@ public class CachedKeyManager else { authkey = this.keyImpl.findKey( key ); - keysCache.put( key,authkey ); + keysCache.put( key, authkey ); return authkey; } } diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/main/java/org/apache/archiva/redback/rbac/cached/CachedRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/main/java/org/apache/archiva/redback/rbac/cached/CachedRbacManager.java index c131aef61..2faf3e0f2 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/main/java/org/apache/archiva/redback/rbac/cached/CachedRbacManager.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-cached/src/main/java/org/apache/archiva/redback/rbac/cached/CachedRbacManager.java @@ -59,31 +59,31 @@ public class CachedRbacManager @Inject @Named(value = "cache#operations") - private Cache operationsCache; + private Cache operationsCache; @Inject @Named(value = "cache#permissions") - private Cache permissionsCache; + private Cache permissionsCache; @Inject @Named(value = "cache#resources") - private Cache resourcesCache; + private Cache resourcesCache; @Inject @Named(value = "cache#roles") - private Cache rolesCache; + private Cache rolesCache; @Inject @Named(value = "cache#userAssignments") - private Cache userAssignmentsCache; + private Cache userAssignmentsCache; @Inject @Named(value = "cache#userPermissions") - private Cache userPermissionsCache; + private Cache>> userPermissionsCache; @Inject @Named(value = "cache#effectiveRoleSet") - private Cache effectiveRoleSetCache; + private Cache> effectiveRoleSetCache; public void addChildRole( Role role, Role childRole ) throws RbacObjectInvalidException, RbacManagerException @@ -210,7 +210,7 @@ public class CachedRbacManager public Map> getAssignedPermissionMap( String principal ) throws RbacObjectNotFoundException, RbacManagerException { - Map> el = (Map>) userPermissionsCache.get( principal ); + Map> el = userPermissionsCache.get( principal ); if ( el != null ) { @@ -278,7 +278,7 @@ public class CachedRbacManager public Set getEffectiveRoles( Role role ) throws RbacObjectNotFoundException, RbacManagerException { - Set el = (Set) effectiveRoleSetCache.get( role.getName() ); + Set el = effectiveRoleSetCache.get( role.getName() ); if ( el != null ) { @@ -305,10 +305,10 @@ public class CachedRbacManager public Operation getOperation( String operationName ) throws RbacObjectNotFoundException, RbacManagerException { - Object el = operationsCache.get( operationName ); + Operation el = operationsCache.get( operationName ); if ( el != null ) { - return (Operation) el; + return el; } else { @@ -321,10 +321,10 @@ public class CachedRbacManager public Permission getPermission( String permissionName ) throws RbacObjectNotFoundException, RbacManagerException { - Object el = permissionsCache.get( permissionName ); + Permission el = permissionsCache.get( permissionName ); if ( el != null ) { - return (Permission) el; + return el; } else { @@ -337,10 +337,10 @@ public class CachedRbacManager public Resource getResource( String resourceIdentifier ) throws RbacObjectNotFoundException, RbacManagerException { - Object el = resourcesCache.get( resourceIdentifier ); + Resource el = resourcesCache.get( resourceIdentifier ); if ( el != null ) { - return (Resource) el; + return el; } else { @@ -353,10 +353,10 @@ public class CachedRbacManager public Role getRole( String roleName ) throws RbacObjectNotFoundException, RbacManagerException { - Object el = rolesCache.get( roleName ); + Role el = rolesCache.get( roleName ); if ( el != null ) { - return (Role) el; + return el; } else { @@ -383,10 +383,10 @@ public class CachedRbacManager public UserAssignment getUserAssignment( String principal ) throws RbacObjectNotFoundException, RbacManagerException { - Object el = userAssignmentsCache.get( principal ); + UserAssignment el = userAssignmentsCache.get( principal ); if ( el != null ) { - return (UserAssignment) el; + return el; } else { diff --git a/redback-users/redback-users-providers/redback-users-cached/src/main/java/org/apache/archiva/redback/users/cached/CachedUserManager.java b/redback-users/redback-users-providers/redback-users-cached/src/main/java/org/apache/archiva/redback/users/cached/CachedUserManager.java index 82cfcb8a1..8e09fad76 100644 --- a/redback-users/redback-users-providers/redback-users-cached/src/main/java/org/apache/archiva/redback/users/cached/CachedUserManager.java +++ b/redback-users/redback-users-providers/redback-users-cached/src/main/java/org/apache/archiva/redback/users/cached/CachedUserManager.java @@ -39,7 +39,7 @@ import java.util.List; * * @author Joakim Erdfelt */ -@Service( "userManager#cached" ) +@Service("userManager#cached") public class CachedUserManager implements UserManager, UserManagerListener { @@ -47,12 +47,12 @@ public class CachedUserManager private Logger log = LoggerFactory.getLogger( getClass() ); @Inject - @Named( value = "userManager#configurable" ) + @Named(value = "userManager#configurable") private UserManager userImpl; @Inject - @Named( value = "cache#users" ) - private Cache usersCache; + @Named(value = "cache#users") + private Cache usersCache; public boolean isReadOnly() { @@ -124,10 +124,10 @@ public class CachedUserManager return getGuestUser(); } - Object el = usersCache.get( username ); + User el = usersCache.get( username ); if ( el != null ) { - return (User) el; + return el; } else { @@ -140,10 +140,10 @@ public class CachedUserManager public User getGuestUser() throws UserNotFoundException, UserManagerException { - Object el = usersCache.get( GUEST_USERNAME ); + User el = usersCache.get( GUEST_USERNAME ); if ( el != null ) { - return (User) el; + return el; } else { diff --git a/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/service/DefaultLdapCacheService.java b/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/service/DefaultLdapCacheService.java index 2802f8a07..4c8a65fbc 100644 --- a/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/service/DefaultLdapCacheService.java +++ b/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/service/DefaultLdapCacheService.java @@ -20,10 +20,11 @@ package org.apache.archiva.redback.users.ldap.service; */ import org.apache.archiva.redback.common.ldap.user.LdapUser; -import org.apache.archiva.redback.components.cache.builder.CacheBuilder; +import org.apache.archiva.redback.components.cache.Cache; import org.springframework.stereotype.Service; import javax.inject.Inject; +import javax.inject.Named; /** * DefaultLdapCacheService @@ -36,7 +37,14 @@ public class DefaultLdapCacheService implements LdapCacheService { @Inject - private CacheBuilder cacheBuilder; + @Named(value = "cache#ldapUser") + private Cache usersCache; + + @Inject + @Named(value = "cache#ldapUserDn") + private Cache ldapCacheDn; + + // LDAP Users @@ -45,7 +53,7 @@ public class DefaultLdapCacheService */ public LdapUser getUser( String username ) { - return (LdapUser) cacheBuilder.getCache( "ldapUser" ).get( username ); + return usersCache.get( username ); } /** @@ -53,7 +61,7 @@ public class DefaultLdapCacheService */ public boolean removeUser( String username ) { - return ( cacheBuilder.getCache( "ldapUser" ).remove( username ) == null ? false : true ); + return ( usersCache.remove( username ) == null ? false : true ); } /** @@ -61,7 +69,7 @@ public class DefaultLdapCacheService */ public void removeAllUsers() { - cacheBuilder.getCache( "ldapUser" ).clear(); + usersCache.clear(); } /** @@ -69,13 +77,13 @@ public class DefaultLdapCacheService */ public void addUser( LdapUser user ) { - LdapUser existingUser = (LdapUser) cacheBuilder.getCache( "ldapUser" ).get( user.getUsername() ); + LdapUser existingUser = usersCache.get( user.getUsername() ); if( existingUser != null ) { removeUser( user.getUsername() ); } - cacheBuilder.getCache( "ldapUser" ).put( user.getUsername(), user ); + usersCache.put( user.getUsername(), user ); } // LDAP UserDn @@ -85,7 +93,7 @@ public class DefaultLdapCacheService */ public String getLdapUserDn( String username ) { - return (String) cacheBuilder.getCache( "ldapUserDn" ).get( username ); + return ldapCacheDn.get( username ); } /** @@ -93,7 +101,7 @@ public class DefaultLdapCacheService */ public boolean removeLdapUserDn( String username ) { - return ( cacheBuilder.getCache( "ldapUserDn" ).remove( username ) == null ? false : true ); + return ( ldapCacheDn.remove( username ) == null ? false : true ); } /** @@ -101,7 +109,7 @@ public class DefaultLdapCacheService */ public void removeAllLdapUserDn() { - cacheBuilder.getCache( "ldapUserDn" ).clear(); + ldapCacheDn.clear(); } /** @@ -109,13 +117,13 @@ public class DefaultLdapCacheService */ public void addLdapUserDn( String username, String userDn ) { - String existingUserDn = (String) cacheBuilder.getCache( "ldapUserDn" ).get( username ); + String existingUserDn = ldapCacheDn.get( username ); if( existingUserDn != null ) { removeUser( username ); } - cacheBuilder.getCache( "ldapUserDn" ).put( username, userDn ); + ldapCacheDn.put( username, userDn ); } }