Class DataSourceStore

All Implemented Interfaces:
Lifecycle, Store

public class DataSourceStore 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 Details

    • storeName

      protected static final String storeName
      Name to register for this Store, used for logging.
      See Also:
    • 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.
  • Constructor Details

    • DataSourceStore

      public DataSourceStore()
  • Method Details

    • getName

      public String getName()
      Returns:
      the name for this instance (built from container name)
    • getStoreName

      public String getStoreName()
      Overrides:
      getStoreName in class StoreBase
      Returns:
      the name for this Store, used for logging.
    • setSessionTable

      public void setSessionTable(String sessionTable)
      Set the table for this Store.
      Parameters:
      sessionTable - The new table
    • getSessionTable

      public String getSessionTable()
      Returns:
      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()
      Returns:
      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()
      Returns:
      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()
      Returns:
      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()
      Returns:
      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()
      Returns:
      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()
      Returns:
      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()
      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 to true to cause the datasource to be looked up in the webapp JNDI Context.
      Parameters:
      localDataSource - the new flag value
    • 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 StoreBase
      Returns:
      list of session keys, that are to be expired
      Throws:
      IOException - if an input-/output error occurred
    • keys

      public String[] keys() throws IOException
      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
      Return an integer containing a count of all Sessions currently saved in this Store. If there are no Sessions, 0 is 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 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 Store.
      Returns:
      database connection ready to use
      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