List of usage examples for org.hibernate.tool.hbm2ddl SingleLineSqlCommandExtractor extractCommands
@Override
public String[] extractCommands(Reader reader)
From source file:py.una.pol.karaku.test.cucumber.DatabasePopulatorCucumberExecutionListener.java
License:Open Source License
/** * @param testContext/*from w w w. j av a 2s . c o m*/ * @param file * @param slsce */ private void executeSQL(TestContext testContext, String file, SingleLineSqlCommandExtractor slsce) { BufferedReader br; ClassPathResource cpr = getClassPathResource(file, testContext); br = _getBr(cpr); // File f = new File(scriptPath); // FileReader fr = new FileReader(file); final String[] commands = slsce.extractCommands(br); if (commands == null) { return; } final HibernateTransactionManager tm = getTransactionManager(testContext); final TransactionTemplate tt = new TransactionTemplate(tm); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { for (String s : commands) { if (StringUtils.isInvalid(s)) { continue; } SQLQuery sql = tm.getSessionFactory().getCurrentSession().createSQLQuery(s.trim()); sql.executeUpdate(); } } }); }