Backport of #1545: Session creation with pre-specified id. #1544
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request address specific use-case of creating session with pre-specified id.
While standard
SessionRepository
interfaces provides means of creating session viacreateSession()
- it does noting to let you control the 'id' creation process. All known to me implementation ofSessionRepository
(Redis,Hazelcast,Jdbc
) fallback to callingMapSession
and what is peculiarMapSession
supports creating session object with externally defined id - via its secondary construtor -new MapSession(id)
.However all implementations (
Redis,Hazelcast,Jdbc
) fallback to using the default construtor which in its default bahaviour callsUUID.randomUUID().toString()
. While this provides necessary uniqueness to id (provied low probability of UUID ever repeating) it leaves us without controll over this process.There are quite a few business casses when internaly created id would not be desired :
We don't want to break any existing functionality (keeping
SessionRepository
as clean as possible) - here comesCreateWithIdSessionRepository
- it expands default implementation with ability to create session with pre-specified id viaS createSession(@Nullable String id);
the same way
FindByIndexNameSessionRepository
expands session repository with ability to find session with principal/indexName.I took upon myself implementing this interfaces in 3 most common used implementations
(Redis,Hazelcast,Jdbc)
since it does not break any existing functionality while still providing benefit on controlling this process by adhering to proper interface.There are no reasons it could not be supported in other available implementations.
PS. Sorry for my english. English is not my primary language.
If you have any suggestions on how i could improve my approach or would like to ask me a question - feel free to contact me. My email - [email protected]