Top Description Fields Constructors Methods
org.apache.catalina.session

public Class DataSourceStore

extends StoreBase
Class Inheritance
Imports
java.io.BufferedInputStream, .BufferedOutputStream, .ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .InputStream, .ObjectInputStream, .ObjectOutputStream, java.sql.Connection, .PreparedStatement, .ResultSet, .SQLException, java.util.ArrayList, .List, javax.naming.Context, .InitialContext, .NamingException, javax.sql.DataSource, org.apache.catalina.Container, .Globals, .Session, org.apache.juli.logging.Log

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

Modifier and TypeField and Description
protected DataSource
dataSource

DataSource to use

protected String
dataSourceName

name of the JNDI resource

private boolean
localDataSource

Context local datasource.

private String
name

Context name associated with this Store

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 final String
storeName

Hides org.apache.catalina.session.StoreBase.storeName.

Name to register for this Store, used for logging.
Inherited from org.apache.catalina.session.StoreBase:
managersmsupport

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Implements org.apache.catalina.Store.clear.

Remove all of the Sessions in this Store.

protected void
close(Connection
The connection to be closed
dbConnection
)

Close the specified database connection.

public String[]
expiredKeys()

Overrides org.apache.catalina.session.StoreBase.expiredKeys.

Get only those keys of sessions, that are saved in the Store and are to be expired.

protected Connection

Returns:

Connection if the connection succeeded
getConnection
()

Check the connection associated with this store, if it's null or closed try to reopen it.

public String

Returns:

the name of the JNDI DataSource-factory
getDataSourceName
()

public boolean

Returns:

if the datasource will be looked up in the webapp JNDI Context.
getLocalDataSource
()

public String

Returns:

the name for this instance (built from container name)
getName
()

public String

Returns:

the web application name column for the table.
getSessionAppCol
()

public String

Returns:

the data column for the table
getSessionDataCol
()

public String

Returns:

the Id column for the table.
getSessionIdCol
()

public String

Returns:

the Last Accessed column
getSessionLastAccessedCol
()

public String

Returns:

the Max Inactive column
getSessionMaxInactiveCol
()

public String

Returns:

the table for this Store.
getSessionTable
()

public String

Returns:

the Is Valid column
getSessionValidCol
()

public int

Returns:

the count of all sessions currently saved in this Store
getSize
()

Implements org.apache.catalina.Store.getSize.

Return an integer containing a count of all Sessions currently saved in this Store.

public String

Returns:

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

Overrides org.apache.catalina.session.StoreBase.getStoreName.

public String[]
private String[]

Returns:

array containing the list of session IDs
keys
(boolean
flag, whether only keys of expired sessions should be returned
expiredOnly
)

Return an array containing the session identifiers of all Sessions currently saved in this Store.

public Session

Returns:

the stored Session
load
(String
a value of type String
id
)

Implements org.apache.catalina.Store.load.

Load the Session associated with the id id.

protected Connection

Returns:

database connection ready to use
open
()

Open (if necessary) and return a database connection for use by this Store.

protected void
release(Connection
The connection to be released
conn
)

Release the connection, if it is associated with a connection pool.

public void
remove(String
Session identifier of the Session to be removed
id
)

Implements org.apache.catalina.Store.remove.

Remove the Session with the specified session identifier from this Store, if present.

private void
remove(String
Session identifier of the Session to be removed
id
,
Connection
open connection to be used
_conn
)

Remove the Session with the specified session identifier from this Store, if present.

public void
save(Session
the session to be stored
session
)

Implements org.apache.catalina.Store.save.

Save a session to the Store.

public void
setDataSourceName(String
The JNDI name of the DataSource-factory
dataSourceName
)

Set the JNDI name of a DataSource-factory to use for db access

public void
setLocalDataSource(boolean
the new flag value
localDataSource
)

Set to true to cause the datasource to be looked up in the webapp JNDI Context.

public void
setSessionAppCol(String
the column name
sessionAppCol
)

