ca.cbc.sportwire.servlet.data
Class JDOMDB

java.lang.Object
  |
  +--ca.cbc.sportwire.servlet.data.DOMFile
        |
        +--ca.cbc.sportwire.servlet.data.JDOMFile
              |
              +--ca.cbc.sportwire.servlet.data.JDOMDB
All Implemented Interfaces:
DBCacheProperties, GlobalCacheProperties, java.lang.Runnable, SportPageProperties, Stoppable

public class JDOMDB
extends JDOMFile
implements Stoppable, SportPageProperties, DBCacheProperties, GlobalCacheProperties

JDOMDB is a JDOMFile that loads it's document via periodic updates from a database. 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.

This class is a merging of the JDOMFile and DBCacheBean, and as such, since both of those classes use the Thread run() method for different purposes, there had to be a lot of cut and paste; someday this class should be revisited to correct the inheritance issues

NOTE: This class creates a JdbcConnection db pool object and stashes it in the application-scoped ExtendedProperties to use for future calls.

Created: Sun Feb 10 15:12:05 EST 2002

Version:
$Id: JDOMDB.java,v 1.8 2002/03/23 19:46:03 garym Exp $
Author:
Gary Lawrence Murphy

Field Summary
(package private) static org.apache.log4j.Category cat
          Set up a reporting category in Log4J
private  JdbcConnections connectPool
           
private  int interval
           
private  boolean running
           
 
Fields inherited from class ca.cbc.sportwire.servlet.data.JDOMFile
builder, document, filename, saxclass, sc, xml
 
Fields inherited from interface ca.cbc.sportwire.servlet.data.SportPageProperties
BEAN_SUFFIX, BEANFACTORY_VAR, CONTEXT_VAR, DATE_VAR, DEFAULT_EXTS, DEFAULT_INDEXES, DEFAULT_PAGE_SUFFIX, DEFAULT_SAX_DRIVER_CLASS, DEFAULT_TIMEZONE, DEFAULT_TOPIC, DOM_VAR, ERROR_TEMPLATE_VAR, EXCEPTION_VAR, EXTENSIONS_VAR, FALSE, GLOBAL_VAR, HOME_PROPERTY, INCLUDE_EXTS_PROPERTY, INCLUDE_VAR, INDEX_INDICATOR_VAR, INDEX_TEMPLATE_VAR, LAYOUT_TEMPLATE_VAR, MACRO_LIB_PROPERTY, MISSING_TEMPLATE_VAR, OUTPUT_VAR, PAGE_EXPIRE, PAGE_TEMPLATE_VAR, PANIC_404_PAGE, PANIC_404_PROPERTY, PANIC_500_PAGE, PANIC_500_PROPERTY, PARAM_PARSER_VAR, PATH_VAR, REQUEST_VAR, RESPONSE_VAR, SAX_CLASS_PROPERTY, SERVLET_DEBUG, SERVLET_LOGCONF_PROPERTY, SQL_SUFFIX, TEMPLATE_PATHS_PROPERTY, TIMEZONE_PROPERTY, TRUE, URI_VAR, VELOCITY_LOGFILE_DEFAULT, VELOCITY_LOGFILE_PROPERTY, XML_EXTS, XML_EXTS_PROPERTY, XML_PATHS_PROPERTY, XML_SUFFIX, XSL_EXTS, XSL_EXTS_PROPERTY, XSL_PATHS_PROPERTY
 
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
protected JDOMDB(org.apache.velocity.context.Context context)
          JDOMDB constructor extracts the global properties from a Velocity page Context.
protected JDOMDB(org.apache.commons.collections.ExtendedProperties sc)
          constructor used withing Velocity to pre-build a query object using the default periodicities.
protected JDOMDB(org.apache.commons.collections.ExtendedProperties sc, java.lang.String query)
          JDOMDB constructor to set up the connection from the server properties and also set the query to start the fetch.
 
Method Summary
 void bump()
          bump locks the object and does a notifyAll to nudge any waiting data access methods
protected  JdbcConnections getConnectPool()
          Get the connectPool; this class caches its XALAN connectPool
static JDOMFile 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 JDOMFile getInstance(org.apache.velocity.context.Context context, java.lang.String sql)
          getInstance gets the app config and also sets the query in motion.
