Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » CDO resourceSet
CDO resourceSet [message #423302] Fri, 26 September 2008 17:02 Go to next message
Paul Richardson is currently offline Paul RichardsonFriend
Messages: 33
Registered: July 2009
Member
Hi,

I maybe missing something vital but it seems that my resources are not
being added to my transaction's resourceSet.

When I do an initial connect with a new transaction, I supply my
transaction with a resourceSet.

However, if I get an ITreeItemContentProvider adapter from my model's
edit package and call getChildren(), the object's children are retrieved
but their resources are not added to the resourceSet.

Is this normal behaviour and I am misunderstanding how children are
retrieved?

How can I get the resources to be added to the resourceSet on account of
the fact that a NullPointerException seems to be thrown if I do
resourceSet.getResources().add(resource) in getChildren, ie. try and add
the resources manually:

java.lang.NullPointerException
at
org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyAdd(CDOVie wSetImpl.java:300)
at
org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyChanged(CD OViewSetImpl.java:250)
at
org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:247)
at
org.eclipse.emf.common.notify.impl.NotifyingListImpl.dispatc hNotification(NotifyingListImpl.java:267)
at
org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:300)
at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
at
isse.folder.provider.ISSEFolderItemProvider.getChildren(ISSE FolderItemProvider.java:162)

Code in getChildren() or ISSEFolderItemProvider:

Collection <?> children = super.getChildren(object);
System.out.println("children size: " + children.size());
for (Object child : children)
{
/* The resourceSet in connection is the same as that supplied to the
transaction upon initialisation of the cdo session */
ISSEConnection connection = ((ISSEFolder) object).getFolderStore();
ResourceSet resourceSet = connection.getResourceStore();
if (child instanceof EObject && !
resourceSet.getResources().contains(((EObject) child).eResource()))
{
resourceSet.getResources().add(((EObject) child).eResource());
}

for (Resource res : resourceSet.getResources())
System.out.println("Resources in resourceSet from getChildren() " +
res);
}

return children;


Thanks

