⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 annotationbinder.java

📁 hibernate3.2.6源码和jar包
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
//$Id: AnnotationBinder.java 14390 2008-03-04 22:42:53Z epbernard $package org.hibernate.cfg;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.EnumSet;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Properties;import java.util.Set;import javax.persistence.Basic;import javax.persistence.Column;import javax.persistence.DiscriminatorType;import javax.persistence.DiscriminatorValue;import javax.persistence.Embeddable;import javax.persistence.Embedded;import javax.persistence.EmbeddedId;import javax.persistence.Entity;import javax.persistence.FetchType;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.IdClass;import javax.persistence.InheritanceType;import javax.persistence.JoinColumn;import javax.persistence.JoinColumns;import javax.persistence.JoinTable;import javax.persistence.ManyToMany;import javax.persistence.ManyToOne;import javax.persistence.MapKey;import javax.persistence.MappedSuperclass;import javax.persistence.NamedNativeQueries;import javax.persistence.NamedNativeQuery;import javax.persistence.NamedQueries;import javax.persistence.NamedQuery;import javax.persistence.OneToMany;import javax.persistence.OneToOne;import javax.persistence.PrimaryKeyJoinColumn;import javax.persistence.PrimaryKeyJoinColumns;import javax.persistence.SequenceGenerator;import javax.persistence.SqlResultSetMapping;import javax.persistence.SqlResultSetMappings;import javax.persistence.Table;import javax.persistence.TableGenerator;import javax.persistence.Transient;import javax.persistence.Version;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.hibernate.AnnotationException;import org.hibernate.AssertionFailure;import org.hibernate.EntityMode;import org.hibernate.FetchMode;import org.hibernate.MappingException;import org.hibernate.annotations.AccessType;import org.hibernate.annotations.BatchSize;import org.hibernate.annotations.Cache;import org.hibernate.annotations.Cascade;import org.hibernate.annotations.CascadeType;import org.hibernate.annotations.Check;import org.hibernate.annotations.CollectionId;import org.hibernate.annotations.CollectionOfElements;import org.hibernate.annotations.Columns;import org.hibernate.annotations.Fetch;import org.hibernate.annotations.Filter;import org.hibernate.annotations.FilterDef;import org.hibernate.annotations.FilterDefs;import org.hibernate.annotations.Filters;import org.hibernate.annotations.ForeignKey;import org.hibernate.annotations.Formula;import org.hibernate.annotations.GenericGenerator;import org.hibernate.annotations.Index;import org.hibernate.annotations.LazyToOne;import org.hibernate.annotations.LazyToOneOption;import org.hibernate.annotations.ManyToAny;import org.hibernate.annotations.MapKeyManyToMany;import org.hibernate.annotations.NaturalId;import org.hibernate.annotations.NotFound;import org.hibernate.annotations.NotFoundAction;import org.hibernate.annotations.OnDelete;import org.hibernate.annotations.OnDeleteAction;import org.hibernate.annotations.OrderBy;import org.hibernate.annotations.ParamDef;import org.hibernate.annotations.Parameter;import org.hibernate.annotations.Parent;import org.hibernate.annotations.Proxy;import org.hibernate.annotations.Sort;import org.hibernate.annotations.Target;import org.hibernate.annotations.Tuplizer;import org.hibernate.annotations.Tuplizers;import org.hibernate.annotations.Type;import org.hibernate.annotations.TypeDef;import org.hibernate.annotations.TypeDefs;import org.hibernate.annotations.Where;import org.hibernate.annotations.GenericGenerators;import org.hibernate.annotations.common.reflection.ReflectionManager;import org.hibernate.annotations.common.reflection.XAnnotatedElement;import org.hibernate.annotations.common.reflection.XClass;import org.hibernate.annotations.common.reflection.XPackage;import org.hibernate.annotations.common.reflection.XProperty;import org.hibernate.cfg.annotations.CollectionBinder;import org.hibernate.cfg.annotations.EntityBinder;import org.hibernate.cfg.annotations.Nullability;import org.hibernate.cfg.annotations.PropertyBinder;import org.hibernate.cfg.annotations.QueryBinder;import org.hibernate.cfg.annotations.SimpleValueBinder;import org.hibernate.cfg.annotations.TableBinder;import org.hibernate.engine.FilterDefinition;import org.hibernate.engine.Versioning;import org.hibernate.id.MultipleHiLoPerTableGenerator;import org.hibernate.id.PersistentIdentifierGenerator;import org.hibernate.id.SequenceHiLoGenerator;import org.hibernate.id.TableHiLoGenerator;import org.hibernate.mapping.Any;import org.hibernate.mapping.Component;import org.hibernate.mapping.DependantValue;import org.hibernate.mapping.IdGenerator;import org.hibernate.mapping.Join;import org.hibernate.mapping.JoinedSubclass;import org.hibernate.mapping.KeyValue;import org.hibernate.mapping.PersistentClass;import org.hibernate.mapping.Property;import org.hibernate.mapping.RootClass;import org.hibernate.mapping.SimpleValue;import org.hibernate.mapping.SingleTableSubclass;import org.hibernate.mapping.Subclass;import org.hibernate.mapping.ToOne;import org.hibernate.mapping.UnionSubclass;import org.hibernate.persister.entity.JoinedSubclassEntityPersister;import org.hibernate.persister.entity.SingleTableEntityPersister;import org.hibernate.persister.entity.UnionSubclassEntityPersister;import org.hibernate.type.TypeFactory;import org.hibernate.util.StringHelper;/** * JSR 175 annotation binder * Will read the annotation from classes, apply the * principles of the EJB3 spec and produces the Hibernate * configuration-time metamodel (the classes in the <tt>mapping</tt> * package) * * @author Emmanuel Bernard */public final class AnnotationBinder {	/*	 * Some design description	 * I tried to remove any link to annotation except from the 2 first level of	 * method call.	 * It'll enable to:	 *   - facilitate annotation overriding	 *   - mutualize one day xml and annotation binder (probably a dream though)	 *   - split this huge class in smaller mapping oriented classes	 *	 * bindSomething usually create the mapping container and is accessed by one of the 2 first level method	 * makeSomething usually create the mapping container and is accessed by bindSomething[else]	 * fillSomething take the container into parameter and fill it.	 *	 *	 */	private AnnotationBinder() {	}	private static final Log log = LogFactory.getLog( AnnotationBinder.class );	public static void bindDefaults(ExtendedMappings mappings) {		Map defaults = mappings.getReflectionManager().getDefaults();		{			List<SequenceGenerator> anns = (List<SequenceGenerator>) defaults.get( SequenceGenerator.class );			if ( anns != null ) {				for (SequenceGenerator ann : anns) {					IdGenerator idGen = buildIdGenerator( ann, mappings );					if ( idGen != null ) mappings.addDefaultGenerator( idGen );				}			}		}		{			List<TableGenerator> anns = (List<TableGenerator>) defaults.get( TableGenerator.class );			if ( anns != null ) {				for (TableGenerator ann : anns) {					IdGenerator idGen = buildIdGenerator( ann, mappings );					if ( idGen != null ) mappings.addDefaultGenerator( idGen );				}			}		}		{			List<NamedQuery> anns = (List<NamedQuery>) defaults.get( NamedQuery.class );			if ( anns != null ) {				for (NamedQuery ann : anns) {					QueryBinder.bindQuery( ann, mappings, true );				}			}		}		{			List<NamedNativeQuery> anns = (List<NamedNativeQuery>) defaults.get( NamedNativeQuery.class );			if ( anns != null ) {				for (NamedNativeQuery ann : anns) {					QueryBinder.bindNativeQuery( ann, mappings, true );				}			}		}		{			List<SqlResultSetMapping> anns = (List<SqlResultSetMapping>) defaults.get( SqlResultSetMapping.class );			if ( anns != null ) {				for (SqlResultSetMapping ann : anns) {					QueryBinder.bindSqlResultsetMapping( ann, mappings, true );				}			}		}	}	public static void bindPackage(String packageName, ExtendedMappings mappings) {		XPackage pckg = null;		try {			pckg = mappings.getReflectionManager().packageForName( packageName );		}		catch (ClassNotFoundException cnf) {			log.warn( "Package not found or wo package-info.java: " + packageName );			return;		}		if ( pckg.isAnnotationPresent( SequenceGenerator.class ) ) {			SequenceGenerator ann = pckg.getAnnotation( SequenceGenerator.class );			IdGenerator idGen = buildIdGenerator( ann, mappings );			mappings.addGenerator( idGen );			log.debug( "Add sequence generator with name: " + idGen.getName() );		}		if ( pckg.isAnnotationPresent( TableGenerator.class ) ) {			TableGenerator ann = pckg.getAnnotation( TableGenerator.class );			IdGenerator idGen = buildIdGenerator( ann, mappings );			mappings.addGenerator( idGen );		}		bindGenericGenerators(pckg, mappings);		bindQueries( pckg, mappings );		bindFilterDefs( pckg, mappings );		bindTypeDefs( pckg, mappings );		BinderHelper.bindAnyMetaDefs( pckg, mappings );	}	private static void bindGenericGenerators(XAnnotatedElement annotatedElement, ExtendedMappings mappings) {		GenericGenerator defAnn = annotatedElement.getAnnotation( GenericGenerator.class );		GenericGenerators defsAnn = annotatedElement.getAnnotation( GenericGenerators.class );		if ( defAnn != null ) {			bindGenericGenerator( defAnn, mappings );		}		if ( defsAnn != null ) {			for (GenericGenerator def : defsAnn.value() ) {				bindGenericGenerator( def, mappings );			}		}	}	private static void bindGenericGenerator(GenericGenerator def, ExtendedMappings mappings) {		IdGenerator idGen = buildIdGenerator( def, mappings );		mappings.addGenerator( idGen );	}	private static void bindQueries(XAnnotatedElement annotatedElement, ExtendedMappings mappings) {		{			SqlResultSetMapping ann = annotatedElement.getAnnotation( SqlResultSetMapping.class );			QueryBinder.bindSqlResultsetMapping( ann, mappings, false );		}		{			SqlResultSetMappings ann = annotatedElement.getAnnotation( SqlResultSetMappings.class );			if ( ann != null ) {				for (SqlResultSetMapping current : ann.value()) {					QueryBinder.bindSqlResultsetMapping( current, mappings, false );				}			}		}		{			NamedQuery ann = annotatedElement.getAnnotation( NamedQuery.class );			QueryBinder.bindQuery( ann, mappings, false );		}		{			org.hibernate.annotations.NamedQuery ann = annotatedElement.getAnnotation(					org.hibernate.annotations.NamedQuery.class			);			QueryBinder.bindQuery( ann, mappings );		}		{			NamedQueries ann = annotatedElement.getAnnotation( NamedQueries.class );			QueryBinder.bindQueries( ann, mappings, false );		}		{			org.hibernate.annotations.NamedQueries ann = annotatedElement.getAnnotation(					org.hibernate.annotations.NamedQueries.class			);			QueryBinder.bindQueries( ann, mappings );		}		{			NamedNativeQuery ann = annotatedElement.getAnnotation( NamedNativeQuery.class );			QueryBinder.bindNativeQuery( ann, mappings, false );		}		{			org.hibernate.annotations.NamedNativeQuery ann = annotatedElement.getAnnotation(					org.hibernate.annotations.NamedNativeQuery.class			);			QueryBinder.bindNativeQuery( ann, mappings );		}		{			NamedNativeQueries ann = annotatedElement.getAnnotation( NamedNativeQueries.class );			QueryBinder.bindNativeQueries( ann, mappings, false );		}		{			org.hibernate.annotations.NamedNativeQueries ann = annotatedElement.getAnnotation(					org.hibernate.annotations.NamedNativeQueries.class			);			QueryBinder.bindNativeQueries( ann, mappings );		}	}	private static IdGenerator buildIdGenerator(java.lang.annotation.Annotation ann, Mappings mappings) {		IdGenerator idGen = new IdGenerator();		if ( mappings.getSchemaName() != null ) {			idGen.addParam( PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName() );		}		if ( mappings.getCatalogName() != null ) {			idGen.addParam( PersistentIdentifierGenerator.CATALOG, mappings.getCatalogName() );		}		if ( ann == null ) {			idGen = null;		}		else if ( ann instanceof TableGenerator ) {			TableGenerator tabGen = (TableGenerator) ann;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -