Hi Mike

I've had some similar thoughts in the past myself.

Where I think this has most use is when some complex mapping is required
thats specified declaratively in XML. eg. when you are navigating over
beans, or XML or SQL and performing complex mappings, where you may set
properties on JDO objects, invoke EJB methods, do some arbitrary SQL, invoke
some web service(s) or output an XML view of your beans or whatever. e.g. in
EAI or implement complex bindings of beans to web service calls or whatever.

I've never quite considered mapping from data objects to JDO yet though. I'm
interested in seeing how this pans out.

James
-------
http://radio.weblogs.com/0112098/
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, November 27, 2002 1:18 PM
Subject: [Jelly] Tags to create or transform an object graph


Hi,

Many people are using the DTO "pattern" in their webapps to transfer data
back and forth between their persistence and presentation layers.  For those
who decide to adopt this pattern, they find themselves with two different
object models: the persistence (domain) model which is mapped to an
underlying data store and a Java Bean model that is used by the JSPs and
Struts actions or what have you.  The problem with this is that you find
yourself writing a tonne of this kind of get()/set() code:

  domainObject.setName(beanObject.getName());

Additonally, if you are using some kind of O/R mapping runtime, you want to
do a set() only if it required, to limit the number of SQL UPDATE
statements, so you have code like this everywhere:

if ( !(domainObject.getName().equals(beanObject.getName())) ) {
domainObject.setName(beanObject.getName());
}

I am half way through a set of Jelly tags that allow me succinctly describe
the rules involved in this kind of situation.

The above Java can be stated as

<graph:set from="name" to="name"/>

(assuming domainObject and beanObject are in the JellyContext and named as
"target" and "source").

Sometimes more complex mappings are required:

<graph:map name="person.site" sourceKeys="country.id,language.id"
targetKeys="country.countryCode,language.languageCode">
    <graph:change>
        <graph:lookup target="site" sourceKeys="country.id,language.id"/>
    </graph:change>
    <graph:prune objects="site"/>
</graph:map>

What this says is "if source.getCountry().getId() and
source.getLanguage().getId() are different to
target.getCountry().getCountryCode() and
target.getLanguage().getLanguageCode() resp, then set target.site to the
result of a lookup based on specified params.  (lookup uses an
ObjectManager.lookup() instance, available from the context).
Alternatively, if either of the sourceKeys is missing or valueless, prune
target.site".

Now, I guess this is more likely to make sense if, like me, you are using
JDO as your persistence runtime.  This allows the graph mapper to surf
references as it needs, driven by the Jelly script.  But, what I wanted to
know is is there a better way to do this, is somebody else working on
something similar and, if not, whether you would consider sucking these tags
into the Jelly dist and allow many minds to make them better ;-)

Thanks a mil,
Mike.

PS I initially looked at using JXPath to do this, but that is good at
pulling data out of a graph, but not so good at transforming a target graph
based on the content of a source graph.  Pruning is the biggest problem I
see, but I am open to correction.

--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to