Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any limitation with number queries/statements we can write inside cftransaction?

Today while fixing bugs in some existing code I found a strange error.

Branch target offset too large for short

After searching I found that it is something to do with Java byte code conversion. Here are the links I found:

  • Branch target offset too large for short
  • Branch Target Offset Error
  • Why does a long cfc file work in CF8, but not CF9? Getting "Branch target offset too large for short" error

In my case cftransaction contains around 870 statements and it's working fine. But I need to add 2 more queries to this transaction. Now I am getting this error when I am adding even one line of code inside cftransaction. Currently I can not move any of the existing cfquery out of the cftransaction.

Here is the overall structure of the code:

<cftransaction action="begin">

   <cfif URL.action eq 'add'>
         Around 200 lines of queries/statements
   <cfelseif URL.action eq 'edit'>
        Around 200 lines of queries/statements
   </cfif>

    <cfif URL.action eq 'add' or URL.action 'edit'>
          Around 450 lines of queries/statements
    </cfif>

</cftransaction>

Is there any workaround to fix this problem?

like image 542
Deepak Kumar Padhy Avatar asked Jun 24 '15 11:06

Deepak Kumar Padhy


1 Answers

Branch offset has to do with the size of the module/function. It can also be caused due to a large conditional code block of cfif/cfelse or cfswitch.

Technically, I am not sure if there is any cap on the no. of queries you can put inside the cftransaciton block. It has nothing to do with the code migration from CF8 to CF9 but the length of your code inside conditional blocks.

I would want to split the function and try to put the each of the big sized conditional blocks as a separate function inside the cfc:

 <cffunction name="myFunc1">
    <cftransaction action="begin">
      <cfif URL.action eq 'add'>
        <!--- function call with your xxx lines of queries/statements --->
        <cfinvoke component="MyCfc" method="firstQueryBlock" result="result1">
      <cfelseif URL.action eq 'edit'>
        <!--- second function call with your yyy lines of queries/statements --->
        <cfinvoke component="MyCfc" method="secondQueryBlock" result="result2">
      </cfif>

       <cfif URL.action eq 'add' or URL.action 'edit'>
            <!--- third function call with your zzz lines of queries/statements --->
            <cfinvoke component="MyCfc" method="thirdQueryBlock" result="result3">
       </cfif>
    </cftransaction>
 </cffunction>
like image 110
Anurag Avatar answered Nov 01 '22 20:11

Anurag