Set the App column for the table.

public void
setSessionDataCol(String
the column name
sessionDataCol
)

Set the Data column for the table

public void
setSessionIdCol(String
the column name
sessionIdCol
)

Set the Id column for the table.

public void
setSessionLastAccessedCol(String
The column name
sessionLastAccessedCol
)

Set the Last Accessed column for the table

public void
setSessionMaxInactiveCol(String
The column name
sessionMaxInactiveCol
)

Set the Max Inactive column for the table

public void
setSessionTable(String
The new table
sessionTable
)

Set the table for this Store.

public void
setSessionValidCol(String
The column name
sessionValidCol
)

Set the Is Valid column for the table

Inherited from org.apache.catalina.session.StoreBase:
addPropertyChangeListenerdestroyInternalgetManagergetObjectInputStreaminitInternalprocessExpiresremovePropertyChangeListenersetManagerstartInternalstopInternaltoString

Field Detail

dataSourceback to summary
protected DataSource dataSource

DataSource to use

dataSourceNameback to summary
protected String dataSourceName

name of the JNDI resource

localDataSourceback to summary
private boolean localDataSource

Context local datasource.

nameback to summary
private String name

Context name associated with this Store

sessionAppColback to summary
protected String sessionAppCol

Column to use for /Engine/Host/Context name

sessionDataColback to summary
protected String sessionDataCol

Data column to use.

sessionIdColback to summary
protected String sessionIdCol

Id column to use.

sessionLastAccessedColback to summary
protected String sessionLastAccessedCol

Last Accessed column to use.

sessionMaxInactiveColback to summary
protected String sessionMaxInactiveCol

Max Inactive column to use.

sessionTableback to summary
protected String sessionTable

Table to use.

sessionValidColback to summary
protected String sessionValidCol

Is Valid column to use.

storeNameback to summary
protected static final String storeName

Hides org.apache.catalina.session.StoreBase.storeName.

Name to register for this Store, used for logging.

Constructor Detail

DataSourceStoreback to summary
public DataSourceStore()

Method Detail

clearback to summary
public void clear() throws IOException

Implements org.apache.catalina.Store.clear.

Remove all of the Sessions in this Store.

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
closeback to summary
protected void close(Connection dbConnection)

Close the specified database connection.

Parameters
dbConnection:Connection

The connection to be closed

expiredKeysback to summary
public String[] expiredKeys() throws IOException

Overrides org.apache.catalina.session.StoreBase.expiredKeys.

Doc from org.apache.catalina.session.StoreBase.expiredKeys.

Get only those keys of sessions, that are saved in the Store and are to be expired.

Returns:String[]

list of session keys, that are to be expired

Annotations
@Override
Exceptions
IOException:
if an input-/output error occurred
getConnectionback to summary
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

Connection if the connection succeeded

getDataSourceNameback to summary
public String getDataSourceName()
Returns:String

the name of the JNDI DataSource-factory

getLocalDataSourceback to summary
public boolean getLocalDataSource()
Returns:boolean

if the datasource will be looked up in the webapp JNDI Context.

getNameback to summary
public String getName()
Returns:String

the name for this instance (built from container name)

getSessionAppColback to summary
public String getSessionAppCol()
Returns:String

the web application name column for the table.

getSessionDataColback to summary
public String getSessionDataCol()
Returns:String

the data column for the table

getSessionIdColback to summary
public String getSessionIdCol()
Returns:String

the Id column for the table.

getSessionLastAccessedColback to summary
public String getSessionLastAccessedCol()
Returns:String

the Last Accessed column

getSessionMaxInactiveColback to summary
public String getSessionMaxInactiveCol()
Returns:String

the Max Inactive column

getSessionTableback to summary
public String getSessionTable()
Returns:String

the table for this Store.

getSessionValidColback to summary
public String getSessionValidCol()
Returns:String

the Is Valid column

getSizeback to summary
public int getSize() throws IOException