PGR
Re: CDO resourceSet [message #423313 is a reply to message #423302] Sat, 27 September 2008 11:17 Go to previous messageGo to next message
Paul Richardson is currently offline Paul RichardsonFriend
Messages: 33
Registered: July 2009
Member
Replying to my own post but have found out more information that may help.

It would seem that the getChildren() call eventually winds up requesting
the resource of the referenced children using
CDOViewImpl.getResource(CDOID) (stacktrace at bottom of reply):

public CDOResourceImpl getResource(CDOID resourceID)
{
if (resourceID == null || resourceID.isNull())
{
throw new IllegalArgumentException("resourceID == null ||
resourceID.isNull()");
}

CDOResourceImpl resource = (CDOResourceImpl)getObject(resourceID);
if (resource != null)
{
return resource;
}

<snip>
}

So the transaction (CDOViewImpl) successfully returns the resource but
never adds it to its resourceSet. Unlike methods such as
createResource() which explicitly use the resourceSet. Is this an
oversight or is there some important reason for not adding the resource?

If former, then I will file a bug,

Cheers

PGR


org.eclipse.emf.internal.cdo.CDOViewImpl.getResource(CDOView Impl.java:323)
org.eclipse.emf.internal.cdo.CDOViewImpl.cleanObject(CDOView Impl.java:546)
org.eclipse.emf.internal.cdo.CDOViewImpl.createObject(CDOVie wImpl.java:528)
org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:432)
org.eclipse.emf.internal.cdo.CDOTransactionImpl.getObject(CD OTransactionImpl.java:270)
org.eclipse.emf.internal.cdo.CDOViewImpl.convertIDToObject(C DOViewImpl.java:654)
org.eclipse.emf.internal.cdo.CDOStore.get(CDOStore.java:162)
org.eclipse.emf.internal.cdo.CDOObjectImpl$CDOStoreEList.del egateGet(CDOObjectImpl.java:919)
org.eclipse.emf.common.util.DelegatingEList.get(DelegatingEL ist.java:396)
org.eclipse.emf.common.util.DelegatingEList$EIterator.doNext (DelegatingEList.java:1075)
org.eclipse.emf.common.util.DelegatingEList$EIterator.next(D elegatingEList.java:1062)
org.eclipse.emf.edit.provider.ItemProviderAdapter.getChildre n(ItemProviderAdapter.java:340)


phantomjinx wrote:
> Hi,
>
> I maybe missing something vital but it seems that my resources are not
> being added to my transaction's resourceSet.
>
> When I do an initial connect with a new transaction, I supply my
> transaction with a resourceSet.
>
> However, if I get an ITreeItemContentProvider adapter from my model's
> edit package and call getChildren(), the object's children are retrieved
> but their resources are not added to the resourceSet.
>
> Is this normal behaviour and I am misunderstanding how children are
> retrieved?
>
> How can I get the resources to be added to the resourceSet on account of
> the fact that a NullPointerException seems to be thrown if I do
> resourceSet.getResources().add(resource) in getChildren, ie. try and add
> the resources manually:
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyAdd(CDOVie wSetImpl.java:300)
>
> at
> org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyChanged(CD OViewSetImpl.java:250)
>
> at
> org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:247)
>
> at
> org.eclipse.emf.common.notify.impl.NotifyingListImpl.dispatc hNotification(NotifyingListImpl.java:267)
>
> at
> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:300)
>
> at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
> at
> isse.folder.provider.ISSEFolderItemProvider.getChildren(ISSE FolderItemProvider.java:162)
>
>
> Code in getChildren() or ISSEFolderItemProvider:
>
> Collection <?> children = super.getChildren(object);
> System.out.println("children size: " + children.size());
> for (Object child : children)
> {
> /* The resourceSet in connection is the same as that supplied to the
> transaction upon initialisation of the cdo session */
> ISSEConnection connection = ((ISSEFolder) object).getFolderStore();
> ResourceSet resourceSet = connection.getResourceStore();
> if (child instanceof EObject && !
> resourceSet.getResources().contains(((EObject) child).eResource()))
> {
> resourceSet.getResources().add(((EObject) child).eResource());
> }
>
> for (Resource res : resourceSet.getResources())
> System.out.println("Resources in resourceSet from getChildren() " +
> res);
> }
>
> return children;
>
>
> Thanks
>
> PGR
Re: CDO resourceSet [message #423317 is a reply to message #423313] Sat, 27 September 2008 13:42 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Hi PGR,

Apologies, I must have marked your mail as read by accident.

I don't really understand what you are doing with your ResourceSet.
Usually you should not add() CDOResources yourself.

What you describe below sounds like a bug but the context,
i.e. getResource(CDOID), is so "normal" that I can't believe it.

I can't fight the feeling that it is caused somehow by a wrong usage
of the ResourceSet or the CDOResources. Could you explain in
more detail what you're doing?

Cheers
/Eike



phantomjinx schrieb:
> Replying to my own post but have found out more information that may
> help.
>
> It would seem that the getChildren() call eventually winds up
> requesting the resource of the referenced children using
> CDOViewImpl.getResource(CDOID) (stacktrace at bottom of reply):
>
> public CDOResourceImpl getResource(CDOID resourceID)
> {
> if (resourceID == null || resourceID.isNull())
> {
> throw new IllegalArgumentException("resourceID == null ||
> resourceID.isNull()");
> }
>
> CDOResourceImpl resource = (CDOResourceImpl)getObject(resourceID);
> if (resource != null)
> {
> return resource;
> }
>
> <snip>
> }
>
> So the transaction (CDOViewImpl) successfully returns the resource but
> never adds it to its resourceSet. Unlike methods such as
> createResource() which explicitly use the resourceSet. Is this an
> oversight or is there some important reason for not adding the resource?
>
> If former, then I will file a bug,
>
> Cheers
>
> PGR
>
>
> org.eclipse.emf.internal.cdo.CDOViewImpl.getResource(CDOView Impl.java:323)
>
> org.eclipse.emf.internal.cdo.CDOViewImpl.cleanObject(CDOView Impl.java:546)
>
> org.eclipse.emf.internal.cdo.CDOViewImpl.createObject(CDOVie wImpl.java:528)
>
> org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:432)
> org.eclipse.emf.internal.cdo.CDOTransactionImpl.getObject(CD OTransactionImpl.java:270)
>
> org.eclipse.emf.internal.cdo.CDOViewImpl.convertIDToObject(C DOViewImpl.java:654)
>
> org.eclipse.emf.internal.cdo.CDOStore.get(CDOStore.java:162)
> org.eclipse.emf.internal.cdo.CDOObjectImpl$CDOStoreEList.del egateGet(CDOObjectImpl.java:919)
>
> org.eclipse.emf.common.util.DelegatingEList.get(DelegatingEL ist.java:396)
> org.eclipse.emf.common.util.DelegatingEList$EIterator.doNext (DelegatingEList.java:1075)
>
> org.eclipse.emf.common.util.DelegatingEList$EIterator.next(D elegatingEList.java:1062)
>
> org.eclipse.emf.edit.provider.ItemProviderAdapter.getChildre n(ItemProviderAdapter.java:340)
>
>
>
> phantomjinx wrote:
>> Hi,
>>
>> I maybe missing something vital but it seems that my resources are
>> not being added to my transaction's resourceSet.
>>
>> When I do an initial connect with a new transaction, I supply my
>> transaction with a resourceSet.
>>
>> However, if I get an ITreeItemContentProvider adapter from my model's
>> edit package and call getChildren(), the object's children are
>> retrieved but their resources are not added to the resourceSet.
>>
>> Is this normal behaviour and I am misunderstanding how children are
>> retrieved?
>>
>> How can I get the resources to be added to the resourceSet on account
>> of the fact that a NullPointerException seems to be thrown if I do
>> resourceSet.getResources().add(resource) in getChildren, ie. try and
>> add the resources manually:
>>
>> java.lang.NullPointerException
>> at
>> org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyAdd(CDOVie wSetImpl.java:300)
>>
>> at
>> org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyChanged(CD OViewSetImpl.java:250)
>>
>> at
>> org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:247)
>>
>> at
>> org.eclipse.emf.common.notify.impl.NotifyingListImpl.dispatc hNotification(NotifyingListImpl.java:267)
>>
>> at
>> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:300)
>>
>> at
>> org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
>> at
>> isse.folder.provider.ISSEFolderItemProvider.getChildren(ISSE FolderItemProvider.java:162)
>>
>>
>> Code in getChildren() or ISSEFolderItemProvider:
>>
>> Collection <?> children = super.getChildren(object);
>> System.out.println("children size: " + children.size());
>> for (Object child : children)
>> {
>> /* The resourceSet in connection is the same as that supplied to
>> the transaction upon initialisation of the cdo session */
>> ISSEConnection connection = ((ISSEFolder) object).getFolderStore();
>> ResourceSet resourceSet = connection.getResourceStore();
>> if (child instanceof EObject && !
>> resourceSet.getResources().contains(((EObject) child).eResource()))
>> {
>> resourceSet.getResources().add(((EObject) child).eResource());
>> }
>>
>> for (Resource res : resourceSet.getResources())
>> System.out.println("Resources in resourceSet from getChildren() "
>> + res);
>> }
>>
>> return children;
>>
>>
>> Thanks
>>
>> PGR


