1
19
20 package com.liferay.portlet.journal.service.persistence;
21
22 import com.liferay.portal.SystemException;
23 import com.liferay.portal.kernel.dao.orm.QueryPos;
24 import com.liferay.portal.kernel.dao.orm.QueryUtil;
25 import com.liferay.portal.kernel.dao.orm.SQLQuery;
26 import com.liferay.portal.kernel.dao.orm.Session;
27 import com.liferay.portal.kernel.dao.orm.Type;
28 import com.liferay.portal.kernel.util.OrderByComparator;
29 import com.liferay.portal.kernel.util.StringPool;
30 import com.liferay.portal.kernel.util.StringUtil;
31 import com.liferay.portal.kernel.util.Validator;
32 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
33 import com.liferay.portlet.journal.model.JournalFeed;
34 import com.liferay.portlet.journal.model.impl.JournalFeedImpl;
35 import com.liferay.util.dao.orm.CustomSQLUtil;
36
37 import java.util.Iterator;
38 import java.util.List;
39
40
46 public class JournalFeedFinderImpl
47 extends BasePersistenceImpl implements JournalFeedFinder {
48
49 public static String COUNT_BY_C_G_F_N_D =
50 JournalFeedFinder.class.getName() + ".countByC_G_F_N_D";
51
52 public static String FIND_BY_C_G_F_N_D =
53 JournalFeedFinder.class.getName() + ".findByC_G_F_N_D";
54
55 public int countByKeywords(long companyId, long groupId, String keywords)
56 throws SystemException {
57
58 String[] feedIds = null;
59 String[] names = null;
60 String[] descriptions = null;
61 boolean andOperator = false;
62
63 if (Validator.isNotNull(keywords)) {
64 feedIds = CustomSQLUtil.keywords(keywords, false);
65 names = CustomSQLUtil.keywords(keywords);
66 descriptions = CustomSQLUtil.keywords(keywords);
67 }
68 else {
69 andOperator = true;
70 }
71
72 return countByC_G_F_N_D(
73 companyId, groupId, feedIds, names, descriptions, andOperator);
74 }
75
76 public int countByC_G_F_N_D(
77 long companyId, long groupId, String feedId, String name,
78 String description, boolean andOperator)
79 throws SystemException {
80
81 return countByC_G_F_N_D(
82 companyId, groupId, new String[] {feedId}, new String[] {name},
83 new String[] {description}, andOperator);
84 }
85
86 public int countByC_G_F_N_D(
87 long companyId, long groupId, String[] feedIds, String[] names,
88 String[] descriptions, boolean andOperator)
89 throws SystemException {
90
91 feedIds = CustomSQLUtil.keywords(feedIds, false);
92 names = CustomSQLUtil.keywords(names);
93 descriptions = CustomSQLUtil.keywords(descriptions);
94
95 Session session = null;
96
97 try {
98 session = openSession();
99
100 String sql = CustomSQLUtil.get(COUNT_BY_C_G_F_N_D);
101
102 if (groupId <= 0) {
103 sql = StringUtil.replace(sql, "(groupId = ?) AND", "");
104 }
105
106 sql = CustomSQLUtil.replaceKeywords(
107 sql, "feedId", StringPool.LIKE, false, feedIds);
108 sql = CustomSQLUtil.replaceKeywords(
109 sql, "lower(name)", StringPool.LIKE, false, names);
110 sql = CustomSQLUtil.replaceKeywords(
111 sql, "lower(description)", StringPool.LIKE, true, descriptions);
112
113 sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
114
115 SQLQuery q = session.createSQLQuery(sql);
116
117 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
118
119 QueryPos qPos = QueryPos.getInstance(q);
120
121 qPos.add(companyId);
122
123 if (groupId > 0) {
124 qPos.add(groupId);
125 }
126
127 qPos.add(feedIds, 2);
128 qPos.add(names, 2);
129 qPos.add(descriptions, 2);
130
131 Iterator<Long> itr = q.list().iterator();
132
133 if (itr.hasNext()) {
134 Long count = itr.next();
135
136 if (count != null) {
137 return count.intValue();
138 }
139 }
140
141 return 0;
142 }
143 catch (Exception e) {
144 throw new SystemException(e);
145 }
146 finally {
147 closeSession(session);
148 }
149 }
150
151 public List<JournalFeed> findByKeywords(
152 long companyId, long groupId, String keywords, int start, int end,
153 OrderByComparator obc)
154 throws SystemException {
155
156 String[] feedIds = null;
157 String[] names = null;
158 String[] descriptions = null;
159 boolean andOperator = false;
160
161 if (Validator.isNotNull(keywords)) {
162 feedIds = CustomSQLUtil.keywords(keywords, false);
163 names = CustomSQLUtil.keywords(keywords);
164 descriptions = CustomSQLUtil.keywords(keywords);
165 }
166 else {
167 andOperator = true;
168 }
169
170 return findByC_G_F_N_D(
171 companyId, groupId, feedIds, names, descriptions, andOperator,
172 start, end, obc);
173 }
174
175 public List<JournalFeed> findByC_G_F_N_D(
176 long companyId, long groupId, String feedId, String name,
177 String description, boolean andOperator, int start, int end,
178 OrderByComparator obc)
179 throws SystemException {
180
181 return findByC_G_F_N_D(
182 companyId, groupId, new String[] {feedId}, new String[] {name},
183 new String[] {description}, andOperator, start, end, obc);
184 }
185
186 public List<JournalFeed> findByC_G_F_N_D(
187 long companyId, long groupId, String[] feedIds, String[] names,
188 String[] descriptions, boolean andOperator, int start, int end,
189 OrderByComparator obc)
190 throws SystemException {
191
192 feedIds = CustomSQLUtil.keywords(feedIds, false);
193 names = CustomSQLUtil.keywords(names);
194 descriptions = CustomSQLUtil.keywords(descriptions);
195
196 Session session = null;
197
198 try {
199 session = openSession();
200
201 String sql = CustomSQLUtil.get(FIND_BY_C_G_F_N_D);
202
203 if (groupId <= 0) {
204 sql = StringUtil.replace(sql, "(groupId = ?) AND", "");
205 }
206
207 sql = CustomSQLUtil.replaceKeywords(
208 sql, "feedId", StringPool.LIKE, false, feedIds);
209 sql = CustomSQLUtil.replaceKeywords(
210 sql, "lower(name)", StringPool.LIKE, false, names);
211 sql = CustomSQLUtil.replaceKeywords(
212 sql, "lower(description)", StringPool.LIKE, true, descriptions);
213
214 sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
215 sql = CustomSQLUtil.replaceOrderBy(sql, obc);
216
217 SQLQuery q = session.createSQLQuery(sql);
218
219 q.addEntity("JournalFeed", JournalFeedImpl.class);
220
221 QueryPos qPos = QueryPos.getInstance(q);
222
223 qPos.add(companyId);
224
225 if (groupId > 0) {
226 qPos.add(groupId);
227 }
228
229 qPos.add(feedIds, 2);
230 qPos.add(names, 2);
231 qPos.add(descriptions, 2);
232
233 return (List<JournalFeed>)QueryUtil.list(
234 q, getDialect(), start, end);
235 }
236 catch (Exception e) {
237 throw new SystemException(e);
238 }
239 finally {
240 closeSession(session);
241 }
242 }
243
244 }