Package org.apache.catalina.session
Class JDBCStore
- java.lang.Object
-
- org.apache.catalina.session.StoreBase
-
- org.apache.catalina.session.JDBCStore
-
public class JDBCStore extends StoreBase
Implementation of theStoreinterface that stores serialized session objects in a database. Sessions that are saved are still subject to being expired based on inactivity.- Version:
- $Revision: 1.4 $, $Date: 2006/11/09 01:12:51 $
- Author:
- Bip Thelin
-
-
Field Summary
Fields Modifier and Type Field Description protected StringconnStringConnection string to use when connecting to the DB.protected StringdriverNameDriver to use.protected static StringinfoThe descriptive information about this implementation.protected PreparedStatementpreparedClearSqlVariable to hold theclear()prepared statement.protected PreparedStatementpreparedKeysSqlVariable to hold thekeys()prepared statement.protected PreparedStatementpreparedLoadSqlVariable to hold theload()prepared statement.protected PreparedStatementpreparedRemoveSqlVariable to hold theremove()prepared statement.protected PreparedStatementpreparedSaveSqlVariable to hold thesave()prepared statement.protected PreparedStatementpreparedSizeSqlVariable to hold thegetSize()prepared statement.protected StringsessionAppColColumn to use for /Engine/Host/Context nameprotected StringsessionDataColData column to use.protected StringsessionIdColId column to use.protected StringsessionLastAccessedColLast Accessed column to use.protected StringsessionMaxInactiveColMax Inactive column to use.protected StringsessionTableTable to use.protected StringsessionValidColIs Valid column to use.protected static StringstoreNameName to register for this Store, used for logging.protected StringthreadNameName to register for the background thread.-
Fields inherited from class org.apache.catalina.session.StoreBase
debug, lifecycle, manager, started, support
-
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, INIT_EVENT, START_EVENT, STOP_EVENT
-
-
Constructor Summary
Constructors Constructor Description JDBCStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Remove all of the Sessions in this Store.protected ConnectiongetConnection()Check the connection associated with this store, if it'snullor closed try to reopen it.StringgetConnectionURL()Return the Connection URL for this Store.StringgetDriverName()Return the driver for this Store.StringgetInfo()Return the info for this Store.StringgetName()Return the name for this instance (built from container name)StringgetSessionAppCol()Return the web application name column for the table.StringgetSessionDataCol()Return the data column for the tableStringgetSessionIdCol()Return the Id column for the table.StringgetSessionLastAccessedCol()Return the Last Accessed columnStringgetSessionMaxInactiveCol()Return the Max Inactive columnStringgetSessionTable()Return the table for this Store.StringgetSessionValidCol()Return the Is Valid columnintgetSize()Return an integer containing a count of all Sessions currently saved in this Store.StringgetStoreName()Return the name for this Store, used for logging.StringgetThreadName()Return the thread name for this Store.String[]keys()Return an array containing the session identifiers of all Sessions currently saved in this Store.Sessionload(String id)Load the Session associated with the idid.protected voidrelease(Connection conn)Release the connection, not needed here since the connection is not associated with a connection pool.voidremove(String id)Remove the Session with the specified session identifier from this Store, if present.voidsave(Session session)Save a session to the Store.voidsetConnectionURL(String connectionURL)Set the Connection URL for this Store.voidsetDriverName(String driverName)Set the driver for this Store.voidsetSessionAppCol(String sessionAppCol)Set the App column for the table.voidsetSessionDataCol(String sessionDataCol)Set the Data column for the tablevoidsetSessionIdCol(String sessionIdCol)Set the Id column for the table.voidsetSessionLastAccessedCol(String sessionLastAccessedCol)Set the Last Accessed column for the tablevoidsetSessionMaxInactiveCol(String sessionMaxInactiveCol)Set the Max Inactive column for the tablevoidsetSessionTable(String sessionTable)Set the table for this Store.voidsetSessionValidCol(String sessionValidCol)Set the Is Valid column for the tablevoidstart()Called once when this Store is first started.voidstop()Gracefully terminate everything associated with our db.-
Methods inherited from class org.apache.catalina.session.StoreBase
addLifecycleListener, addPropertyChangeListener, doProcessExpires, findLifecycleListeners, getDebug, getManager, load, log, processExpires, readSession, removeFromStoreCache, removeLifecycleListener, removePropertyChangeListener, setDebug, setManager, writeSession
-
-
-
-
Field Detail
-
info
protected static final String info
The descriptive information about this implementation.- See Also:
- Constant Field Values
-
storeName
protected static final String storeName
Name to register for this Store, used for logging.- See Also:
- Constant Field Values
-
threadName
protected String threadName
Name to register for the background thread.
-
connString
protected String connString
Connection string to use when connecting to the DB.
-
driverName
protected String driverName
Driver to use.
-
sessionTable
protected String sessionTable
Table to use.
-
sessionAppCol
protected String sessionAppCol
Column to use for /Engine/Host/Context name
-
sessionIdCol
protected String sessionIdCol
Id column to use.
-
sessionDataCol
protected String sessionDataCol
Data column to use.
-
sessionValidCol
protected String sessionValidCol
Is Valid column to use.
-
sessionMaxInactiveCol
protected String sessionMaxInactiveCol
Max Inactive column to use.
-
sessionLastAccessedCol
protected String sessionLastAccessedCol
Last Accessed column to use.
-
preparedSizeSql
protected PreparedStatement preparedSizeSql
Variable to hold thegetSize()prepared statement.
-
preparedKeysSql
protected PreparedStatement preparedKeysSql
Variable to hold thekeys()prepared statement.
-
preparedSaveSql
protected PreparedStatement preparedSaveSql
Variable to hold thesave()prepared statement.
-
preparedClearSql
protected PreparedStatement preparedClearSql
Variable to hold theclear()prepared statement.
-
preparedRemoveSql
protected PreparedStatement preparedRemoveSql
Variable to hold theremove()prepared statement.
-
preparedLoadSql
protected PreparedStatement preparedLoadSql
Variable to hold theload()prepared statement.
-
-
Method Detail
-
getInfo
public String getInfo()
Return the info for this Store.
-
getName
public String getName()
Return the name for this instance (built from container name)
-
getThreadName
public String getThreadName()
Return the thread name for this Store.
-
getStoreName
public String getStoreName()
Return the name for this Store, used for logging.- Overrides:
getStoreNamein classStoreBase
-
setDriverName
public void setDriverName(String driverName)
Set the driver for this Store.- Parameters:
driverName- The new driver
-
getDriverName
public String getDriverName()
Return the driver for this Store.
-
setConnectionURL
public void setConnectionURL(String connectionURL)
Set the Connection URL for this Store.- Parameters:
connectionURL- The new Connection URL
-
getConnectionURL
public String getConnectionURL()
Return the Connection URL for this Store.
-
setSessionTable
public void setSessionTable(String sessionTable)
Set the table for this Store.- Parameters:
sessionTable- The new table
-
getSessionTable
public String getSessionTable()
Return the table for this Store.
-
setSessionAppCol
public void setSessionAppCol(String sessionAppCol)
Set the App column for the table.- Parameters:
sessionAppCol- the column name
-
getSessionAppCol
public String getSessionAppCol()
Return the web application name column for the table.
-
setSessionIdCol
public void setSessionIdCol(String sessionIdCol)
Set the Id column for the table.- Parameters:
sessionIdCol- the column name
-
getSessionIdCol
public String getSessionIdCol()
Return the Id column for the table.
-
setSessionDataCol
public void setSessionDataCol(String sessionDataCol)
Set the Data column for the table- Parameters:
sessionDataCol- the column name
-
getSessionDataCol
public String getSessionDataCol()
Return the data column for the table
-
setSessionValidCol
public void setSessionValidCol(String sessionValidCol)
Set the Is Valid column for the table- Parameters:
sessionValidCol- The column name
-
getSessionValidCol
public String getSessionValidCol()
Return the Is Valid column
-
setSessionMaxInactiveCol
public void setSessionMaxInactiveCol(String sessionMaxInactiveCol)
Set the Max Inactive column for the table- Parameters:
sessionMaxInactiveCol- The column name
-
getSessionMaxInactiveCol
public String getSessionMaxInactiveCol()
Return the Max Inactive column
-
setSessionLastAccessedCol
public void setSessionLastAccessedCol(String sessionLastAccessedCol)
Set the Last Accessed column for the table- Parameters:
sessionLastAccessedCol- The column name
-
getSessionLastAccessedCol
public String getSessionLastAccessedCol()
Return the Last Accessed column
-
keys
public String[] keys() throws IOException
Return an array containing the session identifiers of all Sessions currently saved in this Store. If there are no such Sessions, a zero-length array is returned.- Throws:
IOException- if an input/output error occurred
-
getSize
public int getSize() throws IOExceptionReturn an integer containing a count of all Sessions currently saved in this Store. If there are no Sessions,0is returned.- Throws:
IOException- if an input/output error occurred
-
load
public Session load(String id) throws ClassNotFoundException, IOException
Load the Session associated with the idid. If no such session is foundnullis returned.- Parameters:
id- a value of typeString- Returns:
- the stored
Session - Throws:
ClassNotFoundException- if an error occursIOException- if an input/output error occurred
-
remove
public void remove(String id) throws IOException
Remove the Session with the specified session identifier from this Store, if present. If no such Session is present, this method takes no action.- Parameters:
id- Session identifier of the Session to be removed- Throws:
IOException- if an input/output error occurs
-
clear
public void clear() throws IOExceptionRemove all of the Sessions in this Store.- Throws:
IOException- if an input/output error occurs
-
save
public void save(Session session) throws IOException
Save a session to the Store.- Parameters:
session- the session to be stored- Throws:
IOException- if an input/output error occurs
-
getConnection
protected Connection getConnection()
Check the connection associated with this store, if it'snullor closed try to reopen it. Returnsnullif the connection could not be established.- Returns:
Connectionif the connection succeeded
-
release
protected void release(Connection conn)
Release the connection, not needed here since the connection is not associated with a connection pool.- Parameters:
conn- The connection to be released
-
start
public void start() throws LifecycleExceptionCalled once when this Store is first started.- Specified by:
startin interfaceLifecycle- Overrides:
startin classStoreBase- Throws:
LifecycleException- if this component detects a fatal error that prevents this component from being used
-
stop
public void stop() throws LifecycleExceptionGracefully terminate everything associated with our db. Called once when this Store is stoping.- Specified by:
stopin interfaceLifecycle- Overrides:
stopin classStoreBase- Throws:
LifecycleException- if this component detects a fatal error that needs to be reported
-
-