[#1157] Add extended SQL / JDBC tracing capabilities in addition to logging - added DefaultExecuteListener
This commit is contained in:
parent
753b645389
commit
61c893a0ea
@ -40,8 +40,10 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import org.jooq.conf.Settings;
|
||||
import org.jooq.impl.DefaultExecuteListener;
|
||||
import org.jooq.impl.Factory;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.LoggerListener;
|
||||
import org.jooq.tools.StopWatchListener;
|
||||
|
||||
/**
|
||||
* An event listener for {@link Query} render, prepare, bind, execute, fetch
|
||||
@ -56,8 +58,12 @@ import org.jooq.tools.JooqLogger;
|
||||
* of {@link Connection}, {@link PreparedStatement} and {@link ResultSet} to
|
||||
* jOOQ in apropriate methods.
|
||||
* <p>
|
||||
* If nothing is specified, the default is to use {@link JooqLogger} as the only
|
||||
* event listener.
|
||||
* If nothing is specified, the default is to use {@link LoggerListener} and
|
||||
* {@link StopWatchListener} as the only event listeners.
|
||||
* <p>
|
||||
* For convenience, consider extending {@link DefaultExecuteListener} instead of
|
||||
* implementing this interface. This will prevent compilation errors in future
|
||||
* versions of jOOQ, when this interface might get new methods.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
@ -66,23 +72,30 @@ public interface ExecuteListener {
|
||||
void init(ExecuteContext ctx);
|
||||
|
||||
void renderStart(ExecuteContext ctx);
|
||||
|
||||
void renderEnd(ExecuteContext ctx);
|
||||
|
||||
void prepareStart(ExecuteContext ctx);
|
||||
|
||||
void prepareEnd(ExecuteContext ctx);
|
||||
|
||||
void bindStart(ExecuteContext ctx);
|
||||
|
||||
void bindEnd(ExecuteContext ctx);
|
||||
|
||||
void executeStart(ExecuteContext ctx);
|
||||
|
||||
void executeEnd(ExecuteContext ctx);
|
||||
|
||||
void recordStart(ExecuteContext ctx);
|
||||
|
||||
void recordEnd(ExecuteContext ctx);
|
||||
|
||||
void resultStart(ExecuteContext ctx);
|
||||
|
||||
void resultEnd(ExecuteContext ctx);
|
||||
|
||||
void fetchStart(ExecuteContext ctx);
|
||||
|
||||
void fetchEnd(ExecuteContext ctx);
|
||||
}
|
||||
|
||||
96
jOOQ/src/main/java/org/jooq/impl/DefaultExecuteListener.java
Normal file
96
jOOQ/src/main/java/org/jooq/impl/DefaultExecuteListener.java
Normal file
@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed to you under the Apache License, Version 2.0
|
||||
* (the "License"); You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* . Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* . Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* . Neither the name "jOOQ" nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import org.jooq.ExecuteContext;
|
||||
import org.jooq.ExecuteListener;
|
||||
|
||||
/**
|
||||
* A publicly available default implementation of {@link ExecuteListener}.
|
||||
* <p>
|
||||
* Use this to stay compatible with future API changes (i.e. added methods to
|
||||
* <code>ExecuteListener</code>)
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class DefaultExecuteListener implements ExecuteListener {
|
||||
|
||||
@Override
|
||||
public void init(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void renderStart(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void renderEnd(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void prepareStart(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void prepareEnd(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void bindStart(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void bindEnd(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void executeStart(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void executeEnd(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void recordStart(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void recordEnd(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void resultStart(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void resultEnd(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void fetchStart(ExecuteContext ctx) {}
|
||||
|
||||
@Override
|
||||
public void fetchEnd(ExecuteContext ctx) {}
|
||||
|
||||
}
|
||||
@ -37,6 +37,7 @@ package org.jooq.tools;
|
||||
|
||||
import org.jooq.ExecuteContext;
|
||||
import org.jooq.ExecuteListener;
|
||||
import org.jooq.impl.DefaultExecuteListener;
|
||||
|
||||
/**
|
||||
* A default {@link ExecuteListener} that just logs events to java.util.logging,
|
||||
@ -44,38 +45,10 @@ import org.jooq.ExecuteListener;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class LoggerListener implements ExecuteListener {
|
||||
public class LoggerListener extends DefaultExecuteListener {
|
||||
|
||||
private static final JooqLogger log = JooqLogger.getLogger(LoggerListener.class);
|
||||
|
||||
@Override
|
||||
public void init(ExecuteContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderStart(ExecuteContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderEnd(ExecuteContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareStart(ExecuteContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareEnd(ExecuteContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindStart(ExecuteContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindEnd(ExecuteContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeStart(ExecuteContext ctx) {
|
||||
if (log.isDebugEnabled()) {
|
||||
@ -88,32 +61,12 @@ public class LoggerListener implements ExecuteListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeEnd(ExecuteContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetchStart(ExecuteContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetchEnd(ExecuteContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordStart(ExecuteContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordEnd(ExecuteContext ctx) {
|
||||
if (log.isTraceEnabled() && ctx.record() != null)
|
||||
log.trace("Record fetched", ctx.record());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resultStart(ExecuteContext ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resultEnd(ExecuteContext ctx) {
|
||||
if (log.isDebugEnabled() && ctx.result() != null) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user