public class MongoOperationsSessionRepository extends java.lang.Object implements FindByIndexNameSessionRepository<MongoExpiringSession>
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 |
---|
MongoOperationsSessionRepository(org.springframework.data.mongodb.core.MongoOperations mongoOperations) |
Modifier and Type | Method and Description |
---|---|
MongoExpiringSession |
createSession()
Creates a new
Session that is capable of being persisted by this
SessionRepository . |
void |
delete(java.lang.String id)
|
void |
ensureIndexesAreCreated() |
java.util.Map<java.lang.String,MongoExpiringSession> |
findByIndexNameAndIndexValue(java.lang.String indexName,
java.lang.String indexValue)
Currently this repository allows only querying against
PRINCIPAL_NAME_INDEX_NAME . |
MongoExpiringSession |
getSession(java.lang.String id)
|
void |
save(MongoExpiringSession session)
Ensures the
Session created by
SessionRepository.createSession() is saved. |
void |
setCollectionName(java.lang.String collectionName) |
void |
setMaxInactiveIntervalInSeconds(java.lang.Integer maxInactiveIntervalInSeconds) |
void |
setMongoSessionConverter(AbstractMongoSessionConverter mongoSessionConverter) |
public static final int DEFAULT_INACTIVE_INTERVAL
public static final java.lang.String DEFAULT_COLLECTION_NAME
public MongoOperationsSessionRepository(org.springframework.data.mongodb.core.MongoOperations mongoOperations)
public MongoExpiringSession 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<MongoExpiringSession>
Session
that is capable of being persisted by this
SessionRepository
public void save(MongoExpiringSession 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<MongoExpiringSession>
session
- the Session
to savepublic MongoExpiringSession getSession(java.lang.String id)
SessionRepository
getSession
in interface SessionRepository<MongoExpiringSession>
id
- the Session.getId()
to lookupSession
by the Session.getId()
or null if no
Session
is found.public java.util.Map<java.lang.String,MongoExpiringSession> findByIndexNameAndIndexValue(java.lang.String indexName, java.lang.String indexValue)
PRINCIPAL_NAME_INDEX_NAME
.findByIndexNameAndIndexValue
in interface FindByIndexNameSessionRepository<MongoExpiringSession>
indexName
- the name if the index (i.e.
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME
)indexValue
- the value of the index to search for.public void delete(java.lang.String id)
SessionRepository
delete
in interface SessionRepository<MongoExpiringSession>
id
- the Session.getId()
to delete@PostConstruct public void ensureIndexesAreCreated()
public void setMongoSessionConverter(AbstractMongoSessionConverter mongoSessionConverter)
public void setMaxInactiveIntervalInSeconds(java.lang.Integer maxInactiveIntervalInSeconds)
public void setCollectionName(java.lang.String collectionName)