play.db.jpa
Class JPA

java.lang.Object
  extended by play.db.jpa.JPA

public class JPA
extends java.lang.Object

JPA Helpers.


Constructor Summary
JPA()
           
 
Method Summary
static void bindForCurrentThread(javax.persistence.EntityManager em)
          Bind an EntityManager to the current thread.
static javax.persistence.EntityManager em()
          Get the default EntityManager for this thread.
static javax.persistence.EntityManager em(java.lang.String key)
          Get the EntityManager for specified persistence unit for this thread.
static void withTransaction(F.Callback0 block)
          Run a block of code in a JPA transaction.
static
<T> T
withTransaction(F.Function0<T> block)
          Run a block of code in a JPA transaction.
static
<T> T
withTransaction(java.lang.String name, boolean readOnly, F.Function0<T> block)
          Run a block of code in a JPA transaction.
static
<T> F.Promise<T>
withTransactionAsync(F.Function0<F.Promise<T>> block)
          Run a block of asynchronous code in a JPA transaction.
static
<T> F.Promise<T>
withTransactionAsync(java.lang.String name, boolean readOnly, F.Function0<F.Promise<T>> block)
          Run a block of asynchronous code in a JPA transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JPA

public JPA()
Method Detail

em

public static javax.persistence.EntityManager em(java.lang.String key)
Get the EntityManager for specified persistence unit for this thread.


em

public static javax.persistence.EntityManager em()
Get the default EntityManager for this thread.


bindForCurrentThread

public static void bindForCurrentThread(javax.persistence.EntityManager em)
Bind an EntityManager to the current thread.


withTransaction

public static <T> T withTransaction(F.Function0<T> block)
                         throws java.lang.Throwable
Run a block of code in a JPA transaction.

Parameters:
block - Block of code to execute.
Throws:
java.lang.Throwable

withTransactionAsync

public static <T> F.Promise<T> withTransactionAsync(F.Function0<F.Promise<T>> block)
                                         throws java.lang.Throwable
Run a block of asynchronous code in a JPA transaction.

Parameters:
block - Block of code to execute.
Throws:
java.lang.Throwable

withTransaction

public static void withTransaction(F.Callback0 block)
Run a block of code in a JPA transaction.

Parameters:
block - Block of code to execute.

withTransaction

public static <T> T withTransaction(java.lang.String name,
                                    boolean readOnly,
                                    F.Function0<T> block)
                         throws java.lang.Throwable
Run a block of code in a JPA transaction.

Parameters:
name - The persistence unit name
readOnly - Is the transaction read-only?
block - Block of code to execute.
Throws:
java.lang.Throwable

withTransactionAsync

public static <T> F.Promise<T> withTransactionAsync(java.lang.String name,
                                                    boolean readOnly,
                                                    F.Function0<F.Promise<T>> block)
                                         throws java.lang.Throwable
Run a block of asynchronous code in a JPA transaction.

Parameters:
name - The persistence unit name
readOnly - Is the transaction read-only?
block - Block of code to execute.
Throws:
java.lang.Throwable