30 August, 2011

Dynamic Query

Hope this will be useful !!!!


DynamicQuery query = DynamicQueryFactoryUtil.forClass(User.class, PortalClassLoaderUtil.getClassLoader());
query.addOrder(OrderFactoryUtil.desc("userId"));
List<User> result = UserLocalServiceUtil.dynamicQuery(query);
for(User userList : result){
           System.out.println("....................."+userList.getFirstName());
}





                                   OR 

DynamicQuery query = DynamicQueryFactoryUtil
                                                                .forClass(QuestionGroup.class);
 Criterion defaultCompanyId = RestrictionsFactoryUtil.eq("companyId",
                    Utility.getDefaultCompanyId(request));
  Criterion companyId = RestrictionsFactoryUtil.eq("companyId", Utility
                                                                .getCompanyId(request));
  Criterion criterion = RestrictionsFactoryUtil.or(defaultCompanyId,
                                                                companyId);
 criterion = RestrictionsFactoryUtil.and(criterion,
                            PropertyFactoryUtil.forName("subjectId").eq(subjectId));
                                query.add(criterion);

Stay tuned for more complex query using dynamic query API !!!


Popular Posts

Featured Post

Liferay 7.3 compatibility matrix

Compatibility Matrix Liferay's general policy is to test Liferay Portal CE against newer major releases of operating systems, open s...