Global

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

Global

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

by Wilfred Verkley >> Mon, 8 Jan 2001 22:53:05 GMT

What are the cons/pro of storing data on this class?

Most applications ive seen have defined a seperate "Root" class for which they have a pointer to on Application which they initialise using "Root.firstInstance", thus avoiding Global like the plague.

Having a Root class is a good aproach as it leaves open an easy way of running multiple systems within the same database later (by having different Root instances), but why not just store a reference to this from Global ????

Wilfred (hot, sunny, but confusing day in Auckland).

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

Re: Global

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

by JADE Kid - Ray Hidayat >> Tue, 9 Jan 2001 0:45:42 GMT

Often when I'm programming I have a reference to my root object, and my main objects, like the current user in the app object.

I guess storing a reference to the root object from the global class is an idea.

Using the global class as the root object seems fine to me. It actually sounds like a good idea. But I think it is more useful to define a class for your root, because it has a name. It makes your code easier to read. Global means nothing, but Root means it is the root class.

--
Ray Hidayat
JADE Kid - 2000
www.jadekids.com

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

Re: Global

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

by Peter Gallagher >> Tue, 9 Jan 2001 0:57:18 GMT

We tried putting a persistent reference to a root object on global about 20 months ago. Like you guys we thought it was a good place to store some common stuff. Trust me when I say it will cause you grief. It makes updating schemas very difficult. You might re-install Jade, and the class number for the global class changes, then that live site that you want to upgrade won't accept your schema. I can't recall the particular errors we got, enough though to know that global is a great place to store methods, just don't put any attributes/references on it.

Peter (Hot and windy here in Chch)

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

Re: Global

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

by Craig Shearer >> Tue, 9 Jan 2001 1:49:26 GMT

Hi Peter

I had the same reaction to you with using global to store stuff on - particularly references.

The problem is/was that the global object is extracted with the schema definition and reloaded when you reload a schema - I used to have a reference to an object stored on global, and of course, when I reloaded the schema that resulted in an Object Not Found exception as the object could no longer exist.

I've not done this lately however, and I think that this sort of thing might have been fixed in 5.0 and above (I seem to recall reading something about it).

Perhaps someone has some time to give this a go and see whether it works these days, or perhaps someone from the plant can comment???

Craig. (In Auckland, glad to be straightening out SOME of Wilfred's ideas)

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

Re: Global

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

by Robert Barr >> Sun, 14 Jan 2001 22:52:01 GMT

I've used Global successfully as I suspect it was originally intended
(as a singleton persistent object, with validity and availability guaranteed, c.f. app as a transient singleton).

I find 'global' just as meaningful as 'root', so I don't agree naming is a problem.

I suspect the common avoidance of using Global class is a legacy from
(a) JADE 3 where references on Global just didn't work at all, and (b) that bizarre 'feature' in JADE 4 that Craig and Peter refer to where instance information was extracted to, and reloaded from the ddb file.

So does creating your own Root singleton offer a benefit, or merely the hastle of writing instantiation code?

(Of course, locks on your singeton root object in a multiuser
environment (e.g. by accessing a property) can deny access to other
nodes or threads).

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

Re: Global

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

by Carl Ranson >> Mon, 15 Jan 2001 0:06:18 GMT
So does creating your own Root singleton offer a benefit, or merely the hastle of writing instantiation code?

Yes, because its not necessarilry a singleton as far as the database is concerned. What I mean is that it *is* a singleton for any particular run of an application, but may not be a singleton in the database.

Consider, for instance, if you wanted to have a "test" and "production" dataset in the same system.

Cheers,
CR

(back at work and loving every minute of it....)

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

Re: Global

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

by Richard Mitchell >> Mon, 15 Jan 2001 1:21:45 GMT

Carl makes a good point. If you have more than one schema in the database, then there will be a different global object for each schema. So you can't assume that the reserved word 'global' will return the same object in schema1 vs. schema2.
--
Richard Mitchell
JADE Systems Group
JADE Direct __________________________________________________


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 29 guests

cron