Skip to content

Instantly share code, notes, and snippets.

@sebersole
Forked from dreab8/gist:a288187ec99163514215
Last active August 29, 2015 14:25
Show Gist options
  • Save sebersole/6b1a240c212b5db66c77 to your computer and use it in GitHub Desktop.
Save sebersole/6b1a240c212b5db66c77 to your computer and use it in GitHub Desktop.
@Override
public void doCreation(Metadata metadata, boolean createNamespaces, Dialect dialect, Target... targets)
throws SchemaManagementException {
boolean tryToCreateCatalogs = false;
boolean tryToCreateSchemas = false;
if ( createNamespaces ) {
if ( dialect.canCreateCatalog() ) {
tryToCreateCatalogs = true;
}
if ( dialect.canCreateSchema() ) {
tryToCreateSchemas = true;
}
}
.......
if ( tryToCreateCatalogs || tryToCreateSchemas ) {
Set<Identifier> exportedCatalogs = new HashSet<Identifier>();
for ( Schema namespace : database.getSchemas() ) {
if ( tryToCreateCatalogs ) {
final Identifier logicalName = namespace.getName().getCatalog();
final Identifier physicalName = namespace.getPhysicalName().getCatalog();
if ( catalog == null || exportedCatalogs.contains( logicalName ) {
continue;
}
applySqlStrings(
targets,
dialect.getCreateCatalogCommand( physicalName.render( dialect ) )
);
exportedCatalogs.add( logicalName );
}
}
if ( tryToCreateSchemas ) {
applySqlStrings(
targets,
dialect.getCreateSchemaCommand(
namespace.getPhysicalName().getSchema().render( dialect )
)
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment