Attibute Types in Relations

Relations to a set of objects can be represented in a class using different collection types:

Collection Type

The first option is to use the type Collection . In this case the referencing class has to provide an attribute that supports the interface java.util.Collection . The collection element-type is defined within the field- element.

In the mapping extension the attribute type can be specified more detailed using the extension result-type.

In the sample the result-type element tells Signsoft intelliBO, what the implementation java.util.ArrayList of the Collection interface is used and enables dynamic creation of the resulting collection object.

Sample class Person :

public class Personpossible
{
  private ArrayList addrList;
  ...
}
JDO Descriptor:
<field name="addrList">
<collection element-type="com.signsoft.Address"/>
  <extension vendor-name="ssibo" key="jdbc">
  <extension vendor-name="ssibo" key="mapping" value="one-to-many">
    <extension vendor-name="ssibo" key="result-type" value="java.util.ArrayList"/>
      ...
    </extension>
  </extension>
</field>
Important note for usage of java.util.TreeSet : You have to implement the interface java.lang.Comparable in your data object, if you want to use the class java.util.TreeSet as result-type . The class must therefore implement the following method:
public int compareTo(Object value)

Map Type

The second option is to use a Map collection. The referencing class has to provide an attribute that supports the interface Map . The map value-type is defined within the field- element.

The keys of the map are always of the type of the belonging ObjectID (see also chapter "Object Identity"). In the mapping extension the attribute type can be specified more detailed using the extension result-type .

In the sample the result-type element tells Signsoft intelliBO, what the implementation java.util.HashMap of the Map interface is used and enables dynamic creation of the resulting collection object.

Sample class Person :

public class Person
{
  private HashMap addrList;
  ...
}

JDO Descriptor:

<field name="addrList">
  <map value-type="com.signsoft.Address"/>
  <extension vendor-name="ssibo" key="jdbc">
    <extension vendor-name="ssibo" key="mapping" value="one-to-many">
      <extension vendor-name="ssibo" key="result-type" value="java.util.HashMap"/>
      ...
    </extension>
  </extension>
</field>

Important note for usage of java.util.TreeMap : All key classes have to implement the interface java.lang.Comparable , if you want to use the class java.util.TreeMa p as result type. If you use application-identity , the key class must therefore implement the following method, because intelliBO will use instances of this class as keys for the map:

public int compareTo(Object value)
If you use datastore identity, you have to follow another way, because due to missing information about the sorting, the automatic implementation of the above described method is not possible.

In that case you must overwrite the following method in a subclass of java.util.TreeMap :

public Object put(Object key, Object value)
For example:
public Object put(Object key, Object value)
{
  if (key instanceof KeyClass)
  {
    super.put(createOwnKey(key, value), value);
  }
  else
  {
    super.put(key, value);
  }
}

private Comparable createOwnKey(Object key, Object value)
{
  String ownKey = ...;
  return ownKey;
}
The method createOwnKey must return an object, that implements the interface java.lang.Comparable .

Array Type

The third option is to use an Array collection, where the referencing class has to provide an attribute that is of type Array. The element type is defined by the Array, as known from Java. You may declare an element-type in the mapping extensions; otherwise the type is detected automatically.

Sample class Person :

public class Person
{
  private Address addrList[];
  ...
}
JDO descriptor:
<field name="addrList"> 
  <array/>
  <extension vendor-name="ssibo" key="jdbc">
    <extension vendor-name="ssibo" key="mapping" value="one-tomany">
      <extension vendor-name="ssibo" key="element-type" value="com.signsoft.Address"/>
      ...
    </extension>
  </extension>
</field>