use of javax.sql.DataSource in project cobar by alibaba.
the class AdapterDelegate method createAdapter.
private TimestampPair createAdapter(String ip, int port, String user, String password) {
CobarAdapter adapter = null;
try {
DataSource ds = dsFactory.createDataSource(ip, port, user, password);
adapter = new CobarAdapter();
adapter.setDataSource(ds);
((InitializingBean) adapter).afterPropertiesSet();
return new TimestampPair(adapter);
} catch (Exception exception) {
logger.error("ip=" + ip + ", port=" + port, exception);
try {
adapter.destroy();
} catch (Exception e) {
}
throw new RuntimeException(exception);
}
}
use of javax.sql.DataSource in project cobar by alibaba.
the class CobarAdapter method checkDaoConfig.
@Override
protected void checkDaoConfig() {
super.checkDaoConfig();
DataSource ds = getDataSource();
if (!(ds instanceof DataSource)) {
throw new IllegalArgumentException("property 'dataSource' is not type of " + DataSource.class.getName());
}
}
use of javax.sql.DataSource in project druid by alibaba.
the class Case4 method test_jobss.
public void test_jobss() throws Exception {
LocalTxDataSourceDO dataSourceDO = new LocalTxDataSourceDO();
dataSourceDO.setBlockingTimeoutMillis(1000 * 60);
dataSourceDO.setMaxPoolSize(maxPoolSize);
dataSourceDO.setMinPoolSize(minPoolSize);
dataSourceDO.setDriverClass(driverClass);
dataSourceDO.setConnectionURL(jdbcUrl);
dataSourceDO.setUserName(user);
dataSourceDO.setPassword(password);
LocalTxDataSource tx = TaobaoDataSourceFactory.createLocalTxDataSource(dataSourceDO);
DataSource dataSource = tx.getDatasource();
for (int i = 0; i < loopCount; ++i) {
p0(dataSource, "jboss-datasource", threadCount);
}
System.out.println();
}
use of javax.sql.DataSource in project druid by alibaba.
the class SpringMybatisFilterTest method test_spring.
public void test_spring() throws Exception {
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/alibaba/druid/pool/mybatis/spring-config-mybatis.xml");
DataSource dataSource = (DataSource) context.getBean("dataSource");
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE sequence_seed (value INTEGER, name VARCHAR(50))");
stmt.close();
conn.close();
}
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE t_User (id BIGINT, name VARCHAR(50))");
stmt.close();
conn.close();
}
{
Connection conn = dataSource.getConnection();
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
stmt.execute("insert into sequence_seed (value ,name) values (0, 'druid-spring-test')");
stmt.close();
conn.commit();
conn.close();
}
UserMapper userMapper = (UserMapper) context.getBean("userMapper");
{
User user = new User();
user.setName("xx");
userMapper.addUser(user);
}
{
userMapper.errorSelect(1);
}
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("DROP TABLE sequence_seed");
stmt.close();
conn.close();
}
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("DROP TABLE t_User");
stmt.close();
conn.close();
}
context.close();
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
}
use of javax.sql.DataSource in project druid by alibaba.
the class SqlMapClientWrapperTest method tearDown.
protected void tearDown() throws Exception {
DataSource dataSource = (DataSource) context.getBean("dataSource");
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("DROP TABLE sequence_seed");
stmt.close();
conn.close();
}
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("DROP TABLE t_User");
stmt.close();
conn.close();
}
context.close();
}
Aggregations