use of com.sun.gjc.util.SQLTraceDelegator in project Payara by payara.
the class ManagedConnectionImpl method getConnection.
/**
* Creates a new connection handle for the underlying physical
* connection represented by the <code>ManagedConnectionImpl</code> instance.
*
* @param sub <code>Subject</code> parameter needed for authentication
* @param cxReqInfo <code>ConnectionRequestInfo</code> carries the user
* and password required for getting this connection.
* @return Connection the connection handle <code>Object</code>
* @throws ResourceException if there is an error in allocating the
* physical connection from the pooled connection
* @throws javax.resource.spi.SecurityException
* if there is a mismatch between the
* password credentials or reauthentication is requested
*/
@Override
public Object getConnection(Subject sub, javax.resource.spi.ConnectionRequestInfo cxReqInfo) throws ResourceException {
logFine("In getConnection");
checkIfValid();
/**
* Appserver any way doesnt bother about re-authentication today. So commenting this out now.
* com.sun.gjc.spi.ConnectionRequestInfo cxRequestInfo = (com.sun.gjc.spi.ConnectionRequestInfo) cxReqInfo;
* PasswordCredential passwdCred = SecurityUtils.getPasswordCredential(this.mcf, sub, cxRequestInfo);
*
* if(SecurityUtils.isPasswordCredentialEqual(this.passwdCredential, passwdCred) == false) {
* throw new javax.resource.spi.SecurityException("Re-authentication not supported");
* }
*/
// GJCINT
getActualConnection();
ManagedConnectionFactoryImpl spiMCF = (ManagedConnectionFactoryImpl) mcf;
String statementTimeoutString = spiMCF.getStatementTimeout();
if (statementTimeoutString != null) {
int timeoutValue = Integer.parseInt(statementTimeoutString);
if (timeoutValue >= 0) {
statementTimeout = timeoutValue;
}
}
if (sqlTraceDelegator == null) {
if ((requestTracing != null && requestTracing.isRequestTracingEnabled()) || (isSlowQueryLoggingEnabled())) {
sqlTraceDelegator = new SQLTraceDelegator(spiMCF.getPoolName(), spiMCF.getApplicationName(), spiMCF.getModuleName());
}
}
if (sqlTraceDelegator != null) {
if (requestTracing != null && requestTracing.isRequestTracingEnabled()) {
// This method will only register a request tracing listener
// if one doesn't already exist
sqlTraceDelegator.registerSQLTraceListener(new RequestTracingListener());
} else {
/**
* If request tracing is not enabled, but there is a SQL trace
* delegator, deregister the request tracing listener if one is
* registered.
*/
sqlTraceDelegator.deregisterSQLTraceListener(RequestTracingListener.class);
}
if (!isSlowQueryLoggingEnabled()) {
sqlTraceDelegator.deregisterSQLTraceListener(SlowSQLLogger.class);
sqlTraceDelegator.deregisterSQLTraceListener(SQLTraceStoreAdapter.class);
} else {
sqlTraceDelegator.registerSQLTraceListener(new SlowSQLLogger(getSlowQueryThresholdInMillis(), TimeUnit.MILLISECONDS));
sqlTraceDelegator.registerSQLTraceListener(new SQLTraceStoreAdapter());
}
/**
* If there are no longer any listeners registered, set the
* delegator to null to prevent
* JdbcObjectsFactory().getConnection(...) from using a profiled
* wrapper unnecessarily.
*/
if (!sqlTraceDelegator.listenersRegistered()) {
sqlTraceDelegator = null;
}
}
myLogicalConnection = spiMCF.getJdbcObjectsFactory().getConnection(actualConnection, this, cxReqInfo, spiMCF.isStatementWrappingEnabled(), sqlTraceDelegator);
// TODO : need to see if this should be executed for every getConnection
if (!initSqlExecuted) {
// Check if Initsql is set and execute it
String initSql = spiMCF.getInitSql();
executeInitSql(initSql);
}
incrementCount();
isClean = false;
myLogicalConnection.setActive(true);
return myLogicalConnection;
}
use of com.sun.gjc.util.SQLTraceDelegator 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);
}
}
}
}
}
}
}
use of com.sun.gjc.util.SQLTraceDelegator in project Payara by payara.
the class ManagedConnectionFactoryImpl method setSlowQueryThresholdInSeconds.
public void setSlowQueryThresholdInSeconds(String seconds) {
spec.setDetail(DataSourceSpec.SLOWSQLLOGTHRESHOLD, seconds);
double threshold = Double.parseDouble(seconds);
if (threshold > 0) {
if (sqlTraceDelegator == null) {
sqlTraceDelegator = new SQLTraceDelegator(getPoolName(), getApplicationName(), getModuleName());
}
}
}
Aggregations