Search in sources :

Example 46 with PersistenceException

use of org.mifos.framework.exceptions.PersistenceException in project head by mifos.

the class LegacyGenericDao method executeNamedQueryForUpdate.

// Hugo Technologies
public int executeNamedQueryForUpdate(final String queryName, final Map<String, ?> queryParameters) throws PersistenceException {
    try {
        StaticHibernateUtil.startTransaction();
        Query query = createdNamedQuery(queryName);
        System.out.println(query.getQueryString());
        query.setProperties(queryParameters);
        int result = query.executeUpdate();
        StaticHibernateUtil.commitTransaction();
        return result;
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
}
Also used : Query(org.hibernate.Query) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ConnectionNotFoundException(org.mifos.framework.exceptions.ConnectionNotFoundException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) GenericJDBCException(org.hibernate.exception.GenericJDBCException) HibernateException(org.hibernate.HibernateException)

Example 47 with PersistenceException

use of org.mifos.framework.exceptions.PersistenceException 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();
            }
        }
    }
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) DatabaseMigrator(org.mifos.framework.persistence.DatabaseMigrator) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) CustomJDBCService(org.mifos.application.servicefacade.CustomJDBCService) SystemException(org.mifos.framework.exceptions.SystemException) TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) XMLReaderException(org.mifos.framework.exceptions.XMLReaderException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) AppNotConfiguredException(org.mifos.framework.exceptions.AppNotConfiguredException) AccountException(org.mifos.accounts.exceptions.AccountException) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) HibernateStartUpException(org.mifos.framework.exceptions.HibernateStartUpException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager)

Example 48 with PersistenceException

use of org.mifos.framework.exceptions.PersistenceException in project head by mifos.

the class FeeBOTest method testInvalidConnectionThrowsExceptionInConstructor.

@Test
@ExpectedException(value = FeeException.class)
public void testInvalidConnectionThrowsExceptionInConstructor() throws PersistenceException {
    final OfficePersistence officePersistence = mock(OfficePersistence.class);
    try {
        when(officePersistence.getHeadOffice()).thenThrow(new PersistenceException("some exception"));
        new RateFeeBO(null, "Customer Fee", new CategoryTypeEntity(FeeCategory.CENTER), new FeeFrequencyTypeEntity(FeeFrequencyType.ONETIME), null, 2.0, null, false, new FeePaymentEntity(FeePayment.UPFRONT)) {

            @Override
            public OfficePersistence getOfficePersistence() {
                return officePersistence;
            }
        };
        Assert.fail("should fail because of invalid session");
    } catch (FeeException e) {
    }
}
Also used : FeeException(org.mifos.accounts.fees.exceptions.FeeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) Test(org.junit.Test) ExpectedException(org.springframework.test.annotation.ExpectedException)

Example 49 with PersistenceException

use of org.mifos.framework.exceptions.PersistenceException in project head by mifos.

the class AccountBOTest method testInvalidConnectionThrowsExceptionInUpdate.

@Test(expected = AccountException.class)
public void testInvalidConnectionThrowsExceptionInUpdate() throws Exception {
    final LegacyAccountDao legacyAccountDao = mock(LegacyAccountDao.class);
    AccountBO accountBO = new AccountBO() {

        @Override
        public LegacyAccountDao getlegacyAccountDao() {
            return legacyAccountDao;
        }
    };
    when(legacyAccountDao.createOrUpdate(accountBO)).thenThrow(new PersistenceException("some exception"));
    // exercise test
    accountBO.update();
}
Also used : LegacyAccountDao(org.mifos.accounts.persistence.LegacyAccountDao) PersistenceException(org.mifos.framework.exceptions.PersistenceException) Test(org.junit.Test)

Example 50 with PersistenceException

use of org.mifos.framework.exceptions.PersistenceException in project head by mifos.

the class LoanPrdBusinessServiceTest method testInvalidConnectionThrowsExceptionInGetApplicableProductCategories.

@Test
@ExpectedException(value = ServiceException.class)
public void testInvalidConnectionThrowsExceptionInGetApplicableProductCategories() throws PersistenceException {
    try {
        when(prdOfferingPersistence.getApplicableProductCategories(ProductType.LOAN, PrdCategoryStatus.ACTIVE)).thenThrow(new PersistenceException("some exception"));
        loanPrdBusinessService.getActiveLoanProductCategories();
        Assert.fail("should fail because of invalid session");
    } catch (ServiceException e) {
    }
}
Also used : ServiceException(org.mifos.framework.exceptions.ServiceException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) Test(org.junit.Test) ExpectedException(org.springframework.test.annotation.ExpectedException)

Aggregations

PersistenceException (org.mifos.framework.exceptions.PersistenceException)215 MifosRuntimeException (org.mifos.core.MifosRuntimeException)98 ArrayList (java.util.ArrayList)55 ServiceException (org.mifos.framework.exceptions.ServiceException)53 AccountException (org.mifos.accounts.exceptions.AccountException)40 Test (org.junit.Test)35 ExpectedException (org.springframework.test.annotation.ExpectedException)32 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)24 BusinessRuleException (org.mifos.service.BusinessRuleException)23 Money (org.mifos.framework.util.helpers.Money)22 HibernateSearchException (org.mifos.framework.exceptions.HibernateSearchException)20 MifosUser (org.mifos.security.MifosUser)19 UserContext (org.mifos.security.util.UserContext)19 HashMap (java.util.HashMap)18 HibernateException (org.hibernate.HibernateException)18 Query (org.hibernate.Query)18 LoanBO (org.mifos.accounts.loan.business.LoanBO)18 Session (org.hibernate.Session)14 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)14 QueryResult (org.mifos.framework.hibernate.helper.QueryResult)14