Oracle TopLink Developer's Guide
10g Release 3 (10.1.3) B13593-01 |
|
![]() Previous |
![]() Next |
The TopLink runtime instantiates new instances of a class according to the instantiation policy you configure on the class's descriptor.
Table 28-31 summarizes which descriptors support an instantiation policy.
Table 28-31 Descriptor Support for Instantiation Policy
Descriptor | Using TopLink Workbench
|
Using Java
|
---|---|---|
Relational Descriptors |
|
|
Object-Relational Descriptors |
|
|
EIS Descriptors |
|
|
XML Descriptors |
|
|
You can specify one of the following types of instantiation policy:
Default: TopLink creates a new instance of a class by calling the class's default constructor.
Method: TopLink creates a new instance of a class by calling a public static method that you define on the class descriptor.
Factory: TopLink creates a new instance of a class by calling the appropriate methods on a separate class that you implement according to the Factory design pattern.
To set the instantiation policy for a descriptor, use this procedure:
In the Navigator, select a descriptor.
If the Instantiation advanced property is not visible for the descriptor, right-click the descriptor and choose Select Advanced Properties > Instantiation from the context menu or from the Selected menu.
Use the following information to enter data in each field on the tab:
Field | Description |
---|---|
Use Default Constructor | Specify if the default constructor of the class instantiates a new instance. |
Use Method | Specify a method to execute to create objects from the database. |
|
Select the name of a method to be executed to create objects from the database. The method must be a public, static method on the descriptor's class and must return a new instance of the object. |
Use Factory | Specify an object factory method. |
Factory Class | Select the class of the factory object that creates the new instances. |
Factory Method | Select the method to be used to obtain a factory object. Choose <nothing> to use the default constructor.
|
Instantiation Method | Select the method to be called on the factory object to obtain a new instance that will be populated with data from the data source. |
Use one of the following ClassDescriptor
methods to set the appropriate type of instantiation policy:
useDefaultConstructorInstantiationPolicy
useMethodInstantiationPolicy
useFactoryInstantiationPolicy