com.atlassian.crowd.model.token
Class TokenDAOProxy

java.lang.Object
  extended by com.atlassian.crowd.model.token.TokenDAOProxy
All Implemented Interfaces:
TokenDAO, ObjectDao, java.util.EventListener, org.springframework.context.ApplicationListener

public class TokenDAOProxy
extends java.lang.Object
implements TokenDAO, org.springframework.context.ApplicationListener

Proxies the concrete TokenDAO implementations, and allows runtime swapping between implementations, along with copying of data between during swap.


Constructor Summary
TokenDAOProxy(boolean initialUseIsMemory, TokenDAOPersistence daoMemory, TokenDAOPersistence daoHibernate, PropertyManager propertyManager)
           
TokenDAOProxy(TokenDAOPersistence daoMemory, TokenDAOPersistence daoHibernate, PropertyManager propertyManager)
           
 
Method Summary
 Token add(Token token)
           
 Token findByID(long ID)
           
 Token findByIdentifierHash(java.lang.String identifierHash)
           
 Token findByRandomHash(java.lang.String randomHash)
           
 java.lang.Class getPersistentClass()
          The class that is being persisted
 boolean isUsingHibernateDAO()
          Returns true if the memory token manager is in use.
 java.lang.Object load(long ID)
          Loads a persistnce DAO object from the persistence store.
protected  void move(TokenDAOPersistence to, TokenDAOPersistence from)
          Copies tokens from hibernate to in-memory DAO or vice versa, and upon success deletes the tokens from the source.
 void onApplicationEvent(org.springframework.context.ApplicationEvent event)
          On the application stated event, change to the correct token storage that has been stored in the database
 void remove(long directoryID, java.lang.String name)
           
 void remove(java.lang.Object persistentObject)
          Removes the DAO object from the persistence store.
 void remove(Token token)
           
 void removeAccessedBefore(java.util.Date expiryTime)
           
 void removeAll()
          Removes all tokens from all implementations.
 void removeAll(long directoryId)
           
 void save(java.lang.Object persistentObject)
          Saves a new DAO object to the persistence store.
 java.util.List<Token> search(EntityQuery query)
           
 void setUsingDatabaseStorage(boolean useDatabaseStorage)
          Performs the switch, if necessary.
 void switchToHibernate()
          If the In-memory DAO is in use, transparently switches to Hibernate DAO.
 void switchToMemory()
          If the Hibernate DAO is in use, transparently switches to In-memory DAO.
 void update(java.lang.Object persistentObject)
          Updates an existing DAO object, if the object does not exist it will be added to the persistence store.
 Token update(Token token)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TokenDAOProxy

public TokenDAOProxy(boolean initialUseIsMemory,
                     TokenDAOPersistence daoMemory,
                     TokenDAOPersistence daoHibernate,
                     PropertyManager propertyManager)

TokenDAOProxy

public TokenDAOProxy(TokenDAOPersistence daoMemory,
                     TokenDAOPersistence daoHibernate,
                     PropertyManager propertyManager)
Method Detail

findByRandomHash

public Token findByRandomHash(java.lang.String randomHash)
                       throws org.springframework.dao.DataAccessException,
                              ObjectNotFoundException
Specified by:
findByRandomHash in interface TokenDAO
Throws:
org.springframework.dao.DataAccessException
ObjectNotFoundException

findByIdentifierHash

public Token findByIdentifierHash(java.lang.String identifierHash)
                           throws ObjectNotFoundException
Specified by:
findByIdentifierHash in interface TokenDAO
Throws:
ObjectNotFoundException

add

public Token add(Token token)
          throws org.springframework.dao.DataAccessException
Specified by:
add in interface TokenDAO
Throws:
org.springframework.dao.DataAccessException

update

public Token update(Token token)
             throws ObjectNotFoundException
Specified by:
update in interface TokenDAO
Parameters:
token - token to update.
Returns:
updates the last accessed date on the token (sets it to now).
Throws:
ObjectNotFoundException

remove

public void remove(Token token)
            throws org.springframework.dao.DataAccessException
