views:

272

answers:

1

I have a bunch of annotated, interrelated POJOs that I want to create/modify/search over SOAP. I made a utility to eagerly load every detail of each POJO and create an XML string so I can send the entire POJO graph as a search result. Even though the graphs are very small (less than three nodes), the eager loading took a very long time (500ms/node).

It seems like the bottleneck is having to eager the entire graph of each node. Is it somehow possible to just lazy load over SOAP? What are some other alternatives?

+1  A: 

It is possible to lazy load over SOAP, but it's rather involved. And it most definitely won't be faster :-)

Basically, you'll need to create proxies for your POJOs (using bytecode instrumentation) that will know how to load full object (or its individual property if you want to get down to that level) over SOAP. If that sounds like repeating what Hibernate does, it's because it is :-) This approach only makes sense when the "remotely-lazy" properties are not likely to be accessed by the client that often AND are really expensive to eagerly load to begin with.

Another possible approach is to add "inflation level" parameter to your SOAP API calls, something along the lines of SELF (direct properties only) / CHILDREN (direct children) / FULL (full object tree), which would cause only appropriate properties to be initialized. That delegates responsibility for obtaining properly inflated object to the client (which presumably knows what it needs to work with).

ChssPly76
I was thinking about that proxy approach. Can you point me to some good resources or give sample code on how to use bytecode instrumentation to build a proxy? It sounds like it's in hibernate somewhere.
User1
Take a look at CGlib (http://cglib.sourceforge.net) or Javassist - they both have examples on dynamic proxy creation. Your proxy will then need to maintain its own state (per entity or per property, depending on what you want) and fill missing data on first access by calling back your SOAP service. You'll have to provide access details (URL, credentials, etc...) to proxy during creation or obtain them from client envrionment.
ChssPly76