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

## javax.jdo
Class JDOHelper

    java.lang.Object
      javax.jdo.JDOHelper

    public class JDOHelper

extends java.lang.Object

This class can be used by a JDO-aware application to call the JDO behavior of `PersistenceCapable` instances without declaring them to be `PersistenceCapable`.

It is also used to acquire a `PersistenceManagerFactory` via various methods.

This helper class defines static methods that allow a JDO-aware application to examine the runtime state of instances. For example, an application can discover whether the instance is persistent, transactional, dirty, new, deleted, or detached; and to get its associated `PersistenceManager` if it has one.

Version:
  2.0

Constructor Summary
`JDOHelper()`

Method Summary
`static java.lang.Object` | `getObjectId(java.lang.Object pc)` Return a copy of the JDO identity associated with the parameter instance.
`static java.util.Collection` | `getObjectIds(java.util.Collection pcs)` Get object ids for a collection of instances.
`static java.lang.Object[]` | `getObjectIds(java.lang.Object[] pcs)` Get object ids for an array of instances.
`static PersistenceManager` | `getPersistenceManager(java.lang.Object pc)` Return the associated `PersistenceManager` if there is one.
`static PersistenceManagerFactory` | `getPersistenceManagerFactory(java.io.File propsFile)` Returns a `PersistenceManagerFactory` configured based on the properties stored in the file at `propsFile`.
`static PersistenceManagerFactory` | `getPersistenceManagerFactory(java.io.File propsFile, java.lang.ClassLoader loader)` Returns a `PersistenceManagerFactory` configured based on the properties stored in the file at `propsFile`.
`static PersistenceManagerFactory` | `getPersistenceManagerFactory(java.io.InputStream stream)` Returns a `PersistenceManagerFactory` configured based on the Properties stored in the input stream at `stream`.
`static PersistenceManagerFactory` | `getPersistenceManagerFactory(java.io.InputStream stream, java.lang.ClassLoader loader)` Returns a `PersistenceManagerFactory` configured based on the Properties stored in the input stream at `stream`.
`static PersistenceManagerFactory` | `getPersistenceManagerFactory(java.util.Map props)` Get a `PersistenceManagerFactory` based on a `Properties` instance, using the current thread's context class loader to locate the `PersistenceManagerFactory` class.
`static PersistenceManagerFactory` | `getPersistenceManagerFactory(java.util.Map props, java.lang.ClassLoader cl)` Get a `PersistenceManagerFactory` based on a `Properties` instance and a class loader.
`static PersistenceManagerFactory` | `getPersistenceManagerFactory(java.lang.String propsResource)` Returns a `PersistenceManagerFactory` configured based on the properties stored in the resource at `propsResource`.
`static PersistenceManagerFactory` | `getPersistenceManagerFactory(java.lang.String propsResource, java.lang.ClassLoader loader)` Returns a `PersistenceManagerFactory` configured based on the properties stored in the resource at `propsResource`.
`static PersistenceManagerFactory` | `getPersistenceManagerFactory(java.lang.String propsResource, java.lang.ClassLoader propsLoader, java.lang.ClassLoader pmfLoader)` Returns a `PersistenceManagerFactory` configured based on the properties stored in the resource at `propsResource`.
`static PersistenceManagerFactory` | `getPersistenceManagerFactory(java.lang.String jndiLocation, javax.naming.Context context)` Returns a `PersistenceManagerFactory` at the JNDI location specified by `jndiLocation` in the context `context`.
`static PersistenceManagerFactory` | `getPersistenceManagerFactory(java.lang.String jndiLocation, javax.naming.Context context, java.lang.ClassLoader loader)` Returns a `PersistenceManagerFactory` at the JNDI location specified by `jndiLocation` in the context `context`.
`static java.lang.Object` | `getTransactionalObjectId(java.lang.Object pc)` Return a copy of the JDO identity associated with the parameter instance.
`static java.lang.Object` | `getVersion(java.lang.Object pc)` Return the version of the instance.
`static boolean` | `isDeleted(java.lang.Object pc)` Tests whether the parameter instance has been deleted.
`static boolean` | `isDetached(java.lang.Object pc)` Tests whether the parameter instance has been detached.
`static boolean` | `isDirty(java.lang.Object pc)` Tests whether the parameter instance is dirty.
`static boolean` | `isNew(java.lang.Object pc)` Tests whether the parameter instance has been newly made persistent.
`static boolean` | `isPersistent(java.lang.Object pc)` Tests whether the parameter instance is persistent.
`static boolean` | `isTransactional(java.lang.Object pc)` Tests whether the parameter instance is transactional.
`static void` | `makeDirty(java.lang.Object pc, java.lang.String fieldName)` Explicitly mark the parameter instance and field dirty.

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

Constructor Detail

### JDOHelper

    public JDOHelper()

Method Detail

### getPersistenceManager

    public static PersistenceManager getPersistenceManager(java.lang.Object pc)

  Return the associated `PersistenceManager` if there is one. Transactional and persistent instances return the associated `PersistenceManager`.

  Transient non-transactional instances and instances of classes that do not implement `PersistenceCapable` return `null`.

  Parameters:
    `pc` - the `PersistenceCapable` instance.
  Returns:
    the `PersistenceManager` associated with the parameter instance.
  See Also:
    `PersistenceCapable.jdoGetPersistenceManager()`

### makeDirty

    public static void makeDirty(java.lang.Object pc,
                                 java.lang.String fieldName)

  Explicitly mark the parameter instance and field dirty. Normally, `PersistenceCapable` classes are able to detect changes made to their fields. However, if a reference to an array is given to a method outside the class, and the array is modified, then the persistent instance is not aware of the change. This API allows the application to notify the instance that a change was made to a field.

  Transient instances and instances of classes that do not implement `PersistenceCapable` ignore this method.

  Parameters:
    `pc` - the `PersistenceCapable` instance.
    `fieldName` - the name of the field to be marked dirty.
  See Also:
    `PersistenceCapable.jdoMakeDirty(String fieldName)`

### getObjectId

    public static java.lang.Object getObjectId(java.lang.Object pc)

  Return a copy of the JDO identity associated with the parameter instance.

  Persistent instances of `PersistenceCapable` classes have a JDO identity managed by the `PersistenceManager`. This method returns a copy of the ObjectId that represents the JDO identity.

  Transient instances and instances of classes that do not implement `PersistenceCapable` return `null`.

  The ObjectId may be serialized and later restored, and used with a `PersistenceManager` from the same JDO implementation to locate a persistent instance with the same data store identity.

  If the JDO identity is managed by the application, then the ObjectId may be used with a `PersistenceManager` from any JDO implementation that supports the `PersistenceCapable` class.

  If the JDO identity is not managed by the application or the data store, then the ObjectId returned is only valid within the current transaction.

  Parameters:
    `pc` - the PersistenceCapable instance.
  Returns:
    a copy of the ObjectId of the parameter instance as of the beginning of the transaction.
  See Also:
    `PersistenceManager.getObjectId(Object pc)`, `PersistenceCapable.jdoGetObjectId()`, `PersistenceManager.getObjectById(Object oid, boolean validate)`

### getObjectIds

    public static java.util.Collection getObjectIds(java.util.Collection pcs)

  Get object ids for a collection of instances. For each instance in the parameter, the getObjectId method is called. This method returns one identity instance for each element in the parameter. The order of iteration of the returned Collection exactly matches the order of iteration of the parameter Collection.

  Parameters:
    `pcs` - the persistence-capable instances
  Returns:
    the object ids of the parameters
  Since:
    2.0
  See Also:
    `getObjectId(Object pc)`, `getObjectIds(Object[] pcs)`

### getObjectIds

    public static java.lang.Object[] getObjectIds(java.lang.Object[] pcs)

  Get object ids for an array of instances. For each instance in the parameter, the getObjectId method is called. This method returns one identity instance for each element in the parameter. The order of instances of the returned array exactly matches the order of instances of the parameter array.

  Parameters:
    `pcs` - the persistence-capable instances
  Returns:
    the object ids of the parameters
  Since:
    2.0
  See Also:
    `getObjectId(Object pc)`, `getObjectIds(Collection pcs)`

