DataSourceStore (Apache Tomcat 9.0.111 API Documentation)
Description: declaration: package: org.apache.catalina.session, class: DataSourceStore

# Class DataSourceStore

java.lang.Object
org.apache.catalina.util.LifecycleBase
org.apache.catalina.session.StoreBase
org.apache.catalina.session.JDBCStore
org.apache.catalina.session.DataSourceStore

All Implemented Interfaces:
  `Lifecycle, Store`

public class DataSourceStore extends JDBCStore
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.

- ## Nested Class Summary

  ### Nested classes/interfaces inherited from interface Lifecycle

  `Lifecycle.SingleUse`

- ## Field Summary

  ### Fields inherited from class JDBCStore

  `connectionName, connectionPassword, connectionURL, dataSource, dataSourceName, driver, driverName, preparedClearSql, preparedLoadSql, preparedRemoveSql, preparedSaveSql, preparedSizeSql, sessionAppCol, sessionDataCol, sessionIdCol, sessionLastAccessedCol, sessionMaxInactiveCol, sessionTable, sessionValidCol, storeName, threadName`

  ### Fields inherited from class StoreBase

  `manager, sm, support`

  ### Fields inherited from interface 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
  Constructor
  Description
  `DataSourceStore()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  Remove all of the Sessions in this Store.
  `protected void`
  `close(Connection dbConnection)`
  Close the specified database connection.
  `String[]`
  `expiredKeys()`
  Get only those keys of sessions, that are saved in the Store and are to be expired.
  `int`
  `getSize()`
  Return an integer containing a count of all Sessions currently saved in this Store.
  `String[]`
  `keys()`
  `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 Store.
  `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.

  ### Methods inherited from class JDBCStore

  `getConnection, getConnectionName, getConnectionPassword, getConnectionURL, getDataSourceName, getDriverName, getLocalDataSource, getName, getSessionAppCol, getSessionDataCol, getSessionIdCol, getSessionLastAccessedCol, getSessionMaxInactiveCol, getSessionTable, getSessionValidCol, getStoreName, getThreadName, release, setConnectionName, setConnectionPassword, setConnectionURL, setDataSourceName, setDriverName, setLocalDataSource, setSessionAppCol, setSessionDataCol, setSessionIdCol, setSessionLastAccessedCol, setSessionMaxInactiveCol, setSessionTable, setSessionValidCol, startInternal, stopInternal`

  ### Methods inherited from class StoreBase

  `addPropertyChangeListener, destroyInternal, getManager, getObjectInputStream, initInternal, processExpires, removePropertyChangeListener, setManager, toString`

  ### Methods inherited from class LifecycleBase

  `addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### DataSourceStore

    public DataSourceStore()

- ## Method Details

  - ### expiredKeys

    public String[] expiredKeys() throws IOException
    Description copied from class: `StoreBase`
    Get only those keys of sessions, that are saved in the Store and are to be expired.
    Overrides:
      `expiredKeys` in class `JDBCStore`
    Returns:
      array of session keys, that are to be expired
    Throws:
      `IOException` - if an input-/output error occurred

  - ### keys

    public String[] keys() throws IOException
    Specified by:
      `keys` in interface `Store`
    Overrides:
      `keys` in class `JDBCStore`
    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

    public int getSize() throws IOException
    Description copied from class: `JDBCStore`
    Return an integer containing a count of all Sessions currently saved in this Store. If there are no Sessions, `0` is returned.
    Specified by:
      `getSize` in interface `Store`
    Overrides:
      `getSize` in class `JDBCStore`
    Returns:
      the count of all sessions currently saved in this Store
    Throws:
      `IOException` - if an input/output error occurred

  - ### load

    public Session load(String id) throws ClassNotFoundException, IOException
    Description copied from class: `JDBCStore`
    Load the Session associated with the id `id`. If no such session is found `null` is returned.
    Specified by:
      `load` in interface `Store`
    Overrides:
      `load` in class `JDBCStore`
    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
    Description copied from class: `JDBCStore`
    Remove the Session with the specified session identifier from this Store, if present. If no such Session is present, this method takes no action.
    Specified by:
      `remove` in interface `Store`
    Overrides:
      `remove` in class `JDBCStore`
    Parameters:
      `id` - Session identifier of the Session to be removed
    Throws:
      `IOException` - if an input/output error occurs

  - ### clear

    public void clear() throws IOException
    Description copied from class: `JDBCStore`
    Remove all of the Sessions in this Store.
    Specified by:
      `clear` in interface `Store`
    Overrides:
      `clear` in class `JDBCStore`
    Throws:
      `IOException` - if an input/output error occurs

  - ### save

    public void save(Session session) throws IOException
    Description copied from class: `JDBCStore`
    Save a session to the Store.
    Specified by:
      `save` in interface `Store`
    Overrides:
      `save` in class `JDBCStore`
    Parameters:
      `session` - the session to be stored
    Throws:
      `IOException` - if an input/output error occurs

  - ### open

    protected Connection open() throws SQLException
    Open (if necessary) and return a database connection for use by this Store.
    Overrides:
      `open` in class `JDBCStore`
    Returns:
      database connection ready to use
    Throws:
      `SQLException` - if a database error occurs

  - ### close

    protected void close(Connection dbConnection)
    Close the specified database connection.
    Overrides:
      `close` in class `JDBCStore`
    Parameters:
      `dbConnection` - The connection to be closed