Java Reference
In-Depth Information
The Transaction Script pattern concentrates behavior in the transaction scripts
rather than distributing it among multiple domain classes. This pattern tends not
to work well when the business logic is complex because transaction scripts consist
of procedural code, which is usually hard to understand and maintain. You also
have to write a lot more database access code when using this pattern. Conse-
quently, this pattern should only be used when either the application's business
logic is extremely simple or when it is not possible to efficiently access the data-
base using a persistence framework.
Transaction scripts should not access the database directly because that would
mix business logic with database code and make development and testing harder.
Instead, they should use DAO s that encapsulate the database access code. The
transaction scripts are configured with the DAO s via constructor parameters,
which enables them to be developed and tested using mock DAO s.
The DAO s used by the transaction scripts could use JDBC . However, a much
better approach is to use the i BATIS framework, which significantly reduces the
amount of code required to execute SQL statements. i BATIS takes care of map-
ping Java objects to SQL statement parameters, calling JDBC to execute the SQL
statement, and mapping the ResultSet to one or more Java objects. Therefore,
many DAO methods consist of a single line of code that calls an i BATIS method.
When developing an application's business logic, you do not have to exclu-
sively use either the Domain Model pattern or the Transaction Script pattern. You
should instead choose the pattern that is most appropriate for each request. You
could, for example, implement the first step of a use case using a transaction
script that retrieves a list of orders using a complex SQL query and implement the
rest of use case using domain model-based business logic that manipulates indi-
vidual orders.
Now that we have covered the Transaction Script pattern, the next chapter
tackles implementing POJO s with EJB 3 .
Search WWH ::




Custom Search