[frs-366] Workaround: 0 Query Count Returned From FRAPI Request Objects


FusionRequest objects obtained using FRAPI calls including getRunningRequests() return 0 from the call jdbcTotalQueryCount(), even if queries have been run prior to the call.

This is a bug.


The following code can be used to obtain this value until this bug is fixed.

The key operations are within the cfscript try/catch block, and use Reflection to obtain the relevant data.

<cfset frapiClass = createObject("java","com.intergral.fusionreactor.api.FRAPI") />
<cfset Thread = createObject("java", "java.lang.Thread")/>
<cfset frapi = frapiClass.getInstance() />
<cfset requests = frapi.getRunningRequests() />

<cfloop array="#requests#" index="frRequest">	    		
    <cfif frRequest.getThread() eq Thread.currentThread().getName()>	    			
                txnField = frRequest.getClass().getDeclaredField("txn");
                txn = txnField.get(frRequest);

                if( isNull(txn.getMasterTransaction()) )
                    masterTxn = txn;
                    masterTxn = txn.getMasterTransaction();

                jdbcQueries = masterTxn._getSubTransactionFlavourCount("JDBCRequest");
            catch(any e)
                jdbcQueries = 0;


The workaround uses Java Reflection to obtain an internal field, then queries that to obtain the count of JDBC Requests run in the context of the current request.

If Java is running in a (non-default) security mode, the Reflection calls may fail. In this case, the catch block will be used to default the query count, without causing an error in the page.

Issue Details

Type: Technote
Issue Number: FRS-366
Components: FRAPI
Resolution: Fixed
Last Updated: 12/Nov/15 11:17 AM
Affects Version: 4.5.0, 5.0.0, 5.2.8
Fixed Version: 6.x
Related Issues:

FRS-372: Use FRAPI To Log CFThrow Errors, and Set HTTP Response Codes

Comments are closed.