Class MongoIndexedSessionRepository
java.lang.Object
org.springframework.session.data.mongo.MongoIndexedSessionRepository
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.ApplicationEventPublisherAware
,FindByIndexNameSessionRepository<MongoSession>
,SessionRepository<MongoSession>
- Direct Known Subclasses:
MongoOperationsSessionRepository
public class MongoIndexedSessionRepository
extends Object
implements FindByIndexNameSessionRepository<MongoSession>, org.springframework.context.ApplicationEventPublisherAware, org.springframework.beans.factory.InitializingBean
Session repository implementation which stores sessions in Mongo. Uses
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.- Since:
- 2.2.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
the default collection name for storing session.static final int
The default time period in seconds in which a session will expire.Fields inherited from interface org.springframework.session.FindByIndexNameSessionRepository
PRINCIPAL_NAME_INDEX_NAME
-
Constructor Summary
ConstructorDescriptionMongoIndexedSessionRepository
(org.springframework.data.mongodb.core.MongoOperations mongoOperations) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Creates a newSession
that is capable of being persisted by thisSessionRepository
.void
deleteById
(String id) findByIndexNameAndIndexValue
(String indexName, String indexValue) Currently this repository allows only querying againstPRINCIPAL_NAME_INDEX_NAME
.void
save
(MongoSession session) Ensures theSession
created bySessionRepository.createSession()
is saved.void
setApplicationEventPublisher
(org.springframework.context.ApplicationEventPublisher eventPublisher) void
setCollectionName
(String collectionName) void
setMaxInactiveIntervalInSeconds
(Integer maxInactiveIntervalInSeconds) void
setMongoSessionConverter
(AbstractMongoSessionConverter mongoSessionConverter) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.session.FindByIndexNameSessionRepository
findByPrincipalName
-
Field Details
-
DEFAULT_INACTIVE_INTERVAL
public static final int DEFAULT_INACTIVE_INTERVALThe default time period in seconds in which a session will expire.- See Also:
-
DEFAULT_COLLECTION_NAME
the default collection name for storing session.- See Also:
-
-
Constructor Details
-
MongoIndexedSessionRepository
public MongoIndexedSessionRepository(org.springframework.data.mongodb.core.MongoOperations mongoOperations)
-
-
Method Details
-
createSession
Description copied from interface:SessionRepository
Creates a newSession
that is capable of being persisted by thisSessionRepository
.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.- Specified by:
createSession
in interfaceSessionRepository<MongoSession>
- Returns:
- a new
Session
that is capable of being persisted by thisSessionRepository
-
save
Description copied from interface:SessionRepository
Ensures theSession
created bySessionRepository.createSession()
is saved.Some implementations may choose to save as the
Session
is updated by returning aSession
that immediately persists any changes. In this case, this method may not actually do anything.- Specified by:
save
in interfaceSessionRepository<MongoSession>
- Parameters:
session
- theSession
to save
-
findById
Description copied from interface:SessionRepository
- Specified by:
findById
in interfaceSessionRepository<MongoSession>
- Parameters:
id
- theSession.getId()
to lookup- Returns:
- the
Session
by theSession.getId()
or null if noSession
is found.
-
findByIndexNameAndIndexValue
Currently this repository allows only querying againstPRINCIPAL_NAME_INDEX_NAME
.- Specified by:
findByIndexNameAndIndexValue
in interfaceFindByIndexNameSessionRepository<MongoSession>
- Parameters:
indexName
- the name if the index (i.e.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME
)indexValue
- the value of the index to search for.- Returns:
- sessions map
-
deleteById
Description copied from interface:SessionRepository
- Specified by:
deleteById
in interfaceSessionRepository<MongoSession>
- Parameters:
id
- theSession.getId()
to delete
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
setApplicationEventPublisher
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher) - Specified by:
setApplicationEventPublisher
in interfaceorg.springframework.context.ApplicationEventPublisherAware
-
setMaxInactiveIntervalInSeconds
-
setCollectionName
-
setMongoSessionConverter
-