Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Seeya S Kudtarker
Get only specific records of data in Liferay
April 20, 2013 2:53 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

I have a module where I need to fetch only those records from database where the leaveStatus of employee is "pending".
I have used the following code:

@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 all the details - Pending as well as non pending. This I know happens because of the statement in the above code:

employeeDetails= EmployeeLocalServiceUtil.getEmployees(0,totalEmployees); since It fetches all the rows. So how should I structure and modify my code to get only the pending details?

Is there a function available to fetch only the required records?
Rahul Pande
RE: Get only specific records of data in Liferay
April 21, 2013 11:19 PM
Answer

Rahul Pande

Rank: Expert

Posts: 308

Join Date: July 6, 2010

Recent Posts

Hi Seeya,

You can use Dynamic query for this.

Please refer this link.

Thanks
Rahul
Sunil Kulkarni
RE: Get only specific records of data in Liferay
April 22, 2013 12:07 AM
Answer

Sunil Kulkarni

Rank: Junior Member

Posts: 94

Join Date: June 24, 2011

Recent Posts

Hello,

You can also use Custom SQL.

http://www.liferay.com/community/wiki/-/wiki/Main/Custom+queries+in+Liferay+5.2?_36_pageResourcePrimKey=10595112

Thanks.
Seeya S Kudtarker
RE: Get only specific records of data in Liferay
April 22, 2013 2:55 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

Thanks Rahul..
It is much easier implementing the queries using Dyanamic Query.

Regards

Seeya
Seeya S Kudtarker
RE: Get only specific records of data in Liferay
April 22, 2013 2:57 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

Sunil,
Thanks for your reply. emoticon
You should even check dyanamic queries.. It is lot easier..
But I will try implementing your suggestion.
Regards

Seeya
Manish Yadav
RE: Get only specific records of data in Liferay
April 22, 2013 5:33 AM
Answer

Manish Yadav

Rank: Expert

Posts: 469

Join Date: May 26, 2012

Recent Posts

Hi Seeya,
As per your Requirement You can use findByStatus method
In service.xml add following line and run serivce build

1
2<finder name="Status" return-type="Collection">
3            <finder-column name="status" />
4        </finder>




Add Below method in EmployeeLocalServiceImpl class and Run service build one more time

1public List<Employee> findByStatus(String statusOfProject) throws SystemException {
2        return EmployeeUtil.findByStatus(statusOfProject);
3    }


In Your Code you can use below lines

1List<Employee> empListStatusAsPending=EmployeeLocalServiceUtil.findByStatus("pending");
Seeya S Kudtarker
RE: Get only specific records of data in Liferay
April 23, 2013 6:50 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

Manish..
Thanks emoticon