com.atlassian.jira.bc.project.component
Class CachingProjectComponentStore

java.lang.Object
  extended by com.atlassian.jira.bc.project.component.CachingProjectComponentStore
All Implemented Interfaces:
ProjectComponentStore

public class CachingProjectComponentStore
extends Object
implements ProjectComponentStore

Decorates an implementation of the project component delegateStore with caching. The actual delegateStore implementation is delegated so this class is a Composite and also a Decorator.


Constructor Summary
CachingProjectComponentStore(ProjectComponentStore delegateStore, com.atlassian.cache.CacheManager cacheManager)
          Creates a new instance of this class backed by given delegateStore.
 
Method Summary
 boolean containsName(String name, Long projectId)
          Checks whether component with specified name is stored.
 void delete(Long componentId)
          Removes the component from the persistent storage and a cache.
 MutableProjectComponent find(Long id)
          Looks up the project component by the given ID and returns it.
 Collection findAll()
          Retrieve all ProjectComponent objects stored.
 Collection<MutableProjectComponent> findAllForProject(Long projectId)
          Looks up all components that are related to the project with given ID.
 MutableProjectComponent findByComponentName(Long projectId, String componentName)
          Looks up the component with the given name in the project with the given id.
 Collection<MutableProjectComponent> findByComponentNameCaseInSensitive(String componentName)
          Finds one or more ProjectComponent with a given name.
 Collection findComponentsBylead(String userKey)
          Retrieves all ProjectComponents that have the given user as their lead.
 Long findProjectIdForComponent(Long componentId)
          Looks up the project ID for the given component ID.
 void onClearCache(ClearCacheEvent event)
           
 MutableProjectComponent store(MutableProjectComponent component)
          Persist the component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingProjectComponentStore

public CachingProjectComponentStore(ProjectComponentStore delegateStore,
                                    com.atlassian.cache.CacheManager cacheManager)
Creates a new instance of this class backed by given delegateStore. Initialises the cache with the data in the persistence store.

Parameters:
delegateStore - underlying persistence store
Method Detail

onClearCache

@EventListener
public void onClearCache(ClearCacheEvent event)

find

public MutableProjectComponent find(Long id)
                             throws EntityNotFoundException
Looks up the project component by the given ID and returns it. If not found, throws the EntityNotFoundException, it never returns null.

Specified by:
find in interface ProjectComponentStore
Parameters:
id - project component ID
Returns:
project component found by a given ID
Throws:
EntityNotFoundException - if the component not found

findAllForProject

public Collection<MutableProjectComponent> findAllForProject(Long projectId)
Looks up all components that are related to the project with given ID.

Specified by:
findAllForProject in interface ProjectComponentStore
Parameters:
projectId - project ID
Returns:
a collection of ProjectComponent objects that are related to the project with given ID

findByComponentName

public MutableProjectComponent findByComponentName(Long projectId,
                                                   String componentName)
                                            throws EntityNotFoundException
Looks up the component with the given name in the project with the given id.

Specified by:
findByComponentName in interface ProjectComponentStore
Parameters:
projectId - id of the project.
componentName - name of the component.
Returns:
the component.
Throws:
EntityNotFoundException - if no such component can be found.

findByComponentNameCaseInSensitive

public Collection<MutableProjectComponent> findByComponentNameCaseInSensitive(String componentName)
Finds one or more ProjectComponent with a given name.

Specified by:
findByComponentNameCaseInSensitive in interface ProjectComponentStore
Parameters:
componentName - the name of the component to find.
Returns:
a Collection of Components with the given name.
Throws:
EntityNotFoundException

findProjectIdForComponent

public Long findProjectIdForComponent(Long componentId)
                               throws EntityNotFoundException
Looks up the project ID for the given component ID. If project is not found, throws EntityNotFoundException.

Specified by:
findProjectIdForComponent in interface ProjectComponentStore
Parameters:
componentId - component ID
Returns:
project ID
Throws:
EntityNotFoundException - if project not found for the given component ID

containsName

public boolean containsName(String name,
                            Long projectId)
Checks whether component with specified name is stored.

Specified by:
containsName in interface ProjectComponentStore
Parameters:
name - component name, null will cause IllegalArgumentException
Returns:
true if new name is stored
Throws:
IllegalArgumentException - if name or projectId is null

store

public MutableProjectComponent store(MutableProjectComponent component)
                              throws EntityNotFoundException,
                                     DataAccessException
Persist the component. If component has no ID (null) it is inserted to the database and added to the cache, otherwise an update operation is performed on both cache and database.

Specified by:
store in interface ProjectComponentStore
Parameters:
component - component to persist
Throws:
EntityNotFoundException - in case of update if the component does not exist (maybe was deleted :-)
DataAccessException - if cannot persist the component

delete

public void delete(Long componentId)
            throws EntityNotFoundException
Removes the component from the persistent storage and a cache.

Specified by:
delete in interface ProjectComponentStore
Parameters:
componentId - the id of the component to delete
Throws:
EntityNotFoundException - if component does not exist (maybe was removed previously :-)

findComponentsBylead

public Collection findComponentsBylead(String userKey)
Retrieves all ProjectComponents that have the given user as their lead. Not synchronised, because findAll() returns a private copy of all components.

Specified by:
findComponentsBylead in interface ProjectComponentStore
Parameters:
userKey - key of the lead user
Returns:
possibly empty Collection of ProjectComponents.

findAll

public Collection findAll()
Retrieve all ProjectComponent objects stored.

Specified by:
findAll in interface ProjectComponentStore
Returns:
all ProjectComponent objects stored


Copyright © 2002-2014 Atlassian. All Rights Reserved.