Search in sources :

Example 6 with HibernateSearchException

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

the class QueryResultAccountIdSearch method getSize.

//---Watch out for closeSession block as the cne commendted out here is no longer in codebase
/*
     * public List accountIdSearch(String searchString,Short officeId) throws
     * SystemException { this.searchString = searchString;
     *
     * try{ Session session=null; session= QuerySession.getSession(); Query
     * query=null; if( officeId.shortValue()==0) {
     * query=session.getNamedQuery(NamedQueryConstants
     * .ACCOUNT_ID_SEARCH_NOOFFICEID);
     * query.setString("SEARCH_STRING",searchString); } else {
     *
     * query=session.getNamedQuery(NamedQueryConstants.ACCOUNT_ID_SEARCH);
     * query.setString("SEARCH_STRING",searchString);
     * query.setShort("OFFICEID",officeId); }
     *
     *
     * list=query.list(); this.queryInputs.setTypes(query.getReturnTypes());
     * dtoBuilder.setInputs(queryInputs); QuerySession.closeSession(session); }
     * catch(HibernateProcessException hpe) { throw new SystemException(); }
     * return list; }
     */
@Override
public int getSize() throws HibernateSearchException {
    try {
        Session 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();
        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 7 with HibernateSearchException

use of org.mifos.framework.exceptions.HibernateSearchException 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 8 with HibernateSearchException

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

the class LegacyAccountDao method search.

public QueryResult search(String queryString, Short officeId) throws PersistenceException {
    AccountBO accountBO = findBySystemId(queryString);
    if (accountBO == null) {
        return null;
    }
    if (accountBO.getType() == AccountTypes.CUSTOMER_ACCOUNT || accountBO.getType() == AccountTypes.INDIVIDUAL_LOAN_ACCOUNT) {
        return null;
    }
    QueryResult queryResult = QueryFactory.getQueryResult(CustomerSearchConstants.LOANACCOUNTIDSEARCH);
    ((QueryResultAccountIdSearch) queryResult).setSearchString(queryString);
    String[] namedQuery = new String[2];
    List<Param> paramList = new ArrayList<Param>();
    QueryInputs queryInputs = new QueryInputs();
    String[] aliasNames = { "customerId", "centerName", "centerGlobalCustNum", "customerType", "branchGlobalNum", "branchName", "loanOfficerName", "loanOffcerGlobalNum", "customerStatus", "groupName", "groupGlobalCustNum", "clientName", "clientGlobalCustNum", "loanGlobalAccountNumber" };
    queryInputs.setPath("org.mifos.customers.business.CustomerSearchDto");
    queryInputs.setAliasNames(aliasNames);
    if (officeId != null) {
        if (officeId.shortValue() == 0) {
            namedQuery[0] = NamedQueryConstants.ACCOUNT_ID_SEARCH_NOOFFICEID_COUNT;
            namedQuery[1] = NamedQueryConstants.ACCOUNT_ID_SEARCH_NOOFFICEID;
        } else {
            namedQuery[0] = NamedQueryConstants.ACCOUNT_ID_SEARCH_COUNT;
            namedQuery[1] = NamedQueryConstants.ACCOUNT_ID_SEARCH;
            paramList.add(typeNameValue("Short", "OFFICEID", officeId));
        }
        paramList.add(typeNameValue("String", "SEARCH_STRING", queryString));
    }
    queryInputs.setQueryStrings(namedQuery);
    queryInputs.setParamList(paramList);
    try {
        queryResult.setQueryInputs(queryInputs);
    } catch (HibernateSearchException e) {
        throw new PersistenceException(e);
    }
    return queryResult;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) QueryResultAccountIdSearch(org.mifos.framework.hibernate.helper.QueryResultAccountIdSearch) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) ArrayList(java.util.ArrayList) Param(org.mifos.customers.util.helpers.Param) QueryInputs(org.mifos.framework.hibernate.helper.QueryInputs) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 9 with HibernateSearchException

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

the class LoanAccountServiceFacadeWebTier method retrieveCustomersThatQualifyForLoans.

@Override
public List<CustomerSearchResultDto> retrieveCustomersThatQualifyForLoans(CustomerSearchDto customerSearchDto, boolean isNewGLIMCreation) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        List<CustomerSearchResultDto> pagedDetails = new ArrayList<CustomerSearchResultDto>();
        QueryResult customerForSavings = customerPersistence.searchGroupClient(customerSearchDto.getSearchTerm(), userContext.getId(), isNewGLIMCreation);
        int position = (customerSearchDto.getPage() - 1) * customerSearchDto.getPageSize();
        List<AccountSearchResultsDto> pagedResults = customerForSavings.get(position, customerSearchDto.getPageSize());
        int i = 1;
        for (AccountSearchResultsDto customerBO : pagedResults) {
            CustomerSearchResultDto customer = new CustomerSearchResultDto();
            customer.setCustomerId(customerBO.getClientId());
            customer.setBranchName(customerBO.getOfficeName());
            customer.setGlobalId(customerBO.getGlobelNo());
            customer.setSearchIndex(i);
            customer.setCenterName(StringUtils.defaultIfEmpty(customerBO.getCenterName(), "--"));
            customer.setGroupName(StringUtils.defaultIfEmpty(customerBO.getGroupName(), "--"));
            customer.setClientName(customerBO.getClientName());
            pagedDetails.add(customer);
            i++;
        }
        return pagedDetails;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    } catch (HibernateSearchException e) {
        throw new MifosRuntimeException(e);
    } catch (ConfigurationException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) AccountSearchResultsDto(org.mifos.accounts.util.helpers.AccountSearchResultsDto) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerSearchResultDto(org.mifos.dto.domain.CustomerSearchResultDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 10 with HibernateSearchException

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

the class LegacyPersonnelDao method getQueryResults.

private QueryResult getQueryResults(List<Param> paramList, String[] namedQuery) throws PersistenceException {
    QueryResult queryResult = QueryFactory.getQueryResult(PersonnelConstants.USER_LIST);
    QueryInputs queryInputs = new QueryInputs();
    queryInputs.setQueryStrings(namedQuery);
    queryInputs.setParamList(paramList);
    queryInputs.setPath("org.mifos.customers.personnel.util.helpers.UserSearchResultsDto");
    queryInputs.setAliasNames(getAliasNames());
    try {
        queryResult.setQueryInputs(queryInputs);
    } catch (HibernateSearchException e) {
        throw new PersistenceException(e);
    }
    return queryResult;
}
Also used : QueryResult(org.mifos.framework.hibernate.helper.QueryResult) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) QueryInputs(org.mifos.framework.hibernate.helper.QueryInputs) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

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