Overview | Package | Class | Tree | Deprecated | Index | Help
| Apache Tomcat 7.0.29
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.catalina.session
Class JDBCStore

    java.lang.Object
      org.apache.catalina.util.LifecycleBase
          org.apache.catalina.session.StoreBase
              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.

Version:
  $Id: JDBCStore.java 1153099 2011-08-02 11:51:20Z kfujino $
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 DataSource` | `dataSource` DataSource to use
`protected String` | `dataSourceName` name of the JNDI resource
`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
`manager, sm, support`

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
`JDBCStore()`

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` | `getDataSourceName()` Return the name of the JNDI DataSource-factory
`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, if it is 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` | `setDataSourceName(String dataSourceName)` Set the JNDI name of a DataSource-factory to use for db access
`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
`protected void` | `startInternal()` Start this component and implement the requirements of `LifecycleBase.startInternal()`.
`protected void` | `stopInternal()` Stop this component and implement the requirements of `LifecycleBase.stopInternal()`.

Methods inherited from class org.apache.catalina.session.StoreBase
`addPropertyChangeListener, destroyInternal, getManager, initInternal, processExpires, removePropertyChangeListener, setManager, toString`

Methods inherited from class org.apache.catalina.util.LifecycleBase
`addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, init, removeLifecycleListener, setState, setState, start, stop`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### info

    protected static final String info

  The descriptive information about this implementation.

  See Also:
    Constant Field Values

### 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.

### 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.

### dataSourceName

    protected String dataSourceName

  name of the JNDI resource

### dataSource

    protected DataSource dataSource

  DataSource to use

### sessionTable

    protected String sessionTable

  Table to use.

### sessionAppCol

    protected String sessionAppCol

  Column to use for /Engine/Host/Context name

### sessionIdCol

    protected String sessionIdCol

  Id column to use.

### sessionDataCol

    protected String sessionDataCol

  Data column to use.

### sessionValidCol

    protected String sessionValidCol

  Is Valid column to use.

### sessionMaxInactiveCol

    protected String sessionMaxInactiveCol

  Max Inactive column to use.

### sessionLastAccessedCol

    protected String sessionLastAccessedCol

  Last Accessed column to use.

### preparedSizeSql

    protected PreparedStatement preparedSizeSql

  Variable to hold the `getSize()` prepared statement.

### preparedKeysSql

    protected PreparedStatement preparedKeysSql

  Variable to hold the `keys()` prepared statement.

### preparedSaveSql

    protected PreparedStatement preparedSaveSql

  Variable to hold the `save()` prepared statement.

### preparedClearSql

    protected PreparedStatement preparedClearSql

  Variable to hold the `clear()` prepared statement.

### preparedRemoveSql

    protected PreparedStatement preparedRemoveSql

  Variable to hold the `remove()` prepared statement.

### preparedLoadSql

    protected PreparedStatement preparedLoadSql

  Variable to hold the `load()` prepared statement.

Constructor Detail

### JDBCStore

    public JDBCStore()

Method Detail

### getInfo

    public String getInfo()

  Return the info for this Store.

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

### getName

    public String getName()

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

### getThreadName

    public String getThreadName()

  Return the thread name for this Store.

### getStoreName

    public String getStoreName()

  Return the name for this Store, used for logging.

  Overrides:
    `getStoreName` in class `StoreBase`

### setDriverName

    public void setDriverName(String driverName)

  Set the driver for this Store.

  Parameters:
    `driverName` - The new driver

### getDriverName

    public String getDriverName()

  Return the driver for this Store.

### getConnectionName

    public String getConnectionName()

  Return the username to use to connect to the database.

### setConnectionName

    public void setConnectionName(String connectionName)

  Set the username to use to connect to the database.

  Parameters:
    `connectionName` - Username

### getConnectionPassword

    public String getConnectionPassword()

  Return the password to use to connect to the database.

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

### getConnectionURL

    public String getConnectionURL()

  Return the Connection URL for this Store.

