1
22
23 package com.liferay.portlet.shopping.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.orm.QueryPos;
27 import com.liferay.portal.kernel.dao.orm.QueryUtil;
28 import com.liferay.portal.kernel.dao.orm.SQLQuery;
29 import com.liferay.portal.kernel.dao.orm.Session;
30 import com.liferay.portal.kernel.dao.orm.Type;
31 import com.liferay.portal.kernel.util.StringUtil;
32 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
33 import com.liferay.portlet.shopping.model.ShoppingCoupon;
34 import com.liferay.portlet.shopping.model.impl.ShoppingCouponImpl;
35 import com.liferay.util.dao.orm.CustomSQLUtil;
36
37 import java.util.Iterator;
38 import java.util.List;
39
40
45 public class ShoppingCouponFinderImpl
46 extends BasePersistenceImpl implements ShoppingCouponFinder {
47
48 public static String COUNT_BY_G_C_C_A_DT =
49 ShoppingCouponFinder.class.getName() + ".countByG_C_C_A_DT";
50
51 public static String FIND_BY_G_C_C_A_DT =
52 ShoppingCouponFinder.class.getName() + ".findByG_C_C_A_DT";
53
54 public int countByG_C_C_A_DT(
55 long groupId, long companyId, String code, boolean active,
56 String discountType, boolean andOperator)
57 throws SystemException {
58
59 code = StringUtil.upperCase(code);
60
61 Session session = null;
62
63 try {
64 session = openSession();
65
66 String sql = CustomSQLUtil.get(COUNT_BY_G_C_C_A_DT);
67
68 sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
69
70 SQLQuery q = session.createSQLQuery(sql);
71
72 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
73
74 QueryPos qPos = QueryPos.getInstance(q);
75
76 qPos.add(groupId);
77 qPos.add(companyId);
78 qPos.add(code);
79 qPos.add(code);
80 qPos.add(active);
81 qPos.add(discountType);
82 qPos.add(discountType);
83
84 Iterator<Long> itr = q.list().iterator();
85
86 if (itr.hasNext()) {
87 Long count = itr.next();
88
89 if (count != null) {
90 return count.intValue();
91 }
92 }
93
94 return 0;
95 }
96 catch (Exception e) {
97 throw new SystemException(e);
98 }
99 finally {
100 closeSession(session);
101 }
102 }
103
104 public List<ShoppingCoupon> findByG_C_C_A_DT(
105 long groupId, long companyId, String code, boolean active,
106 String discountType, boolean andOperator, int start, int end)
107 throws SystemException {
108
109 code = StringUtil.upperCase(code);
110
111 Session session = null;
112
113 try {
114 session = openSession();
115
116 String sql = CustomSQLUtil.get(FIND_BY_G_C_C_A_DT);
117
118 sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
119
120 SQLQuery q = session.createSQLQuery(sql);
121
122 q.addEntity("ShoppingCoupon", ShoppingCouponImpl.class);
123
124 QueryPos qPos = QueryPos.getInstance(q);
125
126 qPos.add(groupId);
127 qPos.add(companyId);
128 qPos.add(code);
129 qPos.add(code);
130 qPos.add(active);
131 qPos.add(discountType);
132 qPos.add(discountType);
133
134 return (List<ShoppingCoupon>)QueryUtil.list(
135 q, getDialect(), start, end);
136 }
137 catch (Exception e) {
138 throw new SystemException(e);
139 }
140 finally {
141 closeSession(session);
142 }
143 }
144
145 }