Search in sources :

Example 81 with DruidDataSource

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

the class DruidDataSourceDecryptTest method testDecrypt.

@Test
public void testDecrypt() throws SQLException {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:oracle:thin:@");
    dataSource.setUsername("xiaoyu");
    dataSource.setPassword("OJfUm6WCHi7EuXqE6aEc+Po2xFrAGBeSNy8O2jWhV2FTG8/5kbRRr2rjNKhptlevm/03Y0048P7h88gdUOXAYg==");
    dataSource.setFilters("config");
    dataSource.setConnectionProperties("config.decrypt=true");
    try {
        dataSource.init();
        Assert.assertEquals("The password is " + dataSource.getPassword(), "xiaoyu", dataSource.getPassword());
    } finally {
        JdbcUtils.close(dataSource);
    }
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource) Test(org.junit.Test)

Example 82 with DruidDataSource

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

the class DruidDataSourceFactoryTest1 method test_other.

public void test_other() throws Exception {
    Properties properties = new Properties();
    properties.put(DruidDataSourceFactory.PROP_URL, "jdbc:mock:xxx");
    properties.put(DruidDataSourceFactory.PROP_DEFAULTTRANSACTIONISOLATION, "xxx");
    DruidDataSource dataSource = null;
    try {
        dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
        Assert.assertEquals("jdbc:mock:xxx", dataSource.getUrl());
        Assert.assertEquals(-1, dataSource.getDefaultTransactionIsolation().intValue());
    } finally {
        JdbcUtils.close(dataSource);
    }
}
Also used : Properties(java.util.Properties) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 83 with DruidDataSource

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

the class DruidDataSourceFactoryTest1 method test_NONE.

public void test_NONE() throws Exception {
    Properties properties = new Properties();
    properties.put(DruidDataSourceFactory.PROP_URL, "jdbc:mock:xxx");
    properties.put(DruidDataSourceFactory.PROP_DEFAULTTRANSACTIONISOLATION, "NONE");
    DruidDataSource dataSource = null;
    try {
        dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
        Assert.assertEquals("jdbc:mock:xxx", dataSource.getUrl());
        Assert.assertEquals(Connection.TRANSACTION_NONE, dataSource.getDefaultTransactionIsolation().intValue());
    } finally {
        JdbcUtils.close(dataSource);
    }
}
Also used : Properties(java.util.Properties) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 84 with DruidDataSource

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

the class ConfigErrorTestMysql method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mysql:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setInitialSize(0);
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 85 with DruidDataSource

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

the class DruidConnectionHolderTest method setUp.

protected void setUp() throws Exception {
    driver = new Driver();
    if (driver.getMajorVersion() == 5) {
        exceptionClass = Class.forName("com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException");
        dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mock:xxx");
        dataSource.setTestOnBorrow(false);
        dataSource.setInitialSize(1);
        dataSource.getProxyFilters().add(new FilterAdapter() {

            public int connection_getTransactionIsolation(FilterChain chain, ConnectionProxy connection) throws SQLException {
                throw createSyntaxException();
            }
        });
    }
}
Also used : SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) Driver(com.mysql.jdbc.Driver) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy)

Aggregations

DruidDataSource (com.alibaba.druid.pool.DruidDataSource)389 SQLException (java.sql.SQLException)56 OracleMockDriver (com.alibaba.druid.test.util.OracleMockDriver)55 OracleExceptionSorter (com.alibaba.druid.pool.vendor.OracleExceptionSorter)50 MockDriver (com.alibaba.druid.mock.MockDriver)48 Connection (java.sql.Connection)36 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)35 Properties (java.util.Properties)34 FilterChain (com.alibaba.druid.filter.FilterChain)33 ResultSet (java.sql.ResultSet)19 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)18 MockConnection (com.alibaba.druid.mock.MockConnection)13 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)13 Method (java.lang.reflect.Method)11 PreparedStatement (java.sql.PreparedStatement)11 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)10 Field (java.lang.reflect.Field)8 MockResultSet (com.alibaba.druid.mock.MockResultSet)7 TabularData (javax.management.openmbean.TabularData)7 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)6