public class QueryExecutor extends Object
Modifier and Type | Class and Description |
---|---|
(package private) static interface |
QueryExecutor.Cancelable
Interface to be implemented by classes that knows how to cancel
a query.
|
(package private) static class |
QueryExecutor.CancelableSession
Cancels the query running in a Hibernate session.
|
(package private) static class |
QueryExecutor.CancelableStatelessSession
Cancels a query running in a stateless Hibernate session.
|
(package private) static class |
QueryExecutor.CancelableStatement
Cancels a statement by calling
Statement.cancel() . |
(package private) static class |
QueryExecutor.FutureItem<T> |
(package private) static class |
QueryExecutor.FutureResultSet
A callable implementation the calls
PreparedStatement.executeQuery() |
(package private) static class |
QueryExecutor.FutureScrollIterator<T>
Calls
Query.scroll(ScrollMode) and returns the result as a
ScrollIterator . |
(package private) static class |
QueryExecutor.FutureUpdate
A callable implementation the calls
PreparedStatement.executeUpdate() |
Modifier and Type | Field and Description |
---|---|
private static ExecutorService |
service |
Constructor and Description |
---|
QueryExecutor() |
Modifier and Type | Method and Description |
---|---|
static ResultSet |
executeQuery(PreparedStatement ps,
SessionControl sc)
Execute a query by calling
PreparedStatement.executeQuery() . |
static int |
executeUpdate(PreparedStatement ps,
SessionControl sc)
Execute a query by calling
PreparedStatement.executeUpdate() . |
private static <T> T |
getFutureResult(Callable<T> callable,
QueryExecutor.Cancelable cancelable,
SessionControl sc)
Run the callable and wait for the result.
|
(package private) static void |
init()
This will create a new thread for each query.
|
static <T> T |
loadData(Class<T> clazz,
Query query,
StatelessSession session,
SessionControl sc)
Executes a Hibernate query on a stateless session.
|
static <T> ScrollIterator<T> |
loadIterator(Class<T> clazz,
Query query,
StatelessSession session,
SessionControl sc)
Executes a Hibernate query that returns an iterator on a stateless session.
|
(package private) static void |
unload() |
private static ExecutorService service
static void init()
static void unload()
public static ResultSet executeQuery(PreparedStatement ps, SessionControl sc) throws InterruptedException, SQLException
PreparedStatement.executeQuery()
.ps
- The prepared statement to executesc
- A session control object that should be kept alive while the
query is executing, or nullPreparedStatement.executeQuery()
InterruptedException
- If this thread was interruptedSQLException
- If there was an error executing the SQL statementpublic static int executeUpdate(PreparedStatement ps, SessionControl sc) throws InterruptedException, SQLException
PreparedStatement.executeUpdate()
.ps
- The prepared statement to executesc
- A session control object that should be kept alive while the
query is executing, or nullPreparedStatement.executeUpdate()
InterruptedException
- If this thread was interruptedSQLException
public static <T> ScrollIterator<T> loadIterator(Class<T> clazz, Query query, StatelessSession session, SessionControl sc) throws InterruptedException
clazz
- The class of items returned by the iteratorquery
- The query to executesession
- The stateless session, this must be the same session
that was used to create the querysc
- A session control object that should be kept alive while the
query is executing, or nullInterruptedException
public static <T> T loadData(Class<T> clazz, Query query, StatelessSession session, SessionControl sc) throws InterruptedException
clazz
- The class of items returned by the iteratorquery
- The query to executesession
- The stateless session, this must be the same session
that was used to create the querysc
- A session control object that should be kept alive while the
query is executing, or nullInterruptedException
private static <T> T getFutureResult(Callable<T> callable, QueryExecutor.Cancelable cancelable, SessionControl sc) throws InterruptedException, SQLException
T
- The type of result that is returned by the callablecallable
- The procedure to callcancelable
- An object that know how to cancel the running query if this
thread is interruptedsc
- A session control object that should be kept alive while the
query is executing, or nullInterruptedException
- If this thread was interrupted during the querySQLException