Search in sources :

Example 1 with JdbcDriverConnectionFactory

use of com.newrelic.agent.bridge.datastore.JdbcDriverConnectionFactory in project newrelic-java-agent by newrelic.

the class Driver_Weaved method connect.

public Connection connect(String url, Properties props) {
    boolean firstInConnectPath = !DatastoreInstanceDetection.shouldDetectConnectionAddress();
    try {
        DatastoreInstanceDetection.detectConnectionAddress();
        Connection connection = Weaver.callOriginal();
        DatastoreInstanceDetection.associateAddress(connection);
        if (!JdbcHelper.connectionFactoryExists(connection)) {
            String detectedUrl = JdbcHelper.getConnectionURL(connection);
            if (detectedUrl == null) {
                return connection;
            }
            // Detect correct vendor type and then store new connection factory based on URL
            DatabaseVendor vendor = JdbcHelper.getVendor(getClass(), detectedUrl);
            JdbcHelper.putConnectionFactory(detectedUrl, new JdbcDriverConnectionFactory(vendor, (Driver) this, url, props));
        }
        return connection;
    } finally {
        if (firstInConnectPath) {
            DatastoreInstanceDetection.stopDetectingConnectionAddress();
        }
    }
}
Also used : JdbcDriverConnectionFactory(com.newrelic.agent.bridge.datastore.JdbcDriverConnectionFactory) DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor)

Example 2 with JdbcDriverConnectionFactory

use of com.newrelic.agent.bridge.datastore.JdbcDriverConnectionFactory in project newrelic-java-agent by newrelic.

the class Driver_Instrumentation method connect.

public Connection connect(String url, Properties props) throws SQLException {
    boolean firstInConnectPath = !DatastoreInstanceDetection.shouldDetectConnectionAddress();
    try {
        DatastoreInstanceDetection.detectConnectionAddress();
        Connection connection = Weaver.callOriginal();
        DatastoreInstanceDetection.associateAddress(connection);
        if (!JdbcHelper.connectionFactoryExists(connection)) {
            String detectedUrl = JdbcHelper.getConnectionURL(connection);
            if (detectedUrl == null) {
                return connection;
            }
            // Detect correct vendor type and then store new connection factory based on URL
            DatabaseVendor vendor = JdbcHelper.getVendor(getClass(), detectedUrl);
            JdbcHelper.putConnectionFactory(detectedUrl, new JdbcDriverConnectionFactory(vendor, (java.sql.Driver) this, url, props));
        }
        return connection;
    } finally {
        if (firstInConnectPath) {
            DatastoreInstanceDetection.stopDetectingConnectionAddress();
        }
    }
}
Also used : JdbcDriverConnectionFactory(com.newrelic.agent.bridge.datastore.JdbcDriverConnectionFactory) DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor) Connection(java.sql.Connection)

Aggregations

DatabaseVendor (com.newrelic.agent.bridge.datastore.DatabaseVendor)2 JdbcDriverConnectionFactory (com.newrelic.agent.bridge.datastore.JdbcDriverConnectionFactory)2 Connection (java.sql.Connection)1