I have a solution for it: -
RawSql rawSql = RawSqlBuilder .parse ("SELECT different CASE WHEN PARENT_EQUIPMENT_NUMBER NULL THEN EQUIPMENT_NUMBER ELSE PARENT_EQUIPMENT_NUMBER END AS PARENT_EQUIPMENT_NUMBER" + "FROM TOOLS_DETAILS"). Create ();
Query<ToolsDetail> query = Ebean.find(ToolsDetail.class); ExpressionList<ToolsDetail> expressionList = query.setRawSql(rawSql).where();//ToolsDetail.find.where(); if (StringUtils.isNotBlank(sortBy)) { if (StringUtils.isNotBlank(sortMode) && sortMode.equals("descending")) { expressionList.setOrderBy("LPAD("+sortBy+", 20) "+"desc"); //expressionList.orderBy().asc(sortBy); }else if (StringUtils.isNotBlank(sortMode) && sortMode.equals("ascending")) { expressionList.setOrderBy("LPAD("+sortBy+", 20) "+"asc"); // expressionList.orderBy().asc(sortBy); } else { expressionList.setOrderBy("LPAD("+sortBy+", 20) "+"desc"); } } if (StringUtils.isNotBlank(fullTextSearch)) { fullTextSearch = fullTextSearch.replaceAll("\\*","%"); expressionList.disjunction() .ilike("customerSerialNumber", fullTextSearch) .ilike("organizationalReference", fullTextSearch) .ilike("costCentre", fullTextSearch) .ilike("inventoryKey", fullTextSearch) .ilike("toolType", fullTextSearch); } //add filters for date range String fromContractStartdate = Controller.request().getQueryString("fm_contract_start_date_from"); String toContractStartdate = Controller.request().getQueryString("fm_contract_start_date_to"); String fromContractEndtdate = Controller.request().getQueryString("fm_contract_end_date_from"); String toContractEnddate = Controller.request().getQueryString("fm_contract_end_date_to"); if(StringUtils.isNotBlank(fromContractStartdate) && StringUtils.isNotBlank(toContractStartdate)) { Date fromSqlStartDate=new Date(AppUtils.convertStringToDate(fromContractStartdate).getTime()); Date toSqlStartDate=new Date(AppUtils.convertStringToDate(toContractStartdate).getTime()); expressionList.between("fmContractStartDate",fromSqlStartDate,toSqlStartDate); }if(StringUtils.isNotBlank(fromContractEndtdate) && StringUtils.isNotBlank(toContractEnddate)) { Date fromSqlEndDate=new Date(AppUtils.convertStringToDate(fromContractEndtdate).getTime()); Date toSqlEndDate=new Date(AppUtils.convertStringToDate(toContractEnddate).getTime()); expressionList.between("fmContractEndDate",fromSqlEndDate,toSqlEndDate); } PagedList pagedList = ToolsQueryFilter.getFilter().applyFilters(expressionList).findPagedList(pageNo-1, pageSize); ToolsListCount toolsListCount = new ToolsListCount(); toolsListCount.setList(pagedList.getList()); toolsListCount.setCount(pagedList.getTotalRowCount()); return toolsListCount;
Anant Khurana
source share