Re: CDO resourceSet [message #423318 is a reply to message #423302] Sat, 27 September 2008 13:45 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
phantomjinx schrieb:
> Hi,
>
> I maybe missing something vital but it seems that my resources are not
> being added to my transaction's resourceSet.
>
> When I do an initial connect with a new transaction, I supply my
> transaction with a resourceSet.
>
> However, if I get an ITreeItemContentProvider adapter from my model's
> edit package and call getChildren(), the object's children are
> retrieved but their resources are not added to the resourceSet.
>
> Is this normal behaviour and I am misunderstanding how children are
> retrieved?
>
> How can I get the resources to be added to the resourceSet on account
> of the fact that a NullPointerException seems to be thrown if I do
> resourceSet.getResources().add(resource) in getChildren, ie. try and
> add the resources manually:
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyAdd(CDOVie wSetImpl.java:300)
>
> at
> org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyChanged(CD OViewSetImpl.java:250)
>
> at
> org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:247)
>
> at
> org.eclipse.emf.common.notify.impl.NotifyingListImpl.dispatc hNotification(NotifyingListImpl.java:267)
>
> at
> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:300)
>
> at
> org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
> at
> isse.folder.provider.ISSEFolderItemProvider.getChildren(ISSE FolderItemProvider.java:162)
>
>
> Code in getChildren() or ISSEFolderItemProvider:
>
> Collection <?> children = super.getChildren(object);
> System.out.println("children size: " + children.size());
> for (Object child : children)
> {
> /* The resourceSet in connection is the same as that supplied to the
> transaction upon initialisation of the cdo session */
> ISSEConnection connection = ((ISSEFolder) object).getFolderStore();
> ResourceSet resourceSet = connection.getResourceStore();
I think it's kind of strange that you're storing a ResourceSet in one of
your model object.
Or is this only an abbreviation for
connection.eResource().getResourceSet() ?

> if (child instanceof EObject && !
> resourceSet.getResources().contains(((EObject) child).eResource()))
> {
> resourceSet.getResources().add(((EObject) child).eResource());
Can you please explain what this is expected to achieve?

Cheers
/Eike

> }
>
> for (Resource res : resourceSet.getResources())
> System.out.println("Resources in resourceSet from getChildren() "
> + res);
> }
>
> return children;
>
>
> Thanks
>
> PGR


