public String getDiscColumn() { if (null == cfBaseMapDef) { return discColumn; } else { return cfBaseMapDef.getDiscColumn(); } }
private void generateColumnSliceIfNeeded(CFMappingDef<?> cfMapDef) { if (cfMapDef.isColumnSliceRequired()) { Collection<PropertyMappingDefinition> propColl = cfMapDef.getAllProperties(); String[] columnNames = new String[cfMapDef.isPersistableEntity() ? propColl.size() : propColl.size() + 1]; Iterator<PropertyMappingDefinition> iter = propColl.iterator(); int pos = 0; while (iter.hasNext()) { columnNames[pos++] = iter.next().getColName(); } // if an inheritance hierarchy exists we need to add in the discriminator // column if (!cfMapDef.isPersistableEntity()) { columnNames[pos] = cfMapDef.getDiscColumn(); } cfMapDef.setSliceColumnNameArr(columnNames); } }
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'?"); } }
String discColName = cfSuperMapDef.getDiscColumn(); DiscriminatorType discType = cfSuperMapDef.getDiscType();
String discColName = cfMapDef.getDiscColumn(); DiscriminatorType discType = cfMapDef.getDiscType(); Map<Object, CFMappingDef<? extends T>> derivedClasses = cfMapDef.getDerivedClassMap();
else if (null != cfMapDef.getDiscColumn() && colName.equals(cfMapDef.getDiscColumn())) { continue; } else {
@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()); }
@Test public void testInheritanceOfEntity() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<MyRedTestBean> cfMapDef = cacheMgr.initializeCacheForClass(MyRedTestBean.class); // 13 is valid when custom conversion of enumerations works again // don't like hard coding numbers into JUnits, but took easy way for now assertEquals(14, cfMapDef.getAllProperties().size()); assertNotNull(cfMapDef.getCfBaseMapDef()); assertEquals(MyRedTestBean.class, cfMapDef.getEffectiveClass()); assertEquals("TestBeanColumnFamily", cfMapDef.getEffectiveColFamName()); assertEquals("myType", cfMapDef.getDiscColumn()); assertEquals(DiscriminatorType.STRING, cfMapDef.getDiscType()); assertEquals("baseId", cfMapDef.getKeyDef().getIdPropertyMap().values().iterator().next() .getPropDesc().getName()); // check super class settings assertEquals( MyRedTestBean.class.getSuperclass(), cfMapDef.getCfSuperMapDef().getRealClass()); assertFalse( cfMapDef.getCfSuperMapDef().isColumnSliceRequired()); }