Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2009, Red Hat Middleware LLC 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 Middleware LLC.
   *
   * 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.ejb.metamodel;
 
 import java.util.Map;
 import java.util.Set;
 
Hibernate implementation of the JPA javax.persistence.metamodel.Metamodel contract.

Author(s):
Steve Ebersole
Emmanuel Bernard
 
 public class MetamodelImpl implements MetamodelSerializable {
 	private final Map<Class<?>,EntityTypeImpl<?>> entities;
 	private final Map<Class<?>, EmbeddableTypeImpl<?>> embeddables;
 	private final Map<Class<?>, MappedSuperclassType<?>> mappedSuperclassTypeMap;

    
Build the metamodel using the information from the collection of Hibernate org.hibernate.mapping.PersistentClass models as well as the Hibernate org.hibernate.SessionFactory.

Deprecated:
use buildMetamodel(java.util.Iterator,org.hibernate.engine.spi.SessionFactoryImplementor,boolean) instead
Parameters:
persistentClasses Iterator over the Hibernate (config-time) metamodel
sessionFactory The Hibernate session factory.
Returns:
The built metamodel
 
    	public static MetamodelImpl buildMetamodel(
    			Iterator<PersistentClasspersistentClasses,
    			SessionFactoryImplementor sessionFactory) {
         return buildMetamodel(persistentClassessessionFactoryfalse);
    	}

Build the metamodel using the information from the collection of Hibernate org.hibernate.mapping.PersistentClass models as well as the Hibernate org.hibernate.SessionFactory.

Parameters:
persistentClasses Iterator over the Hibernate (config-time) metamodel
sessionFactory The Hibernate session factory.
ignoreUnsupported ignore unsupported/unknown annotations (like @Any)
Returns:
The built metamodel
 
 	public static MetamodelImpl buildMetamodel(
 			Iterator<PersistentClasspersistentClasses,
 			SessionFactoryImplementor sessionFactory,
             boolean ignoreUnsupported) {
 		MetadataContext context = new MetadataContextsessionFactoryignoreUnsupported );
 		while ( persistentClasses.hasNext() ) {
 			PersistentClass pc = persistentClasses.next();
 			if ( pc.getMappedClass() != null ) {
 				locateOrBuildEntityTypepccontext );
 			}
 		}
 		context.wrapUp();
 		return new MetamodelImplcontext.getEntityTypeMap(), context.getEmbeddableTypeMap(), context.getMappedSuperclassTypeMap() );
 	}
 
 	private static EntityTypeImpl<?> locateOrBuildEntityType(PersistentClass persistentClassMetadataContext context) {
 		EntityTypeImpl<?> entityType = context.locateEntityTypepersistentClass );
 		if ( entityType == null ) {
 			entityType = buildEntityTypepersistentClasscontext );
 		}
 		return entityType;
 	}
 
	//TODO remove / reduce @SW scope
	@SuppressWarnings"unchecked" )
	private static EntityTypeImpl<?> buildEntityType(PersistentClass persistentClassMetadataContext context) {
		final Class javaType = persistentClass.getMappedClass();
		context.pushEntityWorkedOn(persistentClass);
		final MappedSuperclass superMappedSuperclass = persistentClass.getSuperMappedSuperclass();
		AbstractIdentifiableType<?> superType = superMappedSuperclass == null
null
locateOrBuildMappedsuperclassTypesuperMappedSuperclasscontext );
		//no mappedSuperclass, check for a super entity
		if (superType == null) {
			final PersistentClass superPersistentClass = persistentClass.getSuperclass();
			superType = superPersistentClass == null
null
locateOrBuildEntityTypesuperPersistentClasscontext );
		}
		EntityTypeImpl entityType = new EntityTypeImpl(
				javaType,
				superType,
				persistentClass.getJpaEntityName(),
				persistentClass.hasIdentifierProperty(),
				persistentClass.isVersioned()
		);
		context.registerEntityTypepersistentClassentityType );
		context.popEntityWorkedOn(persistentClass);
		return entityType;
	}
			MappedSuperclass mappedSuperclassMetadataContext context) {
		MappedSuperclassTypeImpl<?> mappedSuperclassType = context.locateMappedSuperclassTypemappedSuperclass );
		if ( mappedSuperclassType == null ) {
			mappedSuperclassType = buildMappedSuperclassType(mappedSuperclasscontext);
		}
		return mappedSuperclassType;
	}
	//TODO remove / reduce @SW scope
	@SuppressWarnings"unchecked" )
																		 MetadataContext context) {
		final MappedSuperclass superMappedSuperclass = mappedSuperclass.getSuperMappedSuperclass();
		AbstractIdentifiableType<?> superType = superMappedSuperclass == null
null
locateOrBuildMappedsuperclassTypesuperMappedSuperclasscontext );
		//no mappedSuperclass, check for a super entity
		if (superType == null) {
			final PersistentClass superPersistentClass = mappedSuperclass.getSuperPersistentClass();
			superType = superPersistentClass == null
null
locateOrBuildEntityTypesuperPersistentClasscontext );
		}
		final Class javaType = mappedSuperclass.getMappedClass();
		MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl(
				javaType,
				superType,
				mappedSuperclass.hasIdentifierProperty(),
				mappedSuperclass.isVersioned()
		);
		context.registerMappedSuperclassTypemappedSuperclassmappedSuperclassType );
		return mappedSuperclassType;
	}

Instantiate the metamodel.

Parameters:
entities The entity mappings.
embeddables The embeddable (component) mappings.
mappedSuperclassTypeMap The javax.persistence.MappedSuperclass mappings
	private MetamodelImpl(
			Map<Class<?>, EntityTypeImpl<?>> entities,
			Map<Class<?>, EmbeddableTypeImpl<?>> embeddables,
			Map<Class<?>, MappedSuperclassType<?>> mappedSuperclassTypeMap) {
		this. = entities;
		this. = embeddables;
		this. = mappedSuperclassTypeMap;
	}
	@SuppressWarnings({ "unchecked" })
	public <X> EntityType<X> entity(Class<X> cls) {
		final EntityType<?> entityType = .getcls );
		if ( entityType == null ) {
			throw new IllegalArgumentException"Not an entity: " + cls );
		}
		return (EntityType<X>) entityType;
	}
	@SuppressWarnings({ "unchecked" })
	public <X> ManagedType<X> managedType(Class<X> cls) {
		ManagedType<?> type = .getcls );
		if ( type == null ) {
			type = .getcls );
		}
		if ( type == null ) {
			type = .getcls );
		}
		if ( type == null ) {
			throw new IllegalArgumentException"Not an managed type: " + cls );
		}
		return (ManagedType<X>) type;
	}
	@SuppressWarnings({ "unchecked" })
	public <X> EmbeddableType<X> embeddable(Class<X> cls) {
		final EmbeddableType<?> embeddableType = .getcls );
		if ( embeddableType == null ) {
			throw new IllegalArgumentException"Not an embeddable: " + cls );
		}
		return (EmbeddableType<X>) embeddableType;
	}
		final int setSize = CollectionHelper.determineProperSizing(
		);
		final Set<ManagedType<?>> managedTypes = new HashSet<ManagedType<?>>( setSize );
		managedTypes.addAll.values() );
		managedTypes.addAll.values() );
		return managedTypes;
	}
	public Set<EntityType<?>> getEntities() {
		return new HashSet<EntityType<?>>( .values() );
	}
		return new HashSet<EmbeddableType<?>>( .values() );
	}
New to GrepCode? Check out our FAQ X