Search in sources :

Example 1 with ConnectionProxyImpl

use of com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl in project druid by alibaba.

the class FilterChainImpl method connection_connect.

public ConnectionProxy connection_connect(Properties info) throws SQLException {
    if (this.pos < filterSize) {
        return nextFilter().connection_connect(this, info);
    }
    Driver driver = dataSource.getRawDriver();
    String url = dataSource.getRawJdbcUrl();
    Connection nativeConnection = driver.connect(url, info);
    if (nativeConnection == null) {
        return null;
    }
    return new ConnectionProxyImpl(dataSource, nativeConnection, info, dataSource.createConnectionId());
}
Also used : Connection(java.sql.Connection) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) Driver(java.sql.Driver) ConnectionProxyImpl(com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl)

Example 2 with ConnectionProxyImpl

use of com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl in project druid by alibaba.

the class FilterChainTest_Clob method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    ConnectionProxyImpl conn = new ConnectionProxyImpl(dataSource, null, new Properties(), 0);
    statement = new StatementProxyImpl(conn, null, 1);
    mockResultSet = new MockResultSet(null) {

        public Object getObject(int columnIndex) throws SQLException {
            invokeCount++;
            return new MockClob();
        }
    };
}
Also used : SQLException(java.sql.SQLException) MockClob(com.alibaba.druid.mock.MockClob) ConnectionProxyImpl(com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl) MockResultSet(com.alibaba.druid.mock.MockResultSet) Properties(java.util.Properties) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) StatementProxyImpl(com.alibaba.druid.proxy.jdbc.StatementProxyImpl)

Example 3 with ConnectionProxyImpl

use of com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl in project druid by alibaba.

the class WrapImplTest method test_clone.

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();
    DataSourceProxyImpl dataSource = (DataSourceProxyImpl) connection.getDirectDataSource();
    dataSource.getId();
    Assert.assertEquals(4, dataSource.getProxyFilters().size());
    Assert.assertEquals(4, dataSource.getFilterClasses().length);
    Assert.assertNotNull(dataSource.getCreatedTime());
    Assert.assertTrue(dataSource.getCreatedTime().getTime() != 0);
    Assert.assertEquals("org.apache.derby.jdbc.EmbeddedDriver", dataSource.getRawDriverClassName());
    Assert.assertEquals(url, dataSource.getUrl());
    Assert.assertEquals("jdbc:derby:classpath:petstore-db", dataSource.getRawUrl());
    Assert.assertEquals(10, dataSource.getRawDriverMajorVersion());
    Assert.assertEquals(12, dataSource.getRawDriverMinorVersion());
    Class<?> mysql5ConnectionClass = Utils.loadClass("com.mysql.jdbc.Connection");
    if (mysql5ConnectionClass != null) {
        Assert.assertFalse(connection.isWrapperFor(mysql5ConnectionClass));
    }
    Assert.assertTrue(connection.isWrapperFor(ConnectionProxyImpl.class));
    Assert.assertTrue(connection.isWrapperFor(org.apache.derby.impl.jdbc.EmbedConnection.class));
    Assert.assertNotNull(connection.unwrap(ConnectionProxyImpl.class));
    Assert.assertNull(connection.unwrap(null));
    org.apache.derby.impl.jdbc.EmbedConnection derbyConnection = connection.unwrap(org.apache.derby.impl.jdbc.EmbedConnection.class);
    Assert.assertNotNull(derbyConnection);
    Statement statement = connection.createStatement();
    if (mysql5ConnectionClass != null) {
        Assert.assertFalse(statement.isWrapperFor(Class.forName("com.mysql.jdbc.Statement")));
    }
    Assert.assertFalse(statement.isWrapperFor(null));
    Assert.assertTrue(statement.isWrapperFor(org.apache.derby.impl.jdbc.EmbedStatement.class));
    org.apache.derby.impl.jdbc.EmbedStatement rayStatement = statement.unwrap(org.apache.derby.impl.jdbc.EmbedStatement.class);
    Assert.assertNotNull(rayStatement);
    statement.close();
}
Also used : DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) Statement(java.sql.Statement) FilterChain(com.alibaba.druid.filter.FilterChain) ConnectionProxyImpl(com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl) DruidDriver(com.alibaba.druid.proxy.DruidDriver) Properties(java.util.Properties)

Example 4 with ConnectionProxyImpl

use of com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl in project druid by alibaba.

the class CallableStatementProxyImplTest method test_call.

