ModuleVersion currentVersion = new ModuleVersion();
try
{
Persistent version = pf.create("aktera.Version");
version.setField("type", "M");
version.setField("name", moduleId);
if (version.find())
{
currentVersion = new ModuleVersion(version.getFieldString("version"));
}
else
{
currentVersion = new ModuleVersion("0.0.0");
}
}
catch (Exception x)
{
outModule.setAttribute("oldVersion", currentVersion.toString());
outModule.setAttribute("error", "unableToRetrieveCurrentVersion");
outModule.setAttribute("errorException", x.toString());
response.addOutput("updateError", "Y");
continue;
}
outModule.setAttribute("oldVersion", currentVersion.toString());
String updateHandlerClassName = moduleConfig.getChild("update").getAttribute("class", null);
if (updateHandlerClassName != null)
{
try
{
System.out.println("UpdateDatabase: Updating module '" + moduleId + "' with handler '"
+ updateHandlerClassName + "'");
Class klass = Class.forName(updateHandlerClassName);
if (klass != null)
{
UpdateHandler updateHandler = (UpdateHandler) klass.newInstance();
Connection con = null;
try
{
con = dataSourceComponent.getConnection();
updateHandler.setConnection(con);
updateHandler.updateDatabase(request, logger, con, pf, (ModuleVersion) currentVersion
.clone(), newVersion);
}
finally
{
con.close();
}
needReboot = needReboot || updateHandler.needReboot();
newUserPreferences = newUserPreferences || updateHandler.hasNewUserPreferences();
}
else
{
System.out.println("UpdateDatabase: Unable to find update handler for module '" + moduleId
+ "'");
}
}
catch (ClassNotFoundException x)
{
System.out
.println("UpdateDatabase: Unable call update handler for module '" + moduleId
+ "': " + x);
}
catch (Exception x)
{
outModule.setAttribute("error", "errorDuringUpdate");
outModule.setAttribute("errorException", x.toString());
response.addOutput("updateError", "Y");
continue;
}
}
try
{
Persistent version = pf.create("aktera.Version");
version.setField("type", "M");
version.setField("name", moduleId);
if (version.find())
{
version.setField("version", newVersion.toString());
version.update();
}
else
{
version.setField("version", newVersion.toString());
version.add();
}
}
catch (Exception x)
{
outModule.setAttribute("error", "unableToUpdateVersion");
outModule.setAttribute("errorException", x.toString());
response.addOutput("updateError", "Y");
}
}
if (newUserPreferences)
{
try
{
Persistent sample = pf.create("keel.user");
for (Persistent user : sample.query())
{
KeelPreferencesManager.createDefaultValues(request, user.getFieldInt("uid"));
}
}
catch (PersistenceException x)
{
response.addOutput("updateError", "Y");
response.addOutput("databaseError", x.getMessage());
StringWriter stw = new StringWriter();
PrintWriter pw = new PrintWriter(stw);
x.printStackTrace(pw);
response.addOutput("databaseErrorStackTrace", stw.getBuffer().toString().replaceAll("\n", "<br>"));
}
}
if (response.get("updateError") == null)
{
try
{
Model appInfo = (Model) request.getService(Model.ROLE, "aktera.app-info");
Configuration[] appConfigs = appInfo.getConfiguration().getChildren("app");
for (int i = 0; i < appConfigs.length; ++i)
{
Configuration appConfig = appConfigs[i];
Persistent version = pf.create("aktera.Version");
version.setField("type", "A");
version.setField("name", appConfig.getAttribute("id", "unkown"));
if (version.find())
{
version.setField("version", appConfig.getChild("version").getValue("0.0.0"));
version.update();
}
else
{
version.setField("version", appConfig.getChild("version").getValue("0.0.0"));
version.add();
}
}
}
catch (Exception x)
{