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(COUNT_BY_G_F, queryDefinition);
734
735 if (inlineSQLHelper) {
736 sql = InlineSQLHelperUtil.replacePermissionCheck(
737 sql, JournalArticle.class.getName(),
738 "JournalArticle.resourcePrimKey", groupId);
739 }
740
741 sql = StringUtil.replace(
742 sql, "[$FOLDER_ID$]",
743 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
744
745 SQLQuery q = session.createSQLQuery(sql);
746
747 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
748
749 QueryPos qPos = QueryPos.getInstance(q);
750
751 qPos.add(groupId);
752 qPos.add(queryDefinition.getStatus());
753
754 for (int i = 0; i < folderIds.size(); i++) {
755 Long folderId = folderIds.get(i);
756
757 qPos.add(folderId);
758 }
759
760 Iterator<Long> itr = q.iterate();
761
762 if (itr.hasNext()) {
763 Long count = itr.next();
764
765 if (count != null) {
766 return count.intValue();
767 }
768 }
769
770 return 0;
771 }
772 catch (Exception e) {
773 throw new SystemException(e);
774 }
775 finally {
776 closeSession(session);
777 }
778 }
779
780 protected int doCountByG_C_S(
781 long groupId, long classNameId, String ddmStructureKey,
782 QueryDefinition queryDefinition, boolean inlineSQLHelper)
783 throws SystemException {
784
785 Session session = null;
786
787 try {
788 session = openSession();
789
790 String sql = CustomSQLUtil.get(
791 COUNT_BY_G_C_S, queryDefinition, "JournalArticle");
792
793 if (groupId <= 0) {
794 sql = StringUtil.replace(
795 sql, "(groupId = ?) AND", StringPool.BLANK);
796 }
797
798 if (ddmStructureKey.equals(
799 String.valueOf(
800 JournalArticleConstants.CLASSNAME_ID_DEFAULT))) {
801
802 sql = StringUtil.replace(
803 sql, "(structureId = ?)",
804 "((structureId = ?) OR (structureId = '') OR " +
805 "(structureId IS NULL))");
806 }
807
808 if (inlineSQLHelper) {
809 sql = InlineSQLHelperUtil.replacePermissionCheck(
810 sql, JournalArticle.class.getName(),
811 "JournalArticle.resourcePrimKey", groupId);
812 }
813
814 SQLQuery q = session.createSQLQuery(sql);
815
816 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
817
818 QueryPos qPos = QueryPos.getInstance(q);
819
820 if (groupId > 0) {
821 qPos.add(groupId);
822 }
823
824 qPos.add(classNameId);
825 qPos.add(ddmStructureKey);
826 qPos.add(queryDefinition.getStatus());
827
828 Iterator<Long> itr = q.iterate();
829
830 if (itr.hasNext()) {
831 Long count = itr.next();
832
833 if (count != null) {
834 return count.intValue();
835 }
836 }
837
838 return 0;
839 }
840 catch (Exception e) {
841 throw new SystemException(e);
842 }
843 finally {
844 closeSession(session);
845 }
846 }
847
848 protected int doCountByG_U_F_C(
849 long groupId, long userId, List<Long> folderIds, long classNameId,
850 QueryDefinition queryDefinition, boolean inlineSQLHelper)
851 throws SystemException {
852
853 Session session = null;
854
855 try {
856 session = openSession();
857
858 String sql = CustomSQLUtil.get(
859 COUNT_BY_G_U_F_C, queryDefinition, "JournalArticle");
860
861 if (folderIds.isEmpty()) {
862 sql = StringUtil.replace(
863 sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
864 }
865 else {
866 sql = StringUtil.replace(
867 sql, "[$FOLDER_ID$]",
868 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
869 }
870
871 if (inlineSQLHelper) {
872 sql = InlineSQLHelperUtil.replacePermissionCheck(
873 sql, JournalArticle.class.getName(),
874 "JournalArticle.resourcePrimKey", groupId);
875 }
876
877 SQLQuery q = session.createSQLQuery(sql);
878
879 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
880
881 QueryPos qPos = QueryPos.getInstance(q);
882
883 qPos.add(groupId);
884 qPos.add(userId);
885
886 for (long folderId : folderIds) {
887 qPos.add(folderId);
888 }
889
890 qPos.add(classNameId);
891 qPos.add(queryDefinition.getStatus());
892
893 Iterator<Long> itr = q.iterate();
894
895 if (itr.hasNext()) {
896 Long count = itr.next();
897
898 if (count != null) {
899 return count.intValue();
900 }
901 }
902
903 return 0;
904 }
905 catch (Exception e) {
906 throw new SystemException(e);
907 }
908 finally {
909 closeSession(session);
910 }
911 }
912
913 protected int doCountByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
914 long companyId, long groupId, List<Long> folderIds,
915 long classNameId, String[] articleIds, Double version,
916 String[] titles, String[] descriptions, String[] contents,
917 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
918 Date displayDateGT, Date displayDateLT, Date reviewDate,
919 boolean andOperator, QueryDefinition queryDefinition,
920 boolean inlineSQLHelper)
921 throws SystemException {
922
923 articleIds = CustomSQLUtil.keywords(articleIds, false);
924 titles = CustomSQLUtil.keywords(titles);
925 descriptions = CustomSQLUtil.keywords(descriptions, false);
926 contents = CustomSQLUtil.keywords(contents, false);
927 ddmStructureKeys = CustomSQLUtil.keywords(ddmStructureKeys, false);
928 ddmTemplateKeys = CustomSQLUtil.keywords(ddmTemplateKeys, false);
929 Timestamp displayDateGT_TS = CalendarUtil.getTimestamp(displayDateGT);
930 Timestamp displayDateLT_TS = CalendarUtil.getTimestamp(displayDateLT);
931 Timestamp reviewDate_TS = CalendarUtil.getTimestamp(reviewDate);
932
933 Session session = null;
934
935 try {
936 session = openSession();
937
938 String sql = CustomSQLUtil.get(
939 COUNT_BY_C_G_F_C_A_V_T_D_C_T_S_T_D_R, queryDefinition);
940
941 if (groupId <= 0) {
942 sql = StringUtil.replace(
943 sql, "(groupId = ?) AND", StringPool.BLANK);
944 }
945
946 if (folderIds.isEmpty()) {
947 sql = StringUtil.replace(
948 sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
949 }
950 else {
951 sql = StringUtil.replace(
952 sql, "[$FOLDER_ID$]",
953 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
954 }
955
956 sql = CustomSQLUtil.replaceKeywords(
957 sql, "articleId", StringPool.LIKE, false, articleIds);
958
959 if ((version == null) || (version <= 0)) {
960 sql = StringUtil.replace(
961 sql, "(version = ?) [$AND_OR_CONNECTOR$]",
962 StringPool.BLANK);
963 }
964
965 sql = CustomSQLUtil.replaceKeywords(
966 sql, "lower(title)", StringPool.LIKE, false, titles);
967 sql = CustomSQLUtil.replaceKeywords(
968 sql, "description", StringPool.LIKE, false, descriptions);
969 sql = CustomSQLUtil.replaceKeywords(
970 sql, "content", StringPool.LIKE, false, contents);
971
972 if (Validator.isNull(type)) {
973 sql = StringUtil.replace(
974 sql, _TYPE_UNNAMESPACED_SQL, StringPool.BLANK);
975 }
976
977 if (isNullArray(ddmStructureKeys)) {
978 sql = StringUtil.replace(
979 sql, _STRUCTURE_ID_UNNAMESPACED_SQL, StringPool.BLANK);
980 }
981 else {
982 sql = CustomSQLUtil.replaceKeywords(
983 sql, "structureId", StringPool.LIKE, false,
984 ddmStructureKeys);
985 }
986
987 if (isNullArray(ddmTemplateKeys)) {
988 sql = StringUtil.replace(
989 sql, _TEMPLATE_ID_UNNAMESPACED_SQL, StringPool.BLANK);
990 }
991 else {
992 sql = CustomSQLUtil.replaceKeywords(
993 sql, "templateId", StringPool.LIKE, false, ddmTemplateKeys);
994 }
995
996 sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
997
998 if (inlineSQLHelper) {
999 sql = InlineSQLHelperUtil.replacePermissionCheck(
1000 sql, JournalArticle.class.getName(),
1001 "JournalArticle.resourcePrimKey", groupId);
1002
1003 sql = StringUtil.replace(
1004 sql, "(companyId", "(JournalArticle.companyId");
1005 }
1006
1007 SQLQuery q = session.createSQLQuery(sql);
1008
1009 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1010
1011 QueryPos qPos = QueryPos.getInstance(q);
1012
1013 if (groupId > 0) {
1014 qPos.add(groupId);
1015 }
1016
1017 for (long folderId : folderIds) {
1018 qPos.add(folderId);
1019 }
1020
1021 qPos.add(classNameId);
1022 qPos.add(queryDefinition.getStatus());
1023 qPos.add(articleIds, 2);
1024
1025 if ((version != null) && (version > 0)) {
1026 qPos.add(version);
1027 }
1028
1029 qPos.add(titles, 2);
1030 qPos.add(descriptions, 2);
1031 qPos.add(contents, 2);
1032 qPos.add(displayDateGT_TS);
1033 qPos.add(displayDateGT_TS);
1034 qPos.add(displayDateLT_TS);
1035 qPos.add(displayDateLT_TS);
1036 qPos.add(reviewDate_TS);
1037 qPos.add(reviewDate_TS);
1038
1039 if (Validator.isNotNull(type)) {
1040 qPos.add(type);
1041 qPos.add(type);
1042 }
1043
1044 if (!isNullArray(ddmStructureKeys)) {
1045 qPos.add(ddmStructureKeys, 2);
1046 }
1047
1048 if (!isNullArray(ddmTemplateKeys)) {
1049 qPos.add(ddmTemplateKeys, 2);
1050 }
1051
1052 qPos.add(companyId);
1053
1054 Iterator<Long> itr = q.iterate();
1055
1056 if (itr.hasNext()) {
1057 Long count = itr.next();
1058
1059 if (count != null) {
1060 return count.intValue();
1061 }
1062 }
1063
1064 return 0;
1065 }
1066 catch (Exception e) {
1067 throw new SystemException(e);
1068 }
1069 finally {
1070 closeSession(session);
1071 }
1072 }
1073
1074 protected List<JournalArticle> doFindByG_F(
1075 long groupId, List<Long> folderIds, QueryDefinition queryDefinition,
1076 boolean inlineSQLHelper)
1077 throws SystemException {
1078
1079 Session session = null;
1080
1081 try {
1082 session = openSession();
1083
1084 String sql = CustomSQLUtil.get(
1085 FIND_BY_G_F, queryDefinition, "JournalArticle");
1086
1087 sql = CustomSQLUtil.replaceOrderBy(
1088 sql, queryDefinition.getOrderByComparator());
1089
1090 if (inlineSQLHelper) {
1091 sql = InlineSQLHelperUtil.replacePermissionCheck(
1092 sql, JournalArticle.class.getName(),
1093 "JournalArticle.resourcePrimKey", groupId);
1094 }
1095
1096 sql = StringUtil.replace(
1097 sql, "[$FOLDER_ID$]",
1098 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
1099
1100 SQLQuery q = session.createSQLQuery(sql);
1101
1102 q.addEntity(
1103 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
1104
1105 QueryPos qPos = QueryPos.getInstance(q);
1106
1107 qPos.add(groupId);
1108 qPos.add(queryDefinition.getStatus());
1109
1110 for (int i = 0; i < folderIds.size(); i++) {
1111 Long folderId = folderIds.get(i);
1112
1113 qPos.add(folderId);
1114 }
1115
1116 return (List<JournalArticle>)QueryUtil.list(
1117 q, getDialect(), queryDefinition.getStart(),
1118 queryDefinition.getEnd());
1119 }
1120 catch (Exception e) {
1121 throw new SystemException(e);
1122 }
1123 finally {
1124 closeSession(session);
1125 }
1126 }
1127
1128 protected List<JournalArticle> doFindByG_C_S(
1129 long groupId, long classNameId, String ddmStructureKey,
1130 QueryDefinition queryDefinition, boolean inlineSQLHelper)
1131 throws SystemException {
1132
1133 Session session = null;
1134
1135 try {
1136 session = openSession();
1137
1138 String sql = CustomSQLUtil.get(
1139 FIND_BY_G_C_S, queryDefinition, "JournalArticle");
1140
1141 sql = CustomSQLUtil.replaceOrderBy(
1142 sql, queryDefinition.getOrderByComparator());
1143
1144 if (groupId <= 0) {
1145 sql = StringUtil.replace(
1146 sql, "(JournalArticle.groupId = ?) AND", StringPool.BLANK);
1147 }
1148
1149 if (ddmStructureKey.equals(
1150 String.valueOf(
1151 JournalArticleConstants.CLASSNAME_ID_DEFAULT))) {
1152
1153 sql = StringUtil.replace(
1154 sql, "(JournalArticle.structureId = ?)",
1155 "((JournalArticle.structureId = ?) OR " +
1156 "(JournalArticle.structureId = '') OR" +
1157 "(JournalArticle.structureId IS NULL))");
1158 }
1159
1160 if (inlineSQLHelper) {
1161 sql = InlineSQLHelperUtil.replacePermissionCheck(
1162 sql, JournalArticle.class.getName(),
1163 "JournalArticle.resourcePrimKey", groupId);
1164 }
1165
1166 SQLQuery q = session.createSQLQuery(sql);
1167
1168 q.addEntity(
1169 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
1170
1171 QueryPos qPos = QueryPos.getInstance(q);
1172
1173 if (groupId > 0) {
1174 qPos.add(groupId);
1175 }
1176
1177 qPos.add(classNameId);
1178 qPos.add(ddmStructureKey);
1179 qPos.add(queryDefinition.getStatus());
1180
1181 return (List<JournalArticle>)QueryUtil.list(
1182 q, getDialect(), queryDefinition.getStart(),
1183 queryDefinition.getEnd());
1184 }
1185 catch (Exception e) {
1186 throw new SystemException(e);
1187 }
1188 finally {
1189 closeSession(session);
1190 }
1191 }
1192
1193 protected List<JournalArticle> doFindByG_U_F_C(
1194 long groupId, long userId, List<Long> folderIds, long classNameId,
1195 QueryDefinition queryDefinition, boolean inlineSQLHelper)
1196 throws SystemException {
1197
1198 Session session = null;
1199
1200 try {
1201 session = openSession();
1202
1203 String sql = CustomSQLUtil.get(
1204 FIND_BY_G_U_F_C, queryDefinition, "JournalArticle");
1205
1206 sql = CustomSQLUtil.replaceOrderBy(
1207 sql, queryDefinition.getOrderByComparator());
1208
1209 if (folderIds.isEmpty()) {
1210 sql = StringUtil.replace(
1211 sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
1212 }
1213 else {
1214 sql = StringUtil.replace(
1215 sql, "[$FOLDER_ID$]",
1216 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
1217 }
1218
1219 if (inlineSQLHelper) {
1220 sql = InlineSQLHelperUtil.replacePermissionCheck(
1221 sql, JournalArticle.class.getName(),
1222 "JournalArticle.resourcePrimKey", groupId);
1223 }
1224
1225 SQLQuery q = session.createSQLQuery(sql);
1226
1227 q.addEntity(
1228 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
1229
1230 QueryPos qPos = QueryPos.getInstance(q);
1231
1232 qPos.add(groupId);
1233 qPos.add(classNameId);
1234 qPos.add(userId);
1235
1236 for (long folderId : folderIds) {
1237 qPos.add(folderId);
1238 }
1239
1240 qPos.add(queryDefinition.getStatus());
1241
1242 return (List<JournalArticle>)QueryUtil.list(
1243 q, getDialect(), queryDefinition.getStart(),
1244 queryDefinition.getEnd());
1245 }
1246 catch (Exception e) {
1247 throw new SystemException(e);
1248 }
1249 finally {
1250 closeSession(session);
1251 }
1252 }
1253
1254 protected List<JournalArticle> doFindByC_G_F_C_A_V_T_D_C_T_S_T_D_R(
1255 long companyId, long groupId, List<Long> folderIds,
1256 long classNameId, String[] articleIds, Double version,
1257 String[] titles, String[] descriptions, String[] contents,
1258 String type, String[] ddmStructureKeys, String[] ddmTemplateKeys,
1259 Date displayDateGT, Date displayDateLT, Date reviewDate,
1260 boolean andOperator, QueryDefinition queryDefinition,
1261 boolean inlineSQLHelper)
1262 throws SystemException {
1263
1264 articleIds = CustomSQLUtil.keywords(articleIds, false);
1265 titles = CustomSQLUtil.keywords(titles);
1266 descriptions = CustomSQLUtil.keywords(descriptions, false);
1267 contents = CustomSQLUtil.keywords(contents, false);
1268 ddmStructureKeys = CustomSQLUtil.keywords(ddmStructureKeys, false);
1269 ddmTemplateKeys = CustomSQLUtil.keywords(ddmTemplateKeys, false);
1270 Timestamp displayDateGT_TS = CalendarUtil.getTimestamp(displayDateGT);
1271 Timestamp displayDateLT_TS = CalendarUtil.getTimestamp(displayDateLT);
1272 Timestamp reviewDate_TS = CalendarUtil.getTimestamp(reviewDate);
1273
1274 Session session = null;
1275
1276 try {
1277 session = openSession();
1278
1279 String sql = CustomSQLUtil.get(
1280 FIND_BY_C_G_F_C_A_V_T_D_C_T_S_T_D_R, queryDefinition,
1281 "JournalArticle");
1282
1283 if (groupId <= 0) {
1284 sql = StringUtil.replace(
1285 sql, "(JournalArticle.groupId = ?) AND", StringPool.BLANK);
1286 }
1287
1288 if (folderIds.isEmpty()) {
1289 sql = StringUtil.replace(
1290 sql, "([$FOLDER_ID$]) AND", StringPool.BLANK);
1291 }
1292 else {
1293 sql = StringUtil.replace(
1294 sql, "[$FOLDER_ID$]",
1295 getFolderIds(folderIds, JournalArticleImpl.TABLE_NAME));
1296 }
1297
1298 sql = CustomSQLUtil.replaceKeywords(
1299 sql, "JournalArticle.articleId", StringPool.LIKE, false,
1300 articleIds);
1301
1302 if ((version == null) || (version <= 0)) {
1303 sql = StringUtil.replace(
1304 sql, "(JournalArticle.version = ?) [$AND_OR_CONNECTOR$]",
1305 StringPool.BLANK);
1306 }
1307
1308 sql = CustomSQLUtil.replaceKeywords(
1309 sql, "lower(JournalArticle.title)", StringPool.LIKE, false,
1310 titles);
1311 sql = CustomSQLUtil.replaceKeywords(
1312 sql, "JournalArticle.description", StringPool.LIKE, false,
1313 descriptions);
1314 sql = CustomSQLUtil.replaceKeywords(
1315 sql, "JournalArticle.content", StringPool.LIKE, false,
1316 contents);
1317
1318 if (Validator.isNull(type)) {
1319 sql = StringUtil.replace(
1320 sql, _TYPE_NAMESPACED_SQL, StringPool.BLANK);
1321 }
1322
1323 if (isNullArray(ddmStructureKeys)) {
1324 sql = StringUtil.replace(
1325 sql, _STRUCTURE_ID_NAMESPACED_SQL, StringPool.BLANK);
1326 }
1327 else {
1328 sql = CustomSQLUtil.replaceKeywords(
1329 sql, "JournalArticle.structureId", StringPool.LIKE, false,
1330 ddmStructureKeys);
1331 }
1332
1333 if (isNullArray(ddmTemplateKeys)) {
1334 sql = StringUtil.replace(
1335 sql, _TEMPLATE_ID_NAMESPACED_SQL, StringPool.BLANK);
1336 }
1337 else {
1338 sql = CustomSQLUtil.replaceKeywords(
1339 sql, "JournalArticle.templateId", StringPool.LIKE, false,
1340 ddmTemplateKeys);
1341 }
1342
1343 sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
1344 sql = CustomSQLUtil.replaceOrderBy(
1345 sql, queryDefinition.getOrderByComparator());
1346
1347 if (inlineSQLHelper) {
1348 sql = InlineSQLHelperUtil.replacePermissionCheck(
1349 sql, JournalArticle.class.getName(),
1350 "JournalArticle.resourcePrimKey", groupId);
1351
1352 sql = StringUtil.replace(
1353 sql, "(companyId", "(JournalArticle.companyId");
1354 }
1355
1356 SQLQuery q = session.createSQLQuery(sql);
1357
1358 q.addEntity(
1359 JournalArticleImpl.TABLE_NAME, JournalArticleImpl.class);
1360
1361 QueryPos qPos = QueryPos.getInstance(q);
1362
1363 qPos.add(companyId);
1364
1365 if (groupId > 0) {
1366 qPos.add(groupId);
1367 }
1368
1369 for (long folderId : folderIds) {
1370 qPos.add(folderId);
1371 }
1372
1373 qPos.add(classNameId);
1374 qPos.add(queryDefinition.getStatus());
1375 qPos.add(articleIds, 2);
1376
1377 if ((version != null) && (version > 0)) {
1378 qPos.add(version);
1379 }
1380
1381 qPos.add(titles, 2);
1382 qPos.add(descriptions, 2);
1383 qPos.add(contents, 2);
1384 qPos.add(displayDateGT_TS);
1385 qPos.add(displayDateGT_TS);
1386 qPos.add(displayDateLT_TS);
1387 qPos.add(displayDateLT_TS);
1388 qPos.add(reviewDate_TS);
1389 qPos.add(reviewDate_TS);
1390
1391 if (Validator.isNotNull(type)) {
1392 qPos.add(type);
1393 qPos.add(type);
1394 }
1395
1396 if (!isNullArray(ddmStructureKeys)) {
1397 qPos.add(ddmStructureKeys, 2);
1398 }
1399
1400 if (!isNullArray(ddmTemplateKeys)) {
1401 qPos.add(ddmTemplateKeys, 2);
1402 }
1403
1404 return (List<JournalArticle>)QueryUtil.list(
1405 q, getDialect(), queryDefinition.getStart(),
1406 queryDefinition.getEnd());
1407 }
1408 catch (Exception e) {
1409 throw new SystemException(e);
1410 }
1411 finally {
1412 closeSession(session);
1413 }
1414 }
1415
1416 protected String getFolderIds(List<Long> folderIds, String tableName) {
1417 if (folderIds.isEmpty()) {
1418 return StringPool.BLANK;
1419 }
1420
1421 StringBundler sb = new StringBundler(folderIds.size() * 3 + 1);
1422
1423 sb.append(StringPool.OPEN_PARENTHESIS);
1424
1425 for (int i = 0; i < folderIds.size(); i++) {
1426 sb.append(tableName);
1427 sb.append(".folderId = ? ");
1428
1429 if ((i + 1) != folderIds.size()) {
1430 sb.append(WHERE_OR);
1431 }
1432 }
1433
1434 sb.append(StringPool.CLOSE_PARENTHESIS);
1435
1436 return sb.toString();
1437 }
1438
1439 protected JournalArticle getLatestArticle(
1440 long groupId, String articleId, int status)
1441 throws SystemException {
1442
1443 List<JournalArticle> articles = null;
1444
1445 if (status == WorkflowConstants.STATUS_ANY) {
1446 articles = JournalArticleUtil.findByG_A(groupId, articleId, 0, 1);
1447 }
1448 else {
1449 articles = JournalArticleUtil.findByG_A_ST(
1450 groupId, articleId, status, 0, 1);
1451 }
1452
1453 if (articles.isEmpty()) {
1454 return null;
1455 }
1456
1457 return articles.get(0);
1458 }
1459
1460 protected boolean isNullArray(Object[] array) {
1461 if (ArrayUtil.isEmpty(array)) {
1462 return true;
1463 }
1464
1465 for (Object obj : array) {
1466 if (Validator.isNotNull(obj)) {
1467 return false;
1468 }
1469 }
1470
1471 return true;
1472 }
1473
1474 private static final String _STRUCTURE_ID_NAMESPACED_SQL =
1475 "(JournalArticle.structureId LIKE ? [$AND_OR_NULL_CHECK$]) " +
1476 "[$AND_OR_CONNECTOR$]";
1477
1478 private static final String _STRUCTURE_ID_UNNAMESPACED_SQL =
1479 "(structureId LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]";
1480
1481 private static final String _TEMPLATE_ID_NAMESPACED_SQL =
1482 "(JournalArticle.templateId LIKE ? [$AND_OR_NULL_CHECK$]) " +
1483 "[$AND_OR_CONNECTOR$]";
1484
1485 private static final String _TEMPLATE_ID_UNNAMESPACED_SQL =
1486 "(templateId LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]";
1487
1488 private static final String _TYPE_NAMESPACED_SQL =
1489 "(JournalArticle.type_ = ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]";
1490
1491 private static final String _TYPE_UNNAMESPACED_SQL =
1492 "(type_ = ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]";
1493
1494 }