org.apache.catalina.session

Class JDBCStore

Implemented Interfaces:
Lifecycle, Store

public class JDBCStore
extends StoreBase
implements Store

Implementation of the Store interface that stores serialized session objects in a database. Sessions that are saved are still subject to being expired based on inactivity.

Version:
$Revision: 1.9 $, $Date: 2004/03/20 11:11:07 $

Author:
Bip Thelin

Field Summary

protected String
connectionName
The connection username to use when trying to connect to the database.
protected String
connectionPassword
The connection URL to use when trying to connect to the database.
protected String
connectionURL
Connection string to use when connecting to the DB.
protected Driver
driver
Instance of the JDBC Driver class we use as a connection factory.
protected String
driverName
Driver to use.
protected static String
info
The descriptive information about this implementation.
protected PreparedStatement
preparedClearSql
Variable to hold the clear() prepared statement.
protected PreparedStatement
preparedKeysSql
Variable to hold the keys() prepared statement.
protected PreparedStatement
preparedLoadSql
Variable to hold the load() prepared statement.
protected PreparedStatement
preparedRemoveSql
Variable to hold the remove() prepared statement.
protected PreparedStatement
preparedSaveSql
Variable to hold the save() prepared statement.
protected PreparedStatement
preparedSizeSql
Variable to hold the getSize() prepared statement.
protected String
sessionAppCol
Column to use for /Engine/Host/Context name
protected String
sessionDataCol
Data column to use.
protected String
sessionIdCol
Id column to use.
protected String
sessionLastAccessedCol
Last Accessed column to use.
protected String
sessionMaxInactiveCol
Max Inactive column to use.
protected String
sessionTable
Table to use.
protected String
sessionValidCol
Is Valid column to use.
protected static String
storeName
Name to register for this Store, used for logging.
protected String
threadName
Name to register for the background thread.

Fields inherited from class org.apache.catalina.session.StoreBase

debug, info, lifecycle, manager, sm, started, storeName, support

Fields inherited from interface org.apache.catalina.Lifecycle

AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, START_EVENT, STOP_EVENT

Method Summary

void
clear()
Remove all of the Sessions in this Store.
protected void
close(Connection dbConnection)
Close the specified database connection.
protected Connection
getConnection()
Check the connection associated with this store, if it's null or closed try to reopen it.
String
getConnectionName()
Return the username to use to connect to the database.
String
getConnectionPassword()
Return the password to use to connect to the database.
String
getConnectionURL()
Return the Connection URL for this Store.
String
getDriverName()
Return the driver for this Store.
String
getInfo()
Return the info for this Store.
String
getName()
Return the name for this instance (built from container name)
String
getSessionAppCol()
Return the web application name column for the table.
String
getSessionDataCol()
Return the data column for the table
String
getSessionIdCol()
Return the Id column for the table.
String
getSessionLastAccessedCol()
Return the Last Accessed column
String
getSessionMaxInactiveCol()
Return the Max Inactive column
String
getSessionTable()
Return the table for this Store.
String
getSessionValidCol()
Return the Is Valid column
int
getSize()
Return an integer containing a count of all Sessions currently saved in this Store.
String
getStoreName()
Return the name for this Store, used for logging.
String
getThreadName()
Return the thread name for this Store.
String[]
keys()
Return an array containing the session identifiers of all Sessions currently saved in this Store.
Session
load(String id)
Load the Session associated with the id id.
protected Connection
open()
Open (if necessary) and return a database connection for use by this Realm.
protected void
release(Connection conn)
Release the connection, not needed here since the connection is not associated with a connection pool.
void
remove(String id)
Remove the Session with the specified session identifier from this Store, if present.
void
save(Session session)
Save a session to the Store.
void
setConnectionName(String connectionName)
Set the username to use to connect to the database.
void
setConnectionPassword(String connectionPassword)
Set the password to use to connect to the database.
void
setConnectionURL(String connectionURL)
Set the Connection URL for this Store.
void
setDriverName(String driverName)
Set the driver for this Store.
void
setSessionAppCol(String sessionAppCol)
Set the App column for the table.
void
setSessionDataCol(String sessionDataCol)
Set the Data column for the table
void
setSessionIdCol(String sessionIdCol)
Set the Id column for the table.
void
setSessionLastAccessedCol(String sessionLastAccessedCol)
Set the Last Accessed column for the table
void
setSessionMaxInactiveCol(String sessionMaxInactiveCol)
Set the Max Inactive column for the table
void
setSessionTable(String sessionTable)
Set the table for this Store.
void
setSessionValidCol(String sessionValidCol)
Set the Is Valid column for the table
void
start()
Called once when this Store is first started.
void
stop()
Gracefully terminate everything associated with our db.

Methods inherited from class org.apache.catalina.session.StoreBase

addLifecycleListener, addPropertyChangeListener, findLifecycleListeners, getDebug, getInfo, getManager, getStoreName, log, processExpires, removeLifecycleListener, removePropertyChangeListener, setDebug, setManager, start, stop

Field Details

connectionName

protected String connectionName
The connection username to use when trying to connect to the database.


connectionPassword

protected String connectionPassword
The connection URL to use when trying to connect to the database.


connectionURL

protected String connectionURL
Connection string to use when connecting to the DB.


driver

protected Driver driver
Instance of the JDBC Driver class we use as a connection factory.


driverName

protected String driverName
Driver to use.


info

protected static String info
The descriptive information about this implementation.


preparedClearSql

protected PreparedStatement preparedClearSql
Variable to hold the clear() prepared statement.


preparedKeysSql

protected PreparedStatement preparedKeysSql
Variable to hold the keys() prepared statement.


preparedLoadSql

