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