use of org.glassfish.api.jdbc.SQLTraceListener in project Payara by payara.
the class SQLTraceDelegator method sqlTrace.
@Override
public void sqlTrace(SQLTraceRecord record) {
if (record != null) {
record.setPoolName(poolName);
if (sqlTraceListeners != null) {
for (SQLTraceListener listener : sqlTraceListeners.values()) {
try {
listener.sqlTrace(record);
} catch (Throwable t) {
// don't let a broken listener break the JDBC calls
logger.log(Level.WARNING, "SQL Trace Listener threw exception", t);
}
}
}
String methodName = record.getMethodName();
// Check if the method name is one in which sql query is used
if (isMethodValidForCaching(methodName)) {
Object[] params = record.getParams();
if (params != null && params.length > 0) {
String sqlQuery = null;
for (Object param : params) {
if (param instanceof String) {
sqlQuery = param.toString();
}
break;
}
if (sqlQuery != null) {
probeProvider.traceSQLEvent(poolName, appName, moduleName, sqlQuery, record.getExecutionTime());
}
}
}
}
}
use of org.glassfish.api.jdbc.SQLTraceListener in project Payara by payara.
the class ManagedConnectionFactoryImpl method detectSqlTraceListeners.
private void detectSqlTraceListeners() {
// Check for sql-trace-listeners attribute.
String sqlTraceListeners = getSqlTraceListeners();
String delimiter = ",";
if (sqlTraceListeners != null && !sqlTraceListeners.equals("null")) {
if (sqlTraceDelegator == null) {
sqlTraceDelegator = new SQLTraceDelegator(getPoolName(), getApplicationName(), getModuleName());
}
StringTokenizer st = new StringTokenizer(sqlTraceListeners, delimiter);
while (st.hasMoreTokens()) {
String sqlTraceListener = st.nextToken().trim();
if (!sqlTraceListener.equals("")) {
Class<?> listenerClass = null;
SQLTraceListener listener = null;
Constructor<?>[] constructors = null;
Class<?>[] parameterTypes = null;
Object[] initargs = null;
// Load the listener class
try {
listenerClass = Thread.currentThread().getContextClassLoader().loadClass(sqlTraceListener);
} catch (ClassNotFoundException ex) {
try {
listenerClass = this.getClass().getClassLoader().loadClass(sqlTraceListener);
} catch (ClassNotFoundException ex2) {
_logger.log(Level.SEVERE, "jdbc.sql_trace_listener_cnfe", sqlTraceListener);
}
}
if (listenerClass != null) {
Class<?>[] intf = listenerClass.getInterfaces();
for (Class<?> interfaceName : intf) {
if (interfaceName.getName().equals("org.glassfish.api.jdbc.SQLTraceListener")) {
try {
constructors = listenerClass.getConstructors();
for (Constructor<?> constructor : constructors) {
parameterTypes = constructor.getParameterTypes();
// TODO should this be documented?
if (parameterTypes != null && parameterTypes.length == 0) {
listener = (SQLTraceListener) constructor.newInstance(initargs);
}
}
} catch (InstantiationException ex) {
_logger.log(Level.SEVERE, "jdbc.sql_trace_listener_exception", ex.getMessage());
} catch (IllegalAccessException ex) {
_logger.log(Level.SEVERE, "jdbc.sql_trace_listener_exception", ex.getMessage());
} catch (IllegalArgumentException ex) {
_logger.log(Level.SEVERE, "jdbc.sql_trace_listener_exception", ex.getMessage());
} catch (InvocationTargetException ex) {
_logger.log(Level.SEVERE, "jdbc.sql_trace_listener_exception", ex.getMessage());
} catch (SecurityException ex) {
_logger.log(Level.SEVERE, "jdbc.sql_trace_listener_exception", ex.getMessage());
}
sqlTraceDelegator.registerSQLTraceListener(listener);
}
}
}
}
}
}
}
Aggregations