public void addDerivedClassMap(CFMappingDef<? extends T> cfDerivedMapDef) { derivedClassMap.put(cfDerivedMapDef.getDiscValue(), cfDerivedMapDef); }
private <T> void validateDerivedClassInheritance(CFMappingDef<T> cfMapDef) { if (null == cfMapDef.getDiscValue()) { throw new HectorObjectMapperException("Base class " + cfMapDef.getCfBaseMapDef().getEffectiveClass().getName() + " requested single table inheritance, but this class, " + cfMapDef.getEffectiveClass().getName() + ", did not specify a " + DiscriminatorValue.class.getSimpleName() + " annotation"); } }
public boolean isPersistableDerivedEntity() { return !isBaseEntity() && null != getDiscValue() && !isAbstract(); }
private <T> void validateSingleTableInheritance(CFMappingDef<T> cfMapDef) { // validating the base class in an inheritance hierarchy. must have a // discriminator column defined if (null == cfMapDef.getDiscColumn()) { throw new HectorObjectMapperException("Class, " + cfMapDef.getRealClass().getName() + ", requested single table inheritance, but you did not specify a " + DiscriminatorColumn.class.getSimpleName() + " annotation"); } // if it is abstract, cannot be instantiated and therefore should not have a // discriminator value defined if (cfMapDef.isAbstract() && null != cfMapDef.getDiscValue()) { throw new HectorObjectMapperException("Abstract class, " + cfMapDef.getRealClass().getName() + ", has an @" + DiscriminatorValue.class.getSimpleName() + " annotation, but cannot be instantiated"); } else if (!cfMapDef.isAbstract() && null == cfMapDef.getDiscValue()) { throw new HectorObjectMapperException("Class, " + cfMapDef.getEffectiveClass().getName() + ", is a part of inheritance hierarchy, but did not specify a " + DiscriminatorValue.class.getSimpleName() + " annotation. Should it be 'abstract'?"); } }
createHColumn(discColName, convertDiscTypeToColValue(discType, cfMapDef.getDiscValue())));
@Test public void testInheritanceWithMultiLevels() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<Desk> cfMapDef = cacheMgr.initializeCacheForClass(Desk.class); CFMappingDef<Furniture> cfBaseMapDef = cacheMgr.getCfMapDef(Furniture.class, true); assertEquals(7, cfMapDef.getAllProperties().size()); assertNotNull(cfMapDef.getCfSuperMapDef()); assertNotNull(cfMapDef.getCfBaseMapDef()); assertEquals(Desk.class.getSuperclass(), cfMapDef.getCfSuperMapDef().getEffectiveClass()); assertEquals(Desk.class.getSuperclass().getSuperclass(), cfMapDef.getCfSuperMapDef() .getCfSuperMapDef() .getEffectiveClass()); assertEquals(cfBaseMapDef.getEffectiveColFamName(), cfMapDef.getEffectiveColFamName()); assertEquals("type", cfMapDef.getDiscColumn()); assertEquals("table_desk", cfMapDef.getDiscValue()); assertEquals(DiscriminatorType.STRING, cfMapDef.getDiscType()); assertEquals("id", cfMapDef.getKeyDef().getIdPropertyMap().values().iterator().next() .getPropDesc().getName()); }