Search in sources :

Example 1 with JaxbHbmMultiTenancyType

use of org.hibernate.boot.jaxb.hbm.spi.JaxbHbmMultiTenancyType in project hibernate-orm by hibernate.

the class EntityHierarchySourceImpl method interpretMultiTenancySource.

private static MultiTenancySource interpretMultiTenancySource(final RootEntitySourceImpl rootEntitySource) {
    final JaxbHbmMultiTenancyType jaxbMultiTenancy = rootEntitySource.jaxbEntityMapping().getMultiTenancy();
    if (jaxbMultiTenancy == null) {
        return null;
    }
    final RelationalValueSource relationalValueSource = RelationalValueSourceHelper.buildValueSource(rootEntitySource.sourceMappingDocument(), null, new RelationalValueSourceHelper.AbstractColumnsAndFormulasSource() {

        @Override
        public XmlElementMetadata getSourceType() {
            return XmlElementMetadata.MULTI_TENANCY;
        }

        @Override
        public String getSourceName() {
            return null;
        }

        @Override
        public String getFormulaAttribute() {
            return jaxbMultiTenancy.getFormulaAttribute();
        }

        @Override
        public String getColumnAttribute() {
            return jaxbMultiTenancy.getColumnAttribute();
        }

        private List columnOrFormulas;

        @Override
        public List getColumnOrFormulaElements() {
            if (columnOrFormulas == null) {
                if (jaxbMultiTenancy.getColumn() != null) {
                    if (jaxbMultiTenancy.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(jaxbMultiTenancy.getColumn());
                    }
                } else {
                    if (jaxbMultiTenancy.getFormula() != null) {
                        columnOrFormulas = Collections.singletonList(jaxbMultiTenancy.getColumn());
                    } else {
                        columnOrFormulas = Collections.emptyList();
                    }
                }
            }
            return columnOrFormulas;
        }

        @Override
        public Boolean isNullable() {
            return false;
        }
    });
    return new MultiTenancySource() {

        @Override
        public RelationalValueSource getRelationalValueSource() {
            return relationalValueSource;
        }

        @Override
        public boolean isShared() {
            return jaxbMultiTenancy.isShared();
        }

        @Override
        public boolean bindAsParameter() {
            return jaxbMultiTenancy.isBindAsParam();
        }
    };
}
Also used : JaxbHbmMultiTenancyType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmMultiTenancyType) MultiTenancySource(org.hibernate.boot.model.source.spi.MultiTenancySource) List(java.util.List) RelationalValueSource(org.hibernate.boot.model.source.spi.RelationalValueSource) MappingException(org.hibernate.boot.MappingException)

Aggregations

List (java.util.List)1 MappingException (org.hibernate.boot.MappingException)1 JaxbHbmMultiTenancyType (org.hibernate.boot.jaxb.hbm.spi.JaxbHbmMultiTenancyType)1 MultiTenancySource (org.hibernate.boot.model.source.spi.MultiTenancySource)1 RelationalValueSource (org.hibernate.boot.model.source.spi.RelationalValueSource)1