Search in sources :

Example 46 with DataSource

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

the class SqlRunnerTest method shouldUpdateCategory.

@Test
public void shouldUpdateCategory() throws Exception {
    DataSource ds = createUnpooledDataSource(JPETSTORE_PROPERTIES);
    runScript(ds, JPETSTORE_DDL);
    runScript(ds, JPETSTORE_DATA);
    Connection connection = ds.getConnection();
    SqlRunner exec = new SqlRunner(connection);
    int count = exec.update("update product set category = ? where productid = ?", "DOGS", "FI-SW-01");
    Map<String, Object> row = exec.selectOne("SELECT * FROM PRODUCT WHERE PRODUCTID = ?", "FI-SW-01");
    connection.close();
    assertEquals("DOGS", row.get("CATEGORY"));
    assertEquals(1, count);
}
Also used : Connection(java.sql.Connection) DataSource(javax.sql.DataSource) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 47 with DataSource

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

the class SqlRunnerTest method shouldSelectList.

@Test
public void shouldSelectList() throws Exception {
    DataSource ds = createUnpooledDataSource(JPETSTORE_PROPERTIES);
    runScript(ds, JPETSTORE_DDL);
    runScript(ds, JPETSTORE_DATA);
    Connection connection = ds.getConnection();
    SqlRunner exec = new SqlRunner(connection);
    List<Map<String, Object>> rows = exec.selectAll("SELECT * FROM PRODUCT");
    connection.close();
    assertEquals(16, rows.size());
}
Also used : Connection(java.sql.Connection) Map(java.util.Map) DataSource(javax.sql.DataSource) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 48 with DataSource

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

the class FlushTest method setup.

@BeforeClass
public static void setup() throws Exception {
    DataSource dataSource = BaseDataTest.createBlogDataSource();
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("Production", transactionFactory, dataSource);
    Configuration configuration = new Configuration(environment);
    configuration.setDefaultExecutorType(ExecutorType.BATCH);
    configuration.getTypeAliasRegistry().registerAlias(Post.class);
    configuration.getTypeAliasRegistry().registerAlias(Author.class);
    configuration.addMapper(BoundAuthorMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
Also used : TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) Environment(org.apache.ibatis.mapping.Environment) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) DataSource(javax.sql.DataSource) BeforeClass(org.junit.BeforeClass)

Example 49 with DataSource

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

the class BaseDataTest method createJPetstoreDataSource.

public static DataSource createJPetstoreDataSource() throws IOException, SQLException {
    DataSource ds = createUnpooledDataSource(JPETSTORE_PROPERTIES);
    runScript(ds, JPETSTORE_DDL);
    runScript(ds, JPETSTORE_DATA);
    return ds;
}
Also used : PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) DataSource(javax.sql.DataSource) UnpooledDataSource(org.apache.ibatis.datasource.unpooled.UnpooledDataSource)

Example 50 with DataSource

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

the class BlobInputStreamTypeHandlerTest method setupSqlSessionFactory.

@BeforeClass
public static void setupSqlSessionFactory() throws Exception {
    DataSource dataSource = BaseDataTest.createUnpooledDataSource("org/apache/ibatis/type/jdbc.properties");
    BaseDataTest.runScript(dataSource, "org/apache/ibatis/type/BlobInputStreamTypeHandlerTest.sql");
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("Production", transactionFactory, dataSource);
    Configuration configuration = new Configuration(environment);
    configuration.addMapper(Mapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) Environment(org.apache.ibatis.mapping.Environment) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) DataSource(javax.sql.DataSource) BeforeClass(org.junit.BeforeClass)

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