transaction

toc
<mm:transaction> The transaction tag creates a transaction. A transaction is a group of actions that should be performed as a whole. If one of the things goes wrong, you can roll them back all.
see alsocommit | cancel
attributes
  • name
    The name of the transaction.
    my_transaction
  • jspvar
    The name of the JSP variable to export.
  • commitonclose
    Whether the transaction must be committed after the body. The default is true.
    true
    false
contextwriter attributes
contextreferrer attributes
cloudreferrer attributes
cloudprovider attributes
example 1
<h3>Canceling transaction</h3>
<mm:transaction name="mytrans" commitonclose="false">
  <mm:createnode type="news">
    <mm:setfield name="title">Test node, created in transaction, canceled</mm:setfield>
    <mm:setfield name="subtitle"><mm:write referid="curtime" /></mm:setfield>
  </mm:createnode>
  <mm:cancel />
</mm:transaction>
Transaction was canceled, following should not result anything:
<mm:listnodes id="l" type="news" constraints="subtitle = `$curtime'">
  <mm:field name="gui()" />
</mm:listnodes>
<br />
<h3>Committing transaction</h3>
<mm:transaction name="mytranz" jspvar="trans">
  jspvar of type Transaction:
    <%= trans instanceof org.mmbase.bridge.Transaction %><br />
  <mm:createnode type="news">
    <mm:setfield name="title">Test node, created in transaction, commited</mm:setfield>
    <mm:setfield name="subtitle"><mm:write referid="curtime" /></mm:setfield>
  </mm:createnode>
</mm:transaction>
transaction was commited, following should result anything:
<mm:listnodes id="node" type="news" constraints="subtitle = `$curtime'" max="1">
  <mm:field name="html(subtitle)">
    <mm:compare referid2="curtime">
        YES (created node was <mm:field id="nodenumber" name="number" />)
        <mm:write referid="nodenumber" session="testnodenumber" />
        <mm:write referid="node" session="testnode" />
    </mm:compare>
  </mm:field>
   <mm:field name="html(title)" />
</mm:listnodes>
<br />
<h3>Creating relation in transaction</h3>
<mm:transaction name="mytranc">
  <mm:node id="node1" number="$nodenumber" />
  <mm:createnode id="node2" type="news">
     <mm:setfield name="title">
        Test node2 with relation, created in transaction
     </mm:setfield>
     <mm:setfield name="subtitle"><mm:write referid="curtime" /></mm:setfield>
  </mm:createnode>
  <mm:createrelation source="node1" destination="node2" role="related" />
</mm:transaction>