001
014
015 package com.liferay.portlet.journal.service.persistence;
016
017 import com.liferay.portal.kernel.dao.orm.QueryDefinition;
018 import com.liferay.portal.kernel.dao.orm.QueryPos;
019 import com.liferay.portal.kernel.dao.orm.QueryUtil;
020 import com.liferay.portal.kernel.dao.orm.SQLQuery;
021 import com.liferay.portal.kernel.dao.orm.Session;
022 import com.liferay.portal.kernel.dao.orm.Type;
023 import com.liferay.portal.kernel.exception.SystemException;
024 import com.liferay.portal.kernel.util.CalendarUtil;
025 import com.liferay.portal.kernel.util.OrderByComparator;
026 import com.liferay.portal.kernel.util.StringBundler;
027 import com.liferay.portal.kernel.util.StringPool;
028 import com.liferay.portal.kernel.util.StringUtil;
029 import com.liferay.portal.kernel.util.Validator;
030 import com.liferay.portal.kernel.workflow.WorkflowConstants;
031 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
032 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
033 import com.liferay.portlet.journal.NoSuchArticleException;
034 import com.liferay.portlet.journal.model.JournalArticle;
035 import com.liferay.portlet.journal.model.JournalArticleConstants;
036 import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
037 import com.liferay.util.dao.orm.CustomSQLUtil;
038
039 import java.sql.Timestamp;
040
041 import java.util.Date;
042 import java.util.Iterator;
043 import java.util.List;
044
045
050 public class JournalArticleFinderImpl
051 extends BasePersistenceImpl<JournalArticle>
052 implements JournalArticleFinder {
053
054 public static final String COUNT_BY_G_F =
055 JournalArticleFinder.class.getName() + ".countByG_F";
056
057 public static final String COUNT_BY_G_C_S =
058 JournalArticleFinder.class.getName() + ".countByG_C_S";
059
060 public static final String COUNT_BY_G_U_F_C =
061 JournalArticleFinder.class.getName() + ".countByG_U_F_C";
062
063 public static final String COUNT_BY_C_G_F_C_A_V_T_D_C_T_S_T_D_R =
064 JournalArticleFinder.class.getName() +
065 ".countByC_G_F_C_A_V_T_D_C_T_S_T_D_R";
066
067 public static final String FIND_BY_EXPIRATION_DATE =
068 JournalArticleFinder.class.getName() + ".findByExpirationDate";
069
070 public static final String FIND_BY_REVIEW_DATE =
071 JournalArticleFinder.class.getName() + ".findByReviewDate";
072
073 public static final String FIND_BY_R_D =
074 JournalArticleFinder.class.getName() + ".findByR_D";
075
076 public static final String FIND_BY_G_F =
077 JournalArticleFinder.class.getName() + ".findByG_F";
078
079 public static final String FIND_BY_G_C_S =
080 JournalArticleFinder.class.getName() + ".findByG_C_S";
081
082 public static final String FIND_BY_G_U_F_C =
083 JournalArticleFinder.class.getName() + ".findByG_U_F_C";
084
085 public static final String FIND_BY_C_G_F_C_A_V_T_D_C_T_S_T_D_R =
086 JournalArticleFinder.class.getName() +
087 ".findByC_G_F_C_A_V_T_D_C_T_S_T_D_R";
088
089 public int countByKeywords(
090 long companyId, long groupId, List<Long> folderIds,
091 long classNameId, String keywords, Double version, String type,
092 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
093 Date displayDateLT, int status, Date reviewDate)
094 throws SystemException {
095
096 String[] articleIds = null;
097 String[] titles = null;
098 String[] descriptions = null;
099 String[] contents = null;
100 String[] ddmStructureKeys = CustomSQLUtil.keywords(
101 ddmStructureKey, false);
102 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
103 ddmTemplateKey, false);
104 boolean andOperator = false;
105
106 if (Validator.isNotNull(keywords)) {
107 articleIds = CustomSQLUtil.keywords(keywords, false);
108 titles = CustomSQLUtil.keywords(keywords);
109 descriptions = CustomSQLUtil.keywords(keywords, false);
110 contents = CustomSQLUtil.keywords(keywords, false);
111 }
112 else {
113 andOperator = true;
114 }
115
116 QueryDefinition queryDefinition = new QueryDefinition(status);
117
118 return doCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
119 companyId, groupId, folderIds, classNameId, articleIds, version,
120 titles, descriptions, contents, type, ddmStructureKeys,
121 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
122 andOperator, queryDefinition, false);
123 }
124
125 public int countByG_F(
126 long groupId, List<Long> folderIds, QueryDefinition queryDefinition)
127 throws SystemException {
128
129 return doCountByG_F(groupId, folderIds, queryDefinition, false);
130 }
131
132 public int countByG_C_S(
133 long groupId, long classNameId, String ddmStructureKey,
134 QueryDefinition queryDefinition)
135 throws SystemException {
136
137 return doCountByG_C_S(
138 groupId, classNameId, ddmStructureKey, queryDefinition, false);
139 }
140
141 public int countByG_U_F_C(
142 long groupId, long userId, List<Long> folderIds, long classNameId,
143 QueryDefinition queryDefinition)
144 throws SystemException {
145
146 return doCountByG_U_F_C(
147 groupId, userId, folderIds, classNameId, queryDefinition, false);
148 }
149
150 public int countByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
151 long companyId, long groupId, List<Long> folderIds,
152 long classNameId, String articleId, Double version, String title,
153 String description, String content, String type,
154 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
155 Date displayDateLT, Date reviewDate, boolean andOperator,
156 QueryDefinition queryDefinition)
157 throws SystemException {
158
159 String[] ddmStructureKeys = CustomSQLUtil.keywords(
160 ddmStructureKey, false);
161 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
162 ddmTemplateKey, false);
163
164 return countByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
165 companyId, groupId, folderIds, classNameId, articleId, version,
166 title, description, content, type, ddmStructureKeys,
167 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
168 andOperator, queryDefinition);
169 }
170
171 public int countByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
172 long companyId, long groupId, List<Long> folderIds,
173 long classNameId, String articleId, Double version, String title,
174 String description, String content, String type,
175 String[] ddmStructureKeys, String[] ddmTemplateKeys,
176 Date displayDateGT, Date displayDateLT, Date reviewDate,
177 boolean andOperator, QueryDefinition queryDefinition)
178 throws SystemException {
179
180 String[] articleIds = CustomSQLUtil.keywords(articleId, false);
181 String[] titles = CustomSQLUtil.keywords(title);
182 String[] descriptions = CustomSQLUtil.keywords(description, false);
183 String[] contents = CustomSQLUtil.keywords(content, false);
184
185 return countByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
186 companyId, groupId, folderIds, classNameId, articleIds, version,
187 titles, descriptions, contents, type, ddmStructureKeys,
188 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
189 andOperator, queryDefinition);
190 }
191
192 public int countByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
193 long companyId, long groupId, List<Long> folderIds,
194 long classNameId, String[] articleIds, Double version,
195 String[] titles, String[] descriptions, String[] contents,
196 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
197 Date displayDateGT, Date displayDateLT, Date reviewDate,
198 boolean andOperator, QueryDefinition queryDefinition)
199 throws SystemException {
200
201 return doCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
202 companyId, groupId, folderIds, classNameId, articleIds, version,
203 titles, descriptions, contents, type, ddmStructureKeys,
204 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
205 andOperator, queryDefinition, false);
206 }
207
208 public int filterCountByKeywords(
209 long companyId, long groupId, List<Long> folderIds,
210 long classNameId, String keywords, Double version, String type,
211 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
212 Date displayDateLT, int status, Date reviewDate)
213 throws SystemException {
214
215 String[] articleIds = null;
216 String[] titles = null;
217 String[] descriptions = null;
218 String[] contents = null;
219 String[] ddmStructureKeys = CustomSQLUtil.keywords(
220 ddmStructureKey, false);
221 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
222 ddmTemplateKey, false);
223 boolean andOperator = false;
224
225 if (Validator.isNotNull(keywords)) {
226 articleIds = CustomSQLUtil.keywords(keywords, false);
227 titles = CustomSQLUtil.keywords(keywords);
228 descriptions = CustomSQLUtil.keywords(keywords, false);
229 contents = CustomSQLUtil.keywords(keywords, false);
230 }
231 else {
232 andOperator = true;
233 }
234
235 QueryDefinition queryDefinition = new QueryDefinition(status);
236
237 return doCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
238 companyId, groupId, folderIds, classNameId, articleIds, version,
239 titles, descriptions, contents, type, ddmStructureKeys,
240 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
241 andOperator, queryDefinition, true);
242 }
243
244 public int filterCountByG_F(
245 long groupId, List<Long> folderIds, QueryDefinition queryDefinition)
246 throws SystemException {
247
248 return doCountByG_F(groupId, folderIds, queryDefinition, true);
249 }
250
251 public int filterCountByG_C_S(
252 long groupId, long classNameId, String ddmStructureKey,
253 QueryDefinition queryDefinition)
254 throws SystemException {
255
256 return doCountByG_C_S(
257 groupId, classNameId, ddmStructureKey, queryDefinition, true);
258 }
259
260 public int filterCountByG_U_F_C(
261 long groupId, long userId, List<Long> folderIds, long classNameId,
262 QueryDefinition queryDefinition)
263 throws SystemException {
264
265 return doCountByG_U_F_C(
266 groupId, userId, folderIds, classNameId, queryDefinition, true);
267 }
268
269 public int filterCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
270 long companyId, long groupId, List<Long> folderIds,
271 long classNameId, String articleId, Double version, String title,
272 String description, String content, String type,
273 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
274 Date displayDateLT, Date reviewDate, boolean andOperator,
275 QueryDefinition queryDefinition)
276 throws SystemException {
277
278 String[] ddmStructureKeys = CustomSQLUtil.keywords(
279 ddmStructureKey, false);
280 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
281 ddmTemplateKey, false);
282
283 return filterCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
284 companyId, groupId, folderIds, classNameId, articleId, version,
285 title, description, content, type, ddmStructureKeys,
286 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
287 andOperator, queryDefinition);
288 }
289
290 public int filterCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
291 long companyId, long groupId, List<Long> folderIds,
292 long classNameId, String articleId, Double version, String title,
293 String description, String content, String type,
294 String[] ddmStructureKeys, String[] ddmTemplateKeys,
295 Date displayDateGT, Date displayDateLT, Date reviewDate,
296 boolean andOperator, QueryDefinition queryDefinition)
297 throws SystemException {
298
299 String[] articleIds = CustomSQLUtil.keywords(articleId, false);
300 String[] titles = CustomSQLUtil.keywords(title);
301 String[] descriptions = CustomSQLUtil.keywords(description, false);
302 String[] contents = CustomSQLUtil.keywords(content, false);
303
304 return filterCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
305 companyId, groupId, folderIds, classNameId, articleIds, version,
306 titles, descriptions, contents, type, ddmStructureKeys,
307 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
308 andOperator, queryDefinition);
309 }
310
311 public int filterCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
312 long companyId, long groupId, List<Long> folderIds,
313 long classNameId, String[] articleIds, Double version,
314 String[] titles, String[] descriptions, String[] contents,
315 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
316 Date displayDateGT, Date displayDateLT, Date reviewDate,
317 boolean andOperator, QueryDefinition queryDefinition)
318 throws SystemException {
319
320 return doCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
321 companyId, groupId, folderIds, classNameId, articleIds, version,
322 titles, descriptions, contents, type, ddmStructureKeys,
323 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
324 andOperator, queryDefinition, true);
325 }
326
327 public List<JournalArticle> filterFindByKeywords(
328 long companyId, long groupId, List<Long> folderIds,
329 long classNameId, String keywords, Double version, String type,
330 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
331 Date displayDateLT, int status, Date reviewDate, int start, int end,
332 OrderByComparator orderByComparator)
333 throws SystemException {
334
335 String[] articleIds = null;
336 String[] titles = null;
337 String[] descriptions = null;
338 String[] contents = null;
339 String[] ddmStructureKeys = CustomSQLUtil.keywords(
340 ddmStructureKey, false);
341 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
342 ddmTemplateKey, false);
343 boolean andOperator = false;
344
345 if (Validator.isNotNull(keywords)) {
346 articleIds = CustomSQLUtil.keywords(keywords, false);
347 titles = CustomSQLUtil.keywords(keywords);
348 descriptions = CustomSQLUtil.keywords(keywords, false);
349 contents = CustomSQLUtil.keywords(keywords, false);
350 }
351 else {
352 andOperator = true;
353 }
354
355 QueryDefinition queryDefinition = new QueryDefinition(
356 status, start, end, orderByComparator);
357
358 return doFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
359 companyId, groupId, folderIds, classNameId, articleIds, version,
360 titles, descriptions, contents, type, ddmStructureKeys,
361 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
362 andOperator, queryDefinition, true);
363 }
364
365 public List<JournalArticle> filterFindByG_F(
366 long groupId, List<Long> folderIds, QueryDefinition queryDefinition)
367 throws SystemException {
368
369 return doFindByG_F(groupId, folderIds, queryDefinition, true);
370 }
371
372 public List<JournalArticle> filterFindByG_C_S(
373 long groupId, long classNameId, String ddmStructureKey,
374 QueryDefinition queryDefinition)
375 throws SystemException {
376
377 return doFindByG_C_S(
378 groupId, classNameId, ddmStructureKey, queryDefinition, true);
379 }
380
381 public List<JournalArticle> filterFindByG_U_F_C(
382 long groupId, long userId, List<Long> folderIds, long classNameId,
383 QueryDefinition queryDefinition)
384 throws SystemException {
385
386 return doFindByG_U_F_C(
387 groupId, userId, folderIds, classNameId, queryDefinition, true);
388 }
389
390 public List<JournalArticle> filterFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
391 long companyId, long groupId, List<Long> folderIds,
392 long classNameId, String articleId, Double version, String title,
393 String description, String content, String type,
394 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
395 Date displayDateLT, Date reviewDate, boolean andOperator,
396 QueryDefinition queryDefinition)
397 throws SystemException {
398
399 String[] ddmStructureKeys = CustomSQLUtil.keywords(
400 ddmStructureKey, false);
401 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
402 ddmTemplateKey, false);
403
404 return filterFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
405 companyId, groupId, folderIds, classNameId, articleId, version,
406 title, description, content, type, ddmStructureKeys,
407 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
408 andOperator, queryDefinition);
409 }
410
411 public List<JournalArticle> filterFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
412 long companyId, long groupId, List<Long> folderIds,
413 long classNameId, String articleId, Double version, String title,
414 String description, String content, String type,
415 String[] ddmStructureKeys, String[] ddmTemplateKeys,
416 Date displayDateGT, Date displayDateLT, Date reviewDate,
417 boolean andOperator, QueryDefinition queryDefinition)
418 throws SystemException {
419
420 String[] articleIds = CustomSQLUtil.keywords(articleId, false);
421 String[] titles = CustomSQLUtil.keywords(title);
422 String[] descriptions = CustomSQLUtil.keywords(description, false);
423 String[] contents = CustomSQLUtil.keywords(content, false);
424
425 return filterFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
426 companyId, groupId, folderIds, classNameId, articleIds, version,
427 titles, descriptions, contents, type, ddmStructureKeys,
428 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
429 andOperator, queryDefinition);
430 }
431
432 public List<JournalArticle> filterFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
433 long companyId, long groupId, List<Long> folderIds,
434 long classNameId, String[] articleIds, Double version,
435 String[] titles, String[] descriptions, String[] contents,
436 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
437 Date displayDateGT, Date displayDateLT, Date reviewDate,
438 boolean andOperator, QueryDefinition queryDefinition)
439 throws SystemException {
440
441 return doFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
442 companyId, groupId, folderIds, classNameId, articleIds, version,
443 titles, descriptions, contents, type, ddmStructureKeys,
444 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
445 andOperator, queryDefinition, true);
446 }
447
448 public List<JournalArticle> findByExpirationDate(
449 long classNameId, Date expirationDateLT,
450 QueryDefinition queryDefinition)
451 throws SystemException {
452
453 Timestamp expirationDateLT_TS = CalendarUtil.getTimestamp(
454 expirationDateLT);
455
456 Session session = null;
457
458 try {
459 session = openSession();
460
461 String sql = CustomSQLUtil.get(
462 FIND_BY_EXPIRATION_DATE, queryDefinition);
463
464 SQLQuery q = session.createSQLQuery(sql);
465
466 q.addEntity(
467 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
468
469 QueryPos qPos = QueryPos.getInstance(q);
470
471 qPos.add(classNameId);
472 qPos.add(queryDefinition.getStatus());
473 qPos.add(expirationDateLT_TS);
474
475 return q.list(true);
476 }
477 catch (Exception e) {
478 throw new SystemException(e);
479 }
480 finally {
481 closeSession(session);
482 }
483 }
484
485 public List<JournalArticle> findByKeywords(
486 long companyId, long groupId, List<Long> folderIds,
487 long classNameId, String keywords, Double version, String type,
488 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
489 Date displayDateLT, int status, Date reviewDate, int start, int end,
490 OrderByComparator orderByComparator)
491 throws SystemException {
492
493 String[] articleIds = null;
494 String[] titles = null;
495 String[] descriptions = null;
496 String[] contents = null;
497 String[] ddmStructureKeys = CustomSQLUtil.keywords(
498 ddmStructureKey, false);
499 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
500 ddmTemplateKey, false);
501 boolean andOperator = false;
502
503 if (Validator.isNotNull(keywords)) {
504 articleIds = CustomSQLUtil.keywords(keywords, false);
505 titles = CustomSQLUtil.keywords(keywords);
506 descriptions = CustomSQLUtil.keywords(keywords, false);
507 contents = CustomSQLUtil.keywords(keywords, false);
508 }
509 else {
510 andOperator = true;
511 }
512
513 QueryDefinition queryDefinition = new QueryDefinition(
514 status, start, end, orderByComparator);
515
516 return findByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
517 companyId, groupId, folderIds, classNameId, articleIds, version,
518 titles, descriptions, contents, type, ddmStructureKeys,
519 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
520 andOperator, queryDefinition);
521 }
522
523 public List<JournalArticle> findByReviewDate(
524 long classNameId, Date reviewDateLT, Date reviewDateGT)
525 throws SystemException {
526
527 Timestamp reviewDateLT_TS = CalendarUtil.getTimestamp(reviewDateLT);
528 Timestamp reviewDateGT_TS = CalendarUtil.getTimestamp(reviewDateGT);
529
530 Session session = null;
531 try {
532 session = openSession();
533
534 String sql = CustomSQLUtil.get(FIND_BY_REVIEW_DATE);
535
536 SQLQuery q = session.createSQLQuery(sql);
537
538 q.addEntity(
539 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
540
541 QueryPos qPos = QueryPos.getInstance(q);
542
543 qPos.add(classNameId);
544 qPos.add(reviewDateGT_TS);
545 qPos.add(reviewDateLT_TS);
546
547 return q.list(true);
548 }
549 catch (Exception e) {
550 throw new SystemException(e);
551 }
552 finally {
553 closeSession(session);
554 }
555 }
556
557 public JournalArticle findByR_D(long resourcePrimKey, Date displayDate)
558 throws NoSuchArticleException, SystemException {
559
560 Timestamp displayDate_TS = CalendarUtil.getTimestamp(displayDate);
561
562 Session session = null;
563
564 try {
565 session = openSession();
566
567 String sql = CustomSQLUtil.get(FIND_BY_R_D);
568
569 SQLQuery q = session.createSQLQuery(sql);
570
571 q.addEntity(
572 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
573
574 QueryPos qPos = QueryPos.getInstance(q);
575
576 qPos.add(resourcePrimKey);
577 qPos.add(displayDate_TS);
578
579 List<JournalArticle> articles = q.list();
580
581 if (!articles.isEmpty()) {
582 return articles.get(0);
583 }
584 }
585 catch (Exception e) {
586 throw new SystemException(e);
587 }
588 finally {
589 closeSession(session);
590 }
591
592 StringBundler sb = new StringBundler(6);
593
594 sb.append("No JournalArticle exists with the key ");
595 sb.append("{resourcePrimKey=");
596 sb.append(resourcePrimKey);
597 sb.append(", displayDate=");
598 sb.append(displayDate);
599 sb.append("}");
600
601 throw new NoSuchArticleException(sb.toString());
602 }
603
604 public List<JournalArticle> findByG_F(
605 long groupId, List<Long> folderIds, QueryDefinition queryDefinition)
606 throws SystemException {
607
608 return doFindByG_F(groupId, folderIds, queryDefinition, false);
609 }
610
611 public List<JournalArticle> findByG_C_S(
612 long groupId, long classNameId, String ddmStructureKey,
613 QueryDefinition queryDefinition)
614 throws SystemException {
615
616 return doFindByG_C_S(
617 groupId, classNameId, ddmStructureKey, queryDefinition, false);
618 }
619
620 public List<JournalArticle> findByG_U_F_C(
621 long groupId, long userId, List<Long> folderIds, long classNameId,
622 QueryDefinition queryDefinition)
623 throws SystemException {
624
625 return doFindByG_U_F_C(
626 groupId, userId, folderIds, classNameId, queryDefinition, false);
627 }
628
629 public List<JournalArticle> findByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
630 long companyId, long groupId, List<Long> folderIds,
631 long classNameId, String articleId, Double version, String title,
632 String description, String content, String type,
633 String ddmStructureKey, String ddmTemplateKey, Date displayDateGT,
634 Date displayDateLT, Date reviewDate, boolean andOperator,
635 QueryDefinition queryDefinition)
636 throws SystemException {
637
638 String[] articleIds = CustomSQLUtil.keywords(articleId, false);
639 String[] titles = CustomSQLUtil.keywords(title);
640 String[] descriptions = CustomSQLUtil.keywords(description, false);
641 String[] contents = CustomSQLUtil.keywords(content, false);
642 String[] ddmStructureKeys = CustomSQLUtil.keywords(
643 ddmStructureKey, false);
644 String[] ddmTemplateKeys = CustomSQLUtil.keywords(
645 ddmTemplateKey, false);
646
647 return findByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
648 companyId, groupId, folderIds, classNameId, articleIds, version,
649 titles, descriptions, contents, type, ddmStructureKeys,
650 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
651 andOperator, queryDefinition);
652 }
653
654 public List<JournalArticle> findByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
655 long companyId, long groupId, List<Long> folderIds,
656 long classNameId, String articleId, Double version, String title,
657 String description, String content, String type,
658 String[] ddmStructureKeys, String[] ddmTemplateKeys,
659 Date displayDateGT, Date displayDateLT, Date reviewDate,
660 boolean andOperator, QueryDefinition queryDefinition)
661 throws SystemException {
662
663 String[] articleIds = CustomSQLUtil.keywords(articleId, false);
664 String[] titles = CustomSQLUtil.keywords(title);
665 String[] descriptions = CustomSQLUtil.keywords(description, false);
666 String[] contents = CustomSQLUtil.keywords(content, false);
667
668 return findByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
669 companyId, groupId, folderIds, classNameId, articleIds, version,
670 titles, descriptions, contents, type, ddmStructureKeys,
671 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
672 andOperator, queryDefinition);
673 }
674
675 public List<JournalArticle> findByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
676 long companyId, long groupId, List<Long> folderIds,
677 long classNameId, String[] articleIds, Double version,
678 String[] titles, String[] descriptions, String[] contents,
679 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
680 Date displayDateGT, Date displayDateLT, Date reviewDate,
681 boolean andOperator, QueryDefinition queryDefinition)
682 throws SystemException {
683
684 return doFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
685 companyId, groupId, folderIds, classNameId, articleIds, version,
686 titles, descriptions, contents, type, ddmStructureKeys,
687 ddmTemplateKeys, displayDateGT, displayDateLT, reviewDate,
688 andOperator, queryDefinition, false);
689 }
690
691 protected int doCountByG_F(
692 long groupId, List<Long> folderIds, QueryDefinition queryDefinition,
693 boolean inlineSQLHelper)
694 throws SystemException {
695
696 Session session = null;
697
698 try {
699 session = openSession();
700
701 String sql = CustomSQLUtil.get(COUNT_BY_G_F, queryDefinition);
702
703 if (inlineSQLHelper) {
704 sql = InlineSQLHelperUtil.replacePermissionCheck(
705 sql, JournalArticle.class.getName(),
706 "JournalArticle.resourcePrimKey", groupId);
707 }
708
709 sql = StringUtil.replace(
710 sql, "[$FOLDER_ID$]",
711 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
712
713 SQLQuery q = session.createSQLQuery(sql);
714
715 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
716
717 QueryPos qPos = QueryPos.getInstance(q);
718
719 qPos.add(groupId);
720 qPos.add(queryDefinition.getStatus());
721
722 for (int i = 0; i < folderIds.size(); i++) {
723 Long folderId = folderIds.get(i);
724
725 qPos.add(folderId);
726 }
727
728 Iterator<Long> itr = q.iterate();
729
730 if (itr.hasNext()) {
731 Long count = itr.next();
732
733 if (count != null) {
734 return count.intValue();
735 }
736 }
737
738 return 0;
739 }
740 catch (Exception e) {
741 throw new SystemException(e);
742 }
743 finally {
744 closeSession(session);
745 }
746 }
747
748 protected int doCountByG_C_S(
749 long groupId, long classNameId, String ddmStructureKey,
750 QueryDefinition queryDefinition, boolean inlineSQLHelper)
751 throws SystemException {
752
753 Session session = null;
754
755 try {
756 session = openSession();
757
758 String sql = CustomSQLUtil.get(
759 COUNT_BY_G_C_S, queryDefinition, "JournalArticle");
760
761 if (ddmStructureKey.equals(
762 String.valueOf(
763 JournalArticleConstants.CLASSNAME_ID_DEFAULT))) {
764
765 sql = StringUtil.replace(
766 sql, "(structureId = ?)",
767 "((structureId = ?) OR (structureId = '') OR " +
768 "(structureId IS NULL))");
769 }
770
771 if (inlineSQLHelper) {
772 sql = InlineSQLHelperUtil.replacePermissionCheck(
773 sql, JournalArticle.class.getName(),
774 "JournalArticle.resourcePrimKey", groupId);
775 }
776
777 SQLQuery q = session.createSQLQuery(sql);
778
779 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
780
781 QueryPos qPos = QueryPos.getInstance(q);
782
783 qPos.add(groupId);
784 qPos.add(classNameId);
785 qPos.add(ddmStructureKey);
786 qPos.add(queryDefinition.getStatus());
787
788 Iterator<Long> itr = q.iterate();
789
790 if (itr.hasNext()) {
791 Long count = itr.next();
792
793 if (count != null) {
794 return count.intValue();
795 }
796 }
797
798 return 0;
799 }
800 catch (Exception e) {
801 throw new SystemException(e);
802 }
803 finally {
804 closeSession(session);
805 }
806 }
807
808 protected int doCountByG_U_F_C(
809 long groupId, long userId, List<Long> folderIds, long classNameId,
810 QueryDefinition queryDefinition, boolean inlineSQLHelper)
811 throws SystemException {
812
813 Session session = null;
814
815 try {
816 session = openSession();
817
818 String sql = CustomSQLUtil.get(
819 COUNT_BY_G_U_F_C, queryDefinition, "JournalArticle");
820
821 if (folderIds.isEmpty()) {
822 sql = StringUtil.replace(
823 sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
824 }
825 else {
826 sql = StringUtil.replace(
827 sql, "[$FOLDER_ID$]",
828 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
829 }
830
831 if (inlineSQLHelper) {
832 sql = InlineSQLHelperUtil.replacePermissionCheck(
833 sql, JournalArticle.class.getName(),
834 "JournalArticle.resourcePrimKey", groupId);
835 }
836
837 SQLQuery q = session.createSQLQuery(sql);
838
839 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
840
841 QueryPos qPos = QueryPos.getInstance(q);
842
843 qPos.add(groupId);
844 qPos.add(userId);
845
846 for (long folderId : folderIds) {
847 qPos.add(folderId);
848 }
849
850 qPos.add(classNameId);
851 qPos.add(queryDefinition.getStatus());
852
853 Iterator<Long> itr = q.iterate();
854
855 if (itr.hasNext()) {
856 Long count = itr.next();
857
858 if (count != null) {
859 return count.intValue();
860 }
861 }
862
863 return 0;
864 }
865 catch (Exception e) {
866 throw new SystemException(e);
867 }
868 finally {
869 closeSession(session);
870 }
871 }
872
873 protected int doCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
874 long companyId, long groupId, List<Long> folderIds,
875 long classNameId, String[] articleIds, Double version,
876 String[] titles, String[] descriptions, String[] contents,
877 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
878 Date displayDateGT, Date displayDateLT, Date reviewDate,
879 boolean andOperator, QueryDefinition queryDefinition,
880 boolean inlineSQLHelper)
881 throws SystemException {
882
883 articleIds = CustomSQLUtil.keywords(articleIds, false);
884 titles = CustomSQLUtil.keywords(titles);
885 descriptions = CustomSQLUtil.keywords(descriptions, false);
886 contents = CustomSQLUtil.keywords(contents, false);
887 ddmStructureKeys = CustomSQLUtil.keywords(ddmStructureKeys, false);
888 ddmTemplateKeys = CustomSQLUtil.keywords(ddmTemplateKeys, false);
889 Timestamp displayDateGT_TS = CalendarUtil.getTimestamp(displayDateGT);
890 Timestamp displayDateLT_TS = CalendarUtil.getTimestamp(displayDateLT);
891 Timestamp reviewDate_TS = CalendarUtil.getTimestamp(reviewDate);
892
893 Session session = null;
894
895 try {
896 session = openSession();
897
898 String sql = CustomSQLUtil.get(
899 COUNT_BY_C_G_F_C_A_V_T_D_C_T_S_T_D_R, queryDefinition);
900
901 if (groupId <= 0) {
902 sql = StringUtil.replace(
903 sql, "(groupId = ?) AND", StringPool.BLANK);
904 }
905
906 if (folderIds.isEmpty()) {
907 sql = StringUtil.replace(
908 sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
909 }
910 else {
911 sql = StringUtil.replace(
912 sql, "[$FOLDER_ID$]",
913 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
914 }
915
916 sql = CustomSQLUtil.replaceKeywords(
917 sql, "articleId", StringPool.LIKE, false, articleIds);
918
919 if ((version == null) || (version <= 0)) {
920 sql = StringUtil.replace(
921 sql, "(version = ?) [$AND_OR_CONNECTOR$]",
922 StringPool.BLANK);
923 }
924
925 sql = CustomSQLUtil.replaceKeywords(
926 sql, "lower(title)", StringPool.LIKE, false, titles);
927 sql = CustomSQLUtil.replaceKeywords(
928 sql, "description", StringPool.LIKE, false, descriptions);
929 sql = CustomSQLUtil.replaceKeywords(
930 sql, "content", StringPool.LIKE, false, contents);
931
932 if (Validator.isNull(type)) {
933 sql = StringUtil.replace(
934 sql, _TYPE_UNNAMESPACED_SQL, StringPool.BLANK);
935 }
936
937 if (isNullArray(ddmStructureKeys)) {
938 sql = StringUtil.replace(
939 sql, _STRUCTURE_ID_UNNAMESPACED_SQL, StringPool.BLANK);
940 }
941 else {
942 sql = CustomSQLUtil.replaceKeywords(
943 sql, "structureId", StringPool.LIKE, false,
944 ddmStructureKeys);
945 }
946
947 if (isNullArray(ddmTemplateKeys)) {
948 sql = StringUtil.replace(
949 sql, _TEMPLATE_ID_UNNAMESPACED_SQL, StringPool.BLANK);
950 }
951 else {
952 sql = CustomSQLUtil.replaceKeywords(
953 sql, "templateId", StringPool.LIKE, false, ddmTemplateKeys);
954 }
955
956 sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
957
958 if (inlineSQLHelper) {
959 sql = InlineSQLHelperUtil.replacePermissionCheck(
960 sql, JournalArticle.class.getName(),
961 "JournalArticle.resourcePrimKey", groupId);
962
963 sql = StringUtil.replace(
964 sql, "(companyId", "(JournalArticle.companyId");
965 }
966
967 SQLQuery q = session.createSQLQuery(sql);
968
969 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
970
971 QueryPos qPos = QueryPos.getInstance(q);
972
973 if (groupId > 0) {
974 qPos.add(groupId);
975 }
976
977 for (long folderId : folderIds) {
978 qPos.add(folderId);
979 }
980
981 qPos.add(classNameId);
982 qPos.add(queryDefinition.getStatus());
983 qPos.add(articleIds, 2);
984
985 if ((version != null) && (version > 0)) {
986 qPos.add(version);
987 }
988
989 qPos.add(titles, 2);
990 qPos.add(descriptions, 2);
991 qPos.add(contents, 2);
992 qPos.add(displayDateGT_TS);
993 qPos.add(displayDateGT_TS);
994 qPos.add(displayDateLT_TS);
995 qPos.add(displayDateLT_TS);
996 qPos.add(reviewDate_TS);
997 qPos.add(reviewDate_TS);
998
999 if (Validator.isNotNull(type)) {
1000 qPos.add(type);
1001 qPos.add(type);
1002 }
1003
1004 if (!isNullArray(ddmStructureKeys)) {
1005 qPos.add(ddmStructureKeys, 2);
1006 }
1007
1008 if (!isNullArray(ddmTemplateKeys)) {
1009 qPos.add(ddmTemplateKeys, 2);
1010 }
1011
1012 qPos.add(companyId);
1013
1014 Iterator<Long> itr = q.iterate();
1015
1016 if (itr.hasNext()) {
1017 Long count = itr.next();
1018
1019 if (count != null) {
1020 return count.intValue();
1021 }
1022 }
1023
1024 return 0;
1025 }
1026 catch (Exception e) {
1027 throw new SystemException(e);
1028 }
1029 finally {
1030 closeSession(session);
1031 }
1032 }
1033
1034 protected List<JournalArticle> doFindByG_F(
1035 long groupId, List<Long> folderIds, QueryDefinition queryDefinition,
1036 boolean inlineSQLHelper)
1037 throws SystemException {
1038
1039 Session session = null;
1040
1041 try {
1042 session = openSession();
1043
1044 String sql = CustomSQLUtil.get(
1045 FIND_BY_G_F, queryDefinition, "JournalArticle");
1046
1047 sql = CustomSQLUtil.replaceOrderBy(
1048 sql, queryDefinition.getOrderByComparator());
1049
1050 if (inlineSQLHelper) {
1051 sql = InlineSQLHelperUtil.replacePermissionCheck(
1052 sql, JournalArticle.class.getName(),
1053 "JournalArticle.resourcePrimKey", groupId);
1054 }
1055
1056 sql = StringUtil.replace(
1057 sql, "[$FOLDER_ID$]",
1058 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
1059
1060 SQLQuery q = session.createSQLQuery(sql);
1061
1062 q.addEntity(
1063 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
1064
1065 QueryPos qPos = QueryPos.getInstance(q);
1066
1067 qPos.add(groupId);
1068 qPos.add(queryDefinition.getStatus());
1069
1070 for (int i = 0; i < folderIds.size(); i++) {
1071 Long folderId = folderIds.get(i);
1072
1073 qPos.add(folderId);
1074 }
1075
1076 return (List<JournalArticle>)QueryUtil.list(
1077 q, getDialect(), queryDefinition.getStart(),
1078 queryDefinition.getEnd());
1079 }
1080 catch (Exception e) {
1081 throw new SystemException(e);
1082 }
1083 finally {
1084 closeSession(session);
1085 }
1086 }
1087
1088 protected List<JournalArticle> doFindByG_C_S(
1089 long groupId, long classNameId, String ddmStructureKey,
1090 QueryDefinition queryDefinition, boolean inlineSQLHelper)
1091 throws SystemException {
1092
1093 Session session = null;
1094
1095 try {
1096 session = openSession();
1097
1098 String sql = CustomSQLUtil.get(
1099 FIND_BY_G_C_S, queryDefinition, "JournalArticle");
1100
1101 sql = CustomSQLUtil.replaceOrderBy(
1102 sql, queryDefinition.getOrderByComparator());
1103
1104 if (ddmStructureKey.equals(
1105 String.valueOf(
1106 JournalArticleConstants.CLASSNAME_ID_DEFAULT))) {
1107
1108 sql = StringUtil.replace(
1109 sql, "(JournalArticle.structureId = ?)",
1110 "((JournalArticle.structureId = ?) OR " +
1111 "(JournalArticle.structureId = '') OR" +
1112 "(JournalArticle.structureId IS NULL))");
1113 }
1114
1115 if (inlineSQLHelper) {
1116 sql = InlineSQLHelperUtil.replacePermissionCheck(
1117 sql, JournalArticle.class.getName(),
1118 "JournalArticle.resourcePrimKey", groupId);
1119 }
1120
1121 SQLQuery q = session.createSQLQuery(sql);
1122
1123 q.addEntity(
1124 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
1125
1126 QueryPos qPos = QueryPos.getInstance(q);
1127
1128 qPos.add(groupId);
1129 qPos.add(classNameId);
1130 qPos.add(ddmStructureKey);
1131 qPos.add(queryDefinition.getStatus());
1132
1133 return (List<JournalArticle>)QueryUtil.list(
1134 q, getDialect(), queryDefinition.getStart(),
1135 queryDefinition.getEnd());
1136 }
1137 catch (Exception e) {
1138 throw new SystemException(e);
1139 }
1140 finally {
1141 closeSession(session);
1142 }
1143 }
1144
1145 protected List<JournalArticle> doFindByG_U_F_C(
1146 long groupId, long userId, List<Long> folderIds, long classNameId,
1147 QueryDefinition queryDefinition, boolean inlineSQLHelper)
1148 throws SystemException {
1149
1150 Session session = null;
1151
1152 try {
1153 session = openSession();
1154
1155 String sql = CustomSQLUtil.get(
1156 FIND_BY_G_U_F_C, queryDefinition, "JournalArticle");
1157
1158 sql = CustomSQLUtil.replaceOrderBy(
1159 sql, queryDefinition.getOrderByComparator());
1160
1161 if (folderIds.isEmpty()) {
1162 sql = StringUtil.replace(
1163 sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
1164 }
1165 else {
1166 sql = StringUtil.replace(
1167 sql, "[$FOLDER_ID$]",
1168 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
1169 }
1170
1171 if (inlineSQLHelper) {
1172 sql = InlineSQLHelperUtil.replacePermissionCheck(
1173 sql, JournalArticle.class.getName(),
1174 "JournalArticle.resourcePrimKey", groupId);
1175 }
1176
1177 SQLQuery q = session.createSQLQuery(sql);
1178
1179 q.addEntity(
1180 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
1181
1182 QueryPos qPos = QueryPos.getInstance(q);
1183
1184 qPos.add(groupId);
1185 qPos.add(classNameId);
1186 qPos.add(userId);
1187
1188 for (long folderId : folderIds) {
1189 qPos.add(folderId);
1190 }
1191
1192 qPos.add(queryDefinition.getStatus());
1193
1194 return (List<JournalArticle>)QueryUtil.list(
1195 q, getDialect(), queryDefinition.getStart(),
1196 queryDefinition.getEnd());
1197 }
1198 catch (Exception e) {
1199 throw new SystemException(e);
1200 }
1201 finally {
1202 closeSession(session);
1203 }
1204 }
1205
1206 protected List<JournalArticle> doFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
1207 long companyId, long groupId, List<Long> folderIds,
1208 long classNameId, String[] articleIds, Double version,
1209 String[] titles, String[] descriptions, String[] contents,
1210 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
1211 Date displayDateGT, Date displayDateLT, Date reviewDate,
1212 boolean andOperator, QueryDefinition queryDefinition,
1213 boolean inlineSQLHelper)
1214 throws SystemException {
1215
1216 articleIds = CustomSQLUtil.keywords(articleIds, false);
1217 titles = CustomSQLUtil.keywords(titles);
1218 descriptions = CustomSQLUtil.keywords(descriptions, false);
1219 contents = CustomSQLUtil.keywords(contents, false);
1220 ddmStructureKeys = CustomSQLUtil.keywords(ddmStructureKeys, false);
1221 ddmTemplateKeys = CustomSQLUtil.keywords(ddmTemplateKeys, false);
1222 Timestamp displayDateGT_TS = CalendarUtil.getTimestamp(displayDateGT);
1223 Timestamp displayDateLT_TS = CalendarUtil.getTimestamp(displayDateLT);
1224 Timestamp reviewDate_TS = CalendarUtil.getTimestamp(reviewDate);
1225
1226 Session session = null;
1227
1228 try {
1229 session = openSession();
1230
1231 String sql = CustomSQLUtil.get(
1232 FIND_BY_C_G_F_C_A_V_T_D_C_T_S_T_D_R, queryDefinition,
1233 "JournalArticle");
1234
1235 if (groupId <= 0) {
1236 sql = StringUtil.replace(
1237 sql, "(JournalArticle.groupId = ?) AND", StringPool.BLANK);
1238 }
1239
1240 if (folderIds.isEmpty()) {
1241 sql = StringUtil.replace(
1242 sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
1243 }
1244 else {
1245 sql = StringUtil.replace(
1246 sql, "[$FOLDER_ID$]",
1247 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
1248 }
1249
1250 sql = CustomSQLUtil.replaceKeywords(
1251 sql, "JournalArticle.articleId", StringPool.LIKE, false,
1252 articleIds);
1253
1254 if ((version == null) || (version <= 0)) {
1255 sql = StringUtil.replace(
1256 sql, "(JournalArticle.version = ?) [$AND_OR_CONNECTOR$]",
1257 StringPool.BLANK);
1258 }
1259
1260 sql = CustomSQLUtil.replaceKeywords(
1261 sql, "lower(JournalArticle.title)", StringPool.LIKE, false,
1262 titles);
1263 sql = CustomSQLUtil.replaceKeywords(
1264 sql, "JournalArticle.description", StringPool.LIKE, false,
1265 descriptions);
1266 sql = CustomSQLUtil.replaceKeywords(
1267 sql, "JournalArticle.content", StringPool.LIKE, false,
1268 contents);
1269
1270 if (Validator.isNull(type)) {
1271 sql = StringUtil.replace(
1272 sql, _TYPE_NAMESPACED_SQL, StringPool.BLANK);
1273 }
1274
1275 if (isNullArray(ddmStructureKeys)) {
1276 sql = StringUtil.replace(
1277 sql, _STRUCTURE_ID_NAMESPACED_SQL, StringPool.BLANK);
1278 }
1279 else {
1280 sql = CustomSQLUtil.replaceKeywords(
1281 sql, "JournalArticle.structureId", StringPool.LIKE, false,
1282 ddmStructureKeys);
1283 }
1284
1285 if (isNullArray(ddmTemplateKeys)) {
1286 sql = StringUtil.replace(
1287 sql, _TEMPLATE_ID_NAMESPACED_SQL, StringPool.BLANK);
1288 }
1289 else {
1290 sql = CustomSQLUtil.replaceKeywords(
1291 sql, "JournalArticle.templateId", StringPool.LIKE, false,
1292 ddmTemplateKeys);
1293 }
1294
1295 sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
1296 sql = CustomSQLUtil.replaceOrderBy(
1297 sql, queryDefinition.getOrderByComparator());
1298
1299 if (inlineSQLHelper) {
1300 sql = InlineSQLHelperUtil.replacePermissionCheck(
1301 sql, JournalArticle.class.getName(),
1302 "JournalArticle.resourcePrimKey", groupId);
1303
1304 sql = StringUtil.replace(
1305 sql, "(companyId", "(JournalArticle.companyId");
1306 }
1307
1308 SQLQuery q = session.createSQLQuery(sql);
1309
1310 q.addEntity(
1311 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
1312
1313 QueryPos qPos = QueryPos.getInstance(q);
1314
1315 qPos.add(companyId);
1316
1317 if (groupId > 0) {
1318 qPos.add(groupId);
1319 }
1320
1321 for (long folderId : folderIds) {
1322 qPos.add(folderId);
1323 }
1324
1325 qPos.add(classNameId);
1326 qPos.add(queryDefinition.getStatus());
1327 qPos.add(articleIds, 2);
1328
1329 if ((version != null) && (version > 0)) {
1330 qPos.add(version);
1331 }
1332
1333 qPos.add(titles, 2);
1334 qPos.add(descriptions, 2);
1335 qPos.add(contents, 2);
1336 qPos.add(displayDateGT_TS);
1337 qPos.add(displayDateGT_TS);
1338 qPos.add(displayDateLT_TS);
1339 qPos.add(displayDateLT_TS);
1340 qPos.add(reviewDate_TS);
1341 qPos.add(reviewDate_TS);
1342
1343 if (Validator.isNotNull(type)) {
1344 qPos.add(type);
1345 qPos.add(type);
1346 }
1347
1348 if (!isNullArray(ddmStructureKeys)) {
1349 qPos.add(ddmStructureKeys, 2);
1350 }
1351
1352 if (!isNullArray(ddmTemplateKeys)) {
1353 qPos.add(ddmTemplateKeys, 2);
1354 }
1355
1356 return (List<JournalArticle>)QueryUtil.list(
1357 q, getDialect(), queryDefinition.getStart(),
1358 queryDefinition.getEnd());
1359 }
1360 catch (Exception e) {
1361 throw new SystemException(e);
1362 }
1363 finally {
1364 closeSession(session);
1365 }
1366 }
1367
1368 protected String getFolderIds(List<Long> folderIds, String tableName) {
1369 if (folderIds.isEmpty()) {
1370 return StringPool.BLANK;
1371 }
1372
1373 StringBundler sb = new StringBundler(folderIds.size() * 3 + 1);
1374
1375 sb.append(StringPool.OPEN_PARENTHESIS);
1376
1377 for (int i = 0; i < folderIds.size(); i++) {
1378 sb.append(tableName);
1379 sb.append(".folderId = ? ");
1380
1381 if ((i + 1) != folderIds.size()) {
1382 sb.append(WHERE_OR);
1383 }
1384 }
1385
1386 sb.append(StringPool.CLOSE_PARENTHESIS);
1387
1388 return sb.toString();
1389 }
1390
1391 protected JournalArticle getLatestArticle(
1392 long groupId, String articleId, int status)
1393 throws SystemException {
1394
1395 List<JournalArticle> articles = null;
1396
1397 if (status == WorkflowConstants.STATUS_ANY) {
1398 articles = JournalArticleUtil.findByG_A(groupId, articleId, 0, 1);
1399 }
1400 else {
1401 articles = JournalArticleUtil.findByG_A_ST(
1402 groupId, articleId, status, 0, 1);
1403 }
1404
1405 if (articles.isEmpty()) {
1406 return null;
1407 }
1408
1409 return articles.get(0);
1410 }
1411
1412 protected boolean isNullArray(Object[] array) {
1413 if ((array == null) || (array.length == 0)) {
1414 return true;
1415 }
1416
1417 for (Object obj : array) {
1418 if (Validator.isNotNull(obj)) {
1419 return false;
1420 }
1421 }
1422
1423 return true;
1424 }
1425
1426 private static final String _STRUCTURE_ID_NAMESPACED_SQL =
1427 "(JournalArticle.structureId LIKE ? [$AND_OR_NULL_CHECK$]) " +
1428 "[$AND_OR_CONNECTOR$]";
1429
1430 private static final String _STRUCTURE_ID_UNNAMESPACED_SQL =
1431 "(structureId LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]";
1432
1433 private static final String _TEMPLATE_ID_NAMESPACED_SQL =
1434 "(JournalArticle.templateId LIKE ? [$AND_OR_NULL_CHECK$]) " +
1435 "[$AND_OR_CONNECTOR$]";
1436
1437 private static final String _TEMPLATE_ID_UNNAMESPACED_SQL =
1438 "(templateId LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]";
1439
1440 private static final String _TYPE_NAMESPACED_SQL =
1441 "(JournalArticle.type_ = ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]";
1442
1443 private static final String _TYPE_UNNAMESPACED_SQL =
1444 "(type_ = ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]";
1445
1446 }