001
014
015 package com.liferay.portlet.journal.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.SQLQuery;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.SetUtil;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.CacheModel;
040 import com.liferay.portal.model.ModelListener;
041 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import com.liferay.portlet.journal.NoSuchTemplateException;
045 import com.liferay.portlet.journal.model.JournalTemplate;
046 import com.liferay.portlet.journal.model.impl.JournalTemplateImpl;
047 import com.liferay.portlet.journal.model.impl.JournalTemplateModelImpl;
048
049 import java.io.Serializable;
050
051 import java.util.ArrayList;
052 import java.util.Collections;
053 import java.util.List;
054 import java.util.Set;
055
056
068 public class JournalTemplatePersistenceImpl extends BasePersistenceImpl<JournalTemplate>
069 implements JournalTemplatePersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = JournalTemplateImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
081 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
082 JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083 "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
085 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
086 JournalTemplateImpl.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
089 JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
092 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
093 JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
094 "findByUuid",
095 new String[] {
096 String.class.getName(),
097
098 Integer.class.getName(), Integer.class.getName(),
099 OrderByComparator.class.getName()
100 });
101 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
102 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
103 JournalTemplateImpl.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
105 new String[] { String.class.getName() },
106 JournalTemplateModelImpl.UUID_COLUMN_BITMASK |
107 JournalTemplateModelImpl.TEMPLATEID_COLUMN_BITMASK);
108 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
109 JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
111 new String[] { String.class.getName() });
112
113
120 public List<JournalTemplate> findByUuid(String uuid)
121 throws SystemException {
122 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123 }
124
125
138 public List<JournalTemplate> findByUuid(String uuid, int start, int end)
139 throws SystemException {
140 return findByUuid(uuid, start, end, null);
141 }
142
143
157 public List<JournalTemplate> findByUuid(String uuid, int start, int end,
158 OrderByComparator orderByComparator) throws SystemException {
159 boolean pagination = true;
160 FinderPath finderPath = null;
161 Object[] finderArgs = null;
162
163 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
164 (orderByComparator == null)) {
165 pagination = false;
166 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
167 finderArgs = new Object[] { uuid };
168 }
169 else {
170 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
171 finderArgs = new Object[] { uuid, start, end, orderByComparator };
172 }
173
174 List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
175 finderArgs, this);
176
177 if ((list != null) && !list.isEmpty()) {
178 for (JournalTemplate journalTemplate : list) {
179 if (!Validator.equals(uuid, journalTemplate.getUuid())) {
180 list = null;
181
182 break;
183 }
184 }
185 }
186
187 if (list == null) {
188 StringBundler query = null;
189
190 if (orderByComparator != null) {
191 query = new StringBundler(3 +
192 (orderByComparator.getOrderByFields().length * 3));
193 }
194 else {
195 query = new StringBundler(3);
196 }
197
198 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
199
200 boolean bindUuid = false;
201
202 if (uuid == null) {
203 query.append(_FINDER_COLUMN_UUID_UUID_1);
204 }
205 else if (uuid.equals(StringPool.BLANK)) {
206 query.append(_FINDER_COLUMN_UUID_UUID_3);
207 }
208 else {
209 bindUuid = true;
210
211 query.append(_FINDER_COLUMN_UUID_UUID_2);
212 }
213
214 if (orderByComparator != null) {
215 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
216 orderByComparator);
217 }
218 else
219 if (pagination) {
220 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
221 }
222
223 String sql = query.toString();
224
225 Session session = null;
226
227 try {
228 session = openSession();
229
230 Query q = session.createQuery(sql);
231
232 QueryPos qPos = QueryPos.getInstance(q);
233
234 if (bindUuid) {
235 qPos.add(uuid);
236 }
237
238 if (!pagination) {
239 list = (List<JournalTemplate>)QueryUtil.list(q,
240 getDialect(), start, end, false);
241
242 Collections.sort(list);
243
244 list = new UnmodifiableList<JournalTemplate>(list);
245 }
246 else {
247 list = (List<JournalTemplate>)QueryUtil.list(q,
248 getDialect(), start, end);
249 }
250
251 cacheResult(list);
252
253 FinderCacheUtil.putResult(finderPath, finderArgs, list);
254 }
255 catch (Exception e) {
256 FinderCacheUtil.removeResult(finderPath, finderArgs);
257
258 throw processException(e);
259 }
260 finally {
261 closeSession(session);
262 }
263 }
264
265 return list;
266 }
267
268
277 public JournalTemplate findByUuid_First(String uuid,
278 OrderByComparator orderByComparator)
279 throws NoSuchTemplateException, SystemException {
280 JournalTemplate journalTemplate = fetchByUuid_First(uuid,
281 orderByComparator);
282
283 if (journalTemplate != null) {
284 return journalTemplate;
285 }
286
287 StringBundler msg = new StringBundler(4);
288
289 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
290
291 msg.append("uuid=");
292 msg.append(uuid);
293
294 msg.append(StringPool.CLOSE_CURLY_BRACE);
295
296 throw new NoSuchTemplateException(msg.toString());
297 }
298
299
307 public JournalTemplate fetchByUuid_First(String uuid,
308 OrderByComparator orderByComparator) throws SystemException {
309 List<JournalTemplate> list = findByUuid(uuid, 0, 1, orderByComparator);
310
311 if (!list.isEmpty()) {
312 return list.get(0);
313 }
314
315 return null;
316 }
317
318
327 public JournalTemplate findByUuid_Last(String uuid,
328 OrderByComparator orderByComparator)
329 throws NoSuchTemplateException, SystemException {
330 JournalTemplate journalTemplate = fetchByUuid_Last(uuid,
331 orderByComparator);
332
333 if (journalTemplate != null) {
334 return journalTemplate;
335 }
336
337 StringBundler msg = new StringBundler(4);
338
339 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
340
341 msg.append("uuid=");
342 msg.append(uuid);
343
344 msg.append(StringPool.CLOSE_CURLY_BRACE);
345
346 throw new NoSuchTemplateException(msg.toString());
347 }
348
349
357 public JournalTemplate fetchByUuid_Last(String uuid,
358 OrderByComparator orderByComparator) throws SystemException {
359 int count = countByUuid(uuid);
360
361 List<JournalTemplate> list = findByUuid(uuid, count - 1, count,
362 orderByComparator);
363
364 if (!list.isEmpty()) {
365 return list.get(0);
366 }
367
368 return null;
369 }
370
371
381 public JournalTemplate[] findByUuid_PrevAndNext(long id, String uuid,
382 OrderByComparator orderByComparator)
383 throws NoSuchTemplateException, SystemException {
384 JournalTemplate journalTemplate = findByPrimaryKey(id);
385
386 Session session = null;
387
388 try {
389 session = openSession();
390
391 JournalTemplate[] array = new JournalTemplateImpl[3];
392
393 array[0] = getByUuid_PrevAndNext(session, journalTemplate, uuid,
394 orderByComparator, true);
395
396 array[1] = journalTemplate;
397
398 array[2] = getByUuid_PrevAndNext(session, journalTemplate, uuid,
399 orderByComparator, false);
400
401 return array;
402 }
403 catch (Exception e) {
404 throw processException(e);
405 }
406 finally {
407 closeSession(session);
408 }
409 }
410
411 protected JournalTemplate getByUuid_PrevAndNext(Session session,
412 JournalTemplate journalTemplate, String uuid,
413 OrderByComparator orderByComparator, boolean previous) {
414 StringBundler query = null;
415
416 if (orderByComparator != null) {
417 query = new StringBundler(6 +
418 (orderByComparator.getOrderByFields().length * 6));
419 }
420 else {
421 query = new StringBundler(3);
422 }
423
424 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
425
426 boolean bindUuid = false;
427
428 if (uuid == null) {
429 query.append(_FINDER_COLUMN_UUID_UUID_1);
430 }
431 else if (uuid.equals(StringPool.BLANK)) {
432 query.append(_FINDER_COLUMN_UUID_UUID_3);
433 }
434 else {
435 bindUuid = true;
436
437 query.append(_FINDER_COLUMN_UUID_UUID_2);
438 }
439
440 if (orderByComparator != null) {
441 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
442
443 if (orderByConditionFields.length > 0) {
444 query.append(WHERE_AND);
445 }
446
447 for (int i = 0; i < orderByConditionFields.length; i++) {
448 query.append(_ORDER_BY_ENTITY_ALIAS);
449 query.append(orderByConditionFields[i]);
450
451 if ((i + 1) < orderByConditionFields.length) {
452 if (orderByComparator.isAscending() ^ previous) {
453 query.append(WHERE_GREATER_THAN_HAS_NEXT);
454 }
455 else {
456 query.append(WHERE_LESSER_THAN_HAS_NEXT);
457 }
458 }
459 else {
460 if (orderByComparator.isAscending() ^ previous) {
461 query.append(WHERE_GREATER_THAN);
462 }
463 else {
464 query.append(WHERE_LESSER_THAN);
465 }
466 }
467 }
468
469 query.append(ORDER_BY_CLAUSE);
470
471 String[] orderByFields = orderByComparator.getOrderByFields();
472
473 for (int i = 0; i < orderByFields.length; i++) {
474 query.append(_ORDER_BY_ENTITY_ALIAS);
475 query.append(orderByFields[i]);
476
477 if ((i + 1) < orderByFields.length) {
478 if (orderByComparator.isAscending() ^ previous) {
479 query.append(ORDER_BY_ASC_HAS_NEXT);
480 }
481 else {
482 query.append(ORDER_BY_DESC_HAS_NEXT);
483 }
484 }
485 else {
486 if (orderByComparator.isAscending() ^ previous) {
487 query.append(ORDER_BY_ASC);
488 }
489 else {
490 query.append(ORDER_BY_DESC);
491 }
492 }
493 }
494 }
495 else {
496 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
497 }
498
499 String sql = query.toString();
500
501 Query q = session.createQuery(sql);
502
503 q.setFirstResult(0);
504 q.setMaxResults(2);
505
506 QueryPos qPos = QueryPos.getInstance(q);
507
508 if (bindUuid) {
509 qPos.add(uuid);
510 }
511
512 if (orderByComparator != null) {
513 Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
514
515 for (Object value : values) {
516 qPos.add(value);
517 }
518 }
519
520 List<JournalTemplate> list = q.list();
521
522 if (list.size() == 2) {
523 return list.get(1);
524 }
525 else {
526 return null;
527 }
528 }
529
530
536 public void removeByUuid(String uuid) throws SystemException {
537 for (JournalTemplate journalTemplate : findByUuid(uuid,
538 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
539 remove(journalTemplate);
540 }
541 }
542
543
550 public int countByUuid(String uuid) throws SystemException {
551 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
552
553 Object[] finderArgs = new Object[] { uuid };
554
555 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
556 this);
557
558 if (count == null) {
559 StringBundler query = new StringBundler(2);
560
561 query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
562
563 boolean bindUuid = false;
564
565 if (uuid == null) {
566 query.append(_FINDER_COLUMN_UUID_UUID_1);
567 }
568 else if (uuid.equals(StringPool.BLANK)) {
569 query.append(_FINDER_COLUMN_UUID_UUID_3);
570 }
571 else {
572 bindUuid = true;
573
574 query.append(_FINDER_COLUMN_UUID_UUID_2);
575 }
576
577 String sql = query.toString();
578
579 Session session = null;
580
581 try {
582 session = openSession();
583
584 Query q = session.createQuery(sql);
585
586 QueryPos qPos = QueryPos.getInstance(q);
587
588 if (bindUuid) {
589 qPos.add(uuid);
590 }
591
592 count = (Long)q.uniqueResult();
593
594 FinderCacheUtil.putResult(finderPath, finderArgs, count);
595 }
596 catch (Exception e) {
597 FinderCacheUtil.removeResult(finderPath, finderArgs);
598
599 throw processException(e);
600 }
601 finally {
602 closeSession(session);
603 }
604 }
605
606 return count.intValue();
607 }
608
609 private static final String _FINDER_COLUMN_UUID_UUID_1 = "journalTemplate.uuid IS NULL";
610 private static final String _FINDER_COLUMN_UUID_UUID_2 = "journalTemplate.uuid = ?";
611 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(journalTemplate.uuid IS NULL OR journalTemplate.uuid = '')";
612 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
613 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
614 JournalTemplateImpl.class, FINDER_CLASS_NAME_ENTITY,
615 "fetchByUUID_G",
616 new String[] { String.class.getName(), Long.class.getName() },
617 JournalTemplateModelImpl.UUID_COLUMN_BITMASK |
618 JournalTemplateModelImpl.GROUPID_COLUMN_BITMASK);
619 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
620 JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
621 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
622 new String[] { String.class.getName(), Long.class.getName() });
623
624
633 public JournalTemplate findByUUID_G(String uuid, long groupId)
634 throws NoSuchTemplateException, SystemException {
635 JournalTemplate journalTemplate = fetchByUUID_G(uuid, groupId);
636
637 if (journalTemplate == null) {
638 StringBundler msg = new StringBundler(6);
639
640 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
641
642 msg.append("uuid=");
643 msg.append(uuid);
644
645 msg.append(", groupId=");
646 msg.append(groupId);
647
648 msg.append(StringPool.CLOSE_CURLY_BRACE);
649
650 if (_log.isWarnEnabled()) {
651 _log.warn(msg.toString());
652 }
653
654 throw new NoSuchTemplateException(msg.toString());
655 }
656
657 return journalTemplate;
658 }
659
660
668 public JournalTemplate fetchByUUID_G(String uuid, long groupId)
669 throws SystemException {
670 return fetchByUUID_G(uuid, groupId, true);
671 }
672
673
682 public JournalTemplate fetchByUUID_G(String uuid, long groupId,
683 boolean retrieveFromCache) throws SystemException {
684 Object[] finderArgs = new Object[] { uuid, groupId };
685
686 Object result = null;
687
688 if (retrieveFromCache) {
689 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
690 finderArgs, this);
691 }
692
693 if (result instanceof JournalTemplate) {
694 JournalTemplate journalTemplate = (JournalTemplate)result;
695
696 if (!Validator.equals(uuid, journalTemplate.getUuid()) ||
697 (groupId != journalTemplate.getGroupId())) {
698 result = null;
699 }
700 }
701
702 if (result == null) {
703 StringBundler query = new StringBundler(4);
704
705 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
706
707 boolean bindUuid = false;
708
709 if (uuid == null) {
710 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
711 }
712 else if (uuid.equals(StringPool.BLANK)) {
713 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
714 }
715 else {
716 bindUuid = true;
717
718 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
719 }
720
721 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
722
723 String sql = query.toString();
724
725 Session session = null;
726
727 try {
728 session = openSession();
729
730 Query q = session.createQuery(sql);
731
732 QueryPos qPos = QueryPos.getInstance(q);
733
734 if (bindUuid) {
735 qPos.add(uuid);
736 }
737
738 qPos.add(groupId);
739
740 List<JournalTemplate> list = q.list();
741
742 if (list.isEmpty()) {
743 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
744 finderArgs, list);
745 }
746 else {
747 JournalTemplate journalTemplate = list.get(0);
748
749 result = journalTemplate;
750
751 cacheResult(journalTemplate);
752
753 if ((journalTemplate.getUuid() == null) ||
754 !journalTemplate.getUuid().equals(uuid) ||
755 (journalTemplate.getGroupId() != groupId)) {
756 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
757 finderArgs, journalTemplate);
758 }
759 }
760 }
761 catch (Exception e) {
762 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
763 finderArgs);
764
765 throw processException(e);
766 }
767 finally {
768 closeSession(session);
769 }
770 }
771
772 if (result instanceof List<?>) {
773 return null;
774 }
775 else {
776 return (JournalTemplate)result;
777 }
778 }
779
780
788 public JournalTemplate removeByUUID_G(String uuid, long groupId)
789 throws NoSuchTemplateException, SystemException {
790 JournalTemplate journalTemplate = findByUUID_G(uuid, groupId);
791
792 return remove(journalTemplate);
793 }
794
795
803 public int countByUUID_G(String uuid, long groupId)
804 throws SystemException {
805 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
806
807 Object[] finderArgs = new Object[] { uuid, groupId };
808
809 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
810 this);
811
812 if (count == null) {
813 StringBundler query = new StringBundler(3);
814
815 query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
816
817 boolean bindUuid = false;
818
819 if (uuid == null) {
820 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
821 }
822 else if (uuid.equals(StringPool.BLANK)) {
823 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
824 }
825 else {
826 bindUuid = true;
827
828 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
829 }
830
831 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
832
833 String sql = query.toString();
834
835 Session session = null;
836
837 try {
838 session = openSession();
839
840 Query q = session.createQuery(sql);
841
842 QueryPos qPos = QueryPos.getInstance(q);
843
844 if (bindUuid) {
845 qPos.add(uuid);
846 }
847
848 qPos.add(groupId);
849
850 count = (Long)q.uniqueResult();
851
852 FinderCacheUtil.putResult(finderPath, finderArgs, count);
853 }
854 catch (Exception e) {
855 FinderCacheUtil.removeResult(finderPath, finderArgs);
856
857 throw processException(e);
858 }
859 finally {
860 closeSession(session);
861 }
862 }
863
864 return count.intValue();
865 }
866
867 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "journalTemplate.uuid IS NULL AND ";
868 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "journalTemplate.uuid = ? AND ";
869 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(journalTemplate.uuid IS NULL OR journalTemplate.uuid = '') AND ";
870 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "journalTemplate.groupId = ?";
871 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
872 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
873 JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
874 "findByUuid_C",
875 new String[] {
876 String.class.getName(), Long.class.getName(),
877
878 Integer.class.getName(), Integer.class.getName(),
879 OrderByComparator.class.getName()
880 });
881 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
882 new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
883 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
884 JournalTemplateImpl.class,
885 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
886 new String[] { String.class.getName(), Long.class.getName() },
887 JournalTemplateModelImpl.UUID_COLUMN_BITMASK |
888 JournalTemplateModelImpl.COMPANYID_COLUMN_BITMASK |
889 JournalTemplateModelImpl.TEMPLATEID_COLUMN_BITMASK);
890 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
891 JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
892 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
893 new String[] { String.class.getName(), Long.class.getName() });
894
895
903 public List<JournalTemplate> findByUuid_C(String uuid, long companyId)
904 throws SystemException {
905 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
906 QueryUtil.ALL_POS, null);
907 }
908
909
923 public List<JournalTemplate> findByUuid_C(String uuid, long companyId,
924 int start, int end) throws SystemException {
925 return findByUuid_C(uuid, companyId, start, end, null);
926 }
927
928
943 public List<JournalTemplate> findByUuid_C(String uuid, long companyId,
944 int start, int end, OrderByComparator orderByComparator)
945 throws SystemException {
946 boolean pagination = true;
947 FinderPath finderPath = null;
948 Object[] finderArgs = null;
949
950 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
951 (orderByComparator == null)) {
952 pagination = false;
953 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
954 finderArgs = new Object[] { uuid, companyId };
955 }
956 else {
957 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
958 finderArgs = new Object[] {
959 uuid, companyId,
960
961 start, end, orderByComparator
962 };
963 }
964
965 List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
966 finderArgs, this);
967
968 if ((list != null) && !list.isEmpty()) {
969 for (JournalTemplate journalTemplate : list) {
970 if (!Validator.equals(uuid, journalTemplate.getUuid()) ||
971 (companyId != journalTemplate.getCompanyId())) {
972 list = null;
973
974 break;
975 }
976 }
977 }
978
979 if (list == null) {
980 StringBundler query = null;
981
982 if (orderByComparator != null) {
983 query = new StringBundler(4 +
984 (orderByComparator.getOrderByFields().length * 3));
985 }
986 else {
987 query = new StringBundler(4);
988 }
989
990 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
991
992 boolean bindUuid = false;
993
994 if (uuid == null) {
995 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
996 }
997 else if (uuid.equals(StringPool.BLANK)) {
998 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
999 }
1000 else {
1001 bindUuid = true;
1002
1003 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1004 }
1005
1006 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1007
1008 if (orderByComparator != null) {
1009 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1010 orderByComparator);
1011 }
1012 else
1013 if (pagination) {
1014 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1015 }
1016
1017 String sql = query.toString();
1018
1019 Session session = null;
1020
1021 try {
1022 session = openSession();
1023
1024 Query q = session.createQuery(sql);
1025
1026 QueryPos qPos = QueryPos.getInstance(q);
1027
1028 if (bindUuid) {
1029 qPos.add(uuid);
1030 }
1031
1032 qPos.add(companyId);
1033
1034 if (!pagination) {
1035 list = (List<JournalTemplate>)QueryUtil.list(q,
1036 getDialect(), start, end, false);
1037
1038 Collections.sort(list);
1039
1040 list = new UnmodifiableList<JournalTemplate>(list);
1041 }
1042 else {
1043 list = (List<JournalTemplate>)QueryUtil.list(q,
1044 getDialect(), start, end);
1045 }
1046
1047 cacheResult(list);
1048
1049 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1050 }
1051 catch (Exception e) {
1052 FinderCacheUtil.removeResult(finderPath, finderArgs);
1053
1054 throw processException(e);
1055 }
1056 finally {
1057 closeSession(session);
1058 }
1059 }
1060
1061 return list;
1062 }
1063
1064
1074 public JournalTemplate findByUuid_C_First(String uuid, long companyId,
1075 OrderByComparator orderByComparator)
1076 throws NoSuchTemplateException, SystemException {
1077 JournalTemplate journalTemplate = fetchByUuid_C_First(uuid, companyId,
1078 orderByComparator);
1079
1080 if (journalTemplate != null) {
1081 return journalTemplate;
1082 }
1083
1084 StringBundler msg = new StringBundler(6);
1085
1086 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1087
1088 msg.append("uuid=");
1089 msg.append(uuid);
1090
1091 msg.append(", companyId=");
1092 msg.append(companyId);
1093
1094 msg.append(StringPool.CLOSE_CURLY_BRACE);
1095
1096 throw new NoSuchTemplateException(msg.toString());
1097 }
1098
1099
1108 public JournalTemplate fetchByUuid_C_First(String uuid, long companyId,
1109 OrderByComparator orderByComparator) throws SystemException {
1110 List<JournalTemplate> list = findByUuid_C(uuid, companyId, 0, 1,
1111 orderByComparator);
1112
1113 if (!list.isEmpty()) {
1114 return list.get(0);
1115 }
1116
1117 return null;
1118 }
1119
1120
1130 public JournalTemplate findByUuid_C_Last(String uuid, long companyId,
1131 OrderByComparator orderByComparator)
1132 throws NoSuchTemplateException, SystemException {
1133 JournalTemplate journalTemplate = fetchByUuid_C_Last(uuid, companyId,
1134 orderByComparator);
1135
1136 if (journalTemplate != null) {
1137 return journalTemplate;
1138 }
1139
1140 StringBundler msg = new StringBundler(6);
1141
1142 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1143
1144 msg.append("uuid=");
1145 msg.append(uuid);
1146
1147 msg.append(", companyId=");
1148 msg.append(companyId);
1149
1150 msg.append(StringPool.CLOSE_CURLY_BRACE);
1151
1152 throw new NoSuchTemplateException(msg.toString());
1153 }
1154
1155
1164 public JournalTemplate fetchByUuid_C_Last(String uuid, long companyId,
1165 OrderByComparator orderByComparator) throws SystemException {
1166 int count = countByUuid_C(uuid, companyId);
1167
1168 List<JournalTemplate> list = findByUuid_C(uuid, companyId, count - 1,
1169 count, orderByComparator);
1170
1171 if (!list.isEmpty()) {
1172 return list.get(0);
1173 }
1174
1175 return null;
1176 }
1177
1178
1189 public JournalTemplate[] findByUuid_C_PrevAndNext(long id, String uuid,
1190 long companyId, OrderByComparator orderByComparator)
1191 throws NoSuchTemplateException, SystemException {
1192 JournalTemplate journalTemplate = findByPrimaryKey(id);
1193
1194 Session session = null;
1195
1196 try {
1197 session = openSession();
1198
1199 JournalTemplate[] array = new JournalTemplateImpl[3];
1200
1201 array[0] = getByUuid_C_PrevAndNext(session, journalTemplate, uuid,
1202 companyId, orderByComparator, true);
1203
1204 array[1] = journalTemplate;
1205
1206 array[2] = getByUuid_C_PrevAndNext(session, journalTemplate, uuid,
1207 companyId, orderByComparator, false);
1208
1209 return array;
1210 }
1211 catch (Exception e) {
1212 throw processException(e);
1213 }
1214 finally {
1215 closeSession(session);
1216 }
1217 }
1218
1219 protected JournalTemplate getByUuid_C_PrevAndNext(Session session,
1220 JournalTemplate journalTemplate, String uuid, long companyId,
1221 OrderByComparator orderByComparator, boolean previous) {
1222 StringBundler query = null;
1223
1224 if (orderByComparator != null) {
1225 query = new StringBundler(6 +
1226 (orderByComparator.getOrderByFields().length * 6));
1227 }
1228 else {
1229 query = new StringBundler(3);
1230 }
1231
1232 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1233
1234 boolean bindUuid = false;
1235
1236 if (uuid == null) {
1237 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1238 }
1239 else if (uuid.equals(StringPool.BLANK)) {
1240 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1241 }
1242 else {
1243 bindUuid = true;
1244
1245 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1246 }
1247
1248 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1249
1250 if (orderByComparator != null) {
1251 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1252
1253 if (orderByConditionFields.length > 0) {
1254 query.append(WHERE_AND);
1255 }
1256
1257 for (int i = 0; i < orderByConditionFields.length; i++) {
1258 query.append(_ORDER_BY_ENTITY_ALIAS);
1259 query.append(orderByConditionFields[i]);
1260
1261 if ((i + 1) < orderByConditionFields.length) {
1262 if (orderByComparator.isAscending() ^ previous) {
1263 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1264 }
1265 else {
1266 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1267 }
1268 }
1269 else {
1270 if (orderByComparator.isAscending() ^ previous) {
1271 query.append(WHERE_GREATER_THAN);
1272 }
1273 else {
1274 query.append(WHERE_LESSER_THAN);
1275 }
1276 }
1277 }
1278
1279 query.append(ORDER_BY_CLAUSE);
1280
1281 String[] orderByFields = orderByComparator.getOrderByFields();
1282
1283 for (int i = 0; i < orderByFields.length; i++) {
1284 query.append(_ORDER_BY_ENTITY_ALIAS);
1285 query.append(orderByFields[i]);
1286
1287 if ((i + 1) < orderByFields.length) {
1288 if (orderByComparator.isAscending() ^ previous) {
1289 query.append(ORDER_BY_ASC_HAS_NEXT);
1290 }
1291 else {
1292 query.append(ORDER_BY_DESC_HAS_NEXT);
1293 }
1294 }
1295 else {
1296 if (orderByComparator.isAscending() ^ previous) {
1297 query.append(ORDER_BY_ASC);
1298 }
1299 else {
1300 query.append(ORDER_BY_DESC);
1301 }
1302 }
1303 }
1304 }
1305 else {
1306 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1307 }
1308
1309 String sql = query.toString();
1310
1311 Query q = session.createQuery(sql);
1312
1313 q.setFirstResult(0);
1314 q.setMaxResults(2);
1315
1316 QueryPos qPos = QueryPos.getInstance(q);
1317
1318 if (bindUuid) {
1319 qPos.add(uuid);
1320 }
1321
1322 qPos.add(companyId);
1323
1324 if (orderByComparator != null) {
1325 Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
1326
1327 for (Object value : values) {
1328 qPos.add(value);
1329 }
1330 }
1331
1332 List<JournalTemplate> list = q.list();
1333
1334 if (list.size() == 2) {
1335 return list.get(1);
1336 }
1337 else {
1338 return null;
1339 }
1340 }
1341
1342
1349 public void removeByUuid_C(String uuid, long companyId)
1350 throws SystemException {
1351 for (JournalTemplate journalTemplate : findByUuid_C(uuid, companyId,
1352 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1353 remove(journalTemplate);
1354 }
1355 }
1356
1357
1365 public int countByUuid_C(String uuid, long companyId)
1366 throws SystemException {
1367 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1368
1369 Object[] finderArgs = new Object[] { uuid, companyId };
1370
1371 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1372 this);
1373
1374 if (count == null) {
1375 StringBundler query = new StringBundler(3);
1376
1377 query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
1378
1379 boolean bindUuid = false;
1380
1381 if (uuid == null) {
1382 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1383 }
1384 else if (uuid.equals(StringPool.BLANK)) {
1385 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1386 }
1387 else {
1388 bindUuid = true;
1389
1390 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1391 }
1392
1393 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1394
1395 String sql = query.toString();
1396
1397 Session session = null;
1398
1399 try {
1400 session = openSession();
1401
1402 Query q = session.createQuery(sql);
1403
1404 QueryPos qPos = QueryPos.getInstance(q);
1405
1406 if (bindUuid) {
1407 qPos.add(uuid);
1408 }
1409
1410 qPos.add(companyId);
1411
1412 count = (Long)q.uniqueResult();
1413
1414 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1415 }
1416 catch (Exception e) {
1417 FinderCacheUtil.removeResult(finderPath, finderArgs);
1418
1419 throw processException(e);
1420 }
1421 finally {
1422 closeSession(session);
1423 }
1424 }
1425
1426 return count.intValue();
1427 }
1428
1429 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "journalTemplate.uuid IS NULL AND ";
1430 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "journalTemplate.uuid = ? AND ";
1431 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(journalTemplate.uuid IS NULL OR journalTemplate.uuid = '') AND ";
1432 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "journalTemplate.companyId = ?";
1433 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
1434 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
1435 JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1436 "findByGroupId",
1437 new String[] {
1438 Long.class.getName(),
1439
1440 Integer.class.getName(), Integer.class.getName(),
1441 OrderByComparator.class.getName()
1442 });
1443 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1444 new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
1445 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
1446 JournalTemplateImpl.class,
1447 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1448 new String[] { Long.class.getName() },
1449 JournalTemplateModelImpl.GROUPID_COLUMN_BITMASK |
1450 JournalTemplateModelImpl.TEMPLATEID_COLUMN_BITMASK);
1451 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
1452 JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
1453 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1454 new String[] { Long.class.getName() });
1455
1456
1463 public List<JournalTemplate> findByGroupId(long groupId)
1464 throws SystemException {
1465 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1466 }
1467
1468
1481 public List<JournalTemplate> findByGroupId(long groupId, int start, int end)
1482 throws SystemException {
1483 return findByGroupId(groupId, start, end, null);
1484 }
1485
1486
1500 public List<JournalTemplate> findByGroupId(long groupId, int start,
1501 int end, OrderByComparator orderByComparator) throws SystemException {
1502 boolean pagination = true;
1503 FinderPath finderPath = null;
1504 Object[] finderArgs = null;
1505
1506 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1507 (orderByComparator == null)) {
1508 pagination = false;
1509 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1510 finderArgs = new Object[] { groupId };
1511 }
1512 else {
1513 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1514 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1515 }
1516
1517 List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
1518 finderArgs, this);
1519
1520 if ((list != null) && !list.isEmpty()) {
1521 for (JournalTemplate journalTemplate : list) {
1522 if ((groupId != journalTemplate.getGroupId())) {
1523 list = null;
1524
1525 break;
1526 }
1527 }
1528 }
1529
1530 if (list == null) {
1531 StringBundler query = null;
1532
1533 if (orderByComparator != null) {
1534 query = new StringBundler(3 +
1535 (orderByComparator.getOrderByFields().length * 3));
1536 }
1537 else {
1538 query = new StringBundler(3);
1539 }
1540
1541 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1542
1543 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1544
1545 if (orderByComparator != null) {
1546 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1547 orderByComparator);
1548 }
1549 else
1550 if (pagination) {
1551 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1552 }
1553
1554 String sql = query.toString();
1555
1556 Session session = null;
1557
1558 try {
1559 session = openSession();
1560
1561 Query q = session.createQuery(sql);
1562
1563 QueryPos qPos = QueryPos.getInstance(q);
1564
1565 qPos.add(groupId);
1566
1567 if (!pagination) {
1568 list = (List<JournalTemplate>)QueryUtil.list(q,
1569 getDialect(), start, end, false);
1570
1571 Collections.sort(list);
1572
1573 list = new UnmodifiableList<JournalTemplate>(list);
1574 }
1575 else {
1576 list = (List<JournalTemplate>)QueryUtil.list(q,
1577 getDialect(), start, end);
1578 }
1579
1580 cacheResult(list);
1581
1582 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1583 }
1584 catch (Exception e) {
1585 FinderCacheUtil.removeResult(finderPath, finderArgs);
1586
1587 throw processException(e);
1588 }
1589 finally {
1590 closeSession(session);
1591 }
1592 }
1593
1594 return list;
1595 }
1596
1597
1606 public JournalTemplate findByGroupId_First(long groupId,
1607 OrderByComparator orderByComparator)
1608 throws NoSuchTemplateException, SystemException {
1609 JournalTemplate journalTemplate = fetchByGroupId_First(groupId,
1610 orderByComparator);
1611
1612 if (journalTemplate != null) {
1613 return journalTemplate;
1614 }
1615
1616 StringBundler msg = new StringBundler(4);
1617
1618 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1619
1620 msg.append("groupId=");
1621 msg.append(groupId);
1622
1623 msg.append(StringPool.CLOSE_CURLY_BRACE);
1624
1625 throw new NoSuchTemplateException(msg.toString());
1626 }
1627
1628
1636 public JournalTemplate fetchByGroupId_First(long groupId,
1637 OrderByComparator orderByComparator) throws SystemException {
1638 List<JournalTemplate> list = findByGroupId(groupId, 0, 1,
1639 orderByComparator);
1640
1641 if (!list.isEmpty()) {
1642 return list.get(0);
1643 }
1644
1645 return null;
1646 }
1647
1648
1657 public JournalTemplate findByGroupId_Last(long groupId,
1658 OrderByComparator orderByComparator)
1659 throws NoSuchTemplateException, SystemException {
1660 JournalTemplate journalTemplate = fetchByGroupId_Last(groupId,
1661 orderByComparator);
1662
1663 if (journalTemplate != null) {
1664 return journalTemplate;
1665 }
1666
1667 StringBundler msg = new StringBundler(4);
1668
1669 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1670
1671 msg.append("groupId=");
1672 msg.append(groupId);
1673
1674 msg.append(StringPool.CLOSE_CURLY_BRACE);
1675
1676 throw new NoSuchTemplateException(msg.toString());
1677 }
1678
1679
1687 public JournalTemplate fetchByGroupId_Last(long groupId,
1688 OrderByComparator orderByComparator) throws SystemException {
1689 int count = countByGroupId(groupId);
1690
1691 List<JournalTemplate> list = findByGroupId(groupId, count - 1, count,
1692 orderByComparator);
1693
1694 if (!list.isEmpty()) {
1695 return list.get(0);
1696 }
1697
1698 return null;
1699 }
1700
1701
1711 public JournalTemplate[] findByGroupId_PrevAndNext(long id, long groupId,
1712 OrderByComparator orderByComparator)
1713 throws NoSuchTemplateException, SystemException {
1714 JournalTemplate journalTemplate = findByPrimaryKey(id);
1715
1716 Session session = null;
1717
1718 try {
1719 session = openSession();
1720
1721 JournalTemplate[] array = new JournalTemplateImpl[3];
1722
1723 array[0] = getByGroupId_PrevAndNext(session, journalTemplate,
1724 groupId, orderByComparator, true);
1725
1726 array[1] = journalTemplate;
1727
1728 array[2] = getByGroupId_PrevAndNext(session, journalTemplate,
1729 groupId, orderByComparator, false);
1730
1731 return array;
1732 }
1733 catch (Exception e) {
1734 throw processException(e);
1735 }
1736 finally {
1737 closeSession(session);
1738 }
1739 }
1740
1741 protected JournalTemplate getByGroupId_PrevAndNext(Session session,
1742 JournalTemplate journalTemplate, long groupId,
1743 OrderByComparator orderByComparator, boolean previous) {
1744 StringBundler query = null;
1745
1746 if (orderByComparator != null) {
1747 query = new StringBundler(6 +
1748 (orderByComparator.getOrderByFields().length * 6));
1749 }
1750 else {
1751 query = new StringBundler(3);
1752 }
1753
1754 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1755
1756 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1757
1758 if (orderByComparator != null) {
1759 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1760
1761 if (orderByConditionFields.length > 0) {
1762 query.append(WHERE_AND);
1763 }
1764
1765 for (int i = 0; i < orderByConditionFields.length; i++) {
1766 query.append(_ORDER_BY_ENTITY_ALIAS);
1767 query.append(orderByConditionFields[i]);
1768
1769 if ((i + 1) < orderByConditionFields.length) {
1770 if (orderByComparator.isAscending() ^ previous) {
1771 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1772 }
1773 else {
1774 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1775 }
1776 }
1777 else {
1778 if (orderByComparator.isAscending() ^ previous) {
1779 query.append(WHERE_GREATER_THAN);
1780 }
1781 else {
1782 query.append(WHERE_LESSER_THAN);
1783 }
1784 }
1785 }
1786
1787 query.append(ORDER_BY_CLAUSE);
1788
1789 String[] orderByFields = orderByComparator.getOrderByFields();
1790
1791 for (int i = 0; i < orderByFields.length; i++) {
1792 query.append(_ORDER_BY_ENTITY_ALIAS);
1793 query.append(orderByFields[i]);
1794
1795 if ((i + 1) < orderByFields.length) {
1796 if (orderByComparator.isAscending() ^ previous) {
1797 query.append(ORDER_BY_ASC_HAS_NEXT);
1798 }
1799 else {
1800 query.append(ORDER_BY_DESC_HAS_NEXT);
1801 }
1802 }
1803 else {
1804 if (orderByComparator.isAscending() ^ previous) {
1805 query.append(ORDER_BY_ASC);
1806 }
1807 else {
1808 query.append(ORDER_BY_DESC);
1809 }
1810 }
1811 }
1812 }
1813 else {
1814 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1815 }
1816
1817 String sql = query.toString();
1818
1819 Query q = session.createQuery(sql);
1820
1821 q.setFirstResult(0);
1822 q.setMaxResults(2);
1823
1824 QueryPos qPos = QueryPos.getInstance(q);
1825
1826 qPos.add(groupId);
1827
1828 if (orderByComparator != null) {
1829 Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
1830
1831 for (Object value : values) {
1832 qPos.add(value);
1833 }
1834 }
1835
1836 List<JournalTemplate> list = q.list();
1837
1838 if (list.size() == 2) {
1839 return list.get(1);
1840 }
1841 else {
1842 return null;
1843 }
1844 }
1845
1846
1853 public List<JournalTemplate> filterFindByGroupId(long groupId)
1854 throws SystemException {
1855 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1856 QueryUtil.ALL_POS, null);
1857 }
1858
1859
1872 public List<JournalTemplate> filterFindByGroupId(long groupId, int start,
1873 int end) throws SystemException {
1874 return filterFindByGroupId(groupId, start, end, null);
1875 }
1876
1877
1891 public List<JournalTemplate> filterFindByGroupId(long groupId, int start,
1892 int end, OrderByComparator orderByComparator) throws SystemException {
1893 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1894 return findByGroupId(groupId, start, end, orderByComparator);
1895 }
1896
1897 StringBundler query = null;
1898
1899 if (orderByComparator != null) {
1900 query = new StringBundler(3 +
1901 (orderByComparator.getOrderByFields().length * 3));
1902 }
1903 else {
1904 query = new StringBundler(3);
1905 }
1906
1907 if (getDB().isSupportsInlineDistinct()) {
1908 query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
1909 }
1910 else {
1911 query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
1912 }
1913
1914 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1915
1916 if (!getDB().isSupportsInlineDistinct()) {
1917 query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
1918 }
1919
1920 if (orderByComparator != null) {
1921 if (getDB().isSupportsInlineDistinct()) {
1922 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1923 orderByComparator, true);
1924 }
1925 else {
1926 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1927 orderByComparator, true);
1928 }
1929 }
1930 else {
1931 if (getDB().isSupportsInlineDistinct()) {
1932 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
1933 }
1934 else {
1935 query.append(JournalTemplateModelImpl.ORDER_BY_SQL);
1936 }
1937 }
1938
1939 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1940 JournalTemplate.class.getName(),
1941 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1942
1943 Session session = null;
1944
1945 try {
1946 session = openSession();
1947
1948 SQLQuery q = session.createSQLQuery(sql);
1949
1950 if (getDB().isSupportsInlineDistinct()) {
1951 q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
1952 }
1953 else {
1954 q.addEntity(_FILTER_ENTITY_TABLE, JournalTemplateImpl.class);
1955 }
1956
1957 QueryPos qPos = QueryPos.getInstance(q);
1958
1959 qPos.add(groupId);
1960
1961 return (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
1962 start, end);
1963 }
1964 catch (Exception e) {
1965 throw processException(e);
1966 }
1967 finally {
1968 closeSession(session);
1969 }
1970 }
1971
1972
1982 public JournalTemplate[] filterFindByGroupId_PrevAndNext(long id,
1983 long groupId, OrderByComparator orderByComparator)
1984 throws NoSuchTemplateException, SystemException {
1985 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1986 return findByGroupId_PrevAndNext(id, groupId, orderByComparator);
1987 }
1988
1989 JournalTemplate journalTemplate = findByPrimaryKey(id);
1990
1991 Session session = null;
1992
1993 try {
1994 session = openSession();
1995
1996 JournalTemplate[] array = new JournalTemplateImpl[3];
1997
1998 array[0] = filterGetByGroupId_PrevAndNext(session, journalTemplate,
1999 groupId, orderByComparator, true);
2000
2001 array[1] = journalTemplate;
2002
2003 array[2] = filterGetByGroupId_PrevAndNext(session, journalTemplate,
2004 groupId, orderByComparator, false);
2005
2006 return array;
2007 }
2008 catch (Exception e) {
2009 throw processException(e);
2010 }
2011 finally {
2012 closeSession(session);
2013 }
2014 }
2015
2016 protected JournalTemplate filterGetByGroupId_PrevAndNext(Session session,
2017 JournalTemplate journalTemplate, long groupId,
2018 OrderByComparator orderByComparator, boolean previous) {
2019 StringBundler query = null;
2020
2021 if (orderByComparator != null) {
2022 query = new StringBundler(6 +
2023 (orderByComparator.getOrderByFields().length * 6));
2024 }
2025 else {
2026 query = new StringBundler(3);
2027 }
2028
2029 if (getDB().isSupportsInlineDistinct()) {
2030 query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2031 }
2032 else {
2033 query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
2034 }
2035
2036 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2037
2038 if (!getDB().isSupportsInlineDistinct()) {
2039 query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
2040 }
2041
2042 if (orderByComparator != null) {
2043 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2044
2045 if (orderByConditionFields.length > 0) {
2046 query.append(WHERE_AND);
2047 }
2048
2049 for (int i = 0; i < orderByConditionFields.length; i++) {
2050 if (getDB().isSupportsInlineDistinct()) {
2051 query.append(_ORDER_BY_ENTITY_ALIAS);
2052 }
2053 else {
2054 query.append(_ORDER_BY_ENTITY_TABLE);
2055 }
2056
2057 query.append(orderByConditionFields[i]);
2058
2059 if ((i + 1) < orderByConditionFields.length) {
2060 if (orderByComparator.isAscending() ^ previous) {
2061 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2062 }
2063 else {
2064 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2065 }
2066 }
2067 else {
2068 if (orderByComparator.isAscending() ^ previous) {
2069 query.append(WHERE_GREATER_THAN);
2070 }
2071 else {
2072 query.append(WHERE_LESSER_THAN);
2073 }
2074 }
2075 }
2076
2077 query.append(ORDER_BY_CLAUSE);
2078
2079 String[] orderByFields = orderByComparator.getOrderByFields();
2080
2081 for (int i = 0; i < orderByFields.length; i++) {
2082 if (getDB().isSupportsInlineDistinct()) {
2083 query.append(_ORDER_BY_ENTITY_ALIAS);
2084 }
2085 else {
2086 query.append(_ORDER_BY_ENTITY_TABLE);
2087 }
2088
2089 query.append(orderByFields[i]);
2090
2091 if ((i + 1) < orderByFields.length) {
2092 if (orderByComparator.isAscending() ^ previous) {
2093 query.append(ORDER_BY_ASC_HAS_NEXT);
2094 }
2095 else {
2096 query.append(ORDER_BY_DESC_HAS_NEXT);
2097 }
2098 }
2099 else {
2100 if (orderByComparator.isAscending() ^ previous) {
2101 query.append(ORDER_BY_ASC);
2102 }
2103 else {
2104 query.append(ORDER_BY_DESC);
2105 }
2106 }
2107 }
2108 }
2109 else {
2110 if (getDB().isSupportsInlineDistinct()) {
2111 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2112 }
2113 else {
2114 query.append(JournalTemplateModelImpl.ORDER_BY_SQL);
2115 }
2116 }
2117
2118 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2119 JournalTemplate.class.getName(),
2120 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2121
2122 SQLQuery q = session.createSQLQuery(sql);
2123
2124 q.setFirstResult(0);
2125 q.setMaxResults(2);
2126
2127 if (getDB().isSupportsInlineDistinct()) {
2128 q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
2129 }
2130 else {
2131 q.addEntity(_FILTER_ENTITY_TABLE, JournalTemplateImpl.class);
2132 }
2133
2134 QueryPos qPos = QueryPos.getInstance(q);
2135
2136 qPos.add(groupId);
2137
2138 if (orderByComparator != null) {
2139 Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
2140
2141 for (Object value : values) {
2142 qPos.add(value);
2143 }
2144 }
2145
2146 List<JournalTemplate> list = q.list();
2147
2148 if (list.size() == 2) {
2149 return list.get(1);
2150 }
2151 else {
2152 return null;
2153 }
2154 }
2155
2156
2162 public void removeByGroupId(long groupId) throws SystemException {
2163 for (JournalTemplate journalTemplate : findByGroupId(groupId,
2164 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2165 remove(journalTemplate);
2166 }
2167 }
2168
2169
2176 public int countByGroupId(long groupId) throws SystemException {
2177 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2178
2179 Object[] finderArgs = new Object[] { groupId };
2180
2181 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2182 this);
2183
2184 if (count == null) {
2185 StringBundler query = new StringBundler(2);
2186
2187 query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
2188
2189 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2190
2191 String sql = query.toString();
2192
2193 Session session = null;
2194
2195 try {
2196 session = openSession();
2197
2198 Query q = session.createQuery(sql);
2199
2200 QueryPos qPos = QueryPos.getInstance(q);
2201
2202 qPos.add(groupId);
2203
2204 count = (Long)q.uniqueResult();
2205
2206 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2207 }
2208 catch (Exception e) {
2209 FinderCacheUtil.removeResult(finderPath, finderArgs);
2210
2211 throw processException(e);
2212 }
2213 finally {
2214 closeSession(session);
2215 }
2216 }
2217
2218 return count.intValue();
2219 }
2220
2221
2228 public int filterCountByGroupId(long groupId) throws SystemException {
2229 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2230 return countByGroupId(groupId);
2231 }
2232
2233 StringBundler query = new StringBundler(2);
2234
2235 query.append(_FILTER_SQL_COUNT_JOURNALTEMPLATE_WHERE);
2236
2237 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2238
2239 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2240 JournalTemplate.class.getName(),
2241 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2242
2243 Session session = null;
2244
2245 try {
2246 session = openSession();
2247
2248 SQLQuery q = session.createSQLQuery(sql);
2249
2250 q.addScalar(COUNT_COLUMN_NAME,
2251 com.liferay.portal.kernel.dao.orm.Type.LONG);
2252
2253 QueryPos qPos = QueryPos.getInstance(q);
2254
2255 qPos.add(groupId);
2256
2257 Long count = (Long)q.uniqueResult();
2258
2259 return count.intValue();
2260 }
2261 catch (Exception e) {
2262 throw processException(e);
2263 }
2264 finally {
2265 closeSession(session);
2266 }
2267 }
2268
2269 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalTemplate.groupId = ?";
2270 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEID =
2271 new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
2272 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
2273 JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2274 "findByTemplateId",
2275 new String[] {
2276 String.class.getName(),
2277
2278 Integer.class.getName(), Integer.class.getName(),
2279 OrderByComparator.class.getName()
2280 });
2281 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID =
2282 new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
2283 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
2284 JournalTemplateImpl.class,
2285 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTemplateId",
2286 new String[] { String.class.getName() },
2287 JournalTemplateModelImpl.TEMPLATEID_COLUMN_BITMASK);
2288 public static final FinderPath FINDER_PATH_COUNT_BY_TEMPLATEID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
2289 JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
2290 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTemplateId",
2291 new String[] { String.class.getName() });
2292
2293
2300 public List<JournalTemplate> findByTemplateId(String templateId)
2301 throws SystemException {
2302 return findByTemplateId(templateId, QueryUtil.ALL_POS,
2303 QueryUtil.ALL_POS, null);
2304 }
2305
2306
2319 public List<JournalTemplate> findByTemplateId(String templateId, int start,
2320 int end) throws SystemException {
2321 return findByTemplateId(templateId, start, end, null);
2322 }
2323
2324
2338 public List<JournalTemplate> findByTemplateId(String templateId, int start,
2339 int end, OrderByComparator orderByComparator) throws SystemException {
2340 boolean pagination = true;
2341 FinderPath finderPath = null;
2342 Object[] finderArgs = null;
2343
2344 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2345 (orderByComparator == null)) {
2346 pagination = false;
2347 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID;
2348 finderArgs = new Object[] { templateId };
2349 }
2350 else {
2351 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEID;
2352 finderArgs = new Object[] { templateId, start, end, orderByComparator };
2353 }
2354
2355 List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
2356 finderArgs, this);
2357
2358 if ((list != null) && !list.isEmpty()) {
2359 for (JournalTemplate journalTemplate : list) {
2360 if (!Validator.equals(templateId,
2361 journalTemplate.getTemplateId())) {
2362 list = null;
2363
2364 break;
2365 }
2366 }
2367 }
2368
2369 if (list == null) {
2370 StringBundler query = null;
2371
2372 if (orderByComparator != null) {
2373 query = new StringBundler(3 +
2374 (orderByComparator.getOrderByFields().length * 3));
2375 }
2376 else {
2377 query = new StringBundler(3);
2378 }
2379
2380 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2381
2382 boolean bindTemplateId = false;
2383
2384 if (templateId == null) {
2385 query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
2386 }
2387 else if (templateId.equals(StringPool.BLANK)) {
2388 query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
2389 }
2390 else {
2391 bindTemplateId = true;
2392
2393 query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
2394 }
2395
2396 if (orderByComparator != null) {
2397 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2398 orderByComparator);
2399 }
2400 else
2401 if (pagination) {
2402 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2403 }
2404
2405 String sql = query.toString();
2406
2407 Session session = null;
2408
2409 try {
2410 session = openSession();
2411
2412 Query q = session.createQuery(sql);
2413
2414 QueryPos qPos = QueryPos.getInstance(q);
2415
2416 if (bindTemplateId) {
2417 qPos.add(templateId);
2418 }
2419
2420 if (!pagination) {
2421 list = (List<JournalTemplate>)QueryUtil.list(q,
2422 getDialect(), start, end, false);
2423
2424 Collections.sort(list);
2425
2426 list = new UnmodifiableList<JournalTemplate>(list);
2427 }
2428 else {
2429 list = (List<JournalTemplate>)QueryUtil.list(q,
2430 getDialect(), start, end);
2431 }
2432
2433 cacheResult(list);
2434
2435 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2436 }
2437 catch (Exception e) {
2438 FinderCacheUtil.removeResult(finderPath, finderArgs);
2439
2440 throw processException(e);
2441 }
2442 finally {
2443 closeSession(session);
2444 }
2445 }
2446
2447 return list;
2448 }
2449
2450
2459 public JournalTemplate findByTemplateId_First(String templateId,
2460 OrderByComparator orderByComparator)
2461 throws NoSuchTemplateException, SystemException {
2462 JournalTemplate journalTemplate = fetchByTemplateId_First(templateId,
2463 orderByComparator);
2464
2465 if (journalTemplate != null) {
2466 return journalTemplate;
2467 }
2468
2469 StringBundler msg = new StringBundler(4);
2470
2471 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2472
2473 msg.append("templateId=");
2474 msg.append(templateId);
2475
2476 msg.append(StringPool.CLOSE_CURLY_BRACE);
2477
2478 throw new NoSuchTemplateException(msg.toString());
2479 }
2480
2481
2489 public JournalTemplate fetchByTemplateId_First(String templateId,
2490 OrderByComparator orderByComparator) throws SystemException {
2491 List<JournalTemplate> list = findByTemplateId(templateId, 0, 1,
2492 orderByComparator);
2493
2494 if (!list.isEmpty()) {
2495 return list.get(0);
2496 }
2497
2498 return null;
2499 }
2500
2501
2510 public JournalTemplate findByTemplateId_Last(String templateId,
2511 OrderByComparator orderByComparator)
2512 throws NoSuchTemplateException, SystemException {
2513 JournalTemplate journalTemplate = fetchByTemplateId_Last(templateId,
2514 orderByComparator);
2515
2516 if (journalTemplate != null) {
2517 return journalTemplate;
2518 }
2519
2520 StringBundler msg = new StringBundler(4);
2521
2522 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2523
2524 msg.append("templateId=");
2525 msg.append(templateId);
2526
2527 msg.append(StringPool.CLOSE_CURLY_BRACE);
2528
2529 throw new NoSuchTemplateException(msg.toString());
2530 }
2531
2532
2540 public JournalTemplate fetchByTemplateId_Last(String templateId,
2541 OrderByComparator orderByComparator) throws SystemException {
2542 int count = countByTemplateId(templateId);
2543
2544 List<JournalTemplate> list = findByTemplateId(templateId, count - 1,
2545 count, orderByComparator);
2546
2547 if (!list.isEmpty()) {
2548 return list.get(0);
2549 }
2550
2551 return null;
2552 }
2553
2554
2564 public JournalTemplate[] findByTemplateId_PrevAndNext(long id,
2565 String templateId, OrderByComparator orderByComparator)
2566 throws NoSuchTemplateException, SystemException {
2567 JournalTemplate journalTemplate = findByPrimaryKey(id);
2568
2569 Session session = null;
2570
2571 try {
2572 session = openSession();
2573
2574 JournalTemplate[] array = new JournalTemplateImpl[3];
2575
2576 array[0] = getByTemplateId_PrevAndNext(session, journalTemplate,
2577 templateId, orderByComparator, true);
2578
2579 array[1] = journalTemplate;
2580
2581 array[2] = getByTemplateId_PrevAndNext(session, journalTemplate,
2582 templateId, orderByComparator, false);
2583
2584 return array;
2585 }
2586 catch (Exception e) {
2587 throw processException(e);
2588 }
2589 finally {
2590 closeSession(session);
2591 }
2592 }
2593
2594 protected JournalTemplate getByTemplateId_PrevAndNext(Session session,
2595 JournalTemplate journalTemplate, String templateId,
2596 OrderByComparator orderByComparator, boolean previous) {
2597 StringBundler query = null;
2598
2599 if (orderByComparator != null) {
2600 query = new StringBundler(6 +
2601 (orderByComparator.getOrderByFields().length * 6));
2602 }
2603 else {
2604 query = new StringBundler(3);
2605 }
2606
2607 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2608
2609 boolean bindTemplateId = false;
2610
2611 if (templateId == null) {
2612 query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
2613 }
2614 else if (templateId.equals(StringPool.BLANK)) {
2615 query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
2616 }
2617 else {
2618 bindTemplateId = true;
2619
2620 query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
2621 }
2622
2623 if (orderByComparator != null) {
2624 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2625
2626 if (orderByConditionFields.length > 0) {
2627 query.append(WHERE_AND);
2628 }
2629
2630 for (int i = 0; i < orderByConditionFields.length; i++) {
2631 query.append(_ORDER_BY_ENTITY_ALIAS);
2632 query.append(orderByConditionFields[i]);
2633
2634 if ((i + 1) < orderByConditionFields.length) {
2635 if (orderByComparator.isAscending() ^ previous) {
2636 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2637 }
2638 else {
2639 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2640 }
2641 }
2642 else {
2643 if (orderByComparator.isAscending() ^ previous) {
2644 query.append(WHERE_GREATER_THAN);
2645 }
2646 else {
2647 query.append(WHERE_LESSER_THAN);
2648 }
2649 }
2650 }
2651
2652 query.append(ORDER_BY_CLAUSE);
2653
2654 String[] orderByFields = orderByComparator.getOrderByFields();
2655
2656 for (int i = 0; i < orderByFields.length; i++) {
2657 query.append(_ORDER_BY_ENTITY_ALIAS);
2658 query.append(orderByFields[i]);
2659
2660 if ((i + 1) < orderByFields.length) {
2661 if (orderByComparator.isAscending() ^ previous) {
2662 query.append(ORDER_BY_ASC_HAS_NEXT);
2663 }
2664 else {
2665 query.append(ORDER_BY_DESC_HAS_NEXT);
2666 }
2667 }
2668 else {
2669 if (orderByComparator.isAscending() ^ previous) {
2670 query.append(ORDER_BY_ASC);
2671 }
2672 else {
2673 query.append(ORDER_BY_DESC);
2674 }
2675 }
2676 }
2677 }
2678 else {
2679 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2680 }
2681
2682 String sql = query.toString();
2683
2684 Query q = session.createQuery(sql);
2685
2686 q.setFirstResult(0);
2687 q.setMaxResults(2);
2688
2689 QueryPos qPos = QueryPos.getInstance(q);
2690
2691 if (bindTemplateId) {
2692 qPos.add(templateId);
2693 }
2694
2695 if (orderByComparator != null) {
2696 Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
2697
2698 for (Object value : values) {
2699 qPos.add(value);
2700 }
2701 }
2702
2703 List<JournalTemplate> list = q.list();
2704
2705 if (list.size() == 2) {
2706 return list.get(1);
2707 }
2708 else {
2709 return null;
2710 }
2711 }
2712
2713
2719 public void removeByTemplateId(String templateId) throws SystemException {
2720 for (JournalTemplate journalTemplate : findByTemplateId(templateId,
2721 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2722 remove(journalTemplate);
2723 }
2724 }
2725
2726
2733 public int countByTemplateId(String templateId) throws SystemException {
2734 FinderPath finderPath = FINDER_PATH_COUNT_BY_TEMPLATEID;
2735
2736 Object[] finderArgs = new Object[] { templateId };
2737
2738 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2739 this);
2740
2741 if (count == null) {
2742 StringBundler query = new StringBundler(2);
2743
2744 query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
2745
2746 boolean bindTemplateId = false;
2747
2748 if (templateId == null) {
2749 query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
2750 }
2751 else if (templateId.equals(StringPool.BLANK)) {
2752 query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
2753 }
2754 else {
2755 bindTemplateId = true;
2756
2757 query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
2758 }
2759
2760 String sql = query.toString();
2761
2762 Session session = null;
2763
2764 try {
2765 session = openSession();
2766
2767 Query q = session.createQuery(sql);
2768
2769 QueryPos qPos = QueryPos.getInstance(q);
2770
2771 if (bindTemplateId) {
2772 qPos.add(templateId);
2773 }
2774
2775 count = (Long)q.uniqueResult();
2776
2777 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2778 }
2779 catch (Exception e) {
2780 FinderCacheUtil.removeResult(finderPath, finderArgs);
2781
2782 throw processException(e);
2783 }
2784 finally {
2785 closeSession(session);
2786 }
2787 }
2788
2789 return count.intValue();
2790 }
2791
2792 private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1 = "journalTemplate.templateId IS NULL";
2793 private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2 = "journalTemplate.templateId = ?";
2794 private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3 = "(journalTemplate.templateId IS NULL OR journalTemplate.templateId = '')";
2795 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID =
2796 new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
2797 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
2798 JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2799 "findByStructureId",
2800 new String[] {
2801 String.class.getName(),
2802
2803 Integer.class.getName(), Integer.class.getName(),
2804 OrderByComparator.class.getName()
2805 });
2806 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID =
2807 new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
2808 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
2809 JournalTemplateImpl.class,
2810 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByStructureId",
2811 new String[] { String.class.getName() },
2812 JournalTemplateModelImpl.STRUCTUREID_COLUMN_BITMASK |
2813 JournalTemplateModelImpl.TEMPLATEID_COLUMN_BITMASK);
2814 public static final FinderPath FINDER_PATH_COUNT_BY_STRUCTUREID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
2815 JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
2816 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByStructureId",
2817 new String[] { String.class.getName() });
2818
2819
2826 public List<JournalTemplate> findByStructureId(String structureId)
2827 throws SystemException {
2828 return findByStructureId(structureId, QueryUtil.ALL_POS,
2829 QueryUtil.ALL_POS, null);
2830 }
2831
2832
2845 public List<JournalTemplate> findByStructureId(String structureId,
2846 int start, int end) throws SystemException {
2847 return findByStructureId(structureId, start, end, null);
2848 }
2849
2850
2864 public List<JournalTemplate> findByStructureId(String structureId,
2865 int start, int end, OrderByComparator orderByComparator)
2866 throws SystemException {
2867 boolean pagination = true;
2868 FinderPath finderPath = null;
2869 Object[] finderArgs = null;
2870
2871 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2872 (orderByComparator == null)) {
2873 pagination = false;
2874 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID;
2875 finderArgs = new Object[] { structureId };
2876 }
2877 else {
2878 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID;
2879 finderArgs = new Object[] { structureId, start, end, orderByComparator };
2880 }
2881
2882 List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
2883 finderArgs, this);
2884
2885 if ((list != null) && !list.isEmpty()) {
2886 for (JournalTemplate journalTemplate : list) {
2887 if (!Validator.equals(structureId,
2888 journalTemplate.getStructureId())) {
2889 list = null;
2890
2891 break;
2892 }
2893 }
2894 }
2895
2896 if (list == null) {
2897 StringBundler query = null;
2898
2899 if (orderByComparator != null) {
2900 query = new StringBundler(3 +
2901 (orderByComparator.getOrderByFields().length * 3));
2902 }
2903 else {
2904 query = new StringBundler(3);
2905 }
2906
2907 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
2908
2909 boolean bindStructureId = false;
2910
2911 if (structureId == null) {
2912 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
2913 }
2914 else if (structureId.equals(StringPool.BLANK)) {
2915 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
2916 }
2917 else {
2918 bindStructureId = true;
2919
2920 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
2921 }
2922
2923 if (orderByComparator != null) {
2924 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2925 orderByComparator);
2926 }
2927 else
2928 if (pagination) {
2929 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
2930 }
2931
2932 String sql = query.toString();
2933
2934 Session session = null;
2935
2936 try {
2937 session = openSession();
2938
2939 Query q = session.createQuery(sql);
2940
2941 QueryPos qPos = QueryPos.getInstance(q);
2942
2943 if (bindStructureId) {
2944 qPos.add(structureId);
2945 }
2946
2947 if (!pagination) {
2948 list = (List<JournalTemplate>)QueryUtil.list(q,
2949 getDialect(), start, end, false);
2950
2951 Collections.sort(list);
2952
2953 list = new UnmodifiableList<JournalTemplate>(list);
2954 }
2955 else {
2956 list = (List<JournalTemplate>)QueryUtil.list(q,
2957 getDialect(), start, end);
2958 }
2959
2960 cacheResult(list);
2961
2962 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2963 }
2964 catch (Exception e) {
2965 FinderCacheUtil.removeResult(finderPath, finderArgs);
2966
2967 throw processException(e);
2968 }
2969 finally {
2970 closeSession(session);
2971 }
2972 }
2973
2974 return list;
2975 }
2976
2977
2986 public JournalTemplate findByStructureId_First(String structureId,
2987 OrderByComparator orderByComparator)
2988 throws NoSuchTemplateException, SystemException {
2989 JournalTemplate journalTemplate = fetchByStructureId_First(structureId,
2990 orderByComparator);
2991
2992 if (journalTemplate != null) {
2993 return journalTemplate;
2994 }
2995
2996 StringBundler msg = new StringBundler(4);
2997
2998 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2999
3000 msg.append("structureId=");
3001 msg.append(structureId);
3002
3003 msg.append(StringPool.CLOSE_CURLY_BRACE);
3004
3005 throw new NoSuchTemplateException(msg.toString());
3006 }
3007
3008
3016 public JournalTemplate fetchByStructureId_First(String structureId,
3017 OrderByComparator orderByComparator) throws SystemException {
3018 List<JournalTemplate> list = findByStructureId(structureId, 0, 1,
3019 orderByComparator);
3020
3021 if (!list.isEmpty()) {
3022 return list.get(0);
3023 }
3024
3025 return null;
3026 }
3027
3028
3037 public JournalTemplate findByStructureId_Last(String structureId,
3038 OrderByComparator orderByComparator)
3039 throws NoSuchTemplateException, SystemException {
3040 JournalTemplate journalTemplate = fetchByStructureId_Last(structureId,
3041 orderByComparator);
3042
3043 if (journalTemplate != null) {
3044 return journalTemplate;
3045 }
3046
3047 StringBundler msg = new StringBundler(4);
3048
3049 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3050
3051 msg.append("structureId=");
3052 msg.append(structureId);
3053
3054 msg.append(StringPool.CLOSE_CURLY_BRACE);
3055
3056 throw new NoSuchTemplateException(msg.toString());
3057 }
3058
3059
3067 public JournalTemplate fetchByStructureId_Last(String structureId,
3068 OrderByComparator orderByComparator) throws SystemException {
3069 int count = countByStructureId(structureId);
3070
3071 List<JournalTemplate> list = findByStructureId(structureId, count - 1,
3072 count, orderByComparator);
3073
3074 if (!list.isEmpty()) {
3075 return list.get(0);
3076 }
3077
3078 return null;
3079 }
3080
3081
3091 public JournalTemplate[] findByStructureId_PrevAndNext(long id,
3092 String structureId, OrderByComparator orderByComparator)
3093 throws NoSuchTemplateException, SystemException {
3094 JournalTemplate journalTemplate = findByPrimaryKey(id);
3095
3096 Session session = null;
3097
3098 try {
3099 session = openSession();
3100
3101 JournalTemplate[] array = new JournalTemplateImpl[3];
3102
3103 array[0] = getByStructureId_PrevAndNext(session, journalTemplate,
3104 structureId, orderByComparator, true);
3105
3106 array[1] = journalTemplate;
3107
3108 array[2] = getByStructureId_PrevAndNext(session, journalTemplate,
3109 structureId, orderByComparator, false);
3110
3111 return array;
3112 }
3113 catch (Exception e) {
3114 throw processException(e);
3115 }
3116 finally {
3117 closeSession(session);
3118 }
3119 }
3120
3121 protected JournalTemplate getByStructureId_PrevAndNext(Session session,
3122 JournalTemplate journalTemplate, String structureId,
3123 OrderByComparator orderByComparator, boolean previous) {
3124 StringBundler query = null;
3125
3126 if (orderByComparator != null) {
3127 query = new StringBundler(6 +
3128 (orderByComparator.getOrderByFields().length * 6));
3129 }
3130 else {
3131 query = new StringBundler(3);
3132 }
3133
3134 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
3135
3136 boolean bindStructureId = false;
3137
3138 if (structureId == null) {
3139 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
3140 }
3141 else if (structureId.equals(StringPool.BLANK)) {
3142 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
3143 }
3144 else {
3145 bindStructureId = true;
3146
3147 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
3148 }
3149
3150 if (orderByComparator != null) {
3151 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3152
3153 if (orderByConditionFields.length > 0) {
3154 query.append(WHERE_AND);
3155 }
3156
3157 for (int i = 0; i < orderByConditionFields.length; i++) {
3158 query.append(_ORDER_BY_ENTITY_ALIAS);
3159 query.append(orderByConditionFields[i]);
3160
3161 if ((i + 1) < orderByConditionFields.length) {
3162 if (orderByComparator.isAscending() ^ previous) {
3163 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3164 }
3165 else {
3166 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3167 }
3168 }
3169 else {
3170 if (orderByComparator.isAscending() ^ previous) {
3171 query.append(WHERE_GREATER_THAN);
3172 }
3173 else {
3174 query.append(WHERE_LESSER_THAN);
3175 }
3176 }
3177 }
3178
3179 query.append(ORDER_BY_CLAUSE);
3180
3181 String[] orderByFields = orderByComparator.getOrderByFields();
3182
3183 for (int i = 0; i < orderByFields.length; i++) {
3184 query.append(_ORDER_BY_ENTITY_ALIAS);
3185 query.append(orderByFields[i]);
3186
3187 if ((i + 1) < orderByFields.length) {
3188 if (orderByComparator.isAscending() ^ previous) {
3189 query.append(ORDER_BY_ASC_HAS_NEXT);
3190 }
3191 else {
3192 query.append(ORDER_BY_DESC_HAS_NEXT);
3193 }
3194 }
3195 else {
3196 if (orderByComparator.isAscending() ^ previous) {
3197 query.append(ORDER_BY_ASC);
3198 }
3199 else {
3200 query.append(ORDER_BY_DESC);
3201 }
3202 }
3203 }
3204 }
3205 else {
3206 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
3207 }
3208
3209 String sql = query.toString();
3210
3211 Query q = session.createQuery(sql);
3212
3213 q.setFirstResult(0);
3214 q.setMaxResults(2);
3215
3216 QueryPos qPos = QueryPos.getInstance(q);
3217
3218 if (bindStructureId) {
3219 qPos.add(structureId);
3220 }
3221
3222 if (orderByComparator != null) {
3223 Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
3224
3225 for (Object value : values) {
3226 qPos.add(value);
3227 }
3228 }
3229
3230 List<JournalTemplate> list = q.list();
3231
3232 if (list.size() == 2) {
3233 return list.get(1);
3234 }
3235 else {
3236 return null;
3237 }
3238 }
3239
3240
3246 public void removeByStructureId(String structureId)
3247 throws SystemException {
3248 for (JournalTemplate journalTemplate : findByStructureId(structureId,
3249 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3250 remove(journalTemplate);
3251 }
3252 }
3253
3254
3261 public int countByStructureId(String structureId) throws SystemException {
3262 FinderPath finderPath = FINDER_PATH_COUNT_BY_STRUCTUREID;
3263
3264 Object[] finderArgs = new Object[] { structureId };
3265
3266 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3267 this);
3268
3269 if (count == null) {
3270 StringBundler query = new StringBundler(2);
3271
3272 query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
3273
3274 boolean bindStructureId = false;
3275
3276 if (structureId == null) {
3277 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
3278 }
3279 else if (structureId.equals(StringPool.BLANK)) {
3280 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
3281 }
3282 else {
3283 bindStructureId = true;
3284
3285 query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
3286 }
3287
3288 String sql = query.toString();
3289
3290 Session session = null;
3291
3292 try {
3293 session = openSession();
3294
3295 Query q = session.createQuery(sql);
3296
3297 QueryPos qPos = QueryPos.getInstance(q);
3298
3299 if (bindStructureId) {
3300 qPos.add(structureId);
3301 }
3302
3303 count = (Long)q.uniqueResult();
3304
3305 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3306 }
3307 catch (Exception e) {
3308 FinderCacheUtil.removeResult(finderPath, finderArgs);
3309
3310 throw processException(e);
3311 }
3312 finally {
3313 closeSession(session);
3314 }
3315 }
3316
3317 return count.intValue();
3318 }
3319
3320 private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1 = "journalTemplate.structureId IS NULL";
3321 private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2 = "journalTemplate.structureId = ?";
3322 private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3 = "(journalTemplate.structureId IS NULL OR journalTemplate.structureId = '')";
3323 public static final FinderPath FINDER_PATH_FETCH_BY_SMALLIMAGEID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
3324 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
3325 JournalTemplateImpl.class, FINDER_CLASS_NAME_ENTITY,
3326 "fetchBySmallImageId", new String[] { Long.class.getName() },
3327 JournalTemplateModelImpl.SMALLIMAGEID_COLUMN_BITMASK);
3328 public static final FinderPath FINDER_PATH_COUNT_BY_SMALLIMAGEID = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
3329 JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
3330 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySmallImageId",
3331 new String[] { Long.class.getName() });
3332
3333
3341 public JournalTemplate findBySmallImageId(long smallImageId)
3342 throws NoSuchTemplateException, SystemException {
3343 JournalTemplate journalTemplate = fetchBySmallImageId(smallImageId);
3344
3345 if (journalTemplate == null) {
3346 StringBundler msg = new StringBundler(4);
3347
3348 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3349
3350 msg.append("smallImageId=");
3351 msg.append(smallImageId);
3352
3353 msg.append(StringPool.CLOSE_CURLY_BRACE);
3354
3355 if (_log.isWarnEnabled()) {
3356 _log.warn(msg.toString());
3357 }
3358
3359 throw new NoSuchTemplateException(msg.toString());
3360 }
3361
3362 return journalTemplate;
3363 }
3364
3365
3372 public JournalTemplate fetchBySmallImageId(long smallImageId)
3373 throws SystemException {
3374 return fetchBySmallImageId(smallImageId, true);
3375 }
3376
3377
3385 public JournalTemplate fetchBySmallImageId(long smallImageId,
3386 boolean retrieveFromCache) throws SystemException {
3387 Object[] finderArgs = new Object[] { smallImageId };
3388
3389 Object result = null;
3390
3391 if (retrieveFromCache) {
3392 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
3393 finderArgs, this);
3394 }
3395
3396 if (result instanceof JournalTemplate) {
3397 JournalTemplate journalTemplate = (JournalTemplate)result;
3398
3399 if ((smallImageId != journalTemplate.getSmallImageId())) {
3400 result = null;
3401 }
3402 }
3403
3404 if (result == null) {
3405 StringBundler query = new StringBundler(3);
3406
3407 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
3408
3409 query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
3410
3411 String sql = query.toString();
3412
3413 Session session = null;
3414
3415 try {
3416 session = openSession();
3417
3418 Query q = session.createQuery(sql);
3419
3420 QueryPos qPos = QueryPos.getInstance(q);
3421
3422 qPos.add(smallImageId);
3423
3424 List<JournalTemplate> list = q.list();
3425
3426 if (list.isEmpty()) {
3427 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
3428 finderArgs, list);
3429 }
3430 else {
3431 if ((list.size() > 1) && _log.isWarnEnabled()) {
3432 _log.warn(
3433 "JournalTemplatePersistenceImpl.fetchBySmallImageId(long, boolean) with parameters (" +
3434 StringUtil.merge(finderArgs) +
3435 ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
3436 }
3437
3438 JournalTemplate journalTemplate = list.get(0);
3439
3440 result = journalTemplate;
3441
3442 cacheResult(journalTemplate);
3443
3444 if ((journalTemplate.getSmallImageId() != smallImageId)) {
3445 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
3446 finderArgs, journalTemplate);
3447 }
3448 }
3449 }
3450 catch (Exception e) {
3451 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
3452 finderArgs);
3453
3454 throw processException(e);
3455 }
3456 finally {
3457 closeSession(session);
3458 }
3459 }
3460
3461 if (result instanceof List<?>) {
3462 return null;
3463 }
3464 else {
3465 return (JournalTemplate)result;
3466 }
3467 }
3468
3469
3476 public JournalTemplate removeBySmallImageId(long smallImageId)
3477 throws NoSuchTemplateException, SystemException {
3478 JournalTemplate journalTemplate = findBySmallImageId(smallImageId);
3479
3480 return remove(journalTemplate);
3481 }
3482
3483
3490 public int countBySmallImageId(long smallImageId) throws SystemException {
3491 FinderPath finderPath = FINDER_PATH_COUNT_BY_SMALLIMAGEID;
3492
3493 Object[] finderArgs = new Object[] { smallImageId };
3494
3495 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3496 this);
3497
3498 if (count == null) {
3499 StringBundler query = new StringBundler(2);
3500
3501 query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
3502
3503 query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
3504
3505 String sql = query.toString();
3506
3507 Session session = null;
3508
3509 try {
3510 session = openSession();
3511
3512 Query q = session.createQuery(sql);
3513
3514 QueryPos qPos = QueryPos.getInstance(q);
3515
3516 qPos.add(smallImageId);
3517
3518 count = (Long)q.uniqueResult();
3519
3520 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3521 }
3522 catch (Exception e) {
3523 FinderCacheUtil.removeResult(finderPath, finderArgs);
3524
3525 throw processException(e);
3526 }
3527 finally {
3528 closeSession(session);
3529 }
3530 }
3531
3532 return count.intValue();
3533 }
3534
3535 private static final String _FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2 = "journalTemplate.smallImageId = ?";
3536 public static final FinderPath FINDER_PATH_FETCH_BY_G_T = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
3537 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
3538 JournalTemplateImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_T",
3539 new String[] { Long.class.getName(), String.class.getName() },
3540 JournalTemplateModelImpl.GROUPID_COLUMN_BITMASK |
3541 JournalTemplateModelImpl.TEMPLATEID_COLUMN_BITMASK);
3542 public static final FinderPath FINDER_PATH_COUNT_BY_G_T = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
3543 JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
3544 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_T",
3545 new String[] { Long.class.getName(), String.class.getName() });
3546
3547
3556 public JournalTemplate findByG_T(long groupId, String templateId)
3557 throws NoSuchTemplateException, SystemException {
3558 JournalTemplate journalTemplate = fetchByG_T(groupId, templateId);
3559
3560 if (journalTemplate == null) {
3561 StringBundler msg = new StringBundler(6);
3562
3563 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3564
3565 msg.append("groupId=");
3566 msg.append(groupId);
3567
3568 msg.append(", templateId=");
3569 msg.append(templateId);
3570
3571 msg.append(StringPool.CLOSE_CURLY_BRACE);
3572
3573 if (_log.isWarnEnabled()) {
3574 _log.warn(msg.toString());
3575 }
3576
3577 throw new NoSuchTemplateException(msg.toString());
3578 }
3579
3580 return journalTemplate;
3581 }
3582
3583
3591 public JournalTemplate fetchByG_T(long groupId, String templateId)
3592 throws SystemException {
3593 return fetchByG_T(groupId, templateId, true);
3594 }
3595
3596
3605 public JournalTemplate fetchByG_T(long groupId, String templateId,
3606 boolean retrieveFromCache) throws SystemException {
3607 Object[] finderArgs = new Object[] { groupId, templateId };
3608
3609 Object result = null;
3610
3611 if (retrieveFromCache) {
3612 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_T,
3613 finderArgs, this);
3614 }
3615
3616 if (result instanceof JournalTemplate) {
3617 JournalTemplate journalTemplate = (JournalTemplate)result;
3618
3619 if ((groupId != journalTemplate.getGroupId()) ||
3620 !Validator.equals(templateId,
3621 journalTemplate.getTemplateId())) {
3622 result = null;
3623 }
3624 }
3625
3626 if (result == null) {
3627 StringBundler query = new StringBundler(4);
3628
3629 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
3630
3631 query.append(_FINDER_COLUMN_G_T_GROUPID_2);
3632
3633 boolean bindTemplateId = false;
3634
3635 if (templateId == null) {
3636 query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
3637 }
3638 else if (templateId.equals(StringPool.BLANK)) {
3639 query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
3640 }
3641 else {
3642 bindTemplateId = true;
3643
3644 query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
3645 }
3646
3647 String sql = query.toString();
3648
3649 Session session = null;
3650
3651 try {
3652 session = openSession();
3653
3654 Query q = session.createQuery(sql);
3655
3656 QueryPos qPos = QueryPos.getInstance(q);
3657
3658 qPos.add(groupId);
3659
3660 if (bindTemplateId) {
3661 qPos.add(templateId);
3662 }
3663
3664 List<JournalTemplate> list = q.list();
3665
3666 if (list.isEmpty()) {
3667 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
3668 finderArgs, list);
3669 }
3670 else {
3671 JournalTemplate journalTemplate = list.get(0);
3672
3673 result = journalTemplate;
3674
3675 cacheResult(journalTemplate);
3676
3677 if ((journalTemplate.getGroupId() != groupId) ||
3678 (journalTemplate.getTemplateId() == null) ||
3679 !journalTemplate.getTemplateId().equals(templateId)) {
3680 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
3681 finderArgs, journalTemplate);
3682 }
3683 }
3684 }
3685 catch (Exception e) {
3686 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T,
3687 finderArgs);
3688
3689 throw processException(e);
3690 }
3691 finally {
3692 closeSession(session);
3693 }
3694 }
3695
3696 if (result instanceof List<?>) {
3697 return null;
3698 }
3699 else {
3700 return (JournalTemplate)result;
3701 }
3702 }
3703
3704
3712 public JournalTemplate removeByG_T(long groupId, String templateId)
3713 throws NoSuchTemplateException, SystemException {
3714 JournalTemplate journalTemplate = findByG_T(groupId, templateId);
3715
3716 return remove(journalTemplate);
3717 }
3718
3719
3727 public int countByG_T(long groupId, String templateId)
3728 throws SystemException {
3729 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_T;
3730
3731 Object[] finderArgs = new Object[] { groupId, templateId };
3732
3733 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3734 this);
3735
3736 if (count == null) {
3737 StringBundler query = new StringBundler(3);
3738
3739 query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
3740
3741 query.append(_FINDER_COLUMN_G_T_GROUPID_2);
3742
3743 boolean bindTemplateId = false;
3744
3745 if (templateId == null) {
3746 query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
3747 }
3748 else if (templateId.equals(StringPool.BLANK)) {
3749 query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
3750 }
3751 else {
3752 bindTemplateId = true;
3753
3754 query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
3755 }
3756
3757 String sql = query.toString();
3758
3759 Session session = null;
3760
3761 try {
3762 session = openSession();
3763
3764 Query q = session.createQuery(sql);
3765
3766 QueryPos qPos = QueryPos.getInstance(q);
3767
3768 qPos.add(groupId);
3769
3770 if (bindTemplateId) {
3771 qPos.add(templateId);
3772 }
3773
3774 count = (Long)q.uniqueResult();
3775
3776 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3777 }
3778 catch (Exception e) {
3779 FinderCacheUtil.removeResult(finderPath, finderArgs);
3780
3781 throw processException(e);
3782 }
3783 finally {
3784 closeSession(session);
3785 }
3786 }
3787
3788 return count.intValue();
3789 }
3790
3791 private static final String _FINDER_COLUMN_G_T_GROUPID_2 = "journalTemplate.groupId = ? AND ";
3792 private static final String _FINDER_COLUMN_G_T_TEMPLATEID_1 = "journalTemplate.templateId IS NULL";
3793 private static final String _FINDER_COLUMN_G_T_TEMPLATEID_2 = "journalTemplate.templateId = ?";
3794 private static final String _FINDER_COLUMN_G_T_TEMPLATEID_3 = "(journalTemplate.templateId IS NULL OR journalTemplate.templateId = '')";
3795 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
3796 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
3797 JournalTemplateImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3798 "findByG_S",
3799 new String[] {
3800 Long.class.getName(), String.class.getName(),
3801
3802 Integer.class.getName(), Integer.class.getName(),
3803 OrderByComparator.class.getName()
3804 });
3805 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
3806 JournalTemplateModelImpl.FINDER_CACHE_ENABLED,
3807 JournalTemplateImpl.class,
3808 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
3809 new String[] { Long.class.getName(), String.class.getName() },
3810 JournalTemplateModelImpl.GROUPID_COLUMN_BITMASK |
3811 JournalTemplateModelImpl.STRUCTUREID_COLUMN_BITMASK |
3812 JournalTemplateModelImpl.TEMPLATEID_COLUMN_BITMASK);
3813 public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
3814 JournalTemplateModelImpl.FINDER_CACHE_ENABLED, Long.class,
3815 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
3816 new String[] { Long.class.getName(), String.class.getName() });
3817
3818
3826 public List<JournalTemplate> findByG_S(long groupId, String structureId)
3827 throws SystemException {
3828 return findByG_S(groupId, structureId, QueryUtil.ALL_POS,
3829 QueryUtil.ALL_POS, null);
3830 }
3831
3832
3846 public List<JournalTemplate> findByG_S(long groupId, String structureId,
3847 int start, int end) throws SystemException {
3848 return findByG_S(groupId, structureId, start, end, null);
3849 }
3850
3851
3866 public List<JournalTemplate> findByG_S(long groupId, String structureId,
3867 int start, int end, OrderByComparator orderByComparator)
3868 throws SystemException {
3869 boolean pagination = true;
3870 FinderPath finderPath = null;
3871 Object[] finderArgs = null;
3872
3873 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3874 (orderByComparator == null)) {
3875 pagination = false;
3876 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
3877 finderArgs = new Object[] { groupId, structureId };
3878 }
3879 else {
3880 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
3881 finderArgs = new Object[] {
3882 groupId, structureId,
3883
3884 start, end, orderByComparator
3885 };
3886 }
3887
3888 List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
3889 finderArgs, this);
3890
3891 if ((list != null) && !list.isEmpty()) {
3892 for (JournalTemplate journalTemplate : list) {
3893 if ((groupId != journalTemplate.getGroupId()) ||
3894 !Validator.equals(structureId,
3895 journalTemplate.getStructureId())) {
3896 list = null;
3897
3898 break;
3899 }
3900 }
3901 }
3902
3903 if (list == null) {
3904 StringBundler query = null;
3905
3906 if (orderByComparator != null) {
3907 query = new StringBundler(4 +
3908 (orderByComparator.getOrderByFields().length * 3));
3909 }
3910 else {
3911 query = new StringBundler(4);
3912 }
3913
3914 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
3915
3916 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3917
3918 boolean bindStructureId = false;
3919
3920 if (structureId == null) {
3921 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
3922 }
3923 else if (structureId.equals(StringPool.BLANK)) {
3924 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
3925 }
3926 else {
3927 bindStructureId = true;
3928
3929 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
3930 }
3931
3932 if (orderByComparator != null) {
3933 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3934 orderByComparator);
3935 }
3936 else
3937 if (pagination) {
3938 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
3939 }
3940
3941 String sql = query.toString();
3942
3943 Session session = null;
3944
3945 try {
3946 session = openSession();
3947
3948 Query q = session.createQuery(sql);
3949
3950 QueryPos qPos = QueryPos.getInstance(q);
3951
3952 qPos.add(groupId);
3953
3954 if (bindStructureId) {
3955 qPos.add(structureId);
3956 }
3957
3958 if (!pagination) {
3959 list = (List<JournalTemplate>)QueryUtil.list(q,
3960 getDialect(), start, end, false);
3961
3962 Collections.sort(list);
3963
3964 list = new UnmodifiableList<JournalTemplate>(list);
3965 }
3966 else {
3967 list = (List<JournalTemplate>)QueryUtil.list(q,
3968 getDialect(), start, end);
3969 }
3970
3971 cacheResult(list);
3972
3973 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3974 }
3975 catch (Exception e) {
3976 FinderCacheUtil.removeResult(finderPath, finderArgs);
3977
3978 throw processException(e);
3979 }
3980 finally {
3981 closeSession(session);
3982 }
3983 }
3984
3985 return list;
3986 }
3987
3988
3998 public JournalTemplate findByG_S_First(long groupId, String structureId,
3999 OrderByComparator orderByComparator)
4000 throws NoSuchTemplateException, SystemException {
4001 JournalTemplate journalTemplate = fetchByG_S_First(groupId,
4002 structureId, orderByComparator);
4003
4004 if (journalTemplate != null) {
4005 return journalTemplate;
4006 }
4007
4008 StringBundler msg = new StringBundler(6);
4009
4010 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4011
4012 msg.append("groupId=");
4013 msg.append(groupId);
4014
4015 msg.append(", structureId=");
4016 msg.append(structureId);
4017
4018 msg.append(StringPool.CLOSE_CURLY_BRACE);
4019
4020 throw new NoSuchTemplateException(msg.toString());
4021 }
4022
4023
4032 public JournalTemplate fetchByG_S_First(long groupId, String structureId,
4033 OrderByComparator orderByComparator) throws SystemException {
4034 List<JournalTemplate> list = findByG_S(groupId, structureId, 0, 1,
4035 orderByComparator);
4036
4037 if (!list.isEmpty()) {
4038 return list.get(0);
4039 }
4040
4041 return null;
4042 }
4043
4044
4054 public JournalTemplate findByG_S_Last(long groupId, String structureId,
4055 OrderByComparator orderByComparator)
4056 throws NoSuchTemplateException, SystemException {
4057 JournalTemplate journalTemplate = fetchByG_S_Last(groupId, structureId,
4058 orderByComparator);
4059
4060 if (journalTemplate != null) {
4061 return journalTemplate;
4062 }
4063
4064 StringBundler msg = new StringBundler(6);
4065
4066 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4067
4068 msg.append("groupId=");
4069 msg.append(groupId);
4070
4071 msg.append(", structureId=");
4072 msg.append(structureId);
4073
4074 msg.append(StringPool.CLOSE_CURLY_BRACE);
4075
4076 throw new NoSuchTemplateException(msg.toString());
4077 }
4078
4079
4088 public JournalTemplate fetchByG_S_Last(long groupId, String structureId,
4089 OrderByComparator orderByComparator) throws SystemException {
4090 int count = countByG_S(groupId, structureId);
4091
4092 List<JournalTemplate> list = findByG_S(groupId, structureId, count - 1,
4093 count, orderByComparator);
4094
4095 if (!list.isEmpty()) {
4096 return list.get(0);
4097 }
4098
4099 return null;
4100 }
4101
4102
4113 public JournalTemplate[] findByG_S_PrevAndNext(long id, long groupId,
4114 String structureId, OrderByComparator orderByComparator)
4115 throws NoSuchTemplateException, SystemException {
4116 JournalTemplate journalTemplate = findByPrimaryKey(id);
4117
4118 Session session = null;
4119
4120 try {
4121 session = openSession();
4122
4123 JournalTemplate[] array = new JournalTemplateImpl[3];
4124
4125 array[0] = getByG_S_PrevAndNext(session, journalTemplate, groupId,
4126 structureId, orderByComparator, true);
4127
4128 array[1] = journalTemplate;
4129
4130 array[2] = getByG_S_PrevAndNext(session, journalTemplate, groupId,
4131 structureId, orderByComparator, false);
4132
4133 return array;
4134 }
4135 catch (Exception e) {
4136 throw processException(e);
4137 }
4138 finally {
4139 closeSession(session);
4140 }
4141 }
4142
4143 protected JournalTemplate getByG_S_PrevAndNext(Session session,
4144 JournalTemplate journalTemplate, long groupId, String structureId,
4145 OrderByComparator orderByComparator, boolean previous) {
4146 StringBundler query = null;
4147
4148 if (orderByComparator != null) {
4149 query = new StringBundler(6 +
4150 (orderByComparator.getOrderByFields().length * 6));
4151 }
4152 else {
4153 query = new StringBundler(3);
4154 }
4155
4156 query.append(_SQL_SELECT_JOURNALTEMPLATE_WHERE);
4157
4158 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4159
4160 boolean bindStructureId = false;
4161
4162 if (structureId == null) {
4163 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
4164 }
4165 else if (structureId.equals(StringPool.BLANK)) {
4166 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
4167 }
4168 else {
4169 bindStructureId = true;
4170
4171 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
4172 }
4173
4174 if (orderByComparator != null) {
4175 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4176
4177 if (orderByConditionFields.length > 0) {
4178 query.append(WHERE_AND);
4179 }
4180
4181 for (int i = 0; i < orderByConditionFields.length; i++) {
4182 query.append(_ORDER_BY_ENTITY_ALIAS);
4183 query.append(orderByConditionFields[i]);
4184
4185 if ((i + 1) < orderByConditionFields.length) {
4186 if (orderByComparator.isAscending() ^ previous) {
4187 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4188 }
4189 else {
4190 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4191 }
4192 }
4193 else {
4194 if (orderByComparator.isAscending() ^ previous) {
4195 query.append(WHERE_GREATER_THAN);
4196 }
4197 else {
4198 query.append(WHERE_LESSER_THAN);
4199 }
4200 }
4201 }
4202
4203 query.append(ORDER_BY_CLAUSE);
4204
4205 String[] orderByFields = orderByComparator.getOrderByFields();
4206
4207 for (int i = 0; i < orderByFields.length; i++) {
4208 query.append(_ORDER_BY_ENTITY_ALIAS);
4209 query.append(orderByFields[i]);
4210
4211 if ((i + 1) < orderByFields.length) {
4212 if (orderByComparator.isAscending() ^ previous) {
4213 query.append(ORDER_BY_ASC_HAS_NEXT);
4214 }
4215 else {
4216 query.append(ORDER_BY_DESC_HAS_NEXT);
4217 }
4218 }
4219 else {
4220 if (orderByComparator.isAscending() ^ previous) {
4221 query.append(ORDER_BY_ASC);
4222 }
4223 else {
4224 query.append(ORDER_BY_DESC);
4225 }
4226 }
4227 }
4228 }
4229 else {
4230 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
4231 }
4232
4233 String sql = query.toString();
4234
4235 Query q = session.createQuery(sql);
4236
4237 q.setFirstResult(0);
4238 q.setMaxResults(2);
4239
4240 QueryPos qPos = QueryPos.getInstance(q);
4241
4242 qPos.add(groupId);
4243
4244 if (bindStructureId) {
4245 qPos.add(structureId);
4246 }
4247
4248 if (orderByComparator != null) {
4249 Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
4250
4251 for (Object value : values) {
4252 qPos.add(value);
4253 }
4254 }
4255
4256 List<JournalTemplate> list = q.list();
4257
4258 if (list.size() == 2) {
4259 return list.get(1);
4260 }
4261 else {
4262 return null;
4263 }
4264 }
4265
4266
4274 public List<JournalTemplate> filterFindByG_S(long groupId,
4275 String structureId) throws SystemException {
4276 return filterFindByG_S(groupId, structureId, QueryUtil.ALL_POS,
4277 QueryUtil.ALL_POS, null);
4278 }
4279
4280
4294 public List<JournalTemplate> filterFindByG_S(long groupId,
4295 String structureId, int start, int end) throws SystemException {
4296 return filterFindByG_S(groupId, structureId, start, end, null);
4297 }
4298
4299
4314 public List<JournalTemplate> filterFindByG_S(long groupId,
4315 String structureId, int start, int end,
4316 OrderByComparator orderByComparator) throws SystemException {
4317 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4318 return findByG_S(groupId, structureId, start, end, orderByComparator);
4319 }
4320
4321 StringBundler query = null;
4322
4323 if (orderByComparator != null) {
4324 query = new StringBundler(4 +
4325 (orderByComparator.getOrderByFields().length * 3));
4326 }
4327 else {
4328 query = new StringBundler(4);
4329 }
4330
4331 if (getDB().isSupportsInlineDistinct()) {
4332 query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
4333 }
4334 else {
4335 query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
4336 }
4337
4338 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4339
4340 boolean bindStructureId = false;
4341
4342 if (structureId == null) {
4343 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
4344 }
4345 else if (structureId.equals(StringPool.BLANK)) {
4346 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
4347 }
4348 else {
4349 bindStructureId = true;
4350
4351 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
4352 }
4353
4354 if (!getDB().isSupportsInlineDistinct()) {
4355 query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
4356 }
4357
4358 if (orderByComparator != null) {
4359 if (getDB().isSupportsInlineDistinct()) {
4360 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4361 orderByComparator, true);
4362 }
4363 else {
4364 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4365 orderByComparator, true);
4366 }
4367 }
4368 else {
4369 if (getDB().isSupportsInlineDistinct()) {
4370 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
4371 }
4372 else {
4373 query.append(JournalTemplateModelImpl.ORDER_BY_SQL);
4374 }
4375 }
4376
4377 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4378 JournalTemplate.class.getName(),
4379 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4380
4381 Session session = null;
4382
4383 try {
4384 session = openSession();
4385
4386 SQLQuery q = session.createSQLQuery(sql);
4387
4388 if (getDB().isSupportsInlineDistinct()) {
4389 q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
4390 }
4391 else {
4392 q.addEntity(_FILTER_ENTITY_TABLE, JournalTemplateImpl.class);
4393 }
4394
4395 QueryPos qPos = QueryPos.getInstance(q);
4396
4397 qPos.add(groupId);
4398
4399 if (bindStructureId) {
4400 qPos.add(structureId);
4401 }
4402
4403 return (List<JournalTemplate>)QueryUtil.list(q, getDialect(),
4404 start, end);
4405 }
4406 catch (Exception e) {
4407 throw processException(e);
4408 }
4409 finally {
4410 closeSession(session);
4411 }
4412 }
4413
4414
4425 public JournalTemplate[] filterFindByG_S_PrevAndNext(long id, long groupId,
4426 String structureId, OrderByComparator orderByComparator)
4427 throws NoSuchTemplateException, SystemException {
4428 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4429 return findByG_S_PrevAndNext(id, groupId, structureId,
4430 orderByComparator);
4431 }
4432
4433 JournalTemplate journalTemplate = findByPrimaryKey(id);
4434
4435 Session session = null;
4436
4437 try {
4438 session = openSession();
4439
4440 JournalTemplate[] array = new JournalTemplateImpl[3];
4441
4442 array[0] = filterGetByG_S_PrevAndNext(session, journalTemplate,
4443 groupId, structureId, orderByComparator, true);
4444
4445 array[1] = journalTemplate;
4446
4447 array[2] = filterGetByG_S_PrevAndNext(session, journalTemplate,
4448 groupId, structureId, orderByComparator, false);
4449
4450 return array;
4451 }
4452 catch (Exception e) {
4453 throw processException(e);
4454 }
4455 finally {
4456 closeSession(session);
4457 }
4458 }
4459
4460 protected JournalTemplate filterGetByG_S_PrevAndNext(Session session,
4461 JournalTemplate journalTemplate, long groupId, String structureId,
4462 OrderByComparator orderByComparator, boolean previous) {
4463 StringBundler query = null;
4464
4465 if (orderByComparator != null) {
4466 query = new StringBundler(6 +
4467 (orderByComparator.getOrderByFields().length * 6));
4468 }
4469 else {
4470 query = new StringBundler(3);
4471 }
4472
4473 if (getDB().isSupportsInlineDistinct()) {
4474 query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE);
4475 }
4476 else {
4477 query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1);
4478 }
4479
4480 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4481
4482 boolean bindStructureId = false;
4483
4484 if (structureId == null) {
4485 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
4486 }
4487 else if (structureId.equals(StringPool.BLANK)) {
4488 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
4489 }
4490 else {
4491 bindStructureId = true;
4492
4493 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
4494 }
4495
4496 if (!getDB().isSupportsInlineDistinct()) {
4497 query.append(_FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2);
4498 }
4499
4500 if (orderByComparator != null) {
4501 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4502
4503 if (orderByConditionFields.length > 0) {
4504 query.append(WHERE_AND);
4505 }
4506
4507 for (int i = 0; i < orderByConditionFields.length; i++) {
4508 if (getDB().isSupportsInlineDistinct()) {
4509 query.append(_ORDER_BY_ENTITY_ALIAS);
4510 }
4511 else {
4512 query.append(_ORDER_BY_ENTITY_TABLE);
4513 }
4514
4515 query.append(orderByConditionFields[i]);
4516
4517 if ((i + 1) < orderByConditionFields.length) {
4518 if (orderByComparator.isAscending() ^ previous) {
4519 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4520 }
4521 else {
4522 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4523 }
4524 }
4525 else {
4526 if (orderByComparator.isAscending() ^ previous) {
4527 query.append(WHERE_GREATER_THAN);
4528 }
4529 else {
4530 query.append(WHERE_LESSER_THAN);
4531 }
4532 }
4533 }
4534
4535 query.append(ORDER_BY_CLAUSE);
4536
4537 String[] orderByFields = orderByComparator.getOrderByFields();
4538
4539 for (int i = 0; i < orderByFields.length; i++) {
4540 if (getDB().isSupportsInlineDistinct()) {
4541 query.append(_ORDER_BY_ENTITY_ALIAS);
4542 }
4543 else {
4544 query.append(_ORDER_BY_ENTITY_TABLE);
4545 }
4546
4547 query.append(orderByFields[i]);
4548
4549 if ((i + 1) < orderByFields.length) {
4550 if (orderByComparator.isAscending() ^ previous) {
4551 query.append(ORDER_BY_ASC_HAS_NEXT);
4552 }
4553 else {
4554 query.append(ORDER_BY_DESC_HAS_NEXT);
4555 }
4556 }
4557 else {
4558 if (orderByComparator.isAscending() ^ previous) {
4559 query.append(ORDER_BY_ASC);
4560 }
4561 else {
4562 query.append(ORDER_BY_DESC);
4563 }
4564 }
4565 }
4566 }
4567 else {
4568 if (getDB().isSupportsInlineDistinct()) {
4569 query.append(JournalTemplateModelImpl.ORDER_BY_JPQL);
4570 }
4571 else {
4572 query.append(JournalTemplateModelImpl.ORDER_BY_SQL);
4573 }
4574 }
4575
4576 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4577 JournalTemplate.class.getName(),
4578 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4579
4580 SQLQuery q = session.createSQLQuery(sql);
4581
4582 q.setFirstResult(0);
4583 q.setMaxResults(2);
4584
4585 if (getDB().isSupportsInlineDistinct()) {
4586 q.addEntity(_FILTER_ENTITY_ALIAS, JournalTemplateImpl.class);
4587 }
4588 else {
4589 q.addEntity(_FILTER_ENTITY_TABLE, JournalTemplateImpl.class);
4590 }
4591
4592 QueryPos qPos = QueryPos.getInstance(q);
4593
4594 qPos.add(groupId);
4595
4596 if (bindStructureId) {
4597 qPos.add(structureId);
4598 }
4599
4600 if (orderByComparator != null) {
4601 Object[] values = orderByComparator.getOrderByConditionValues(journalTemplate);
4602
4603 for (Object value : values) {
4604 qPos.add(value);
4605 }
4606 }
4607
4608 List<JournalTemplate> list = q.list();
4609
4610 if (list.size() == 2) {
4611 return list.get(1);
4612 }
4613 else {
4614 return null;
4615 }
4616 }
4617
4618
4625 public void removeByG_S(long groupId, String structureId)
4626 throws SystemException {
4627 for (JournalTemplate journalTemplate : findByG_S(groupId, structureId,
4628 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4629 remove(journalTemplate);
4630 }
4631 }
4632
4633
4641 public int countByG_S(long groupId, String structureId)
4642 throws SystemException {
4643 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
4644
4645 Object[] finderArgs = new Object[] { groupId, structureId };
4646
4647 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4648 this);
4649
4650 if (count == null) {
4651 StringBundler query = new StringBundler(3);
4652
4653 query.append(_SQL_COUNT_JOURNALTEMPLATE_WHERE);
4654
4655 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4656
4657 boolean bindStructureId = false;
4658
4659 if (structureId == null) {
4660 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
4661 }
4662 else if (structureId.equals(StringPool.BLANK)) {
4663 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
4664 }
4665 else {
4666 bindStructureId = true;
4667
4668 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
4669 }
4670
4671 String sql = query.toString();
4672
4673 Session session = null;
4674
4675 try {
4676 session = openSession();
4677
4678 Query q = session.createQuery(sql);
4679
4680 QueryPos qPos = QueryPos.getInstance(q);
4681
4682 qPos.add(groupId);
4683
4684 if (bindStructureId) {
4685 qPos.add(structureId);
4686 }
4687
4688 count = (Long)q.uniqueResult();
4689
4690 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4691 }
4692 catch (Exception e) {
4693 FinderCacheUtil.removeResult(finderPath, finderArgs);
4694
4695 throw processException(e);
4696 }
4697 finally {
4698 closeSession(session);
4699 }
4700 }
4701
4702 return count.intValue();
4703 }
4704
4705
4713 public int filterCountByG_S(long groupId, String structureId)
4714 throws SystemException {
4715 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4716 return countByG_S(groupId, structureId);
4717 }
4718
4719 StringBundler query = new StringBundler(3);
4720
4721 query.append(_FILTER_SQL_COUNT_JOURNALTEMPLATE_WHERE);
4722
4723 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4724
4725 boolean bindStructureId = false;
4726
4727 if (structureId == null) {
4728 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
4729 }
4730 else if (structureId.equals(StringPool.BLANK)) {
4731 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
4732 }
4733 else {
4734 bindStructureId = true;
4735
4736 query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
4737 }
4738
4739 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4740 JournalTemplate.class.getName(),
4741 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4742
4743 Session session = null;
4744
4745 try {
4746 session = openSession();
4747
4748 SQLQuery q = session.createSQLQuery(sql);
4749
4750 q.addScalar(COUNT_COLUMN_NAME,
4751 com.liferay.portal.kernel.dao.orm.Type.LONG);
4752
4753 QueryPos qPos = QueryPos.getInstance(q);
4754
4755 qPos.add(groupId);
4756
4757 if (bindStructureId) {
4758 qPos.add(structureId);
4759 }
4760
4761 Long count = (Long)q.uniqueResult();
4762
4763 return count.intValue();
4764 }
4765 catch (Exception e) {
4766 throw processException(e);
4767 }
4768 finally {
4769 closeSession(session);
4770 }
4771 }
4772
4773 private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "journalTemplate.groupId = ? AND ";
4774 private static final String _FINDER_COLUMN_G_S_STRUCTUREID_1 = "journalTemplate.structureId IS NULL";
4775 private static final String _FINDER_COLUMN_G_S_STRUCTUREID_2 = "journalTemplate.structureId = ?";
4776 private static final String _FINDER_COLUMN_G_S_STRUCTUREID_3 = "(journalTemplate.structureId IS NULL OR journalTemplate.structureId = '')";
4777
4778
4783 public void cacheResult(JournalTemplate journalTemplate) {
4784 EntityCacheUtil.putResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
4785 JournalTemplateImpl.class, journalTemplate.getPrimaryKey(),
4786 journalTemplate);
4787
4788 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
4789 new Object[] { journalTemplate.getUuid(), journalTemplate.getGroupId() },
4790 journalTemplate);
4791
4792 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
4793 new Object[] { journalTemplate.getSmallImageId() }, journalTemplate);
4794
4795 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T,
4796 new Object[] {
4797 journalTemplate.getGroupId(), journalTemplate.getTemplateId()
4798 }, journalTemplate);
4799
4800 journalTemplate.resetOriginalValues();
4801 }
4802
4803
4808 public void cacheResult(List<JournalTemplate> journalTemplates) {
4809 for (JournalTemplate journalTemplate : journalTemplates) {
4810 if (EntityCacheUtil.getResult(
4811 JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
4812 JournalTemplateImpl.class,
4813 journalTemplate.getPrimaryKey()) == null) {
4814 cacheResult(journalTemplate);
4815 }
4816 else {
4817 journalTemplate.resetOriginalValues();
4818 }
4819 }
4820 }
4821
4822
4829 @Override
4830 public void clearCache() {
4831 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
4832 CacheRegistryUtil.clear(JournalTemplateImpl.class.getName());
4833 }
4834
4835 EntityCacheUtil.clearCache(JournalTemplateImpl.class.getName());
4836
4837 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4838 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4839 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4840 }
4841
4842
4849 @Override
4850 public void clearCache(JournalTemplate journalTemplate) {
4851 EntityCacheUtil.removeResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
4852 JournalTemplateImpl.class, journalTemplate.getPrimaryKey());
4853
4854 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4855 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4856
4857 clearUniqueFindersCache(journalTemplate);
4858 }
4859
4860 @Override
4861 public void clearCache(List<JournalTemplate> journalTemplates) {
4862 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4863 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4864
4865 for (JournalTemplate journalTemplate : journalTemplates) {
4866 EntityCacheUtil.removeResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
4867 JournalTemplateImpl.class, journalTemplate.getPrimaryKey());
4868
4869 clearUniqueFindersCache(journalTemplate);
4870 }
4871 }
4872
4873 protected void cacheUniqueFindersCache(JournalTemplate journalTemplate) {
4874 if (journalTemplate.isNew()) {
4875 Object[] args = new Object[] {
4876 journalTemplate.getUuid(), journalTemplate.getGroupId()
4877 };
4878
4879 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4880 Long.valueOf(1));
4881 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4882 journalTemplate);
4883
4884 args = new Object[] { journalTemplate.getSmallImageId() };
4885
4886 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID, args,
4887 Long.valueOf(1));
4888 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID, args,
4889 journalTemplate);
4890
4891 args = new Object[] {
4892 journalTemplate.getGroupId(),
4893 journalTemplate.getTemplateId()
4894 };
4895
4896 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_T, args,
4897 Long.valueOf(1));
4898 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T, args,
4899 journalTemplate);
4900 }
4901 else {
4902 JournalTemplateModelImpl journalTemplateModelImpl = (JournalTemplateModelImpl)journalTemplate;
4903
4904 if ((journalTemplateModelImpl.getColumnBitmask() &
4905 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4906 Object[] args = new Object[] {
4907 journalTemplate.getUuid(), journalTemplate.getGroupId()
4908 };
4909
4910 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4911 Long.valueOf(1));
4912 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4913 journalTemplate);
4914 }
4915
4916 if ((journalTemplateModelImpl.getColumnBitmask() &
4917 FINDER_PATH_FETCH_BY_SMALLIMAGEID.getColumnBitmask()) != 0) {
4918 Object[] args = new Object[] { journalTemplate.getSmallImageId() };
4919
4920 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
4921 args, Long.valueOf(1));
4922 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
4923 args, journalTemplate);
4924 }
4925
4926 if ((journalTemplateModelImpl.getColumnBitmask() &
4927 FINDER_PATH_FETCH_BY_G_T.getColumnBitmask()) != 0) {
4928 Object[] args = new Object[] {
4929 journalTemplate.getGroupId(),
4930 journalTemplate.getTemplateId()
4931 };
4932
4933 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_T, args,
4934 Long.valueOf(1));
4935 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_T, args,
4936 journalTemplate);
4937 }
4938 }
4939 }
4940
4941 protected void clearUniqueFindersCache(JournalTemplate journalTemplate) {
4942 JournalTemplateModelImpl journalTemplateModelImpl = (JournalTemplateModelImpl)journalTemplate;
4943
4944 Object[] args = new Object[] {
4945 journalTemplate.getUuid(), journalTemplate.getGroupId()
4946 };
4947
4948 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4949 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4950
4951 if ((journalTemplateModelImpl.getColumnBitmask() &
4952 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4953 args = new Object[] {
4954 journalTemplateModelImpl.getOriginalUuid(),
4955 journalTemplateModelImpl.getOriginalGroupId()
4956 };
4957
4958 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4959 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4960 }
4961
4962 args = new Object[] { journalTemplate.getSmallImageId() };
4963
4964 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID, args);
4965 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID, args);
4966
4967 if ((journalTemplateModelImpl.getColumnBitmask() &
4968 FINDER_PATH_FETCH_BY_SMALLIMAGEID.getColumnBitmask()) != 0) {
4969 args = new Object[] {
4970 journalTemplateModelImpl.getOriginalSmallImageId()
4971 };
4972
4973 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID, args);
4974 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID, args);
4975 }
4976
4977 args = new Object[] {
4978 journalTemplate.getGroupId(), journalTemplate.getTemplateId()
4979 };
4980
4981 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T, args);
4982 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T, args);
4983
4984 if ((journalTemplateModelImpl.getColumnBitmask() &
4985 FINDER_PATH_FETCH_BY_G_T.getColumnBitmask()) != 0) {
4986 args = new Object[] {
4987 journalTemplateModelImpl.getOriginalGroupId(),
4988 journalTemplateModelImpl.getOriginalTemplateId()
4989 };
4990
4991 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T, args);
4992 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_T, args);
4993 }
4994 }
4995
4996
5002 public JournalTemplate create(long id) {
5003 JournalTemplate journalTemplate = new JournalTemplateImpl();
5004
5005 journalTemplate.setNew(true);
5006 journalTemplate.setPrimaryKey(id);
5007
5008 String uuid = PortalUUIDUtil.generate();
5009
5010 journalTemplate.setUuid(uuid);
5011
5012 return journalTemplate;
5013 }
5014
5015
5023 public JournalTemplate remove(long id)
5024 throws NoSuchTemplateException, SystemException {
5025 return remove((Serializable)id);
5026 }
5027
5028
5036 @Override
5037 public JournalTemplate remove(Serializable primaryKey)
5038 throws NoSuchTemplateException, SystemException {
5039 Session session = null;
5040
5041 try {
5042 session = openSession();
5043
5044 JournalTemplate journalTemplate = (JournalTemplate)session.get(JournalTemplateImpl.class,
5045 primaryKey);
5046
5047 if (journalTemplate == null) {
5048 if (_log.isWarnEnabled()) {
5049 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5050 }
5051
5052 throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5053 primaryKey);
5054 }
5055
5056 return remove(journalTemplate);
5057 }
5058 catch (NoSuchTemplateException nsee) {
5059 throw nsee;
5060 }
5061 catch (Exception e) {
5062 throw processException(e);
5063 }
5064 finally {
5065 closeSession(session);
5066 }
5067 }
5068
5069 @Override
5070 protected JournalTemplate removeImpl(JournalTemplate journalTemplate)
5071 throws SystemException {
5072 journalTemplate = toUnwrappedModel(journalTemplate);
5073
5074 Session session = null;
5075
5076 try {
5077 session = openSession();
5078
5079 if (!session.contains(journalTemplate)) {
5080 journalTemplate = (JournalTemplate)session.get(JournalTemplateImpl.class,
5081 journalTemplate.getPrimaryKeyObj());
5082 }
5083
5084 if (journalTemplate != null) {
5085 session.delete(journalTemplate);
5086 }
5087 }
5088 catch (Exception e) {
5089 throw processException(e);
5090 }
5091 finally {
5092 closeSession(session);
5093 }
5094
5095 if (journalTemplate != null) {
5096 clearCache(journalTemplate);
5097 }
5098
5099 return journalTemplate;
5100 }
5101
5102 @Override
5103 public JournalTemplate updateImpl(
5104 com.liferay.portlet.journal.model.JournalTemplate journalTemplate)
5105 throws SystemException {
5106 journalTemplate = toUnwrappedModel(journalTemplate);
5107
5108 boolean isNew = journalTemplate.isNew();
5109
5110 JournalTemplateModelImpl journalTemplateModelImpl = (JournalTemplateModelImpl)journalTemplate;
5111
5112 if (Validator.isNull(journalTemplate.getUuid())) {
5113 String uuid = PortalUUIDUtil.generate();
5114
5115 journalTemplate.setUuid(uuid);
5116 }
5117
5118 Session session = null;
5119
5120 try {
5121 session = openSession();
5122
5123 if (journalTemplate.isNew()) {
5124 session.save(journalTemplate);
5125
5126 journalTemplate.setNew(false);
5127 }
5128 else {
5129 session.merge(journalTemplate);
5130 }
5131 }
5132 catch (Exception e) {
5133 throw processException(e);
5134 }
5135 finally {
5136 closeSession(session);
5137 }
5138
5139 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5140
5141 if (isNew || !JournalTemplateModelImpl.COLUMN_BITMASK_ENABLED) {
5142 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5143 }
5144
5145 else {
5146 if ((journalTemplateModelImpl.getColumnBitmask() &
5147 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
5148 Object[] args = new Object[] {
5149 journalTemplateModelImpl.getOriginalUuid()
5150 };
5151
5152 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5153 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5154 args);
5155
5156 args = new Object[] { journalTemplateModelImpl.getUuid() };
5157
5158 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5159 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5160 args);
5161 }
5162
5163 if ((journalTemplateModelImpl.getColumnBitmask() &
5164 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
5165 Object[] args = new Object[] {
5166 journalTemplateModelImpl.getOriginalUuid(),
5167 journalTemplateModelImpl.getOriginalCompanyId()
5168 };
5169
5170 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
5171 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
5172 args);
5173
5174 args = new Object[] {
5175 journalTemplateModelImpl.getUuid(),
5176 journalTemplateModelImpl.getCompanyId()
5177 };
5178
5179 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
5180 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
5181 args);
5182 }
5183
5184 if ((journalTemplateModelImpl.getColumnBitmask() &
5185 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
5186 Object[] args = new Object[] {
5187 journalTemplateModelImpl.getOriginalGroupId()
5188 };
5189
5190 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
5191 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
5192 args);
5193
5194 args = new Object[] { journalTemplateModelImpl.getGroupId() };
5195
5196 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
5197 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
5198 args);
5199 }
5200
5201 if ((journalTemplateModelImpl.getColumnBitmask() &
5202 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID.getColumnBitmask()) != 0) {
5203 Object[] args = new Object[] {
5204 journalTemplateModelImpl.getOriginalTemplateId()
5205 };
5206
5207 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
5208 args);
5209 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID,
5210 args);
5211
5212 args = new Object[] { journalTemplateModelImpl.getTemplateId() };
5213
5214 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
5215 args);
5216 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID,
5217 args);
5218 }
5219
5220 if ((journalTemplateModelImpl.getColumnBitmask() &
5221 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID.getColumnBitmask()) != 0) {
5222 Object[] args = new Object[] {
5223 journalTemplateModelImpl.getOriginalStructureId()
5224 };
5225
5226 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
5227 args);
5228 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
5229 args);
5230
5231 args = new Object[] { journalTemplateModelImpl.getStructureId() };
5232
5233 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
5234 args);
5235 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
5236 args);
5237 }
5238
5239 if ((journalTemplateModelImpl.getColumnBitmask() &
5240 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
5241 Object[] args = new Object[] {
5242 journalTemplateModelImpl.getOriginalGroupId(),
5243 journalTemplateModelImpl.getOriginalStructureId()
5244 };
5245
5246 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
5247 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
5248 args);
5249
5250 args = new Object[] {
5251 journalTemplateModelImpl.getGroupId(),
5252 journalTemplateModelImpl.getStructureId()
5253 };
5254
5255 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
5256 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
5257 args);
5258 }
5259 }
5260
5261 EntityCacheUtil.putResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
5262 JournalTemplateImpl.class, journalTemplate.getPrimaryKey(),
5263 journalTemplate);
5264
5265 clearUniqueFindersCache(journalTemplate);
5266 cacheUniqueFindersCache(journalTemplate);
5267
5268 return journalTemplate;
5269 }
5270
5271 protected JournalTemplate toUnwrappedModel(JournalTemplate journalTemplate) {
5272 if (journalTemplate instanceof JournalTemplateImpl) {
5273 return journalTemplate;
5274 }
5275
5276 JournalTemplateImpl journalTemplateImpl = new JournalTemplateImpl();
5277
5278 journalTemplateImpl.setNew(journalTemplate.isNew());
5279 journalTemplateImpl.setPrimaryKey(journalTemplate.getPrimaryKey());
5280
5281 journalTemplateImpl.setUuid(journalTemplate.getUuid());
5282 journalTemplateImpl.setId(journalTemplate.getId());
5283 journalTemplateImpl.setGroupId(journalTemplate.getGroupId());
5284 journalTemplateImpl.setCompanyId(journalTemplate.getCompanyId());
5285 journalTemplateImpl.setUserId(journalTemplate.getUserId());
5286 journalTemplateImpl.setUserName(journalTemplate.getUserName());
5287 journalTemplateImpl.setCreateDate(journalTemplate.getCreateDate());
5288 journalTemplateImpl.setModifiedDate(journalTemplate.getModifiedDate());
5289 journalTemplateImpl.setTemplateId(journalTemplate.getTemplateId());
5290 journalTemplateImpl.setStructureId(journalTemplate.getStructureId());
5291 journalTemplateImpl.setName(journalTemplate.getName());
5292 journalTemplateImpl.setDescription(journalTemplate.getDescription());
5293 journalTemplateImpl.setXsl(journalTemplate.getXsl());
5294 journalTemplateImpl.setLangType(journalTemplate.getLangType());
5295 journalTemplateImpl.setCacheable(journalTemplate.isCacheable());
5296 journalTemplateImpl.setSmallImage(journalTemplate.isSmallImage());
5297 journalTemplateImpl.setSmallImageId(journalTemplate.getSmallImageId());
5298 journalTemplateImpl.setSmallImageURL(journalTemplate.getSmallImageURL());
5299
5300 return journalTemplateImpl;
5301 }
5302
5303
5311 @Override
5312 public JournalTemplate findByPrimaryKey(Serializable primaryKey)
5313 throws NoSuchTemplateException, SystemException {
5314 JournalTemplate journalTemplate = fetchByPrimaryKey(primaryKey);
5315
5316 if (journalTemplate == null) {
5317 if (_log.isWarnEnabled()) {
5318 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5319 }
5320
5321 throw new NoSuchTemplateException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5322 primaryKey);
5323 }
5324
5325 return journalTemplate;
5326 }
5327
5328
5336 public JournalTemplate findByPrimaryKey(long id)
5337 throws NoSuchTemplateException, SystemException {
5338 return findByPrimaryKey((Serializable)id);
5339 }
5340
5341
5348 @Override
5349 public JournalTemplate fetchByPrimaryKey(Serializable primaryKey)
5350 throws SystemException {
5351 JournalTemplate journalTemplate = (JournalTemplate)EntityCacheUtil.getResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
5352 JournalTemplateImpl.class, primaryKey);
5353
5354 if (journalTemplate == _nullJournalTemplate) {
5355 return null;
5356 }
5357
5358 if (journalTemplate == null) {
5359 Session session = null;
5360
5361 try {
5362 session = openSession();
5363
5364 journalTemplate = (JournalTemplate)session.get(JournalTemplateImpl.class,
5365 primaryKey);
5366
5367 if (journalTemplate != null) {
5368 cacheResult(journalTemplate);
5369 }
5370 else {
5371 EntityCacheUtil.putResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
5372 JournalTemplateImpl.class, primaryKey,
5373 _nullJournalTemplate);
5374 }
5375 }
5376 catch (Exception e) {
5377 EntityCacheUtil.removeResult(JournalTemplateModelImpl.ENTITY_CACHE_ENABLED,
5378 JournalTemplateImpl.class, primaryKey);
5379
5380 throw processException(e);
5381 }
5382 finally {
5383 closeSession(session);
5384 }
5385 }
5386
5387 return journalTemplate;
5388 }
5389
5390
5397 public JournalTemplate fetchByPrimaryKey(long id) throws SystemException {
5398 return fetchByPrimaryKey((Serializable)id);
5399 }
5400
5401
5407 public List<JournalTemplate> findAll() throws SystemException {
5408 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5409 }
5410
5411
5423 public List<JournalTemplate> findAll(int start, int end)
5424 throws SystemException {
5425 return findAll(start, end, null);
5426 }
5427
5428
5441 public List<JournalTemplate> findAll(int start, int end,
5442 OrderByComparator orderByComparator) throws SystemException {
5443 boolean pagination = true;
5444 FinderPath finderPath = null;
5445 Object[] finderArgs = null;
5446
5447 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5448 (orderByComparator == null)) {
5449 pagination = false;
5450 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5451 finderArgs = FINDER_ARGS_EMPTY;
5452 }
5453 else {
5454 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5455 finderArgs = new Object[] { start, end, orderByComparator };
5456 }
5457
5458 List<JournalTemplate> list = (List<JournalTemplate>)FinderCacheUtil.getResult(finderPath,
5459 finderArgs, this);
5460
5461 if (list == null) {
5462 StringBundler query = null;
5463 String sql = null;
5464
5465 if (orderByComparator != null) {
5466 query = new StringBundler(2 +
5467 (orderByComparator.getOrderByFields().length * 3));
5468
5469 query.append(_SQL_SELECT_JOURNALTEMPLATE);
5470
5471 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5472 orderByComparator);
5473
5474 sql = query.toString();
5475 }
5476 else {
5477 sql = _SQL_SELECT_JOURNALTEMPLATE;
5478
5479 if (pagination) {
5480 sql = sql.concat(JournalTemplateModelImpl.ORDER_BY_JPQL);
5481 }
5482 }
5483
5484 Session session = null;
5485
5486 try {
5487 session = openSession();
5488
5489 Query q = session.createQuery(sql);
5490
5491 if (!pagination) {
5492 list = (List<JournalTemplate>)QueryUtil.list(q,
5493 getDialect(), start, end, false);
5494
5495 Collections.sort(list);
5496
5497 list = new UnmodifiableList<JournalTemplate>(list);
5498 }
5499 else {
5500 list = (List<JournalTemplate>)QueryUtil.list(q,
5501 getDialect(), start, end);
5502 }
5503
5504 cacheResult(list);
5505
5506 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5507 }
5508 catch (Exception e) {
5509 FinderCacheUtil.removeResult(finderPath, finderArgs);
5510
5511 throw processException(e);
5512 }
5513 finally {
5514 closeSession(session);
5515 }
5516 }
5517
5518 return list;
5519 }
5520
5521
5526 public void removeAll() throws SystemException {
5527 for (JournalTemplate journalTemplate : findAll()) {
5528 remove(journalTemplate);
5529 }
5530 }
5531
5532
5538 public int countAll() throws SystemException {
5539 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5540 FINDER_ARGS_EMPTY, this);
5541
5542 if (count == null) {
5543 Session session = null;
5544
5545 try {
5546 session = openSession();
5547
5548 Query q = session.createQuery(_SQL_COUNT_JOURNALTEMPLATE);
5549
5550 count = (Long)q.uniqueResult();
5551
5552 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5553 FINDER_ARGS_EMPTY, count);
5554 }
5555 catch (Exception e) {
5556 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
5557 FINDER_ARGS_EMPTY);
5558
5559 throw processException(e);
5560 }
5561 finally {
5562 closeSession(session);
5563 }
5564 }
5565
5566 return count.intValue();
5567 }
5568
5569 @Override
5570 protected Set<String> getBadColumnNames() {
5571 return _badColumnNames;
5572 }
5573
5574
5577 public void afterPropertiesSet() {
5578 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5579 com.liferay.portal.util.PropsUtil.get(
5580 "value.object.listener.com.liferay.portlet.journal.model.JournalTemplate")));
5581
5582 if (listenerClassNames.length > 0) {
5583 try {
5584 List<ModelListener<JournalTemplate>> listenersList = new ArrayList<ModelListener<JournalTemplate>>();
5585
5586 for (String listenerClassName : listenerClassNames) {
5587 listenersList.add((ModelListener<JournalTemplate>)InstanceFactory.newInstance(
5588 getClassLoader(), listenerClassName));
5589 }
5590
5591 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5592 }
5593 catch (Exception e) {
5594 _log.error(e);
5595 }
5596 }
5597 }
5598
5599 public void destroy() {
5600 EntityCacheUtil.removeCache(JournalTemplateImpl.class.getName());
5601 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5602 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5603 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5604 }
5605
5606 private static final String _SQL_SELECT_JOURNALTEMPLATE = "SELECT journalTemplate FROM JournalTemplate journalTemplate";
5607 private static final String _SQL_SELECT_JOURNALTEMPLATE_WHERE = "SELECT journalTemplate FROM JournalTemplate journalTemplate WHERE ";
5608 private static final String _SQL_COUNT_JOURNALTEMPLATE = "SELECT COUNT(journalTemplate) FROM JournalTemplate journalTemplate";
5609 private static final String _SQL_COUNT_JOURNALTEMPLATE_WHERE = "SELECT COUNT(journalTemplate) FROM JournalTemplate journalTemplate WHERE ";
5610 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "journalTemplate.id_";
5611 private static final String _FILTER_SQL_SELECT_JOURNALTEMPLATE_WHERE = "SELECT DISTINCT {journalTemplate.*} FROM JournalTemplate journalTemplate WHERE ";
5612 private static final String _FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_1 =
5613 "SELECT {JournalTemplate.*} FROM (SELECT DISTINCT journalTemplate.id_ FROM JournalTemplate journalTemplate WHERE ";
5614 private static final String _FILTER_SQL_SELECT_JOURNALTEMPLATE_NO_INLINE_DISTINCT_WHERE_2 =
5615 ") TEMP_TABLE INNER JOIN JournalTemplate ON TEMP_TABLE.id_ = JournalTemplate.id_";
5616 private static final String _FILTER_SQL_COUNT_JOURNALTEMPLATE_WHERE = "SELECT COUNT(DISTINCT journalTemplate.id_) AS COUNT_VALUE FROM JournalTemplate journalTemplate WHERE ";
5617 private static final String _FILTER_ENTITY_ALIAS = "journalTemplate";
5618 private static final String _FILTER_ENTITY_TABLE = "JournalTemplate";
5619 private static final String _ORDER_BY_ENTITY_ALIAS = "journalTemplate.";
5620 private static final String _ORDER_BY_ENTITY_TABLE = "JournalTemplate.";
5621 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalTemplate exists with the primary key ";
5622 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalTemplate exists with the key {";
5623 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5624 private static Log _log = LogFactoryUtil.getLog(JournalTemplatePersistenceImpl.class);
5625 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
5626 "uuid", "id"
5627 });
5628 private static JournalTemplate _nullJournalTemplate = new JournalTemplateImpl() {
5629 @Override
5630 public Object clone() {
5631 return this;
5632 }
5633
5634 @Override
5635 public CacheModel<JournalTemplate> toCacheModel() {
5636 return _nullJournalTemplateCacheModel;
5637 }
5638 };
5639
5640 private static CacheModel<JournalTemplate> _nullJournalTemplateCacheModel = new CacheModel<JournalTemplate>() {
5641 public JournalTemplate toEntityModel() {
5642 return _nullJournalTemplate;
5643 }
5644 };
5645 }