org.apache.openjpa.persistence.OpenJPAEntityManager Java Examples

The following examples show how to use org.apache.openjpa.persistence.OpenJPAEntityManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenJpaDialect.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object beginTransaction(EntityManager entityManager, 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);
}
 
Example #2
Source File: OpenJpaDialect.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public Object beginTransaction(EntityManager entityManager, 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);
}
 
Example #3
Source File: OpenJpaDialect.java    From syncope with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: DaoHelper.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
public static <T> List<T> fillLazy(EntityManager em, Function<OpenJPAEntityManager, TypedQuery<T>> func, String...groups) {
	OpenJPAEntityManager oem = OpenJPAPersistence.cast(em);
	boolean qrce = oem.getFetchPlan().getQueryResultCacheEnabled();
	try {
		oem.getFetchPlan().setQueryResultCacheEnabled(false); //update in cache during update
		TypedQuery<T> q = func.apply(oem);
		@SuppressWarnings("unchecked")
		OpenJPAQuery<T> kq = OpenJPAPersistence.cast(q);
		kq.getFetchPlan().addFetchGroups(groups);
		return kq.getResultList();
	} finally {
		oem.getFetchPlan().setQueryResultCacheEnabled(qrce);
	}
}
 
Example #5
Source File: OpenJpaDialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public OpenJpaTransactionData(OpenJPAEntityManager entityManager) {
	this.entityManager = entityManager;
}
 
Example #6
Source File: OpenJpaDialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public OpenJpaConnectionHandle(OpenJPAEntityManager entityManager) {
	this.entityManager = entityManager;
}
 
Example #7
Source File: OpenJpaDialect.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public OpenJpaTransactionData(OpenJPAEntityManager entityManager) {
	this.entityManager = entityManager;
}
 
Example #8
Source File: OpenJpaDialect.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public OpenJpaConnectionHandle(OpenJPAEntityManager entityManager) {
	this.entityManager = entityManager;
}
 
Example #9
Source File: OpenJpaEntityManagerFactoryIntegrationTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public void testCanCastSharedEntityManagerProxyToOpenJpaEntityManager() {
	assertTrue("native EM expected", sharedEntityManager instanceof OpenJPAEntityManager);
}
 
Example #10
Source File: OpenJpaEntityManagerFactoryIntegrationTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public void testCanGetSharedOpenJpaEntityManagerProxy() {
	OpenJPAEntityManager openJPAEntityManager = (OpenJPAEntityManager) SharedEntityManagerCreator.createSharedEntityManager(
			entityManagerFactory, null, OpenJPAEntityManager.class);
	assertNotNull(openJPAEntityManager.getDelegate());
}
 
Example #11
Source File: OpenJpaDialect.java    From syncope with Apache License 2.0 4 votes vote down vote up
OpenJpaTransactionData(final OpenJPAEntityManager entityManager) {
    this.entityManager = entityManager;
}
 
Example #12
Source File: OpenJpaDialect.java    From syncope with Apache License 2.0 4 votes vote down vote up
OpenJpaConnectionHandle(final OpenJPAEntityManager entityManager) {
    this.entityManager = entityManager;
}
 
Example #13
Source File: OpenJpaDialect.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the OpenJPA-specific variant of {@code EntityManager}.
 * @param em the generic {@code EntityManager} instance
 * @return the OpenJPA-specific variant of {@code EntityManager}
 */
protected OpenJPAEntityManager getOpenJPAEntityManager(EntityManager em) {
	return OpenJPAPersistence.cast(em);
}
 
Example #14
Source File: OpenJpaDialect.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Return the OpenJPA-specific variant of {@code EntityManager}.
 * @param em the generic {@code EntityManager} instance
 * @return the OpenJPA-specific variant of {@code EntityManager}
 */
protected OpenJPAEntityManager getOpenJPAEntityManager(EntityManager em) {
	return OpenJPAPersistence.cast(em);
}
 
Example #15
Source File: OpenJpaDialect.java    From syncope with Apache License 2.0 2 votes vote down vote up
/**
 * Return the OpenJPA-specific variant of {@code EntityManager}.
 *
 * @param em the generic {@code EntityManager} instance
 * @return the OpenJPA-specific variant of {@code EntityManager}
 */
protected static OpenJPAEntityManager getOpenJPAEntityManager(final EntityManager em) {
    return OpenJPAPersistence.cast(em);
}