Class HibernateTopiaSqlSupport
java.lang.Object
org.nuiton.topia.persistence.internal.support.HibernateTopiaSqlSupport
- All Implemented Interfaces:
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)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TopiaHibernateSupportprotected org.hibernate.SessionDelay after which Topia should consider a query as slow then log a warn. -
Constructor Summary
ConstructorsConstructorDescriptionHibernateTopiaSqlSupport(org.hibernate.Session session) HibernateTopiaSqlSupport(TopiaHibernateSupport hibernateSupport, Optional<Duration> slowQueriesThreshold) -
Method Summary
Modifier and TypeMethodDescriptionvoiddoSqlWork(TopiaSqlWork sqlWork) Runs the given SQL work on the current contextvoidexecuteSql(String sqlScript) Execute a given SQL code inside this transaction.<O> List<O>findMultipleResult(String sql, SqlFunction<ResultSet, O> transformer) Runs the given SQL query and return all his result if there is some.<O> List<O>findMultipleResult(SqlFunction<Connection, PreparedStatement> preparer, SqlFunction<ResultSet, O> transformer) Runs the given SQL query and return all his result if there is some.<O> List<O>findMultipleResult(TopiaSqlQuery<O> query) Runs the given SQL query and return all his result if there is some.<O> OfindSingleResult(String sql, SqlFunction<ResultSet, O> transformer) Runs the given SQL query and return its first result if there is some.<O> OfindSingleResult(SqlFunction<Connection, PreparedStatement> preparer, SqlFunction<ResultSet, O> transformer) Runs the given SQL query and return its first result if there is some.<O> OfindSingleResult(TopiaSqlQuery<O> query) Runs the given SQL query and return its first result if there is some.protected org.hibernate.Sessionprotected SlowQueryWatchermonitorWork(org.hibernate.jdbc.Work query) voidsetSlowQueriesThreshold(Duration slowQueriesThreshold) Tells to the context after which delay a query should be considered as slow.
-
Field Details
-
hibernateSupport
-
session
protected org.hibernate.Session session -
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
Description copied from interface:TopiaSqlSupportTells 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:
setSlowQueriesThresholdin interfaceTopiaSqlSupport- Parameters:
slowQueriesThreshold- the new value to set
-
monitorWork
-
executeSql
Description copied from interface:TopiaSqlSupportExecute a given SQL code inside this transaction.- Specified by:
executeSqlin interfaceTopiaSqlSupport- Parameters:
sqlScript- the sql script to execute
-
getHibernateSession
protected org.hibernate.Session getHibernateSession() -
doSqlWork
Description copied from interface:TopiaSqlSupportRuns the given SQL work on the current context- Specified by:
doSqlWorkin interfaceTopiaSqlSupport- Parameters:
sqlWork- the SQL work instance to execute
-
findSingleResult
Description copied from interface:TopiaSqlSupportRuns the given SQL query and return its first result if there is some.- Specified by:
findSingleResultin interfaceTopiaSqlSupport- Type Parameters:
O- type of result- Parameters:
query- query to play- Returns:
- the single result or
nullif none found. - Throws:
TopiaException- for any pb
-
findSingleResult
public <O> O findSingleResult(SqlFunction<Connection, PreparedStatement> preparer, SqlFunction<ResultSet, throws TopiaExceptionO> transformer) Description copied from interface:TopiaSqlSupportRuns the given SQL query and return its first result if there is some.- Specified by:
findSingleResultin interfaceTopiaSqlSupport- Type Parameters:
O- type of result- Parameters:
preparer- function to prepare the querytransformer- function to transform the ResultSet into the expected element- Returns:
- the single result or
nullif none found. - Throws:
TopiaException- for any pb
-
findSingleResult
public <O> O findSingleResult(String sql, SqlFunction<ResultSet, O> transformer) throws TopiaExceptionDescription copied from interface:TopiaSqlSupportRuns the given SQL query and return its first result if there is some.- Specified by:
findSingleResultin interfaceTopiaSqlSupport- Type Parameters:
O- type of result- Parameters:
sql- the sql querytransformer- function to transform the ResultSet into the expected element- Returns:
- the single result or
nullif none found. - Throws:
TopiaException- for any pb
-
findMultipleResult
Description copied from interface:TopiaSqlSupportRuns the given SQL query and return all his result if there is some.- Specified by:
findMultipleResultin interfaceTopiaSqlSupport- 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, throws TopiaExceptionO> transformer) Description copied from interface:TopiaSqlSupportRuns the given SQL query and return all his result if there is some.- Specified by:
findMultipleResultin interfaceTopiaSqlSupport- Type Parameters:
O- type of result- Parameters:
preparer- function to prepare the querytransformer- 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 TopiaExceptionDescription copied from interface:TopiaSqlSupportRuns the given SQL query and return all his result if there is some.- Specified by:
findMultipleResultin interfaceTopiaSqlSupport- Type Parameters:
O- type of result- Parameters:
sql- the sql querytransformer- 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
-