Class SqlServerJdbcSessionRepositoryDialect
- All Implemented Interfaces:
JdbcSessionRepositoryDialect
The upsert and the insert-if-absent are a MERGE under HOLDLOCK, so that
two concurrent saves of a new id cannot both take the insert branch. The lock covers
the key range around the id and is held until the transaction ends: in a caller's
transaction that stays open, an insert of another new id into that range and a write to
the next session in key order wait for it. The insert-if-absent is not a plain
INSERT, because its duplicate-key error would roll an enclosing transaction
back on a connection with XACT_ABORT ON.
The timestamps and the metadata are cast so that a null expiry keeps its column
type. The id is not: a cast silently cuts a value longer than its type, to the id of
another session at worst, whereas the insert of an over-long id is rejected. SQL Server
has no LIMIT; rows are limited with OFFSET ... FETCH.
- Since:
- 2.1.0
- Author:
- Durga Dasepalli, Christian Tzolov
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionInserts a row intoAI_SESSIONonly if its id does not exist, with the same four parameters asJdbcSessionRepositoryDialect.getUpsertSessionSql(): one row updated on insert, zero rows or a duplicate-key error when the id exists.The clause appended after a query'sORDER BYto keep at most as many rows as its single parameter, bound last.Inserts a row intoAI_SESSIONor updates the existing one, refreshing onlyexpires_atandmetadata:created_atkeeps its value andevent_versionis never touched.toKeywordParameter(String keyword) The value bound to the parameter ofJdbcSessionRepositoryDialect.getKeywordPredicate()for a keyword: by default the keyword between two%, with!,%and_escaped by!, so that a keyword is matched as text and never as a pattern.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.ai.session.jdbc.JdbcSessionRepositoryDialect
getKeywordPredicate
-
Constructor Details
-
SqlServerJdbcSessionRepositoryDialect
public SqlServerJdbcSessionRepositoryDialect()
-
-
Method Details
-
getUpsertSessionSql
Description copied from interface:JdbcSessionRepositoryDialectInserts a row intoAI_SESSIONor updates the existing one, refreshing onlyexpires_atandmetadata:created_atkeeps its value andevent_versionis never touched. Parameters, in order:id,created_at,expires_at,metadata.- Specified by:
getUpsertSessionSqlin interfaceJdbcSessionRepositoryDialect
-
getInsertSessionIfAbsentSql
Description copied from interface:JdbcSessionRepositoryDialectInserts a row intoAI_SESSIONonly if its id does not exist, with the same four parameters asJdbcSessionRepositoryDialect.getUpsertSessionSql(): one row updated on insert, zero rows or a duplicate-key error when the id exists. The default is a plainINSERT; a database whose failed statement aborts the enclosing transaction, PostgreSQL always and SQL Server withXACT_ABORT ON, uses a form that inserts nothing instead.- Specified by:
getInsertSessionIfAbsentSqlin interfaceJdbcSessionRepositoryDialect
-
getLimitClause
Description copied from interface:JdbcSessionRepositoryDialectThe clause appended after a query'sORDER BYto keep at most as many rows as its single parameter, bound last. The default,LIMIT ?, serves PostgreSQL, H2, MySQL and MariaDB; a database withoutLIMITreturns its own form, such asOFFSET 0 ROWS FETCH NEXT ? ROWS ONLY.- Specified by:
getLimitClausein interfaceJdbcSessionRepositoryDialect
-
toKeywordParameter
Description copied from interface:JdbcSessionRepositoryDialectThe value bound to the parameter ofJdbcSessionRepositoryDialect.getKeywordPredicate()for a keyword: by default the keyword between two%, with!,%and_escaped by!, so that a keyword is matched as text and never as a pattern. A database whoseLIKEknows more wildcards escapes them too.- Specified by:
toKeywordParameterin interfaceJdbcSessionRepositoryDialect
-