Information Technology Reference
In-Depth Information
1.2 The Traditional Query Mode
In the traditional query mode, the query conditions need to be transferred from web
layer to business object, and then the business object constructs select statements by
listing out the conditions. It is traditional to use Map as a container of conditions.
However, the Map can only transfer the name and value, not deliver the logic of con-
ditions that is conditional expressions, thus, the business object has to involve many
conditional expressions. So once the logic of conditions change, the business object
must be modified accordingly, and it's prone to much error.
1.3 The Off-line Query Based on Middle Layer
To solve the above problem, this paper used another query mode; called DetachedCri-
teria. DetachedCriteria is an off-line query mode, used to build up Criteria outside the
scope of a session. DetachedCriteria can purity the DAO, so that DAO can concen-
trate on accessing database. In this case, it's not need to add conditions in the DAO,
instead all of query conditions are encapsulated into a detached object, and then the
detached object is transferred to DAO without having to using any data transfer ob-
jects. You can later on reattach the detached object to another session. Choosing De-
tachedcriteria query mode, the codes of program can be reduced and the boundary of
every layer is also delimited. The working way of Detachedcriteria between the JSF
and Hibernate is shown in Figure 1:
Fig. 1. The working way of Detachedcriteria between the JSF and Hibernate
None the less, Detachedcriteria object is still exposed to the web layer. It isn't good
to divide the front and back labors. The web programmer has to learn some knowl-
edge of Detachedcriteria. So it's necessary to design a middle layer to encapsulate
Detachedcriteria object, thus the details of Detachedcriteria is transparent to the web
programmer. In this way, the JSF and Hibernate are really separated. The whole
framework after adding the Middle Layer is shown in Figure 2:
Search WWH ::




Custom Search