The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » Metro and JAXB

Thread: best way to copy SOAP <-> ORM ?

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 5 - Last Post: Sep 4, 2008 9:09 AM by: caroljmcdonald
Felipe Gaúcho
best way to copy SOAP <-> ORM ?
Posted: Sep 2, 2008 1:17 AM
  Click to reply to this thread Reply

Few days evaluating my options about binding my SOAP message objects
to my JPA entities....

I have:

A soap type, let's say A
A JPA entity type, let's say B

@XmlType(name = "", propOrder = {"number", ... })
class A { int number; .. }

@Entity
class B { int other; ... }

How to copy the values of the message to the entity ??

Options I am considering right now:

1) Brute force, copying one by one the fields and properties from one
side to another. Simple, fast and the most reliable solution, but with
a lot of identical code for all entities... The number of line codes
required to copy is linearly coupled with the number of entities and
its attributes (can be thousands of lines to code and maintain).

2) Reflection: trying to match the getters and setters names.. it
works fine for shallow copy but becomes wierd in collections and deep
clonage (Dozer mess). Reflection reduces the number of lines, ad
depending on the simplicity of the models, can be a good option. You
pay a bit of performance but in my early experiments, the cost/benefit
of reflection is good.

3) Adapters using annotations:
http://tssblog.blogs.techtarget.com/2007/02/08/combining-orm-and-soap-part-1/
* My problem is not to convert Object to XML, it is to convert
Object to Object (from different models)

3) Inheritance between the soap objects and entities (entities are
subclasses of XML generated objects, so I need to copy only from xml
to entites, the reverse order is naturally bounded by casting. What
means you solve half of the problem :)

hoping to hear from you something new :)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
For additional commands, e-mail: users-help@metro.dev.java.net


wasppit

Posts: 32
Re: best way to copy SOAP <-> ORM ?
Posted: Sep 2, 2008 3:02 AM   in response to: Felipe Gaúcho
  Click to reply to this thread Reply

You could try writing your own XJC plugin which injects specific converter code into your generated beans.

I've done this to generate custom serializers and I can say it's way faster than using reflection.

Felipe Gaúcho
Re: best way to copy SOAP <-> ORM ?
Posted: Sep 2, 2008 3:05 AM   in response to: wasppit
  Click to reply to this thread Reply

even worse, because I am looking to reduce the amout of plumbing code
of copying from one side to another.... and also to reduce the cost of
that copying operation (proceed several times in the common
web-services operations...)

injecting the adapter I will add another cost in my adaption process...

On Tue, Sep 2, 2008 at 12:02 PM, <metro@javadesktop.org> wrote:
> You could try writing your own XJC plugin which injects specific converter code into your generated beans.
>
> I've done this to generate custom serializers and I can say it's way faster than using reflection.
> [Message sent by forum member 'wasppit' (wasppit)]
>
> http://forums.java.net/jive/thread.jspa?messageID=296645
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
> For additional commands, e-mail: users-help@metro.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
For additional commands, e-mail: users-help@metro.dev.java.net


wasppit

Posts: 32
Re: best way to copy SOAP <-> ORM ?
Posted: Sep 2, 2008 3:37 AM   in response to: Felipe Gaúcho
  Click to reply to this thread Reply

Well, the code would be generated, so you should only care about the extra jar size. Injection happens at build time, therefore you have no runtime penalty.

The trick is to inject specific code, e.g. if a bean has 2 fields, than only 2 lines of code will be generated, tailored for those 2 fields. This is as fast as it gets.

By the way, are your soap beans generated from wsdl/xsd or are you writing them by hand?

Felipe Gaúcho
Re: best way to copy SOAP <-> ORM ?
Posted: Sep 2, 2008 4:04 AM   in response to: wasppit
  Click to reply to this thread Reply

my project is WSDL first.. it is generated automatically by wsimport...

Full source code available is you want to check it out:
https://cejug-classifieds.dev.java.net/

---------- if you want to try:

SVN: https://cejug-classifieds.dev.java.net/svn/cejug-classifieds/trunk/cejug-classifieds-server

after checkout:

- setup the environment variable AS_HOME
- start database and server:
asadmin start-database
asadmin start-domain domain1

and run ant deploy

The project will be up and running at
http://localhost:8080/cejug-classifieds-server



On Tue, Sep 2, 2008 at 12:37 PM, <metro@javadesktop.org> wrote:
> Well, the code would be generated, so you should only care about the extra jar size. Injection happens at build time, therefore you have no runtime penalty.
>
> The trick is to inject specific code, e.g. if a bean has 2 fields, than only 2 lines of code will be generated, tailored for those 2 fields. This is as fast as it gets.
>
> By the way, are your soap beans generated from wsdl/xsd or are you writing them by hand?
> [Message sent by forum member 'wasppit' (wasppit)]
>
> http://forums.java.net/jive/thread.jspa?messageID=296660
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
> For additional commands, e-mail: users-help@metro.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
For additional commands, e-mail: users-help@metro.dev.java.net


caroljmcdonald

Posts: 13
Re: best way to copy SOAP <-> ORM ?
Posted: Sep 4, 2008 9:09 AM   in response to: Felipe Gaúcho
  Click to reply to this thread Reply

I have 2 examples in my blog, one that uses jax-ws and JPA
http://weblogs.java.net/blog/caroljmcdonald/archive/2007/09/sample_applicat_2.html

and one that uses JAX-RS and JPA
http://weblogs.java.net/blog/caroljmcdonald/archive/2008/08/a_restful_pet_c.html

I built both of them using code that Netbeans generates for JPA and JAX-RS or JPA, JSF, and JAX-WS respectively.
Here is an example of JAXB code generated by the Netbeans JAX-RS wizard , Item is a JPA entity class:

@XmlRootElement(name = "item")
public class ItemConverter {
public ItemConverter(Item entity) {
this.entity = entity;
}
@XmlElement
public Long getId() {
return getEntity().getId();
}
....




 XML java.net RSS