org.jasig.portal.concurrency.caching
Class RDBMCachedEntityInvalidationStore

java.lang.Object
  extended by org.jasig.portal.concurrency.caching.RDBMCachedEntityInvalidationStore

public class RDBMCachedEntityInvalidationStore
extends java.lang.Object

RDBMS-based store for CachedEntityInvalidations.

Version:
$Revision: 1.22 $
Author:
Dan Ellentuck
See Also:
CachedEntityInvalidation, IEntityCache

Field Summary
private static java.lang.String addSql
           
private static java.lang.String allTableColumns
           
private static java.lang.String ENTITY_CACHE_ID_COLUMN
           
private static java.lang.String ENTITY_INVALIDATION_TABLE
           
private static java.lang.String ENTITY_KEY_COLUMN
           
private static java.lang.String ENTITY_TYPE_COLUMN
           
private static java.lang.String EQ
           
private static java.lang.String GT
           
private static java.lang.String INVALIDATION_TIME_COLUMN
           
private static org.apache.commons.logging.Log log
           
private static java.lang.String LT
           
private static java.lang.String NE
           
private static java.lang.String QUOTE
           
private static RDBMCachedEntityInvalidationStore singleton
           
private static boolean timestampHasMillis
           
private static java.lang.String updateSql
           
 
Constructor Summary
RDBMCachedEntityInvalidationStore()
          RDBMCachedEntityInvalidationStore constructor.
 
Method Summary
 void add(CachedEntityInvalidation cachedEnt)
          Adds/updates the row corresponding to this invalidation in the underlying store.
 void add(IBasicEntity entity, int cacheID)
          Adds/updates the row corresponding to this entity in the underlying store.
 void deleteAll()
          Delete all invalidations from the underlying store.
 void deleteBefore(java.util.Date expiration)
          Delete invalid entities the underlying store whose invalidation time is before invalidation.
private  boolean existsInStore(CachedEntityInvalidation ent, java.sql.Connection conn)
          Answers if this entity is represented in the store.
 CachedEntityInvalidation[] find(java.lang.Class entityType, java.lang.String entityKey)
          Retrieve CachedEntityInvalidations from the underlying entity invalidation store.
 CachedEntityInvalidation[] findAfter(java.util.Date invalidation, java.lang.Class entityType, java.lang.String entityKey, java.lang.Integer cacheID)
          Retrieve CachedEntityInvalidations from the underlying store.
private static java.lang.String getAddSql()
          SQL for inserting a row into the invalid entities table.
private static java.lang.String getAllTableColumns()
           
private static java.lang.String getDeleteInvalidationsSql()
          SQL for deleting old invalid entity rows.
private static java.lang.String getSelectInvalidationsByTypeSql()
           
private static java.lang.String getSelectSql()
           
private static long getTimestampMillis(java.sql.Timestamp ts)
           
private static java.lang.String getUpdateSql()
          SQL for updating a row on the lock table.
private  void initialize()
          Clear invalidations more than 1 hour old.
private  CachedEntityInvalidation instanceFromResultSet(java.sql.ResultSet rs)
          Extract values from ResultSet and create a new CachedEntityInvalidation.
private  CachedEntityInvalidation newInstance(java.lang.Class type, java.lang.String key, java.util.Date expiration, int cacheID)
           
private  void primAdd(CachedEntityInvalidation ent, java.sql.Connection conn)
          Add the invalid entity to the underlying store.
private  void primDeleteBefore(java.util.Date expiration, java.sql.Connection conn)
          Delete invalid entities from the underlying store whose invalidation is before invalidation.
private  CachedEntityInvalidation[] primSelect(java.lang.String sql, java.sql.Connection conn)
          Retrieve CachedEntityInvalidations from the underlying store.
private  void primUpdate(CachedEntityInvalidation ent, java.sql.Connection conn)
          Updates the invalid enity's expiration in the underlying store.
private static java.lang.String printTimestamp(java.sql.Timestamp ts)
           
private  CachedEntityInvalidation[] select(java.lang.Class entityType, java.lang.String entityKey, java.util.Date invalidation, java.lang.Integer cacheID, java.sql.Connection conn)
          Retrieve CachedEntityInvalidation from the underlying store.
