return;
}
database = args[0];
ProcessEngine processEngine = new ConfigurationImpl()
.skipDbCheck()
.buildProcessEngine();
try {
JbpmVersion jbpmVersion = (JbpmVersion) processEngine.execute(new Command<Object>(){
private static final long serialVersionUID = 1L;
public Object execute(Environment environment) throws Exception {
Session session = environment.get(Session.class);
if (!PropertyImpl.propertiesTableExists(session)) {
try {
session.createSQLQuery("select CLASSNAME_ from JBPM4_VARIABLE").list();
return JbpmVersion.V_4_1;
} catch (HibernateException e) {
return JbpmVersion.V_4_0;
}
}
String dbVersion = PropertyImpl.getDbVersion(session);
if (dbVersion == null) {
throw new JbpmException("property table exists, but no db version property is present");
}
return JbpmVersion.getJbpmVersion(dbVersion);
}
});
if (jbpmVersion == JbpmVersion.V_4_2) {
throw new JbpmException("jBPM schema is already up to date");
}
if (jbpmVersion.isEarlier(JbpmVersion.V_4_1)) {
processEngine.execute(new Command<Object>(){
private static final long serialVersionUID = 1L;
public Object execute(Environment environment) throws Exception {
Session session = environment.get(Session.class);
DbHelper.executeSqlResource("upgrade-4.0-to-4.1/jbpm." + database + ".upgrade.sql", session);
return null;
}
});
}
if (jbpmVersion.isEarlier(JbpmVersion.V_4_2)) {
processEngine.execute(new Command<Object>(){
private static final long serialVersionUID = 1L;
public Object execute(Environment environment) throws Exception {
Session session = environment.get(Session.class);
DbHelper.executeSqlResource("upgrade-4.1-to-4.2/jbpm." + database + ".upgrade.sql", session);
PropertyImpl.upgradeProperties(session);
return null;
}
});
processEngine.execute(new Command<Object>(){
private static final long serialVersionUID = 1L;
public Object execute(Environment environment) throws Exception {
Session session = environment.get(Session.class);
// find deployments without a langid property
List<DeploymentProperty> deploymentProperties = session.createCriteria(DeploymentProperty.class)
.add(Restrictions.eq("key", DeploymentImpl.KEY_PROCESS_DEFINITION_ID))
.list();
for (DeploymentProperty deploymentProperty : deploymentProperties) {
String objectName = deploymentProperty.getObjectName();
DeploymentImpl deployment = deploymentProperty.getDeployment();
deployment.setProcessLanguageId(objectName, "jpdl-4.0");
}
return null;
}
});
}
log.info("jBPM DB upgrade completed successfully.");
} catch (Exception e) {
log.error("ERROR: jBPM DB upgrade FAILED", e);
} finally {
processEngine.close();
}
}