Java Reference
In-Depth Information
p.setLastName("Smith");
sqlMapClient.update("updatePerson", p);
}
Where is the transaction? Well, since it's automatic, it just happens behind the
scenes, but it does happen. Many times that is adequate, but sometimes you need
to have finer control, and in those cases, you'll need to use more explicit local or
global transactions.
7.3 L ocal transactions
Local transactions are the most
common type of transaction, and
are really the minimum you
should use on any project involv-
ing a relational database. Even
automatic transactions, as dis-
cussed in the previous section, are a less verbose form of local transaction. A local
transaction is one that is contained within a single application and involves a
resource, such as a relational database, that is capable of only a single transaction.
Figure 7.1 depicts this.
Local transactions are configured in the i BATIS SQL Map configuration XML
file as a JDBC transaction manager. Listing 7.2 shows how the transaction manager
configuration might read.
Start
Commit
End
Application
DB2
Figure 7.1
Local transaction scope
Listing 7.2
Local transaction manager configuration
<transactionManager type= " JDBC ">
<dataSource type="SIMPLE">
<property …/>
<property …/>
<property …/>
</dataSource>
</transactionManager>
The type="JDBC" attribute tells i BATIS to use the standard JDBC Connection API
for managing transactions. Using the SqlMapClient API to demarcate transactions
is very easy. Listing 7.3 shows the typical pattern for transaction demarcation.
Search WWH ::




Custom Search