Class COM.odi.ClassInfo
java.lang.Object
|
+----COM.odi.ClassInfo
- public class ClassInfo
- extends Object
ClassInfo is an abstract class that ObjectStore uses
to manage the schema information for persistence-capable classes.
Normally, the Class File Postprocessor
defines the ClassInfo
subclass, creates an instance, and inserts calls to ClassInfo
methods where required. You run the postprocessor
after you compile your source files. However, under exceptional
circumstances, you might want to implement this yourself.
Unless you implement ClassInfo yourself, you
do not need to be familiar with this class.
For each class that inherits from the ObjectStore
Persistent class, or OSHashPersistent class there must
be a subclass of the ClassInfo class.
Subclasses of the ClassInfo class provide information about
the associated persistence-capable class. ObjectStore
needs this schema information to manage the object.
If you do implement ClassInfo yourself,
here is an example that shows the definition of a persistence-capable
class followed by the definition of a ClassInfo subclass for
the newly-defined persistence-capable class:
package COM.odi.demo.people;
class Person extends Persistent {
String name;
int age;
Person children[];
public Person(String name, int age, Person children[])
{ this.name = name; this.age = age; this.children = children }
...
}
public class PersonClassInfo extends ClassInfo {
public Persistent create() { return new Person(null, 0, null); }
public Class getClassDescriptor() {
return Person.class;
}
public Field[] getFields() { return fields; }
private static Field[] fields = {
Field.createString("name");
Field.createInt("age");
Field.createClassArray("children", "COM.odi.demo.people.Person", 1);
}
}
See the API User Guide, for additional information about
Defining a ClassInfo Subclass.
- See Also:
- Persistent, Field
-
create()
- Creates a default instance of the persistence-capable class
associated with this instance of ClassInfo.
-
get(String)
- Obtains the class-specific information for the specified
Persistent subclass.
-
getClassDescriptor()
- Obtains the class object for the persistence-capable class with
which this instance of ClassInfo is associated.
-
getFields()
- Gets the array of fields for the persistence-capable class associated
with this instance of ClassInfo.
-
notePersistentField(String)
- Notes a field as needing to be part of the schema for the class despite
its transient declaration.
-
noteTransientField(String)
- Notes a field as needing to be excluded from the schema for the class
even though the field has not been declared transient.
-
register(ClassInfo)
- Registers a class as persistence-capable with ObjectStore
by providing an
instance of its associated ClassInfo subclass.
-
remove(String)
- Removes a persistence-capable class from the registry.
create
public abstract IPersistent create()
- Creates a default instance of the persistence-capable class
associated with this instance of ClassInfo.
ObjectStore calls this method the first time it makes
an instance of a persistence-capable class addressable.
When you define a create() method that overrides this one, it
must set all the
associated persistence-capable class's nonstatic reference
fields to null. ObjectStore sets the proper
values for each field when it calls the initializeContents()
method on an instance of the persistence-capable class.
For example:
class Person extends Persistent {
String name; int age; Person children[];
...
}
class PersonInfo extends ClassInfo {
public Persistent create() { return new Person(null, 0, null); }
...
}
- Returns:
- A default instance of the persistence-capable class
associated with this instance of ClassInfo.
- See Also:
- initializeContents
getClassDescriptor
public abstract Class getClassDescriptor() throws ClassNotFoundException
- Obtains the class object for the persistence-capable class with
which this instance of ClassInfo is associated.
- Returns:
- The class object for the persistence-capable class
associated with this instance of ClassInfo.
- Throws: ClassNotFoundException
- If the class was not found.
getFields
public abstract Field[] getFields()
- Gets the array of fields for the persistence-capable class associated
with this instance of ClassInfo. If you define this method,
the order that you specify for the fields determines
the index numbers used by the Persistent.initializeContents()
and Persistent.flushContents() methods, which ObjectStore calls
as needed on the persistence-capable class.
For example:
class PersonInfo extends ClassInfo {
public Field[] getFields() { return fields; }
private static Field[] fields = {
Field.createString("name");
Field.createInt("age");
Field.createClassArray("children", "Person", 1);
}
...
}
The definition of the ClassInfo.getFields() method calls a
create method for each field that you want to access in a persistent object.
ObjectStore does not require an exact match between each field in
the Java class definition and each field created by the getFields()
method.
A persistence-capable Java class can define a field that does not
appear in the list of fields returned by the ClassInfo.getFields()
method. Such a field is a transient-only field. The
initializeContents() method
or postInitializeContents() method that is associated with
the class must initialize transient-only fields.
The getFields() method can return a list of fields that does
not include one or more fields that are
in the Java class definition. Such a field is a persistent-only
field. The
flushContents() method
associated with the
class must initialize persistent-only fields.
An example of how you might use transient-only and persistent-only
fields is in the demo directory that is included in ObjectStore.
In the rep example, Rectangle.a and Rectangle.b
are transient-only fields, while ax, ay, bx, and
by are persistent-only fields.
Chapter 9 in the API User Guide provides additional information for
defining a getFields() method. See
Defining a ClassInfo Subclass.
- Returns:
- The array of fields for the persistence-capable class
associated with this instance of ClassInfo.
- See Also:
- Field
register
public static ClassInfo register(ClassInfo classInfo)
- Registers a class as persistence-capable with ObjectStore
by providing an
instance of its associated ClassInfo subclass. Typically,
an application calls this method the first time it loads an instance
of the associated persistence-capable class. A call to this
method should be in a static expression in the persistence-capable class.
For example:
class Person extends Persistent {
ClassInfo personClassInfo = new PersonClassInfo();
static {
ClassInfo.register(personClassInfo);
}
...
}
- Parameters:
- classInfo - The instance of the subclass of ClassInfo.
- Returns:
- The ClassInfo input argument
- Throws: NullPointerException
- If the classInfo argument is null.
- Throws: SchemaException
- If the persistence-capable
class associated with the specified ClassInfo subclass
does not exist.
get
public static ClassInfo get(String className)
- Obtains the class-specific information for the specified
Persistent subclass. If this persistence-capable class has
not yet been loaded into the Java Virtual Machine, a call to this method
causes the class to be loaded. This invokes user-defined handlers
as needed.
- Parameters:
- className - The fully qualified name of the
Persistent subclass, including the package name.
- Returns:
- The instance of the ClassInfo subclass that was
registered for the specified Persistent subclass.
This value is never null.
- Throws: ClassNotRegisteredException
- If the associated ClassInfo
instance is not found.
- Throws: NullPointerException
- If the className argument is null.
remove
public static void remove(String className)
- Removes a persistence-capable class from the registry.
- Parameters:
- className - The fully qualified name of a Persistent
subclass. Be sure to include the package name in the specification.
- Throws: NullPointerException
- If the className argument is null.
notePersistentField
public static void notePersistentField(String fieldName)
- Notes a field as needing to be part of the schema for the class despite
its transient declaration. If susbsequently ClassInfo must be created
for it via the reflection API, the field will be included as part of
the schema for the class.
- Parameters:
- fieldName<\b> - The fully qualified name of the field that
must be treated as persistent.
- Throws: SchemaException
- If the schema for the class is already
known and the field had been excluded from the schema.
noteTransientField
public static void noteTransientField(String fieldName)
- Notes a field as needing to be excluded from the schema for the class
even though the field has not been declared transient.
- Parameters:
- fieldName<\b> - The fully qualified name of the non-transient
field that is to be assumed transient.
- Throws: SchemaException
- If the schema for the class is already known
and the field had been included in the schema.
Copyright © 1996, 1997, 1998 Object Design, Inc. All rights reserved.