Overview | Package | Class | Tree | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javax.jdo.spi
Class JDOImplHelper

    java.lang.Object
      |
      +--javax.jdo.spi.JDOImplHelper

public class JDOImplHelper
extends java.lang.Object

This class is a helper class for JDO implementations. It contains methods to register metadata for persistence-capable classes and to perform common operations needed by implementations, not by end users.

`JDOImplHelper` allows construction of instances of persistence-capable classes without using reflection.

Persistence-capable classes register themselves via a static method at class load time. There is no security restriction on this access. JDO implementations get access to the functions provided by this class only if they are authorized by the security manager. To avoid having every call go through the security manager, only the call to get an instance is checked. Once an implementation has an instance, any of the methods can be invoked without security checks.

Version:
  0.9
Author:
  Craig Russell

Nested Class Summary
`(package private) static class` | `JDOImplHelper.Meta` This is a helper class to manage metadata per persistence-capable class.

Method Summary
`void` | `addRegisterClassListener(RegisterClassListener crl)` Add the specified `RegisterClassListener` to the listener list.
`void` | `copyKeyFieldsFromObjectId(java.lang.Class pcClass, PersistenceCapable.ObjectIdFieldConsumer fm, java.lang.Object oid)` Copy fields to an outside source from the key fields in the ObjectId.
`void` | `copyKeyFieldsToObjectId(java.lang.Class pcClass, PersistenceCapable.ObjectIdFieldSupplier fm, java.lang.Object oid)` Copy fields from an outside source to the key fields in the ObjectId.
`byte[]` | `getFieldFlags(java.lang.Class pcClass)` Get the field flags for a `PersistenceCapable` class.
`java.lang.String[]` | `getFieldNames(java.lang.Class pcClass)` Get the field names for a `PersistenceCapable` class.
`java.lang.Class[]` | `getFieldTypes(java.lang.Class pcClass)` Get the field types for a `PersistenceCapable` class.
`static JDOImplHelper` | `getInstance()` Get an instance of `JDOImplHelper`.
`java.lang.Class` | `getPersistenceCapableSuperclass(java.lang.Class pcClass)` Get the persistence-capable superclass for a `PersistenceCapable` class.
`java.util.Collection` | `getRegisteredClasses()` Returns a collection of class objects of the registered persistence-capable classes.
`PersistenceCapable` | `newInstance(java.lang.Class pcClass, StateManager sm)` Create a new instance of the class and assign its `jdoStateManager`.
`PersistenceCapable` | `newInstance(java.lang.Class pcClass, StateManager sm, java.lang.Object oid)` Create a new instance of the class and assign its `jdoStateManager` and key values from the ObjectId.
`java.lang.Object` | `newObjectIdInstance(java.lang.Class pcClass)` Create a new instance of the ObjectId class of this `PersistenceCapable` class.
`java.lang.Object` | `newObjectIdInstance(java.lang.Class pcClass, java.lang.String str)` Create a new instance of the ObjectId class of this `PersistenceCapable` class, using the `String` form of the constructor.
`static void` | `registerClass(java.lang.Class pcClass, java.lang.String[] fieldNames, java.lang.Class[] fieldTypes, byte[] fieldFlags, java.lang.Class persistenceCapableSuperclass, PersistenceCapable pc)` Register metadata by class.
`void` | `removeRegisterClassListener(RegisterClassListener crl)` Remove the specified `RegisterClassListener` from the listener list.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### getInstance

    public static JDOImplHelper getInstance()
                                     throws java.lang.SecurityException

  Get an instance of `JDOImplHelper`. This method checks that the caller is authorized for `JDOPermission("getMetadata")`, and if not, throws `SecurityException`.

  Returns:
    an instance of `JDOImplHelper`.
    `java.lang.SecurityException`

### getFieldNames

    public java.lang.String[] getFieldNames(java.lang.Class pcClass)

  Get the field names for a `PersistenceCapable` class. The order of fields is the natural ordering of the `String` class (without considering localization).

  Parameters:
    `pcClass` - the `PersistenceCapable` class.
  Returns:
    the field names for the class.

### getFieldTypes

    public java.lang.Class[] getFieldTypes(java.lang.Class pcClass)

  Get the field types for a `PersistenceCapable` class. The order of fields is the same as for field names.

  Parameters:
    `pcClass` - the `PersistenceCapable` class.
  Returns:
    the field types for the class.

### getFieldFlags

    public byte[] getFieldFlags(java.lang.Class pcClass)

  Get the field flags for a `PersistenceCapable` class. The order of fields is the same as for field names.

  Parameters:
    `pcClass` - the `PersistenceCapable` class.
  Returns:
    the field types for the class.

### getPersistenceCapableSuperclass

    public java.lang.Class getPersistenceCapableSuperclass(java.lang.Class pcClass)

  Get the persistence-capable superclass for a `PersistenceCapable` class.

  Parameters:
    `pcClass` - the `PersistenceCapable` class.
  Returns:
    The `PersistenceCapable` superclass for this class, or `null` if there isn't one.

### newInstance

    public PersistenceCapable newInstance(java.lang.Class pcClass,
                                          StateManager sm)

  Create a new instance of the class and assign its `jdoStateManager`. The new instance has its `jdoFlags` set to `LOAD_REQUIRED`.

  Parameters:
    `pcClass` - the `PersistenceCapable` class.
    `sm` - the `StateManager` which will own the new instance.
  Returns:
    the new instance, or `null` if the class is not registered.
  See Also:
    `PersistenceCapable.jdoNewInstance(StateManager sm)`

