From 61c893a0ea121881fe6db08715a962b2bfc9a13b Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 22 Feb 2012 07:13:12 +0000 Subject: [PATCH] [#1157] Add extended SQL / JDBC tracing capabilities in addition to logging - added DefaultExecuteListener --- .../main/java/org/jooq/ExecuteListener.java | 19 +++- .../org/jooq/impl/DefaultExecuteListener.java | 96 +++++++++++++++++++ .../java/org/jooq/tools/LoggerListener.java | 51 +--------- 3 files changed, 114 insertions(+), 52 deletions(-) create mode 100644 jOOQ/src/main/java/org/jooq/impl/DefaultExecuteListener.java diff --git a/jOOQ/src/main/java/org/jooq/ExecuteListener.java b/jOOQ/src/main/java/org/jooq/ExecuteListener.java index 3f318e1393..c27961b3a4 100644 --- a/jOOQ/src/main/java/org/jooq/ExecuteListener.java +++ b/jOOQ/src/main/java/org/jooq/ExecuteListener.java @@ -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. *

- * 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. + *

+ * 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); } diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultExecuteListener.java b/jOOQ/src/main/java/org/jooq/impl/DefaultExecuteListener.java new file mode 100644 index 0000000000..f611cd8bda --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultExecuteListener.java @@ -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}. + *

+ * Use this to stay compatible with future API changes (i.e. added methods to + * ExecuteListener) + * + * @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) {} + +} diff --git a/jOOQ/src/main/java/org/jooq/tools/LoggerListener.java b/jOOQ/src/main/java/org/jooq/tools/LoggerListener.java index 8fdb28a658..e91f5fb452 100644 --- a/jOOQ/src/main/java/org/jooq/tools/LoggerListener.java +++ b/jOOQ/src/main/java/org/jooq/tools/LoggerListener.java @@ -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) {