String.asOid - Object.getOidString - really very usefull

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

String.asOid - Object.getOidString - really very usefull

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:16 pm

by Paul Mathews >> Wed, 7 Jul 1999 14:14:50 GMT

1) We have found the asOid method really usefull those fixups of data requred after you have gon einto the inspector and found what is
wrong, eg

fixTest() updating;

// Date: 03 February 1999
// User: paulm
begin

beginTransaction; // '2526.4'.asOid.CMJobTemplate.cmCustomiseArray.rebuild;
// or
// delete '2512.1'.asOid;
commitTransaction;
end;

2) Another great use is it enables an exclusive collection to be store
as a string property to be used later.

Paul Mathews
pem@cmsystemsgroup.com.au
Phone: [612] (99717384) Fax[612] (99711679)
(Dee Why,Sydney,Australia)

Please visit our homepage cmsystemsgroup.com.au.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: String.asOid - Object.getOidString - really very usefull

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:16 pm

by Dean Cooper >> Thu, 8 Jul 1999 9:35:19 GMT
2) Another great use is it enables an exclusive collection to be store as a string property to be used later.

Be wary about doing this. Fundamental to the semantics of exclusive collections is that they have only one parent or owner (that is, only one object can reference them). That is why, for example, the compiler doesn't let you assign an exclusive collection reference to another property; but you can assign it to a local variable or a parameter. By storing the exclusive oid in a string and constructing a reference using asOid, you are breaking the exclusivity of the collection; effectively treating it as a shared reference. You can certainly create situations where automatic inverse maintenance won't be performed, and could easily end up with invalid references (through either unmaintained inverses, or because of the fact that the lifetime of the exclusive collection is determined by the lifetime of its parent). Also you can defeat the compiler's checks to warn you about accidentally attempting to update automatic collections.

asOid is a very useful method when testing or debugging; or in peripheral, utility code. But I would be suspicious about it use in main-line, production code. If you need a collection to be shared, then make it shared. If you need to access an exclusive collection from methods on another object, then have the object hold a reference to the parent, and ask the parent for the collection. Both of these approaches are safer.

Dean.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: String.asOid - Object.getOidString - really very usefull

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:16 pm

by Paul Mathews >> Thu, 8 Jul 1999 10:00:21 GMT

Deans advise is correct we are purely using this approach transiently.

1) Data fixups.

2) Some Classes can have many collections on them, so there may be a screen to select which collection to use, this enables that to passed back effectlively, for a maintenance procedure to then use, and / or report on.

It can simplify code quite a lot because you cannot pass exclusive collections as parrameters, they can only be returned.

eg RootObject.allOrders, RootObject.allOrdersActive,
Customer.allOrders, Customer.allOrdersActive.

instanceCollection():Collection;
begin

if zObject.isKindOf(RootObject) then
if zActive then
return zObject.RootObject.allOrdersActive;
else
return zObject.RootObject.allOrders;
endif;
elseif zObject.isKindOf(Customer) then
if zActive then
return zObject.RootObject.allOrdersActive;
else
return zObject.RootObject.allOrders;
endif;
endif;
end;

OR

instanceCollection():Collection;
begin

return zOid.asOid.Collection;
end;

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: String.asOid - Object.getOidString - really very usefull

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:16 pm

by Craig Shearer >> Fri, 9 Jul 1999 0:32:55 GMT
Deans advise is correct we are purely using this approach transiently.

1) Data fixups.

2) Some Classes can have many collections on them, so there may be a screen to select which collection to use, this enables that to passed back effectlively, for a maintenance procedure to then use, and / or report on.

It can simplify code quite a lot because you cannot pass exclusive collections as parrameters, they can only be returned.


Yes you can!!! It is quite possible to pass an exclusive collection as a parameter to a method - you just can't store the reference on another object inside the method (since the reference is exclusive, it doesn't make sense to store it on another object!)

eg RootObject.allOrders, RootObject.allOrdersActive,
Customer.allOrders, Customer.allOrdersActive.

instanceCollection():Collection;

begin
if zObject.isKindOf(RootObject) then
if zActive then
return zObject.RootObject.allOrdersActive;
else
return zObject.RootObject.allOrders;
endif;
elseif zObject.isKindOf(Customer) then
if zActive then
return zObject.RootObject.allOrdersActive;
else
return zObject.RootObject.allOrders;
endif;
endif;
end;

OR

instanceCollection():Collection;

begin
return zOid.asOid.Collection;
end;



I'm having trouble fathoming the purpose of the above code - care to explain it further Paul? On what class is the instanceCollection method? What is zObject and zActive?

Craig.


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 1 guest