Package com.alibaba.druid.proxy

Examples of com.alibaba.druid.proxy.DruidDriver


            Assert.assertNotNull(error);
        }
    }

    public void test_getRawDriver() throws Exception {
        DruidDriver driver = new DruidDriver();
        Assert.assertNotNull(driver.createDriver(MockDriver.class.getName()));

        {
            Exception error = null;
            try {
                driver.createDriver(null);
            } catch (Exception ex) {
                error = ex;
            }
            Assert.assertNotNull(error);
        }
        {
            Exception error = null;
            try {
                driver.createDriver(PrivateDriver.class.getName());
            } catch (Exception ex) {
                error = ex;
            }
            Assert.assertNotNull(error);
        }

        {
            Exception error = null;
            try {
                driver.createDriver(InitErrorDriver.class.getName());
            } catch (Exception ex) {
                error = ex;
            }
            Assert.assertNotNull(error);
        }
View Full Code Here


        }

    }

    public void test_driver_wrap() throws Exception {
        DruidDriver driver = new DruidDriver();

        {
            ConnectionProxyImpl conn = (ConnectionProxyImpl) driver.connect("jdbc:wrap-jdbc:filters=:name=driverWrapperTest:jdbc:derby:memory:driverWrapperTestDB;create=true",
                                                                            new Properties());
            Assert.assertEquals(0, conn.getDirectDataSource().getProxyFilters().size());
            conn.close();
        }
        {
            ConnectionProxyImpl conn = (ConnectionProxyImpl) driver.connect("jdbc:wrap-jdbc:filters=,:name=driverWrapperTest:jdbc:derby:memory:driverWrapperTestDB;create=true",
                                                                            new Properties());
            Assert.assertEquals(0, conn.getDirectDataSource().getProxyFilters().size());
            conn.close();
        }
        {
            ConnectionProxyImpl conn = (ConnectionProxyImpl) driver.connect("jdbc:wrap-jdbc:filters=,:jdbc:derby:memory:driverWrapperTestDB;create=true",
                                                                            new Properties());
            Assert.assertEquals(0, conn.getDirectDataSource().getProxyFilters().size());
            conn.close();
        }
        {
            ConnectionProxyImpl conn = (ConnectionProxyImpl) driver.connect("jdbc:wrap-jdbc:filters=,:name=:jdbc:derby:memory:driverWrapperTestDB;create=true",
                                                                            new Properties());
            Assert.assertEquals(0, conn.getDirectDataSource().getProxyFilters().size());
            conn.close();
        }
        {
            ConnectionProxyImpl conn = (ConnectionProxyImpl) driver.connect("jdbc:wrap-jdbc:driver=:filters=,:name=driverWrapperTest:jdbc:derby:memory:driverWrapperTestDB;create=true",
                                                                            new Properties());
            Assert.assertEquals(0, conn.getDirectDataSource().getProxyFilters().size());
            conn.close();
        }
        {
            ConnectionProxyImpl conn = (ConnectionProxyImpl) driver.connect("jdbc:wrap-jdbc:name=driverWrapperTest:jdbc:derby:memory:driverWrapperTestDB;create=true",
                                                                            new Properties());
            Assert.assertEquals(0, conn.getDirectDataSource().getProxyFilters().size());
            conn.close();
        }
        {
            ConnectionProxyImpl conn = (ConnectionProxyImpl) driver.connect("jdbc:wrap-jdbc:filters="
                                                                                    + PublicJdbcFilterAdapter.class.getName()
                                                                                    + ":name=driverWrapperTest:jdbc:derby:memory:driverWrapperTestDB;create=true",
                                                                            new Properties());
            Assert.assertEquals(1, conn.getDirectDataSource().getProxyFilters().size());
            conn.close();
        }
        {
            Exception error = null;
            try {
                driver.connect("jdbc:wrap-jdbc:filters=" + PrivateJdbcFilterAdapter.class.getName()
                                       + ":name=driverWrapperTest:jdbc:derby:memory:driverWrapperTestDB;create=true",
                               new Properties()).close();
            } catch (Exception ex) {
                error = ex;
            }
            Assert.assertNotNull(error);
        }
        {
            Exception error = null;
            try {
                driver.connect("jdbc:wrap-jdbc:filters=" + InitErrorJdbcFilterAdapter.class.getName()
                                       + ":name=driverWrapperTest:jdbc:derby:memory:driverWrapperTestDB;create=true",
                               new Properties()).close();
            } catch (Exception ex) {
                error = ex;
            }
View Full Code Here

    private static String url = "jdbc:wrap-jdbc:filters=default,commonLogging,log4j,encoding,null:name=demo:jdbc:derby:classpath:petstore-db";

    public void test_clone() throws Exception {
        Class.forName("com.alibaba.druid.proxy.DruidDriver");

        DruidDriver driver = (DruidDriver) DriverManager.getDriver(url);

        ConnectionProxyImpl connection = (ConnectionProxyImpl) driver.connect(url, new Properties());

        connection.getRawObject();

        FilterChain filterChain = (FilterChain) connection.createChain();
        filterChain.cloneChain();
View Full Code Here

public class DruidDriverTest extends TestCase {

    public void test_0() throws Exception {
        String url = "jdbc:wrap-jdbc:filters=default,commonLogging,log4j:name=preCallTest:jdbc:fake:c1";
        Properties info = new Properties();
        DruidDriver driver = new DruidDriver();
        Connection conn = driver.connect(url, info);
        Assert.assertNotNull(conn);
        Assert.assertEquals("c1", conn.getCatalog());

        conn.setCatalog("c2");
        Assert.assertEquals("c2", conn.getCatalog());
View Full Code Here

        Connection connection = DriverManager.getConnection(url_0);
        connection.close();

        Driver driver = DriverManager.getDriver(url_0);

        DruidDriver driverWrapper = (DruidDriver) driver;

        Assert.assertEquals(4, driverWrapper.getMajorVersion());
        Assert.assertEquals(0, driverWrapper.getMinorVersion());
        Assert.assertEquals(true, driverWrapper.jdbcCompliant());

        Assert.assertTrue(driverWrapper.getConnectCount() > 0);

        Assert.assertNotNull(DruidDriver.getInstance());

        Assert.assertEquals("jdbc:wrap-jdbc:", driverWrapper.getAcceptPrefix());

        Assert.assertTrue(driverWrapper.getDataSourceUrls().length > 0);

        driverWrapper.getPropertyInfo(url_0, new Properties());

        Assert.assertFalse(driverWrapper.acceptsURL(null));
        Assert.assertFalse(driverWrapper.acceptsURL("xxx"));
        Assert.assertTrue(driverWrapper.acceptsURL(url_1));

        Connection connection_1 = DriverManager.getConnection(url_1);
        ConnectionProxy connection_wrapper_1 = connection_1.unwrap(ConnectionProxy.class);
        DataSourceProxy dataSource_1 = connection_wrapper_1.getDirectDataSource();
        Assert.assertEquals(1, dataSource_1.getProxyFilters().size());
View Full Code Here

TOP

Related Classes of com.alibaba.druid.proxy.DruidDriver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.