Skip to content

Commit

Permalink
HHH-9974 - Rename org.hibernate.boot.model.relational.Schema to Names…
Browse files Browse the repository at this point in the history
…pace
  • Loading branch information
sebersole committed Jul 23, 2015
1 parent 333e404 commit ff4774a
Show file tree
Hide file tree
Showing 33 changed files with 188 additions and 182 deletions.
Expand Up @@ -44,7 +44,7 @@
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.ExportableProducer;
import org.hibernate.boot.model.relational.Schema;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.source.internal.ConstraintSecondPass;
import org.hibernate.boot.model.source.internal.ImplicitColumnNamingSecondPass;
import org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext;
Expand Down Expand Up @@ -461,8 +461,8 @@ public IdentifierGeneratorDefinition getIdentifierGenerator(String name) {
@Override
public java.util.Collection<Table> collectTableMappings() {
ArrayList<Table> tables = new ArrayList<Table>();
for ( Schema schema : getDatabase().getSchemas() ) {
tables.addAll( schema.getTables() );
for ( Namespace namespace : getDatabase().getNamespaces() ) {
tables.addAll( namespace.getTables() );
}
return tables;
}
Expand Down Expand Up @@ -723,7 +723,7 @@ public Table addTable(
String name,
String subselectFragment,
boolean isAbstract) {
final Schema schema = getDatabase().locateSchema(
final Namespace namespace = getDatabase().locateNamespace(
getDatabase().toIdentifier( catalogName ),
getDatabase().toIdentifier( schemaName )
);
Expand All @@ -739,17 +739,17 @@ public Table addTable(
}

if ( subselectFragment != null ) {
return new Table( schema, logicalName, subselectFragment, isAbstract );
return new Table( namespace, logicalName, subselectFragment, isAbstract );
}
else {
Table table = schema.locateTable( logicalName );
Table table = namespace.locateTable( logicalName );
if ( table != null ) {
if ( !isAbstract ) {
table.setAbstract( false );
}
return table;
}
return schema.createTable( logicalName, isAbstract );
return namespace.createTable( logicalName, isAbstract );
}
}

Expand All @@ -761,7 +761,7 @@ public Table addDenormalizedTable(
boolean isAbstract,
String subselectFragment,
Table includedTable) throws DuplicateMappingException {
final Schema schema = getDatabase().locateSchema(
final Namespace namespace = getDatabase().locateNamespace(
getDatabase().toIdentifier( catalogName ),
getDatabase().toIdentifier( schemaName )
);
Expand All @@ -777,15 +777,15 @@ public Table addDenormalizedTable(
}

if ( subselectFragment != null ) {
return new DenormalizedTable( schema, logicalName, subselectFragment, isAbstract, includedTable );
return new DenormalizedTable( namespace, logicalName, subselectFragment, isAbstract, includedTable );
}
else {
Table table = schema.locateTable( logicalName );
Table table = namespace.locateTable( logicalName );
if ( table != null ) {
throw new DuplicateMappingException( DuplicateMappingException.Type.TABLE, logicalName.toString() );
}
else {
table = schema.createDenormalizedTable( logicalName, isAbstract, includedTable );
table = namespace.createDenormalizedTable( logicalName, isAbstract, includedTable );
}
return table;
}
Expand Down Expand Up @@ -2191,8 +2191,8 @@ private void processExportableProducers(MetadataBuildingContext buildingContext)
// for now we only handle id generators as ExportableProducers

final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect();
final String defaultCatalog = extractName( getDatabase().getDefaultSchema().getName().getCatalog(), dialect );
final String defaultSchema = extractName( getDatabase().getDefaultSchema().getName().getSchema(), dialect );
final String defaultCatalog = extractName( getDatabase().getDefaultNamespace().getName().getCatalog(), dialect );
final String defaultSchema = extractName( getDatabase().getDefaultNamespace().getName().getSchema(), dialect );

for ( PersistentClass entityBinding : entityBindingMap.values() ) {
if ( entityBinding.isInherited() ) {
Expand Down
Expand Up @@ -23,7 +23,7 @@
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
import org.hibernate.boot.model.TypeDefinition;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.Schema;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.boot.spi.MetadataImplementor;
Expand Down Expand Up @@ -293,8 +293,8 @@ public Map<String, SQLFunction> getSqlFunctionMap() {
@Override
public java.util.Collection<Table> collectTableMappings() {
ArrayList<Table> tables = new ArrayList<Table>();
for ( Schema schema : database.getSchemas() ) {
tables.addAll( schema.getTables() );
for ( Namespace namespace : database.getNamespaces() ) {
tables.addAll( namespace.getTables() );
}
return tables;
}
Expand Down
Expand Up @@ -29,9 +29,9 @@ public class Database {
private final MetadataBuildingOptions buildingOptions;
private final JdbcEnvironment jdbcEnvironment;

private Schema implicitSchema;
private Namespace implicitNamespace;

private final Map<Schema.Name,Schema> schemaMap = new TreeMap<Schema.Name, Schema>();
private final Map<Namespace.Name,Namespace> namespaceMap = new TreeMap<Namespace.Name, Namespace>();

private List<AuxiliaryDatabaseObject> auxiliaryDatabaseObjects;
private List<InitCommand> initCommands;
Expand All @@ -47,8 +47,8 @@ public Database(MetadataBuildingOptions buildingOptions, JdbcEnvironment jdbcEnv

this.dialect = determineDialect( buildingOptions );

this.implicitSchema = makeSchema(
new Schema.Name(
this.implicitNamespace = makeNamespace(
new Namespace.Name(
toIdentifier( buildingOptions.getMappingDefaults().getImplicitCatalogName() ),
toIdentifier( buildingOptions.getMappingDefaults().getImplicitSchemaName() )
)
Expand All @@ -65,11 +65,11 @@ private static Dialect determineDialect(MetadataBuildingOptions buildingOptions)
return new H2Dialect();
}

private Schema makeSchema(Schema.Name name) {
Schema schema;
schema = new Schema( this, name );
schemaMap.put( name, schema );
return schema;
private Namespace makeNamespace(Namespace.Name name) {
Namespace namespace;
namespace = new Namespace( this, name );
namespaceMap.put( name, namespace );
return namespace;
}

public MetadataBuildingOptions getBuildingOptions() {
Expand Down Expand Up @@ -107,43 +107,43 @@ public PhysicalNamingStrategy getPhysicalNamingStrategy() {
return getBuildingOptions().getPhysicalNamingStrategy();
}

public Iterable<Schema> getSchemas() {
return schemaMap.values();
public Iterable<Namespace> getNamespaces() {
return namespaceMap.values();
}

public Schema getDefaultSchema() {
return implicitSchema;
public Namespace getDefaultNamespace() {
return implicitNamespace;
}

public Schema locateSchema(Identifier catalogName, Identifier schemaName) {
public Namespace locateNamespace(Identifier catalogName, Identifier schemaName) {
if ( catalogName == null && schemaName == null ) {
return getDefaultSchema();
return getDefaultNamespace();
}

final Schema.Name name = new Schema.Name( catalogName, schemaName );
Schema schema = schemaMap.get( name );
if ( schema == null ) {
schema = makeSchema( name );
final Namespace.Name name = new Namespace.Name( catalogName, schemaName );
Namespace namespace = namespaceMap.get( name );
if ( namespace == null ) {
namespace = makeNamespace( name );
}
return schema;
return namespace;
}

public Schema adjustDefaultSchema(Identifier catalogName, Identifier schemaName) {
final Schema.Name name = new Schema.Name( catalogName, schemaName );
if ( implicitSchema.getName().equals( name ) ) {
return implicitSchema;
public Namespace adjustDefaultNamespace(Identifier catalogName, Identifier schemaName) {
final Namespace.Name name = new Namespace.Name( catalogName, schemaName );
if ( implicitNamespace.getName().equals( name ) ) {
return implicitNamespace;
}

Schema schema = schemaMap.get( name );
if ( schema == null ) {
schema = makeSchema( name );
Namespace namespace = namespaceMap.get( name );
if ( namespace == null ) {
namespace = makeNamespace( name );
}
implicitSchema = schema;
return implicitSchema;
implicitNamespace = namespace;
return implicitNamespace;
}

public Schema adjustDefaultSchema(String implicitCatalogName, String implicitSchemaName) {
return adjustDefaultSchema( toIdentifier( implicitCatalogName ), toIdentifier( implicitSchemaName ) );
public Namespace adjustDefaultNamespace(String implicitCatalogName, String implicitSchemaName) {
return adjustDefaultNamespace( toIdentifier( implicitCatalogName ), toIdentifier( implicitSchemaName ) );
}

public void addAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject) {
Expand Down
Expand Up @@ -19,30 +19,36 @@
import org.hibernate.mapping.Table;

/**
* Represents a named schema/catalog pair and manages objects defined within.
* Represents a namespace (named schema/catalog pair) with a Database and manages objects defined within.
*
* @author Steve Ebersole
*/
public class Schema {
private static final CoreMessageLogger log = CoreLogging.messageLogger( Schema.class );
public class Namespace {
private static final CoreMessageLogger log = CoreLogging.messageLogger( Namespace.class );

private final Database database;
private final Name name;

private final Name physicalName;

private Map<Identifier, Table> tables = new TreeMap<Identifier, Table>();
private Map<Identifier, Sequence> sequences = new TreeMap<Identifier, Sequence>();

public Schema(Database database, Name name) {
public Namespace(Database database, Name name) {
this.database = database;
this.name = name;

final Identifier physicalCatalogIdentifier = database.getPhysicalNamingStrategy()
.toPhysicalCatalogName( name.getCatalog(), database.getJdbcEnvironment() );
final Identifier physicalSchemaIdentifier = database.getPhysicalNamingStrategy()
.toPhysicalCatalogName( name.getSchema(), database.getJdbcEnvironment() );
this.physicalName = new Name( physicalCatalogIdentifier, physicalSchemaIdentifier );
this.physicalName = new Name(
database.getPhysicalNamingStrategy()
.toPhysicalCatalogName( name.getCatalog(), database.getJdbcEnvironment() ),
database.getPhysicalNamingStrategy()
.toPhysicalCatalogName( name.getSchema(), database.getJdbcEnvironment() )
);

log.debugf(
"Created database namespace [logicalName=%s, physicalName=%s]",
name.toString(),
physicalName.toString()
);
}

public Name getName() {
Expand Down Expand Up @@ -138,7 +144,7 @@ public boolean equals(Object o) {
return false;
}

final Schema that = (Schema) o;
final Namespace that = (Namespace) o;
return EqualsHelper.equals( this.name, that.name );
}

Expand Down
Expand Up @@ -12,7 +12,7 @@
* @author Steve Ebersole
*/
public class QualifiedNameImpl extends QualifiedNameParser.NameParts implements QualifiedName {
public QualifiedNameImpl(Schema.Name schemaName, Identifier objectName) {
public QualifiedNameImpl(Namespace.Name schemaName, Identifier objectName) {
this(
schemaName.getCatalog(),
schemaName.getSchema(),
Expand Down
Expand Up @@ -16,7 +16,7 @@ public QualifiedSequenceName(Identifier catalogName, Identifier schemaName, Iden
super( catalogName, schemaName, sequenceName );
}

public QualifiedSequenceName(Schema.Name schemaName, Identifier sequenceName) {
public QualifiedSequenceName(Namespace.Name schemaName, Identifier sequenceName) {
super( schemaName, sequenceName );
}

Expand Down
Expand Up @@ -16,7 +16,7 @@ public QualifiedTableName(Identifier catalogName, Identifier schemaName, Identif
super( catalogName, schemaName, tableName );
}

public QualifiedTableName(Schema.Name schemaName, Identifier tableName) {
public QualifiedTableName(Namespace.Name schemaName, Identifier tableName) {
super( schemaName, tableName );
}

Expand Down
Expand Up @@ -32,27 +32,27 @@ public class SimpleAuxiliaryDatabaseObject extends AbstractAuxiliaryDatabaseObje
private final String[] dropStrings;

public SimpleAuxiliaryDatabaseObject(
Schema schema,
Namespace namespace,
String createString,
String dropString,
Set<String> dialectScopes) {
this(
schema,
namespace,
new String[] { createString },
new String[] { dropString },
dialectScopes
);
}

public SimpleAuxiliaryDatabaseObject(
Schema schema,
Namespace namespace,
String[] createStrings,
String[] dropStrings,
Set<String> dialectScopes) {
this(
dialectScopes,
extractName( schema.getPhysicalName().getCatalog() ),
extractName( schema.getPhysicalName().getSchema() ),
extractName( namespace.getPhysicalName().getCatalog() ),
extractName( namespace.getPhysicalName().getSchema() ),
createStrings,
dropStrings
);
Expand Down
Expand Up @@ -176,7 +176,7 @@ public boolean shouldImplicitlyQuoteIdentifiers() {
}
);

rootMetadataBuildingContext.getMetadataCollector().getDatabase().adjustDefaultSchema(
rootMetadataBuildingContext.getMetadataCollector().getDatabase().adjustDefaultNamespace(
rootMetadataBuildingContext.getBuildingOptions().getMappingDefaults().getImplicitCatalogName(),
rootMetadataBuildingContext.getBuildingOptions().getMappingDefaults().getImplicitSchemaName()
);
Expand Down
Expand Up @@ -52,7 +52,7 @@ public static void processAuxiliaryDatabaseObject(
}
else {
auxDbObject = new SimpleAuxiliaryDatabaseObject(
context.getMetadataCollector().getDatabase().getDefaultSchema(),
context.getMetadataCollector().getDatabase().getDefaultNamespace(),
auxDbObjectMapping.getCreate(),
auxDbObjectMapping.getDrop(),
null
Expand Down

0 comments on commit ff4774a

Please sign in to comment.