[#1157] Add extended SQL / JDBC tracing capabilities in addition to logging - added ExecuteType for convenience
This commit is contained in:
parent
dc0e2943de
commit
e09cda2a2f
@ -56,6 +56,13 @@ public interface ExecuteContext extends Configuration {
|
||||
*/
|
||||
Configuration configuration();
|
||||
|
||||
/**
|
||||
* The type of database interaction that is being executed
|
||||
*
|
||||
* @see ExecuteType
|
||||
*/
|
||||
ExecuteType type();
|
||||
|
||||
/**
|
||||
* The jOOQ {@link Query} that is being executed or <code>null</code> if the
|
||||
* query is unknown or if there was no jOOQ <code>Query</code>
|
||||
@ -152,4 +159,43 @@ public interface ExecuteContext extends Configuration {
|
||||
*/
|
||||
void result(Result<?> result);
|
||||
|
||||
/**
|
||||
* The type of database interaction that is being executed with this
|
||||
* context.
|
||||
*/
|
||||
enum ExecuteType {
|
||||
|
||||
/**
|
||||
* A <code>SELECT</code> query is being executed
|
||||
*/
|
||||
READ,
|
||||
|
||||
/**
|
||||
* An <code>INSERT</code>, <code>UPDATE</code>, <code>DELETE</code>,
|
||||
* <code>MERGE</code> query is being executed
|
||||
*/
|
||||
WRITE,
|
||||
|
||||
/**
|
||||
* A routine (stored procedure or function) is being executed
|
||||
*/
|
||||
ROUTINE,
|
||||
|
||||
/**
|
||||
* A batch statement is being executed (not yet supported)
|
||||
*/
|
||||
BATCH,
|
||||
|
||||
/**
|
||||
* A DDL statement is being executed
|
||||
* <p>
|
||||
* Currently, this only applies to <code>TRUNCATE</code> statements
|
||||
*/
|
||||
DDL,
|
||||
|
||||
/**
|
||||
* An other (unknown) type of database interaction is being executed
|
||||
*/
|
||||
OTHER,
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,11 +39,17 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Delete;
|
||||
import org.jooq.ExecuteContext;
|
||||
import org.jooq.Insert;
|
||||
import org.jooq.Merge;
|
||||
import org.jooq.Query;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.ResultQuery;
|
||||
import org.jooq.Routine;
|
||||
import org.jooq.Truncate;
|
||||
import org.jooq.Update;
|
||||
|
||||
/**
|
||||
* A default iplementation for the {@link ExecuteContext}
|
||||
@ -87,13 +93,37 @@ class DefaultExecuteContext extends AbstractConfiguration implements ExecuteCont
|
||||
this.routine = routine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ExecuteType type() {
|
||||
if (routine != null) {
|
||||
return ExecuteType.ROUTINE;
|
||||
}
|
||||
else if (query != null) {
|
||||
if (query instanceof ResultQuery) {
|
||||
return ExecuteType.READ;
|
||||
}
|
||||
else if (query instanceof Insert
|
||||
|| query instanceof Update
|
||||
|| query instanceof Delete
|
||||
|| query instanceof Merge) {
|
||||
|
||||
return ExecuteType.WRITE;
|
||||
}
|
||||
else if (query instanceof Truncate) {
|
||||
return ExecuteType.DDL;
|
||||
}
|
||||
}
|
||||
|
||||
return ExecuteType.OTHER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Query query() {
|
||||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Routine routine() {
|
||||
public final Routine<?> routine() {
|
||||
return routine;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user