SQLAppender innerAppender = getDynamicSQLAppender(buf);
Metadata metadata = schema.getMetadata();
VersionUpgrade firstVersion = (sVersion == null)
? upgrade.getFirstVersion() : upgrade.getVersion(sVersion);
Lookup/*<Object, UpgradeState>*/ stateMap = Upgrade.getInitialState(firstVersion);
SchemaVersion version = new SchemaVersion();
upgrade.validate(metadata, null);
version.setNamespace(metadata.getNamespace());
version.setUpgradable(true);
appendUpgradeInitialize(buf, schema);
if (buf.length() > 0) // don't want to output end-of-statement character if there's nothing in buffer
{
m_appender.appendSQL(buf.toString());
buf.setLength(0);
}
// skip all upgrade versions not applicable to schema's DataSourceAdapter
if (sVersion == null)
{
firstVersion =
findFirstVersion(firstVersion, stateMap, (RelationalDatabase)schema.getDataSource());
}
for (VersionUpgrade u = firstVersion; u != null; u = u.getNext())
{
if (u.getName() == null)
{
u.apply(Upgrade.getState(stateMap, u));
}
else
{
version.setVersion(u.getName());
version.setStep(UPGRADE_END_STEP);
SchemaVersion prev = (SchemaVersion)version.clone();
version.setStep((u instanceof ScriptUpgrade && ((ScriptUpgrade)u).getFunction() == null ||
u instanceof RelationalSchemaUpgrade &&
((RelationalSchemaUpgrade)u).getDataSource().getSchema() != schema ||
u instanceof LabelUpgrade) ? UPGRADE_END_STEP : 0);
if (u.getPrev() != null && u.getPrev().getName() != null)
{
prev.setVersion(u.getPrev().getName());
appendUpgradeStepStart(buf, schema, prev);
appendUpgradeStepEnd(buf, schema, version, prev, null);
m_appender.appendSQL(buf.toString());
buf.setLength(0);
}