* @param upgrade The upgrade this UpgradeVersion will be used for (not null).
*/
public static VersionUpgrade create(
String sName, Metadata metadata, Machine machine, Upgrade upgrade)
{
Metaclass versionClass = metadata.getMetaclass(Metadata.VERSION_CLASS_NAME);
PersistenceMapping mapping = versionClass.getPersistenceMapping();
DataSource ds = mapping.getDataSource();
if (ds instanceof RelationalDatabase) // SysVersion persisted in RDBMS
{
Table table = ((RelationalMapping)mapping).getPrimaryTable();
RelationalSchemaUpgrade version = new RelationalSchemaUpgrade(sName);
ExecStep step = new ExecStep();
SQLScript script = new SQLScript();
SQLStatement stmt = new SQLStatement();
stmt.setSQL("update ${table:"+ table.getName() +"} set " +
table.getColumn("loaded").getQuotedName() + "=0");
script.addStatement(stmt);
step.getScriptHolder().addScript(script);
version.setDataSource(ds);
version.addStep(step);
return version;
}
// SysVersion accessible via a Scheme function
ScriptUpgrade version = new ScriptUpgrade(sName);
// (SysVersion 'unload)
version.setBody(
Pair.list(
Pair.list(versionClass.getSymbol(), Pair.list(Symbol.QUOTE, Symbol.define("unload")))));
version.setUpgrade(upgrade); // required for compile() to work
version.compile(machine);
return version;
}