protected PreparedStatement preparedLoadSql
Variable to hold the load() prepared statement.


preparedRemoveSql

protected PreparedStatement preparedRemoveSql
Variable to hold the remove() prepared statement.


preparedSaveSql

protected PreparedStatement preparedSaveSql
Variable to hold the save() prepared statement.


preparedSizeSql

protected PreparedStatement preparedSizeSql
Variable to hold the getSize() prepared statement.


sessionAppCol

protected String sessionAppCol
Column to use for /Engine/Host/Context name


sessionDataCol

protected String sessionDataCol
Data column to use.


sessionIdCol

protected String sessionIdCol
Id column to use.


sessionLastAccessedCol

protected String sessionLastAccessedCol
Last Accessed column to use.


sessionMaxInactiveCol

protected String sessionMaxInactiveCol
Max Inactive column to use.


sessionTable

protected String sessionTable
Table to use.


sessionValidCol

protected String sessionValidCol
Is Valid column to use.


storeName

protected static String storeName
Name to register for this Store, used for logging.


threadName

protected String threadName
Name to register for the background thread.

Method Details

clear

public void clear()
            throws IOException
Remove all of the Sessions in this Store.
Specified by:
clear in interface Store


close

protected void close(Connection dbConnection)
Close the specified database connection.

Parameters:
dbConnection - The connection to be closed


getConnection

protected Connection getConnection()
Check the connection associated with this store, if it's null or closed try to reopen it. Returns null if the connection could not be established.

Returns:
Connection if the connection suceeded


getConnectionName

public String getConnectionName()
Return the username to use to connect to the database.


getConnectionPassword

public String getConnectionPassword()
Return the password to use to connect to the database.


getConnectionURL

public String getConnectionURL()
Return the Connection URL for this Store.


getDriverName

public String getDriverName()
Return the driver for this Store.


getInfo

public String getInfo()
Return the info for this Store.
Specified by:
getInfo in interface Store
Overrides:
getInfo in interface StoreBase


getName

public String getName()
Return the name for this instance (built from container name)


getSessionAppCol

public String getSessionAppCol()
Return the web application name column for the table.


getSessionDataCol

public String getSessionDataCol()
Return the data column for the table


getSessionIdCol

public String getSessionIdCol()
Return the Id column for the table.


getSessionLastAccessedCol

public String getSessionLastAccessedCol()
Return the Last Accessed column


getSessionMaxInactiveCol

public String getSessionMaxInactiveCol()
Return the Max Inactive column


getSessionTable

public String getSessionTable()
Return the table for this Store.


getSessionValidCol

public String getSessionValidCol()
Return the Is Valid column


getSize

public int getSize()
            throws IOException
Return an integer containing a count of all Sessions currently saved in this Store. If there are no Sessions, 0 is returned.
Specified by:
getSize in interface Store


getStoreName

public String getStoreName()
Return the name for this Store, used for logging.
Overrides:
getStoreName in interface StoreBase


getThreadName

public String getThreadName()
Return the thread name for this Store.


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.
Specified by:
keys in interface Store


load

public Session load(String id)
            throws ClassNotFoundException,
                   IOException
Load the Session associated with the id id. If no such session is found null is returned.
Specified by:
load in interface Store

Parameters:
id - a value of type String

Returns:
the stored Session


open

protected Connection open()
            throws SQLException
Open (if necessary) and return a database connection for use by this Realm.


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


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.
Specified by:
remove in interface Store

Parameters:
id - Session identifier of the Session to be removed


save

public void save(Session session)
            throws IOException
Save a session to the Store.
Specified by:
save in interface Store

Parameters:
session - the session to be stored


setConnectionName

public void setConnectionName(String connectionName)
Set the username to use to connect to the database.

Parameters:
connectionName - Username


setConnectionPassword

public void setConnectionPassword(String connectionPassword)
Set the password to use to connect to the database.

Parameters:
connectionPassword - User password


setConnectionURL

public void setConnectionURL(String connectionURL)
Set the Connection URL for this Store.

Parameters:
connectionURL - The new Connection URL


setDriverName

public void setDriverName(String driverName)
Set the driver for this Store.

Parameters:
driverName - The new driver


setSessionAppCol

public void setSessionAppCol(String sessionAppCol)
Set the App column for the table.

Parameters:
sessionAppCol - the column name


setSessionDataCol

public void setSessionDataCol(String sessionDataCol)
Set the Data column for the table

Parameters:
sessionDataCol - the column name


setSessionIdCol

public void setSessionIdCol(String sessionIdCol)
Set the Id column for the table.

Parameters:
sessionIdCol - the column name


setSessionLastAccessedCol

public void setSessionLastAccessedCol(String sessionLastAccessedCol)
Set the Last Accessed column for the table

Parameters:
sessionLastAccessedCol - The column name


setSessionMaxInactiveCol

public void setSessionMaxInactiveCol(String sessionMaxInactiveCol)
Set the Max Inactive column for the table

Parameters:
sessionMaxInactiveCol - The column name


setSessionTable

public void setSessionTable(String sessionTable)
Set the table for this Store.

Parameters:
sessionTable - The new table


setSessionValidCol

public void setSessionValidCol(String sessionValidCol)
Set the Is Valid column for the table

Parameters:
sessionValidCol - The column name


start

public void start()
            throws LifecycleException
Called once when this Store is first started.
Specified by:
start in interface Lifecycle
Overrides:
start in interface StoreBase


stop

public void stop()
            throws LifecycleException
Gracefully terminate everything associated with our db. Called once when this Store is stoping.
Specified by:
stop in interface Lifecycle
Overrides:
stop in interface StoreBase


Copyright B) 2000-2003 Apache Software Foundation. All Rights Reserved.