/** * Process the next form entry in the database and then remove the form entry from the database. */ @Override public void execute() { try { Context.openSession(); log.info("****************************** SEND EMAIL TASK: Executing task ..."); } finally { Context.closeSession(); } }
@Override public void run() { isDaemonThread.set(true); try { Context.openSession(); //Suppressing sonar issue "squid:S1217" //We intentionally do not start a new thread yet, rather wrap the run call in a session. runnable.run(); } finally { Context.closeSession(); } } };
@Override public void run() { isDaemonThread.set(true); try { Context.openSession(); //Suppressing sonar issue "squid:S1217" //We intentionally do not start a new thread yet, rather wrap the run call in a session. runnable.run(); } finally { Context.closeSession(); } } };
@Override public void run() { isDaemonThread.set(true); try { Listener.startOpenmrs(servletContext); } catch (Exception e) { exceptionThrown = e; } finally { Context.closeSession(); } } };
@Override public void run() { isDaemonThread.set(true); try { Context.openSession(); returnedObject = ModuleFactory.startModuleInternal(module, isOpenmrsStartup, applicationContext); } catch (Exception e) { exceptionThrown = e; } finally { Context.closeSession(); } } };
@Override public void run() { isDaemonThread.set(true); try { Context.openSession(); TimerSchedulerTask.execute(task); } catch (Exception e) { exceptionThrown = e; } finally { Context.closeSession(); } } };
@Override public void run() { isDaemonThread.set(true); try { Context.openSession(); service.onStartup(); } catch (Exception e) { exceptionThrown = e; } finally { Context.closeSession(); } } };
/** * Process the next form entry in the database and then remove the form entry from the database. */ @Override public void execute() { Context.openSession(); try { log.debug("Processing HL7 queue ... "); processor.processHL7InQueue(); } catch (HL7Exception e) { log.error("Error running hl7 in queue task", e); throw new APIException("Hl7inQueue.error.running", null, e); } finally { Context.closeSession(); } }
Context.closeSession();
/** * @see Context#getUserContext() */ @Test(expected = APIException.class) public void getUserContext_shouldFailIfSessionHasntBeenOpened() { Context.closeSession(); Context.getUserContext(); // trigger the api exception }
/** * @see Context#logout() */ @Test public void logout_shouldNotFailIfSessionHasntBeenOpenedYet() { Context.closeSession(); Context.logout(); }
/** * The validate password method should be in a separate jvm here so that the Context and * services are not available to the validatePassword (similar to how its used in the * initialization wizard), but that is not possible to set up on a test-by-test basis, so we * settle by making the user context not available. * * @see OpenmrsUtil#validatePassword(String,String,String) */ @Test public void validatePassword_shouldStillWorkWithoutAnOpenSession() { Context.closeSession(); OpenmrsUtil.validatePassword("admin", "1234Password", "systemId"); }
Context.closeSession();
Context.closeSession();
@Override public void afterTestClass(TestContext testContext) throws Exception { StartModule startModuleAnnotation = testContext.getTestClass().getAnnotation(StartModule.class); if (startModuleAnnotation != null) { if (!Context.isSessionOpen()) { Context.openSession(); } // re-registering the bean definitions that we may have removed for (String beanName : filteredDefinitions.keySet()) { ((GenericApplicationContext) testContext.getApplicationContext()) .registerBeanDefinition(beanName, filteredDefinitions.get(beanName)); } filteredDefinitions.clear(); ModuleUtil.shutdown(); Context.closeSession(); } } }
/** * @see Context#getLocale() */ @Test public void getLocale_shouldNotFailIfSessionHasntBeenOpened() { Context.closeSession(); Assert.assertEquals(LocaleUtility.getDefaultLocale(), Context.getLocale()); }
/** * Called after each test class. This is called once per test class that extends * {@link BaseContextSensitiveTest}. Needed so that "unit of work" that is the test class is * surrounded by a pair of open/close session calls. * * @throws Exception */ @AfterClass public static void closeSessionAfterEachClass() throws Exception { //Some tests add data via executeDataset() //We need to delete it in order not to interfere with others if (instance != null) { try { instance.deleteAllData(); } catch (Exception ex) { //No need to worry about this } instance = null; } // clean up the session so we don't leak memory if (Context.isSessionOpen()) { Context.closeSession(); } }
/** * @see Context#isSessionOpen() */ @Test public void isSessionOpen_shouldReturnTrueIfSessionIsClosed() { Assert.assertTrue(Context.isSessionOpen()); Context.closeSession(); Assert.assertFalse(Context.isSessionOpen()); }
Context.closeSession();