use of javax.persistence.EntityManagerFactory in project syndesis by syndesisio.
the class ConfiguredConnectionTest method setUp.
@BeforeClass
public static void setUp() {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("io.syndesis.runtime.db");
em = factory.createEntityManager();
}
use of javax.persistence.EntityManagerFactory 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 javax.persistence.EntityManagerFactory 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 javax.persistence.EntityManagerFactory 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();
}
}
}
use of javax.persistence.EntityManagerFactory in project jbpm by kiegroup.
the class CorrelationPersistenceTest method testCreateCorrelation.
@Test
public void testCreateCorrelation() throws Exception {
EntityManagerFactory emf = (EntityManagerFactory) context.get(EnvironmentName.ENTITY_MANAGER_FACTORY);
EntityManager em = emf.createEntityManager();
Query query = em.createNamedQuery("GetProcessInstanceIdByCorrelation");
query.setParameter("ckey", "test123");
List<Long> processInstances = query.getResultList();
em.close();
assertNotNull(processInstances);
assertEquals(1, processInstances.size());
}
Aggregations