Page 1 of 1
Help on collection rebuild
Posted: Fri Aug 07, 2009 12:33 pm
by ConvertFromOldNGs
by Marcelle Goslin >> Mon, 23 Feb 2004 4:49:40 GMT
Hi
I need to rebuild an automatic/manual collection that is returning error 4 (Object not found) errors while being traversed.
I have vague memories of a rebuild() method on a collection, and a white paper describing all the problems one can encounter with collections and how to fix them.
I've trawled jadeworld, as well as online help and can't find any documentation.
Can anyone oblige...
TIA
Re: Help on collection rebuild
Posted: Fri Aug 07, 2009 12:33 pm
by ConvertFromOldNGs
by Brendan Doolan >> Mon, 23 Feb 2004 10:01:36 GMT
Marcelle,
I am assuming your collection is man/auto so that you can add, clear etc on the collection? If so, then you should be able to fix up the problem using a workspace along the following lines
vars
saveColl : ObjectArray;
suspectColl : Collection;
obj : Any;
begin
create saveColl transient;
suspectColl := <grab a reference to your dodgy collection>;
foreach obj in suspectColl do
if global.isValidObject(obj.Object) then
saveColl.add(obj.Object);
endif;
endforeach;
beginTransaction;
suspectColl.clear;
foreach obj in saveColl do
suspectColl.add(obj);
endforeach;
commitTransaction;
I am assuming the the population is not huge so that the fixup can be done in one transaction. If this is not true you may need to save saveColl persistently in case there is an exception when running the workspace.
A more interesting question is how did it happen, has it happened more than once etc.?
Is this a consequence of having a man/auto inverse rather than a purely manual or purely auotmatic one? If so, maybe you ought to consider making it purely automatic?
Brendan
Re: Help on collection rebuild
Posted: Fri Aug 07, 2009 12:33 pm
by ConvertFromOldNGs
by Marcelle >> Thu, 11 Mar 2004 2:25:16 GMT
Brendan
Thanks for your reply, and apologies for not responding sooner.
To answer your questions:
1) There 2 invalid objects in the collection
2) The references are defined as
- Obj1.allObj2s
Automatic, Peer-to-peer
- Obj2.myObj1
Manual, Peer-to-peer, Transient to persistent reference allowed
How would changing the Obj2.myObj1 to Automatic help the problem?
I'm making an assumption that the rogue Obj2s are transients, as we never delete persistent Obj2s. We also don't allow deletes of Obj1 unless Obj1.allObj2s is empty. If any Obj2 gets deleted, surely the Obj1.allObj2s collection should get updated (automatically) to reflect this?
Thanks
Marcelle
Re: Help on collection rebuild
Posted: Fri Aug 07, 2009 12:33 pm
by ConvertFromOldNGs
by Dr J. >> Tue, 24 Feb 2004 3:52:35 GMT
You perhaps want to use the JADE Logical Certify utility?
Refer to the online help for more details on using this utility.
Re: Help on collection rebuild
Posted: Fri Aug 07, 2009 12:33 pm
by ConvertFromOldNGs
by AVL >> Tue, 2 Mar 2004 3:32:33 GMT
I have used the rebuild() method successfully in the past.
However, I believe regular use was not recommended (I haven't checked whether it is still supported in Jade 6).
If the collection you want rebuilt is persistent then you will need to be in transaction state.
Syntax is real simple:
beginTransaction;
myCollection.rebuild();
commitTransaction;
Re: Help on collection rebuild
Posted: Fri Aug 07, 2009 12:33 pm
by ConvertFromOldNGs
by Marcelle >> Thu, 11 Mar 2004 2:17:58 GMT
Thanks to all. The problem has been sorted through your collective efforts. Marcelle