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