use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.
the class FilterDefinitionBinder method processFilterDefinition.
/**
* Handling for a {@code <filter-def/>} declaration.
*
* @param context Access to information relative to the mapping document containing this binding
* @param jaxbFilterDefinitionMapping The {@code <filter-def/>} JAXB mapping
*/
@SuppressWarnings("unchecked")
public static void processFilterDefinition(HbmLocalMetadataBuildingContext context, JaxbHbmFilterDefinitionType jaxbFilterDefinitionMapping) {
Map<String, Type> parameterMap = null;
String condition = jaxbFilterDefinitionMapping.getCondition();
for (Serializable content : jaxbFilterDefinitionMapping.getContent()) {
if (String.class.isInstance(content)) {
final String contentString = content.toString().trim();
if (StringHelper.isNotEmpty(contentString)) {
if (condition != null) {
log.debugf("filter-def [name=%s, origin=%s] defined multiple conditions, accepting arbitrary one", jaxbFilterDefinitionMapping.getName(), context.getOrigin().toString());
}
}
} else {
final JaxbHbmFilterParameterType jaxbParameterMapping;
if (JaxbHbmFilterParameterType.class.isInstance(content)) {
jaxbParameterMapping = (JaxbHbmFilterParameterType) content;
} else if (JAXBElement.class.isInstance(content)) {
final JAXBElement<JaxbHbmFilterParameterType> jaxbElement = (JAXBElement<JaxbHbmFilterParameterType>) content;
jaxbParameterMapping = jaxbElement.getValue();
} else {
throw new MappingException("Unable to decipher filter-def content type [" + content.getClass().getName() + "]", context.getOrigin());
}
if (parameterMap == null) {
parameterMap = new HashMap<String, Type>();
}
parameterMap.put(jaxbParameterMapping.getParameterName(), context.getMetadataCollector().getTypeResolver().heuristicType(jaxbParameterMapping.getParameterValueTypeName()));
}
}
context.getMetadataCollector().addFilterDefinition(new FilterDefinition(jaxbFilterDefinitionMapping.getName(), condition, parameterMap));
log.debugf("Processed filter definition : %s", jaxbFilterDefinitionMapping.getName());
}
use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.
the class CacheableFileXmlSource method doBind.
@Override
@SuppressWarnings("unchecked")
public Binding doBind(Binder binder) {
if (strict) {
try {
return new Binding(readSerFile(), getOrigin());
} catch (SerializationException e) {
throw new MappingException(String.format("Unable to deserialize from cached file [%s]", getOrigin().getName()), e, getOrigin());
} catch (FileNotFoundException e) {
throw new MappingException(String.format("Unable to locate cached file [%s]", getOrigin().getName()), e, getOrigin());
}
} else {
if (!isSerfileObsolete()) {
try {
return readSerFile();
} catch (SerializationException e) {
log.unableToDeserializeCache(serFile.getName(), e);
} catch (FileNotFoundException e) {
log.cachedFileNotFound(serFile.getName(), e);
}
} else {
log.cachedFileObsolete(serFile);
}
log.readingMappingsFromFile(xmlFile.getPath());
final Binding binding = FileXmlSource.doBind(binder, xmlFile, getOrigin());
writeSerFile(binding);
return binding;
}
}
use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.
the class ModelBinder method bindSimpleEntityIdentifier.
private void bindSimpleEntityIdentifier(MappingDocument sourceDocument, final EntityHierarchySourceImpl hierarchySource, RootClass rootEntityDescriptor) {
final IdentifierSourceSimple idSource = (IdentifierSourceSimple) hierarchySource.getIdentifierSource();
final SimpleValue idValue = new SimpleValue(sourceDocument.getMetadataCollector(), rootEntityDescriptor.getTable());
rootEntityDescriptor.setIdentifier(idValue);
bindSimpleValueType(sourceDocument, idSource.getIdentifierAttributeSource().getTypeInformation(), idValue);
final String propertyName = idSource.getIdentifierAttributeSource().getName();
if (propertyName == null || !rootEntityDescriptor.hasPojoRepresentation()) {
if (!idValue.isTypeSpecified()) {
throw new MappingException("must specify an identifier type: " + rootEntityDescriptor.getEntityName(), sourceDocument.getOrigin());
}
} else {
idValue.setTypeUsingReflection(rootEntityDescriptor.getClassName(), propertyName);
}
relationalObjectBinder.bindColumnsAndFormulas(sourceDocument, ((RelationalValueSourceContainer) idSource.getIdentifierAttributeSource()).getRelationalValueSources(), idValue, false, new RelationalObjectBinder.ColumnNamingDelegate() {
@Override
public Identifier determineImplicitName(final LocalMetadataBuildingContext context) {
context.getBuildingOptions().getImplicitNamingStrategy().determineIdentifierColumnName(new ImplicitIdentifierColumnNameSource() {
@Override
public EntityNaming getEntityNaming() {
return hierarchySource.getRoot().getEntityNamingSource();
}
@Override
public AttributePath getIdentifierAttributePath() {
return idSource.getIdentifierAttributeSource().getAttributePath();
}
@Override
public MetadataBuildingContext getBuildingContext() {
return context;
}
});
return database.toIdentifier(propertyName);
}
});
if (propertyName != null) {
Property prop = new Property();
prop.setValue(idValue);
bindProperty(sourceDocument, idSource.getIdentifierAttributeSource(), prop);
rootEntityDescriptor.setIdentifierProperty(prop);
rootEntityDescriptor.setDeclaredIdentifierProperty(prop);
}
makeIdentifier(sourceDocument, idSource.getIdentifierGeneratorDescriptor(), idSource.getUnsavedValue(), idValue);
}
use of org.hibernate.boot.MappingException in project hibernate-orm by hibernate.
the class ModelBinder method bindEntityTableSpecification.
private Table bindEntityTableSpecification(final MappingDocument mappingDocument, TableSpecificationSource tableSpecSource, Table denormalizedSuperTable, final EntitySource entitySource, PersistentClass entityDescriptor) {
final Namespace namespace = database.locateNamespace(determineCatalogName(tableSpecSource), determineSchemaName(tableSpecSource));
final boolean isTable = TableSource.class.isInstance(tableSpecSource);
final boolean isAbstract = entityDescriptor.isAbstract() == null ? false : entityDescriptor.isAbstract();
final String subselect;
final Identifier logicalTableName;
final Table table;
if (isTable) {
final TableSource tableSource = (TableSource) tableSpecSource;
if (StringHelper.isNotEmpty(tableSource.getExplicitTableName())) {
logicalTableName = database.toIdentifier(tableSource.getExplicitTableName());
} else {
final ImplicitEntityNameSource implicitNamingSource = new ImplicitEntityNameSource() {
@Override
public EntityNaming getEntityNaming() {
return entitySource.getEntityNamingSource();
}
@Override
public MetadataBuildingContext getBuildingContext() {
return mappingDocument;
}
};
logicalTableName = mappingDocument.getBuildingOptions().getImplicitNamingStrategy().determinePrimaryTableName(implicitNamingSource);
}
if (denormalizedSuperTable == null) {
table = namespace.createTable(logicalTableName, isAbstract);
} else {
table = namespace.createDenormalizedTable(logicalTableName, isAbstract, denormalizedSuperTable);
}
} else {
final InLineViewSource inLineViewSource = (InLineViewSource) tableSpecSource;
subselect = inLineViewSource.getSelectStatement();
logicalTableName = database.toIdentifier(inLineViewSource.getLogicalName());
if (denormalizedSuperTable == null) {
table = new Table(namespace, subselect, isAbstract);
} else {
table = new DenormalizedTable(namespace, subselect, isAbstract, denormalizedSuperTable);
}
table.setName(logicalTableName.render());
}
EntityTableXref superEntityTableXref = null;
if (entitySource.getSuperType() != null) {
//noinspection SuspiciousMethodCalls
final String superEntityName = ((EntitySource) entitySource.getSuperType()).getEntityNamingSource().getEntityName();
superEntityTableXref = mappingDocument.getMetadataCollector().getEntityTableXref(superEntityName);
if (superEntityTableXref == null) {
throw new MappingException(String.format(Locale.ENGLISH, "Unable to locate entity table xref for entity [%s] super-type [%s]", entityDescriptor.getEntityName(), superEntityName), mappingDocument.getOrigin());
}
}
mappingDocument.getMetadataCollector().addEntityTableXref(entitySource.getEntityNamingSource().getEntityName(), logicalTableName, table, superEntityTableXref);
if (isTable) {
final TableSource tableSource = (TableSource) tableSpecSource;
table.setRowId(tableSource.getRowId());
if (StringHelper.isNotEmpty(tableSource.getCheckConstraint())) {
table.addCheckConstraint(tableSource.getCheckConstraint());
}
}
table.setComment(tableSpecSource.getComment());
mappingDocument.getMetadataCollector().addTableNameBinding(logicalTableName, table);
return table;
}
use of org.hibernate.boot.MappingException 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;
}
Aggregations