comparing types

For questions and postings not covered by the other forums
User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

comparing types

Postby ghosttie » Mon May 12, 2014 5:10 am

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?
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

allistar
Posts: 156
Joined: Fri Aug 14, 2009 11:02 am
Location: Mount Maunganui, Tauranga

Re: comparing types

Postby allistar » Mon May 12, 2014 9:09 am

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).

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: comparing types

Postby BeeJay » Mon May 12, 2014 9:58 am

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.

User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

Re: comparing types

Postby ghosttie » Tue May 13, 2014 1:16 am

Allistar answered my question, thanks.
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: comparing types

Postby BeeJay » Tue May 13, 2014 8:04 am

No worries.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 22 guests

cron