use of javax.sql.DataSource in project mybatis-3 by mybatis.
the class ScriptRunnerTest method shouldRunScriptsUsingConnection.
@Test
public void shouldRunScriptsUsingConnection() throws Exception {
DataSource ds = createUnpooledDataSource(JPETSTORE_PROPERTIES);
Connection conn = ds.getConnection();
ScriptRunner runner = new ScriptRunner(conn);
runner.setAutoCommit(true);
runner.setStopOnError(false);
runner.setErrorLogWriter(null);
runner.setLogWriter(null);
runJPetStoreScripts(runner);
assertProductsTableExistsAndLoaded();
}
use of javax.sql.DataSource in project mybatis-3 by mybatis.
the class ScriptRunnerTest method shouldRunScriptsBySendingFullScriptAtOnce.
@Test
@Ignore("This fails with HSQLDB 2.0 due to the create index statements in the schema script")
public void shouldRunScriptsBySendingFullScriptAtOnce() throws Exception {
DataSource ds = createUnpooledDataSource(JPETSTORE_PROPERTIES);
Connection conn = ds.getConnection();
ScriptRunner runner = new ScriptRunner(conn);
runner.setSendFullScript(true);
runner.setAutoCommit(true);
runner.setStopOnError(false);
runner.setErrorLogWriter(null);
runner.setLogWriter(null);
runJPetStoreScripts(runner);
assertProductsTableExistsAndLoaded();
}
use of javax.sql.DataSource in project mybatis-3 by mybatis.
the class ScriptRunnerTest method testLogging.
@Test
public void testLogging() throws Exception {
DataSource ds = createUnpooledDataSource(JPETSTORE_PROPERTIES);
Connection conn = ds.getConnection();
ScriptRunner runner = new ScriptRunner(conn);
runner.setAutoCommit(true);
runner.setStopOnError(false);
runner.setErrorLogWriter(null);
runner.setSendFullScript(false);
StringWriter sw = new StringWriter();
PrintWriter logWriter = new PrintWriter(sw);
runner.setLogWriter(logWriter);
Reader reader = new StringReader("select userid from account where userid = 'j2ee';");
runner.runScript(reader);
assertEquals("select userid from account where userid = 'j2ee'" + System.getProperty("line.separator") + System.getProperty("line.separator") + "USERID\t" + System.getProperty("line.separator") + "j2ee\t" + System.getProperty("line.separator"), sw.toString());
}
use of javax.sql.DataSource in project mybatis-3 by mybatis.
the class ScriptRunnerTest method testLoggingFullScipt.
@Test
public void testLoggingFullScipt() throws Exception {
DataSource ds = createUnpooledDataSource(JPETSTORE_PROPERTIES);
Connection conn = ds.getConnection();
ScriptRunner runner = new ScriptRunner(conn);
runner.setAutoCommit(true);
runner.setStopOnError(false);
runner.setErrorLogWriter(null);
runner.setSendFullScript(true);
StringWriter sw = new StringWriter();
PrintWriter logWriter = new PrintWriter(sw);
runner.setLogWriter(logWriter);
Reader reader = new StringReader("select userid from account where userid = 'j2ee';");
runner.runScript(reader);
assertEquals("select userid from account where userid = 'j2ee';" + System.getProperty("line.separator") + System.getProperty("line.separator") + "USERID\t" + System.getProperty("line.separator") + "j2ee\t" + System.getProperty("line.separator"), sw.toString());
}
use of javax.sql.DataSource in project mybatis-3 by mybatis.
the class ScriptRunnerTest method commentAferStatementDelimiterShouldNotCauseRunnerFail.
@Test
public void commentAferStatementDelimiterShouldNotCauseRunnerFail() throws Exception {
DataSource ds = createUnpooledDataSource(JPETSTORE_PROPERTIES);
Connection conn = ds.getConnection();
ScriptRunner runner = new ScriptRunner(conn);
runner.setAutoCommit(true);
runner.setStopOnError(true);
runner.setErrorLogWriter(null);
runner.setLogWriter(null);
runJPetStoreScripts(runner);
String resource = "org/apache/ibatis/jdbc/ScriptCommentAfterEOLTerminator.sql";
Reader reader = Resources.getResourceAsReader(resource);
try {
runner.runScript(reader);
} catch (Exception e) {
fail(e.getMessage());
}
}
Aggregations