Page 1 of 1
comparing types
Posted: Mon May 12, 2014 5:10 am
by ghosttie
At some point someone mentioned that comparing types was risky - I think this was because of subschema copies.
Since then I've always compared Type.name or Type.number instead of Type - is this a good idea or am I wasting my time? What's the best practice?
Re: comparing types
Posted: Mon May 12, 2014 9:09 am
by allistar
Comparing types by name is the best approach as it removes the subschema copy problem. The other thing worth mentioning is to not store references to type objects (e.g. Classes) on other persistent object. The reason is that when a class is reorged the object for the class changes, and so your pointer to that class either points to an invalid object, or it points to a different class. It's fine to do this for transient objects though because by definition they cannot exist across a reorg.
If you use class name it makes sense to also store the schema name. We tend to use class number as that is stable, and it's unique globally in a database. Unfortunately JADE's implementation of Schema::getClassByNumber is very slow if you have a large number of classes, so we have a transient cache of class number to class maps. (On our system each call to Schema::getClassByNumber in multiuser is about 18ms, which is an eternity. From what I understand it recurses the schemas to find the class).
Re: comparing types
Posted: Mon May 12, 2014 9:58 am
by BeeJay
At some point someone mentioned that comparing types was risky - I think this was because of subschema copies.
Since then I've always compared Type.name or Type.number instead of Type - is this a good idea or am I wasting my time? What's the best practice?
Allistar has already provided an answer, which may or may not answer your intended question. If it didn't answer your question, a little more detail such as a use-case would be useful to better understand your question.
Cheers,
BeeJay.
Re: comparing types
Posted: Tue May 13, 2014 1:16 am
by ghosttie
Allistar answered my question, thanks.
Re: comparing types
Posted: Tue May 13, 2014 8:04 am
by BeeJay
No worries.