by
cnwdad1 >> Tue, 20 Jan 2004 4:02:22 GMT
Try taking a look at some of the Online Tutorials to help get you going:
http://www.jadeworld.com/Jade6/jade6_tutorials.htm
Basically, what you need is some root object. Create a class called "Root". On your Person class, add a reference to the Root class (say, "myRoot"). Create a MemberKeyDictionary subclass, say "PersonByLastNameDict", and give it a membership of Person, and add two keys, say "sLastname" and "sFirstname". On the Root class, add a reference to the PersonByLastNameDict (call it say "allPersons"), click the "Define Inverse" button, and select the "myRoot" reference of the Person class - you will probably have to do a reorg after this step. On your schema's Application subclass, create a reference to the Root class, say "myRoot".
On your schema's Application subclass, add a method called "initialize", and code something like:
initialize() updating;
vars
rootObj : Root;begin
rootObj := Root.firstInstance();
if rootObj = null then
beginTransaction;
create rootObj;
commitTransaction;
endif;
app.myRoot := rootObj;
end;
Because you've already created your instances of Person, you'll need to fix up your data, something like:
TestScript_FixPersons();
vars
rootObj : Root;
personObj : Person;begin
rootObj := Root.firstInstance();
if rootObj = null then
beginTransaction;
create rootObj;
commitTransaction;
endif;
beginTransaction;
foreach personObj in Person.instances do
personObj.myRoot := rootObj;
endforeach;
commitTransaction;
end;
Whenever your application starts, by default it will run "app.initialize". You can use a different name, but if you do, you'll need to specify it for your Application (refer to the Application Browser window, select the application, right-click, and select "Change"). Now, anywhere in your code, you can access the Person objects by referencing the singleton Root object, and iterating the collection of persons (i.e. allPersons). If you're just using a JadeScript, you can do something similar to the above initialize method to get a root object, for example:
TestScript_ListPersons();
vars
rootObj : Root;
personObj : Person;begin
rootObj := Root.firstInstance();
if rootObj = null then
beginTransaction;
create rootObj;
commitTransaction;
endif;
foreach personObj in rootObj.allPersons do
write personObj.sLastname & ", " & personObj.sFirstname;
endforeach;
end;
Finally, you should change your "addPeople" JadeScript to fetch a reference a reference to the singleton Root instance, something like above, and always set the "Person::myRoot" reference whenever you create an instance of Person, such as in the "TestScript_FixPersons" JadeScript example above.
Hope that helps a bit, but you really should at least give the Online Tutorials a go, or you could download them to run locally on your machine.
regards,
darrell.