use of org.hibernate.boot.model.source.spi.RelationalValueSource 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();
}
};
}
use of org.hibernate.boot.model.source.spi.RelationalValueSource in project hibernate-orm by hibernate.
the class RelationalObjectBinder method bindColumnsAndFormulas.
public void bindColumnsAndFormulas(MappingDocument sourceDocument, List<RelationalValueSource> relationalValueSources, SimpleValue simpleValue, boolean areColumnsNullableByDefault, ColumnNamingDelegate columnNamingDelegate) {
for (RelationalValueSource relationalValueSource : relationalValueSources) {
if (ColumnSource.class.isInstance(relationalValueSource)) {
final ColumnSource columnSource = (ColumnSource) relationalValueSource;
bindColumn(sourceDocument, columnSource, simpleValue, areColumnsNullableByDefault, columnNamingDelegate);
} else {
final DerivedValueSource formulaSource = (DerivedValueSource) relationalValueSource;
simpleValue.addFormula(new Formula(formulaSource.getExpression()));
}
}
}
use of org.hibernate.boot.model.source.spi.RelationalValueSource in project hibernate-orm by hibernate.
the class ModelBinder method resolveLob.
private void resolveLob(final SingularAttributeSourceBasic attributeSource, SimpleValue value) {
// Essentially this expects the type to map to a CLOB/NCLOB/BLOB sql type internally and compares.
if (!value.isLob() && value.getTypeName() != null) {
final TypeResolver typeResolver = attributeSource.getBuildingContext().getMetadataCollector().getTypeResolver();
final BasicType basicType = typeResolver.basic(value.getTypeName());
if (basicType instanceof AbstractSingleColumnStandardBasicType) {
if (isLob(((AbstractSingleColumnStandardBasicType) basicType).getSqlTypeDescriptor().getSqlType(), null)) {
value.makeLob();
}
}
}
// if this maps to CLOB/NCLOB/BLOB then the value will be marked as lob.
if (!value.isLob()) {
for (RelationalValueSource relationalValueSource : attributeSource.getRelationalValueSources()) {
if (ColumnSource.class.isInstance(relationalValueSource)) {
if (isLob(null, ((ColumnSource) relationalValueSource).getSqlType())) {
value.makeLob();
}
}
}
}
}
use of org.hibernate.boot.model.source.spi.RelationalValueSource in project hibernate-orm by hibernate.
the class RelationalValueSourceHelper method buildColumnSource.
/**
* Given a {@link ColumnsAndFormulasSource}, build a single {@link RelationalValueSource}
* which is required to be a column. More than one {@link RelationalValueSource} will result
* in an exception. A 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 single ColumnSource.
*/
public static ColumnSource buildColumnSource(MappingDocument mappingDocument, String containingTableName, RelationalValueSourceHelper.ColumnsAndFormulasSource columnsAndFormulasSource) {
final List<RelationalValueSource> sources = buildValueSources(mappingDocument, containingTableName, columnsAndFormulasSource);
if (sources.size() > 1) {
final String errorMessage;
if (columnsAndFormulasSource.getSourceType().canBeNamed() && StringHelper.isNotEmpty(columnsAndFormulasSource.getSourceName())) {
errorMessage = String.format(Locale.ENGLISH, "Expecting just a single formula/column in context of <%s name=\"%s\"/>", columnsAndFormulasSource.getSourceType().getElementName(), columnsAndFormulasSource.getSourceName());
} else {
errorMessage = String.format(Locale.ENGLISH, "Expecting just a single formula/column in context of <%s/>", columnsAndFormulasSource.getSourceType().getElementName());
}
throw new MappingException(errorMessage, mappingDocument.getOrigin());
}
final RelationalValueSource result = sources.get(0);
if (!ColumnSource.class.isInstance(result)) {
final String errorMessage;
if (columnsAndFormulasSource.getSourceType().canBeNamed() && StringHelper.isNotEmpty(columnsAndFormulasSource.getSourceName())) {
errorMessage = String.format(Locale.ENGLISH, "Expecting single column in context of <%s name=\"%s\"/>, but found formula [%s]", columnsAndFormulasSource.getSourceType().getElementName(), columnsAndFormulasSource.getSourceName(), ((DerivedValueSource) result).getExpression());
} else {
errorMessage = String.format(Locale.ENGLISH, "Expecting single column in context of <%s/>, but found formula [%s]", columnsAndFormulasSource.getSourceType().getElementName(), ((DerivedValueSource) result).getExpression());
}
throw new MappingException(errorMessage, mappingDocument.getOrigin());
}
return (ColumnSource) result;
}
use of org.hibernate.boot.model.source.spi.RelationalValueSource 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();
}
};
}
Aggregations