23 October 2012

Dynamic Query examples

 DynamicQuery query = DynamicQueryFactoryUtil.forClass(Subcription.class);
                    query.addOrder(OrderFactoryUtil.desc("createDate"));
                    query.add(RestrictionsFactoryUtil.eq("companyId", themeDisplay.getCompanyId()));
                    query.add(RestrictionsFactoryUtil.eq("groupId", themeDisplay.getScopeGroupId()));
                    query.add(RestrictionsFactoryUtil.eq("mdn", MDN));
                results=SubcriptionLocalServiceUtil.dynamicQuery(query);


DynamicQuery query = DynamicQueryFactoryUtil.forClass(Subcription.class);

                query.add(RestrictionsFactoryUtil.between("crdDate", fromDate, toDate));
                if(packtype!=-1 && packtype!=0)
                {
                query.add(RestrictionsFactoryUtil.eq("packageId", packtype));
                }
                if(!subscriptiontype.equals("") && !subscriptiontype.equals("ALL"))
                {
                DynamicQuery CustomerQuery = DynamicQueryFactoryUtil.forClass(Customer.class, "cus").setProjection(ProjectionFactoryUtil.property("cus.userId")).add(PropertyFactoryUtil.forName("cus.subscriptionType").eq(subscriptiontype));
                query.add(PropertyFactoryUtil.forName("userId").in(CustomerQuery));
                }

No comments: