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