Search in sources :

Example 1 with ExplainPlanExecutor

use of com.newrelic.agent.database.ExplainPlanExecutor in project newrelic-java-agent by newrelic.

the class TransactionTrace method runExplainPlans.

private void runExplainPlans() {
    if (!sqlTracers.isEmpty()) {
        DatabaseService dbService = ServiceFactory.getDatabaseService();
        for (Entry<ConnectionFactory, List<ExplainPlanExecutor>> entry : sqlTracers.entrySet()) {
            Agent.LOG.finer(MessageFormat.format("Running {0} explain plan(s)", entry.getValue().size()));
            Connection connection = null;
            try {
                connection = entry.getKey().getConnection();
                DatabaseVendor vendor = entry.getKey().getDatabaseVendor();
                for (ExplainPlanExecutor explainExecutor : entry.getValue()) {
                    if (explainExecutor != null) {
                        explainExecutor.runExplainPlan(dbService, connection, vendor);
                    }
                }
            } catch (Throwable t) {
                String msg = MessageFormat.format("An error occurred executing an explain plan: {0}", t.toString());
                if (Agent.LOG.isLoggable(Level.FINER)) {
                    Agent.LOG.log(Level.FINER, msg, t);
                } else {
                    Agent.LOG.fine(msg);
                }
            } finally {
                if (connection != null) {
                    try {
                        connection.close();
                    } catch (Exception e) {
                        Agent.LOG.log(Level.FINER, "Unable to close connection", e);
                    }
                }
            }
        }
        sqlTracers.clear();
    }
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) DatabaseVendor(com.newrelic.agent.bridge.datastore.DatabaseVendor) Connection(java.sql.Connection) ExplainPlanExecutor(com.newrelic.agent.database.ExplainPlanExecutor) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) DatabaseService(com.newrelic.agent.database.DatabaseService) IOException(java.io.IOException)

Example 2 with ExplainPlanExecutor

use of com.newrelic.agent.database.ExplainPlanExecutor in project newrelic-java-agent by newrelic.

the class TransactionTrace method processSqlTracer.

private void processSqlTracer(Tracer tracer) {
    if (tracer instanceof SqlTracer) {
        SqlTracer sqlTracer = (SqlTracer) tracer;
        ExplainPlanExecutor explainExecutor = sqlTracer.getExplainPlanExecutor();
        ConnectionFactory connectionFactory = sqlTracer.getConnectionFactory();
        if (!sqlTracer.hasExplainPlan() && explainExecutor != null && connectionFactory != null) {
            List<ExplainPlanExecutor> tracers = sqlTracers.get(connectionFactory);
            if (tracers == null) {
                tracers = new LinkedList<>();
                sqlTracers.put(connectionFactory, tracers);
            }
            tracers.add(explainExecutor);
        }
    }
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) ExplainPlanExecutor(com.newrelic.agent.database.ExplainPlanExecutor) SqlTracer(com.newrelic.agent.tracers.SqlTracer)

Aggregations

ConnectionFactory (com.newrelic.agent.bridge.datastore.ConnectionFactory)2 ExplainPlanExecutor (com.newrelic.agent.database.ExplainPlanExecutor)2 DatabaseVendor (com.newrelic.agent.bridge.datastore.DatabaseVendor)1 DatabaseService (com.newrelic.agent.database.DatabaseService)1 SqlTracer (com.newrelic.agent.tracers.SqlTracer)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1