Specified by:
remove in interface TokenDAO
Throws:
org.springframework.dao.DataAccessException

search

public java.util.List<Token> search(EntityQuery query)
Specified by:
search in interface TokenDAO

findByID

public Token findByID(long ID)
               throws org.springframework.dao.DataAccessException,
                      ObjectNotFoundException
Specified by:
findByID in interface TokenDAO
Throws:
org.springframework.dao.DataAccessException
ObjectNotFoundException

remove

public void remove(long directoryID,
                   java.lang.String name)
            throws org.springframework.dao.DataAccessException
Specified by:
remove in interface TokenDAO
Throws:
org.springframework.dao.DataAccessException

removeAll

public void removeAll(long directoryId)
Specified by:
removeAll in interface TokenDAO

removeAccessedBefore

public void removeAccessedBefore(java.util.Date expiryTime)
Specified by:
removeAccessedBefore in interface TokenDAO

removeAll

public void removeAll()
Removes all tokens from all implementations.

Specified by:
removeAll in interface TokenDAO

getPersistentClass

public java.lang.Class getPersistentClass()
Description copied from interface: ObjectDao
The class that is being persisted

Specified by:
getPersistentClass in interface ObjectDao
Returns:
Class

save

public void save(java.lang.Object persistentObject)
          throws org.springframework.dao.DataAccessException
Description copied from interface: ObjectDao
Saves a new DAO object to the persistence store.

Specified by:
save in interface ObjectDao
Parameters:
persistentObject - The object to save.
Throws:
org.springframework.dao.DataAccessException - A persistence exception has occurred.

update

public void update(java.lang.Object persistentObject)
            throws org.springframework.dao.DataAccessException
Description copied from interface: ObjectDao
Updates an existing DAO object, if the object does not exist it will be added to the persistence store.

Specified by:
update in interface ObjectDao
Parameters:
persistentObject - The object to update.
Throws:
org.springframework.dao.DataAccessException - A persistence exception has occurred.

remove

public void remove(java.lang.Object persistentObject)
            throws org.springframework.dao.DataAccessException
Description copied from interface: ObjectDao
Removes the DAO object from the persistence store.

Specified by:
remove in interface ObjectDao
Parameters:
persistentObject - The object to remove.
Throws:
org.springframework.dao.DataAccessException - A persistence exception has occurred.

load

public java.lang.Object load(long ID)
                      throws ObjectNotFoundException
Description copied from interface: ObjectDao
Loads a persistnce DAO object from the persistence store.

Specified by:
load in interface ObjectDao
Parameters:
ID - The unique identifier of the object to load from the persistence store.
Returns:
Object The populated object from the database
Throws:
ObjectNotFoundException - if the given object with ID for the persistent class does not exist

isUsingHibernateDAO

public boolean isUsingHibernateDAO()
Returns true if the memory token manager is in use. False if the Hibernate manager is being used.

Returns:

setUsingDatabaseStorage

public void setUsingDatabaseStorage(boolean useDatabaseStorage)
                             throws PropertyManagerException
Performs the switch, if necessary.

Parameters:
useDatabaseStorage -
Throws:
PropertyManagerException

switchToMemory

public void switchToMemory()
If the Hibernate DAO is in use, transparently switches to In-memory DAO. Does nothing if the In-memory DAO is already in use. Acquires write lock for safety.


switchToHibernate

public void switchToHibernate()
If the In-memory DAO is in use, transparently switches to Hibernate DAO. Does nothing if the hibernate DAO is already in use. Acquires write lock for safety.


move

protected void move(TokenDAOPersistence to,
                    TokenDAOPersistence from)
Copies tokens from hibernate to in-memory DAO or vice versa, and upon success deletes the tokens from the source. Acquires write lock, so make sure the lock you use is reentrant!


onApplicationEvent

public void onApplicationEvent(org.springframework.context.ApplicationEvent event)
On the application stated event, change to the correct token storage that has been stored in the database

Specified by:
onApplicationEvent in interface org.springframework.context.ApplicationListener
Parameters:
event -


Copyright © 2009 Atlassian Pty Ltd. All Rights Reserved.