Example usage for org.springframework.orm.jpa JpaDialect prepareTransaction

List of usage examples for org.springframework.orm.jpa JpaDialect prepareTransaction

Introduction

In this page you can find the example usage for org.springframework.orm.jpa JpaDialect prepareTransaction.

Prototype

@Nullable
Object prepareTransaction(EntityManager entityManager, boolean readOnly, @Nullable String name)
        throws PersistenceException;

Source Link

Document

Prepare a JPA transaction, applying the specified semantics.

Usage

From source file:org.springframework.orm.jpa.EntityManagerFactoryUtils.java

/**
 * Prepare a transaction on the given EntityManager, if possible.
 * @param em the EntityManager to prepare
 * @param emf the EntityManagerFactory that the EntityManager has been created with
 * @return an arbitrary object that holds transaction data, if any
 * (to be passed into cleanupTransaction)
 * @see JpaDialect#prepareTransaction//from   w  w  w.ja  va 2 s  .  c om
 */
@Nullable
private static Object prepareTransaction(EntityManager em, EntityManagerFactory emf) {
    if (emf instanceof EntityManagerFactoryInfo) {
        EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) emf;
        JpaDialect jpaDialect = emfInfo.getJpaDialect();
        if (jpaDialect != null) {
            return jpaDialect.prepareTransaction(em,
                    TransactionSynchronizationManager.isCurrentTransactionReadOnly(),
                    TransactionSynchronizationManager.getCurrentTransactionName());
        }
    }
    return null;
}