Java Reference
In-Depth Information
9.1.3
When to use the Transaction Script pattern
As you have just seen, business logic organized using the Transaction Script pat-
tern can be hard to maintain because it is procedural and typically uses handwrit-
ten SQL to access the database. However, there are four main situations where the
Transaction Script pattern is the best choice.
The application must use SQL directly
One common reason to use the Transaction Script pattern is if the application
must execute SQL directly because it needs to access the database in ways that are
not efficiently supported by the persistence framework. However, it is important
to keep in mind that persistence frameworks are constantly improving. JDO and
Hibernate have powerful query languages and they both support SQL queries,
which means that you can implement more of your business logic with the
Domain Model pattern. In addition, Hibernate 3.0 and EJB 3 support bulk
updates and deletes, which reduces the need to use SQL . As a result, the need to
directly use SQL directly is diminishing
A persistence framework is unavailable
It can also make sense to use the Transaction Script pattern if the application can-
not use a persistence framework. Budget issues and preference of the architect or
developers are just two reasons why you'd want to take this approach. In this case,
the developers must use SQL directly to access the database. In principle, you
could write JDBC code to persist a domain model, but this is usually impractical if
the domain model is complex.
The business logic is very simple
You might consider using the Transaction Script pattern if the business logic is
very simple and developing a domain model is not worthwhile. For example, if
the application just queries a database and displays the data, then it could very
well be a candidate for the Transaction Script pattern.
The development team doesn't have OO design skills
Developing a domain model requires the development team to have OO design
skills, which is not always the case. It is better to succeed with a procedural trans-
action script-based design rather than fail with a domain model.
Now that we have gotten an overview of the Transaction Script pattern and its
benefits and drawbacks, let's see how to develop transaction script-based business
logic.
 
 
 
 
 
Search WWH ::




Custom Search