### getTransactionalObjectId

    public static java.lang.Object getTransactionalObjectId(java.lang.Object pc)

  Return a copy of the JDO identity associated with the parameter instance.

  Parameters:
    `pc` - the `PersistenceCapable` instance.
  Returns:
    a copy of the ObjectId of the parameter instance as modified in this transaction.
  See Also:
    `PersistenceCapable.jdoGetTransactionalObjectId()`, `PersistenceManager.getObjectById(Object oid, boolean validate)`

### getVersion

    public static java.lang.Object getVersion(java.lang.Object pc)

  Return the version of the instance.

  Parameters:
    `pc` - the instance
  Returns:
    the version of the instance
  Since:
    2.0

### isDirty

    public static boolean isDirty(java.lang.Object pc)

  Tests whether the parameter instance is dirty. Instances that have been modified, deleted, or newly made persistent in the current transaction return `true`.

  Transient instances and instances of classes that do not implement `PersistenceCapable` return `false`.

  Parameters:
    `pc` - the `PersistenceCapable` instance.
  Returns:
    `true` if the parameter instance has been modified in the current transaction.
  See Also:
    `StateManager.makeDirty(PersistenceCapable pc, String fieldName)`, `PersistenceCapable.jdoIsDirty()`

### isTransactional

    public static boolean isTransactional(java.lang.Object pc)

  Tests whether the parameter instance is transactional. Instances whose state is associated with the current transaction return true.

  Transient instances and instances of classes that do not implement `PersistenceCapable` return `false`.

  Parameters:
    `pc` - the `PersistenceCapable` instance.
  Returns:
    `true` if the parameter instance is transactional.
  See Also:
    `PersistenceCapable.jdoIsTransactional()`

### isPersistent

    public static boolean isPersistent(java.lang.Object pc)

  Tests whether the parameter instance is persistent. Instances that represent persistent objects in the data store return `true`.

  Transient instances and instances of classes that do not implement `PersistenceCapable` return `false`.

  Parameters:
    `pc` - the `PersistenceCapable` instance.
  Returns:
    `true` if the parameter instance is persistent.
  See Also:
    `PersistenceManager.makePersistent(Object pc)`, `PersistenceCapable.jdoIsPersistent()`

### isNew

    public static boolean isNew(java.lang.Object pc)

  Tests whether the parameter instance has been newly made persistent. Instances that have been made persistent in the current transaction return `true`.

  Transient instances and instances of classes that do not implement `PersistenceCapable` return `false`.

  Parameters:
    `pc` - the `PersistenceCapable` instance.
  Returns:
    `true` if the parameter instance was made persistent in the current transaction.
  See Also:
    `PersistenceManager.makePersistent(Object pc)`, `PersistenceCapable.jdoIsNew()`

### isDeleted

    public static boolean isDeleted(java.lang.Object pc)

  Tests whether the parameter instance has been deleted. Instances that have been deleted in the current transaction return `true`.

  Transient instances and instances of classes that do not implement `PersistenceCapable` return `false`.

  Parameters:
    `pc` - the `PersistenceCapable` instance.
  Returns:
    `true` if the parameter instance was deleted in the current transaction.
  See Also:
    `PersistenceManager.deletePersistent(Object pc)`, `PersistenceCapable.jdoIsDeleted()`

### isDetached

    public static boolean isDetached(java.lang.Object pc)

  Tests whether the parameter instance has been detached. Instances that have been detached return true.

  Transient instances return false.

  Parameters:
    `pc` - the instance
  Returns:
    `true` if this instance is detached.
  Since:
    2.0
  See Also:
    `PersistenceCapable.jdoIsDetached()`

### getPersistenceManagerFactory

    public static PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map props)

  Get a `PersistenceManagerFactory` based on a `Properties` instance, using the current thread's context class loader to locate the `PersistenceManagerFactory` class.

  Parameters:
    `props` - a `Properties` instance with properties of the `PersistenceManagerFactory`.
  Returns:
    the `PersistenceManagerFactory`.
  See Also:
    `getPersistenceManagerFactory(Map,ClassLoader)`

