HHH-2448 Generate identical column aliases among cluster

This commit is contained in:
Brett Meyer 2013-01-15 15:06:24 -05:00
parent c5850fac6c
commit 4187717c56
2 changed files with 27 additions and 8 deletions

View File

@ -26,6 +26,7 @@ package org.hibernate.metamodel.internal;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -64,7 +65,6 @@ import org.hibernate.metamodel.spi.binding.AttributeBinding;
import org.hibernate.metamodel.spi.binding.BackRefAttributeBinding;
import org.hibernate.metamodel.spi.binding.EntityBinding;
import org.hibernate.metamodel.spi.binding.FetchProfile;
import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor;
import org.hibernate.metamodel.spi.binding.IdGenerator;
import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding;
import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding;
@ -79,6 +79,8 @@ import org.hibernate.metamodel.spi.domain.SingularAttribute;
import org.hibernate.metamodel.spi.domain.Type;
import org.hibernate.metamodel.spi.relational.Column;
import org.hibernate.metamodel.spi.relational.Database;
import org.hibernate.metamodel.spi.relational.Schema;
import org.hibernate.metamodel.spi.relational.Table;
import org.hibernate.metamodel.spi.source.FilterDefinitionSource;
import org.hibernate.metamodel.spi.source.FilterParameterSource;
import org.hibernate.metamodel.spi.source.IdentifierGeneratorSource;
@ -216,6 +218,8 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
final HbmMetadataSourceProcessorImpl processor = new HbmMetadataSourceProcessorImpl( this, jaxbRoots );
final Binder binder = new Binder( this, identifierGeneratorFactory );
binder.bindEntityHierarchies( processor.extractEntityHierarchies() );
secondPass();
}
@ -236,6 +240,20 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
}
}
}
private void secondPass() {
// This must be done outside of Table, rather than statically, to ensure
// deterministic alias names. See HHH-2448.
int uniqueInteger = 0;
Iterator<Schema> schemaIter = database.getSchemas().iterator();
while ( schemaIter.hasNext() ) {
Schema schema = schemaIter.next();
Iterator<Table> tableIter = schema.getTables().iterator();
while (tableIter.hasNext()) {
tableIter.next().setTableNumber( uniqueInteger++ );
}
}
}
@Override
public ObjectNameNormalizer getObjectNameNormalizer() {

View File

@ -27,17 +27,16 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Convenience base class for implementing the {@link ValueContainer} contract centralizing commonality
* between modeling tables, views and inline views.
*
* @author Steve Ebersole
* @author Brett Meyer
*/
public abstract class AbstractTableSpecification implements TableSpecification {
private final static AtomicInteger tableCounter = new AtomicInteger( 0 );
private final int tableNumber;
private int tableNumber;
private final List<Value> valueList = new ArrayList<Value>();
private final LinkedHashMap<Identifier, Value> valueMap = new LinkedHashMap<Identifier, Value>();
@ -45,14 +44,16 @@ public abstract class AbstractTableSpecification implements TableSpecification {
private final PrimaryKey primaryKey = new PrimaryKey( this );
private final List<ForeignKey> foreignKeys = new ArrayList<ForeignKey>();
public AbstractTableSpecification() {
this.tableNumber = tableCounter.getAndIncrement();
}
@Override
public int getTableNumber() {
return tableNumber;
}
public void setTableNumber( int tableNumber ) {
// This must be done outside of Table, rather than statically, to ensure
// deterministic alias names. See HHH-2448.
this.tableNumber = tableNumber;
}
@Override
public List<Value> values() {