use of org.mifos.framework.persistence.DatabaseMigrator in project head by mifos.
the class ApplicationInitializer method dbUpgrade.
public void dbUpgrade(ApplicationContext applicationContext) throws ConfigurationException, PersistenceException, FinancialException, TaskSystemException {
logger.info("Logger has been initialised");
initializeHibernate(applicationContext);
logger.info(getDatabaseConnectionInfo());
// if a database upgrade loads an instance of Money then MoneyCompositeUserType needs the default
// currency
MoneyCompositeUserType.setDefaultCurrency(AccountingRules.getMifosCurrency(new ConfigurationPersistence()));
// load the additional currencies
AccountingRules.init();
Money.setDefaultCurrency(AccountingRules.getMifosCurrency(new ConfigurationPersistence()));
final MifosConfigurationManager configuration = MifosConfigurationManager.getInstance();
final String imageStorageConfig = configuration.getString(IMAGESTORE_CONFIG_KEY);
if (imageStorageConfig == null || !imageStorageConfig.equals(DB_CONFIG)) {
ImageStorageManager.initStorage();
}
DatabaseMigrator migrator = new DatabaseMigrator();
initializeDBConnectionForHibernate(migrator);
if (!databaseError.isError) {
try {
migrator.upgrade(applicationContext);
} catch (Throwable t) {
setDatabaseError(DatabaseErrorCode.UPGRADE_FAILURE, "Failed to upgrade database.", t);
}
}
if (databaseError.isError) {
databaseError.logError();
} else {
initializeDB(applicationContext);
/*
* John W - Added in G Release and back patched to F Release.
* Related to jira issue MIFOS-4948
*
* Can find all code and the related query by searching for mifos4948
*
*/
CustomJDBCService customJdbcService = applicationContext.getBean(CustomJDBCService.class);
boolean keyExists = customJdbcService.mifos4948IssueKeyExists();
if (!keyExists) {
try {
StaticHibernateUtil.startTransaction();
applyMifos4948Fix();
customJdbcService.insertMifos4948Issuekey();
StaticHibernateUtil.commitTransaction();
} catch (AccountException e) {
StaticHibernateUtil.rollbackTransaction();
e.printStackTrace();
} finally {
StaticHibernateUtil.closeSession();
}
}
boolean key5722Exists = customJdbcService.mifos5722IssueKeyExists();
if (!key5722Exists) {
try {
applyMifos5722Fix();
customJdbcService.insertMifos5722Issuekey();
} catch (Exception e) {
logger.error("Could not apply Mifos-5692 and mifos-5722 fix");
e.printStackTrace();
} finally {
StaticHibernateUtil.closeSession();
}
}
boolean key5763Exists = customJdbcService.mifos5763IssueKeyExists();
if (!key5763Exists) {
try {
applyMifos5763Fix();
customJdbcService.insertMifos5763Issuekey();
} catch (Exception e) {
logger.info("Failed to apply Mifos-5763 fix");
e.printStackTrace();
} finally {
StaticHibernateUtil.closeSession();
}
}
boolean key5632Exists = customJdbcService.mifos5632IssueKeyExists();
if (!key5632Exists) {
try {
applyMifos5632();
customJdbcService.insertMifos5632IssueKey();
} catch (Exception e) {
logger.info("Failed to apply Mifos-5632 fix");
e.printStackTrace();
} finally {
StaticHibernateUtil.closeSession();
}
}
}
}
Aggregations