Package tech.muyan.utils
Class QueryHelper
- java.lang.Object
-
- tech.muyan.utils.QueryHelper
-
public class QueryHelper extends java.lang.ObjectA utility class that provides methods for executing database queries using Groovy's Sql class.
-
-
Constructor Summary
Constructors Constructor Description QueryHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TwithNewSession(groovy.lang.Closure<T> closure)Executes a closure within the context of a new database session.static <T> TwithSession(groovy.lang.Closure<T> closure)Executes a closure within the context of an existing database session.static <T> TwithSql(java.util.function.Function<groovy.sql.Sql,T> function)Executes a function that takes a Sql instance as a parameter and returns a result.static <T> TwithTransaction(groovy.lang.Closure<T> closure)Executes a closure within the context of a transaction using an existing database session.
-
-
-
Method Detail
-
withSession
public static <T> T withSession(groovy.lang.Closure<T> closure)
Executes a closure within the context of an existing database session.- Type Parameters:
T- the return type of the closure- Parameters:
closure- the closure to be executed- Returns:
- the result of executing the closure
- Throws:
java.lang.IllegalStateException- if the method is called directly from the library
-
withNewSession
public static <T> T withNewSession(groovy.lang.Closure<T> closure)
Executes a closure within the context of a new database session.- Type Parameters:
T- the return type of the closure- Parameters:
closure- the closure to be executed- Returns:
- the result of executing the closure
- Throws:
java.lang.IllegalStateException- if the method is called directly from the library
-
withTransaction
public static <T> T withTransaction(groovy.lang.Closure<T> closure)
Executes a closure within the context of a transaction using an existing database session.- Type Parameters:
T- the return type of the closure- Parameters:
closure- the closure to be executed- Returns:
- the result of executing the closure
- Throws:
java.lang.IllegalStateException- if the method is called directly from the library
-
withSql
public static <T> T withSql(java.util.function.Function<groovy.sql.Sql,T> function)
Executes a function that takes a Sql instance as a parameter and returns a result.- Type Parameters:
T- the return type of the function- Parameters:
function- the function to be executed- Returns:
- the result of executing the function
- Throws:
java.lang.IllegalStateException- if the method is called directly from the library
-
-