Package org.apache.catalina.session
Class DataSourceStore
java.lang.Object
org.apache.catalina.util.LifecycleBase
org.apache.catalina.session.StoreBase
org.apache.catalina.session.DataSourceStore
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.catalina.Lifecycle
Lifecycle.SingleUse -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DataSourceDataSource to useprotected Stringname of the JNDI resourceprotected StringColumn to use for /Engine/Host/Context nameprotected StringData column to use.protected StringId column to use.protected StringLast Accessed column to use.protected StringMax Inactive column to use.protected StringTable to use.protected StringIs Validcolumn to use.protected static final StringName to register for this Store, used for logging.Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Remove all of the Sessions in this Store.protected voidclose(Connection dbConnection) Close the specified database connection.String[]Get only those keys of sessions, that are saved in the Store and are to be expired.protected ConnectionCheck the connection associated with this store, if it'snullor closed try to reopen it.booleangetName()intgetSize()Return an integer containing a count of all Sessions currently saved in this Store.String[]keys()Load the Session associated with the idid.protected Connectionopen()Open (if necessary) and return a database connection for use by this Store.protected voidrelease(Connection conn) Release the connection, if it is associated with a connection pool.voidRemove the Session with the specified session identifier from this Store, if present.voidSave a session to the Store.voidsetDataSourceName(String dataSourceName) Set the JNDI name of a DataSource-factory to use for db accessvoidsetLocalDataSource(boolean localDataSource) Set totrueto cause the datasource to be looked up in the webapp JNDI Context.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 theLast Accessedcolumn for the tablevoidsetSessionMaxInactiveCol(String sessionMaxInactiveCol) Set theMax Inactivecolumn for the tablevoidsetSessionTable(String sessionTable) Set the table for this Store.voidsetSessionValidCol(String sessionValidCol) Set theIs Validcolumn for the tableMethods inherited from class org.apache.catalina.session.StoreBase
addPropertyChangeListener, destroyInternal, getManager, getObjectInputStream, initInternal, processExpires, removePropertyChangeListener, setManager, startInternal, stopInternal, toStringMethods inherited from class org.apache.catalina.util.LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
-
Field Details
-
storeName
Name to register for this Store, used for logging.- See Also:
-
dataSourceName
name of the JNDI resource -
dataSource
DataSource to use -
sessionTable
Table to use. -
sessionAppCol
Column to use for /Engine/Host/Context name -
sessionIdCol
Id column to use. -
sessionDataCol
Data column to use. -
sessionValidCol
Is Validcolumn to use. -
sessionMaxInactiveCol
Max Inactive column to use. -
sessionLastAccessedCol
Last Accessed column to use.
-
-
Constructor Details
-
DataSourceStore
public DataSourceStore()
-
-
Method Details
-
getName
- Returns:
- the name for this instance (built from container name)
-
getStoreName
- Overrides:
getStoreNamein classStoreBase- Returns:
- the name for this Store, used for logging.
-
setSessionTable
Set the table for this Store.- Parameters:
sessionTable- The new table
-
getSessionTable
- Returns:
- the table for this Store.
-
setSessionAppCol
Set the App column for the table.- Parameters:
sessionAppCol- the column name
-
getSessionAppCol
- Returns:
- the web application name column for the table.
-
setSessionIdCol
Set the Id column for the table.- Parameters:
sessionIdCol- the column name
-
getSessionIdCol
- Returns:
- the Id column for the table.
-
setSessionDataCol
Set the Data column for the table- Parameters:
sessionDataCol- the column name
-
getSessionDataCol
- Returns:
- the data column for the table
-
setSessionValidCol
Set theIs Validcolumn for the table- Parameters:
sessionValidCol- The column name
-
getSessionValidCol
- Returns:
- the
Is Validcolumn
-
setSessionMaxInactiveCol
Set theMax Inactivecolumn for the table- Parameters:
sessionMaxInactiveCol- The column name
-
getSessionMaxInactiveCol
- Returns:
- the
Max Inactivecolumn
-
setSessionLastAccessedCol
Set theLast Accessedcolumn for the table- Parameters:
sessionLastAccessedCol- The column name
-
getSessionLastAccessedCol
- Returns:
- the
Last Accessedcolumn
-
setDataSourceName
Set the JNDI name of a DataSource-factory to use for db access- Parameters:
dataSourceName- The JNDI name of the DataSource-factory
-
getDataSourceName
- Returns:
- the name of the JNDI DataSource-factory
-
getLocalDataSource
public boolean getLocalDataSource()- Returns:
- if the datasource will be looked up in the webapp JNDI Context.
-
setLocalDataSource
public void setLocalDataSource(boolean localDataSource) Set totrueto cause the datasource to be looked up in the webapp JNDI Context.- Parameters:
localDataSource- the new flag value
-
expiredKeys
Description copied from class:StoreBaseGet only those keys of sessions, that are saved in the Store and are to be expired.- Overrides:
expiredKeysin classStoreBase- Returns:
- list of session keys, that are to be expired
- Throws:
IOException- if an input-/output error occurred
-
keys
- Returns:
- 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
Return an integer containing a count of all Sessions currently saved in this Store. If there are no Sessions,0is returned.- Returns:
- the count of all sessions currently saved in this Store
- Throws:
IOException- if an input/output error occurred
-
load
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
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
Remove all of the Sessions in this Store.- Throws:
IOException- if an input/output error occurs
-
save
Save a session to the Store.- Parameters:
session- the session to be stored- Throws:
IOException- if an input/output error occurs
-
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
-
open
Open (if necessary) and return a database connection for use by this Store.- Returns:
- database connection ready to use
- Throws:
SQLException- if a database error occurs
-
close
Close the specified database connection.- Parameters:
dbConnection- The connection to be closed
-
release
Release the connection, if it is associated with a connection pool.- Parameters:
conn- The connection to be released
-