Search in sources :

Example 96 with Session

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

the class QueryResultSearchDTOImpl method get.

/**
     * Returns the requested set of search result objects based on the pagination at the front end.
     */
@Override
public List<Object> get(int position, int noOfObjects) throws HibernateSearchException {
    Session session = null;
    List<Object> returnList = new ArrayList<Object>();
    List<?> list = new ArrayList<Object>();
    try {
        session = StaticHibernateUtil.getSessionTL();
        Query query = prepareQuery(session, queryInputs.getQueryStrings()[1]);
        query.setFirstResult(position);
        query.setMaxResults(noOfObjects);
        list = query.list();
        logger.debug("\n\nInside get of QueryResultSearchDTOImpl.java . size of main query=" + list.size());
        this.queryInputs.setTypes(query.getReturnTypes());
        dtoBuilder.setInputs(queryInputs);
        returnList = new ArrayList<Object>();
        for (int i = 0; i < list.size(); i++) {
            if (buildDTO) {
                returnList.add(buildDTO((Object[]) list.get(i)));
            } else {
                if (i < noOfObjects) {
                    returnList.add(list.get(i));
                }
            }
        }
        StaticHibernateUtil.closeSession();
    } catch (Exception e) {
        throw new HibernateSearchException(HibernateConstants.SEARCH_FAILED, e);
    }
    return returnList;
}
Also used : Query(org.hibernate.Query) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) ArrayList(java.util.ArrayList) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) Session(org.hibernate.Session)

Example 97 with Session

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

the class ApplicationInitializer method applyMifos4948Fix.

@SuppressWarnings("unchecked")
private void applyMifos4948Fix() throws AccountException {
    Session session = StaticHibernateUtil.getSessionTL();
    List<LoanBO> fixLoans;
    Query query = session.getNamedQuery("fetchMissingInstalmentsForWriteOffsAndReschedules");
    fixLoans = query.list();
    if (fixLoans != null && fixLoans.size() > 0) {
        for (LoanBO fixLoan : fixLoans) {
            Set<AccountActionDateEntity> fixLoanSchedules = fixLoan.getAccountActionDates();
            Money totalMissedPayment = new Money(fixLoan.getCurrency());
            if (fixLoanSchedules != null && fixLoanSchedules.size() > 0) {
                for (AccountActionDateEntity fixLoanSchedule : fixLoanSchedules) {
                    LoanScheduleEntity loanInstallment = (LoanScheduleEntity) fixLoanSchedule;
                    totalMissedPayment = totalMissedPayment.add(loanInstallment.getPrincipalDue());
                }
            }
            logger.info("MIFOS-4948 - Loan: " + fixLoan.getGlobalAccountNum() + " - Adding payment: " + totalMissedPayment + " to fix instalments that should have been written-off or rescheduled.");
            fixLoan.applyMifos4948FixPayment(totalMissedPayment);
        }
        logger.info(fixLoans.size() + " Account Payments created to fix data related to MIFOS-4948");
    }
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) Query(org.hibernate.Query) LoanBO(org.mifos.accounts.loan.business.LoanBO) Session(org.hibernate.Session)

Example 98 with Session

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

the class ProductCategoryBOIntegrationTest method deleteProductCategory.

private void deleteProductCategory(ProductCategoryBO productCategoryBO) {
    Session session = StaticHibernateUtil.getSessionTL();
    Transaction transaction = StaticHibernateUtil.startTransaction();
    session.delete(productCategoryBO);
    session.flush();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session)

Example 99 with Session

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

the class TestObjectFactory method deleteAccountWithoutFee.

private static void deleteAccountWithoutFee(final AccountBO account) {
    Session session = StaticHibernateUtil.getSessionTL();
    deleteAccountPayments(account);
    deleteAccountActionDates(account, session);
    deleteAccountFees(account);
    deleteSpecificAccount(account, session);
}
Also used : Session(org.hibernate.Session)

Example 100 with Session

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

the class TestObjectPersistence method update.

public void update(AbstractEntity obj) {
    Session session = StaticHibernateUtil.getSessionTL();
    StaticHibernateUtil.startTransaction();
    session.saveOrUpdate(obj);
    StaticHibernateUtil.flushSession();
}
Also used : Session(org.hibernate.Session)

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