📄 mappings.java
字号:
} public void addResultSetMapping(ResultSetMappingDefinition sqlResultSetMapping) { final String name = sqlResultSetMapping.getName(); if ( resultSetMappings.containsKey(name) ) { throw new DuplicateMappingException("resultSet", name); } resultSetMappings.put(name, sqlResultSetMapping); } public ResultSetMappingDefinition getResultSetMapping(String name) { return (ResultSetMappingDefinition) resultSetMappings.get(name); } public NamedQueryDefinition getQuery(String name) { return (NamedQueryDefinition) queries.get(name); } public void addSecondPass(SecondPass sp) { addSecondPass(sp, false); } public void addSecondPass(SecondPass sp, boolean onTopOfTheQueue) { if (onTopOfTheQueue) { secondPasses.add(0, sp); } else { 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(String referencedClass, String propertyName) { PropertyReference upr = new PropertyReference(); upr.referencedClass = referencedClass; upr.propertyName = propertyName; upr.unique = true; propertyReferences.add(upr); } void addPropertyReference(String referencedClass, String propertyName) { PropertyReference upr = new PropertyReference(); upr.referencedClass = referencedClass; upr.propertyName = propertyName; propertyReferences.add(upr); } private String buildTableNameKey(String schema, String catalog, 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(); } static final class PropertyReference implements Serializable { String referencedClass; String propertyName; boolean unique; } /** * @return Returns the defaultPackage. */ public String getDefaultPackage() { return defaultPackage; } /** * @param defaultPackage The defaultPackage to set. */ public void setDefaultPackage(String defaultPackage) { this.defaultPackage = defaultPackage; } public NamingStrategy getNamingStrategy() { return namingStrategy; } public void addTypeDef(String typeName, String typeClass, Properties paramMap) { TypeDef def = new TypeDef(typeClass, paramMap); typeDefs.put(typeName, def); log.debug("Added " + typeName + " with class " + typeClass); } public TypeDef getTypeDef(String typeName) { return (TypeDef) typeDefs.get(typeName); } public Iterator iterateCollections() { return collections.values().iterator(); } public Iterator iterateTables() { return tables.values().iterator(); } public Map getFilterDefinitions() { return filterDefinitions; } public void addFilterDefinition(FilterDefinition definition) { filterDefinitions.put( definition.getFilterName(), definition ); } public FilterDefinition getFilterDefinition(String name) { return (FilterDefinition) filterDefinitions.get(name); } public boolean isDefaultLazy() { return defaultLazy; } public void setDefaultLazy(boolean defaultLazy) { this.defaultLazy = defaultLazy; } public void addToExtendsQueue(ExtendsQueueEntry entry) { extendsQueue.put( entry, null ); } public PersistentClass locatePersistentClassByEntityName(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 void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject) { auxiliaryDatabaseObjects.add( auxiliaryDatabaseObject ); } public void addTableBinding( String schema, String catalog, String logicalName, String physicalName, 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 void addColumnBinding(String logicalName, Column finalColumn, 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 + "'"); } } private String getLogicalTableName(String schema, String catalog, 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 String getPhysicalColumnName(String logicalName, 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 String getLogicalColumnName(String physicalName, 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; } public String getLogicalTableName(Table table) { return getLogicalTableName( table.getQuotedSchema(), table.getCatalog(), table.getQuotedName() ); } static public class ColumnNames implements Serializable { //<String, String> public Map logicalToPhysical = new HashMap(); //<String, String> public Map physicalToLogical = new HashMap(); public ColumnNames() { } } static public class TableDescription implements Serializable { public TableDescription(String logicalName, Table denormalizedSupertable) { this.logicalName = logicalName; this.denormalizedSupertable = denormalizedSupertable; } public String logicalName; public Table denormalizedSupertable; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -