Apache Tomcat 6.0.53

org.apache.catalina.session
Class JDBCStore

java.lang.Object
  extended by org.apache.catalina.session.StoreBase
      extended by org.apache.catalina.session.JDBCStore
All Implemented Interfaces:
Lifecycle, Store

public class JDBCStore
extends StoreBase

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.

Author:
Bip Thelin

Field Summary
protected  java.lang.String connectionName
          The connection username to use when trying to connect to the database.
protected  java.lang.String connectionPassword
          The connection URL to use when trying to connect to the database.
protected  java.lang.String connectionURL
          Connection string to use when connecting to the DB.
protected  java.sql.Driver driver
          Instance of the JDBC Driver class we use as a connection factory.
protected  java.lang.String driverName
          Driver to use.
protected static java.lang.String info
          The descriptive information about this implementation.
protected  java.sql.PreparedStatement preparedClearSql
          Variable to hold the clear() prepared statement.
protected  java.sql.PreparedStatement preparedKeysSql
          Variable to hold the keys() prepared statement.
protected  java.sql.PreparedStatement preparedLoadSql
          Variable to hold the load() prepared statement.
protected  java.sql.PreparedStatement preparedRemoveSql
          Variable to hold the remove() prepared statement.
protected  java.sql.PreparedStatement preparedSaveSql
          Variable to hold the save() prepared statement.
protected  java.sql.PreparedStatement preparedSizeSql
          Variable to hold the getSize() prepared statement.
protected  java.lang.String sessionAppCol
          Column to use for /Engine/Host/Context name
protected  java.lang.String sessionDataCol
          Data column to use.
protected  java.lang.String sessionIdCol
          Id column to use.
protected  java.lang.String sessionLastAccessedCol
          Last Accessed column to use.
protected  java.lang.String sessionMaxInactiveCol
          Max Inactive column to use.
protected  java.lang.String sessionTable
          Table to use.
protected  java.lang.String sessionValidCol
          Is Valid column to use.
protected static java.lang.String storeName
          Name to register for this Store, used for logging.
protected  java.lang.String threadName
          Name to register for the background thread.
 
Fields inherited from class org.apache.catalina.session.StoreBase
lifecycle, manager, sm, started, support
 
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, DESTROY_EVENT, INIT_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT
 
Constructor Summary
JDBCStore()
           
 
Method Summary
 void clear()
          Remove all of the Sessions in this Store.
protected  void close(java.sql.Connection dbConnection)
          Close the specified database connection.
protected  java.sql.Connection getConnection()
          Check the connection associated with this store, if it's null or closed try to reopen it.
 java.lang.String getConnectionName()
          Return the username to use to connect to the database.
 java.lang.String getConnectionPassword()
          Return the password to use to connect to the database.
 java.lang.String getConnectionURL()
          Return the Connection URL for this Store.
 java.lang.String getDriverName()
          Return the driver for this Store.
 java.lang.String getInfo()
          Return the info for this Store.
 java.lang.String getName()
          Return the name for this instance (built from container name)
 java.lang.String getSessionAppCol()
          Return the web application name column for the table.
 java.lang.String getSessionDataCol()
          Return the data column for the table
 java.lang.String getSessionIdCol()
          Return the Id column for the table.
 java.lang.String getSessionLastAccessedCol()
          Return the Last Accessed column
 java.lang.String getSessionMaxInactiveCol()
          Return the Max Inactive column
 java.lang.String getSessionTable()
          Return the table for this Store.
 java.lang.String getSessionValidCol()
          Return the Is Valid column
 int getSize()
          Return an integer containing a count of all Sessions currently saved in this Store.
 java.lang.String getStoreName()
          Return the name for this Store, used for logging.
 java.lang.String getThreadName()
          Return the thread name for this Store.
 java.lang.String[] keys()
          Return an array containing the session identifiers of all Sessions currently saved in this Store.
 Session load(java.lang.String id)
          Load the Session associated with the id id.
protected  java.sql.Connection open()
          Open (if necessary) and return a database connection for use by this Realm.
