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