Java Reference
In-Depth Information
Let's look at the details:
B
The constructor takes the real PendingOrder and the total computed by the busi-
ness tier as parameters and stores them in fields.
C
D
Most methods delegate to the PendingOrder .
The getTotal() method returns the value stored in a field.
Adapters are somewhat similar to DTO s except that they do not involve copying as
much data because they delegate to the domain object. They are useful when
some values must be computed by the business tier. However, one downside of
using adapters is that you have to write more code than you would if the domain
object implemented an interface. In the extreme case, an adapter could store so
many values that it would effectively be a DTO .
7.2.2
Detaching objects
Another important POJO façade design issue is how to detach the domain objects
that are returned to the presentation tier. Each POJO façade method must ensure
that the object graph it returns to the presentation tier contains all of the
required objects. Otherwise, an exception will be thrown when the presentation
tier tries to access a missing object or collection. For example, if the presentation
tier displays the PendingOrder and its restaurant's menu items, the business tier
must load those objects from the database and detach them. Let's look at the
details of how to do this with JDO and Hibernate.
Using JDO detached objects
JDO will throw an exception if the application tries to access the field of an object
after its PersistenceManager is closed. In order to return JDO objects to the pre-
sentation tier, the façade must first call JDO to detach the object graph from a
PersistenceManager . Later on, it can call JDO to reattach the object graph to a
new PersistenceManager .
A JDO application detaches objects by calling either Persistence-
Manager.detachCopy() , which returns detached copy of the specified object, or
PersistenceManager.detachCopyAll() , which returns a list of detached copies of
the specified objects. By default, these methods will detach only the objects that
are passed to them and not any referenced objects. For example, if you call
detachCopy() with a PendingOrder , its default behavior is to return a copy of the
PendingOrder whose line items, restaurant, and coupon fields are not initialized—
a JDODetachedObjectAccessException will be thrown if the application tries to
access them.
 
 
 
 
 
 
Search WWH ::




Custom Search