Starting Tiger objectbase
Tiger can be used either in a distributed multiuser environment or in the local JVM.
This section describes how to use it locally.
To start Tiger in the local JVM you could just make an instance of LocalObjectBase.
The constructor must have a filename to the descriptor file for the objectbase, as an argument.
Then the Tiger objectbase is ready for local use. The LocalObjectBase class implements the
ObjectBase interface which is the interface of the tiger objectbase.
Descriptor file
The descriptor file is a file that contains following elements.
- path. File directory there Tiger will put the files for this objectbase.
- metadata. Filename of the metadata file for the objectbase. The metadata file contains information about the persistent objects and relations in the objectbase.
Persistent objects - basics
To make an object persistent in Tiger the object should subclass PersistObject and there
must be a persist-class element in the metadata xml-file. The persist-class element must have
following attributes.
- name. Name of the persistent class.
- java-class. Full class name of the persistent class.
- id-class. Full class name of the class that are used as an identification of the persistent class. The id-class must be a comparable.
Creating objects
To create a new instance of a persistent object you have to call the createObject method
on the ObjectBase object. The createObject method will return an instance of the persistent
class. You should supply an ID object as argument. The ID is a class that wrapps the actual
id object (an instance of the class specified by the id-class attribute in the metadata file).
To create an ID object you just calls the constructor and supplied name of the persistent class
(specified in the metadata file) and the actual id object.
The persitent object will be saved in the objectbase when createObject is called, but it
will be empty.
Finding objects
To find a persistent object you have to create an ID object (se above) and call the method
findObject on the ObjectBase object.
Manipulating objects
To manipulate a persistent object you just have to call the save method and the object will
be saved in the objectbase.
There are also a deleteObject method in the ObjectBase that will delete the object with a given id.
Relations
Tiger objectbase uses the concepts of relations. Relations can be defined in the metadata
file. There are currently two types of relations, one-to-many relations and many-to-many
relations.
One-to-many relations
To define a one-to-many relation you have to create a one-to-many-relation element in the metadata
file. This element have the following attributes.
- name. The name of the relation. This attribute is not mandatory. If the name is not supplied
the name will be constructed from the other attributes.
- one-class. The name of the class on the one-side of the relation.
- many-class. The name of the class on the many-side of the relation.
- prefix. Prefix which is used to construct a relation name.
- suffix. Suffix which is used to construct a relation name.
- name-for-one. Name of the relation from the one-side.
- name-for-many. Name of the relation from the many-side.
As said above you can supply a name for the relation. But usually it is unnecessary.
The name of the relation will be one-class_many-class. If there are serval different
relations between the same classes, you can supply a prefix or/and suffix which are used
to construct a relation name. An other way of giving name to a relation is to supply a
name that are used from the one-side and a name that are used from the many-side.
When you should related objects to each other in a relation you call bind methods.
You call the bind method on one of the two participating objects and supply the relation
name and the other object.
To find the one-object from a many-object you can use the getRelatedObject method on
the many-object. You have to supply a relation name as argument. To find the
many-objects from a one-object you call the getRelatedObjects method on the one-object.
Many-to-many relations
To define a many-to-many relation you have to create a many-to-many-relation element
in the metadata file. This element have the following attributes.
- name. The name of the relation. This attribute is not mandatory. If the name is not supplied
the name will be constructed from the other attributes.
- a-class. The name of the first class.
- b-class. The name of the second class.
- prefix. Prefix which is used to construct a relation name.
- suffix. Suffix which is used to construct a relation name.
- name-for-a. Name of the relation from the a-side.
- name-for-b. Name of the relation from the b-side.
The concept of creating relation names is the same as for one-to-many relations.
The way to relate objects to each other is exactly the same as for one-to-many relations.
Finding related objects is also the same as for one-to-many relations. Except of that you
use the getRelatedObjects method in both directions.