Encapsulates a transaction.
<dsp:demaracateTransaction var-spec
>
...
</dsp:demaracateTransaction>
Attributes
var-spec
Defines an EL variable or scripting variable with one of these attributes:
Attribute | Description |
---|---|
| Names an EL variable. When you use |
| Names a scripting variable that scriptlets and expressions can access at runtime. |
The variable has three properties:
success
: A Boolean property, specifies the status of transaction. A call toisSuccess
obtains the property’s setting:true
: The start and commit operations succeeded.false
: The start or commit operation failed.
exception
: Identifies theThrowable
exception object produced when a transaction fails to start properly. A call togetException
returns the exception object.commitException
: Identifies theThrowable
exception object produced when a transaction fails to commit. A call togetCommitException
returns the exception object
Usage Notes
The dsp:demarcateTransaction
tag manages a transaction by starting it, checking it for errors, committing the transaction if no errors exist, and rolling back the transaction if errors occur. This tag creates a variable whose properties—success
, exception
, and commitException
—indicate the status of the transaction.
Note: An error might occur if dsp
:demarcateTransaction
starts execution when another transaction is in progress.
Example
The following example assumes the following conditions are true:
currentStudent
is a page parameter that is set while a servlet bean iterates through all students in a class.A mechanism exists to consecutively save each student’s grade to the
currentGrade
page parameter.
<dsp:importbean bean="\atg\samples\Student_01" var="student"/> <dsp:importbean bean="\atg\samples\Algebra" /> <dsp:demarcateTransaction var="demarcateXA"> <dsp:setvalue bean="Algebra.class.student" value="${student.name}"/> <dsp:setvalue bean="Algebra.class.grade" value="${student.grade}"/> <c:if test="${!demarcateXA.success}"> The grade could not be processed. Here's why: <c:choose> <c:when value="${!empty demarcateXA.exception}"/> <c:out value="${demarcateXA.exception}"/> <c:when value="${!empty demarcateXA.commitException}"/> <c:out value="${demarcateXA.commitException}"/> </c:choose> </c:if> </dsp:demarcateTransaction>
In this example, the transaction encapsulates the tasks required to save the grades provided to students in a class. The transaction ensures that student names and grades are added to Algebra.Student_01
at the same time. If the transaction fails, no name or grade is saved; instead, the appropriate message displays for the exception
or commitException
exceptions.