Class JdbcSessionRepository

java.lang.Object
com.networknt.session.jdbc.JdbcSessionRepository
All Implemented Interfaces:
SessionRepository<com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession>

public class JdbcSessionRepository extends Object implements SessionRepository<com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession>
A SessionRepository implementation that uses Database to store sessions in a relational database. This implementation does not support publishing of session events.

An example of how to create a new instance can be seen below:


 JdbcSessionRepository sessionRepository =
 new JdbcSessionRepository(dataSource);
 

Depending on your database, the table definition can be described as below:

 CREATE TABLE light_session (
 session_id VARCHAR2(100) NOT NULL,
 creation_time bigint NOT NULL,
 last_access_time bigint NOT NULL,
 max_inactive_interval int,
 expiry_time bigint,
 principal_name VARCHAR(100),
 PRIMARY KEY(session_id)
 );

 CREATE TABLE light_session_attributes (
 session_id VARCHAR2(100) NOT NULL,
 attribute_name VARCHAR(200) NOT NULL,
 attribute_bytes BYTEA,
 PRIMARY KEY(session_id, attribute_name)
 );
 
  • Constructor Details

    • JdbcSessionRepository

      public JdbcSessionRepository(DataSource dataSource)
  • Method Details

    • setDefaultMaxInactiveInterval

      public void setDefaultMaxInactiveInterval(int defaultMaxInactiveInterval)
      Set the maximum inactive interval in seconds between requests before newly created sessions will be invalidated. A negative time indicates that the session will never timeout. The default is 1800 (30 minutes).
      Parameters:
      defaultMaxInactiveInterval - the maximum inactive interval in seconds
    • createSession

      public com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession createSession()
      Specified by:
      createSession in interface SessionRepository<com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession>
    • getSessions

      public Map<String,Session> getSessions()
    • save

      public void save(com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession session)
      Specified by:
      save in interface SessionRepository<com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession>
    • findById

      public com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession findById(String id)
      Specified by:
      findById in interface SessionRepository<com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession>
    • deleteById

      public void deleteById(String id)
      Specified by:
      deleteById in interface SessionRepository<com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession>
    • cleanUpExpiredSessions

      public void cleanUpExpiredSessions()
    • updateSessionLastAccessTime

      public void updateSessionLastAccessTime(String id)
    • extractData

      public List<com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession> extractData(ResultSet rs) throws SQLException
      Throws:
      SQLException