Java 类org.hibernate.tool.hbm2ddl.SingleLineSqlCommandExtractor 实例源码

项目:karaku    文件:DatabasePopulatorCucumberExecutionListener.java   
/**
 * @param testContext
 * @param sqlFiles
 */
private void executeSQLFiles(TestContext testContext, SQLFiles sqlFiles) {

    if (sqlFiles == null) {
        return;
    }
    List<String> files = getFiles(testContext, sqlFiles);
    SingleLineSqlCommandExtractor slsce = new SingleLineSqlCommandExtractor();

    for (String file : files) {
        executeSQL(testContext, file, slsce);
    }
}
项目:karaku    文件:DatabasePopulatorCucumberExecutionListener.java   
/**
 * @param testContext
 * @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();
            }

        }
    });

}
项目:karaku    文件:DatabasePopulatorExecutionListener.java   
/**
 * @param testContext
 * @param sqlFiles
 */
private void executeSQLFiles(TestContext testContext, SQLFiles sqlFiles) {

    if (sqlFiles == null) {
        return;
    }
    List<String> files = getFiles(testContext, sqlFiles);
    SingleLineSqlCommandExtractor slsce = new SingleLineSqlCommandExtractor();

    for (String file : files) {
        executeSQL(testContext, file, slsce);
    }
}
项目:karaku    文件:DatabasePopulatorExecutionListener.java   
/**
 * @param testContext
 * @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();
            }

        }
    });

}