Search in sources :

Example 6 with RelationalValueSource

use of org.hibernate.boot.model.source.spi.RelationalValueSource in project hibernate-orm by hibernate.

the class RelationalValueSourceHelper method buildColumnSources.

/**
 * Given a {@link ColumnsAndFormulasSource}, build the corresponding list of
 * {@link ColumnSource}.  Any formula, rather than a column, will result in an exception.
 *
 * @param mappingDocument the mapping document
 * @param containingTableName The logical name of the table containing the relational values
 * @param columnsAndFormulasSource the adapter describing the value sources.
 *
 * @return The corresponding list.
 */
public static List<ColumnSource> buildColumnSources(MappingDocument mappingDocument, String containingTableName, RelationalValueSourceHelper.ColumnsAndFormulasSource columnsAndFormulasSource) {
    final List<RelationalValueSource> sources = buildValueSources(mappingDocument, containingTableName, columnsAndFormulasSource);
    final List<ColumnSource> columnSources = CollectionHelper.arrayList(sources.size());
    for (RelationalValueSource source : sources) {
        if (!ColumnSource.class.isInstance(source)) {
            final String errorMessage;
            if (columnsAndFormulasSource.getSourceType().canBeNamed() && StringHelper.isNotEmpty(columnsAndFormulasSource.getSourceName())) {
                errorMessage = String.format(Locale.ENGLISH, "Expecting only columns in context of <%s name=\"%s\"/>, but found formula [%s]", columnsAndFormulasSource.getSourceType().getElementName(), columnsAndFormulasSource.getSourceName(), ((DerivedValueSource) source).getExpression());
            } else {
                errorMessage = String.format(Locale.ENGLISH, "Expecting only columns in context of <%s/>, but found formula [%s]", columnsAndFormulasSource.getSourceType().getElementName(), ((DerivedValueSource) source).getExpression());
            }
            throw new MappingException(errorMessage, mappingDocument.getOrigin());
        }
        columnSources.add((ColumnSource) source);
    }
    return columnSources;
}
Also used : RelationalValueSource(org.hibernate.boot.model.source.spi.RelationalValueSource) DerivedValueSource(org.hibernate.boot.model.source.spi.DerivedValueSource) ColumnSource(org.hibernate.boot.model.source.spi.ColumnSource) MappingException(org.hibernate.boot.MappingException)

Aggregations

RelationalValueSource (org.hibernate.boot.model.source.spi.RelationalValueSource)6 MappingException (org.hibernate.boot.MappingException)4 ColumnSource (org.hibernate.boot.model.source.spi.ColumnSource)3 DerivedValueSource (org.hibernate.boot.model.source.spi.DerivedValueSource)3 List (java.util.List)2 JaxbHbmEntityDiscriminatorType (org.hibernate.boot.jaxb.hbm.spi.JaxbHbmEntityDiscriminatorType)1 JaxbHbmMultiTenancyType (org.hibernate.boot.jaxb.hbm.spi.JaxbHbmMultiTenancyType)1 DiscriminatorSource (org.hibernate.boot.model.source.spi.DiscriminatorSource)1 MultiTenancySource (org.hibernate.boot.model.source.spi.MultiTenancySource)1 SizeSource (org.hibernate.boot.model.source.spi.SizeSource)1 Formula (org.hibernate.mapping.Formula)1 AbstractSingleColumnStandardBasicType (org.hibernate.type.AbstractSingleColumnStandardBasicType)1 BasicType (org.hibernate.type.BasicType)1 TypeResolver (org.hibernate.type.TypeResolver)1