*/
protected void execute(String sCommand) throws Exception
{
m_sCommand = sCommand;
SQLSchemaManager manager = null;
if (sCommand.equals("create"))
{
manager = getSchemaManager();
manager.createSchema(getSchema());
}
else if (sCommand.equals("drop"))
{
manager = getSchemaManager();
manager.dropSchema(getSchema());
}
else if (sCommand.equals("insert"))
{
generateInsertScript();
}
else if (sCommand.equals("truncate"))
{
manager = getSchemaManager();
manager.truncateSchema(getSchema());
}
else if (sCommand.equals("upgrade"))
{
manager = getSchemaManager();
manager.upgrade(getSchema(), getProperty("meta.start"));
}
else if (sCommand.equals("analyze"))
{
manager = getSchemaManager();
manager.analyzeSchema(getSchema());
}
else if (sCommand.equals("export"))
{
exportSchema();
}
else if (sCommand.equals("setup"))
{
Metadata metadata = new MetadataLoaderDispatcher().load(null, null,
MetadataLoader.DATASOURCE_ONLY | MetadataLoader.INTEGRATION_EXCLUDED, null);
RelationalDatabase database = getDatabase(metadata);
manager = getSchemaManager(database);
manager.createDatabase((RelationalSchema)database.getSchema(), new PropertyMap()
{
public Object findValue(String sName, Object defaultValue)
{
Object value = getValue(sName);
return (value == null) ? defaultValue : value;
}
public Object getValue(String sName)
{
Object value = getProperty(sName);
return (value == null) ? getProperty("setup." + sName) : value; // also check CMD args
}
// thin wrapper around corresponding getProperty(...) methods
public Object findValue(String sName) { return getValue(sName); }
public String getClassName() { return getClass().getName(); }
public PropertyIterator getIterator() { throw new UnsupportedOperationException(); }
public int getValueCount() { throw new UnsupportedOperationException(); }
public boolean hasValue(String sName) { return getValue(sName) != null; }
public void setValue(String sName, Object value)
{
throw new UnsupportedOperationException();
}
});
}
else if (sCommand.equals("wrap"))
{
exportSchema();
exportClasses();
}
else
{
throw new IllegalArgumentException("Invalid command \"" + sCommand + "\"");
}
if (manager != null && manager.getSQLAppender() instanceof SQLFileAppender)
{
((SQLFileAppender)manager.getSQLAppender()).close();
}
}