Oracle® Application Server TopLink Application Developer's Guide
10g Release 2 (10.1.2) Part No. B15901-01 |
|
Previous |
Next |
OracleAS TopLink uses a class known as the ConversionManager
to convert database types to Java types. This class, found in the oracle.toplink.internal.helper
package, is the central location for type conversion and provides you with a mechanism for using custom types in OracleAS TopLink.
This section describes:
Employ the conversion manager to create and use custom types in OracleAS TopLink.
To use custom types in OracleAS TopLink:
Use one of the following methods to create a subclass of the ConversionManager
:
Overload the public Object convertObject(Object sourceObject, Class javaClass)
method to call the conversion method you provide in the subclass for the custom type.
Delegate the conversion to the superclass.
Implement the protected ClassX convertObjectToClassX(Object sourceObject) throws ConversionException
conversion method to convert incoming objects to the required class.
Assign the class to OracleAS TopLink in either of two ways:
Assign a custom conversion manager to the OracleAS TopLink session using the (getSession().getPlatform().setConversionManager (ConversionManager))
platform.
Set the conversion manager singleton by calling the setDefaultManager(ConversionManager)
static method on the conversion manager. This setting causes all OracleAS TopLink sessions created in the Java Virtual Machine (JVM) to use the custom conversion manager. See the ConversionManager
class in the Oracle Application Server TopLink API Reference for examples.
OracleAS TopLink provides a class loader within the conversion manager that enables the conversion manager to load classes from both an OracleAS TopLink Mapping Workbench project and the class library. The conversion manager uses the System class loader by default.
In some cases, such as when OracleAS TopLink is deployed within an application server, you may want to use other class loaders for the deployed classes. Doing this can cause a ClassNotFound
exception. To resolve this problem, use one of the following methods:
Call the public void setShouldUseClassLoaderFromCurrentThread(boolean useCurrentThread)
method on the default conversion manager before logging in any sessions. This method resolves the problem for most application servers and ensures that OracleAS TopLink uses the correct class loader.
Set the default class loader to be the one that the application uses. For example, if you use the session manager, pass the class loader into the getSession()
call to set the required class loader on the conversion manager.
Call public static void setDefaultLoader(ClassLoader classLoader)
on the conversion manager before any sessions are logged in, and pass in the class loader that contains the deployed classes.