static JDOMFile getInstance(org.apache.commons.collections.ExtendedProperties sc)
          getInstance using the application properties (needed for the JDBC and cache periodicity settings.
static JDOMFile 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
 boolean isRunning()
          Get the value of running.
 void run()
          run implements the refresh timer; if the running flag is true, the refresh is run, then the thread pauses for interval seconds.
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.
 void setDocument(java.lang.String sql)
          ignored because we need to setup the db connection before we start the thread
 void setInterval(int sec)
           
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.
 void setRunning(boolean v)
          running: can be set to false to terminate the refresh thread.
 
Methods inherited from class ca.cbc.sportwire.servlet.data.JDOMFile
getDocument, getFilename, getRootElement, getSaxclass, getXml, getXml, setFilename, setSaxclass, transform, transform, xpath, xpath
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

cat

static org.apache.log4j.Category cat
Set up a reporting category in Log4J

connectPool

private JdbcConnections connectPool

interval

private int interval

running

private boolean running
Constructor Detail

JDOMDB

protected JDOMDB(org.apache.velocity.context.Context context)
          throws java.io.IOException,
                 java.io.FileNotFoundException
JDOMDB constructor extracts the global properties from a Velocity page Context.
Parameters:
context - a Context value
Throws:
java.io.IOException - if an error occurs
java.io.FileNotFoundException - is actually inherited due to bad design :(

JDOMDB

protected JDOMDB(org.apache.commons.collections.ExtendedProperties sc)
          throws java.io.IOException,
                 java.io.FileNotFoundException
constructor used withing Velocity to pre-build a query object using the default periodicities.
Parameters:
sc - the ExtendedProperties app config
Throws:
java.io.IOException - if an error occurs
java.io.FileNotFoundException - is not likely, see above.

JDOMDB

protected JDOMDB(org.apache.commons.collections.ExtendedProperties sc,
                 java.lang.String query)
          throws java.io.IOException,
                 java.io.FileNotFoundException
JDOMDB constructor to set up the connection from the server properties and also set the query to start the fetch.
Parameters:
sc - the ExtendedProperties app config
query - a String SQL statement.
Throws:
java.io.IOException - if an error occurs
java.io.FileNotFoundException -  
Method Detail

getConnectPool

protected JdbcConnections getConnectPool()
Get the connectPool; this class caches its XALAN connectPool
Returns:
JdbcConnections value of connectPool.

setConnectPool

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.
Parameters:
sc - the ExtendedProperties app config

getQuery

public java.lang.String getQuery()
Get the SQL query; since updates are done periodically, this must handle time-sensitive reports on the update schedule.
Returns:
String value SQL query.

setQuery

protected void setQuery(java.lang.String v)
Set the SQL query and begin the updates. This can only be called once; subsequent calls throw IllegalStateException.
Parameters:
v - String value of the SQL query.

getReloadPeriod

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
Parameters:
sc - an ExtendedProperties value
Returns:
an int value

getInstance

public static JDOMFile getInstance(org.apache.velocity.context.Context context)
                            throws java.io.IOException,
                                   java.io.FileNotFoundException
getInstance attempts to fetch the matching instance via the Velocity Context $globals link to the TTL cache.
Parameters:
context - the Velocity page Context
Returns:
a JDOMFile value
Throws:
java.io.IOException - if an error occurs
java.io.FileNotFoundException - if an error occurs

getInstance

public static JDOMFile getInstance(org.apache.velocity.context.Context context,
                                   java.lang.String sql)
                            throws java.io.IOException,
                                   java.io.FileNotFoundException
getInstance gets the app config and also sets the query in motion.
Parameters:
context - a Velocity page Context
sql - a String SQL statement
Returns:
a JDOMDB value
Throws:
java.io.IOException - if an error occurs
java.io.FileNotFoundException - if an error occurs

getInstance

public static JDOMFile getInstance(org.apache.commons.collections.ExtendedProperties sc)
                            throws java.io.IOException,
                                   java.io.FileNotFoundException
getInstance using the application properties (needed for the JDBC and cache periodicity settings.
Parameters:
sc - an ExtendedProperties value
Returns:
a JDOMDB value
Throws:
java.io.IOException - if an error occurs
java.io.FileNotFoundException - if an error occurs

getInstance

public static JDOMFile getInstance(org.apache.commons.collections.ExtendedProperties sc,
                                   java.lang.String sql)
                            throws java.io.IOException,
                                   java.io.FileNotFoundException
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.
Parameters:
sc - the ExtendedProperties app config
sql - a String SQL statement
Returns:
a JDOMDB value
Throws:
java.io.IOException - if an error occurs
java.io.FileNotFoundException - if an error occurs

setDocument

public void setDocument(java.lang.String sql)
ignored because we need to setup the db connection before we start the thread
Overrides:
setDocument in class JDOMFile
Following copied from class: ca.cbc.sportwire.servlet.data.JDOMFile
Parameters:
filename - a String value
Throws:
java.io.FileNotFoundException - if an error occurs
java.io.IOException - if an error occurs

setInterval

public void setInterval(int sec)

isRunning

public boolean isRunning()
Get the value of running.
Specified by:
isRunning in interface Stoppable
Returns:
boolean value of running.

setRunning

public void setRunning(boolean v)
running: can be set to false to terminate the refresh thread.
Specified by:
setRunning in interface Stoppable
Parameters:
v - Value to assign to running.

bump

public void bump()
bump locks the object and does a notifyAll to nudge any waiting data access methods

run

public void run()
run implements the refresh timer; if the running flag is true, the refresh is run, then the thread pauses for interval seconds.
Overrides:
run in class JDOMFile

setResults

public 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.