Skip to content

Instantly share code, notes, and snippets.

@dreab8
Created July 23, 2015 14:03
Show Gist options
  • Save dreab8/a288187ec99163514215 to your computer and use it in GitHub Desktop.
Save dreab8/a288187ec99163514215 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.canCreateSchema() ) {
tryToCreateSchemas = true;
}
if(dialect.canCreateCatalog()){
tryToCreateCatalogs = true;
}
}
.......
// first, create each schema
if ( tryToCreateSchemas ) {
Set<Identifier> exportedCatalogs = new HashSet<Identifier>();
for ( Schema schema : database.getSchemas() ) {
if ( schema.getName().getSchema() == null ) {
continue;
}
if ( tryToCreateCatalogs ) {
final Identifier catalog = schema.getName().getCatalog();
if ( catalog != null && !exportedCatalogs.contains( catalog ) ) {
applySqlStrings(
targets, dialect.getCreateCatalogCommand(
catalog.render(
dialect
)
)
);
exportedCatalogs.add( catalog );
}
}
applySqlStrings(
targets, dialect.getCreateSchemaCommand(
schema.getName()
.getSchema()
.render( dialect )
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment