private DeployInheritInfo createInfo(Class<?> cls) { DeployInheritInfo info = new DeployInheritInfo(cls); Class<?> parent = findParent(cls); if (parent != null) { info.setParent(parent); } else { // its the root of inheritance tree... } Inheritance ia = (Inheritance) cls.getAnnotation(Inheritance.class); if (ia != null) { ia.strategy(); } DiscriminatorColumn da = (DiscriminatorColumn) cls.getAnnotation(DiscriminatorColumn.class); if (da != null) { // lowercase the discriminator column for RawSql and JSON info.setDiscriminatorColumn(da.name().toLowerCase()); DiscriminatorType discriminatorType = da.discriminatorType(); if (discriminatorType.equals(DiscriminatorType.INTEGER)) { info.setDiscriminatorType(Types.INTEGER); } else { info.setDiscriminatorType(Types.VARCHAR); } info.setDiscriminatorLength(da.length()); } DiscriminatorValue dv = (DiscriminatorValue) cls.getAnnotation(DiscriminatorValue.class); if (dv != null) { info.setDiscriminatorValue(dv.value()); } return info; }
/** Introspects the Inheritance */ void introspectInheritance( AmberPersistenceUnit persistenceUnit, EntityType entityType, Class type, Inheritance inheritanceAnn, InheritanceConfig inheritanceConfig) throws ConfigException, SQLException { InheritanceType strategy; if (inheritanceAnn != null) strategy = inheritanceAnn.strategy(); else strategy = inheritanceConfig.getStrategy(); switch (strategy) { case JOINED: entityType.setJoinedSubClass(true); break; } getInternalDiscriminatorColumnConfig(type, _annotationCfg); DiscriminatorColumn discriminatorAnn = (DiscriminatorColumn) _annotationCfg.getAnnotation(); DiscriminatorColumnConfig discriminatorConfig = _annotationCfg.getDiscriminatorColumnConfig(); String columnName = null; if (discriminatorAnn != null) columnName = discriminatorAnn.name(); if (columnName == null || columnName.equals("")) columnName = "DTYPE"; AmberType columnType = null; DiscriminatorType discType = DiscriminatorType.STRING; if (discriminatorAnn != null) discType = discriminatorAnn.discriminatorType(); switch (discType) { case STRING: columnType = StringType.create(); break; case CHAR: columnType = PrimitiveCharType.create(); break; case INTEGER: columnType = PrimitiveIntType.create(); break; default: throw new IllegalStateException(); } AmberTable table = entityType.getTable(); // jpa/0gg0 if (table == null) return; com.caucho.amber.table.AmberColumn column = table.createColumn(columnName, columnType); if (discriminatorAnn != null) { // column.setNotNull(! discriminatorAnn.nullable()); column.setLength(discriminatorAnn.length()); if (!"".equals(discriminatorAnn.columnDefinition())) column.setSQLType(discriminatorAnn.columnDefinition()); } else { column.setNotNull(true); column.setLength(10); } entityType.setDiscriminator(column); }