Search in sources :

Example 76 with Session

use of org.hibernate.Session in project head by mifos.

the class BranchReportHelper method execute.

@Override
public void execute(long timeInMillis) throws BatchJobException {
    Session session = StaticHibernateUtil.getSessionTL();
    StaticHibernateUtil.startTransaction();
    Date runDate = new Date(timeInMillis);
    try {
        removeExistingBranchReportsForGivenRunDate(runDate);
        populateBranchReportBatch(session, runDate);
        StaticHibernateUtil.commitTransaction();
    } catch (HibernateException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new BatchJobException(e);
    } catch (ServiceException e) {
        throw new BatchJobException(e);
    }
}
Also used : BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateException(org.hibernate.HibernateException) Date(java.util.Date) Session(org.hibernate.Session)

Example 77 with Session

use of org.hibernate.Session in project head by mifos.

the class FinancialInitializer method initalizeFinancialAction.

@SuppressWarnings("unchecked")
public static void initalizeFinancialAction() throws FinancialException {
    Session session = StaticHibernateUtil.getSessionTL();
    try {
        Query queryFinancialAction = session.getNamedQuery(FinancialQueryConstants.GET_ALL_FINANCIAL_ACTION);
        List<FinancialActionTypeEntity> listFinancialAction = queryFinancialAction.list();
        for (FinancialActionTypeEntity fabo : listFinancialAction) {
            FinancialActionCache.addToCache(fabo);
        }
    } catch (Exception e) {
        throw new FinancialException(FinancialExceptionConstants.FINANCIALACTION_INITFAILED, e);
    }
}
Also used : FinancialActionTypeEntity(org.mifos.accounts.financial.business.FinancialActionTypeEntity) Query(org.hibernate.Query) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) IOException(java.io.IOException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) Session(org.hibernate.Session)

Example 78 with Session

use of org.hibernate.Session in project head by mifos.

the class FinancialInitializer method cacheCOA.

/**
     * Reads chart of accounts from the database and caches in memory.
     */
@SuppressWarnings("unchecked")
public static void cacheCOA() {
    if (ChartOfAccountsCache.isInitialized()) {
        return;
    }
    Session session = StaticHibernateUtil.getSessionTL();
    Query query = session.getNamedQuery(NamedQueryConstants.GET_ALL_COA);
    List<COABO> coaBoList = query.list();
    for (COABO coabo : coaBoList) {
        ChartOfAccountsCache.add(hibernateInitalize(coabo));
    }
}
Also used : Query(org.hibernate.Query) COABO(org.mifos.accounts.financial.business.COABO) Session(org.hibernate.Session)

Example 79 with Session

use of org.hibernate.Session in project head by mifos.

the class FeeDaoHibernate method doFetchListOfMasterDataFor.

@SuppressWarnings("unchecked")
private <T extends MasterDataEntity> List<T> doFetchListOfMasterDataFor(Class<T> type) {
    Session session = StaticHibernateUtil.getSessionTL();
    List<T> masterEntities = session.createQuery("from " + type.getName()).list();
    for (MasterDataEntity masterData : masterEntities) {
        Hibernate.initialize(masterData.getNames());
    }
    return masterEntities;
}
Also used : MasterDataEntity(org.mifos.application.master.business.MasterDataEntity) Session(org.hibernate.Session)

Example 80 with Session

use of org.hibernate.Session in project head by mifos.

the class GenericDaoHibernate method executeNamedQueryWithResultTransformer.

@SuppressWarnings("unchecked")
@Override
public final List<? extends Object> executeNamedQueryWithResultTransformer(final String queryName, final Map<String, ?> nameQueryParameters, final Class<?> className) {
    try {
        Session session = getSession();
        Query query = session.getNamedQuery(queryName).setResultTransformer(Transformers.aliasToBean(className));
        query.setProperties(nameQueryParameters);
        return query.list();
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : Query(org.hibernate.Query) MifosRuntimeException(org.mifos.core.MifosRuntimeException) Session(org.hibernate.Session) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

Session (org.hibernate.Session)4457 Test (org.junit.Test)2517 Transaction (org.hibernate.Transaction)1327 List (java.util.List)576 ArrayList (java.util.ArrayList)475 Test (org.testng.annotations.Test)411 TestForIssue (org.hibernate.testing.TestForIssue)389 Query (org.hibernate.Query)345 HibernateException (org.hibernate.HibernateException)299 DAOException (com.tomasio.projects.trainning.exception.DAOException)186 Criteria (org.hibernate.Criteria)174 Date (java.util.Date)134 Iterator (java.util.Iterator)127 SkipForDialect (org.hibernate.testing.SkipForDialect)114 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)113 SQLException (java.sql.SQLException)108 Map (java.util.Map)105 SessionFactory (org.hibernate.SessionFactory)105 GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)104 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)104