java - Get only specific records of data in Liferay -
i using liferay develop module. part of involves fetching records form database leave status of employees pending. code have fetch "pending" records is:
@suppresswarnings("unchecked") public static list<employee> getemployeedata() throws portalexception, systemexception{ list<employee> employeedetails; try{ int totalemployees = employeelocalserviceutil.getemployeescount(); for(employee emp: employeedetails { if(emp.getempstatus.equals("pending") { employeedetails= employeelocalserviceutil.getemployees(0,totalemployees); } } }catch(systemexception se){ employeedetails = collections.emptylist(); } return employeedetails; }
the above code fetches details - pending non pending. know happens because of statement in above code:
employeedetails= employeelocalserviceutil.getemployees(0,totalemployees);
since fetches rows. how should structure , modify code pending details?
a quick bad practice keeping code change :
list<employee> employeedetails = new arraylist<employee>; try{ list<employees> allemployees = employeelocalserviceutil.getallemployees(); for(employee emp: allemployees { if(emp.getempstatus.equals("pending") { employeedetails.add(emp); } }return employeedetails;
now, correct way :
- add finder, @pankaj kathiriya proposed. then, build services
go employeelocalserviceimpl, , add
public list getallemployeesbyempstatus (string status) { try { return employeepersistence.findbyempstatus(status); } catch (systemexception e) { e.printstacktrace(); return collections.emptylist(); } }
then build service again
replace code with
list employeedetails = employeelocalserviceutil.getallemployeesbyempstatus("pending") ; return employeedetails;
Comments
Post a Comment