Re: CDO resourceSet [message #423326 is a reply to message #423317] Sat, 27 September 2008 15:37 Go to previous messageGo to next message
Paul Richardson is currently offline Paul RichardsonFriend
Messages: 33
Registered: July 2009
Member
Eike,

Sure, hopefully I can give you some proper context. Here goes...

I have a Folder object that contains the following references:
Connection (single Connection object)
Folders (list of references to sub-folders)

The Connection object is transient and thus loaded at run-time. Our app
demands local and remote persistence thus Connection can either be a
FileConnection (resource stored on local filesystem) or a
RemoteConnection (resources stored in CDO). At runtime, Connection
creates a resourceSet for use. This is especially important for
FileConnection but since I can pass a resourceSet when creating a
Transaction, I initialise a new resourceSet for this too. Thus,
Connection stores a transient reference to the resourceSet used by
Transaction.

The importance of the resourceSet is I wanted to be able to find
inverseCrossReferences. This is especially crucial for Folders as a
Folder stores uncontained refeferences to sub-folders, ie. A Folder is
persisted in its own resource. Thus, to find a folder's parent requires
finding an inverseCrossReference. I have mentioned this before on the
newsgroup in relation to CrossReferenceAdapters. This would be my
preferred method for doing this, ie.

resourceSet.eAdapters().add(new ECrossReferenceAdapter).

This will recursively add itself as an adapter to all resources that get
added and enables easy finding of inverseCrossReferences.

The problem is that when I came to finding an adapter on a CDOObject, it
returned null. I then found that my resourceSet only contained 1
resource and not 2 as it should. This is the scenario:

1) CDO server contains a folder, named Folder1, which in turn has a
sub-folder, named SubFolder2. Both are stored in separate resources
while Folder1 retains an uncontained reference to SubFolder2.

2) Open app and connect to Folder1. This inits a cdoSession and creates
a transaction. It calls transaction.getResource(Folder1URI.path), finds
the resource correctly and this resource is added to the resourceSet.

3) Upon display of Folder1, clicking on it asks it to display its
children. This uses the FolderItemProvider.getChildren() method to
attain its subfolders. From my investigations, getChildren() ends up in
getResource(CDOID), which correctly returns the resource containing
SubFolder2. However, the transaction's resourceSet still only contains
Folder1's resource. It seems SubFolder2's resource exists in isolation.

Any attempts to add the resource artificially to the transaction's
resourceSet have been futile due to the NullPointerException at the
bottom of my first mail. Yes, I shouldnt need to add it artificially but
then it was a workaround for part 3 of the scenario above.

Hope this explains my problem a little better.

Cheers

PGR

