Search in sources :

Example 1 with SQLTraceStoreAdapter

use of fish.payara.jdbc.SQLTraceStoreAdapter 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;
}
Also used : SlowSQLLogger(fish.payara.jdbc.SlowSQLLogger) SQLTraceDelegator(com.sun.gjc.util.SQLTraceDelegator) SQLTraceStoreAdapter(fish.payara.jdbc.SQLTraceStoreAdapter) RequestTracingListener(fish.payara.jdbc.RequestTracingListener)

Aggregations

SQLTraceDelegator (com.sun.gjc.util.SQLTraceDelegator)1 RequestTracingListener (fish.payara.jdbc.RequestTracingListener)1 SQLTraceStoreAdapter (fish.payara.jdbc.SQLTraceStoreAdapter)1 SlowSQLLogger (fish.payara.jdbc.SlowSQLLogger)1