private  CachedEntityInvalidation[] selectAfter(java.lang.Class entityType, java.lang.String entityKey, java.util.Date invalidation, java.lang.Integer cacheID, java.sql.Connection conn)
          Retrieve CachedEntityInvalidations from the underlying store.
static RDBMCachedEntityInvalidationStore singleton()
           
private static java.lang.String sqlQuote(java.lang.Object o)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log

singleton

private static RDBMCachedEntityInvalidationStore singleton

ENTITY_INVALIDATION_TABLE

private static java.lang.String ENTITY_INVALIDATION_TABLE

ENTITY_TYPE_COLUMN

private static java.lang.String ENTITY_TYPE_COLUMN

ENTITY_KEY_COLUMN

private static java.lang.String ENTITY_KEY_COLUMN

INVALIDATION_TIME_COLUMN

private static java.lang.String INVALIDATION_TIME_COLUMN

ENTITY_CACHE_ID_COLUMN

private static java.lang.String ENTITY_CACHE_ID_COLUMN

EQ

private static java.lang.String EQ

NE

private static java.lang.String NE

GT

private static java.lang.String GT

LT

private static java.lang.String LT

QUOTE

private static java.lang.String QUOTE

allTableColumns

private static java.lang.String allTableColumns

addSql

private static java.lang.String addSql

updateSql

private static java.lang.String updateSql

timestampHasMillis

private static boolean timestampHasMillis
Constructor Detail

RDBMCachedEntityInvalidationStore

public RDBMCachedEntityInvalidationStore()
                                  throws CachingException
RDBMCachedEntityInvalidationStore constructor.

Throws:
CachingException
Method Detail

add

public void add(CachedEntityInvalidation cachedEnt)
         throws CachingException
Adds/updates the row corresponding to this invalidation in the underlying store.

Parameters:
cachedEnt - org.jasig.portal.concurrency.caching.CachedEntityInvalidation
Throws:
CachingException

add

public void add(IBasicEntity entity,
                int cacheID)
         throws CachingException
Adds/updates the row corresponding to this entity in the underlying store.

Parameters:
entity - org.jasig.portal.IBasicEntity entity
Throws:
CachingException

deleteAll

public void deleteAll()
               throws CachingException
Delete all invalidations from the underlying store.

Throws:
CachingException

deleteBefore

public void deleteBefore(java.util.Date expiration)
                  throws CachingException
Delete invalid entities the underlying store whose invalidation time is before invalidation.

Parameters:
expiration - java.util.Date
Throws:
CachingException

existsInStore

private boolean existsInStore(CachedEntityInvalidation ent,
                              java.sql.Connection conn)
                       throws CachingException
Answers if this entity is represented in the store.

Parameters:
ent - org.jasig.portal.concurrency.CachedEntityInvalidation
Throws:
CachingException

find

public CachedEntityInvalidation[] find(java.lang.Class entityType,
                                       java.lang.String entityKey)
                                throws CachingException
Retrieve CachedEntityInvalidations from the underlying entity invalidation store. Either or both of the parameters may be null.

Parameters:
entityType - Class
entityKey - String
Throws:
CachingException - - wraps an Exception specific to the store.

findAfter

public CachedEntityInvalidation[] findAfter(java.util.Date invalidation,
                                            java.lang.Class entityType,
                                            java.lang.String entityKey,
                                            java.lang.Integer cacheID)
                                     throws CachingException
Retrieve CachedEntityInvalidations from the underlying store. Any or all of the parameters may be null.

Parameters:
invalidation - Date
entityType - Class
entityKey - String
cacheID - Integer - the cache ID we do NOT want to retrieve.
Throws:
CachingException - - wraps an Exception specific to the store.

getAddSql

private static java.lang.String getAddSql()
SQL for inserting a row into the invalid entities table.


getAllTableColumns

private static java.lang.String getAllTableColumns()
Returns:
java.lang.String

getDeleteInvalidationsSql

private static java.lang.String getDeleteInvalidationsSql()
SQL for deleting old invalid entity rows.


getSelectInvalidationsByTypeSql