### getPersistenceManagerFactory

    public static PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map props,
                                                                         java.lang.ClassLoader cl)

  Get a `PersistenceManagerFactory` based on a `Properties` instance and a class loader. The following are standard key values:
  `"javax.jdo.PersistenceManagerFactoryClass"
  "javax.jdo.option.Optimistic",
  "javax.jdo.option.RetainValues",
  "javax.jdo.option.RestoreValues",
  "javax.jdo.option.IgnoreCache",
  "javax.jdo.option.NontransactionalRead",
  "javax.jdo.option.NontransactionalWrite",
  "javax.jdo.option.Multithreaded",
  "javax.jdo.option.ConnectionUserName",
  "javax.jdo.option.ConnectionPassword",
  "javax.jdo.option.ConnectionURL",
  "javax.jdo.option.ConnectionFactoryName",
  "javax.jdo.option.ConnectionFactory2Name",
  "javax.jdo.option.Mapping",
  "javax.jdo.mapping.Catalog",
  "javax.jdo.mapping.Schema".`

  JDO implementations are permitted to define key values of their own. Any key values not recognized by the implementation must be ignored. Key values that are recognized but not supported by an implementation must result in a `JDOFatalUserException` thrown by the method.

  The returned `PersistenceManagerFactory` is not configurable (the `setXXX` methods will throw an exception).

  JDO implementations might manage a map of instantiated `PersistenceManagerFactory` instances based on specified property key values, and return a previously instantiated `PersistenceManagerFactory` instance. In this case, the properties of the returned instance must exactly match the requested properties.

  Parameters:
    `props` - a `Properties` instance with properties of the `PersistenceManagerFactory`.
    `cl` - the class loader to use to load the `PersistenceManagerFactory` class
  Returns:
    the `PersistenceManagerFactory`.

### getPersistenceManagerFactory

    public static PersistenceManagerFactory getPersistenceManagerFactory(java.lang.String propsResource)

  Returns a `PersistenceManagerFactory` configured based on the properties stored in the resource at `propsResource`. This method is equivalent to invoking `getPersistenceManagerFactory(String,ClassLoader)` with `Thread.currentThread().getContextClassLoader()` as the `loader` argument.

  Parameters:
    `propsResource` - the resource containing the Properties
  Returns:
    the PersistenceManagerFactory
  Since:
    2.0

### getPersistenceManagerFactory

    public static PersistenceManagerFactory getPersistenceManagerFactory(java.lang.String propsResource,
                                                                         java.lang.ClassLoader loader)

  Returns a `PersistenceManagerFactory` configured based on the properties stored in the resource at `propsResource`. Loads the resource via `loader`, and creates a `PersistenceManagerFactory` with `loader`. Any `IOException`s thrown during resource loading will be wrapped in a `JDOFatalUserException`.

  Parameters:
    `propsResource` - the resource containing the Properties
    `loader` - the class loader to use to load both the propsResource and the `PersistenceManagerFactory` class
  Returns:
    the PersistenceManagerFactory
  Since:
    2.0

### getPersistenceManagerFactory

    public static PersistenceManagerFactory getPersistenceManagerFactory(java.lang.String propsResource,
                                                                         java.lang.ClassLoader propsLoader,
                                                                         java.lang.ClassLoader pmfLoader)

  Returns a `PersistenceManagerFactory` configured based on the properties stored in the resource at `propsResource`. Loads the Properties via `propsLoader`, and creates a `PersistenceManagerFactory` with `pmfLoader`. Any `IOException`s thrown during resource loading will be wrapped in a `JDOFatalUserException`.

  Parameters:
    `propsResource` - the resource containing the Properties
    `propsLoader` - the class loader to use to load the propsResource
    `pmfLoader` - the class loader to use to load the `PersistenceManagerFactory` class
  Returns:
    the PersistenceManagerFactory
  Since:
    2.0

