Skip to content
This repository has been archived by the owner on Jul 22, 2018. It is now read-only.

liftmodules/jta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lift JTA Transaction API

To include this module in your Lift project, update your `libraryDependencies` in `build.sbt` to include:

Lift 2.6.x for Scala 2.9 and 2.10:

    "net.liftmodules" %% "jpa_2.6" % "1.2"

Lift 2.5.x for Scala 2.9 and 2.10:

    "net.liftmodules" %% "jpa_2.5" % "1.2"

Lift 3.0.x for Scala 2.10:

    "net.liftmodules" %% "jpa_3.0" % "1.2-SNAPSHOT"

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.

Note: The module package changed from net.liftweb.transaction to net.liftmodules.transaction in May 2012. Please consider this when referencing documentation written before that date.

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.modules.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.

Jenkins

The Jenkins build is triggered on a push to master. The server is at https://liftmodules.ci.cloudbees.com/job/jta/