private static java.lang.String getSelectInvalidationsByTypeSql()
Returns:
java.lang.String

getSelectSql

private static java.lang.String getSelectSql()
Returns:
java.lang.String

getUpdateSql

private static java.lang.String getUpdateSql()
SQL for updating a row on the lock table.


instanceFromResultSet

private CachedEntityInvalidation instanceFromResultSet(java.sql.ResultSet rs)
                                                throws java.sql.SQLException,
                                                       CachingException
Extract values from ResultSet and create a new CachedEntityInvalidation.

Parameters:
rs - java.sql.ResultSet
Returns:
org.jasig.portal.concurrency.locking.CachedEntityInvalidation
Throws:
java.sql.SQLException
CachingException

newInstance

private CachedEntityInvalidation newInstance(java.lang.Class type,
                                             java.lang.String key,
                                             java.util.Date expiration,
                                             int cacheID)
Returns:
org.jasig.portal.concurrency.caching.CachedEntityInvalidation

primAdd

private void primAdd(CachedEntityInvalidation ent,
                     java.sql.Connection conn)
              throws java.sql.SQLException,
                     CachingException
Add the invalid entity to the underlying store.

Parameters:
ent - org.jasig.portal.concurrency.caching.CachedEntityInvalidation
conn - java.sql.Connection
Throws:
java.sql.SQLException
CachingException

primDeleteBefore

private void primDeleteBefore(java.util.Date expiration,
                              java.sql.Connection conn)
                       throws CachingException,
                              java.sql.SQLException
Delete invalid entities from the underlying store whose invalidation is before invalidation.

Parameters:
expiration - java.util.Date
conn - Connection
Throws:
CachingException
java.sql.SQLException

primSelect

private CachedEntityInvalidation[] primSelect(java.lang.String sql,
                                              java.sql.Connection conn)
                                       throws CachingException
Retrieve CachedEntityInvalidations from the underlying store.

Parameters:
sql - String - the sql string used to select the entity lock rows.
conn - Connection
Throws:
CachingException - - wraps an Exception specific to the store.

primUpdate

private void primUpdate(CachedEntityInvalidation ent,
                        java.sql.Connection conn)
                 throws java.sql.SQLException,
                        CachingException
Updates the invalid enity's expiration in the underlying store.

Parameters:
ent - org.jasig.portal.concurrency.caching.CachedEntityInvalidation
conn - Connection
Throws:
java.sql.SQLException
CachingException

select

private CachedEntityInvalidation[] select(java.lang.Class entityType,
                                          java.lang.String entityKey,
                                          java.util.Date invalidation,
                                          java.lang.Integer cacheID,
                                          java.sql.Connection conn)
                                   throws CachingException
Retrieve CachedEntityInvalidation from the underlying store. Any or all of the parameters may be null.

Parameters:
entityType - Class
entityKey - String
invalidation - Date
conn - Connection
Throws:
CachingException - - wraps an Exception specific to the store.

selectAfter

private CachedEntityInvalidation[] selectAfter(java.lang.Class entityType,
                                               java.lang.String entityKey,
                                               java.util.Date invalidation,
                                               java.lang.Integer cacheID,
                                               java.sql.Connection conn)
                                        throws CachingException
Retrieve CachedEntityInvalidations from the underlying store. Any or all of the parameters may be null.

Parameters:
entityType - Class
entityKey - String
invalidation - Date
cacheID - Integer - the cache ID we do NOT want to retrieve.
conn - Connection
Throws:
CachingException - - wraps an Exception specific to the store.

singleton

public static RDBMCachedEntityInvalidationStore singleton()
                                                   throws CachingException
Returns:
org.jasig.portal.concurrency.caching.RDBMCachedEntityInvalidationStore
Throws:
CachingException

sqlQuote

private static java.lang.String sqlQuote(java.lang.Object o)
Returns:
java.lang.String

getTimestampMillis

private static long getTimestampMillis(java.sql.Timestamp ts)
Returns:
long

initialize

private void initialize()
                 throws CachingException
Clear invalidations more than 1 hour old.

Throws:
CachingException

printTimestamp

private static java.lang.String printTimestamp(java.sql.Timestamp ts)
Returns:
java.lang.String