Search in sources :

Example 21 with HibernateSearchException

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

the class QueryResultDTOImpl 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 {
    List<Object> returnList = new ArrayList<Object>();
    try {
        scrollResult.setRowNumber(position);
        returnList = new ArrayList<Object>();
        if (position < size) {
            if (buildDTO) {
                returnList.add(buildDTO(scrollResult.get()));
            } else {
                Object[] obj = scrollResult.get();
                returnList.add(obj[0]);
            }
        }
        for (int i = 0; i < noOfObjects - 1; i++) {
            if (scrollResult.next()) {
                if (buildDTO) {
                    returnList.add(buildDTO(scrollResult.get()));
                } else {
                    Object[] obj = scrollResult.get();
                    returnList.add(obj[0]);
                }
            }
        }
    } catch (Exception e) {
        throw new HibernateSearchException(HibernateConstants.SEARCH_FAILED, e);
    }
    return returnList;
}
Also used : HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) ArrayList(java.util.ArrayList) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) HibernateException(org.hibernate.HibernateException)

Example 22 with HibernateSearchException

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

the class QueryResultSearchDTOImpl method prepareQuery.

public Query prepareQuery(Session session, String namedQuery) throws HibernateSearchException {
    if (this.queryInputs == null) {
        throw new HibernateSearchException(HibernateConstants.SEARCH_INPUTNULL);
    }
    List<Param> paramList = queryInputs.getParamList();
    Query query = null;
    query = session.getNamedQuery(namedQuery);
    if (paramList != null) {
        for (int i = 0; i < paramList.size(); i++) {
            if (paramList.get(i) != null) {
                if (paramList.get(i).getValue() instanceof List) {
                    query.setParameterList(paramList.get(i).getName(), (List) paramList.get(i).getValue());
                } else {
                    query.setParameter(paramList.get(i).getName(), paramList.get(i).getValue());
                }
            }
        }
    }
    return query;
}
Also used : Query(org.hibernate.Query) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) Param(org.mifos.customers.util.helpers.Param) List(java.util.List) ArrayList(java.util.ArrayList)

Example 23 with HibernateSearchException

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

the class QueryResultSearchDTOImpl method getSize.

/**
     * Returns the records valid for the query
     */
@Override
public int getSize() throws HibernateSearchException {
    Session session = null;
    try {
        session = StaticHibernateUtil.getSessionTL();
        if (this.queryInputs == null) {
            throw new HibernateSearchException(HibernateConstants.SEARCH_INPUTNULL);
        }
        Query query = prepareQuery(session, queryInputs.getQueryStrings()[0]);
        Integer resultSetCount = ((Number) query.uniqueResult()).intValue();
        logger.debug("\n\nInside get of QueryResultSearchDTOImpl.java . size of count query=" + resultSetCount);
        this.queryInputs.setTypes(query.getReturnTypes());
        dtoBuilder.setInputs(queryInputs);
        if (resultSetCount != null && resultSetCount > 0) {
            size = resultSetCount;
        }
        StaticHibernateUtil.closeSession();
    } catch (Exception e) {
        throw new HibernateSearchException(HibernateConstants.SEARCH_FAILED, e);
    }
    return size;
}
Also used : Query(org.hibernate.Query) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) Session(org.hibernate.Session)

Example 24 with HibernateSearchException

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

the class QueryResultsMainSearchImpl method get.

@Override
public java.util.List get(int position, int noOfObjects) throws HibernateSearchException {
    java.util.List returnList = new java.util.ArrayList();
    java.util.List list = new java.util.ArrayList();
    Session session = null;
    try {
        session = StaticHibernateUtil.getSessionTL();
        Query query = prepareQuery(session, queryInputs.getQueryStrings()[1]);
        query.setFirstResult(position);
        query.setMaxResults(noOfObjects);
        list = query.list();
        this.queryInputs.setTypes(query.getReturnTypes());
        dtoBuilder.setInputs(queryInputs);
        Query query1 = session.createQuery("select account.globalAccountNum " + "from org.mifos.accounts.business.AccountBO account " + "where account.customer.customerId=:customerId" + " and account.accountType.accountTypeId=:accountTypeId" + " and account.accountState.id not in (6,7,10,15,17,18) ");
        if (list != null) {
            for (int i = 0; i < list.size(); i++) {
                if (buildDTO) {
                    Object record = buildDTO((Object[]) list.get(i));
                    CustomerSearchDto cs = ((CustomerSearchDto) record);
                    query1.setInteger("customerId", cs.getCustomerId()).setShort("accountTypeId", (short) 1);
                    cs.setLoanGlobalAccountNum(query1.list());
                    query1.setShort("accountTypeId", (short) 5);
                    cs.setGroupLoanGlobalAccountNum(query1.list());
                    query1.setShort("accountTypeId", (short) 2);
                    cs.setSavingsGlobalAccountNum(query1.list());
                    returnList.add(cs);
                } 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) CustomerSearchDto(org.mifos.customers.business.CustomerSearchDto) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) Session(org.hibernate.Session)

Example 25 with HibernateSearchException

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

the class TableTag method getCacheNullList.

private List getCacheNullList() throws HibernateSearchException {
    List list = null;
    Cache cache = null;
    try {
        QueryResult query = (QueryResult) SessionUtils.getAttribute(Constants.SEARCH_RESULTS, (HttpServletRequest) pageContext.getRequest());
        if (null != query) {
            cache = new Cache(query);
            list = cache.getList(0, "");
            if (null == list) {
                list = new ArrayList();
            } else {
                SessionUtils.setRemovableAttribute(TableTagConstants.TABLECACHE, cache, TableTagConstants.PATH, pageContext.getSession());
                size = cache.getSize();
            }
        }
    } catch (PageExpiredException e) {
        throw new HibernateSearchException(e);
    }
    return list;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) ArrayList(java.util.ArrayList) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) ArrayList(java.util.ArrayList) List(java.util.List) Cache(org.mifos.framework.util.helpers.Cache)

Aggregations

HibernateSearchException (org.mifos.framework.exceptions.HibernateSearchException)25 ArrayList (java.util.ArrayList)16 QueryResult (org.mifos.framework.hibernate.helper.QueryResult)15 PersistenceException (org.mifos.framework.exceptions.PersistenceException)13 Query (org.hibernate.Query)8 Param (org.mifos.customers.util.helpers.Param)8 QueryInputs (org.mifos.framework.hibernate.helper.QueryInputs)8 Session (org.hibernate.Session)7 MifosRuntimeException (org.mifos.core.MifosRuntimeException)5 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)5 MifosUser (org.mifos.security.MifosUser)4 UserContext (org.mifos.security.util.UserContext)4 List (java.util.List)3 AccountSearchResultsDto (org.mifos.accounts.util.helpers.AccountSearchResultsDto)3 CustomerSearchDto (org.mifos.customers.business.CustomerSearchDto)3 CustomerSearchResultDto (org.mifos.dto.domain.CustomerSearchResultDto)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HibernateException (org.hibernate.HibernateException)2 ConfigurationException (org.mifos.config.exceptions.ConfigurationException)2 CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)2