Search in sources :

Example 21 with DataSource

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);
    }
}
Also used : InitializingBean(org.springframework.beans.factory.InitializingBean) DataSource(javax.sql.DataSource)

Example 22 with DataSource

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());
    }
}
Also used : DataSource(javax.sql.DataSource) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 23 with DataSource

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();
}
Also used : LocalTxDataSourceDO(com.taobao.datasource.LocalTxDataSourceDO) LocalTxDataSource(com.taobao.datasource.resource.adapter.jdbc.local.LocalTxDataSource) LocalTxDataSource(com.taobao.datasource.resource.adapter.jdbc.local.LocalTxDataSource) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) BoneCPDataSource(com.jolbox.bonecp.BoneCPDataSource) ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) ProxoolDataSource(org.logicalcobwebs.proxool.ProxoolDataSource) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) DataSource(javax.sql.DataSource)

Example 24 with DataSource

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());
}
Also used : User(com.alibaba.druid.spring.User) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Statement(java.sql.Statement) Connection(java.sql.Connection) DataSource(javax.sql.DataSource)

Example 25 with DataSource

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();
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) DataSource(javax.sql.DataSource)

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