Class HibernateTopiaSqlSupport

java.lang.Object
org.nuiton.topia.persistence.internal.support.HibernateTopiaSqlSupport
All Implemented Interfaces:
TopiaSqlSupport

public class HibernateTopiaSqlSupport extends Object implements TopiaSqlSupport
Hibernate-based implementation of TopiaSqlSupport. It is used through Topia or directly with an Hibernate Session.
Since:
3.0
Author:
Arnaud Thimel (Code Lutin)
  • Field Details

    • hibernateSupport

      protected TopiaHibernateSupport hibernateSupport
    • session

      protected org.hibernate.Session session
    • slowQueriesThreshold

      protected Optional<Duration> slowQueriesThreshold
      Delay after which Topia should consider a query as slow then log a warn. If no value is present, the slow queries won't be tracked.
      Since:
      3.8
  • Constructor Details

    • HibernateTopiaSqlSupport

      public HibernateTopiaSqlSupport(TopiaHibernateSupport hibernateSupport, Optional<Duration> slowQueriesThreshold)
    • HibernateTopiaSqlSupport

      public HibernateTopiaSqlSupport(org.hibernate.Session session)
  • Method Details

    • setSlowQueriesThreshold

      public void setSlowQueriesThreshold(Duration slowQueriesThreshold)
      Description copied from interface: TopiaSqlSupport
      Tells to the context after which delay a query should be considered as slow. Default value is to skip slow queries watching unless specified in application configuration.
      Specified by:
      setSlowQueriesThreshold in interface TopiaSqlSupport
      Parameters:
      slowQueriesThreshold - the new value to set
    • monitorWork

      protected SlowQueryWatcher monitorWork(org.hibernate.jdbc.Work query)
    • executeSql

      public void executeSql(String sqlScript)
      Description copied from interface: TopiaSqlSupport
      Execute a given SQL code inside this transaction.
      Specified by:
      executeSql in interface TopiaSqlSupport
      Parameters:
      sqlScript - the sql script to execute
    • getHibernateSession

      protected org.hibernate.Session getHibernateSession()
    • doSqlWork

      public void doSqlWork(TopiaSqlWork sqlWork)
      Description copied from interface: TopiaSqlSupport
      Runs the given SQL work on the current context
      Specified by:
      doSqlWork in interface TopiaSqlSupport
      Parameters:
      sqlWork - the SQL work instance to execute
    • findSingleResult

      public <O> O findSingleResult(TopiaSqlQuery<O> query) throws TopiaException
      Description copied from interface: TopiaSqlSupport
      Runs the given SQL query and return its first result if there is some.
      Specified by:
      findSingleResult in interface TopiaSqlSupport
      Type Parameters:
      O - type of result
      Parameters:
      query - query to play
      Returns:
      the single result or null if none found.
      Throws:
      TopiaException - for any pb
    • findSingleResult

      public <O> O findSingleResult(SqlFunction<Connection,PreparedStatement> preparer, SqlFunction<ResultSet,O> transformer) throws TopiaException
      Description copied from interface: TopiaSqlSupport
      Runs the given SQL query and return its first result if there is some.
      Specified by:
      findSingleResult in interface TopiaSqlSupport
      Type Parameters:
      O - type of result
      Parameters:
      preparer - function to prepare the query
      transformer - function to transform the ResultSet into the expected element
      Returns:
      the single result or null if none found.
      Throws:
      TopiaException - for any pb
    • findSingleResult

      public <O> O findSingleResult(String sql, SqlFunction<ResultSet,O> transformer) throws TopiaException
      Description copied from interface: TopiaSqlSupport
      Runs the given SQL query and return its first result if there is some.
      Specified by:
      findSingleResult in interface TopiaSqlSupport
      Type Parameters:
      O - type of result
      Parameters:
      sql - the sql query
      transformer - function to transform the ResultSet into the expected element
      Returns:
      the single result or null if none found.
      Throws:
      TopiaException - for any pb
    • findMultipleResult

      public <O> List<O> findMultipleResult(TopiaSqlQuery<O> query) throws TopiaException
      Description copied from interface: TopiaSqlSupport
      Runs the given SQL query and return all his result if there is some.
      Specified by:
      findMultipleResult in interface TopiaSqlSupport
      Type Parameters:
      O - type of result
      Parameters:
      query - query to play
      Returns:
      the list of results (the list is empty if query returns no result).
      Throws:
      TopiaException - for any pb
    • findMultipleResult

      public <O> List<O> findMultipleResult(SqlFunction<Connection,PreparedStatement> preparer, SqlFunction<ResultSet,O> transformer) throws TopiaException
      Description copied from interface: TopiaSqlSupport
      Runs the given SQL query and return all his result if there is some.
      Specified by:
      findMultipleResult in interface TopiaSqlSupport
      Type Parameters:
      O - type of result
      Parameters:
      preparer - function to prepare the query
      transformer - function to transform the ResultSet into the expected element
      Returns:
      the list of results (the list is empty if query returns no result).
      Throws:
      TopiaException - for any pb
    • findMultipleResult

      public <O> List<O> findMultipleResult(String sql, SqlFunction<ResultSet,O> transformer) throws TopiaException
      Description copied from interface: TopiaSqlSupport
      Runs the given SQL query and return all his result if there is some.
      Specified by:
      findMultipleResult in interface TopiaSqlSupport
      Type Parameters:
      O - type of result
      Parameters:
      sql - the sql query
      transformer - function to transform the ResultSet into the expected element
      Returns:
      the list of results (the list is empty if query returns no result).
      Throws:
      TopiaException - for any pb