Search in sources :

Example 91 with DataSource

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();
}
Also used : Connection(java.sql.Connection) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) DataSource(javax.sql.DataSource) UnpooledDataSource(org.apache.ibatis.datasource.unpooled.UnpooledDataSource) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 92 with DataSource

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();
}
Also used : Connection(java.sql.Connection) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) DataSource(javax.sql.DataSource) UnpooledDataSource(org.apache.ibatis.datasource.unpooled.UnpooledDataSource) Ignore(org.junit.Ignore) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 93 with DataSource

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());
}
Also used : StringWriter(java.io.StringWriter) Connection(java.sql.Connection) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) DataSource(javax.sql.DataSource) UnpooledDataSource(org.apache.ibatis.datasource.unpooled.UnpooledDataSource) PrintWriter(java.io.PrintWriter) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 94 with DataSource

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());
}
Also used : StringWriter(java.io.StringWriter) Connection(java.sql.Connection) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) DataSource(javax.sql.DataSource) UnpooledDataSource(org.apache.ibatis.datasource.unpooled.UnpooledDataSource) PrintWriter(java.io.PrintWriter) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 95 with DataSource

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());
    }
}
Also used : Connection(java.sql.Connection) Reader(java.io.Reader) StringReader(java.io.StringReader) IOException(java.io.IOException) SQLException(java.sql.SQLException) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) DataSource(javax.sql.DataSource) UnpooledDataSource(org.apache.ibatis.datasource.unpooled.UnpooledDataSource) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Aggregations

DataSource (javax.sql.DataSource)603 Connection (java.sql.Connection)211 Test (org.junit.Test)207 SQLException (java.sql.SQLException)124 Context (javax.naming.Context)73 InitialContext (javax.naming.InitialContext)64 NamingException (javax.naming.NamingException)62 ResultSet (java.sql.ResultSet)60 Statement (java.sql.Statement)59 HashMap (java.util.HashMap)40 EJBException (javax.ejb.EJBException)40 PreparedStatement (java.sql.PreparedStatement)38 Properties (java.util.Properties)37 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)35 IOException (java.io.IOException)32 RemoteException (java.rmi.RemoteException)32 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)31 UserTransaction (javax.transaction.UserTransaction)30 ArrayList (java.util.ArrayList)26 Map (java.util.Map)21