### setSessionTable

    public void setSessionTable(String sessionTable)

  Set the table for this Store.

  Parameters:
    `sessionTable` - The new table

### getSessionTable

    public String getSessionTable()

  Return the table for this Store.

### setSessionAppCol

    public void setSessionAppCol(String sessionAppCol)

  Set the App column for the table.

  Parameters:
    `sessionAppCol` - the column name

### getSessionAppCol

    public String getSessionAppCol()

  Return the web application name column for the table.

### setSessionIdCol

    public void setSessionIdCol(String sessionIdCol)

  Set the Id column for the table.

  Parameters:
    `sessionIdCol` - the column name

### getSessionIdCol

    public String getSessionIdCol()

  Return the Id column for the table.

### setSessionDataCol

    public void setSessionDataCol(String sessionDataCol)

  Set the Data column for the table

  Parameters:
    `sessionDataCol` - the column name

### getSessionDataCol

    public String getSessionDataCol()

  Return the data column for the table

### setSessionValidCol

    public void setSessionValidCol(String sessionValidCol)

  Set the Is Valid column for the table

  Parameters:
    `sessionValidCol` - The column name

### getSessionValidCol

    public String getSessionValidCol()

  Return the Is Valid column

### setSessionMaxInactiveCol

    public void setSessionMaxInactiveCol(String sessionMaxInactiveCol)

  Set the Max Inactive column for the table

  Parameters:
    `sessionMaxInactiveCol` - The column name

### getSessionMaxInactiveCol

    public String getSessionMaxInactiveCol()

  Return the Max Inactive column

### setSessionLastAccessedCol

    public void setSessionLastAccessedCol(String sessionLastAccessedCol)

  Set the Last Accessed column for the table

  Parameters:
    `sessionLastAccessedCol` - The column name

### getSessionLastAccessedCol

    public String getSessionLastAccessedCol()

  Return the Last Accessed column

### setDataSourceName

    public void setDataSourceName(String dataSourceName)

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

  Parameters:
    `dataSourceName` - The JNDI name of the DataSource-factory

### getDataSourceName

    public String getDataSourceName()

  Return the name of the JNDI DataSource-factory

### 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.

  Throws:
    `IOException` - if an input/output error occurred

### 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.

  Throws:
    `IOException` - if an input/output error occurred

### 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.

  Parameters:
    `id` - a value of type `String`
  Returns:
    the stored `Session`
  Throws:
    `ClassNotFoundException` - if an error occurs
    `IOException` - if an input/output error occurred

### 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.

  Parameters:
    `id` - Session identifier of the Session to be removed
  Throws:
    `IOException` - if an input/output error occurs

### clear

    public void clear()
               throws IOException

  Remove all of the Sessions in this Store.

  Throws:
    `IOException` - if an input/output error occurs

### save

    public void save(Session session)
              throws IOException

  Save a session to the Store.

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

### 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 succeeded

### open

    protected Connection open()
                       throws SQLException

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

  Throws:
    `SQLException` - if a database error occurs

### close

    protected void close(Connection dbConnection)

  Close the specified database connection.

  Parameters:
    `dbConnection` - The connection to be closed

### release

    protected void release(Connection conn)

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

  Parameters:
    `conn` - The connection to be released

### startInternal

    protected void startInternal()
                          throws LifecycleException

  Start this component and implement the requirements of `LifecycleBase.startInternal()`.

  Overrides:
    `startInternal` in class `StoreBase`
  Throws:
    `LifecycleException` - if this component detects a fatal error that prevents this component from being used

### stopInternal

    protected void stopInternal()
                         throws LifecycleException

  Stop this component and implement the requirements of `LifecycleBase.stopInternal()`.

  Overrides:
    `stopInternal` in class `StoreBase`
  Throws:
    `LifecycleException` - if this component detects a fatal error that prevents this component from being used

Overview | Package | Class | Tree | Deprecated | Index | Help
| Apache Tomcat 7.0.29
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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