@ThreadSafe public class JPAEnabledManager extends Object
IEntityManagerProvider required in the constructor should be a
request singleton that ensures one EntityManager per thread. The main
EntityManager objects are usually create from a subclass of
AbstractGlobalEntityManagerFactory.| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEFAULT_ALLOW_NESTED_TRANSACTIONS
By default nested transactions are not allowed
|
static int |
DEFAULT_EXECUTION_WARN_TIME_MS
The default execution time after which a warning is emitted
|
static boolean |
DEFAULT_SYNC_ENTITY_MGR
By default the entity manager is not locked (changed in 3.0.0)
|
static boolean |
DEFAULT_USE_TRANSACTIONS_FOR_SELECT
By default no transaction is used for select statements
|
protected static ReadWriteLock |
s_aRWLock |
| Constructor and Description |
|---|
JPAEnabledManager(IEntityManagerProvider aEntityManagerProvider) |
| Modifier and Type | Method and Description |
|---|---|
<T> JPAExecutionResult<T> |
doInTransaction(Callable<T> aCallable) |
static <T> JPAExecutionResult<T> |
doInTransaction(javax.persistence.EntityManager aEntityMgr,
boolean bAllowNestedTransactions,
Callable<T> aCallable) |
static JPAExecutionResult<?> |
doInTransaction(javax.persistence.EntityManager aEntityMgr,
boolean bAllowNestedTransactions,
com.phloc.commons.callback.IThrowingRunnable aRunnable) |
static JPAExecutionResult<?> |
doInTransaction(javax.persistence.EntityManager aEntityMgr,
boolean bAllowNestedTransactions,
Runnable aRunnable) |
JPAExecutionResult<?> |
doInTransaction(com.phloc.commons.callback.IThrowingRunnable aRunnable) |
JPAExecutionResult<?> |
doInTransaction(Runnable aRunnable) |
<T> JPAExecutionResult<T> |
doSelect(Callable<T> aCallable)
Run a read-only query.
|
static <T> JPAExecutionResult<T> |
doSelectStatic(Callable<T> aCallable)
Perform a select, without a transaction
|
static com.phloc.commons.callback.IExceptionHandler<Throwable> |
getCustomExceptionHandler()
Get the custom exception handler.
|
static int |
getDefaultExecutionWarnTime() |
protected javax.persistence.EntityManager |
getEntityManager() |
static IExecutionTimeExceededHandler |
getExecutionTimeExceededHandler()
Get the custom exception handler.
|
static long |
getSelectCountResult(javax.persistence.Query aQuery)
Helper method to handle the execution of "SELECT COUNT(...) ..."
|
static Number |
getSelectCountResultObj(javax.persistence.Query aQuery)
Helper method to handle the execution of "SELECT COUNT(...) ..."
|
boolean |
isAllowNestedTransactions() |
boolean |
isSyncEntityMgr() |
boolean |
isUseTransactionsForSelect() |
static void |
onExecutionTimeExceeded(String sMsg,
long nExecutionMillis) |
void |
setAllowNestedTransactions(boolean bAllowNestedTransactions)
Allow nested transaction
|
static void |
setCustomExceptionHandler(com.phloc.commons.callback.IExceptionHandler<Throwable> aExceptionHandler)
Set a custom exception handler that is called in case performing some
operation fails.
|
static void |
setDefaultExecutionWarnTime(int nMillis)
Set the milli seconds duration on which a warning should be emitted, if a
single SQL execution too at least that long.
|
static void |
setExecutionTimeExceededHandler(IExecutionTimeExceededHandler aExecutionTimeExceededHandler) |
void |
setSyncEntityMgr(boolean bSyncEntityMgr)
Set whether the entity manager should be synchronized upon each access
|
void |
setUseTransactionsForSelect(boolean bUseTransactionsForSelect)
Use transactions for select statements?
|
public static final boolean DEFAULT_SYNC_ENTITY_MGR
public static final boolean DEFAULT_ALLOW_NESTED_TRANSACTIONS
public static final boolean DEFAULT_USE_TRANSACTIONS_FOR_SELECT
public static final int DEFAULT_EXECUTION_WARN_TIME_MS
protected static final ReadWriteLock s_aRWLock
public JPAEnabledManager(@Nonnull IEntityManagerProvider aEntityManagerProvider)
public final boolean isSyncEntityMgr()
public final void setSyncEntityMgr(boolean bSyncEntityMgr)
bSyncEntityMgr - true to enable sync, false to disable syncpublic final boolean isAllowNestedTransactions()
public final void setAllowNestedTransactions(boolean bAllowNestedTransactions)
bAllowNestedTransactions - true to enable nested transactionpublic final boolean isUseTransactionsForSelect()
true if transactions should be used for selecting,
false if this can be done without transactionspublic final void setUseTransactionsForSelect(boolean bUseTransactionsForSelect)
bUseTransactionsForSelect - true to enable the usage of transactions for select
statements.@Nonnull protected final javax.persistence.EntityManager getEntityManager()
null.public static final void setCustomExceptionHandler(@Nullable com.phloc.commons.callback.IExceptionHandler<Throwable> aExceptionHandler)
aExceptionHandler - The exception handler to be set. May be null to
indicate no custom exception handler.@Nullable public static final com.phloc.commons.callback.IExceptionHandler<Throwable> getCustomExceptionHandler()
null if non is set@Nonnegative public static final int getDefaultExecutionWarnTime()
public static final void setDefaultExecutionWarnTime(int nMillis)
nMillis - The number of milli seconds. Must be ≥ 0.public static final void setExecutionTimeExceededHandler(@Nullable IExecutionTimeExceededHandler aExecutionTimeExceededHandler)
@Nullable public static final IExecutionTimeExceededHandler getExecutionTimeExceededHandler()
null if non is setpublic static final void onExecutionTimeExceeded(@Nonnull String sMsg, @Nonnegative long nExecutionMillis)
@Nonnull public static final JPAExecutionResult<?> doInTransaction(@Nonnull@WillNotClose javax.persistence.EntityManager aEntityMgr, boolean bAllowNestedTransactions, @Nonnull Runnable aRunnable)
@Nonnull public static final JPAExecutionResult<?> doInTransaction(@Nonnull@WillNotClose javax.persistence.EntityManager aEntityMgr, boolean bAllowNestedTransactions, @Nonnull com.phloc.commons.callback.IThrowingRunnable aRunnable)
@Nonnull public final JPAExecutionResult<?> doInTransaction(@Nonnull com.phloc.commons.callback.IThrowingRunnable aRunnable)
@Nonnull public final JPAExecutionResult<?> doInTransaction(@Nonnull Runnable aRunnable)
@Nonnull public static final <T> JPAExecutionResult<T> doInTransaction(@Nonnull@WillNotClose javax.persistence.EntityManager aEntityMgr, boolean bAllowNestedTransactions, @Nonnull Callable<T> aCallable)
@Nonnull public final <T> JPAExecutionResult<T> doInTransaction(@Nonnull Callable<T> aCallable)
@Nonnull public static final <T> JPAExecutionResult<T> doSelectStatic(@Nonnull Callable<T> aCallable)
aCallable - The callablenull upon success@Nonnull public final <T> JPAExecutionResult<T> doSelect(@Nonnull Callable<T> aCallable)
aCallable - The callable to execute.null result of the select.@Nonnull public static final Number getSelectCountResultObj(@Nonnull javax.persistence.Query aQuery)
doSelect(Callable) or
doSelectStatic(Callable) method.aQuery - The SELECT COUNT query@Nonnegative public static final long getSelectCountResult(@Nonnull javax.persistence.Query aQuery)
doSelect(Callable) or
doSelectStatic(Callable) method.aQuery - The SELECT COUNT queryCopyright © 2006–2015 phloc systems. All rights reserved.