### getPersistenceManagerFactory

    public static PersistenceManagerFactory getPersistenceManagerFactory(java.io.File propsFile)

  Returns a `PersistenceManagerFactory` configured based on the properties stored in the file at `propsFile`. This method is equivalent to invoking `getPersistenceManagerFactory(File,ClassLoader)` with `Thread.currentThread().getContextClassLoader()` as the `loader` argument.

  Parameters:
    `propsFile` - the file containing the Properties
  Returns:
    the PersistenceManagerFactory
  Since:
    2.0

### getPersistenceManagerFactory

    public static PersistenceManagerFactory getPersistenceManagerFactory(java.io.File propsFile,
                                                                         java.lang.ClassLoader loader)

  Returns a `PersistenceManagerFactory` configured based on the properties stored in the file at `propsFile`. Creates a `PersistenceManagerFactory` with `loader`. Any `IOException`s or `FileNotFoundException`s thrown during resource loading will be wrapped in a `JDOFatalUserException`.

  Parameters:
    `propsFile` - the file containing the Properties
    `loader` - the class loader to use to load the `PersistenceManagerFactory` class
  Returns:
    the PersistenceManagerFactory
  Since:
    2.0

### getPersistenceManagerFactory

    public static PersistenceManagerFactory getPersistenceManagerFactory(java.lang.String jndiLocation,
                                                                         javax.naming.Context context)

  Returns a `PersistenceManagerFactory` at the JNDI location specified by `jndiLocation` in the context `context`. If `context` is `null`, `new InitialContext()` will be used. This method is equivalent to invoking `getPersistenceManagerFactory(String,Context,ClassLoader)` with `Thread.currentThread().getContextClassLoader()` as the `loader` argument.

  Parameters:
    `jndiLocation` - the JNDI location containing the PersistenceManagerFactory
    `context` - the context in which to find the named PersistenceManagerFactory
  Returns:
    the PersistenceManagerFactory
  Since:
    2.0

### getPersistenceManagerFactory

    public static PersistenceManagerFactory getPersistenceManagerFactory(java.lang.String jndiLocation,
                                                                         javax.naming.Context context,
                                                                         java.lang.ClassLoader loader)

  Returns a `PersistenceManagerFactory` at the JNDI location specified by `jndiLocation` in the context `context`. If `context` is `null`, `new InitialContext()` will be used. Creates a `PersistenceManagerFactory` with `loader`. Any `NamingException`s thrown will be wrapped in a `JDOFatalUserException`.

  Parameters:
    `jndiLocation` - the JNDI location containing the PersistenceManagerFactory
    `context` - the context in which to find the named PersistenceManagerFactory
    `loader` - the class loader to use to load the `PersistenceManagerFactory` class
  Returns:
    the PersistenceManagerFactory
  Since:
    2.0

### getPersistenceManagerFactory

    public static PersistenceManagerFactory getPersistenceManagerFactory(java.io.InputStream stream)

  Returns a `PersistenceManagerFactory` configured based on the Properties stored in the input stream at `stream`. This method is equivalent to invoking `getPersistenceManagerFactory(InputStream,ClassLoader)` with `Thread.currentThread().getContextClassLoader()` as the `loader` argument.

  Parameters:
    `stream` - the stream containing the Properties
  Returns:
    the PersistenceManagerFactory
  Since:
    2.0

### getPersistenceManagerFactory

    public static PersistenceManagerFactory getPersistenceManagerFactory(java.io.InputStream stream,
                                                                         java.lang.ClassLoader loader)

  Returns a `PersistenceManagerFactory` configured based on the Properties stored in the input stream at `stream`. Creates a `PersistenceManagerFactory` with `loader`. Any `IOException`s thrown during resource loading will be wrapped in a `JDOFatalUserException`.

  Parameters:
    `stream` - the stream containing the Properties
    `loader` - the class loader to use to load the `PersistenceManagerFactory` class
  Returns:
    the PersistenceManagerFactory
  Since:
    2.0

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

Copyright © 2005-2006 Apache Software Foundation. All Rights Reserved.