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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations