List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext close
@Override public void close()
From source file:edu.mayo.cts2.uriresolver.dao.DAOUtiltities.java
public static DataSource createInMemoryDatabase(UriDAO uriDAO) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml"); // createDatabase in memory logger.info("Creating an in memory database"); DataSource ds = (DataSource) context.getBean("h2DataSource"); context.close(); int connectionCode = uriDAO.checkDataSource(ds); importMySQLDataToH2Database(ds);//from ww w .j a va2s. c o m if (connectionCode != 0) { logger.error("Unable to create in memory database. Cannot continue."); return null; } return ds; }
From source file:com.thinkbiganalytics.server.KyloServerApplication.java
/** * Return the database version for Kylo. * * @return the version of Kylo stored in the database *///from w w w . j a va 2s. c o m private static KyloVersion getDatabaseVersion() { try { //ensure native profile is there for spring to load String profiles = System.getProperty("spring.profiles.active", ""); if (!profiles.contains("native")) { profiles = StringUtils.isEmpty(profiles) ? "native" : profiles + ",native"; System.setProperty("spring.profiles.active", profiles); } //Spring is needed to load the Spring Cloud context so we can decrypt the passwords for the database connection ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "kylo-upgrade-check-application-context.xml"); ctx.refresh(); KyloUpgradeDatabaseVersionChecker upgradeDatabaseVersionChecker = (KyloUpgradeDatabaseVersionChecker) ctx .getBean("kyloUpgradeDatabaseVersionChecker"); KyloVersion kyloVersion = upgradeDatabaseVersionChecker.getDatabaseVersion(); ctx.close(); return kyloVersion; } catch (Exception e) { log.error( "Failed get the database version prior to upgrade. The Kylo Upgrade application will load by default. {}", e.getMessage()); } return null; }
From source file:com.digitalgeneralists.assurance.model.ModelUtils.java
public static IInitializableEntity initializeEntity(IInitializableEntity entity, String propertyKey) { IInitializableEntity result = null;/* w w w . j a va2 s . c o m*/ if (entity != null) { if (!Hibernate.isInitialized(entity.getPropertyToInitialize(propertyKey))) { // Because we are operating in a Swing application, the session context // closes after the initial bootstrap run. There appears to be an // "application"-level session configuration that should enable the // behavior we want for a desktop application, but there is no documentation // for it that I can find. // So, Assurance mimics a web app request/response // cycle for calls into the model delegate through the Swing // application. All calls to the model initiated directly from the UI // essentially operate as a new "request" and rebuild the Hibernate and // Spring session contexts for use within that operation. ClassPathXmlApplicationContext springContext = null; try { springContext = new ClassPathXmlApplicationContext("/META-INF/spring/app-context.xml"); IModelDelegate modelDelegate = (IModelDelegate) springContext.getBean("ModelDelegate"); result = modelDelegate.initializeEntity(entity, propertyKey); modelDelegate = null; } finally { if (springContext != null) { springContext.close(); } springContext = null; } } else { result = entity; } } return result; }
From source file:com.dinstone.jrpc.example.spring.ServiceWithSpring.java
protected static void case03() { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "jrpc-example-case3.xml"); HelloService rhsv1 = (HelloService) applicationContext.getBean("rhsv1"); try {// w w w . j a va 2 s .co m testHot(rhsv1); } catch (Exception e) { e.printStackTrace(); } try { testSend1k(rhsv1); } catch (Exception e) { e.printStackTrace(); } try { System.in.read(); } catch (IOException e) { } applicationContext.close(); }
From source file:com.dinstone.jrpc.example.spring.ServiceWithSpring.java
protected static void case01() { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "jrpc-example-case1.xml"); HelloService rhsv1 = (HelloService) applicationContext.getBean("rhsv1"); try {/*from ww w .jav a 2s . c o m*/ testHot(rhsv1); } catch (Exception e) { e.printStackTrace(); } try { testSend1k(rhsv1); } catch (Exception e) { e.printStackTrace(); } try { System.in.read(); } catch (IOException e) { } applicationContext.close(); }
From source file:gr.seab.r2rml.beans.MainParser.java
public static void runParcer(String[] args) { Calendar c0 = Calendar.getInstance(); long t0 = c0.getTimeInMillis(); CommandLineParser cmdParser = new PosixParser(); Options cmdOptions = new Options(); cmdOptions.addOption("p", "properties", true, "define the properties file. Example: r2rml-parser -p r2rml.properties"); cmdOptions.addOption("h", "print help", false, "help"); String propertiesFile = "r2rml.properties"; try {/*from w w w. j a v a 2 s . com*/ if (StringUtils.isNotEmpty(propertiesFile)) { properties.load(new FileInputStream(propertiesFile)); log.info("Loaded properties from " + propertiesFile); if (args != null && args.length > 0 && args[0].equals("fixProperty")) { properties = fixProperty(properties); } } } catch (FileNotFoundException e) { //e.printStackTrace(); String err = "Properties file not found (" + propertiesFile + ")."; log.error(err); throw new RuntimeException(err); //System.exit(0); } catch (IOException e) { //e.printStackTrace(); String err = "Error reading properties file (" + propertiesFile + ")."; log.error(err); throw new RuntimeException(err); //System.exit(0); } ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("app-context.xml"); Database db = (Database) context.getBean("db"); db.setProperties(properties); Parser parser = (Parser) context.getBean("parser"); parser.setProperties(properties); MappingDocument mappingDocument = parser.parse(); mappingDocument.getTimestamps().add(t0); //0 Started mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //1 Finished parsing. Starting generating result model. Generator generator = (Generator) context.getBean("generator"); generator.setProperties(properties); generator.setResultModel(parser.getResultModel()); //Actually do the output generator.createTriples(mappingDocument); context.close(); Calendar c1 = Calendar.getInstance(); long t1 = c1.getTimeInMillis(); log.info("Finished in " + (t1 - t0) + " milliseconds. Done."); mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //5 Finished. //log.info("5 Finished."); //output the result for (int i = 0; i < mappingDocument.getTimestamps().size(); i++) { if (i > 0) { long l = (mappingDocument.getTimestamps().get(i).longValue() - mappingDocument.getTimestamps().get(i - 1).longValue()); //System.out.println(l); log.info(String.valueOf(l)); } } log.info("Parse. Generate in memory. Dump to disk/database. Log. - Alltogether in " + String.valueOf(mappingDocument.getTimestamps().get(5).longValue() - mappingDocument.getTimestamps().get(0).longValue()) + " msec."); log.info("Done."); System.out.println("Done."); }
From source file:com.digitalgeneralists.assurance.model.ModelUtils.java
public static String calculateHashForFile(File file) { Logger logger = Logger.getLogger(ModelUtils.class); String result = null;//from w w w .jav a2 s . c o m if (file != null) { // Because we are operating in a Swing application, the session context // closes after the initial bootstrap run. There appears to be an // "application"-level session configuration that should enable the // behavior we want for a desktop application, but there is no documentation // for it that I can find. // So, Assurance mimics a web app request/response // cycle for calls into the model delegate through the Swing // application. All calls to the model initiated directly from the UI // essentially operate as a new "request" and rebuild the Hibernate and // Spring session contexts for use within that operation. ClassPathXmlApplicationContext springContext = null; try { springContext = new ClassPathXmlApplicationContext("/META-INF/spring/app-context.xml"); IFileComparor comparor = (IFileComparor) springContext.getBean("FileCompareValidator"); byte[] hash = comparor.calculateHashForFile(file); if (hash != null) { result = hash.toString(); } else { result = ""; } if (result.length() > 512) { result = result.substring(0, 511); } comparor = null; } catch (NoSuchAlgorithmException e) { result = ""; logger.warn(e); } catch (IOException e) { result = ""; logger.warn(e); } finally { if (springContext != null) { springContext.close(); } springContext = null; } } return result; }
From source file:org.pegadi.client.ApplicationLauncher.java
private static void closeContextOnShutdown(final ClassPathXmlApplicationContext context) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { context.close(); }/*w w w.j av a 2 s . co m*/ }); }
From source file:com.dinstone.jrpc.example.spring.ServiceWithSpring.java
private static void case02() { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "jrpc-example-case2.xml"); HelloService rhsv1Netty = (HelloService) applicationContext.getBean("rhsv1-netty"); System.out.println("rhsv1Netty"); try {/*from w ww . j a v a2 s . c o m*/ testHot(rhsv1Netty); } catch (Exception e) { e.printStackTrace(); } try { testSend1k(rhsv1Netty); } catch (Exception e) { e.printStackTrace(); } HelloService rhsv1Mina = (HelloService) applicationContext.getBean("rhsv1-mina"); System.out.println("rhsv1Mina"); try { testHot(rhsv1Mina); } catch (Exception e) { e.printStackTrace(); } try { testSend1k(rhsv1Mina); } catch (Exception e) { e.printStackTrace(); } try { System.in.read(); } catch (IOException e) { } applicationContext.close(); }
From source file:com.brienwheeler.apps.schematool.SchemaToolBeanTest.java
@Test public void testSchemaExportDefaultPUP() { PropertiesTestUtils.clearAllTestSystemProperties(); System.setProperty("com.brienwheeler.apps.schematool.schemaTool.mode", "CLEAN"); System.setProperty("com.brienwheeler.apps.schematool.schemaTool.exec", "false"); System.setProperty("com.brienwheeler.apps.schematool.schemaTool.closeContextOnDone", "false"); System.setProperty("com.brienwheeler.apps.schematool.schemaTool.emfContextLocation", CONTEXT_LOCATION_DPUP); System.setProperty("com.brienwheeler.apps.schematool.schemaTool.emfPersistenceLocationsPropValue", "classpath:com/brienwheeler/lib/db/persistence.xml"); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(CONTEXT_LOCATION_SCHEMATOOL); context.close(); }