Implements org.apache.catalina.Store.getSize.

Return an integer containing a count of all Sessions currently saved in this Store. If there are no Sessions, 0 is returned.

Returns:int

the count of all sessions currently saved in this Store

Annotations
@Override
Exceptions
IOException:
if an input/output error occurred
getStoreNameback to summary
public String getStoreName()

Overrides org.apache.catalina.session.StoreBase.getStoreName.

Returns:String

the name for this Store, used for logging.

Annotations
@Override
keysback to summary
public String[] keys() throws IOException

Implements org.apache.catalina.Store.keys.

Returns:String[]

Doc from org.apache.catalina.Store.keys.

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.

Annotations
@Override
Exceptions
IOException:

Doc from org.apache.catalina.Store.keys.

if an input/output error occurred

keysback to summary
private String[] keys(boolean expiredOnly) 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.

Parameters
expiredOnly:boolean

flag, whether only keys of expired sessions should be returned

Returns:String[]

array containing the list of session IDs

Exceptions
IOException:
if an input/output error occurred
loadback to summary
public Session load(String id) throws ClassNotFoundException, IOException

Implements org.apache.catalina.Store.load.

Load the Session associated with the id id. If no such session is found null is returned.

Parameters
id:String

a value of type String

Returns:Session

the stored Session

Annotations
@Override
Exceptions
ClassNotFoundException:
if an error occurs
IOException:
if an input/output error occurred
openback to summary
protected Connection open() throws SQLException

Open (if necessary) and return a database connection for use by this Store.

Returns:Connection

database connection ready to use

Exceptions
SQLException:
if a database error occurs
releaseback to summary
protected void release(Connection conn)

Release the connection, if it is associated with a connection pool.

Parameters
conn:Connection

The connection to be released

removeback to summary
public void remove(String id) throws IOException

Implements org.apache.catalina.Store.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:String

Session identifier of the Session to be removed

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
removeback to summary
private void remove(String id, Connection _conn) throws SQLException

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:String

Session identifier of the Session to be removed

_conn:Connection

open connection to be used

Exceptions
SQLException:
if an error occurs while talking to the database
saveback to summary
public void save(Session session) throws IOException

Implements org.apache.catalina.Store.save.

Save a session to the Store.

Parameters
session:Session

the session to be stored

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
setDataSourceNameback to summary
public void setDataSourceName(String dataSourceName)

Set the JNDI name of a DataSource-factory to use for db access

Parameters
dataSourceName:String

The JNDI name of the DataSource-factory

setLocalDataSourceback to summary
public void setLocalDataSource(boolean localDataSource)

Set to true to cause the datasource to be looked up in the webapp JNDI Context.

Parameters
localDataSource:boolean

the new flag value

setSessionAppColback to summary
public void setSessionAppCol(String sessionAppCol)

Set the App column for the table.

Parameters
sessionAppCol:String

the column name

setSessionDataColback to summary
public void setSessionDataCol(String sessionDataCol)

Set the Data column for the table

Parameters
sessionDataCol:String

the column name

setSessionIdColback to summary
public void setSessionIdCol(String sessionIdCol)

Set the Id column for the table.

Parameters
sessionIdCol:String

the column name

setSessionLastAccessedColback to summary
public void setSessionLastAccessedCol(String sessionLastAccessedCol)

Set the Last Accessed column for the table

Parameters
sessionLastAccessedCol:String

The column name

setSessionMaxInactiveColback to summary
public void setSessionMaxInactiveCol(String sessionMaxInactiveCol)

Set the Max Inactive column for the table

Parameters
sessionMaxInactiveCol:String

The column name

setSessionTableback to summary
public void setSessionTable(String sessionTable)

Set the table for this Store.

Parameters
sessionTable:String

The new table

setSessionValidColback to summary
public void setSessionValidCol(String sessionValidCol)

Set the Is Valid column for the table

Parameters
sessionValidCol:String

The column name