Search in sources :

Example 1 with IsolationLevel

use of org.apache.openjpa.persistence.jdbc.IsolationLevel in project syncope by apache.

the class OpenJpaDialect method beginTransaction.

@Override
public Object beginTransaction(final EntityManager entityManager, final TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException {
    OpenJPAEntityManager openJpaEntityManager = getOpenJPAEntityManager(entityManager);
    if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
        // Pass custom isolation level on to OpenJPA's JDBCFetchPlan configuration
        FetchPlan fetchPlan = openJpaEntityManager.getFetchPlan();
        if (fetchPlan instanceof JDBCFetchPlan) {
            IsolationLevel isolation = IsolationLevel.fromConnectionConstant(definition.getIsolationLevel());
            ((JDBCFetchPlan) fetchPlan).setIsolation(isolation);
        }
    }
    entityManager.getTransaction().begin();
    if (!definition.isReadOnly()) {
        // Like with EclipseLink, make sure to start the logic transaction early so that other
        // participants using the connection (such as JdbcTemplate) run in a transaction.
        openJpaEntityManager.beginStore();
    }
    // Custom implementation for OpenJPA savepoint handling
    return new OpenJpaTransactionData(openJpaEntityManager);
}
Also used : OpenJPAEntityManager(org.apache.openjpa.persistence.OpenJPAEntityManager) IsolationLevel(org.apache.openjpa.persistence.jdbc.IsolationLevel) JDBCFetchPlan(org.apache.openjpa.persistence.jdbc.JDBCFetchPlan) FetchPlan(org.apache.openjpa.persistence.FetchPlan) JDBCFetchPlan(org.apache.openjpa.persistence.jdbc.JDBCFetchPlan)

Aggregations

FetchPlan (org.apache.openjpa.persistence.FetchPlan)1 OpenJPAEntityManager (org.apache.openjpa.persistence.OpenJPAEntityManager)1 IsolationLevel (org.apache.openjpa.persistence.jdbc.IsolationLevel)1 JDBCFetchPlan (org.apache.openjpa.persistence.jdbc.JDBCFetchPlan)1