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

📄 mappings.java

📁 hibernate-3.1.3-all-src.zip 面向对象的访问数据库工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//$Id: Mappings.java 9155 2006-01-27 16:46:34Z steveebersole $
package org.hibernate.cfg;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.DuplicateMappingException;
import org.hibernate.MappingException;
import org.hibernate.engine.FilterDefinition;
import org.hibernate.engine.NamedQueryDefinition;
import org.hibernate.engine.NamedSQLQueryDefinition;
import org.hibernate.engine.ResultSetMappingDefinition;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.DenormalizedTable;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.TypeDef;
import org.hibernate.mapping.AuxiliaryDatabaseObject;
import org.hibernate.mapping.Column;
import org.hibernate.util.StringHelper;

/**
 * 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 implements Serializable {

	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 Map resultSetMappings;
	private final Map typeDefs;
	private final List secondPasses;
	private final Map imports;
	private String schemaName;
    private String catalogName;
	private String defaultCascade;
	private String defaultPackage;
	private String defaultAccess;
	private boolean autoImport;
	private boolean defaultLazy;
	private final List propertyReferences;
	private final NamingStrategy namingStrategy;
	private final Map filterDefinitions;
	private final List auxiliaryDatabaseObjects;

	private final Map extendsQueue;
//	private final List extendsQueue;

	/**
	 * binding table between the logical column name and the name out of the naming strategy
	 * for each table.
	 * According that when the column name is not set, the property name is considered as such
	 * This means that while theorically possible through the naming strategy contract, it is
	 * forbidden to have 2 real columns having the same logical name
	 * <Table, ColumnNames >
	 */
	protected final Map columnNameBindingPerTable;
	/**
	 * binding between logical table name and physical one (ie after the naming strategy has been applied)
	 * <String, TableDescription>
	 */
	protected final Map tableNameBinding;


	Mappings(
			final Map classes,
			final Map collections,
			final Map tables,
			final Map queries,
			final Map sqlqueries,
			final Map sqlResultSetMappings,
			final Map imports,
			final List secondPasses,
			final List propertyReferences,
			final NamingStrategy namingStrategy,
			final Map typeDefs,
			final Map filterDefinitions,
//			final List extendsQueue,
			final Map extendsQueue,
			final List auxiliaryDatabaseObjects,
			final Map tableNamebinding,
			final Map columnNameBindingPerTable
			) {
		this.classes = classes;
		this.collections = collections;
		this.queries = queries;
		this.sqlqueries = sqlqueries;
		this.resultSetMappings = sqlResultSetMappings;
		this.tables = tables;
		this.imports = imports;
		this.secondPasses = secondPasses;
		this.propertyReferences = propertyReferences;
		this.namingStrategy = namingStrategy;
		this.typeDefs = typeDefs;
		this.filterDefinitions = filterDefinitions;
		this.extendsQueue = extendsQueue;
		this.auxiliaryDatabaseObjects = auxiliaryDatabaseObjects;
		this.tableNameBinding = tableNamebinding;
		this.columnNameBindingPerTable = columnNameBindingPerTable;
	}

	public void addClass(PersistentClass persistentClass) throws MappingException {
		Object old = classes.put( persistentClass.getEntityName(), persistentClass );
		if ( old!=null ) {
			throw new DuplicateMappingException( "class/entity", persistentClass.getEntityName() );
		}
	}
	public void addCollection(Collection collection) throws MappingException {
		Object old = collections.put( collection.getRole(), collection );
		if ( old!=null ) {
			throw new DuplicateMappingException( "collection role", collection.getRole() );
		}
	}
	public PersistentClass getClass(String className) {
		return (PersistentClass) classes.get(className);
	}
	public Collection getCollection(String role) {
		return (Collection) collections.get(role);
	}

	public void addImport(String className, String rename) throws MappingException {
		String existing = (String) imports.put(rename, className);
		if ( existing!=null ) {
			if ( existing.equals(className) ) {
				log.info( "duplicate import: " + className + "->" + rename );
			}
			else {
				throw new DuplicateMappingException(
						"duplicate import: " + rename + 
						" refers to both " + className + 
						" and " + existing + 
						" (try using auto-import=\"false\")",
						"import",
						rename
					);
			}
		}
	}

	public Table addTable(String schema, 
			String catalog, 
			String name,
			String subselect,
			boolean isAbstract
	) {
        String key = subselect==null ?
			Table.qualify(catalog, schema, name) :
			subselect;
		Table table = (Table) tables.get(key);

		if (table == null) {
			table = new Table();
			table.setAbstract(isAbstract);
			table.setName(name);
			table.setSchema(schema);
			table.setCatalog(catalog);
			table.setSubselect(subselect);
			tables.put(key, table);
		}
		else {
			if (!isAbstract) table.setAbstract(false);
		}

		return table;
	}

	public Table addDenormalizedTable(
			String schema, 
			String catalog, 
			String name,
			boolean isAbstract, 
			String subselect,
			Table includedTable)
	throws MappingException {
        String key = subselect==null ?
        		Table.qualify(catalog, schema, name) :
        		subselect;
		if ( tables.containsKey(key) ) {
			throw new DuplicateMappingException("table", name);
		}
		
		Table table = new DenormalizedTable(includedTable);
		table.setAbstract(isAbstract);
		table.setName(name);
		table.setSchema(schema);
		table.setCatalog(catalog);
		table.setSubselect(subselect);
		tables.put(key, table);
		return table;
	}

	public Table getTable(String schema, String catalog, String name) {
        String key = Table.qualify(catalog, schema, name);
		return (Table) tables.get(key);
	}

	public String getSchemaName() {
		return schemaName;
	}

    public String getCatalogName() {
        return catalogName;
    }

	public String getDefaultCascade() {
		return defaultCascade;
	}

	/**
	 * Sets the schemaName.
	 * @param schemaName The schemaName to set
	 */
	public void setSchemaName(String schemaName) {
		this.schemaName = schemaName;
	}

    /**
     * Sets the catalogName.
     * @param catalogName The catalogName to set
     */
    public void setCatalogName(String catalogName) {
        this.catalogName = catalogName;
    }

	/**
	 * Sets the defaultCascade.
	 * @param defaultCascade The defaultCascade to set
	 */
	public void setDefaultCascade(String defaultCascade) {
		this.defaultCascade = defaultCascade;
	}

	/**
	 * sets the default access strategy
	 * @param defaultAccess the default access strategy.
	 */
	public void setDefaultAccess(String defaultAccess) {
		this.defaultAccess = defaultAccess;
	}

	public String getDefaultAccess() {
		return defaultAccess;
	}

	public void addQuery(String name, NamedQueryDefinition query) throws MappingException {
		checkQueryExist(name);
		queries.put( name.intern(), query );
	}

	public void addSQLQuery(String name, NamedSQLQueryDefinition query) throws MappingException {
		checkQueryExist(name);
		sqlqueries.put( name.intern(), query );
	}

	private void checkQueryExist(String name) throws MappingException {
		if ( sqlqueries.containsKey(name) || queries.containsKey(name) ) {
			throw new DuplicateMappingException("query", name);
		}

⌨️ 快捷键说明

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