@SuppressWarnings("unchecked") private void addTableName(MetadataImplementor metadata, ArrayList<String> tables, Table table, String aSchemaName) { String name = (null == aSchemaName) ? "" : aSchemaName + "."; name += table.getName(); if (tables.contains(name)) { return; } final Collection<Table> ts = metadata.collectTableMappings(); for (Table t : ts) { if (t.equals(table)) { continue; } Iterator<ForeignKey> relationships = t.getForeignKeyIterator(); while (relationships.hasNext()) { ForeignKey fk = relationships.next(); if (fk.getReferencedTable().equals(table)) { addTableName(metadata, tables, fk.getTable(), aSchemaName); } } } tables.add(name); }
private Set<String> getIndicesExcludingPK(Table table) { Set<String> res = new HashSet<>(); try (ResultSet indices = dialect.getMetadata().getIndexInfo(table.getCatalog(), table.getSchema(), table.getName(), false, false)) { while (indices.next()) { if (!indices.getString("INDEX_NAME").equalsIgnoreCase("PRIMARY_KEY")) res.add(indices.getString("INDEX_NAME")); } } catch (SQLException e) { // ignore at this point, just return an empty set } return res; }
@Override public void configure(Type type, Properties params, Dialect dialect) throws MappingException { ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER ); sequenceName = normalizer.normalizeIdentifierQuoting( ConfigurationHelper.getString( SEQUENCE, params, "hibernate_sequence" ) ); parameters = params.getProperty( PARAMETERS ); if ( sequenceName.indexOf( '.' ) < 0 ) { final String schemaName = normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) ); final String catalogName = normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) ); sequenceName = Table.qualify( dialect.quote( catalogName ), dialect.quote( schemaName ), dialect.quote( sequenceName ) ); } else { // if already qualified there is not much we can do in a portable manner so we pass it // through and assume the user has set up the name correctly. } this.identifierType = type; sql = dialect.getSequenceNextValString( sequenceName ); }
@SuppressWarnings("unchecked") private boolean hasUniqueIndex(Index index, Table table) { HashSet<Column> indexCols = new HashSet<Column>(); Iterator<Column> icolIter = index.getColumnIterator(); while( icolIter.hasNext() ) { Column col = icolIter.next(); indexCols.add(col); if( index.getColumnSpan() == 1 && table.getColumn(col).isUnique() ) { return true; } } Iterator<UniqueKey> iter = table.getUniqueKeyIterator(); while( iter.hasNext() ) { UniqueKey uk = iter.next(); if( uk.getColumnSpan() == indexCols.size() && indexCols.containsAll(uk.getColumns()) ) { return true; } } return false; }
/** * @param tableName * @param columnName * @param changeNotNull * @param nullable Pass in null to use the annotation on the column. This is * not always possible (see Redmine #3329). * @param changeType * @return */ public List<String> getModifyColumnSQL(String tableName, String columnName, boolean changeNotNull, boolean changeType) { List<String> sqlStrings = new ArrayList<String>(); Table table = findTable(tableName); Column column = table.getColumn(new Column(columnName)); StringBuffer alter = new StringBuffer("alter table ") .append(table.getQualifiedName(dialect, defaultCatalog, defaultSchema)).append(' ') .append(extDialect.getModifyColumnSql(mapping, column, changeNotNull, changeType)); sqlStrings.add(alter.toString()); return sqlStrings; }
public List<String> getDropColumnSQL(String tableName, String... columns) { List<String> sqlStrings = new ArrayList<String>(); Table table = findTable(tableName); for( String columnName : columns ) { Column column = table.getColumn(new Column(columnName)); if( column == null ) { throw new RuntimeException("Could not find column " + columnName + " on table " + tableName); } sqlStrings.add(extDialect.getDropColumnSql(table.getQualifiedName(dialect, defaultCatalog, defaultSchema), column)); } return sqlStrings; }
public List<String> getAddNotNullSQL(String tableName, String... columns) { List<String> sqlStrings = new ArrayList<String>(); Table table = findTable(tableName); for( String columnName : columns ) { Column column = table.getColumn(new Column(columnName)); StringBuffer alter = new StringBuffer("alter table ") .append(table.getQualifiedName(dialect, defaultCatalog, defaultSchema)).append(' ') .append(extDialect.getAddNotNullSql(mapping, column)); sqlStrings.add(alter.toString()); } return sqlStrings; }
@SuppressWarnings("unchecked") public Collection<? extends String> getAddIndexesIfRequired(Session session, String tableName, String... indexes) { final Table table = findTable(tableName); List<String> sqlStrings = new ArrayList<String>(); Map<Set<String>, String> revIndexMap = getExistingIndexes(table, session); Set<String> indexSet = new HashSet<String>(Arrays.asList(indexes)); Iterator<Index> indexIterator = table.getIndexIterator(); while( indexIterator.hasNext() ) { Index index = indexIterator.next(); if( !indexSet.remove(index.getName()) ) { continue; } processIndex(table, index, revIndexMap, sqlStrings); } if( !indexSet.isEmpty() ) { throw new RuntimeException("Failed to find indexes:" + indexSet + " on table: " + tableName); } return sqlStrings; }
public Collection<? extends String> getAddIndexesRawIfRequired(Session session, String tableName, String[]... indexes) { List<String> sqlStrings = new ArrayList<String>(); final Table table = findTable(tableName); Map<Set<String>, String> revIndexMap = getExistingIndexes(table, session); for( String[] index : indexes ) { Index indexObj = new Index(); indexObj.setTable(table); indexObj.setName(index[0]); for( int i = 1; i < index.length; i++ ) { Column col = new Column(index[i]); indexObj.addColumn(col); } processIndex(table, indexObj, revIndexMap, sqlStrings); } return sqlStrings; }
public Collection<? extends String> getAddIndexesRaw(String tableName, String[]... indexes) { List<String> sqlStrings = new ArrayList<String>(); final Table table = findTable(tableName); for( String[] index : indexes ) { Index indexObj = new Index(); indexObj.setTable(table); indexObj.setName(index[0]); for( int i = 1; i < index.length; i++ ) { Column col = new Column(index[i]); indexObj.addColumn(col); } sqlStrings.add(indexObj.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema)); } return sqlStrings; }
@SuppressWarnings("unchecked") private void processIndex(Table table, Index index, Map<Set<String>, String> revIndexMap, List<String> sqlStrings) { Iterator<Column> colIter = index.getColumnIterator(); Set<String> indexCols = new HashSet<String>(); while( colIter.hasNext() ) { Column col = colIter.next(); indexCols.add(col.getName().toLowerCase()); } String existingIndex = revIndexMap.get(indexCols); if( existingIndex != null ) { if( existingIndex.equalsIgnoreCase(index.getName()) ) { return; } else { sqlStrings.add(extDialect.getDropIndexSql(table.getName(), '`' + existingIndex + '`')); } } sqlStrings.add(index.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema)); }
/** * Determine the name of the sequence (or table if this resolves to a physical table) * to use. * <p/> * Called during {@link #configure configuration}. * * @param params The params supplied in the generator config (plus some standard useful extras). * @param dialect The dialect in effect * @return The sequence name */ protected String determineSequenceName(Properties params, Dialect dialect) { final String sequencePerEntitySuffix = ConfigurationHelper.getString( CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, params, DEF_SEQUENCE_SUFFIX ); // JPA_ENTITY_NAME value honors <class ... entity-name="..."> (HBM) and @Entity#name (JPA) overrides. String sequenceName = ConfigurationHelper.getBoolean( CONFIG_PREFER_SEQUENCE_PER_ENTITY, params, false ) ? params.getProperty( JPA_ENTITY_NAME ) + sequencePerEntitySuffix : DEF_SEQUENCE_NAME; final ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get( IDENTIFIER_NORMALIZER ); sequenceName = ConfigurationHelper.getString( SEQUENCE_PARAM, params, sequenceName ); if ( sequenceName.indexOf( '.' ) < 0 ) { sequenceName = normalizer.normalizeIdentifierQuoting( sequenceName ); final String schemaName = params.getProperty( SCHEMA ); final String catalogName = params.getProperty( CATALOG ); sequenceName = Table.qualify( dialect.quote( catalogName ), dialect.quote( schemaName ), dialect.quote( sequenceName ) ); } // if already qualified there is not much we can do in a portable manner so we pass it // through and assume the user has set up the name correctly. return sequenceName; }
private static void bindDiscriminatorProperty(Table table, RootClass entity, Element subnode, Mappings mappings) { SimpleValue discrim = new SimpleValue( mappings, table ); entity.setDiscriminator( discrim ); bindSimpleValue( subnode, discrim, false, RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME, mappings ); if ( !discrim.isTypeSpecified() ) { discrim.setTypeName( "string" ); // ( (Column) discrim.getColumnIterator().next() ).setType(type); } entity.setPolymorphic( true ); final String explicitForceValue = subnode.attributeValue( "force" ); boolean forceDiscriminatorInSelects = explicitForceValue == null ? mappings.forceDiscriminatorInSelectsByDefault() : "true".equals( explicitForceValue ); entity.setForceDiscriminator( forceDiscriminatorInSelects ); if ( "false".equals( subnode.attributeValue( "insert" ) ) ) { entity.setDiscriminatorInsertable( false ); } }
private static String getClassTableName( PersistentClass model, Element node, String schema, String catalog, Table denormalizedSuperTable, Mappings mappings) { Attribute tableNameNode = node.attribute( "table" ); String logicalTableName; String physicalTableName; if ( tableNameNode == null ) { logicalTableName = StringHelper.unqualify( model.getEntityName() ); physicalTableName = getNamingStrategyDelegate( mappings ).determineImplicitPrimaryTableName( model.getEntityName(), model.getJpaEntityName() ); } else { logicalTableName = tableNameNode.getValue(); physicalTableName = getNamingStrategyDelegate( mappings ).toPhysicalTableName( logicalTableName ); } mappings.addTableBinding( schema, catalog, logicalTableName, physicalTableName, denormalizedSuperTable ); return physicalTableName; }
public Table addDenormalizedTable( String schema, String catalog, String name, boolean isAbstract, String subselect, Table includedTable) throws DuplicateMappingException { name = getObjectNameNormalizer().normalizeIdentifierQuoting( name ); schema = getObjectNameNormalizer().normalizeIdentifierQuoting( schema ); catalog = getObjectNameNormalizer().normalizeIdentifierQuoting( catalog ); 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 void addTableBinding( String schema, String catalog, String logicalName, String physicalName, Table denormalizedSuperTable) throws DuplicateMappingException { 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 DuplicateMappingException( "Same physical table name [" + physicalName + "] references several logical table names: [" + oldDescriptor.logicalName + "], [" + logicalName + ']', "table", physicalName ); } }
/** * Determine the table name to use for the generator values. * <p/> * Called during {@link #configure configuration}. * * @see #getTableName() * @param params The params supplied in the generator config (plus some standard useful extras). * @param dialect The dialect in effect * @return The table name to use. */ protected String determineGeneratorTableName(Properties params, Dialect dialect) { String name = ConfigurationHelper.getString( TABLE_PARAM, params, DEF_TABLE ); final boolean isGivenNameUnqualified = name.indexOf( '.' ) < 0; if ( isGivenNameUnqualified ) { final ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get( IDENTIFIER_NORMALIZER ); name = normalizer.normalizeIdentifierQuoting( name ); // if the given name is un-qualified we may neen to qualify it final String schemaName = normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) ); final String catalogName = normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) ); name = Table.qualify( dialect.quote( catalogName ), dialect.quote( schemaName ), dialect.quote( name) ); } // if already qualified there is not much we can do in a portable manner so we pass it // through and assume the user has set up the name correctly. return name; }
public void addProperty(Property prop, Ejb3Column[] columns, XClass declaringClass) { //Ejb3Column.checkPropertyConsistency( ); //already called earlier /* * Check table matches between the component and the columns * if not, change the component table if no properties are set * if a property is set already the core cannot support that */ if (columns != null) { Table table = columns[0].getTable(); if ( !table.equals( component.getTable() ) ) { if ( component.getPropertySpan() == 0 ) { component.setTable( table ); } else { throw new AnnotationException( "A component cannot hold properties split into 2 different tables: " + this.getPath() ); } } } addProperty( prop, declaringClass ); }
private org.hibernate.annotations.Table findMatchingComplimentTableAnnotation(Join join) { String tableName = join.getTable().getQuotedName(); org.hibernate.annotations.Table table = annotatedClass.getAnnotation( org.hibernate.annotations.Table.class ); org.hibernate.annotations.Table matchingTable = null; if ( table != null && tableName.equals( table.appliesTo() ) ) { matchingTable = table; } else { Tables tables = annotatedClass.getAnnotation( Tables.class ); if ( tables != null ) { for (org.hibernate.annotations.Table current : tables.value()) { if ( tableName.equals( current.appliesTo() ) ) { matchingTable = current; break; } } } } return matchingTable; }
private String[] getTableNames(String aSchemaName, boolean reverse) { final ArrayList<String> t = new ArrayList<>(); final Collection<Table> tables = metadata.collectTableMappings(); for (Table table : tables) { if (table.isPhysicalTable()) { addTableName(metadata, t, table, aSchemaName); } } if (reverse) { Collections.reverse(t); } return t.toArray(new String[t.size()]); }
public SecondaryIndexHint(Class<?> annotated, String index) { javax.persistence.Table table = (javax.persistence.Table) annotated.getAnnotation( javax.persistence.Table.class); String name = table.name(); String schema = table.schema(); this.table = (schema != null ? schema + "." : "") + name; this.index = index; }
private boolean tableExists(Table table) { boolean exists = true; try (ResultSet tables = dialect.getMetadata().getTables(table.getCatalog(), table.getSchema(), table.getName(), null)) { exists = tables.next(); } catch (SQLException e) { // ignore at this point, just try to drop it. } return exists; }
@SuppressWarnings("unchecked") private void addTableInfo(QueryEntity queryEntity, SchemaDefinitionContext context, String tableName) { Namespace namespace = context.getDatabase().getDefaultNamespace(); Optional<Table> tableOptional = namespace.getTables().stream().filter( currentTable -> currentTable.getName().equals( tableName ) ).findFirst(); if ( tableOptional.isPresent() ) { Table table = tableOptional.get(); for ( Iterator<Column> columnIterator = table.getColumnIterator(); columnIterator.hasNext(); ) { Column currentColumn = columnIterator.next(); String fieldType = fieldType( currentColumn ); queryEntity.addQueryField( currentColumn.getName(), fieldType, null ); } } }
public List<String> getDropTableSql(String... tables) { List<String> drops = new ArrayList<String>(); for( String tableName : tables ) { Table table = findTable(tableName); drops.add(table.sqlDropString(dialect, defaultCatalog, defaultSchema)); } return drops; }
public List<String> getAddColumnsSQL(String tableName, String... columnNames) { List<String> sqlStrings = new ArrayList<String>(); Table table = findTable(tableName); for( String columnName : columnNames ) { Column column = table.getColumn(new Column(columnName)); StringBuffer alter = new StringBuffer("alter table ") .append(table.getQualifiedName(dialect, defaultCatalog, defaultSchema)).append(' ') .append(dialect.getAddColumnString()); alter.append(' ').append(column.getQuotedName(dialect)).append(' ') .append(column.getSqlType(dialect, mapping)); boolean useUniqueConstraint = extDialect.supportsModifyWithConstraints() && column.isUnique() && dialect.supportsUnique() && (!column.isNullable() || dialect.supportsNotNullUnique()); if( useUniqueConstraint ) { alter.append(" unique"); } if( column.hasCheckConstraint() && dialect.supportsColumnCheck() ) { alter.append(" check(").append(column.getCheckConstraint()).append(")"); } String columnComment = column.getComment(); if( columnComment != null ) { alter.append(dialect.getColumnComment(columnComment)); } sqlStrings.add(alter.toString()); } return sqlStrings; }
public List<String> getAddIndexesForColumns(String tableName, String... columnNames) { Set<Column> colSet = new HashSet<Column>(); for( String columnName : columnNames ) { colSet.add(new Column(columnName)); } List<String> sqlStrings = new ArrayList<String>(); Table table = findTable(tableName); addIndexSQL(sqlStrings, table, colSet); return sqlStrings; }
public List<String> getRenameColumnSQL(String tableName, String columnName, String newColumnName) { List<String> sqlStrings = new ArrayList<String>(); Table table = findTable(tableName); Column column = table.getColumn(new Column(columnName)); String alter = null; alter = extDialect.getRenameColumnSql(table.getQualifiedName(dialect, defaultCatalog, defaultSchema), column, newColumnName); sqlStrings.add(alter); return sqlStrings; }
public List<String> getAddNotNullSQLIfRequired(Session session, String tableName, String... columns) { final Table table = findTable(tableName); final List<String> sqlStrings = new ArrayList<String>(); final Set<String> colset = new HashSet<String>(Arrays.asList(columns)); session.doWork(new Work() { @Override public void execute(Connection connection) throws SQLException { ResultSet colresult = connection.getMetaData().getColumns(getDefaultCatalog(), extDialect.getNameForMetadataQuery(getDefaultSchema(), false), extDialect.getNameForMetadataQuery(table.getName(), table.isQuoted()), "%"); try { while( colresult.next() ) { String columnName = colresult.getString("COLUMN_NAME").toLowerCase(); if( colset.contains(columnName) && "yes".equals(colresult.getString("IS_NULLABLE").toLowerCase()) ) { Column column = table.getColumn(new Column(columnName)); StringBuffer alter = new StringBuffer("alter table ") .append(table.getQualifiedName(dialect, defaultCatalog, defaultSchema)).append(' ') .append(extDialect.getAddNotNullSql(mapping, column)); sqlStrings.add(alter.toString()); } } } finally { colresult.close(); } } }); return sqlStrings; }
private Table findTable(String tableName) { Map<String, Table> tableMap = configuration.getTableMap(); Table table = tableMap.get(tableName); if( table == null ) { throw new RuntimeException("Failed to find table: " + tableName); } return table; }
/** * Find appropriate table of the column. * It can come from a secondary table or from the main table of the persistent class * * @return appropriate table * @throws AnnotationException missing secondary table */ public Table getTable() { if ( table != null ){ return table; } if ( isSecondary() ) { return getJoin().getTable(); } else { return propertyHolder.getTable(); } }
private static void bindVersioningProperty(Table table, Element subnode, Mappings mappings, String name, RootClass entity, java.util.Map inheritedMetas) { String propertyName = subnode.attributeValue( "name" ); SimpleValue val = new SimpleValue( mappings, table ); bindSimpleValue( subnode, val, false, propertyName, mappings ); if ( !val.isTypeSpecified() ) { // this is either a <version/> tag with no type attribute, // or a <timestamp/> tag if ( "version".equals( name ) ) { val.setTypeName( "integer" ); } else { if ( "db".equals( subnode.attributeValue( "source" ) ) ) { val.setTypeName( "dbtimestamp" ); } else { val.setTypeName( "timestamp" ); } } } Property prop = new Property(); prop.setValue( val ); bindProperty( subnode, prop, mappings, inheritedMetas ); // for version properties marked as being generated, make sure they are "always" // generated; aka, "insert" is invalid; this is dis-allowed by the DTD, // but just to make sure... if ( prop.getValueGenerationStrategy() != null ) { if ( prop.getValueGenerationStrategy().getGenerationTiming() == GenerationTiming.INSERT ) { throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" ); } } makeVersion( subnode, val ); entity.setVersion( prop ); entity.addProperty( prop ); }
public void processComplementaryTableDefinitions(org.hibernate.annotations.Table table) { //comment and index are processed here if ( table == null ) return; String appliedTable = table.appliesTo(); Iterator tables = persistentClass.getTableClosureIterator(); Table hibTable = null; while ( tables.hasNext() ) { Table pcTable = (Table) tables.next(); if ( pcTable.getQuotedName().equals( appliedTable ) ) { //we are in the correct table to find columns hibTable = pcTable; break; } hibTable = null; } if ( hibTable == null ) { //maybe a join/secondary table for ( Join join : secondaryTables.values() ) { if ( join.getTable().getQuotedName().equals( appliedTable ) ) { hibTable = join.getTable(); break; } } } if ( hibTable == null ) { throw new AnnotationException( "@org.hibernate.annotations.Table references an unknown table: " + appliedTable ); } if ( !BinderHelper.isEmptyAnnotationValue( table.comment() ) ) hibTable.setComment( table.comment() ); TableBinder.addIndexes( hibTable, table.indexes(), mappings ); }
@Override public void prepare( JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess, Mappings mappings, Mapping mapping, Map settings) { this.catalog = ConfigurationHelper.getString( CATALOG, settings, ConfigurationHelper.getString( AvailableSettings.DEFAULT_CATALOG, settings ) ); this.schema = ConfigurationHelper.getString( SCHEMA, settings, ConfigurationHelper.getString( AvailableSettings.DEFAULT_SCHEMA, settings ) ); this.cleanUpTables = ConfigurationHelper.getBoolean( CLEAN_UP_ID_TABLES, settings, false ); final Iterator<PersistentClass> entityMappings = mappings.iterateClasses(); final List<Table> idTableDefinitions = new ArrayList<Table>(); while ( entityMappings.hasNext() ) { final PersistentClass entityMapping = entityMappings.next(); final Table idTableDefinition = generateIdTableDefinition( entityMapping ); idTableDefinitions.add( idTableDefinition ); } exportTableDefinitions( idTableDefinitions, jdbcServices, connectionAccess, mappings, mapping ); }
protected void secondPassCompileForeignKeys(Table table, Set<ForeignKey> done) throws MappingException { table.createForeignKeys(); Iterator iter = table.getForeignKeyIterator(); while ( iter.hasNext() ) { ForeignKey fk = (ForeignKey) iter.next(); if ( !done.contains( fk ) ) { done.add( fk ); final String referencedEntityName = fk.getReferencedEntityName(); if ( referencedEntityName == null ) { throw new MappingException( "An association from the table " + fk.getTable().getName() + " does not specify the referenced entity" ); } LOG.debugf( "Resolving reference to class: %s", referencedEntityName ); PersistentClass referencedClass = classes.get( referencedEntityName ); if ( referencedClass == null ) { throw new MappingException( "An association from the table " + fk.getTable().getName() + " refers to an unmapped class: " + referencedEntityName ); } if ( referencedClass.isJoinedSubclass() ) { secondPassCompileForeignKeys( referencedClass.getSuperclass().getTable(), done ); } fk.setReferencedTable( referencedClass.getTable() ); fk.alignColumns(); } } }
public void addColumnBinding(String logicalName, Column physicalColumn, Table table) throws DuplicateMappingException { TableColumnNameBinding binding = ( TableColumnNameBinding ) columnNameBindingPerTable.get( table ); if ( binding == null ) { binding = new TableColumnNameBinding( table.getName() ); columnNameBindingPerTable.put( table, binding ); } binding.addBinding( logicalName, physicalColumn ); }
public String getPhysicalColumnName(String logicalName, Table table) throws MappingException { logicalName = logicalName.toLowerCase(); String finalName = null; Table currentTable = table; do { TableColumnNameBinding binding = ( TableColumnNameBinding ) columnNameBindingPerTable.get( currentTable ); if ( binding != null ) { finalName = ( String ) binding.logicalToPhysical.get( logicalName ); } String key = buildTableNameKey( currentTable.getQuotedSchema(), currentTable.getQuotedCatalog(), currentTable.getQuotedName() ); TableDescription description = ( TableDescription ) tableNameBinding.get( key ); if ( description != null ) { currentTable = description.denormalizedSupertable; } else { currentTable = null; } } 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; }
@Override public String getLogicalColumnName(String physicalName, Table table) throws MappingException { String logical = null; Table currentTable = table; TableDescription description = null; do { TableColumnNameBinding binding = ( TableColumnNameBinding ) columnNameBindingPerTable.get( currentTable ); if ( binding != null ) { logical = ( String ) binding.physicalToLogical.get( physicalName ); } String key = buildTableNameKey( currentTable.getQuotedSchema(), currentTable.getQuotedCatalog(), currentTable.getQuotedName() ); description = ( TableDescription ) tableNameBinding.get( key ); if ( description != null ) { currentTable = description.denormalizedSupertable; } else { currentTable = null; } } while ( logical == null && currentTable != null ); if ( logical == null ) { throw new MappingException( "Unable to find logical column name from physical name " + physicalName + " in table " + table.getName() ); } return logical; }
@SuppressWarnings({ "unchecked" }) public void addUniqueConstraints(Table table, List uniqueConstraints) { List<UniqueConstraintHolder> constraintHolders = new ArrayList<UniqueConstraintHolder>( CollectionHelper.determineProperSizing( uniqueConstraints.size() ) ); int keyNameBase = determineCurrentNumberOfUniqueConstraintHolders( table ); for ( String[] columns : ( List<String[]> ) uniqueConstraints ) { final String keyName = "key" + keyNameBase++; constraintHolders.add( new UniqueConstraintHolder().setName( keyName ).setColumns( columns ) ); } addUniqueConstraintHolders( table, constraintHolders ); }
public void addUniqueConstraintHolders(Table table, List<UniqueConstraintHolder> uniqueConstraintHolders) { List<UniqueConstraintHolder> holderList = getUniqueConstraintHoldersByTable().get( table ); if ( holderList == null ) { holderList = new ArrayList<UniqueConstraintHolder>(); getUniqueConstraintHoldersByTable().put( table, holderList ); } holderList.addAll( uniqueConstraintHolders ); }
public void addJpaIndexHolders(Table table, List<JPAIndexHolder> holders) { List<JPAIndexHolder> holderList = jpaIndexHoldersByTable.get( table ); if ( holderList == null ) { holderList = new ArrayList<JPAIndexHolder>(); jpaIndexHoldersByTable.put( table, holderList ); } holderList.addAll( holders ); }