public class JPA
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
JPA.JPAContext |
Modifier and Type | Field and Description |
---|---|
static java.lang.ThreadLocal<java.util.Map<java.lang.String,JPA.JPAContext>> |
currentEntityManager |
static java.lang.String |
DEFAULT |
protected static java.util.Map<java.lang.String,javax.persistence.EntityManagerFactory> |
emfs |
Constructor and Description |
---|
JPA() |
Modifier and Type | Method and Description |
---|---|
static void |
bindForCurrentThread(java.lang.String name,
javax.persistence.EntityManager em,
boolean readonly)
Bind an EntityManager to the current thread.
|
static void |
closeTx(java.lang.String name) |
static javax.persistence.EntityManager |
createEntityManager() |
static javax.persistence.EntityManager |
createEntityManager(java.lang.String name) |
static javax.persistence.EntityManager |
em() |
static javax.persistence.EntityManager |
em(java.lang.String key)
Get the EntityManager for specified persistence unit for this thread.
|
static int |
execute(java.lang.String query)
Execute a JPQL query
|
static int |
execute(java.lang.String em,
java.lang.String query) |
static java.lang.String |
getDBName(java.lang.Class<?> clazz) |
static boolean |
isEnabled() |
static boolean |
isEnabled(java.lang.String em) |
static boolean |
isInitialized() |
static boolean |
isInsideTransaction() |
static boolean |
isInsideTransaction(java.lang.String name) |
static javax.persistence.EntityManager |
newEntityManager() |
static javax.persistence.EntityManager |
newEntityManager(java.lang.String key) |
static void |
rollbackTx(java.lang.String name) |
static void |
setRollbackOnly() |
static void |
setRollbackOnly(java.lang.String em) |
static void |
startTx(java.lang.String name,
boolean readOnly)
initialize the JPA context and starts a JPA transaction
|
static void |
unbindForCurrentThread(java.lang.String name) |
static <T> T |
withinFilter(F.Function0<T> block) |
static <T> T |
withTransaction(java.lang.String dbName,
boolean readOnly,
F.Function0<T> block)
Run a block of code in a JPA transaction.
|
protected static java.util.Map<java.lang.String,javax.persistence.EntityManagerFactory> emfs
public static final java.lang.ThreadLocal<java.util.Map<java.lang.String,JPA.JPAContext>> currentEntityManager
public static java.lang.String DEFAULT
public static boolean isInitialized()
public static javax.persistence.EntityManager newEntityManager(java.lang.String key)
public static javax.persistence.EntityManager em(java.lang.String key)
key
- The DB namepublic static void bindForCurrentThread(java.lang.String name, javax.persistence.EntityManager em, boolean readonly)
name
- The DB nameem
- The EntityManagerreadonly
- indicate if it is in read only modepublic static void unbindForCurrentThread(java.lang.String name)
public static javax.persistence.EntityManager em()
public static void setRollbackOnly()
public static void setRollbackOnly(java.lang.String em)
public static boolean isEnabled()
public static boolean isEnabled(java.lang.String em)
public static int execute(java.lang.String query)
query
- The query to executepublic static int execute(java.lang.String em, java.lang.String query)
public static javax.persistence.EntityManager newEntityManager()
public static javax.persistence.EntityManager createEntityManager()
public static javax.persistence.EntityManager createEntityManager(java.lang.String name)
public static boolean isInsideTransaction()
public static boolean isInsideTransaction(java.lang.String name)
public static <T> T withinFilter(F.Function0<T> block) throws java.lang.Throwable
java.lang.Throwable
public static java.lang.String getDBName(java.lang.Class<?> clazz)
public static <T> T withTransaction(java.lang.String dbName, boolean readOnly, F.Function0<T> block) throws java.lang.Throwable
T
- The entity classdbName
- The persistence unit namereadOnly
- Is the transaction read-only?block
- Block of code to execute.java.lang.Throwable
- Thrown in case of errorpublic static void startTx(java.lang.String name, boolean readOnly)
name
- The persistence unit namereadOnly
- true for a readonly transactionpublic static void closeTx(java.lang.String name)
public static void rollbackTx(java.lang.String name)
Guillaume Bort & zenexity - Distributed under Apache 2 licence, without any warrantly