Interface JdbcSessionRepositoryDialect

All Known Implementing Classes:
H2JdbcSessionRepositoryDialect, MysqlJdbcSessionRepositoryDialect, PostgresJdbcSessionRepositoryDialect, SqlServerJdbcSessionRepositoryDialect

public interface JdbcSessionRepositoryDialect
The SQL that differs between databases, for JdbcSessionRepository: the upsert and the insert-if-absent of a session, and the clause that limits a query's rows. Every other statement is shared and lives in the repository. from(DataSource) detects the dialect from the database metadata.
Since:
2.1.0
Author:
Christian Tzolov
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    from(DataSource dataSource)
    The dialect of the database the data source connects to, from its product name: PostgreSQL, H2, MySQL, MariaDB or Microsoft SQL Server.
    default String
    Inserts a row into AI_SESSION only if its id does not exist, with the same four parameters as getUpsertSessionSql(): one row updated on insert, zero rows or a duplicate-key error when the id exists.
    default String
    The predicate of a keyword search: whether the text of an event's message contains a keyword, ignoring case.
    default String
    The clause appended after a query's ORDER BY to keep at most as many rows as its single parameter, bound last.
    Inserts a row into AI_SESSION or updates the existing one, refreshing only expires_at and metadata: created_at keeps its value and event_version is never touched.
    default String
    The value bound to the parameter of 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.
  • Method Details

    • getUpsertSessionSql

      String getUpsertSessionSql()
      Inserts a row into AI_SESSION or updates the existing one, refreshing only expires_at and metadata: created_at keeps its value and event_version is never touched. Parameters, in order: id, created_at, expires_at, metadata.
    • getInsertSessionIfAbsentSql

      default String getInsertSessionIfAbsentSql()
      Inserts a row into AI_SESSION only if its id does not exist, with the same four parameters as getUpsertSessionSql(): one row updated on insert, zero rows or a duplicate-key error when the id exists. The default is a plain INSERT; a database whose failed statement aborts the enclosing transaction, PostgreSQL always and SQL Server with XACT_ABORT ON, uses a form that inserts nothing instead.
    • getLimitClause

      default String getLimitClause()
      The clause appended after a query's ORDER BY to keep at most as many rows as its single parameter, bound last. The default, LIMIT ?, serves PostgreSQL, H2, MySQL and MariaDB; a database without LIMIT returns its own form, such as OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY.
    • getKeywordPredicate

      default String getKeywordPredicate()
      The predicate of a keyword search: whether the text of an event's message contains a keyword, ignoring case. A predicate over the event row with the alias e, with one parameter and no leading AND; the repository repeats it per keyword and binds each parameter to toKeywordParameter(String). The default is a LIKE with ! as the escape character that lower-cases both the message_content and the parameter in the database, so that the two sides are folded by the same rules. It serves every supported database.
    • toKeywordParameter

      default String toKeywordParameter(String keyword)
      The value bound to the parameter of 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 whose LIKE knows more wildcards escapes them too.
    • from

      static JdbcSessionRepositoryDialect from(DataSource dataSource)
      The dialect of the database the data source connects to, from its product name: PostgreSQL, H2, MySQL, MariaDB or Microsoft SQL Server.
      Throws:
      IllegalStateException - if the product name cannot be read or the database is not supported; set the dialect with JdbcSessionRepository.Builder.dialect(JdbcSessionRepositoryDialect) then