Java Code Examples for org.apache.openjpa.persistence.OpenJPAEntityManager

The following examples show how to use org.apache.openjpa.persistence.OpenJPAEntityManager. These examples are extracted from open source projects. 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 Project: lams   Source File: OpenJpaDialect.java    License: 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 Project: spring4-understanding   Source File: OpenJpaDialect.java    License: 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 Project: syncope   Source File: OpenJpaDialect.java    License: 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 Project: openmeetings   Source File: DaoHelper.java    License: 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 Project: lams   Source File: OpenJpaDialect.java    License: GNU General Public License v2.0 4 votes vote down vote up
public OpenJpaTransactionData(OpenJPAEntityManager entityManager) {
	this.entityManager = entityManager;
}
 
Example 6
Source Project: lams   Source File: OpenJpaDialect.java    License: GNU General Public License v2.0 4 votes vote down vote up
public OpenJpaConnectionHandle(OpenJPAEntityManager entityManager) {
	this.entityManager = entityManager;
}
 
Example 7
Source Project: spring4-understanding   Source File: OpenJpaDialect.java    License: Apache License 2.0 4 votes vote down vote up
public OpenJpaTransactionData(OpenJPAEntityManager entityManager) {
	this.entityManager = entityManager;
}
 
Example 8
Source Project: spring4-understanding   Source File: OpenJpaDialect.java    License: Apache License 2.0 4 votes vote down vote up
public OpenJpaConnectionHandle(OpenJPAEntityManager entityManager) {
	this.entityManager = entityManager;
}
 
Example 9
public void testCanCastSharedEntityManagerProxyToOpenJpaEntityManager() {
	assertTrue("native EM expected", sharedEntityManager instanceof OpenJPAEntityManager);
}
 
Example 10
public void testCanGetSharedOpenJpaEntityManagerProxy() {
	OpenJPAEntityManager openJPAEntityManager = (OpenJPAEntityManager) SharedEntityManagerCreator.createSharedEntityManager(
			entityManagerFactory, null, OpenJPAEntityManager.class);
	assertNotNull(openJPAEntityManager.getDelegate());
}
 
Example 11
Source Project: syncope   Source File: OpenJpaDialect.java    License: Apache License 2.0 4 votes vote down vote up
OpenJpaTransactionData(final OpenJPAEntityManager entityManager) {
    this.entityManager = entityManager;
}
 
Example 12
Source Project: syncope   Source File: OpenJpaDialect.java    License: Apache License 2.0 4 votes vote down vote up
OpenJpaConnectionHandle(final OpenJPAEntityManager entityManager) {
    this.entityManager = entityManager;
}
 
Example 13
Source Project: lams   Source File: OpenJpaDialect.java    License: 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 Project: spring4-understanding   Source File: OpenJpaDialect.java    License: 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 Project: syncope   Source File: OpenJpaDialect.java    License: 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);
}