org.apache.catalina.session

Class JDBCStore

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: 554109 $, $Date: 2007-07-07 03:40:19 +0200 (Sat, 07 Jul 2007) $

Author: Bip Thelin

Field Summary
protected StringconnectionName
The connection username to use when trying to connect to the database.
protected StringconnectionPassword
The connection URL to use when trying to connect to the database.
protected StringconnectionURL
Connection string to use when connecting to the DB.
protected Driverdriver
Instance of the JDBC Driver class we use as a connection factory.
protected StringdriverName
Driver to use.
protected static Stringinfo
The descriptive information about this implementation.
protected PreparedStatementpreparedClearSql
Variable to hold the clear() prepared statement.
protected PreparedStatementpreparedKeysSql
Variable to hold the keys() prepared statement.
protected PreparedStatementpreparedLoadSql
Variable to hold the load() prepared statement.
protected PreparedStatementpreparedRemoveSql
Variable to hold the remove() prepared statement.
protected PreparedStatementpreparedSaveSql
Variable to hold the save() prepared statement.
protected PreparedStatementpreparedSizeSql
Variable to hold the getSize() prepared statement.
protected StringsessionAppCol
Column to use for /Engine/Host/Context name
protected StringsessionDataCol
Data column to use.
protected StringsessionIdCol
Id column to use.
protected StringsessionLastAccessedCol
Last Accessed column to use.
protected StringsessionMaxInactiveCol
Max Inactive column to use.
protected StringsessionTable
Table to use.
protected StringsessionValidCol
Is Valid column to use.
protected static StringstoreName
Name to register for this Store, used for logging.
protected StringthreadName
Name to register for the background thread.
Method Summary
voidclear()
Remove all of the Sessions in this Store.
protected voidclose(Connection dbConnection)
Close the specified database connection.
protected ConnectiongetConnection()
Check the connection associated with this store, if it's null or closed try to reopen it.
StringgetConnectionName()
Return the username to use to connect to the database.
StringgetConnectionPassword()
Return the password to use to connect to the database.
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 table
StringgetSessionIdCol()
Return the Id column for the table.
StringgetSessionLastAccessedCol()
Return the Last Accessed column
StringgetSessionMaxInactiveCol()
Return the Max Inactive column
StringgetSessionTable()
Return the table for this Store.
StringgetSessionValidCol()
Return the Is Valid column
intgetSize()
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 id id.
protected Connectionopen()
Open (if necessary) and return a database connection for use by this Realm.
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.
voidsetConnectionName(String connectionName)
Set the username to use to connect to the database.
voidsetConnectionPassword(String connectionPassword)
Set the password to use to connect to the database.
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 table
voidsetSessionIdCol(String sessionIdCol)
Set the Id column for the table.
voidsetSessionLastAccessedCol(String sessionLastAccessedCol)
Set the Last Accessed column for the table
voidsetSessionMaxInactiveCol(String sessionMaxInactiveCol)
Set the Max Inactive column for the table
voidsetSessionTable(String sessionTable)
Set the table for this Store.
voidsetSessionValidCol(String sessionValidCol)
Set the Is Valid column for the table
voidstart()
Called once when this Store is first started.
voidstop()
Gracefully terminate everything associated with our db.

Field Detail

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 Detail

clear

public void clear()
Remove all of the Sessions in this Store.

Throws: IOException if an input/output error occurs

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.

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()
Return an integer containing a count of all Sessions currently saved in this Store. If there are no Sessions, 0 is returned.

Throws: IOException if an input/output error occurred

getStoreName

public String getStoreName()
Return the name for this Store, used for logging.

getThreadName

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

keys

public String[] keys()
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

load

public Session load(String id)
Load the Session associated with the id id. If no such session is found null is returned.

Parameters: id a value of type String

Returns: the stored Session

Throws: ClassNotFoundException if an error occurs IOException if an input/output error occurred

open

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

Throws: SQLException if a database error occurs

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)
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

save

public void save(Session session)
Save a session to the Store.

Parameters: session the session to be stored

Throws: IOException if an input/output error occurs

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()
Called once when this Store is first started.

stop

public void stop()
Gracefully terminate everything associated with our db. Called once when this Store is stopping.
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.