Search in sources :

Example 36 with DataSource

use of javax.sql.DataSource in project databus by linkedin.

the class TestOracleJarUtils method testCreateOracleDataSource.

@Test
public void testCreateOracleDataSource() throws Exception {
    // Invoke the method more than once in the same process
    DataSource ds1 = OracleJarUtils.createOracleDataSource("jdbc:oracle:thin:person/person@devdb:1521:db");
    DataSource ds2 = OracleJarUtils.createOracleDataSource("jdbc:oracle:thin:person/person@devdb:1521:db");
    // Should create a new object each time, and be invocable as many times as desired
    boolean isEqual = ds1.equals(ds2);
    Assert.assertEquals(isEqual, false);
    boolean isIdentical = (ds1 == ds2);
    Assert.assertEquals(isIdentical, false);
}
Also used : DataSource(javax.sql.DataSource) Test(org.testng.annotations.Test)

Example 37 with DataSource

use of javax.sql.DataSource in project mybatis-3 by mybatis.

the class ScriptRunnerTest method shouldReturnWarningIfNotTheCurrentDelimiterUsed.

@Test
public void shouldReturnWarningIfNotTheCurrentDelimiterUsed() throws Exception {
    DataSource ds = createUnpooledDataSource(JPETSTORE_PROPERTIES);
    Connection conn = ds.getConnection();
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setAutoCommit(false);
    runner.setStopOnError(true);
    runner.setErrorLogWriter(null);
    runner.setLogWriter(null);
    String resource = "org/apache/ibatis/jdbc/ScriptChangingDelimiterMissingDelimiter.sql";
    Reader reader = Resources.getResourceAsReader(resource);
    try {
        runner.runScript(reader);
        fail("Expected script runner to fail due to the usage of invalid delimiter.");
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("end-of-line terminator"));
    }
}
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)

Example 38 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 39 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 40 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)

Aggregations

DataSource (javax.sql.DataSource)546 Connection (java.sql.Connection)200 Test (org.junit.Test)192 SQLException (java.sql.SQLException)118 Context (javax.naming.Context)70 ResultSet (java.sql.ResultSet)59 Statement (java.sql.Statement)59 NamingException (javax.naming.NamingException)57 InitialContext (javax.naming.InitialContext)55 EJBException (javax.ejb.EJBException)40 HashMap (java.util.HashMap)38 PreparedStatement (java.sql.PreparedStatement)37 Properties (java.util.Properties)35 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)34 RemoteException (java.rmi.RemoteException)32 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)31 UserTransaction (javax.transaction.UserTransaction)30 IOException (java.io.IOException)29 ArrayList (java.util.ArrayList)26 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)21