|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--ca.cbc.sportwire.util.PeriodicData | +--ca.cbc.sportwire.servlet.data.DBCacheBean
DBCacheBean is a general purpose base class for JSP page beans that do a period update from a database, then offer the result set read-only to a large number of concurrent sessions. Data results are refreshed according to a periodicity, and then cached in the global MRUCacheMap so that queries are removed from memory if no one actually accesses them, but are kept in reasonable sync with the database while they are popular.
NOTE: This class creates a JdbcConnection db pool object and stashes it in the application-scoped ExtendedProperties to use for future calls.
Created: Fri Nov 23 13:29:20 2001
Field Summary | |
private TTLCacheMap |
cache
|
(package private) static org.apache.log4j.Category |
cat
Set up a reporting category in Log4J |
private java.util.ArrayList |
columns
|
private JdbcConnections |
connectPool
|
private java.lang.String |
query
|
private java.util.ArrayList |
results
|
Fields inherited from class ca.cbc.sportwire.util.PeriodicData |
interval, running |
Fields inherited from class java.lang.Thread |
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ, userDaemon |
Fields inherited from interface ca.cbc.sportwire.servlet.data.DBCacheProperties |
DB_CACHE_DEFAULT_PERIOD, DB_REFRESH_PROPERTY, DBCACHE_POOL_PROPERTY, DBCACHE_TEXT_FILTER_DEFAULT, DBCACHE_TEXT_FILTER_PROPERTY |
Fields inherited from interface ca.cbc.sportwire.servlet.data.GlobalCacheProperties |
CACHE_DEFAULT_PERIOD, CACHE_DEFAULT_TIMEOUT, CACHE_PERIOD, CACHE_TIMEOUT, MRU_PROPERTY, MRU_VAR, TTL_PROPERTY, TTL_VAR |
Constructor Summary | |
DBCacheBean()
Creates a new DBCacheBean instance with no values
set; could be used this way within JSP; the refreshing doesn't
start until you set the query. |
|
DBCacheBean(org.apache.commons.collections.ExtendedProperties sc)
constructor used withing Velocity to pre-build a query object using the default periodicities. |
|
DBCacheBean(org.apache.commons.collections.ExtendedProperties sc,
java.lang.String query)
DBCacheBean constructor to set up the connection
from the server properties and also set the query to start the
fetch. |
|
DBCacheBean(org.apache.commons.collections.ExtendedProperties sc,
java.lang.String query,
int reloadPeriod)
DBCacheBean deluxe constructor constructor sets
the query, and sets the reload-period. |
Method Summary | |
protected TTLCacheMap |
getCache()
Get the cache map. |
java.util.ArrayList |
getColumns()
Get the list of column labels as an ArrayList in the same order as the result set. |
protected JdbcConnections |
getConnectPool()
Get the connectPool; this object caches its XALAN connectPool used to get connections to the database. |
static DBCacheBean |
getInstance(org.apache.velocity.context.Context context)
getInstance attempts to fetch the matching
instance via the Velocity Context $globals
link to the TTL cache. |
static DBCacheBean |
getInstance(org.apache.velocity.context.Context context,
java.lang.String sql)
getInstance gets the app config and also sets the
query in motion. |
static DBCacheBean |
getInstance(org.apache.commons.collections.ExtendedProperties sc)
getInstance : |
static DBCacheBean |
getInstance(org.apache.commons.collections.ExtendedProperties sc,
java.lang.String sql)
getInstance is the same as the version using the
Velocity page config, but gets the app config directly. |
java.lang.String |
getQuery()
Get the SQL query; since updates are done periodically, this must handle time-sensitive reports on the update schedule. |
protected static int |
getReloadPeriod(org.apache.commons.collections.ExtendedProperties sc)
getReloadPeriod computes the refresh period from
the properties, or sets it to the default
DB_CACHE_DEFAULT_PERIOD |
java.util.ArrayList |
getResults()
getResults will wait for an initial ResultSet and
then return the cached list of columns and a list of value
lists (rows of columns of Object elements) -- if you
need the column labels, they are in the getColumns(). |
protected void |
refresh()
refresh is the PeriodicData method called by the
timer thread. |
protected void |
setCache(TTLCacheMap v)
Set the cache. |
protected void |
setColumns(java.util.ArrayList v)
Set the columns list. |
protected void |
setConnectPool(org.apache.commons.collections.ExtendedProperties sc)
Retrieve the connectPool from the global properties, or create one and stash it if none exists. |
protected void |
setQuery(java.lang.String v)
Set the SQL query and begin the updates. |
void |
setResults()
Set the value of cached results by doing a database lookup using the statement; notes that a ResultSet falls out of scope with the Statement that created it so we make a copy to be used by the cache. |
Methods inherited from class ca.cbc.sportwire.util.PeriodicData |
bump, isRunning, run, setInterval, setRunning |
Methods inherited from class java.lang.Thread |
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
static org.apache.log4j.Category cat
private JdbcConnections connectPool
private TTLCacheMap cache
private java.lang.String query
private java.util.ArrayList columns
private java.util.ArrayList results
Constructor Detail |
public DBCacheBean()
DBCacheBean
instance with no values
set; could be used this way within JSP; the refreshing doesn't
start until you set the query.public DBCacheBean(org.apache.commons.collections.ExtendedProperties sc)
sc
- the ExtendedProperties
app configpublic DBCacheBean(org.apache.commons.collections.ExtendedProperties sc, java.lang.String query)
DBCacheBean
constructor to set up the connection
from the server properties and also set the query to start the
fetch.sc
- the ExtendedProperties
app configquery
- a String
SQL statement.public DBCacheBean(org.apache.commons.collections.ExtendedProperties sc, java.lang.String query, int reloadPeriod)
DBCacheBean
deluxe constructor constructor sets
the query, and sets the reload-period.sc
- an ExtendedProperties
app configquery
- a String
SQL statementreloadPeriod
- an int
seconds valueMethod Detail |
protected JdbcConnections getConnectPool()
protected void setConnectPool(org.apache.commons.collections.ExtendedProperties sc)
sc
- the ExtendedProperties
app configprotected TTLCacheMap getCache()
protected void setCache(TTLCacheMap v)
v
- Value to assign to cache.public java.lang.String getQuery()
protected void setQuery(java.lang.String v)
v
- String value of the SQL query.protected static int getReloadPeriod(org.apache.commons.collections.ExtendedProperties sc)
getReloadPeriod
computes the refresh period from
the properties, or sets it to the default
DB_CACHE_DEFAULT_PERIODsc
- an ExtendedProperties
valueint
valuepublic static DBCacheBean getInstance(org.apache.velocity.context.Context context)
getInstance
attempts to fetch the matching
instance via the Velocity Context $globals
link to the TTL cache.context
- the Velocity page Context
DBCacheBean
valuepublic static DBCacheBean getInstance(org.apache.velocity.context.Context context, java.lang.String sql)
getInstance
gets the app config and also sets the
query in motion.context
- a Velocity page Context
sql
- a String
SQL statementDBCacheBean
valuepublic static DBCacheBean getInstance(org.apache.commons.collections.ExtendedProperties sc)
getInstance
:sc
- an ExtendedProperties
valueDBCacheBean
valuepublic static DBCacheBean getInstance(org.apache.commons.collections.ExtendedProperties sc, java.lang.String sql)
getInstance
is the same as the version using the
Velocity page config, but gets the app config directly. This
is used in pre-loading SQL beans specified in the
sportpage.conf
file.sc
- the ExtendedProperties
app configsql
- a String
SQL statementDBCacheBean
valueprotected void refresh()
refresh
is the PeriodicData method called by the
timer thread. Here it re-fetches the result set.refresh
in class PeriodicData
public java.util.ArrayList getColumns()
protected void setColumns(java.util.ArrayList v)
v
- ArrayList value to assign to columns.public java.util.ArrayList getResults()
getResults
will wait for an initial ResultSet and
then return the cached list of columns and a list of value
lists (rows of columns of Object elements) -- if you
need the column labels, they are in the getColumns(). It is up
to the calling program to decide what to do with the Object
values.
The data is restructured into this form because a ResultSet is closed when its connection or its statement go out of scope; if we every had a requirement to store more metadata about each column, the Objects in the row lists could be wrapped in an inner class.
public void setResults()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Javadocs generated Tue Apr 23 01:08:36 EDT 2002 by garym@maya.dyndns.org
Copyright © 2002 Canadian Broadcasting Corp