Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
src
README.textile

README.textile

Lift JTA Transaction API

The semantics are the same as used in the EJB spec. E.g. Required, RequiresNew, Mandatory, Supports, Never. All these are exposed as monadic objects and high-order functions in the TransactionContext object.

The implementation is hooked into the Lift’s JPA implementation.
Check the ScalaDoc (or the source) for the documentation on usage, semantics etc.

There are two versions of the API, one monadic and one using high-order functions.

Monadic API

 for {
   ctx <- TransactionContext.Required
   entity <- updatedEntities
   if !ctx.isRollbackOnly
 } {
   // transactional stuff
   ctx.getEntityManager.merge(entity)
 }
val users = for {
   ctx <- TransactionContext.RequiresNew
   name <- userNames
 } yield {
   // transactional stuff
   val query = ctx.getEntityManager.createNamedQuery("findUserByName")
   query.setParameter("userName", name)
   query.getSingleResult
 }

High-order functions API

TransactionContext.withTxRequired {
    ... // REQUIRED semantics 

  TransactionContext.withTxRequiresNew {
    ... // REQUIRES_NEW semantics
  }
}

Configuration

The configuration is done in the persistence.xml file + the jta.properties. Sample configuration files can be found in the src/main/resources directory.
Here are the essential configuration options in the JPA persistence.xml file:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">
  <persistence-unit name="LiftPersistenceUnit" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <mapping-file>...</mapping-file>
    <class>...</class>

    <properties>
      <property name="hibernate.transaction.manager_lookup_class"
                value="net.liftweb.transaction.hibernate.LiftTransactionManagerLookup" />
    </properties>
  </persistence-unit>
</persistence>

TODOs

Currently it is hard-coded to use the Atomikos Transaction library and the Hibernate JPA implementation.
This will have to be configurable + some other options as well. See the TODOs in the code.

Something went wrong with that request. Please try again.