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());
}
}
use of javax.sql.DataSource in project mybatis-3 by mybatis.
the class SqlRunnerTest method shouldInsert.
@Test
public void shouldInsert() throws Exception {
DataSource ds = createUnpooledDataSource(BLOG_PROPERTIES);
runScript(ds, BLOG_DDL);
Connection connection = ds.getConnection();
SqlRunner exec = new SqlRunner(connection);
exec.setUseGeneratedKeySupport(true);
int id = exec.insert("INSERT INTO author (username, password, email, bio) VALUES (?,?,?,?)", "someone", "******", "someone@apache.org", Null.LONGVARCHAR);
Map<String, Object> row = exec.selectOne("SELECT * FROM author WHERE username = ?", "someone");
connection.rollback();
connection.close();
assertTrue(SqlRunner.NO_GENERATED_KEY != id);
assertEquals("someone", row.get("USERNAME"));
}
use of javax.sql.DataSource in project mybatis-3 by mybatis.
the class SqlRunnerTest method shouldDemonstrateDDLThroughRunMethod.
@Test
public void shouldDemonstrateDDLThroughRunMethod() throws Exception {
DataSource ds = createUnpooledDataSource(JPETSTORE_PROPERTIES);
Connection connection = ds.getConnection();
SqlRunner exec = new SqlRunner(connection);
exec.run("CREATE TABLE BLAH(ID INTEGER)");
exec.run("insert into BLAH values (1)");
List<Map<String, Object>> rows = exec.selectAll("SELECT * FROM BLAH");
exec.run("DROP TABLE BLAH");
connection.close();
assertEquals(1, rows.size());
}
use of javax.sql.DataSource in project mybatis-3 by mybatis.
the class SqlRunnerTest method shouldSelectOne.
@Test
public void shouldSelectOne() throws Exception {
DataSource ds = createUnpooledDataSource(JPETSTORE_PROPERTIES);
runScript(ds, JPETSTORE_DDL);
runScript(ds, JPETSTORE_DATA);
Connection connection = ds.getConnection();
SqlRunner exec = new SqlRunner(connection);
Map<String, Object> row = exec.selectOne("SELECT * FROM PRODUCT WHERE PRODUCTID = ?", "FI-SW-01");
connection.close();
assertEquals("FI-SW-01", row.get("PRODUCTID"));
}
Aggregations