### newInstance

    public PersistenceCapable newInstance(java.lang.Class pcClass,
                                          StateManager sm,
                                          java.lang.Object oid)

  Create a new instance of the class and assign its `jdoStateManager` and key values from the ObjectId. If the oid parameter is `null`, no key values are copied. The new instance has its `jdoFlags` set to `LOAD_REQUIRED`.

  Parameters:
    `pcClass` - the `PersistenceCapable` class.
    `sm` - the `StateManager` which will own the new instance.
    `oid` - the ObjectId instance from which to copy key field values.
  Returns:
    the new instance, or `null` if the class is not registered.
  See Also:
    `PersistenceCapable.jdoNewInstance(StateManager sm, Object oid)`

### newObjectIdInstance

    public java.lang.Object newObjectIdInstance(java.lang.Class pcClass)

  Create a new instance of the ObjectId class of this `PersistenceCapable` class.

  Parameters:
    `pcClass` - the `PersistenceCapable` class.
  Returns:
    the new ObjectId instance, or `null` if the class is not registered.

### newObjectIdInstance

    public java.lang.Object newObjectIdInstance(java.lang.Class pcClass,
                                                java.lang.String str)

  Create a new instance of the ObjectId class of this `PersistenceCapable` class, using the `String` form of the constructor.

  Parameters:
    `str` - the `String` form of the object id
    `pcClass` - the `PersistenceCapable` class.
  Returns:
    the new ObjectId instance, or `null` if the class is not registered.

### copyKeyFieldsToObjectId

    public void copyKeyFieldsToObjectId(java.lang.Class pcClass,
                                        PersistenceCapable.ObjectIdFieldSupplier fm,
                                        java.lang.Object oid)

  Copy fields from an outside source to the key fields in the ObjectId. This method is generated in the `PersistenceCapable` class to generate a call to the field manager for each key field in the ObjectId.

  For example, an ObjectId class that has three key fields (`int id`, `String name`, and `Float salary`) would have the method generated:

  `void jdoCopyKeyFieldsToObjectId (Object oid, ObjectIdFieldSupplier fm) {
  oid.id = fm.fetchIntField (0);
  oid.name = fm.fetchStringField (1);
  oid.salary = fm.fetchObjectField (2);
  }`

  The implementation is responsible for implementing the `ObjectIdFieldSupplier` to provide the values for the key fields.

  Parameters:
    `pcClass` - the `PersistenceCapable Class`.
    `oid` - the ObjectId target of the copy.
    `fm` - the field manager that supplies the field values.

### copyKeyFieldsFromObjectId

    public void copyKeyFieldsFromObjectId(java.lang.Class pcClass,
                                          PersistenceCapable.ObjectIdFieldConsumer fm,
                                          java.lang.Object oid)

  Copy fields to an outside source from the key fields in the ObjectId. This method is generated in the `PersistenceCapable` class to generate a call to the field manager for each key field in the ObjectId. For example, an ObjectId class that has three key fields (`int id`, `String name`, and `Float salary`) would have the method generated:

  `void jdoCopyKeyFieldsFromObjectId
  (PersistenceCapable oid, ObjectIdFieldConsumer fm) {
  fm.storeIntField (0, oid.id);
  fm.storeStringField (1, oid.name);
  fm.storeObjectField (2, oid.salary);
  }`

  The implementation is responsible for implementing the `ObjectIdFieldConsumer` to store the values for the key fields.

  Parameters:
    `pcClass` - the `PersistenceCapable` class
    `oid` - the ObjectId source of the copy.
    `fm` - the field manager that receives the field values.

### registerClass

    public static void registerClass(java.lang.Class pcClass,
                                     java.lang.String[] fieldNames,
                                     java.lang.Class[] fieldTypes,
                                     byte[] fieldFlags,
                                     java.lang.Class persistenceCapableSuperclass,
                                     PersistenceCapable pc)

  Register metadata by class. The registration will be done in the class named `JDOImplHelper` loaded by the same class loader as the `PersistenceCapable` class performing the registration.

  Parameters:
    `pcClass` - the `PersistenceCapable` class used as the key for lookup.
    `fieldNames` - an array of `String` field names for persistent and transactional fields
    `fieldTypes` - an array of `Class` field types
    `fieldFlags` - the Field Flags for persistent and transactional fields
    `pc` - an instance of the `PersistenceCapable` class
    `persistenceCapableSuperclass` - the most immediate superclass that is `PersistenceCapable`

### addRegisterClassListener

    public void addRegisterClassListener(RegisterClassListener crl)

  Add the specified `RegisterClassListener` to the listener list.

  Parameters:
    `crl` - the listener to be added

### removeRegisterClassListener

    public void removeRegisterClassListener(RegisterClassListener crl)

  Remove the specified `RegisterClassListener` from the listener list.

  Parameters:
    `crl` - the listener to be removed

### getRegisteredClasses

    public java.util.Collection getRegisteredClasses()

  Returns a collection of class objects of the registered persistence-capable classes.

  Returns:
    registered persistence-capable classes

Overview | Package | Class | Tree | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD