FileDocCategorySizeDatePackage
Mappings.javaAPI DocHibernate 3.2.516973Tue Jan 16 16:22:50 GMT 2007org.hibernate.cfg

Mappings

public class Mappings extends Object implements Serializable
A collection of mappings from classes and collections to relational database tables. (Represents a single <hibernate-mapping> element.)
author
Gavin King

Fields Summary
private static final Log
log
protected final Map
classes
protected final Map
collections
protected final Map
tables
protected final Map
queries
protected final Map
sqlqueries
protected final Map
resultSetMappings
protected final Map
typeDefs
protected final List
secondPasses
protected final Map
imports
protected String
schemaName
protected String
catalogName
protected String
defaultCascade
protected String
defaultPackage
protected String
defaultAccess
protected boolean
autoImport
protected boolean
defaultLazy
protected final List
propertyReferences
protected final NamingStrategy
namingStrategy
protected final Map
filterDefinitions
protected final List
auxiliaryDatabaseObjects
protected final Map
extendsQueue
protected final Map
columnNameBindingPerTable
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
protected final Map
tableNameBinding
binding between logical table name and physical one (ie after the naming strategy has been applied)
Constructors Summary
Mappings(Map classes, Map collections, Map tables, Map queries, Map sqlqueries, Map sqlResultSetMappings, Map imports, List secondPasses, List propertyReferences, NamingStrategy namingStrategy, Map typeDefs, Map filterDefinitions, Map extendsQueue, List auxiliaryDatabaseObjects, Map tableNamebinding, Map columnNameBindingPerTable)



	
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
			  
//			final List extendsQueue,
			  
			  
			  
			  
			 
		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;
	
Methods Summary
public voidaddAuxiliaryDatabaseObject(org.hibernate.mapping.AuxiliaryDatabaseObject auxiliaryDatabaseObject)

		auxiliaryDatabaseObjects.add( auxiliaryDatabaseObject );
	
public voidaddClass(org.hibernate.mapping.PersistentClass persistentClass)

		Object old = classes.put( persistentClass.getEntityName(), persistentClass );
		if ( old!=null ) {
			throw new DuplicateMappingException( "class/entity", persistentClass.getEntityName() );
		}
	
public voidaddCollection(org.hibernate.mapping.Collection collection)

		Object old = collections.put( collection.getRole(), collection );
		if ( old!=null ) {
			throw new DuplicateMappingException( "collection role", collection.getRole() );
		}
	
public voidaddColumnBinding(java.lang.String logicalName, org.hibernate.mapping.Column finalColumn, org.hibernate.mapping.Table table)

		ColumnNames binding = (ColumnNames) columnNameBindingPerTable.get(table);
		if (binding == null) {
			binding = new ColumnNames();
			columnNameBindingPerTable.put(table, binding);
		}
		String oldFinalName = (String) binding.logicalToPhysical.put(
				logicalName.toLowerCase(),
				finalColumn.getQuotedName()
		);
		if ( oldFinalName != null &&
				! ( finalColumn.isQuoted() ?
						oldFinalName.equals( finalColumn.getQuotedName() ) :
						oldFinalName.equalsIgnoreCase( finalColumn.getQuotedName() ) ) ) {
			//TODO possibly relax that
			throw new MappingException("Same logical column name referenced by different physical ones: "
					+ table.getName() + "." + logicalName + " => '" + oldFinalName + "' and '" + finalColumn.getQuotedName() + "'" );
		}
		String oldLogicalName = (String) binding.physicalToLogical.put(
				finalColumn.getQuotedName(),
				logicalName
		);
		if ( oldLogicalName != null && ! oldLogicalName.equals( logicalName ) ) {
			//TODO possibly relax that
			throw new MappingException("Same physical column represented by different logical column names: "
					+ table.getName() + "." + finalColumn.getQuotedName() + " => '" + oldLogicalName + "' and '" + logicalName + "'");
		}
	
public org.hibernate.mapping.TableaddDenormalizedTable(java.lang.String schema, java.lang.String catalog, java.lang.String name, boolean isAbstract, java.lang.String subselect, org.hibernate.mapping.Table includedTable)

        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 voidaddFilterDefinition(org.hibernate.engine.FilterDefinition definition)

		filterDefinitions.put( definition.getFilterName(), definition );
	
public voidaddImport(java.lang.String className, java.lang.String rename)

		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
					);
			}
		}
	
voidaddPropertyReference(java.lang.String referencedClass, java.lang.String propertyName)

		PropertyReference upr = new PropertyReference();
		upr.referencedClass = referencedClass;
		upr.propertyName = propertyName;
		propertyReferences.add(upr);
	
public voidaddQuery(java.lang.String name, org.hibernate.engine.NamedQueryDefinition query)

		checkQueryExist(name);
		queries.put( name.intern(), query );
	
public voidaddResultSetMapping(org.hibernate.engine.ResultSetMappingDefinition sqlResultSetMapping)

		final String name = sqlResultSetMapping.getName();
		if ( resultSetMappings.containsKey(name) ) {
			throw new DuplicateMappingException("resultSet",  name);
		}
		resultSetMappings.put(name, sqlResultSetMapping);
	
public voidaddSQLQuery(java.lang.String name, org.hibernate.engine.NamedSQLQueryDefinition query)

		checkQueryExist(name);
		sqlqueries.put( name.intern(), query );
	
public voidaddSecondPass(SecondPass sp)

		addSecondPass(sp, false);
	
public voidaddSecondPass(SecondPass sp, boolean onTopOfTheQueue)

		if (onTopOfTheQueue) {
			secondPasses.add(0, sp);
		}
		else {
			secondPasses.add(sp);
		}
	
public org.hibernate.mapping.TableaddTable(java.lang.String schema, java.lang.String catalog, java.lang.String name, java.lang.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 voidaddTableBinding(java.lang.String schema, java.lang.String catalog, java.lang.String logicalName, java.lang.String physicalName, org.hibernate.mapping.Table denormalizedSuperTable)

		String key = buildTableNameKey( schema, catalog, physicalName );
		TableDescription tableDescription = new TableDescription(
				logicalName, denormalizedSuperTable
		);
		TableDescription oldDescriptor = (TableDescription) tableNameBinding.put( key, tableDescription );
		if ( oldDescriptor != null && ! oldDescriptor.logicalName.equals( logicalName ) ) {
			//TODO possibly relax that
			throw new MappingException("Same physical table name reference several logical table names: "
					+ physicalName + " => " + "'" + oldDescriptor.logicalName + "' and '" + logicalName + "'");
		}
	
public voidaddToExtendsQueue(ExtendsQueueEntry entry)

	    extendsQueue.put( entry, null );
    
public voidaddTypeDef(java.lang.String typeName, java.lang.String typeClass, java.util.Properties paramMap)

		TypeDef def = new TypeDef(typeClass, paramMap);
		typeDefs.put(typeName, def);
		log.debug("Added " + typeName + " with class " + typeClass);
	
voidaddUniquePropertyReference(java.lang.String referencedClass, java.lang.String propertyName)

		PropertyReference upr = new PropertyReference();
		upr.referencedClass = referencedClass;
		upr.propertyName = propertyName;
		upr.unique = true;
		propertyReferences.add(upr);
	
private java.lang.StringbuildTableNameKey(java.lang.String schema, java.lang.String catalog, java.lang.String finalName)

		StringBuffer keyBuilder = new StringBuffer();
		if (schema != null) keyBuilder.append( schema );
		keyBuilder.append( ".");
		if (catalog != null) keyBuilder.append( catalog );
		keyBuilder.append( ".");
		keyBuilder.append( finalName );
		return keyBuilder.toString();
	
private voidcheckQueryExist(java.lang.String name)

		if ( sqlqueries.containsKey(name) || queries.containsKey(name) ) {
			throw new DuplicateMappingException("query", name);
		}
	
public java.lang.StringgetCatalogName()

        return catalogName;
    
public org.hibernate.mapping.PersistentClassgetClass(java.lang.String className)

		return (PersistentClass) classes.get(className);
	
public org.hibernate.mapping.CollectiongetCollection(java.lang.String role)

		return (Collection) collections.get(role);
	
public java.lang.StringgetDefaultAccess()

		return defaultAccess;
	
public java.lang.StringgetDefaultCascade()

		return defaultCascade;
	
public java.lang.StringgetDefaultPackage()

return
Returns the defaultPackage.

		return defaultPackage;
	
public org.hibernate.engine.FilterDefinitiongetFilterDefinition(java.lang.String name)

		return (FilterDefinition) filterDefinitions.get(name);
	
public java.util.MapgetFilterDefinitions()

		return filterDefinitions;
	
public java.lang.StringgetLogicalColumnName(java.lang.String physicalName, org.hibernate.mapping.Table table)

		String logical = null;
		Table currentTable = table;
		TableDescription description = null;
		do {
			ColumnNames binding = (ColumnNames) columnNameBindingPerTable.get(currentTable);
			if (binding != null) {
				logical = (String) binding.physicalToLogical.get( physicalName );
			}
			String key = buildTableNameKey( currentTable.getSchema(), currentTable.getCatalog(), currentTable.getName() );
			description = (TableDescription) tableNameBinding.get(key);
			if (description != null) currentTable = description.denormalizedSupertable;
		}
		while (logical == null && currentTable != null && description != null);
		if (logical == null) {
			throw new MappingException( "Unable to find logical column name from physical name "
					+ physicalName + " in table " + table.getName() );
		}
		return logical;
	
private java.lang.StringgetLogicalTableName(java.lang.String schema, java.lang.String catalog, java.lang.String physicalName)

		String key = buildTableNameKey( schema, catalog, physicalName );
		TableDescription descriptor = (TableDescription) tableNameBinding.get( key );
		if (descriptor == null) {
			throw new MappingException( "Unable to find physical table: " + physicalName);
		}
		return descriptor.logicalName;
	
public java.lang.StringgetLogicalTableName(org.hibernate.mapping.Table table)

		return getLogicalTableName( table.getQuotedSchema(), table.getCatalog(), table.getQuotedName() );
	
public NamingStrategygetNamingStrategy()

		return namingStrategy;
	
public java.lang.StringgetPhysicalColumnName(java.lang.String logicalName, org.hibernate.mapping.Table table)

		logicalName = logicalName.toLowerCase();
		String finalName = null;
		Table currentTable = table;
		do {
			ColumnNames binding = (ColumnNames) columnNameBindingPerTable.get(currentTable);
			if (binding != null) {
				finalName = (String) binding.logicalToPhysical.get( logicalName );
			}
			String key = buildTableNameKey( currentTable.getSchema(), currentTable.getCatalog(), currentTable.getName() );
			TableDescription description = (TableDescription) tableNameBinding.get(key);
			if (description != null) currentTable = description.denormalizedSupertable;
		}
		while (finalName == null && currentTable != null);
		if (finalName == null) {
			throw new MappingException( "Unable to find column with logical name "
					+ logicalName + " in table " + table.getName() );
		}
		return finalName;
	
public org.hibernate.engine.NamedQueryDefinitiongetQuery(java.lang.String name)

		return (NamedQueryDefinition) queries.get(name);
	
public org.hibernate.engine.ResultSetMappingDefinitiongetResultSetMapping(java.lang.String name)

		return (ResultSetMappingDefinition) resultSetMappings.get(name);
	
public java.lang.StringgetSchemaName()

		return schemaName;
	
public org.hibernate.mapping.TablegetTable(java.lang.String schema, java.lang.String catalog, java.lang.String name)

        String key = Table.qualify(catalog, schema, name);
		return (Table) tables.get(key);
	
public org.hibernate.mapping.TypeDefgetTypeDef(java.lang.String typeName)

		return (TypeDef) typeDefs.get(typeName);
	
public booleanisAutoImport()
Returns the autoImport.

return
boolean

		return autoImport;
	
public booleanisDefaultLazy()

		return defaultLazy;
	
public java.util.IteratoriterateCollections()

        return collections.values().iterator();
    
public java.util.IteratoriterateTables()

    	return tables.values().iterator();
    
public org.hibernate.mapping.PersistentClasslocatePersistentClassByEntityName(java.lang.String entityName)

		PersistentClass persistentClass = ( PersistentClass ) classes.get( entityName );
		if ( persistentClass == null ) {
			String actualEntityName = ( String ) imports.get( entityName );
			if ( StringHelper.isNotEmpty( actualEntityName ) ) {
				persistentClass = ( PersistentClass ) classes.get( actualEntityName );
			}
		}
		return persistentClass;
	
public voidsetAutoImport(boolean autoImport)
Sets the autoImport.

param
autoImport The autoImport to set

		this.autoImport = autoImport;
	
public voidsetCatalogName(java.lang.String catalogName)
Sets the catalogName.

param
catalogName The catalogName to set

        this.catalogName = catalogName;
    
public voidsetDefaultAccess(java.lang.String defaultAccess)
sets the default access strategy

param
defaultAccess the default access strategy.

		this.defaultAccess = defaultAccess;
	
public voidsetDefaultCascade(java.lang.String defaultCascade)
Sets the defaultCascade.

param
defaultCascade The defaultCascade to set

		this.defaultCascade = defaultCascade;
	
public voidsetDefaultLazy(boolean defaultLazy)

		this.defaultLazy = defaultLazy;
	
public voidsetDefaultPackage(java.lang.String defaultPackage)

param
defaultPackage The defaultPackage to set.

		this.defaultPackage = defaultPackage;
	
public voidsetSchemaName(java.lang.String schemaName)
Sets the schemaName.

param
schemaName The schemaName to set

		this.schemaName = schemaName;