HHH-7050 : back out of changes
This commit is contained in:
parent
f5679281e0
commit
2115f1f79c
|
@ -256,7 +256,6 @@ public class Binder {
|
||||||
|
|
||||||
bindSecondaryTables( entitySource, entityBinding );
|
bindSecondaryTables( entitySource, entityBinding );
|
||||||
Deque<TableSpecification> tableStack = new ArrayDeque<TableSpecification>( );
|
Deque<TableSpecification> tableStack = new ArrayDeque<TableSpecification>( );
|
||||||
tableStack.add( entityBinding.getPrimaryTable() );
|
|
||||||
bindAttributes( entitySource, entityBinding, tableStack );
|
bindAttributes( entitySource, entityBinding, tableStack );
|
||||||
|
|
||||||
bindTableUniqueConstraints( entitySource, entityBinding );
|
bindTableUniqueConstraints( entitySource, entityBinding );
|
||||||
|
@ -385,6 +384,7 @@ public class Binder {
|
||||||
final EntityBinding entityBinding = buildBasicEntityBinding( entitySource, superEntityBinding );
|
final EntityBinding entityBinding = buildBasicEntityBinding( entitySource, superEntityBinding );
|
||||||
|
|
||||||
entityBinding.setPrimaryTable( superEntityBinding.getPrimaryTable() );
|
entityBinding.setPrimaryTable( superEntityBinding.getPrimaryTable() );
|
||||||
|
entityBinding.setPrimaryTableName( superEntityBinding.getPrimaryTableName() );
|
||||||
bindDiscriminatorValue( entitySource, entityBinding );
|
bindDiscriminatorValue( entitySource, entityBinding );
|
||||||
|
|
||||||
return entityBinding;
|
return entityBinding;
|
||||||
|
@ -989,10 +989,12 @@ public class Binder {
|
||||||
|
|
||||||
final String tableName = attributeSource.getExplicitCollectionTableName();
|
final String tableName = attributeSource.getExplicitCollectionTableName();
|
||||||
if ( StringHelper.isNotEmpty( tableName ) ) {
|
if ( StringHelper.isNotEmpty( tableName ) ) {
|
||||||
final String table = currentBindingContext.getNamingStrategy().tableName( tableName );
|
final Identifier tableIdentifier = Identifier.toIdentifier(
|
||||||
Table collectionTable = schema.locateTable( table );
|
currentBindingContext.getNamingStrategy().tableName( tableName )
|
||||||
|
);
|
||||||
|
Table collectionTable = schema.locateTable( tableIdentifier );
|
||||||
if ( collectionTable == null ) {
|
if ( collectionTable == null ) {
|
||||||
collectionTable = schema.createTable( Identifier.toIdentifier( tableName ), true );
|
collectionTable = schema.createTable( tableIdentifier );
|
||||||
}
|
}
|
||||||
pluralAttributeBinding.setCollectionTable( collectionTable );
|
pluralAttributeBinding.setCollectionTable( collectionTable );
|
||||||
}
|
}
|
||||||
|
@ -1000,7 +1002,7 @@ public class Binder {
|
||||||
// todo : not sure wel have all the needed info here in all cases, specifically when needing to know the "other side"
|
// todo : not sure wel have all the needed info here in all cases, specifically when needing to know the "other side"
|
||||||
final EntityBinding owner = pluralAttributeBinding.getContainer().seekEntityBinding();
|
final EntityBinding owner = pluralAttributeBinding.getContainer().seekEntityBinding();
|
||||||
final String ownerTableLogicalName = Table.class.isInstance( owner.getPrimaryTable() )
|
final String ownerTableLogicalName = Table.class.isInstance( owner.getPrimaryTable() )
|
||||||
? owner.getPrimaryTable().getLogicalName()
|
? Table.class.cast( owner.getPrimaryTable() ).getTableName().getName()
|
||||||
: null;
|
: null;
|
||||||
String collectionTableName = currentBindingContext.getNamingStrategy().collectionTableName(
|
String collectionTableName = currentBindingContext.getNamingStrategy().collectionTableName(
|
||||||
owner.getEntity().getName(),
|
owner.getEntity().getName(),
|
||||||
|
@ -1010,13 +1012,11 @@ public class Binder {
|
||||||
pluralAttributeBinding.getContainer().getPathBase() + '.' + attributeSource.getName()
|
pluralAttributeBinding.getContainer().getPathBase() + '.' + attributeSource.getName()
|
||||||
);
|
);
|
||||||
collectionTableName = quoteIdentifier( collectionTableName );
|
collectionTableName = quoteIdentifier( collectionTableName );
|
||||||
// TODO: may not know physical collection table name if this is an association;
|
|
||||||
// for now, assume that the physical collection table name is known at this point;
|
|
||||||
boolean isPhysicalCollectionTable = true;
|
|
||||||
pluralAttributeBinding.setCollectionTable(
|
pluralAttributeBinding.setCollectionTable(
|
||||||
schema.locateOrCreateTable(
|
schema.locateOrCreateTable(
|
||||||
collectionTableName,
|
Identifier.toIdentifier(
|
||||||
isPhysicalCollectionTable
|
collectionTableName
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1037,9 +1037,11 @@ public class Binder {
|
||||||
AbstractPluralAttributeBinding pluralAttributeBinding,
|
AbstractPluralAttributeBinding pluralAttributeBinding,
|
||||||
Deque<TableSpecification> tableStack) {
|
Deque<TableSpecification> tableStack) {
|
||||||
|
|
||||||
|
// TableSpecification targetTable = tableStack.peekLast();
|
||||||
pluralAttributeBinding.getPluralAttributeKeyBinding().prepareForeignKey(
|
pluralAttributeBinding.getPluralAttributeKeyBinding().prepareForeignKey(
|
||||||
attributeSource.getKeySource().getExplicitForeignKeyName(),
|
attributeSource.getKeySource().getExplicitForeignKeyName(),
|
||||||
tableStack.peekLast().getLogicalName()
|
//tableStack.peekLast().getLogicalName()
|
||||||
|
null // todo : handle secondary table names
|
||||||
);
|
);
|
||||||
pluralAttributeBinding.getPluralAttributeKeyBinding().getForeignKey().setDeleteRule(
|
pluralAttributeBinding.getPluralAttributeKeyBinding().getForeignKey().setDeleteRule(
|
||||||
attributeSource.getKeySource().getOnDeleteAction()
|
attributeSource.getKeySource().getOnDeleteAction()
|
||||||
|
@ -1289,6 +1291,7 @@ public class Binder {
|
||||||
final TableSource tableSource = entitySource.getPrimaryTable();
|
final TableSource tableSource = entitySource.getPrimaryTable();
|
||||||
final Table table = createTable( entityBinding, tableSource );
|
final Table table = createTable( entityBinding, tableSource );
|
||||||
entityBinding.setPrimaryTable( table );
|
entityBinding.setPrimaryTable( table );
|
||||||
|
entityBinding.setPrimaryTableName( table.getTableName().getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindSecondaryTables(EntitySource entitySource, EntityBinding entityBinding) {
|
private void bindSecondaryTables(EntitySource entitySource, EntityBinding entityBinding) {
|
||||||
|
@ -1317,7 +1320,7 @@ public class Binder {
|
||||||
return currentBindingContext.getMetadataImplementor()
|
return currentBindingContext.getMetadataImplementor()
|
||||||
.getDatabase()
|
.getDatabase()
|
||||||
.locateSchema( databaseSchemaName )
|
.locateSchema( databaseSchemaName )
|
||||||
.locateOrCreateTable( tableName, true );
|
.locateOrCreateTable( Identifier.toIdentifier( tableName ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindTableUniqueConstraints(EntitySource entitySource, EntityBinding entityBinding) {
|
private void bindTableUniqueConstraints(EntitySource entitySource, EntityBinding entityBinding) {
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class TableProcessor {
|
||||||
String tableName = JandexHelper.getValue( tableAnnotation, "appliesTo", String.class );
|
String tableName = JandexHelper.getValue( tableAnnotation, "appliesTo", String.class );
|
||||||
ObjectName objectName = new ObjectName( tableName );
|
ObjectName objectName = new ObjectName( tableName );
|
||||||
Schema schema = metadata.getDatabase().getSchema( objectName.getSchema(), objectName.getCatalog() );
|
Schema schema = metadata.getDatabase().getSchema( objectName.getSchema(), objectName.getCatalog() );
|
||||||
Table table = schema.locateTable( tableName );
|
Table table = schema.locateTable( objectName.getName() );
|
||||||
if ( table != null ) {
|
if ( table != null ) {
|
||||||
bindHibernateTableAnnotation( table, tableAnnotation );
|
bindHibernateTableAnnotation( table, tableAnnotation );
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,7 @@ public class EntityBinding implements AttributeBindingContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TableSpecification locateTable(String tableName) {
|
public TableSpecification locateTable(String tableName) {
|
||||||
if ( tableName == null || tableName.equals( getPrimaryTableLogicalName() ) ) {
|
if ( tableName == null || tableName.equals( getPrimaryTableName() ) ) {
|
||||||
return primaryTable;
|
return primaryTable;
|
||||||
}
|
}
|
||||||
TableSpecification tableSpec = secondaryTables.get( tableName );
|
TableSpecification tableSpec = secondaryTables.get( tableName );
|
||||||
|
@ -246,8 +246,8 @@ public class EntityBinding implements AttributeBindingContainer {
|
||||||
}
|
}
|
||||||
return tableSpec;
|
return tableSpec;
|
||||||
}
|
}
|
||||||
public String getPrimaryTableLogicalName() {
|
public String getPrimaryTableName() {
|
||||||
return primaryTable.getLogicalName();
|
return primaryTableName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrimaryTableName(String primaryTableName) {
|
public void setPrimaryTableName(String primaryTableName) {
|
||||||
|
|
|
@ -53,11 +53,6 @@ public class InLineView extends AbstractTableSpecification {
|
||||||
return select;
|
return select;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLogicalName() {
|
|
||||||
return logicalName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLoggableValueQualifier() {
|
public String getLoggableValueQualifier() {
|
||||||
return logicalName;
|
return logicalName;
|
||||||
|
|
|
@ -34,7 +34,7 @@ import java.util.Map;
|
||||||
public class Schema {
|
public class Schema {
|
||||||
private final Name name;
|
private final Name name;
|
||||||
private Map<String, InLineView> inLineViews = new HashMap<String, InLineView>();
|
private Map<String, InLineView> inLineViews = new HashMap<String, InLineView>();
|
||||||
private Map<String, Table> tables = new HashMap<String, Table>();
|
private Map<Identifier, Table> tables = new HashMap<Identifier, Table>();
|
||||||
|
|
||||||
public Schema(Name name) {
|
public Schema(Name name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -48,72 +48,20 @@ public class Schema {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Table locateTable(Identifier name) {
|
||||||
* Returns the table with the specified logical table name.
|
return tables.get( name );
|
||||||
* .
|
|
||||||
* @param logicalTableName
|
|
||||||
*
|
|
||||||
* @return the table with the specified logical table name,
|
|
||||||
* or null if there is no table with the specified
|
|
||||||
* logical table name.
|
|
||||||
*/
|
|
||||||
public Table locateTable(String logicalTableName) {
|
|
||||||
return tables.get( logicalTableName );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Table createTable(Identifier name) {
|
||||||
* Creates a {@link Table} with the specified logical name. If
|
Table table = new Table( this, name );
|
||||||
* {@code isPhysicalName} is true, then {@code name} is also
|
tables.put( name, table );
|
||||||
* the phycical table name.
|
|
||||||
*
|
|
||||||
* @param name - the name of the table
|
|
||||||
* @param isPhysicalName - true, if the name is known to be the
|
|
||||||
* physical name.
|
|
||||||
* @return the created table.
|
|
||||||
*/
|
|
||||||
public Table createTable(Identifier name, boolean isPhysicalName) {
|
|
||||||
Table table = new Table( this, name, isPhysicalName );
|
|
||||||
tables.put( table.getLogicalName(), table );
|
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package-protected */
|
public Table locateOrCreateTable(Identifier name) {
|
||||||
void remapLogicalTableName(String oldName) {
|
|
||||||
Table table = tables.remove( oldName );
|
|
||||||
if ( table == null ) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
String.format(
|
|
||||||
"Schema (%s) does not contain a table with logical name (%s) to remap.",
|
|
||||||
name,
|
|
||||||
oldName
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
tables.put( table.getLogicalName(), table );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Locates the table with the specified name; if none is found,
|
|
||||||
* a table with the specified name is created.
|
|
||||||
* <p/>
|
|
||||||
* The value for {@code isPhysicalTableName} is ignored if a table
|
|
||||||
* is located with the specified name, and that name is defined
|
|
||||||
* as the physical table name (indicated by a non-null value returned
|
|
||||||
* by {@link Table#getTableName()}.
|
|
||||||
*
|
|
||||||
* @param name - the name
|
|
||||||
* @param isPhysicalTableName - true, if the table is known to be
|
|
||||||
* the physical table name.
|
|
||||||
* @return the located or created table.
|
|
||||||
*/
|
|
||||||
public Table locateOrCreateTable(String name, boolean isPhysicalTableName) {
|
|
||||||
final Table existing = locateTable( name );
|
final Table existing = locateTable( name );
|
||||||
Identifier tableIdentifier = Identifier.toIdentifier( name );
|
|
||||||
if ( existing == null ) {
|
if ( existing == null ) {
|
||||||
return createTable( tableIdentifier, isPhysicalTableName );
|
return createTable( name );
|
||||||
}
|
|
||||||
else if ( isPhysicalTableName && existing.getTableName() == null ) {
|
|
||||||
existing.setPhysicalName( tableIdentifier );
|
|
||||||
}
|
}
|
||||||
return existing;
|
return existing;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,54 +34,27 @@ import org.hibernate.dialect.Dialect;
|
||||||
*
|
*
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
* @author Gail Badner
|
|
||||||
*/
|
*/
|
||||||
public class Table extends AbstractTableSpecification implements Exportable {
|
public class Table extends AbstractTableSpecification implements Exportable {
|
||||||
private final Schema database;
|
private final Schema database;
|
||||||
private String logicalName;
|
private final Identifier tableName;
|
||||||
private Identifier name;
|
private final ObjectName objectName;
|
||||||
private boolean isPhysicalName;
|
private final String qualifiedName;
|
||||||
private ObjectName objectName;
|
|
||||||
private String qualifiedName;
|
|
||||||
|
|
||||||
private final LinkedHashMap<String,Index> indexes = new LinkedHashMap<String,Index>();
|
private final LinkedHashMap<String,Index> indexes = new LinkedHashMap<String,Index>();
|
||||||
private final LinkedHashMap<String,UniqueKey> uniqueKeys = new LinkedHashMap<String,UniqueKey>();
|
private final LinkedHashMap<String,UniqueKey> uniqueKeys = new LinkedHashMap<String,UniqueKey>();
|
||||||
private final List<CheckConstraint> checkConstraints = new ArrayList<CheckConstraint>();
|
private final List<CheckConstraint> checkConstraints = new ArrayList<CheckConstraint>();
|
||||||
private final List<String> comments = new ArrayList<String>();
|
private final List<String> comments = new ArrayList<String>();
|
||||||
|
|
||||||
/**
|
public Table(Schema database, String tableName) {
|
||||||
* Constructs a {@link Table} instance.
|
this( database, Identifier.toIdentifier( tableName ) );
|
||||||
*
|
|
||||||
* @param database - the schema
|
|
||||||
* @param name - the name
|
|
||||||
* @param isPhysicalTableName - true, if the name is known to be the physical
|
|
||||||
* table name; false, otherwise.
|
|
||||||
*/
|
|
||||||
public Table(Schema database, String name, boolean isPhysicalTableName) {
|
|
||||||
this( database, Identifier.toIdentifier( name ), isPhysicalTableName );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Table(Schema database, Identifier tableName) {
|
||||||
/**
|
|
||||||
* Constructs a {@link Table} instance.
|
|
||||||
*
|
|
||||||
* @param database - the schema
|
|
||||||
* @param name - the name {@link Identifier}
|
|
||||||
* @param isPhysicalTableName - true, if the name is known to be the physical
|
|
||||||
* table name; false, otherwise.
|
|
||||||
*/
|
|
||||||
public Table(Schema database, Identifier name, boolean isPhysicalTableName) {
|
|
||||||
this.database = database;
|
this.database = database;
|
||||||
setName( name, isPhysicalTableName );
|
this.tableName = tableName;
|
||||||
}
|
objectName = new ObjectName( database.getName().getSchema(), database.getName().getCatalog(), tableName );
|
||||||
|
this.qualifiedName = objectName.toText();
|
||||||
private static String createLogicalName(Identifier tableName) {
|
|
||||||
return tableName.isQuoted() ?
|
|
||||||
new StringBuilder( tableName.getName().length() + 2 )
|
|
||||||
.append( '`' )
|
|
||||||
.append( tableName.getName() )
|
|
||||||
.append( '`' ).toString() :
|
|
||||||
tableName.getName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -89,51 +62,8 @@ public class Table extends AbstractTableSpecification implements Exportable {
|
||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the logical table name.
|
|
||||||
*
|
|
||||||
* @return the logical table name.
|
|
||||||
*/
|
|
||||||
public String getLogicalName() {
|
|
||||||
return logicalName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the physical table name.
|
|
||||||
*
|
|
||||||
* @return the physical table name, or null if the physical
|
|
||||||
* table name is not defined.
|
|
||||||
*/
|
|
||||||
public Identifier getTableName() {
|
public Identifier getTableName() {
|
||||||
return isPhysicalName ? name : null;
|
return tableName;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the physical table name.
|
|
||||||
*
|
|
||||||
* @param physicalName - the physical table name
|
|
||||||
*/
|
|
||||||
public final void setPhysicalName(Identifier physicalName) {
|
|
||||||
setName( physicalName, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setName(Identifier name, boolean isPhysicalName) {
|
|
||||||
if ( name == null ) {
|
|
||||||
throw new IllegalArgumentException( "name cannot be null." );
|
|
||||||
}
|
|
||||||
if ( isPhysicalName && ! this.isPhysicalName ) {
|
|
||||||
this.isPhysicalName = isPhysicalName;
|
|
||||||
}
|
|
||||||
if ( ! name.equals( this.name ) ) {
|
|
||||||
String logicalNameOld = logicalName;
|
|
||||||
this.name = name;
|
|
||||||
this.logicalName = createLogicalName( name );
|
|
||||||
objectName = new ObjectName( database.getName().getSchema(), database.getName().getCatalog(), name );
|
|
||||||
this.qualifiedName = objectName.toText();
|
|
||||||
if ( logicalNameOld != null ) {
|
|
||||||
database.remapLogicalTableName( logicalNameOld );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -45,13 +45,6 @@ public interface TableSpecification extends ValueContainer, Loggable {
|
||||||
*/
|
*/
|
||||||
public int getTableNumber();
|
public int getTableNumber();
|
||||||
|
|
||||||
/**
|
|
||||||
* Get logical table name
|
|
||||||
*
|
|
||||||
* @return the logical table name.
|
|
||||||
*/
|
|
||||||
public String getLogicalName();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the primary key definition for this table spec.
|
* Get the primary key definition for this table spec.
|
||||||
*
|
*
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class SimpleValueBindingTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicMiddleOutBuilding() {
|
public void testBasicMiddleOutBuilding() {
|
||||||
Table table = new Table( new Schema( null, null ), "the_table", true );
|
Table table = new Table( new Schema( null, null ), "the_table" );
|
||||||
Column idColumn = table.locateOrCreateColumn( "id" );
|
Column idColumn = table.locateOrCreateColumn( "id" );
|
||||||
idColumn.setJdbcDataType( BIGINT );
|
idColumn.setJdbcDataType( BIGINT );
|
||||||
idColumn.setSize( Size.precision( 18, 0 ) );
|
idColumn.setSize( Size.precision( 18, 0 ) );
|
||||||
|
|
|
@ -35,7 +35,6 @@ import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,7 +47,7 @@ public class TableManipulationTests extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testTableCreation() {
|
public void testTableCreation() {
|
||||||
Schema schema = new Schema( null, null );
|
Schema schema = new Schema( null, null );
|
||||||
Table table = schema.createTable( Identifier.toIdentifier( "my_table" ), true );
|
Table table = schema.createTable( Identifier.toIdentifier( "my_table" ) );
|
||||||
assertNull( table.getSchema().getName().getSchema() );
|
assertNull( table.getSchema().getName().getSchema() );
|
||||||
assertNull( table.getSchema().getName().getCatalog() );
|
assertNull( table.getSchema().getName().getCatalog() );
|
||||||
assertEquals( "my_table", table.getTableName().toString() );
|
assertEquals( "my_table", table.getTableName().toString() );
|
||||||
|
@ -92,10 +91,10 @@ public class TableManipulationTests extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testTableSpecificationCounter() {
|
public void testTableSpecificationCounter() {
|
||||||
Schema schema = new Schema( null, null );
|
Schema schema = new Schema( null, null );
|
||||||
Table table = schema.createTable( Identifier.toIdentifier( "my_table" ), true );
|
Table table = schema.createTable( Identifier.toIdentifier( "my_table" ) );
|
||||||
InLineView inLineView = schema.createInLineView( "my_inlineview", "subselect" );
|
InLineView inLineView = schema.createInLineView( "my_inlineview", "subselect" );
|
||||||
InLineView otherInLineView = schema.createInLineView( "my_other_inlineview", "other subselect" );
|
InLineView otherInLineView = schema.createInLineView( "my_other_inlineview", "other subselect" );
|
||||||
Table otherTable = schema.createTable( Identifier.toIdentifier( "my_other_table" ), true );
|
Table otherTable = schema.createTable( Identifier.toIdentifier( "my_other_table" ) );
|
||||||
|
|
||||||
int firstTableNumber = table.getTableNumber();
|
int firstTableNumber = table.getTableNumber();
|
||||||
assertEquals( firstTableNumber, table.getTableNumber() );
|
assertEquals( firstTableNumber, table.getTableNumber() );
|
||||||
|
@ -107,7 +106,7 @@ public class TableManipulationTests extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testBasicForeignKeyDefinition() {
|
public void testBasicForeignKeyDefinition() {
|
||||||
Schema schema = new Schema( null, null );
|
Schema schema = new Schema( null, null );
|
||||||
Table book = schema.createTable( Identifier.toIdentifier( "BOOK" ), true );
|
Table book = schema.createTable( Identifier.toIdentifier( "BOOK" ) );
|
||||||
|
|
||||||
Column bookId = book.locateOrCreateColumn( "id" );
|
Column bookId = book.locateOrCreateColumn( "id" );
|
||||||
bookId.setJdbcDataType( INTEGER );
|
bookId.setJdbcDataType( INTEGER );
|
||||||
|
@ -115,7 +114,7 @@ public class TableManipulationTests extends BaseUnitTestCase {
|
||||||
book.getPrimaryKey().addColumn( bookId );
|
book.getPrimaryKey().addColumn( bookId );
|
||||||
book.getPrimaryKey().setName( "BOOK_PK" );
|
book.getPrimaryKey().setName( "BOOK_PK" );
|
||||||
|
|
||||||
Table page = schema.createTable( Identifier.toIdentifier( "PAGE" ), true );
|
Table page = schema.createTable( Identifier.toIdentifier( "PAGE" ) );
|
||||||
|
|
||||||
Column pageId = page.locateOrCreateColumn( "id" );
|
Column pageId = page.locateOrCreateColumn( "id" );
|
||||||
pageId.setJdbcDataType( INTEGER );
|
pageId.setJdbcDataType( INTEGER );
|
||||||
|
@ -137,12 +136,12 @@ public class TableManipulationTests extends BaseUnitTestCase {
|
||||||
public void testQualifiedName() {
|
public void testQualifiedName() {
|
||||||
Dialect dialect = new H2Dialect();
|
Dialect dialect = new H2Dialect();
|
||||||
Schema schema = new Schema( Identifier.toIdentifier( "schema" ), Identifier.toIdentifier( "`catalog`" ) );
|
Schema schema = new Schema( Identifier.toIdentifier( "schema" ), Identifier.toIdentifier( "`catalog`" ) );
|
||||||
Table table = schema.createTable( Identifier.toIdentifier( "my_table" ), true );
|
Table table = schema.createTable( Identifier.toIdentifier( "my_table" ) );
|
||||||
assertEquals( "my_table", table.getTableName().getName() );
|
assertEquals( "my_table", table.getTableName().getName() );
|
||||||
assertEquals( "my_table", table.getTableName().toString() );
|
assertEquals( "my_table", table.getTableName().toString() );
|
||||||
assertEquals( "schema.\"catalog\".my_table", table.getQualifiedName( dialect ) );
|
assertEquals( "schema.\"catalog\".my_table", table.getQualifiedName( dialect ) );
|
||||||
|
|
||||||
table = schema.createTable( Identifier.toIdentifier( "`my_table`" ), true );
|
table = schema.createTable( Identifier.toIdentifier( "`my_table`" ) );
|
||||||
assertEquals( "my_table", table.getTableName().getName() );
|
assertEquals( "my_table", table.getTableName().getName() );
|
||||||
assertEquals( "`my_table`", table.getTableName().toString() );
|
assertEquals( "`my_table`", table.getTableName().toString() );
|
||||||
assertEquals( "schema.\"catalog\".\"my_table\"", table.getQualifiedName( dialect ) );
|
assertEquals( "schema.\"catalog\".\"my_table\"", table.getQualifiedName( dialect ) );
|
||||||
|
@ -150,67 +149,4 @@ public class TableManipulationTests extends BaseUnitTestCase {
|
||||||
InLineView inLineView = schema.createInLineView( "my_inlineview", "select ..." );
|
InLineView inLineView = schema.createInLineView( "my_inlineview", "select ..." );
|
||||||
assertEquals( "( select ... )", inLineView.getQualifiedName( dialect ) );
|
assertEquals( "( select ... )", inLineView.getQualifiedName( dialect ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testTableLogicalName() {
|
|
||||||
Schema schema = new Schema( Identifier.toIdentifier( "schema" ), Identifier.toIdentifier( "`catalog`" ) );
|
|
||||||
Table table = schema.createTable( Identifier.toIdentifier( "my_table" ), false );
|
|
||||||
assertEquals( "my_table", table.getLogicalName() );
|
|
||||||
assertNull( table.getTableName() );
|
|
||||||
assertSame( table, schema.locateTable( table.getLogicalName() ) );
|
|
||||||
table.setPhysicalName( Identifier.toIdentifier( "my_new_table" ) );
|
|
||||||
assertEquals( "my_new_table", table.getLogicalName() );
|
|
||||||
assertEquals( "my_new_table", table.getTableName().getName() );
|
|
||||||
assertSame( table, schema.locateTable( "my_new_table" ) );
|
|
||||||
assertNull( schema.locateTable( "my_table" ) );
|
|
||||||
table.setPhysicalName( Identifier.toIdentifier( "my_newer_table" ) );
|
|
||||||
assertEquals( "my_newer_table", table.getLogicalName() );
|
|
||||||
assertEquals( "my_newer_table", table.getTableName().getName() );
|
|
||||||
assertSame( table, schema.locateTable( "my_newer_table" ) );
|
|
||||||
assertNull( schema.locateTable( "my_new_table" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testQuotedTableLogicalName() {
|
|
||||||
Schema schema = new Schema( Identifier.toIdentifier( "schema" ), Identifier.toIdentifier( "`catalog`" ) );
|
|
||||||
Table table = schema.createTable( Identifier.toIdentifier( "`my_table`" ), false );
|
|
||||||
assertEquals( "`my_table`", table.getLogicalName() );
|
|
||||||
assertNull( table.getTableName() );
|
|
||||||
assertSame( table, schema.locateTable( table.getLogicalName() ) );
|
|
||||||
table.setPhysicalName( Identifier.toIdentifier( "`my_new_table`" ) );
|
|
||||||
assertEquals( "`my_new_table`", table.getLogicalName() );
|
|
||||||
assertEquals( "my_new_table", table.getTableName().getName() );
|
|
||||||
assertSame( table, schema.locateTable( "`my_new_table`" ) );
|
|
||||||
assertNull( schema.locateTable( "`my_table`" ) );
|
|
||||||
table.setPhysicalName( Identifier.toIdentifier( "`my_newer_table`" ) );
|
|
||||||
assertEquals( "`my_newer_table`", table.getLogicalName() );
|
|
||||||
assertEquals( "my_newer_table", table.getTableName().getName() );
|
|
||||||
assertSame( table, schema.locateTable( "`my_newer_table`" ) );
|
|
||||||
assertNull( schema.locateTable( "`my_new_table`" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInLineViewLogicalName() {
|
|
||||||
Schema schema = new Schema( Identifier.toIdentifier( "schema" ), Identifier.toIdentifier( "`catalog`" ) );
|
|
||||||
InLineView view = schema.createInLineView( "my_view", "select" );
|
|
||||||
assertEquals( "my_view", view.getLogicalName() );
|
|
||||||
assertEquals( "select", view.getSelect() );
|
|
||||||
assertSame( view, schema.getInLineView( view.getLogicalName() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLocateOrCreateTable() {
|
|
||||||
Schema schema = new Schema( Identifier.toIdentifier( "schema" ), Identifier.toIdentifier( "`catalog`" ) );
|
|
||||||
Table table = schema.locateOrCreateTable( "my_table", false );
|
|
||||||
assertEquals( "my_table", table.getLogicalName() );
|
|
||||||
assertNull( table.getTableName() );
|
|
||||||
Table tableTemp = schema.locateOrCreateTable( "my_table", true );
|
|
||||||
assertSame( table, tableTemp );
|
|
||||||
assertEquals( "my_table", table.getLogicalName() );
|
|
||||||
assertEquals( Identifier.toIdentifier( "my_table" ), table.getTableName() );
|
|
||||||
tableTemp = schema.locateOrCreateTable( "my_table", false );
|
|
||||||
assertSame( table, tableTemp );
|
|
||||||
assertEquals( "my_table", table.getLogicalName() );
|
|
||||||
assertEquals( Identifier.toIdentifier( "my_table" ), table.getTableName() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue