5.5 Additional APIs


JDO defines two additional classes that are usable by an application:

  • JDOHelper

  • I18NHelper

5.5.1 JDOHelper Class

This class defines a number of static methods that a persistence-capable class or JDO application can use. Each method simply delegates to other JDO classes, like PersistenceManager and PersistenceManagerFactory , as well as classes defined in the javax.jdo.spi package like PersistenceCapable .

5.5.1.1 Method summary

This class defines methods that can be used as a bootstrap mechanism for creating a PersistenceManagerFactory instance, as well as convenience methods for interacting with persistent objects.

 
 static PersistenceManager getPersistenceManager (Object pc) 

This method returns the PersistenceManager instance associated with the specified object. It returns null if the specified instance is transient or is not an instance of a persistence-capable class.

 
 static PersistenceManagerFactory getPersistenceManagerFactory (Properties props) static PersistenceManagerFactory getPersistenceManagerFactory (Properties props, ClassLoader cl) 

These methods create a PersistenceManagerFactory instance based on the specified properties. See the section on PersistenceManagerFactory for more details on each property.

If no class loader is specified, then the calling thread's context ClassLoader is used to find the PersistenceManagerFactory class.

Table 5-9 provides a list of the standard properties that can be used.

The only required property is javax.jdo.PersistenceManagerFactoryClass . All others are optional.

In addition to these standard properties, a JDO implementation may also support its own additional properties. Any properties not recognized by a JDO implementation are ignored.

Table 5-9. JDOHelper Properties

Property Name

Value

javax.jdo.PersistenceManagerFactoryClass

Class name of JDO implementation's PersistenceManagerFactory class

javax.jdo.option.Optimistic

true or false

javax.jdo.option.RetainValues

true or false

javax.jdo.option.RestoreValues

true or false

javax.jdo.option.IgnoreCache

true or false

javax.jdo.option.NontransactionalRead

true or false

javax.jdo.option.NontransactionalWrite

true or false

javax.jdo.option.Multithreaded

true or false

javax.jdo.option.ConnectionDriverName

Undefined [*]

javax.jdo.option.ConnectionUserName

Undefined [*]

javax.jdo.option.ConnectionPassword

Undefined [*]

javax.jdo.option.ConnectionURL

Undefined [*]

javax.jdo.option.ConnectionFactoryName

Undefined [*]

javax.jdo.option.ConnectionFactory2Name

Undefined [*]

[*] The value of this property is specific to the JDO implementation being used.

  •  
     static Object getObjectId (Object pc) static Object getTransactionalObjectId (Object pc) 

    These methods provide shortcuts for the getObjectId() and getTransactionalObjectId() methods defined on PersistenceManager .

  •  
     static boolean isDirty (Object pc) static boolean isTransactional (Object pc) static boolean isPersistent (Object pc) static boolean isNew (Object pc) static boolean isDeleted (Object pc) 

    These methods allow an application to interrogate the lifecycle state of a persistent object and determine if it is dirty, transactional, persistent, new, or deleted.

    See Chapter 4 for more details on the object lifecycle.

  •  
     static void makeDirty (Object pc, String fieldName) 

    This method allows an application to explicitly mark the specified field of the given persistent object as dirty. The fieldName is the name of the field, optionally fully qualified with the package and class name. If the specified object is null , transient, or not an instance of a persistence-capable class or the specified field name is not a managed field, then this method does nothing.

5.5.2 I18NHelper class

This class provides localized strings for the classes in the javax.jdo and javax.jdo.spi packages (primarily the exception classes). It finds a Java ResourceBundle for the current locale using java.jdo.Bundle as the baseclass. If no ResourceBundle is found for the current locale, then the Bundle.properties file located in the javax.jdo package is used. If an application needed to provide localized strings, it could provide its own ResourceBundle .

Although this class is in the javax.jdo package, it is not supposed to be used by an application. As of the JDO 1.0.1 maintenance release, this class has been deprecated and in future releases will be moved to the javax.jdo.spi package.



Core Java Data Objects
Core Java Data Objects
ISBN: 0131407317
EAN: 2147483647
Year: 2003
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net