protected  void release(java.sql.Connection conn)
          Release the connection, not needed here since the connection is not associated with a connection pool.
 void remove(java.lang.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(java.lang.String connectionName)
          Set the username to use to connect to the database.
 void setConnectionPassword(java.lang.String connectionPassword)
          Set the password to use to connect to the database.
 void setConnectionURL(java.lang.String connectionURL)
          Set the Connection URL for this Store.
 void setDriverName(java.lang.String driverName)
          Set the driver for this Store.
 void setSessionAppCol(java.lang.String sessionAppCol)
          Set the App column for the table.
 void setSessionDataCol(java.lang.String sessionDataCol)
          Set the Data column for the table
 void setSessionIdCol(java.lang.String sessionIdCol)
          Set the Id column for the table.
 void setSessionLastAccessedCol(java.lang.String sessionLastAccessedCol)
          Set the Last Accessed column for the table
 void setSessionMaxInactiveCol(java.lang.String sessionMaxInactiveCol)
          Set the Max Inactive column for the table
 void setSessionTable(java.lang.String sessionTable)
          Set the table for this Store.
 void setSessionValidCol(java.lang.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, getManager, getObjectInputStream, processExpires, removeLifecycleListener, removePropertyChangeListener, setManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

info

protected static java.lang.String info
The descriptive information about this implementation.


storeName

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


threadName

protected java.lang.String threadName
Name to register for the background thread.


connectionName

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


connectionPassword

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


connectionURL

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


driver

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


driverName

protected java.lang.String driverName
Driver to use.


sessionTable

protected java.lang.String sessionTable
Table to use.


sessionAppCol

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


sessionIdCol

protected java.lang.String sessionIdCol
Id column to use.


sessionDataCol

protected java.lang.String sessionDataCol
Data column to use.


sessionValidCol

protected java.lang.String sessionValidCol
Is Valid column to use.


sessionMaxInactiveCol

protected java.lang.String sessionMaxInactiveCol
Max Inactive column to use.


sessionLastAccessedCol

protected java.lang.String sessionLastAccessedCol
Last Accessed column to use.


preparedSizeSql

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


preparedKeysSql

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


preparedSaveSql

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


preparedClearSql

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


preparedRemoveSql

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


preparedLoadSql

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

Constructor Detail

JDBCStore

public JDBCStore()
Method Detail

getInfo

public java.lang.String getInfo()
Return the info for this Store.

Specified by:
getInfo in interface Store
Overrides:
getInfo in class StoreBase

getName

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


getThreadName

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


getStoreName

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

Overrides:
getStoreName in class StoreBase

setDriverName

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

Parameters:
driverName - The new driver

getDriverName

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


getConnectionName

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


setConnectionName

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

Parameters:
connectionName - Username

getConnectionPassword

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


setConnectionPassword

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

Parameters:
connectionPassword - User password

setConnectionURL

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

Parameters:
connectionURL - The new Connection URL

getConnectionURL

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


setSessionTable

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

Parameters:
sessionTable - The new table

getSessionTable

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


setSessionAppCol

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

Parameters:
sessionAppCol - the column name

getSessionAppCol

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


setSessionIdCol

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

Parameters:
sessionIdCol - the column name

getSessionIdCol

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


setSessionDataCol

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

Parameters:
sessionDataCol - the column name

getSessionDataCol

public java.lang.String getSessionDataCol()
Return the data column for the table


setSessionValidCol

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

Parameters:
sessionValidCol - The column name

getSessionValidCol

public java.lang.String getSessionValidCol()
Return the Is Valid column


setSessionMaxInactiveCol

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

Parameters:
sessionMaxInactiveCol - The column name

getSessionMaxInactiveCol

public java.lang.String getSessionMaxInactiveCol()
Return the Max Inactive column


setSessionLastAccessedCol

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

Parameters:
sessionLastAccessedCol - The column name

getSessionLastAccessedCol

public java.lang.String getSessionLastAccessedCol()
Return the Last Accessed column


keys

public java.lang.String[] keys()
                        throws java.io.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:
java.io.IOException - if an input/output error occurred

getSize

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

Throws:
java.io.IOException - if an input/output error occurred

load

public Session load(java.lang.String id)
             throws java.lang.ClassNotFoundException,
                    java.io.IOException
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:
java.lang.ClassNotFoundException - if an error occurs
java.io.IOException - if an input/output error occurred

remove

public void remove(java.lang.String id)
            throws java.io.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:
java.io.IOException - if an input/output error occurs

clear

public void clear()
           throws java.io.IOException
Remove all of the Sessions in this Store.

Throws:
java.io.IOException - if an input/output error occurs

save

public void save(Session session)
          throws java.io.IOException
Save a session to the Store.

Parameters:
session - the session to be stored
Throws:
java.io.IOException - if an input/output error occurs

getConnection

protected java.sql.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

open

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

Throws:
java.sql.SQLException - if a database error occurs

close

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

Parameters:
dbConnection - The connection to be closed

release

protected void release(java.sql.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 LifecycleException
Called once when this Store is first started.

Specified by:
start in interface Lifecycle
Overrides:
start in class StoreBase
Throws:
LifecycleException - if this component detects a fatal error that prevents this component from being used

stop

public void stop()
          throws LifecycleException
Gracefully terminate everything associated with our db. Called once when this Store is stopping.

Specified by:
stop in interface Lifecycle
Overrides:
stop in class StoreBase
Throws:
LifecycleException - if this component detects a fatal error that needs to be reported

Apache Tomcat 6.0.53

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.