A custom inheritance provider, in order to create a custom mapping of identifiers to specific class types, may be implemented using the interface com.signsoft.ibo.mapping.jdbc.InheritanceClassProvider . These identifiers can be defined by a set of properties in the inheritance descriptor in the class mapping files. The identifier mapping information is stored in a Map .
Here is an example for an inheritance provider:
public class IdInheritanceProvider implements InheritanceClassProvider
{
/**
* initializes the instance from inside the intelliBO framework
* @param ihd the inheritance descriptor
* @param p the properties
public void init(InheritanceDescriptor ihd, Properties p)
{
// use the embedded id list from the jdo descriptor
// more complex algos. should be specified via the properties section
// the idToClass map contains the class as key and the id as value
this.idToClass = ihd.getSubClassDescriptions();
}
/**
* returns the class for the given id
* @param id the inheritance id
* @return the persistent object class
*/
public Class getClassForId(Object id)
{
Iterator it = idToClass.keySet().iterator();
Class c;
Integer cId;
while (it.hasNext())
{
c = (Class)it.next();
cId = new Integer((String)idToClass.get(c));
if (id.equals(cId)) return c;
}
throw new RuntimeException("Class for id not found: id=" + id);
}
/**
* returns an id for the given class
* @param c the class
* @return an id
*/
public Object getIdForClass(Class c)
{
String id = (String)idToClass.get(c);
if (id == null)
{
throw new RuntimeException("Id for class not found: class=" + c.getName());
}
return new Integer(id);
}
/**
* returns the SQL type
* @return the SQL type
*/
public int getSQLType()
{
return java.sql.Types.INTEGER;
}
/**
* returns the Java type
* @return the Java type
*/
public Class getJavaType()
{
return Integer.class;
}
/**
* here are the class - id relations stored
*/
private Map idToClass;
}