public final void upgradeFramework(MFramework framework) {
LOG.info("Upgrading framework metadata");
RepositoryTransaction tx = null;
try {
MetadataUpgrader upgrader = FrameworkManager.getInstance()
.getMetadataUpgrader();
List<MConnection> connections = findConnections();
List<MJob> jobs = findJobs();
Validator validator = FrameworkManager.getInstance().getValidator();
boolean upgradeSuccessful = true;
// -- BEGIN TXN --
tx = getTransaction();
tx.begin();
deleteConnectionsAndJobs(connections, jobs, tx);
updateFramework(framework, tx);
for (MConnection connection : connections) {
long connectionID = connection.getPersistenceId();
// Make a new copy of the forms from the connector,
// else the values will get set in the forms in the connector for
// each connection.
List<MForm> forms = framework.getConnectionForms().clone(false).getForms();
MConnectionForms newConnectionForms = new MConnectionForms(forms);
upgrader.upgrade(connection.getFrameworkPart(), newConnectionForms);
MConnection newConnection = new MConnection(connection.getConnectorId(),
connection.getConnectorPart(), newConnectionForms);
newConnection.setPersistenceId(connectionID);
// Transform form structures to objects for validations
Object newConfigurationObject = ClassUtils.instantiate(FrameworkManager.getInstance().getConnectionConfigurationClass());
FormUtils.fromForms(newConnection.getFrameworkPart().getForms(), newConfigurationObject);
Validation validation = validator.validateConnection(newConfigurationObject);
if (validation.getStatus().canProceed()) {
updateConnection(newConnection, tx);
} else {
logInvalidModelObject("connection", newConnection, validation);
upgradeSuccessful = false;
}
}
for (MJob job : jobs) {
// Make a new copy of the forms from the framework,
// else the values will get set in the forms in the connector for
// each connection.
List<MForm> forms = framework.getJobForms(job.getType()).clone(false).getForms();
MJobForms newJobForms = new MJobForms(job.getType(), forms);
upgrader.upgrade(job.getFrameworkPart(), newJobForms);
MJob newJob = new MJob(job.getConnectorId(), job.getConnectionId(),
job.getType(), job.getConnectorPart(), newJobForms);
newJob.setPersistenceId(job.getPersistenceId());
// Transform form structures to objects for validations