alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (MappingDocument.java)

This example Hibernate source code file (MappingDocument.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

hbmbindingcontext, jaxbroot, localbindingcontextimpl, localbindingcontextimpl, mappingdefaults, mappingdocument, metaattributecontext, metaattributecontext, metadataimplementor, origin, override, override, string, string, util

The Hibernate MappingDocument.java source code

/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  All third-party contributions are
 * distributed under license by Red Hat Inc.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.hibernate.metamodel.source.hbm;

import java.util.List;

import org.hibernate.cfg.NamingStrategy;
import org.hibernate.internal.util.Value;
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.Origin;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.EntityElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLFetchProfileElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLHibernateMapping;
import org.hibernate.metamodel.source.internal.JaxbRoot;
import org.hibernate.metamodel.source.internal.OverriddenMappingDefaults;
import org.hibernate.service.ServiceRegistry;

/**
 * Aggregates together information about a mapping document.
 * 
 * @author Steve Ebersole
 */
public class MappingDocument {
	private final JaxbRoot<XMLHibernateMapping> hbmJaxbRoot;
	private final LocalBindingContextImpl mappingLocalBindingContext;

	public MappingDocument(JaxbRoot<XMLHibernateMapping> hbmJaxbRoot, MetadataImplementor metadata) {
		this.hbmJaxbRoot = hbmJaxbRoot;
		this.mappingLocalBindingContext = new LocalBindingContextImpl( metadata );

	}

	public XMLHibernateMapping getMappingRoot() {
		return hbmJaxbRoot.getRoot();
	}

	public Origin getOrigin() {
		return hbmJaxbRoot.getOrigin();
	}

	public JaxbRoot<XMLHibernateMapping> 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 locateClassByName(String name) {
			return metadata.locateClassByName( name );
		}

		@Override
		public Type makeJavaType(String className) {
			return metadata.makeJavaType( className );
		}

		@Override
		public Value<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<XMLFetchProfileElement> fetchProfiles, String containingEntityName) {
			// todo : this really needs to not be part of the context
		}
	}
}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate MappingDocument.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.