Eike Stepper wrote:
> Hi PGR,
>
> Apologies, I must have marked your mail as read by accident.
>
> I don't really understand what you are doing with your ResourceSet.
> Usually you should not add() CDOResources yourself.
>
> What you describe below sounds like a bug but the context,
> i.e. getResource(CDOID), is so "normal" that I can't believe it.
>
> I can't fight the feeling that it is caused somehow by a wrong usage
> of the ResourceSet or the CDOResources. Could you explain in
> more detail what you're doing?
>
> Cheers
> /Eike
>
>
>
> phantomjinx schrieb:
>> Replying to my own post but have found out more information that may
>> help.
>>
>> It would seem that the getChildren() call eventually winds up
>> requesting the resource of the referenced children using
>> CDOViewImpl.getResource(CDOID) (stacktrace at bottom of reply):
>>
>> public CDOResourceImpl getResource(CDOID resourceID)
>> {
>> if (resourceID == null || resourceID.isNull())
>> {
>> throw new IllegalArgumentException("resourceID == null ||
>> resourceID.isNull()");
>> }
>>
>> CDOResourceImpl resource = (CDOResourceImpl)getObject(resourceID);
>> if (resource != null)
>> {
>> return resource;
>> }
>>
>> <snip>
>> }
>>
>> So the transaction (CDOViewImpl) successfully returns the resource but
>> never adds it to its resourceSet. Unlike methods such as
>> createResource() which explicitly use the resourceSet. Is this an
>> oversight or is there some important reason for not adding the resource?
>>
>> If former, then I will file a bug,
>>
>> Cheers
>>
>> PGR
>>
>>
>> org.eclipse.emf.internal.cdo.CDOViewImpl.getResource(CDOView Impl.java:323)
>>
>> org.eclipse.emf.internal.cdo.CDOViewImpl.cleanObject(CDOView Impl.java:546)
>>
>> org.eclipse.emf.internal.cdo.CDOViewImpl.createObject(CDOVie wImpl.java:528)
>>
>> org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:432)
>> org.eclipse.emf.internal.cdo.CDOTransactionImpl.getObject(CD OTransactionImpl.java:270)
>>
>> org.eclipse.emf.internal.cdo.CDOViewImpl.convertIDToObject(C DOViewImpl.java:654)
>>
>> org.eclipse.emf.internal.cdo.CDOStore.get(CDOStore.java:162)
>> org.eclipse.emf.internal.cdo.CDOObjectImpl$CDOStoreEList.del egateGet(CDOObjectImpl.java:919)
>>
>> org.eclipse.emf.common.util.DelegatingEList.get(DelegatingEL ist.java:396)
>> org.eclipse.emf.common.util.DelegatingEList$EIterator.doNext (DelegatingEList.java:1075)
>>
>> org.eclipse.emf.common.util.DelegatingEList$EIterator.next(D elegatingEList.java:1062)
>>
>> org.eclipse.emf.edit.provider.ItemProviderAdapter.getChildre n(ItemProviderAdapter.java:340)
>>
>>
>>
>> phantomjinx wrote:
>>> Hi,
>>>
>>> I maybe missing something vital but it seems that my resources are
>>> not being added to my transaction's resourceSet.
>>>
>>> When I do an initial connect with a new transaction, I supply my
>>> transaction with a resourceSet.
>>>
>>> However, if I get an ITreeItemContentProvider adapter from my model's
>>> edit package and call getChildren(), the object's children are
>>> retrieved but their resources are not added to the resourceSet.
>>>
>>> Is this normal behaviour and I am misunderstanding how children are
>>> retrieved?
>>>
>>> How can I get the resources to be added to the resourceSet on account
>>> of the fact that a NullPointerException seems to be thrown if I do
>>> resourceSet.getResources().add(resource) in getChildren, ie. try and
>>> add the resources manually:
>>>
>>> java.lang.NullPointerException
>>> at
>>> org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyAdd(CDOVie wSetImpl.java:300)
>>>
>>> at
>>> org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyChanged(CD OViewSetImpl.java:250)
>>>
>>> at
>>> org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:247)
>>>
>>> at
>>> org.eclipse.emf.common.notify.impl.NotifyingListImpl.dispatc hNotification(NotifyingListImpl.java:267)
>>>
>>> at
>>> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:300)
>>>
>>> at
>>> org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
>>> at
>>> isse.folder.provider.ISSEFolderItemProvider.getChildren(ISSE FolderItemProvider.java:162)
>>>
>>>
>>> Code in getChildren() or ISSEFolderItemProvider:
>>>
>>> Collection <?> children = super.getChildren(object);
>>> System.out.println("children size: " + children.size());
>>> for (Object child : children)
>>> {
>>> /* The resourceSet in connection is the same as that supplied to
>>> the transaction upon initialisation of the cdo session */
>>> ISSEConnection connection = ((ISSEFolder) object).getFolderStore();
>>> ResourceSet resourceSet = connection.getResourceStore();
>>> if (child instanceof EObject && !
>>> resourceSet.getResources().contains(((EObject) child).eResource()))
>>> {
>>> resourceSet.getResources().add(((EObject) child).eResource());
>>> }
>>>
>>> for (Resource res : resourceSet.getResources())
>>> System.out.println("Resources in resourceSet from getChildren() "
>>> + res);
>>> }
>>>
>>> return children;
>>>
>>>
>>> Thanks
>>>
>>> PGR
Re: CDO resourceSet - submitted bug #248915 [message #423341 is a reply to message #423326] Mon, 29 September 2008 10:12 Go to previous messageGo to next message
Paul Richardson is currently offline Paul RichardsonFriend
Messages: 33
Registered: July 2009
Member
phantomjinx wrote:
> Eike,
>
> Sure, hopefully I can give you some proper context. Here goes...
>
> I have a Folder object that contains the following references:
> Connection (single Connection object)
> Folders (list of references to sub-folders)
>
> The Connection object is transient and thus loaded at run-time. Our app
> demands local and remote persistence thus Connection can either be a
> FileConnection (resource stored on local filesystem) or a
> RemoteConnection (resources stored in CDO). At runtime, Connection
> creates a resourceSet for use. This is especially important for
> FileConnection but since I can pass a resourceSet when creating a
> Transaction, I initialise a new resourceSet for this too. Thus,
> Connection stores a transient reference to the resourceSet used by
> Transaction.
>
> The importance of the resourceSet is I wanted to be able to find
> inverseCrossReferences. This is especially crucial for Folders as a
> Folder stores uncontained refeferences to sub-folders, ie. A Folder is
> persisted in its own resource. Thus, to find a folder's parent requires
> finding an inverseCrossReference. I have mentioned this before on the
> newsgroup in relation to CrossReferenceAdapters. This would be my
> preferred method for doing this, ie.
>
> resourceSet.eAdapters().add(new ECrossReferenceAdapter).
>
> This will recursively add itself as an adapter to all resources that get
> added and enables easy finding of inverseCrossReferences.
>
> The problem is that when I came to finding an adapter on a CDOObject, it
> returned null. I then found that my resourceSet only contained 1
> resource and not 2 as it should. This is the scenario:
>
> 1) CDO server contains a folder, named Folder1, which in turn has a
> sub-folder, named SubFolder2. Both are stored in separate resources
> while Folder1 retains an uncontained reference to SubFolder2.
>
> 2) Open app and connect to Folder1. This inits a cdoSession and creates
> a transaction. It calls transaction.getResource(Folder1URI.path), finds
> the resource correctly and this resource is added to the resourceSet.
>
> 3) Upon display of Folder1, clicking on it asks it to display its
> children. This uses the FolderItemProvider.getChildren() method to
> attain its subfolders. From my investigations, getChildren() ends up in
> getResource(CDOID), which correctly returns the resource containing
> SubFolder2. However, the transaction's resourceSet still only contains
> Folder1's resource. It seems SubFolder2's resource exists in isolation.
>
> Any attempts to add the resource artificially to the transaction's
> resourceSet have been futile due to the NullPointerException at the
> bottom of my first mail. Yes, I shouldnt need to add it artificially but
> then it was a workaround for part 3 of the scenario above.
>
> Hope this explains my problem a little better.
>
> Cheers
>
> PGR
>
> Eike Stepper wrote:
>> Hi PGR,
>>
>> Apologies, I must have marked your mail as read by accident.
>>
>> I don't really understand what you are doing with your ResourceSet.
>> Usually you should not add() CDOResources yourself.
>>
>> What you describe below sounds like a bug but the context,
>> i.e. getResource(CDOID), is so "normal" that I can't believe it.
>>
>> I can't fight the feeling that it is caused somehow by a wrong usage
>> of the ResourceSet or the CDOResources. Could you explain in
>> more detail what you're doing?
>>
>> Cheers
>> /Eike
>>
>>
>>
>> phantomjinx schrieb:
>>> Replying to my own post but have found out more information that may
>>> help.
>>>
>>> It would seem that the getChildren() call eventually winds up
>>> requesting the resource of the referenced children using
>>> CDOViewImpl.getResource(CDOID) (stacktrace at bottom of reply):
>>>
>>> public CDOResourceImpl getResource(CDOID resourceID)
>>> {
>>> if (resourceID == null || resourceID.isNull())
>>> {
>>> throw new IllegalArgumentException("resourceID == null ||
>>> resourceID.isNull()");
>>> }
>>>
>>> CDOResourceImpl resource = (CDOResourceImpl)getObject(resourceID);
>>> if (resource != null)
>>> {
>>> return resource;
>>> }
>>>
>>> <snip>
>>> }
>>>
>>> So the transaction (CDOViewImpl) successfully returns the resource
>>> but never adds it to its resourceSet. Unlike methods such as
>>> createResource() which explicitly use the resourceSet. Is this an
>>> oversight or is there some important reason for not adding the resource?
>>>
>>> If former, then I will file a bug,
>>>
>>> Cheers
>>>
>>> PGR
>>>
>>>
>>> org.eclipse.emf.internal.cdo.CDOViewImpl.getResource(CDOView Impl.java:323)
>>>
>>> org.eclipse.emf.internal.cdo.CDOViewImpl.cleanObject(CDOView Impl.java:546)
>>>
>>> org.eclipse.emf.internal.cdo.CDOViewImpl.createObject(CDOVie wImpl.java:528)
>>>
>>> org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:432)
>>> org.eclipse.emf.internal.cdo.CDOTransactionImpl.getObject(CD OTransactionImpl.java:270)
>>>
>>> org.eclipse.emf.internal.cdo.CDOViewImpl.convertIDToObject(C DOViewImpl.java:654)
>>>
>>> org.eclipse.emf.internal.cdo.CDOStore.get(CDOStore.java:162)
>>> org.eclipse.emf.internal.cdo.CDOObjectImpl$CDOStoreEList.del egateGet(CDOObjectImpl.java:919)
>>>
>>> org.eclipse.emf.common.util.DelegatingEList.get(DelegatingEL ist.java:396)
>>>
>>> org.eclipse.emf.common.util.DelegatingEList$EIterator.doNext (DelegatingEList.java:1075)
>>>
>>> org.eclipse.emf.common.util.DelegatingEList$EIterator.next(D elegatingEList.java:1062)
>>>
>>> org.eclipse.emf.edit.provider.ItemProviderAdapter.getChildre n(ItemProviderAdapter.java:340)
>>>
>>>
>>>
>>> phantomjinx wrote:
>>>> Hi,
>>>>
>>>> I maybe missing something vital but it seems that my resources are
>>>> not being added to my transaction's resourceSet.
>>>>
>>>> When I do an initial connect with a new transaction, I supply my
>>>> transaction with a resourceSet.
>>>>
>>>> However, if I get an ITreeItemContentProvider adapter from my
>>>> model's edit package and call getChildren(), the object's children
>>>> are retrieved but their resources are not added to the resourceSet.
>>>>
>>>> Is this normal behaviour and I am misunderstanding how children are
>>>> retrieved?
>>>>
>>>> How can I get the resources to be added to the resourceSet on
>>>> account of the fact that a NullPointerException seems to be thrown
>>>> if I do
>>>> resourceSet.getResources().add(resource) in getChildren, ie. try and
>>>> add the resources manually:
>>>>
>>>> java.lang.NullPointerException
>>>> at
>>>> org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyAdd(CDOVie wSetImpl.java:300)
>>>>
>>>> at
>>>> org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyChanged(CD OViewSetImpl.java:250)
>>>>
>>>> at
>>>> org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:247)
>>>>
>>>> at
>>>> org.eclipse.emf.common.notify.impl.NotifyingListImpl.dispatc hNotification(NotifyingListImpl.java:267)
>>>>
>>>> at
>>>> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:300)
>>>>
>>>> at
>>>> org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
>>>> at
>>>> isse.folder.provider.ISSEFolderItemProvider.getChildren(ISSE FolderItemProvider.java:162)
>>>>
>>>>
>>>> Code in getChildren() or ISSEFolderItemProvider:
>>>>
>>>> Collection <?> children = super.getChildren(object);
>>>> System.out.println("children size: " + children.size());
>>>> for (Object child : children)
>>>> {
>>>> /* The resourceSet in connection is the same as that supplied to
>>>> the transaction upon initialisation of the cdo session */
>>>> ISSEConnection connection = ((ISSEFolder) object).getFolderStore();
>>>> ResourceSet resourceSet = connection.getResourceStore();
>>>> if (child instanceof EObject && !
>>>> resourceSet.getResources().contains(((EObject) child).eResource()))
>>>> {
>>>> resourceSet.getResources().add(((EObject) child).eResource());
>>>> }
>>>>
>>>> for (Resource res : resourceSet.getResources())
>>>> System.out.println("Resources in resourceSet from getChildren()
>>>> " + res);
>>>> }
>>>>
>>>> return children;
>>>>
>>>>
>>>> Thanks
>>>>
>>>> PGR
Re: CDO resourceSet [message #423356 is a reply to message #423317] Mon, 29 September 2008 12:56 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Eike Stepper schrieb:
> Hi PGR,
>
> Apologies, I must have marked your mail as read by accident.
>
> I don't really understand what you are doing with your ResourceSet.
> Usually you should not add() CDOResources yourself.
>
> What you describe below sounds like a bug but the context,
> i.e. getResource(CDOID), is so "normal" that I can't believe it.
Sorry, Paul, I am so unexperienced in seeing usage of our internal code
that I indeed overlooked your mention of getResource(CDOID).
It's clearly an internal method of CDOViewImpl and not supposed to be
called by clients.
There's a switch in your IDE configuration to produce builder warnings
or errors for usage of restricted code. That might be helpful.
And we have always strictly followed the convention that "internal" in
the package name means "no, no, don't use me directly" ;-)

Cheers
/Eike


>
> I can't fight the feeling that it is caused somehow by a wrong usage
> of the ResourceSet or the CDOResources. Could you explain in
> more detail what you're doing?
>
> Cheers
> /Eike
>
>
>
> phantomjinx schrieb:
>> Replying to my own post but have found out more information that may
>> help.
>>
>> It would seem that the getChildren() call eventually winds up
>> requesting the resource of the referenced children using
>> CDOViewImpl.getResource(CDOID) (stacktrace at bottom of reply):
>>
>> public CDOResourceImpl getResource(CDOID resourceID)
>> {
>> if (resourceID == null || resourceID.isNull())
>> {
>> throw new IllegalArgumentException("resourceID == null ||
>> resourceID.isNull()");
>> }
>>
>> CDOResourceImpl resource = (CDOResourceImpl)getObject(resourceID);
>> if (resource != null)
>> {
>> return resource;
>> }
>>
>> <snip>
>> }
>>
>> So the transaction (CDOViewImpl) successfully returns the resource
>> but never adds it to its resourceSet. Unlike methods such as
>> createResource() which explicitly use the resourceSet. Is this an
>> oversight or is there some important reason for not adding the resource?
>>
>> If former, then I will file a bug,
>>
>> Cheers
>>
>> PGR
>>
>>
>> org.eclipse.emf.internal.cdo.CDOViewImpl.getResource(CDOView Impl.java:323)
>>
>> org.eclipse.emf.internal.cdo.CDOViewImpl.cleanObject(CDOView Impl.java:546)
>>
>> org.eclipse.emf.internal.cdo.CDOViewImpl.createObject(CDOVie wImpl.java:528)
>>
>> org.eclipse.emf.internal.cdo.CDOViewImpl.getObject(CDOViewIm pl.java:432)
>> org.eclipse.emf.internal.cdo.CDOTransactionImpl.getObject(CD OTransactionImpl.java:270)
>>
>> org.eclipse.emf.internal.cdo.CDOViewImpl.convertIDToObject(C DOViewImpl.java:654)
>>
>> org.eclipse.emf.internal.cdo.CDOStore.get(CDOStore.java:162)
>> org.eclipse.emf.internal.cdo.CDOObjectImpl$CDOStoreEList.del egateGet(CDOObjectImpl.java:919)
>>
>> org.eclipse.emf.common.util.DelegatingEList.get(DelegatingEL ist.java:396)
>>
>> org.eclipse.emf.common.util.DelegatingEList$EIterator.doNext (DelegatingEList.java:1075)
>>
>> org.eclipse.emf.common.util.DelegatingEList$EIterator.next(D elegatingEList.java:1062)
>>
>> org.eclipse.emf.edit.provider.ItemProviderAdapter.getChildre n(ItemProviderAdapter.java:340)
>>
>>
>>
>> phantomjinx wrote:
>>> Hi,
>>>
>>> I maybe missing something vital but it seems that my resources are
>>> not being added to my transaction's resourceSet.
>>>
>>> When I do an initial connect with a new transaction, I supply my
>>> transaction with a resourceSet.
>>>
>>> However, if I get an ITreeItemContentProvider adapter from my
>>> model's edit package and call getChildren(), the object's children
>>> are retrieved but their resources are not added to the resourceSet.
>>>
>>> Is this normal behaviour and I am misunderstanding how children are
>>> retrieved?
>>>
>>> How can I get the resources to be added to the resourceSet on
>>> account of the fact that a NullPointerException seems to be thrown
>>> if I do
>>> resourceSet.getResources().add(resource) in getChildren, ie. try and
>>> add the resources manually:
>>>
>>> java.lang.NullPointerException
>>> at
>>> org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyAdd(CDOVie wSetImpl.java:300)
>>>
>>> at
>>> org.eclipse.emf.internal.cdo.CDOViewSetImpl.notifyChanged(CD OViewSetImpl.java:250)
>>>
>>> at
>>> org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:247)
>>>
>>> at
>>> org.eclipse.emf.common.notify.impl.NotifyingListImpl.dispatc hNotification(NotifyingListImpl.java:267)
>>>
>>> at
>>> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:300)
>>>
>>> at
>>> org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
>>> at
>>> isse.folder.provider.ISSEFolderItemProvider.getChildren(ISSE FolderItemProvider.java:162)
>>>
>>>
>>> Code in getChildren() or ISSEFolderItemProvider:
>>>
>>> Collection <?> children = super.getChildren(object);
>>> System.out.println("children size: " + children.size());
>>> for (Object child : children)
>>> {
>>> /* The resourceSet in connection is the same as that supplied to
>>> the transaction upon initialisation of the cdo session */
>>> ISSEConnection connection = ((ISSEFolder) object).getFolderStore();
>>> ResourceSet resourceSet = connection.getResourceStore();
>>> if (child instanceof EObject && !
>>> resourceSet.getResources().contains(((EObject) child).eResource()))
>>> {
>>> resourceSet.getResources().add(((EObject) child).eResource());
>>> }
>>>
>>> for (Resource res : resourceSet.getResources())
>>> System.out.println("Resources in resourceSet from getChildren()
>>> " + res);
>>> }
>>>
>>> return children;
>>>
>>>
>>> Thanks
>>>
>>> PGR


Previous Topic:How to extract the corresponding XML for an EObject.
Next Topic:[CDO] Version handling
Goto Forum:
  


Current Time: Thu Apr 25 00:09:45 GMT 2024

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

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

Back to the top