Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2) Part No. B15900-01 |
|
Previous |
Next |
A container policy specifies the concrete class OracleAS TopLink should use when reading target objects from the database. You can specify a container policy for collection mappings (DirectCollectionMapping
, OneToManyMapping
, and ManyToManyMapping
) and for read-all queries (ReadAllQuery
).
Starting with JDK 1.2, the collection mappings can use any concrete class that implements either the java.util.Collection
interface or the java.util.Map interface
.
When using OracleAS TopLink with JDK 1.2 (or later), you can map object attributes declared as Collection
or Map
, or any subinterface of these two interfaces, or as a class that implements one of these two interfaces. You must specify in the mapping the concrete container class to be used. When OracleAS TopLink reads objects from the database that contain an attribute mapped with a collection mapping, the attribute is set with an instance of the concrete class specified. By default, a collection mapping's container class is java.util.Vector
.
Read-all queries also require a container policy to specify how the result objects are to be returned. The default container is java.util.Vector
.
Container policies cannot be used to specify a custom container class when using indirect containers.
For collection mappings, you can specify the container class in the OracleAS TopLink Mapping Workbench (see "Working with Direct Collection Mappings").
To set the container policy without using the OracleAS TopLink Mapping Workbench, the following API is available for both CollectionMapping
and ReadAllQuery
:
useCollectionClass(Class)
– Specifies the concrete Collection
class to use as a container for the objects in the collection. In JDK 1.2, the class must implement the java.util.Collection
interface.
useMapClass(Class, String)
– Specifies the concrete Map class to use as a container for the objects in the collection. In JDK 1.2, the class must implement the java.util.Map interface
.
Also specified is the name of the zero argument method whose result, when called on the target object, is used as the key in the Hashtable
or Map
. This method must return an object that is a valid key in the Hashtable
or Map
.