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

📄 mappings.java

📁 用Java实现的23个常用设计模式源代码
💻 JAVA
字号:
//$Id: Mappings.java,v 1.7.2.7 2003/11/24 03:25:29 oneovthafew Exp $package net.sf.hibernate.cfg;import java.util.List;import java.util.Map;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import net.sf.hibernate.MappingException;import net.sf.hibernate.cache.CacheConcurrencyStrategy;import net.sf.hibernate.mapping.Collection;import net.sf.hibernate.mapping.NamedSQLQuery;import net.sf.hibernate.mapping.PersistentClass;import net.sf.hibernate.mapping.Table;/** * A collection of mappings from classes and collections to * relational database tables. (Represents a single * <tt>&lt;hibernate-mapping&gt;</tt> element.) * @author Gavin King */public class Mappings {		private static final Log log = LogFactory.getLog(Mappings.class);		private final Map classes;	private final Map collections;	private final Map tables;	private final Map queries;	private final Map sqlqueries;	private final List secondPasses;	private final Map imports;	private String schemaName;	private String defaultCascade;	private boolean autoImport;	private final List propertyReferences;	private final Map caches;		Mappings(Map classes, Map collections, Map tables, Map queries, Map sqlqueries, Map imports, Map caches, List secondPasses, List propertyReferences) {		this.classes = classes;		this.collections = collections;		this.queries = queries;		this.sqlqueries = sqlqueries;		this.tables = tables;		this.imports = imports;		this.secondPasses = secondPasses;		this.propertyReferences = propertyReferences;		this.caches = caches;			}		public void addClass(PersistentClass persistentClass) throws MappingException {		Object old = classes.put( persistentClass.getMappedClass(), persistentClass );		if ( old!=null ) log.warn( "duplicate class mapping: " + persistentClass.getMappedClass().getName() );	}	public void addCollection(Collection collection) throws MappingException {		Object old = collections.put( collection.getRole(), collection );		if ( old!=null ) log.warn( "duplicate collection role: " + collection.getRole() );	}	public PersistentClass getClass(Class clazz) {		return (PersistentClass) classes.get(clazz);	}	public Collection getCollection(String role) {		return (Collection) collections.get(role);	}		public void addImport(String className, String rename) throws MappingException {		if ( imports.put(rename, className)!=null ) throw new MappingException("duplicate import: " + rename);	}		public Table addTable(String schema, String name) {				String key = schema != null ? schema + "." + name : name;		Table table = (Table) tables.get(key);				if (table == null) {			table = new Table();			table.setName(name);			table.setSchema(schema);			tables.put(key, table);		}				return table;	}		public Table getTable(String schema, String name) {		String key = schema != null ? schema + "." + name : name;		return (Table) tables.get(key);	}		public String getSchemaName() {		return schemaName;	}		public String getDefaultCascade() {		return defaultCascade;	}		/**	 * Sets the schemaName.	 * @param schemaName The schemaName to set	 */	public void setSchemaName(String schemaName) {		this.schemaName = schemaName;	}	/**	 * Sets the defaultCascade.	 * @param defaultCascade The defaultCascade to set	 */	public void setDefaultCascade(String defaultCascade) {		this.defaultCascade = defaultCascade;	}		public void addQuery(String name, String query) throws MappingException {		checkQueryExist(name);			queries.put(name, query);			}			public void addSQLQuery(String name, NamedSQLQuery query) throws MappingException {				checkQueryExist(name);			sqlqueries.put(name, query);	}	private void checkQueryExist(String name) throws MappingException {		if ( sqlqueries.containsKey(name) || queries.containsKey(name) ) {			throw new MappingException("Duplicate query named: " + name);			}	}		public String getQuery(String name) {		return (String) queries.get(name);	}		void addSecondPass(Binder.SecondPass sp) {		secondPasses.add(sp);	}	/**	 * Returns the autoImport.	 * @return boolean	 */	public boolean isAutoImport() {		return autoImport;	}	/**	 * Sets the autoImport.	 * @param autoImport The autoImport to set	 */	public void setAutoImport(boolean autoImport) {		this.autoImport = autoImport;	}		void addUniquePropertyReference(Class referencedClass, String propertyName) {		UniquePropertyReference upr = new UniquePropertyReference();		upr.referencedClass = referencedClass;		upr.propertyName = propertyName;		propertyReferences.add(upr);	}		static final class UniquePropertyReference {		Class referencedClass;		String propertyName;	}		public void addCache(String name, CacheConcurrencyStrategy cache) throws MappingException {		Object old = caches.put(name, cache);		if (old!=null) throw new MappingException("duplicate cache region");	}		}

⌨️ 快捷键说明

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