Package com.networknt.session.jdbc
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>
ASessionRepositoryimplementation 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 Summary
Constructors Constructor Description JdbcSessionRepository(DataSource dataSource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanUpExpiredSessions()com.networknt.session.jdbc.JdbcSessionRepository.JdbcSessioncreateSession()voiddeleteById(String id)List<com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession>extractData(ResultSet rs)com.networknt.session.jdbc.JdbcSessionRepository.JdbcSessionfindById(String id)Map<String,Session>getSessions()voidsave(com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession session)voidsetDefaultMaxInactiveInterval(int defaultMaxInactiveInterval)Set the maximum inactive interval in seconds between requests before newly created sessions will be invalidated.voidupdateSessionLastAccessTime(String id)
-
-
-
Constructor Detail
-
JdbcSessionRepository
public JdbcSessionRepository(DataSource dataSource)
-
-
Method Detail
-
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:
createSessionin interfaceSessionRepository<com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession>
-
save
public void save(com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession session)
- Specified by:
savein interfaceSessionRepository<com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession>
-
findById
public com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession findById(String id)
- Specified by:
findByIdin interfaceSessionRepository<com.networknt.session.jdbc.JdbcSessionRepository.JdbcSession>
-
deleteById
public void deleteById(String id)
- Specified by:
deleteByIdin interfaceSessionRepository<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
-
-