final Schema.Name schemaName = Helper.determineDatabaseSchemaName(
attributeSource.getExplicitSchemaName(),
attributeSource.getExplicitCatalogName(),
currentBindingContext
);
final Schema schema = metadata.getDatabase().locateSchema( schemaName );
final String tableName = attributeSource.getExplicitCollectionTableName();
if ( StringHelper.isNotEmpty( tableName ) ) {
final Identifier tableIdentifier = Identifier.toIdentifier(
currentBindingContext.getNamingStrategy().tableName( tableName )
);
Table collectionTable = schema.locateTable( tableIdentifier );
if ( collectionTable == null ) {
collectionTable = schema.createTable( tableIdentifier );
}
pluralAttributeBinding.setCollectionTable( collectionTable );
}
else {
// 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 String ownerTableLogicalName = Table.class.isInstance( owner.getPrimaryTable() )
? Table.class.cast( owner.getPrimaryTable() ).getTableName().getName()
: null;
String collectionTableName = currentBindingContext.getNamingStrategy().collectionTableName(
owner.getEntity().getName(),
ownerTableLogicalName,
null, // todo : here
null, // todo : and here
pluralAttributeBinding.getContainer().getPathBase() + '.' + attributeSource.getName()
);
collectionTableName = quoteIdentifier( collectionTableName );
pluralAttributeBinding.setCollectionTable(
schema.locateOrCreateTable(
Identifier.toIdentifier(
collectionTableName
)
)
);