Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] fully load model object for use outside of transaction
[CDO] fully load model object for use outside of transaction [message #1835764] Fri, 11 December 2020 19:14 Go to next message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
Hi, I'd like to return CDO model objects from a spring controller to the caller but get a failure during json serialization because serialiization occurs in the spring framework after returning from the controller method and I've closed the CDO transaction by then. Is there a way to fully load a model object such that even after a transaction is closed the fields can be resolved? I'm currently using CDOUtil.getObject(CDOID) to fetch these objects. Should I use getObject(CDOID, loadOnDemand) and with loadOnDemand set to "false" so that it doesn't load on demand and loads everything? Its unclear from the javadoc that I'm looking at what loadOnDemand means in this context. Or does loadOnDemand mean something entirely different?
Re: [CDO] fully load model object for use outside of transaction [message #1835766 is a reply to message #1835764] Fri, 11 December 2020 19:58 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7680
Registered: July 2009
Senior Member
Hi

In EMF, load-on-demand determines where loading a Resource from disk is lazy or eager, not whether the Resource contents are resolved eagerly.

For straight EMF, invoking EcoreUtil.resolveAll on the Resource (or ResourceSet) should visit everything and so force resolution without needing to code a custom traversal. CDO may need more / have a better facility.

Regards

Ed Willink
Re: [CDO] fully load model object for use outside of transaction [message #1835769 is a reply to message #1835766] Fri, 11 December 2020 20:50 Go to previous messageGo to next message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
Thanks Ed. I tried that API but it didn't work for the CDO object so, as you say, there might be a similar API for CDO but I haven't found it yet.
Re: [CDO] fully load model object for use outside of transaction [message #1835770 is a reply to message #1835764] Fri, 11 December 2020 20:54 Go to previous messageGo to next message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
An update to this. I'm actually not using the getCDOObject() method in many cases these are results from CDO queries so a mechanism to resolve an object after its fetched rather than during the fetch would be the simplest to integrate. Although a mechanism to eagerly load the CDO objects during the query would solve the issue too.
Re: [CDO] fully load model object for use outside of transaction [message #1835778 is a reply to message #1835770] Sat, 12 December 2020 09:16 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6690
Registered: July 2009
Senior Member
Hi, I think that quite a few topics are mixed into this thread, most of them probably unrelated to the original question/problem. Nevertheless, here are a few facts:

1) CDOObjects can not be used anymore after the view/transaction that loaded them is closed. That's intentional. If you need to use objects outside of the view/transaction you must copy them before it's closed. In theory you could also detach them from their CDOResource(s) without committing that modification, but copying is the preferred alternative (and the only one if the view is read-only).

2) CDOView.getObject(cdoid, loadOnDemand) fetches an object from the view cache of objects. The loadOnDemand parameter specifies what happens if the requested object is not in the cache. If loadOnDemand is false then null is returned. If loadOnDemand is true then the object is loaded from the repository, cached in the view, and returned.

3) References between persistent CDOObjects work fundamentally different from normal EObjects. EMF's resolve/resolveAll are normally not needed in CDO. The latter can cause many sequential server round-trips. CDO's prefetching mechanisms are usually preferred to load multiple objects / trees in one server round-trip.

4) How a CDOQuery behaves is determined by the server-side IQueryHandler that's selected for the query. See org.eclipse.emf.cdo.internal.server.Repository.getQueryHandler(CDOQueryInfo). Without knowing how exactly you create the CDOQuery on the client-side (e.g., language, parameters, ...) I can't tell how it behaves on the server-side. For example the SQLQueryHandler by default returns CDOIDs over the wire. These are eventually turned into CDOObjects (see point 2 above). This results in additional load requests to the server for the objects that are not yet cached. If that leads to poor performance you can get the query results as CDOIDs instead of CDOObjects. Then you can look them up in the local cache with loadOnDemand=false. This leads to two sets, one with the already cached objects and one with the CDOIDs of the missing objects. The missing objects can then be loaded in one server round-trip, see view.getSession().getRevisionManager().getRevisions(List<CDOID>, ...). BTW., it strikes me that I should add a getObjects(Collection<CDOID>) method directly to CDOView that provides this optimization for multiple object lookups.


Re: [CDO] fully load model object for use outside of transaction [message #1835788 is a reply to message #1835778] Sat, 12 December 2020 17:48 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6690
Registered: July 2009
Senior Member
Eike Stepper wrote on Sat, 12 December 2020 10:16
[...] it strikes me that I should add a getObjects(Collection<CDOID>) method directly to CDOView that provides this optimization for multiple object lookups.


I've added that method: https://bugs.eclipse.org/bugs/show_bug.cgi?id=569680


Re: [CDO] fully load model object for use outside of transaction [message #1835789 is a reply to message #1835764] Sat, 12 December 2020 19:57 Go to previous messageGo to next message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
Thanks for the information on the background operations. I'll go with your suggestion in #1 and create DTOs from the CDO objects since the goal is to provide json data to a UI.
Re: [CDO] fully load model object for use outside of transaction [message #1835792 is a reply to message #1835789] Sun, 13 December 2020 06:57 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6690
Registered: July 2009
Senior Member
You can easily create your DTOs with EcoreUtil.copy() if you want.

Re: [CDO] fully load model object for use outside of transaction [message #1836790 is a reply to message #1835792] Thu, 14 January 2021 03:58 Go to previous message
Warwick Burrows is currently offline Warwick BurrowsFriend
Messages: 132
Registered: July 2009
Location: Austin, TX
Senior Member
Thanks, after reviewing my objects it was simpler and faster to just create small DTOs as the complexity of the entire object wasn't required on the UI.
Previous Topic:load model by using EMF API
Next Topic:[CDO] Can multiple CDO servers be clustered and replicate to each other for high availability?
Goto Forum:
  


Current Time: Wed Dec 04 21:52:38 GMT 2024

Powered by FUDForum. Page generated in 0.04420 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top