use of org.springframework.orm.jpa.JpaTransactionManager in project workbench by all-of-us.
the class TestJpaConfig method transactionManager.
@Bean
public JpaTransactionManager transactionManager(final EntityManagerFactory entityManagerFactory) {
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory);
return transactionManager;
}
use of org.springframework.orm.jpa.JpaTransactionManager in project modesti by jlsalmon.
the class JpaConfig method coreTransactionManager.
@Bean
@Primary
public JpaTransactionManager coreTransactionManager(EntityManagerFactoryBuilder builder) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(coreEntityManagerFactory(builder).getObject());
return transactionManager;
}
use of org.springframework.orm.jpa.JpaTransactionManager in project BroadleafCommerce by BroadleafCommerce.
the class AdminTestHelper method startView.
/**
* Useful to start an EntityManager-In-View. This allows test operations that want to read directly from the database
* to work without lazy init exceptions, etc... This is not needed for MockMVC#perform operations, since those
* requests will include the OpenEntityManagerInView filter as part of their flow. At the completion of the test
* operation, the {@link #endView()} method should be called to end the scope of the view.
* </p>
* This view scope is also aware of nested views against the same persistence unit, so you don't need to worry
* about coding carefully to avoid nesting calls to startView.
*
* @param siteId
* @param sandBoxName
*/
public void startView(Long siteId, String sandBoxName) {
EntityManagerFactory emf = ((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory();
boolean isEntityManagerInView = TransactionSynchronizationManager.hasResource(emf);
if (!isEntityManagerInView) {
EntityManager em = emf.createEntityManager();
em.clear();
EntityManagerHolder emHolder = new EntityManagerHolder(em);
TransactionSynchronizationManager.bindResource(emf, emHolder);
Stack<String> stack = new Stack<>();
TransactionSynchronizationManager.bindResource("emStack", stack);
if (siteId != null) {
Site site = siteService.retrievePersistentSiteById(siteId);
ThreadLocalManager.remove();
BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
context.setSite(site);
context.setDeployBehavior(DeployBehavior.CLONE_PARENT);
context.setAdmin(true);
if (!StringUtils.isEmpty(sandBoxName)) {
SandBox sb = findSandBox(siteId, sandBoxName, false);
context.setSandBox(sb);
}
}
}
Stack<String> stack = (Stack<String>) TransactionSynchronizationManager.getResource("emStack");
RuntimeException trace = new RuntimeException();
StringWriter writer = new StringWriter();
PrintWriter pw = new PrintWriter(writer);
trace.printStackTrace(pw);
stack.push(writer.toString());
}
use of org.springframework.orm.jpa.JpaTransactionManager in project BroadleafCommerce by BroadleafCommerce.
the class AdminTestHelper method findSandBox.
private SandBox findSandBox(Long siteId, String sandBoxName, boolean initialize) {
if (initialize) {
startView(siteId, sandBoxName);
}
try {
if (DEFAULT_SB.equals(sandBoxName)) {
return getDefaultSandBox(siteId);
} else {
EntityManagerFactory emf = ((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory();
EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource(emf);
return findSandBox(sandBoxName, emHolder.getEntityManager());
}
} finally {
if (initialize) {
endView();
}
}
}
use of org.springframework.orm.jpa.JpaTransactionManager in project BroadleafCommerce by BroadleafCommerce.
the class AdminTestHelper method endView.
/**
* Complete the scope of the EntityManager-In-View operation. See {@link #startView(Long, String)}.
*/
public void endView() {
EntityManagerFactory emf = ((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory();
boolean isEntityManagerInView = TransactionSynchronizationManager.hasResource(emf);
if (isEntityManagerInView) {
Stack<Integer> stack = (Stack<Integer>) TransactionSynchronizationManager.getResource("emStack");
if (stack.size() <= 1) {
EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.unbindResource(emf);
EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager());
TransactionSynchronizationManager.unbindResource("emStack");
ThreadLocalManager.remove();
} else {
stack.pop();
}
}
}
Aggregations