Search in sources :

Example 31 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class HibernateCRUDTest method setUp.

@Override
public void setUp() throws Exception {
    /*init dataSource*/
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:h2:file:~/.h2/HibernateCRUDTest;AUTO_SERVER=TRUE");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    dataSource.setDefaultAutoCommit(false);
    dataSource.setFilters("log4j");
    /*init sessionFactory*/
    LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
    factoryBean.setDataSource(dataSource);
    Properties prop = new Properties();
    prop.put("hibernate.show_sql", "true");
    // prop.put("hibernate.format_sql", "true");
    prop.put("hibernate.hbm2ddl.auto", "create");
    prop.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    factoryBean.setHibernateProperties(prop);
    factoryBean.setAnnotatedClasses(new Class<?>[] { Sample.class });
    try {
        factoryBean.afterPropertiesSet();
    } catch (IOException e) {
        e.printStackTrace();
    }
    sessionFactory = factoryBean.getObject();
}
Also used : LocalSessionFactoryBean(org.springframework.orm.hibernate4.LocalSessionFactoryBean) IOException(java.io.IOException) Properties(java.util.Properties) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 32 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class DupRegisterTest method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setMinEvictableIdleTimeMillis(10);
    dataSource.setTimeBetweenEvictionRunsMillis(10);
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 33 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class LoggerTest method test_log.

public void test_log() throws Exception {
    TestLoader classLoader = new TestLoader();
    Thread.currentThread().setContextClassLoader(classLoader);
    dataSource = new DruidDataSource();
    dataSource.setFilters("log");
    dataSource.setUrl("jdbc:mock:xx");
    Connection conn = dataSource.getConnection();
    conn.close();
}
Also used : Connection(java.sql.Connection) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 34 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class AsyncInitTest_1_scheduler method setUp.

protected void setUp() throws Exception {
    super.setUp();
    dataSource = new DruidDataSource();
    dataSource.setAsyncInit(true);
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setInitialSize(10);
    dataSource.setMaxActive(10);
    scheduler = Executors.newScheduledThreadPool(2);
    dataSource.setCreateScheduler(scheduler);
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 35 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class Case1 method test_f.

public void test_f() throws Exception {
    final DruidDataSource dataSource = new DruidDataSource();
    dataSource.setTimeBetweenConnectErrorMillis(100);
    final long startTime = System.currentTimeMillis();
    final long okTime = startTime + 1000 * 1;
    dataSource.setDriver(new MockDriver() {

        @Override
        public Connection connect(String url, Properties info) throws SQLException {
            if (System.currentTimeMillis() < okTime) {
                throw new SQLException();
            }
            return super.connect(url, info);
        }
    });
    dataSource.setUrl("jdbc:mock:");
    dataSource.setMinIdle(0);
    dataSource.setMaxActive(2);
    dataSource.setMaxIdle(2);
    Connection conn = dataSource.getConnection();
    conn.close();
    dataSource.close();
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Properties(java.util.Properties) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Aggregations

DruidDataSource (com.alibaba.druid.pool.DruidDataSource)474 SQLException (java.sql.SQLException)74 OracleMockDriver (com.alibaba.druid.test.util.OracleMockDriver)56 OracleExceptionSorter (com.alibaba.druid.pool.vendor.OracleExceptionSorter)50 MockDriver (com.alibaba.druid.mock.MockDriver)49 Connection (java.sql.Connection)43 Properties (java.util.Properties)41 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)35 FilterChain (com.alibaba.druid.filter.FilterChain)33 Bean (org.springframework.context.annotation.Bean)21 ResultSet (java.sql.ResultSet)20 Test (org.junit.Test)19 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)18 PreparedStatement (java.sql.PreparedStatement)14 Primary (org.springframework.context.annotation.Primary)14 MockConnection (com.alibaba.druid.mock.MockConnection)13 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)13 Method (java.lang.reflect.Method)11 Map (java.util.Map)11 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)10