/** * PUBLIC: * Add a class indicator for the root classes subclass. * The indicator is used to determine the class to use for a row read from the database, * and to query only instances of a class from the database. * Every concrete persistent subclass must have a single unique indicator defined for it. * If the root class is concrete then it must also define an indicator. * Only the root class's descriptor of the entire inheritance hierarchy can define the class indicator mapping. */ public void addClassIndicator(Class childClass, Object typeValue) { // Note we should think about supporting null values. // Store as key and value for bi-diractional lookup. getClassIndicatorMapping().put(typeValue, childClass); getClassIndicatorMapping().put(childClass, typeValue); }
/** * INTERNAL: * Return the association of indicators and classes */ public Map getClassIndicatorMapping() { return getClassIndicatorMapping(ConversionManager.getDefaultManager()); }
/** * INTERNAL: * Returns the indicator field value for the given class * If no abstract indicator mapping is specified, use the class name. */ protected Object getClassIndicatorValue(Class javaClass) { if (shouldUseClassNameAsIndicator()) { return javaClass.getName(); } else { return getClassIndicatorMapping().get(javaClass); } }
concreteClass = (Class)getClassIndicatorMapping().get(classFieldValue); if (concreteClass == null) { throw DescriptorException.missingClassForIndicatorFieldValue(classFieldValue, getDescriptor());
DataTable table = dataSet.getTable(field.getTableName()); DataRow row = getRow(rowMap, table); Object value = inheritancePolicy.getClassIndicatorMapping().get(getEntityDesc().getEntityClass()); row.setValue(field.getName(), value);
setClassIndicatorMapping(getParentDescriptor().getInheritancePolicy().getClassIndicatorMapping(session.getDatasourcePlatform().getConversionManager())); setShouldUseClassNameAsIndicator(getParentDescriptor().getInheritancePolicy().shouldUseClassNameAsIndicator()); } else if (!getClassIndicatorMapping(session.getDatasourcePlatform().getConversionManager()).isEmpty()) { Class type = null; Iterator fieldValuesEnum = getClassIndicatorMapping(session.getDatasourcePlatform().getConversionManager()).values().iterator(); while (fieldValuesEnum.hasNext() && (type == null)) { Object value = fieldValuesEnum.next();