public class QueryExecutor
extends java.lang.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 java.util.concurrent.ExecutorService |
service |
Constructor and Description |
---|
QueryExecutor() |
Modifier and Type | Method and Description |
---|---|
static java.sql.ResultSet |
executeQuery(java.sql.PreparedStatement ps,
SessionControl sc)
Execute a query by calling
PreparedStatement.executeQuery() . |
static int |
executeUpdate(java.sql.PreparedStatement ps,
SessionControl sc)
Execute a query by calling
PreparedStatement.executeUpdate() . |
private static <T> T |
getFutureResult(java.util.concurrent.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(java.lang.Class<T> clazz,
Query query,
StatelessSession session,
SessionControl sc)
Executes a Hibernate query on a stateless session.
|
static <T> ScrollIterator<T> |
loadIterator(java.lang.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() |
static void init()
static void unload()
public static java.sql.ResultSet executeQuery(java.sql.PreparedStatement ps, SessionControl sc) throws java.lang.InterruptedException, java.sql.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()
java.lang.InterruptedException
- If this thread was interruptedjava.sql.SQLException
- If there was an error executing the SQL statementpublic static int executeUpdate(java.sql.PreparedStatement ps, SessionControl sc) throws java.lang.InterruptedException, java.sql.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()
java.lang.InterruptedException
- If this thread was interruptedjava.sql.SQLException
public static <T> ScrollIterator<T> loadIterator(java.lang.Class<T> clazz, Query query, StatelessSession session, SessionControl sc) throws java.lang.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 nulljava.lang.InterruptedException
public static <T> T loadData(java.lang.Class<T> clazz, Query query, StatelessSession session, SessionControl sc) throws java.lang.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 nulljava.lang.InterruptedException
private static <T> T getFutureResult(java.util.concurrent.Callable<T> callable, QueryExecutor.Cancelable cancelable, SessionControl sc) throws java.lang.InterruptedException, java.sql.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 nulljava.lang.InterruptedException
- If this thread was interrupted during the queryjava.sql.SQLException