package org.hibernate.metamodel.source.hbm;
import java.util.List;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.internal.jaxb.JaxbRoot;
import org.hibernate.internal.jaxb.Origin;
import org.hibernate.internal.jaxb.mapping.hbm.EntityElement;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbFetchProfileElement;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbHibernateMapping;
import org.hibernate.internal.util.ValueHolder;
import org.hibernate.metamodel.domain.Type;
import org.hibernate.metamodel.source.MappingDefaults;
import org.hibernate.metamodel.source.MetaAttributeContext;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.source.internal.OverriddenMappingDefaults;
import org.hibernate.service.ServiceRegistry;
public class MappingDocument {
private final JaxbRoot<JaxbHibernateMapping> hbmJaxbRoot;
private final LocalBindingContextImpl mappingLocalBindingContext;
public MappingDocument(JaxbRoot<JaxbHibernateMapping> hbmJaxbRoot, MetadataImplementor metadata) {
this.hbmJaxbRoot = hbmJaxbRoot;
this.mappingLocalBindingContext = new LocalBindingContextImpl( metadata );
}
public JaxbHibernateMapping getMappingRoot() {
return hbmJaxbRoot.getRoot();
}
public Origin getOrigin() {
return hbmJaxbRoot.getOrigin();
}
public JaxbRoot<JaxbHibernateMapping> getJaxbRoot() {
return hbmJaxbRoot;
}
public HbmBindingContext getMappingLocalBindingContext() {
return mappingLocalBindingContext;
}
private class LocalBindingContextImpl implements HbmBindingContext {
private final MetadataImplementor metadata;
private final MappingDefaults localMappingDefaults;
private final MetaAttributeContext metaAttributeContext;
private LocalBindingContextImpl(MetadataImplementor metadata) {
this.metadata = metadata;
this.localMappingDefaults = new OverriddenMappingDefaults(
metadata.getMappingDefaults(),
hbmJaxbRoot.getRoot().getPackage(),
hbmJaxbRoot.getRoot().getSchema(),
hbmJaxbRoot.getRoot().getCatalog(),
null,
null,
hbmJaxbRoot.getRoot().getDefaultCascade(),
hbmJaxbRoot.getRoot().getDefaultAccess(),
hbmJaxbRoot.getRoot().isDefaultLazy()
);
if ( hbmJaxbRoot.getRoot().getMeta() == null || hbmJaxbRoot.getRoot().getMeta().isEmpty() ) {
this.metaAttributeContext = new MetaAttributeContext( metadata.getGlobalMetaAttributeContext() );
}
else {
this.metaAttributeContext = Helper.extractMetaAttributeContext(
hbmJaxbRoot.getRoot().getMeta(),
true,
metadata.getGlobalMetaAttributeContext()
);
}
}
@Override
public ServiceRegistry getServiceRegistry() {
return metadata.getServiceRegistry();
}
@Override
public NamingStrategy getNamingStrategy() {
return metadata.getNamingStrategy();
}
@Override
public MappingDefaults getMappingDefaults() {
return localMappingDefaults;
}
@Override
public MetadataImplementor getMetadataImplementor() {
return metadata;
}
@Override
public <T> Class<T> locateClassByName(String name) {
return metadata.locateClassByName( name );
}
@Override
public Type makeJavaType(String className) {
return metadata.makeJavaType( className );
}
@Override
public ValueHolder<Class<?>> makeClassReference(String className) {
return metadata.makeClassReference( className );
}
@Override
public boolean isAutoImport() {
return hbmJaxbRoot.getRoot().isAutoImport();
}
@Override
public MetaAttributeContext getMetaAttributeContext() {
return metaAttributeContext;
}
@Override
public Origin getOrigin() {
return hbmJaxbRoot.getOrigin();
}
@Override
public String qualifyClassName(String unqualifiedName) {
return Helper.qualifyIfNeeded( unqualifiedName, getMappingDefaults().getPackageName() );
}
@Override
public String determineEntityName(EntityElement entityElement) {
return Helper.determineEntityName( entityElement, getMappingDefaults().getPackageName() );
}
@Override
public boolean isGloballyQuotedIdentifiers() {
return metadata.isGloballyQuotedIdentifiers();
}
@Override
public void processFetchProfiles(List<JaxbFetchProfileElement> fetchProfiles, String containingEntityName) {
}
}
}