Skip Headers

# Using Java

Previous

Next

Classes that implement the `oracle.toplink.mappings.ContainerMapping` interface provide the following methods to set the container policy:

- `useCollectionClass(java.lang.Class concreteClass)`–Configure the mapping to use an instance of the specified `java.util.Collection` container class to hold the target objects.

- `useMapClass(java.lang.Class concreteClass, java.lang.String methodName)`–Configure the mapping to use an instance of the specified `java.util.Map` container class to hold the target objects. The key used to index a value in the `Map` is the value returned by a call to the specified zero-argument method. The method must be implemented by the class (or a superclass) of any value to be inserted into the `Map`.

Classes that extend `oracle.toplink.mappings.CollectionMapping` (which implements the `ContainerMapping` interface) also provide the following methods to set the container policy:

- `useSortedSetClass(java.lang.Class concreteClass, java.util.Comparator comparator)`–Configure the mapping to use an instance of the specified `java.util.SortedSet` container class. Specify the `Comparator` to use to sort the target objects.

Example: Object Array Mapping shows how to configure an `ObjectArrayMapping` to use a `java.util.ArrayList` container class.

Object Array Mapping

    // Create a new mapping and register it with the source Object-relational descriptor
    ObjectArrayMapping phonesMapping = new ObjectArrayMapping();
    phonesMapping.setAttributeName("phones");
    phonesMapping.setGetMethodName("getPhones");
    phonesMapping.setSetMethodName("setPhones");
    phonesMapping.setStructureName("PHONELIST_TYPE");
    phonesMapping.setReferenceClass(Phone.class);
    phonesMapping.setFieldName("PHONES");
    phonesMapping.useCollectionClass(ArrayList.class);
    orDescriptor.addMapping(phonesMapping);