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);
}
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());
}
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);
}
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;
}
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);
}
Aggregations