}
@Override
protected boolean handle() throws IOException
{
PlatformBroker platformBroker = PlatformBrokerFactory.createPlatformBroker( getOptions().getPlatform(), getConfigProperties() );
if( getOptions().isInit() )
return init( platformBroker );
if( !platformBroker.confirmMetaData() )
{
getPrinter().printFormatted( "path: %s has not been initialized, use --init", platformBroker.getFullMetadataPath() );
return false;
}
boolean doNotWrite = false;
try
{
Target target = null;
if( getOptions().isDDL() )
target = new DDLTarget( getPrinter(), getOptions() );
if( getOptions().isListSchemas() || getOptions().isSchemaActions() )
target = new SchemaTarget( getPrinter(), getOptions() );
else if( getOptions().isListTables() || getOptions().isTableActions() )
target = new TableTarget( getPrinter(), getOptions() );
else if( getOptions().isListStereotypes() || getOptions().isStereotypeActions() )
target = new StereotypeTarget( getPrinter(), getOptions() );
else if( getOptions().isListFormats() || getOptions().isFormatActions() )
target = new FormatTarget( getPrinter(), getOptions() );
else if( getOptions().isListProtocols() || getOptions().isProtocolActions() )
target = new ProtocolTarget( getPrinter(), getOptions() );
else if( getOptions().isListProviders() || getOptions().isProviderActions() )
target = new ProviderTarget( getPrinter(), getOptions() );
else if( getOptions().isListRepos() || getOptions().isRepoActions() )
target = new RepoTarget( getPrinter(), getOptions() );
if( target == null )
return getOptions().printInvalidOptionMessage( getErrPrintStream(), "no command given: missing --add, --rename, --remove, --update, --validate, --show" );
if( !( target instanceof ProtocolTarget || target instanceof FormatTarget ) && getOptions().hasProperties() )
return getOptions().printInvalidOptionMessage( getErrPrintStream(), "--properties may only be added to formats or protocols via --add or --update" );
return target.handle( platformBroker );
}
catch( Throwable throwable )
{
doNotWrite = true;
Throwables.propagate( throwable );
return false;
}
finally
{
LOG.info( "catalog loaded: {}", platformBroker.catalogManagerLoaded() );
if( !doNotWrite && platformBroker.catalogManagerLoaded() )
platformBroker.commitCatalog();
}
}