org.tynamo.jpa.JPATransactionManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tapestry-jpa-core Show documentation
Show all versions of tapestry-jpa-core Show documentation
Basic JPA2 services for Tapestry IoC
// Copyright 2007, 2008 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.tynamo.jpa;
import javax.persistence.EntityManager;
/**
* Manages the JPA transaction for the current thread. This includes creating an entity manager as
* needed, allowing the em to checkpoint (commit the current transaction and continue) and commit
* the transaction automatically at the end of the request.
*
* Remember that in Tapestry, action requests and render requests are entirely separate, and you
* will see a separate request and a separate transaction for each. Care should be taken to ensure
* that entity objects that are retained (in the session, as persistent field values) between
* requests are handled correctly (they tend to become detached instances).
*
* This implementation of this service is per-thread.
*/
public interface JPATransactionManager
{
/**
* Gets the active session for this request, creating it as necessary. When the session is first
* created, a transaction is started.
*
* @return the request's entityManager
* @see JPAEntityManagerSource
*/
EntityManager getEntityManager();
/**
* Commits the current transaction (which will cause a flush of data to the database), then
* starts a new transaction to replace it.
*/
void commit();
/**
* Aborts the current transaction, and starts a new transaction to replace it.
*/
void abort();
}