|
3.1.1: 2012-03-29 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.basedb.core.QueryExecutor
public class QueryExecutor
Utility class for executing SQL and Hibernate queries. If enabled, this class will use a thread pool to execute a query in separate threads. The benefits are:
| Nested Class Summary | |
|---|---|
(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() |
| Field Summary | |
|---|---|
private static ExecutorService |
service
|
| Constructor Summary | |
|---|---|
QueryExecutor()
|
|
| Method Summary | ||
|---|---|---|
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
|
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
|
loadData(Class<T> clazz,
Query query,
StatelessSession session,
SessionControl sc)
Executes a Hibernate query on a stateless session. |
|
static
|
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()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static ExecutorService service
| Constructor Detail |
|---|
public QueryExecutor()
| Method Detail |
|---|
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 null
PreparedStatement.executeQuery()
InterruptedException - If this thread was interrupted
SQLException - If there was an error executing the SQL statement
public 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 null
PreparedStatement.executeUpdate()
InterruptedException - If this thread was interrupted
SQLException
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 null
InterruptedException
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 null
InterruptedException
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 null
InterruptedException - If this thread was interrupted during the query
SQLException
|
3.1.1: 2012-03-29 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||