public class MongoIndexedSessionRepository extends java.lang.Object implements FindByIndexNameSessionRepository<MongoSession>, org.springframework.context.ApplicationEventPublisherAware, org.springframework.beans.factory.InitializingBean
AbstractMongoSessionConverter
to transform session objects from/to native Mongo
representation (DBObject
). Repository is also responsible for removing expired
sessions from database. Cleanup is done every minute.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_COLLECTION_NAME
the default collection name for storing session.
|
static int |
DEFAULT_INACTIVE_INTERVAL
The default time period in seconds in which a session will expire.
|
PRINCIPAL_NAME_INDEX_NAME
Constructor and Description |
---|
MongoIndexedSessionRepository(org.springframework.data.mongodb.core.MongoOperations mongoOperations) |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
MongoSession |
createSession()
Creates a new
Session that is capable of being persisted by this
SessionRepository . |
void |
deleteById(java.lang.String id)
|
MongoSession |
findById(java.lang.String id)
|
java.util.Map<java.lang.String,MongoSession> |
findByIndexNameAndIndexValue(java.lang.String indexName,
java.lang.String indexValue)
Currently this repository allows only querying against
PRINCIPAL_NAME_INDEX_NAME . |
void |
save(MongoSession session)
Ensures the
Session created by
SessionRepository.createSession() is saved. |
void |
setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher) |
void |
setCollectionName(java.lang.String collectionName) |
void |
setMaxInactiveIntervalInSeconds(java.lang.Integer maxInactiveIntervalInSeconds) |
void |
setMongoSessionConverter(AbstractMongoSessionConverter mongoSessionConverter) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
findByPrincipalName
public static final int DEFAULT_INACTIVE_INTERVAL
public static final java.lang.String DEFAULT_COLLECTION_NAME
public MongoIndexedSessionRepository(org.springframework.data.mongodb.core.MongoOperations mongoOperations)
public MongoSession createSession()
SessionRepository
Session
that is capable of being persisted by this
SessionRepository
.
This allows optimizations and customizations in how the Session
is
persisted. For example, the implementation returned might keep track of the changes
ensuring that only the delta needs to be persisted on a save.
createSession
in interface SessionRepository<MongoSession>
Session
that is capable of being persisted by this
SessionRepository
public void save(MongoSession session)
SessionRepository
Session
created by
SessionRepository.createSession()
is saved.
Some implementations may choose to save as the Session
is updated by
returning a Session
that immediately persists any changes. In this case,
this method may not actually do anything.
save
in interface SessionRepository<MongoSession>
session
- the Session
to save@Nullable public MongoSession findById(java.lang.String id)
SessionRepository
findById
in interface SessionRepository<MongoSession>
id
- the Session.getId()
to lookupSession
by the Session.getId()
or null if no
Session
is found.public java.util.Map<java.lang.String,MongoSession> findByIndexNameAndIndexValue(java.lang.String indexName, java.lang.String indexValue)
PRINCIPAL_NAME_INDEX_NAME
.findByIndexNameAndIndexValue
in interface FindByIndexNameSessionRepository<MongoSession>
indexName
- the name if the index (i.e.
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME
)indexValue
- the value of the index to search for.public void deleteById(java.lang.String id)
SessionRepository
deleteById
in interface SessionRepository<MongoSession>
id
- the Session.getId()
to deletepublic void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher)
setApplicationEventPublisher
in interface org.springframework.context.ApplicationEventPublisherAware
public void setMaxInactiveIntervalInSeconds(java.lang.Integer maxInactiveIntervalInSeconds)
public void setCollectionName(java.lang.String collectionName)
public void setMongoSessionConverter(AbstractMongoSessionConverter mongoSessionConverter)