use of org.hibernate.boot.jaxb.hbm.spi.JaxbHbmEntityDiscriminatorType in project hibernate-orm by hibernate.
the class EntityHierarchySourceImpl method interpretDiscriminatorSource.
private static DiscriminatorSource interpretDiscriminatorSource(final RootEntitySourceImpl rootEntitySource) {
final JaxbHbmEntityDiscriminatorType jaxbDiscriminatorMapping = rootEntitySource.jaxbEntityMapping().getDiscriminator();
if (jaxbDiscriminatorMapping == null) {
return null;
}
final RelationalValueSource relationalValueSource = RelationalValueSourceHelper.buildValueSource(rootEntitySource.sourceMappingDocument(), null, new RelationalValueSourceHelper.AbstractColumnsAndFormulasSource() {
@Override
public XmlElementMetadata getSourceType() {
return XmlElementMetadata.DISCRIMINATOR;
}
@Override
public String getSourceName() {
return null;
}
@Override
public SizeSource getSizeSource() {
return Helper.interpretSizeSource(jaxbDiscriminatorMapping.getLength(), (Integer) null, null);
}
@Override
public String getFormulaAttribute() {
return jaxbDiscriminatorMapping.getFormulaAttribute();
}
@Override
public String getColumnAttribute() {
return jaxbDiscriminatorMapping.getColumnAttribute();
}
private List columnOrFormulas;
@Override
public List getColumnOrFormulaElements() {
if (columnOrFormulas == null) {
if (jaxbDiscriminatorMapping.getColumn() != null) {
if (jaxbDiscriminatorMapping.getFormula() != null) {
throw new MappingException(String.format(Locale.ENGLISH, "discriminator mapping [%s] named both <column/> and <formula/>, but only one or other allowed", rootEntitySource.getEntityNamingSource().getEntityName()), rootEntitySource.sourceMappingDocument().getOrigin());
} else {
columnOrFormulas = Collections.singletonList(jaxbDiscriminatorMapping.getColumn());
}
} else {
if (jaxbDiscriminatorMapping.getFormula() != null) {
columnOrFormulas = Collections.singletonList(jaxbDiscriminatorMapping.getFormula());
} else {
columnOrFormulas = Collections.emptyList();
}
}
}
return columnOrFormulas;
}
@Override
public Boolean isNullable() {
return !jaxbDiscriminatorMapping.isNotNull();
}
});
return new DiscriminatorSource() {
@Override
public EntityNaming getEntityNaming() {
return rootEntitySource.getEntityNamingSource();
}
@Override
public MetadataBuildingContext getBuildingContext() {
return rootEntitySource.metadataBuildingContext();
}
@Override
public RelationalValueSource getDiscriminatorRelationalValueSource() {
return relationalValueSource;
}
@Override
public String getExplicitHibernateTypeName() {
return jaxbDiscriminatorMapping.getType();
}
@Override
public boolean isForced() {
return jaxbDiscriminatorMapping.isForce();
}
@Override
public boolean isInserted() {
return jaxbDiscriminatorMapping.isInsert();
}
};
}
Aggregations