public void test_call() throws Exception {
    DataSourceProxyConfig config = new DataSourceProxyConfig();
    DataSourceProxy dataSource = new DataSourceProxyImpl(null, config);
    FilterEventAdapter filter = new FilterEventAdapter() {
    };
    filter.init(dataSource);
    config.getFilters().add(filter);
    String sql = "CALL P_0(?, ?)";
    CallableStatementProxyImpl rawCallStatement = new FakeCallableStatement(new ConnectionProxyImpl(null, null, null, 0), null, sql, 1001);
    ConnectionProxy connection = new ConnectionProxyImpl(dataSource, null, new Properties(), 1001);
    CallableStatementProxyImpl cstmt = new CallableStatementProxyImpl(connection, rawCallStatement, sql, 2001);
    cstmt.registerOutParameter(1, Types.VARCHAR);
    cstmt.registerOutParameter(1, Types.VARCHAR, "VARCHAR");
    cstmt.registerOutParameter(1, Types.VARCHAR, 3);
    cstmt.registerOutParameter("1", Types.VARCHAR);
    cstmt.registerOutParameter("1", Types.VARCHAR, "VARCHAR");
    cstmt.registerOutParameter("1", Types.VARCHAR, 3);
    cstmt.setBoolean("1", true);
    cstmt.setByte("1", (byte) 0);
    cstmt.setShort("1", (short) 0);
    cstmt.setInt("1", 0);
    cstmt.setLong("1", 0);
    cstmt.setFloat("1", 0);
    cstmt.setDouble("1", 0);
    cstmt.setBigDecimal("1", new BigDecimal("111"));
    cstmt.setString("1", "X");
    cstmt.setURL("1", null);
    cstmt.setSQLXML("1", null);
    cstmt.setBytes("1", null);
    cstmt.setDate("1", null);
    cstmt.setDate("1", null, Calendar.getInstance());
    cstmt.setTime("1", null);
    cstmt.setTime("1", null, Calendar.getInstance());
    cstmt.setTimestamp("1", null);
    cstmt.setTimestamp("1", null, Calendar.getInstance());
    cstmt.setAsciiStream("1", null);
    cstmt.setAsciiStream("1", null, 0);
    cstmt.setAsciiStream("1", null, 0L);
    cstmt.setBinaryStream("1", null);
    cstmt.setBinaryStream("1", null, 0);
    cstmt.setBinaryStream("1", null, 0L);
    cstmt.setObject("1", null);
    cstmt.setObject("1", null, Types.VARCHAR);
    cstmt.setObject("1", null, Types.VARCHAR, 3);
    cstmt.setCharacterStream("1", null);
    cstmt.setCharacterStream("1", null, 0);
    cstmt.setCharacterStream("1", null, 0L);
    cstmt.setNull("1", Types.VARCHAR);
    cstmt.setNull("1", Types.VARCHAR, "VARCHAR");
    cstmt.setRowId("1", null);
    cstmt.setNString("1", null);
    cstmt.setNCharacterStream("1", null);
    cstmt.setNCharacterStream("1", null, 0);
    cstmt.setNClob("1", (NClob) null);
    cstmt.setNClob("1", (Reader) null);
    cstmt.setNClob("1", (Reader) null, 0);
    cstmt.setClob("1", (Clob) null);
    cstmt.setClob("1", (Reader) null);
    cstmt.setClob("1", (Reader) null, 0);
    cstmt.setBlob("1", (Blob) null);
    cstmt.setBlob("1", (InputStream) null);
    cstmt.setBlob("1", (InputStream) null, 0);
    cstmt.setURL(1, null);
    cstmt.setSQLXML(1, null);
    cstmt.setArray(1, null);
    cstmt.setNCharacterStream(1, null);
    cstmt.setNCharacterStream(1, null, 0);
    cstmt.setNClob(1, (NClob) null);
    cstmt.setNClob(1, (Reader) null);
    cstmt.setNClob(1, (Reader) null, 0);
    cstmt.setNString(1, null);
    cstmt.setObject(1, null);
    cstmt.setRef(1, null);
    cstmt.setRowId(1, null);
    cstmt.setUnicodeStream(1, null, 0);
    cstmt.getClob(1);
    cstmt.getClob("1");
    cstmt.cancel();
    cstmt.getResultSet();
}
Also used : DataSourceProxyConfig(com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig) DataSourceProxy(com.alibaba.druid.proxy.jdbc.DataSourceProxy) DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) FilterEventAdapter(com.alibaba.druid.filter.FilterEventAdapter) ConnectionProxyImpl(com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl) CallableStatementProxyImpl(com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl) Properties(java.util.Properties) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy) BigDecimal(java.math.BigDecimal)

Example 5 with ConnectionProxyImpl

use of com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl in project druid by alibaba.

the class FilterChainTest_Clob_2 method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    MockCallableStatement mockStmt = new MockCallableStatement(null, "") {

        @Override
        public Object getObject(int parameterIndex) throws SQLException {
            invokeCount++;
            return new MockClob();
        }
    };
    statement = new CallableStatementProxyImpl(new ConnectionProxyImpl(null, null, null, 0), mockStmt, "", 1);
}
Also used : MockCallableStatement(com.alibaba.druid.mock.MockCallableStatement) MockClob(com.alibaba.druid.mock.MockClob) ConnectionProxyImpl(com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl) CallableStatementProxyImpl(com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Aggregations

ConnectionProxyImpl (com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl)10 Properties (java.util.Properties)7 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)6 CallableStatementProxyImpl (com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl)4 DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)4 FilterEventAdapter (com.alibaba.druid.filter.FilterEventAdapter)3 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)3 MockResultSet (com.alibaba.druid.mock.MockResultSet)3 DataSourceProxy (com.alibaba.druid.proxy.jdbc.DataSourceProxy)3 DataSourceProxyConfig (com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig)3 SQLException (java.sql.SQLException)3 FilterChain (com.alibaba.druid.filter.FilterChain)2 MockClob (com.alibaba.druid.mock.MockClob)2 MockNClob (com.alibaba.druid.mock.MockNClob)2 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)2 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)2 StatementProxyImpl (com.alibaba.druid.proxy.jdbc.StatementProxyImpl)2 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)1 DruidDriver (com.alibaba.druid.proxy.DruidDriver)1 PreparedStatementProxy (com.alibaba.druid.proxy.jdbc.PreparedStatementProxy)1