1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.journal.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.annotation.BeanReference;
27  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29  import com.liferay.portal.kernel.dao.orm.Query;
30  import com.liferay.portal.kernel.dao.orm.QueryPos;
31  import com.liferay.portal.kernel.dao.orm.QueryUtil;
32  import com.liferay.portal.kernel.dao.orm.Session;
33  import com.liferay.portal.kernel.log.Log;
34  import com.liferay.portal.kernel.log.LogFactoryUtil;
35  import com.liferay.portal.kernel.util.GetterUtil;
36  import com.liferay.portal.kernel.util.OrderByComparator;
37  import com.liferay.portal.kernel.util.StringPool;
38  import com.liferay.portal.kernel.util.StringUtil;
39  import com.liferay.portal.kernel.util.Validator;
40  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
41  import com.liferay.portal.model.ModelListener;
42  import com.liferay.portal.service.persistence.BatchSessionUtil;
43  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
44  
45  import com.liferay.portlet.journal.NoSuchTemplateException;
46  import com.liferay.portlet.journal.model.JournalTemplate;
47  import com.liferay.portlet.journal.model.impl.JournalTemplateImpl;
48  import com.liferay.portlet.journal.model.impl.JournalTemplateModelImpl;
49  
50  import java.util.ArrayList;
51  import java.util.Collections;
52  import java.util.Iterator;
53  import java.util.List;
54  
55  /**
56   * <a href="JournalTemplatePersistenceImpl.java.html"><b><i>View Source</i></b></a>
57   *
58   * @author Brian Wing Shun Chan
59   *
60   */
61  public class JournalTemplatePersistenceImpl extends BasePersistenceImpl
62      implements JournalTemplatePersistence {
63      public JournalTemplate create(long id) {
64          JournalTemplate journalTemplate = new JournalTemplateImpl();
65  
66          journalTemplate.setNew(true);
67          journalTemplate.setPrimaryKey(id);
68  
69          String uuid = PortalUUIDUtil.generate();
70  
71          journalTemplate.setUuid(uuid);
72  
73          return journalTemplate;
74      }
75  
76      public JournalTemplate remove(long id)
77          throws NoSuchTemplateException, SystemException {
78          Session session = null;
79  
80          try {
81              session = openSession();
82  
83              JournalTemplate journalTemplate = (JournalTemplate)session.get(JournalTemplateImpl.class,
84                      new Long(id));
85  
86              if (journalTemplate == null) {
87                  if (_log.isWarnEnabled()) {
88                      _log.warn("No JournalTemplate exists with the primary key " +
89                          id);
90                  }
91  
92                  throw new NoSuchTemplateException(
93                      "No JournalTemplate exists with the primary key " + id);
94              }
95  
96              return remove(journalTemplate);
97          }
98          catch (NoSuchTemplateException nsee) {
99              throw nsee;
100         }
101         catch (Exception e) {
102             throw processException(e);
103         }
104         finally {
105             closeSession(session);
106         }
107     }
108 
109     public JournalTemplate remove(JournalTemplate journalTemplate)
110         throws SystemException {
111         for (ModelListener listener : listeners) {
112             listener.onBeforeRemove(journalTemplate);
113         }
114 
115         journalTemplate = removeImpl(journalTemplate);
116 
117         for (ModelListener listener : listeners) {
118             listener.onAfterRemove(journalTemplate);
119         }
120 
121         return journalTemplate;
122     }
123 
124     protected JournalTemplate removeImpl(JournalTemplate journalTemplate)
125         throws SystemException {
126         Session session = null;
127 
128         try {
129             session = openSession();
130 
131             if (BatchSessionUtil.isEnabled()) {
132                 Object staleObject = session.get(JournalTemplateImpl.class,
133                         journalTemplate.getPrimaryKeyObj());
134 
135                 if (staleObject != null) {
136                     session.evict(staleObject);
137                 }
138             }
139 
140             session.delete(journalTemplate);
141 
142             session.flush();
143 
144             return journalTemplate;
145         }
146         catch (Exception e) {
147             throw processException(e);
148         }
149         finally {
150             closeSession(session);
151 
152             FinderCacheUtil.clearCache(JournalTemplate.class.getName());
153         }
154     }
155 
156     /**
157      * @deprecated Use <code>update(JournalTemplate journalTemplate, boolean merge)</code>.
158      */
159     public JournalTemplate update(JournalTemplate journalTemplate)
160         throws SystemException {
161         if (_log.isWarnEnabled()) {
162             _log.warn(
163                 "Using the deprecated update(JournalTemplate journalTemplate) method. Use update(JournalTemplate journalTemplate, boolean merge) instead.");
164         }
165 
166         return update(journalTemplate, false);
167     }
168 
169     /**
170      * Add, update, or merge, the entity. This method also calls the model
171      * listeners to trigger the proper events associated with adding, deleting,
172      * or updating an entity.
173      *
174      * @param        journalTemplate the entity to add, update, or merge
175      * @param        merge boolean value for whether to merge the entity. The
176      *                default value is false. Setting merge to true is more
177      *                expensive and should only be true when journalTemplate is
178      *                transient. See LEP-5473 for a detailed discussion of this
179      *                method.
180      * @return        true if the portlet can be displayed via Ajax
181      */
182     public JournalTemplate update(JournalTemplate journalTemplate, boolean merge)
183         throws SystemException {
184         boolean isNew = journalTemplate.isNew();
185 
186         for (ModelListener listener : listeners) {
187             if (isNew) {
188                 listener.onBeforeCreate(journalTemplate);
189             }
190             else {
191                 listener.onBeforeUpdate(journalTemplate);
192             }
193         }
194 
195         journalTemplate = updateImpl(journalTemplate, merge);
196 
197         for (ModelListener listener : listeners) {
198             if (isNew) {
199                 listener.onAfterCreate(journalTemplate);
200             }
201             else {
202                 listener.onAfterUpdate(journalTemplate);
203             }
204         }
205 
206         return journalTemplate;
207     }
208 
209     public JournalTemplate updateImpl(
210         com.liferay.portlet.journal.model.JournalTemplate journalTemplate,
211         boolean merge) throws SystemException {
212         if (Validator.isNull(journalTemplate.getUuid())) {
213             String uuid = PortalUUIDUtil.generate();
214 
215             journalTemplate.setUuid(uuid);
216         }
217 
218         Session session = null;
219 
220         try {
221             session = openSession();
222 
223             BatchSessionUtil.update(session, journalTemplate, merge);
224 
225             journalTemplate.setNew(false);
226 
227             return journalTemplate;
228         }
229         catch (Exception e) {
230             throw processException(e);
231         }
232         finally {
233             closeSession(session);
234 
235             FinderCacheUtil.clearCache(JournalTemplate.class.getName());
236         }
237     }
238 
239     public JournalTemplate findByPrimaryKey(long id)
240         throws NoSuchTemplateException, SystemException {
241         JournalTemplate journalTemplate = fetchByPrimaryKey(id);
242 
243         if (journalTemplate == null) {
244             if (_log.isWarnEnabled()) {
245                 _log.warn("No JournalTemplate exists with the primary key " +
246                     id);
247             }
248 
249             throw new NoSuchTemplateException(
250                 "No JournalTemplate exists with the primary key " + id);
251         }
252 
253         return journalTemplate;
254     }
255 
256     public JournalTemplate fetchByPrimaryKey(long id) throws SystemException {
257         Session session = null;
258 
259         try {
260             session = openSession();
261 
262             return (JournalTemplate)session.get(JournalTemplateImpl.class,
263                 new Long(id));
264         }
265         catch (Exception e) {
266             throw processException(e);
267         }
268         finally {
269             closeSession(session);
270         }
271     }
272 
273     public List<JournalTemplate> findByUuid(String uuid)
274         throws SystemException {
275         boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
276         String finderClassName = JournalTemplate.class.getName();
277         String finderMethodName = "findByUuid";
278         String[] finderParams = new String[] { String.class.getName() };
279         Object[] finderArgs = new Object[] { uuid };
280 
281         Object result = null;
282 
283         if (finderClassNameCacheEnabled) {
284             result = FinderCacheUtil.getResult(finderClassName,
285                     finderMethodName, finderParams, finderArgs, this);
286         }
287 
288         if (result == null) {
289             Session session = null;
290 
291             try {
292                 session = openSession();
293 
294                 StringBuilder query = new StringBuilder();
295 
296                 query.append(
297                     "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
298 
299                 if (uuid == null) {
300                     query.append("uuid_ IS NULL");
301                 }
302                 else {
303                     query.append("uuid_ = ?");
304                 }
305 
306                 query.append(" ");
307 
308                 query.append("ORDER BY ");
309 
310                 query.append("templateId ASC");
311 
312                 Query q = session.createQuery(query.toString());
313 
314                 QueryPos qPos = QueryPos.getInstance(q);
315 
316                 if (uuid != null) {
317                     qPos.add(uuid);
318                 }
319 
320                 List<JournalTemplate> list = q.list();
321 
322                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
323                     finderClassName, finderMethodName, finderParams,
324                     finderArgs, list);
325 
326                 return list;
327             }
328             catch (Exception e) {
329                 throw processException(e);
330             }
331             finally {
332                 closeSession(session);
333             }
334         }
335         else {
336             return (List<JournalTemplate>)result;
337         }
338     }
339 
340     public List<JournalTemplate> findByUuid(String uuid, int start, int end)
341         throws SystemException {
342         return findByUuid(uuid, start, end, null);
343     }
344 
345     public List<JournalTemplate> findByUuid(String uuid, int start, int end,
346         OrderByComparator obc) throws SystemException {
347         boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
348         String finderClassName = JournalTemplate.class.getName();
349         String finderMethodName = "findByUuid";
350         String[] finderParams = new String[] {
351                 String.class.getName(),
352                 
353                 "java.lang.Integer", "java.lang.Integer",
354                 "com.liferay.portal.kernel.util.OrderByComparator"
355             };
356         Object[] finderArgs = new Object[] {
357                 uuid,
358                 
359                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
360             };
361 
362         Object result = null;
363 
364         if (finderClassNameCacheEnabled) {
365             result = FinderCacheUtil.getResult(finderClassName,
366                     finderMethodName, finderParams, finderArgs, this);
367         }
368 
369         if (result == null) {
370             Session session = null;
371 
372             try {
373                 session = openSession();
374 
375                 StringBuilder query = new StringBuilder();
376 
377                 query.append(
378                     "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
379 
380                 if (uuid == null) {
381                     query.append("uuid_ IS NULL");
382                 }
383                 else {
384                     query.append("uuid_ = ?");
385                 }
386 
387                 query.append(" ");
388 
389                 if (obc != null) {
390                     query.append("ORDER BY ");
391                     query.append(obc.getOrderBy());
392                 }
393 
394                 else {
395                     query.append("ORDER BY ");
396 
397                     query.append("templateId ASC");
398                 }
399 
400                 Query q = session.createQuery(query.toString());
401 
402                 QueryPos qPos = QueryPos.getInstance(q);
403 
404                 if (uuid != null) {
405                     qPos.add(uuid);
406                 }
407 
408                 List<JournalTemplate> list = (List<JournalTemplate>)QueryUtil.list(q,
409                         getDialect(), start, end);
410 
411                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
412                     finderClassName, finderMethodName, finderParams,
413                     finderArgs, list);
414 
415                 return list;
416             }
417             catch (Exception e) {
418                 throw processException(e);
419             }
420             finally {
421                 closeSession(session);
422             }
423         }
424         else {
425             return (List<JournalTemplate>)result;
426         }
427     }
428 
429     public JournalTemplate findByUuid_First(String uuid, OrderByComparator obc)
430         throws NoSuchTemplateException, SystemException {
431         List<JournalTemplate> list = findByUuid(uuid, 0, 1, obc);
432 
433         if (list.size() == 0) {
434             StringBuilder msg = new StringBuilder();
435 
436             msg.append("No JournalTemplate exists with the key {");
437 
438             msg.append("uuid=" + uuid);
439 
440             msg.append(StringPool.CLOSE_CURLY_BRACE);
441 
442             throw new NoSuchTemplateException(msg.toString());
443         }
444         else {
445             return list.get(0);
446         }
447     }
448 
449     public JournalTemplate findByUuid_Last(String uuid, OrderByComparator obc)
450         throws NoSuchTemplateException, SystemException {
451         int count = countByUuid(uuid);
452 
453         List<JournalTemplate> list = findByUuid(uuid, count - 1, count, obc);
454 
455         if (list.size() == 0) {
456             StringBuilder msg = new StringBuilder();
457 
458             msg.append("No JournalTemplate exists with the key {");
459 
460             msg.append("uuid=" + uuid);
461 
462             msg.append(StringPool.CLOSE_CURLY_BRACE);
463 
464             throw new NoSuchTemplateException(msg.toString());
465         }
466         else {
467             return list.get(0);
468         }
469     }
470 
471     public JournalTemplate[] findByUuid_PrevAndNext(long id, String uuid,
472         OrderByComparator obc) throws NoSuchTemplateException, SystemException {
473         JournalTemplate journalTemplate = findByPrimaryKey(id);
474 
475         int count = countByUuid(uuid);
476 
477         Session session = null;
478 
479         try {
480             session = openSession();
481 
482             StringBuilder query = new StringBuilder();
483 
484             query.append(
485                 "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
486 
487             if (uuid == null) {
488                 query.append("uuid_ IS NULL");
489             }
490             else {
491                 query.append("uuid_ = ?");
492             }
493 
494             query.append(" ");
495 
496             if (obc != null) {
497                 query.append("ORDER BY ");
498                 query.append(obc.getOrderBy());
499             }
500 
501             else {
502                 query.append("ORDER BY ");
503 
504                 query.append("templateId ASC");
505             }
506 
507             Query q = session.createQuery(query.toString());
508 
509             QueryPos qPos = QueryPos.getInstance(q);
510 
511             if (uuid != null) {
512                 qPos.add(uuid);
513             }
514 
515             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
516                     journalTemplate);
517 
518             JournalTemplate[] array = new JournalTemplateImpl[3];
519 
520             array[0] = (JournalTemplate)objArray[0];
521             array[1] = (JournalTemplate)objArray[1];
522             array[2] = (JournalTemplate)objArray[2];
523 
524             return array;
525         }
526         catch (Exception e) {
527             throw processException(e);
528         }
529         finally {
530             closeSession(session);
531         }
532     }
533 
534     public JournalTemplate findByUUID_G(String uuid, long groupId)
535         throws NoSuchTemplateException, SystemException {
536         JournalTemplate journalTemplate = fetchByUUID_G(uuid, groupId);
537 
538         if (journalTemplate == null) {
539             StringBuilder msg = new StringBuilder();
540 
541             msg.append("No JournalTemplate exists with the key {");
542 
543             msg.append("uuid=" + uuid);
544 
545             msg.append(", ");
546             msg.append("groupId=" + groupId);
547 
548             msg.append(StringPool.CLOSE_CURLY_BRACE);
549 
550             if (_log.isWarnEnabled()) {
551                 _log.warn(msg.toString());
552             }
553 
554             throw new NoSuchTemplateException(msg.toString());
555         }
556 
557         return journalTemplate;
558     }
559 
560     public JournalTemplate fetchByUUID_G(String uuid, long groupId)
561         throws SystemException {
562         boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
563         String finderClassName = JournalTemplate.class.getName();
564         String finderMethodName = "fetchByUUID_G";
565         String[] finderParams = new String[] {
566                 String.class.getName(), Long.class.getName()
567             };
568         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
569 
570         Object result = null;
571 
572         if (finderClassNameCacheEnabled) {
573             result = FinderCacheUtil.getResult(finderClassName,
574                     finderMethodName, finderParams, finderArgs, this);
575         }
576 
577         if (result == null) {
578             Session session = null;
579 
580             try {
581                 session = openSession();
582 
583                 StringBuilder query = new StringBuilder();
584 
585                 query.append(
586                     "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
587 
588                 if (uuid == null) {
589                     query.append("uuid_ IS NULL");
590                 }
591                 else {
592                     query.append("uuid_ = ?");
593                 }
594 
595                 query.append(" AND ");
596 
597                 query.append("groupId = ?");
598 
599                 query.append(" ");
600 
601                 query.append("ORDER BY ");
602 
603                 query.append("templateId ASC");
604 
605                 Query q = session.createQuery(query.toString());
606 
607                 QueryPos qPos = QueryPos.getInstance(q);
608 
609                 if (uuid != null) {
610                     qPos.add(uuid);
611                 }
612 
613                 qPos.add(groupId);
614 
615                 List<JournalTemplate> list = q.list();
616 
617                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
618                     finderClassName, finderMethodName, finderParams,
619                     finderArgs, list);
620 
621                 if (list.size() == 0) {
622                     return null;
623                 }
624                 else {
625                     return list.get(0);
626                 }
627             }
628             catch (Exception e) {
629                 throw processException(e);
630             }
631             finally {
632                 closeSession(session);
633             }
634         }
635         else {
636             List<JournalTemplate> list = (List<JournalTemplate>)result;
637 
638             if (list.size() == 0) {
639                 return null;
640             }
641             else {
642                 return list.get(0);
643             }
644         }
645     }
646 
647     public List<JournalTemplate> findByGroupId(long groupId)
648         throws SystemException {
649         boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
650         String finderClassName = JournalTemplate.class.getName();
651         String finderMethodName = "findByGroupId";
652         String[] finderParams = new String[] { Long.class.getName() };
653         Object[] finderArgs = new Object[] { new Long(groupId) };
654 
655         Object result = null;
656 
657         if (finderClassNameCacheEnabled) {
658             result = FinderCacheUtil.getResult(finderClassName,
659                     finderMethodName, finderParams, finderArgs, this);
660         }
661 
662         if (result == null) {
663             Session session = null;
664 
665             try {
666                 session = openSession();
667 
668                 StringBuilder query = new StringBuilder();
669 
670                 query.append(
671                     "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
672 
673                 query.append("groupId = ?");
674 
675                 query.append(" ");
676 
677                 query.append("ORDER BY ");
678 
679                 query.append("templateId ASC");
680 
681                 Query q = session.createQuery(query.toString());
682 
683                 QueryPos qPos = QueryPos.getInstance(q);
684 
685                 qPos.add(groupId);
686 
687                 List<JournalTemplate> list = q.list();
688 
689                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
690                     finderClassName, finderMethodName, finderParams,
691                     finderArgs, list);
692 
693                 return list;
694             }
695             catch (Exception e) {
696                 throw processException(e);
697             }
698             finally {
699                 closeSession(session);
700             }
701         }
702         else {
703             return (List<JournalTemplate>)result;
704         }
705     }
706 
707     public List<JournalTemplate> findByGroupId(long groupId, int start, int end)
708         throws SystemException {
709         return findByGroupId(groupId, start, end, null);
710     }
711 
712     public List<JournalTemplate> findByGroupId(long groupId, int start,
713         int end, OrderByComparator obc) throws SystemException {
714         boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
715         String finderClassName = JournalTemplate.class.getName();
716         String finderMethodName = "findByGroupId";
717         String[] finderParams = new String[] {
718                 Long.class.getName(),
719                 
720                 "java.lang.Integer", "java.lang.Integer",
721                 "com.liferay.portal.kernel.util.OrderByComparator"
722             };
723         Object[] finderArgs = new Object[] {
724                 new Long(groupId),
725                 
726                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
727             };
728 
729         Object result = null;
730 
731         if (finderClassNameCacheEnabled) {
732             result = FinderCacheUtil.getResult(finderClassName,
733                     finderMethodName, finderParams, finderArgs, this);
734         }
735 
736         if (result == null) {
737             Session session = null;
738 
739             try {
740                 session = openSession();
741 
742                 StringBuilder query = new StringBuilder();
743 
744                 query.append(
745                     "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
746 
747                 query.append("groupId = ?");
748 
749                 query.append(" ");
750 
751                 if (obc != null) {
752                     query.append("ORDER BY ");
753                     query.append(obc.getOrderBy());
754                 }
755 
756                 else {
757                     query.append("ORDER BY ");
758 
759                     query.append("templateId ASC");
760                 }
761 
762                 Query q = session.createQuery(query.toString());
763 
764                 QueryPos qPos = QueryPos.getInstance(q);
765 
766                 qPos.add(groupId);
767 
768                 List<JournalTemplate> list = (List<JournalTemplate>)QueryUtil.list(q,
769                         getDialect(), start, end);
770 
771                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
772                     finderClassName, finderMethodName, finderParams,
773                     finderArgs, list);
774 
775                 return list;
776             }
777             catch (Exception e) {
778                 throw processException(e);
779             }
780             finally {
781                 closeSession(session);
782             }
783         }
784         else {
785             return (List<JournalTemplate>)result;
786         }
787     }
788 
789     public JournalTemplate findByGroupId_First(long groupId,
790         OrderByComparator obc) throws NoSuchTemplateException, SystemException {
791         List<JournalTemplate> list = findByGroupId(groupId, 0, 1, obc);
792 
793         if (list.size() == 0) {
794             StringBuilder msg = new StringBuilder();
795 
796             msg.append("No JournalTemplate exists with the key {");
797 
798             msg.append("groupId=" + groupId);
799 
800             msg.append(StringPool.CLOSE_CURLY_BRACE);
801 
802             throw new NoSuchTemplateException(msg.toString());
803         }
804         else {
805             return list.get(0);
806         }
807     }
808 
809     public JournalTemplate findByGroupId_Last(long groupId,
810         OrderByComparator obc) throws NoSuchTemplateException, SystemException {
811         int count = countByGroupId(groupId);
812 
813         List<JournalTemplate> list = findByGroupId(groupId, count - 1, count,
814                 obc);
815 
816         if (list.size() == 0) {
817             StringBuilder msg = new StringBuilder();
818 
819             msg.append("No JournalTemplate exists with the key {");
820 
821             msg.append("groupId=" + groupId);
822 
823             msg.append(StringPool.CLOSE_CURLY_BRACE);
824 
825             throw new NoSuchTemplateException(msg.toString());
826         }
827         else {
828             return list.get(0);
829         }
830     }
831 
832     public JournalTemplate[] findByGroupId_PrevAndNext(long id, long groupId,
833         OrderByComparator obc) throws NoSuchTemplateException, SystemException {
834         JournalTemplate journalTemplate = findByPrimaryKey(id);
835 
836         int count = countByGroupId(groupId);
837 
838         Session session = null;
839 
840         try {
841             session = openSession();
842 
843             StringBuilder query = new StringBuilder();
844 
845             query.append(
846                 "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
847 
848             query.append("groupId = ?");
849 
850             query.append(" ");
851 
852             if (obc != null) {
853                 query.append("ORDER BY ");
854                 query.append(obc.getOrderBy());
855             }
856 
857             else {
858                 query.append("ORDER BY ");
859 
860                 query.append("templateId ASC");
861             }
862 
863             Query q = session.createQuery(query.toString());
864 
865             QueryPos qPos = QueryPos.getInstance(q);
866 
867             qPos.add(groupId);
868 
869             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
870                     journalTemplate);
871 
872             JournalTemplate[] array = new JournalTemplateImpl[3];
873 
874             array[0] = (JournalTemplate)objArray[0];
875             array[1] = (JournalTemplate)objArray[1];
876             array[2] = (JournalTemplate)objArray[2];
877 
878             return array;
879         }
880         catch (Exception e) {
881             throw processException(e);
882         }
883         finally {
884             closeSession(session);
885         }
886     }
887 
888     public List<JournalTemplate> findByTemplateId(String templateId)
889         throws SystemException {
890         boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
891         String finderClassName = JournalTemplate.class.getName();
892         String finderMethodName = "findByTemplateId";
893         String[] finderParams = new String[] { String.class.getName() };
894         Object[] finderArgs = new Object[] { templateId };
895 
896         Object result = null;
897 
898         if (finderClassNameCacheEnabled) {
899             result = FinderCacheUtil.getResult(finderClassName,
900                     finderMethodName, finderParams, finderArgs, this);
901         }
902 
903         if (result == null) {
904             Session session = null;
905 
906             try {
907                 session = openSession();
908 
909                 StringBuilder query = new StringBuilder();
910 
911                 query.append(
912                     "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
913 
914                 if (templateId == null) {
915                     query.append("templateId IS NULL");
916                 }
917                 else {
918                     query.append("templateId = ?");
919                 }
920 
921                 query.append(" ");
922 
923                 query.append("ORDER BY ");
924 
925                 query.append("templateId ASC");
926 
927                 Query q = session.createQuery(query.toString());
928 
929                 QueryPos qPos = QueryPos.getInstance(q);
930 
931                 if (templateId != null) {
932                     qPos.add(templateId);
933                 }
934 
935                 List<JournalTemplate> list = q.list();
936 
937                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
938                     finderClassName, finderMethodName, finderParams,
939                     finderArgs, list);
940 
941                 return list;
942             }
943             catch (Exception e) {
944                 throw processException(e);
945             }
946             finally {
947                 closeSession(session);
948             }
949         }
950         else {
951             return (List<JournalTemplate>)result;
952         }
953     }
954 
955     public List<JournalTemplate> findByTemplateId(String templateId, int start,
956         int end) throws SystemException {
957         return findByTemplateId(templateId, start, end, null);
958     }
959 
960     public List<JournalTemplate> findByTemplateId(String templateId, int start,
961         int end, OrderByComparator obc) throws SystemException {
962         boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
963         String finderClassName = JournalTemplate.class.getName();
964         String finderMethodName = "findByTemplateId";
965         String[] finderParams = new String[] {
966                 String.class.getName(),
967                 
968                 "java.lang.Integer", "java.lang.Integer",
969                 "com.liferay.portal.kernel.util.OrderByComparator"
970             };
971         Object[] finderArgs = new Object[] {
972                 templateId,
973                 
974                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
975             };
976 
977         Object result = null;
978 
979         if (finderClassNameCacheEnabled) {
980             result = FinderCacheUtil.getResult(finderClassName,
981                     finderMethodName, finderParams, finderArgs, this);
982         }
983 
984         if (result == null) {
985             Session session = null;
986 
987             try {
988                 session = openSession();
989 
990                 StringBuilder query = new StringBuilder();
991 
992                 query.append(
993                     "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
994 
995                 if (templateId == null) {
996                     query.append("templateId IS NULL");
997                 }
998                 else {
999                     query.append("templateId = ?");
1000                }
1001
1002                query.append(" ");
1003
1004                if (obc != null) {
1005                    query.append("ORDER BY ");
1006                    query.append(obc.getOrderBy());
1007                }
1008
1009                else {
1010                    query.append("ORDER BY ");
1011
1012                    query.append("templateId ASC");
1013                }
1014
1015                Query q = session.createQuery(query.toString());
1016
1017                QueryPos qPos = QueryPos.getInstance(q);
1018
1019                if (templateId != null) {
1020                    qPos.add(templateId);
1021                }
1022
1023                List<JournalTemplate> list = (List<JournalTemplate>)QueryUtil.list(q,
1024                        getDialect(), start, end);
1025
1026                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1027                    finderClassName, finderMethodName, finderParams,
1028                    finderArgs, list);
1029
1030                return list;
1031            }
1032            catch (Exception e) {
1033                throw processException(e);
1034            }
1035            finally {
1036                closeSession(session);
1037            }
1038        }
1039        else {
1040            return (List<JournalTemplate>)result;
1041        }
1042    }
1043
1044    public JournalTemplate findByTemplateId_First(String templateId,
1045        OrderByComparator obc) throws NoSuchTemplateException, SystemException {
1046        List<JournalTemplate> list = findByTemplateId(templateId, 0, 1, obc);
1047
1048        if (list.size() == 0) {
1049            StringBuilder msg = new StringBuilder();
1050
1051            msg.append("No JournalTemplate exists with the key {");
1052
1053            msg.append("templateId=" + templateId);
1054
1055            msg.append(StringPool.CLOSE_CURLY_BRACE);
1056
1057            throw new NoSuchTemplateException(msg.toString());
1058        }
1059        else {
1060            return list.get(0);
1061        }
1062    }
1063
1064    public JournalTemplate findByTemplateId_Last(String templateId,
1065        OrderByComparator obc) throws NoSuchTemplateException, SystemException {
1066        int count = countByTemplateId(templateId);
1067
1068        List<JournalTemplate> list = findByTemplateId(templateId, count - 1,
1069                count, obc);
1070
1071        if (list.size() == 0) {
1072            StringBuilder msg = new StringBuilder();
1073
1074            msg.append("No JournalTemplate exists with the key {");
1075
1076            msg.append("templateId=" + templateId);
1077
1078            msg.append(StringPool.CLOSE_CURLY_BRACE);
1079
1080            throw new NoSuchTemplateException(msg.toString());
1081        }
1082        else {
1083            return list.get(0);
1084        }
1085    }
1086
1087    public JournalTemplate[] findByTemplateId_PrevAndNext(long id,
1088        String templateId, OrderByComparator obc)
1089        throws NoSuchTemplateException, SystemException {
1090        JournalTemplate journalTemplate = findByPrimaryKey(id);
1091
1092        int count = countByTemplateId(templateId);
1093
1094        Session session = null;
1095
1096        try {
1097            session = openSession();
1098
1099            StringBuilder query = new StringBuilder();
1100
1101            query.append(
1102                "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
1103
1104            if (templateId == null) {
1105                query.append("templateId IS NULL");
1106            }
1107            else {
1108                query.append("templateId = ?");
1109            }
1110
1111            query.append(" ");
1112
1113            if (obc != null) {
1114                query.append("ORDER BY ");
1115                query.append(obc.getOrderBy());
1116            }
1117
1118            else {
1119                query.append("ORDER BY ");
1120
1121                query.append("templateId ASC");
1122            }
1123
1124            Query q = session.createQuery(query.toString());
1125
1126            QueryPos qPos = QueryPos.getInstance(q);
1127
1128            if (templateId != null) {
1129                qPos.add(templateId);
1130            }
1131
1132            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1133                    journalTemplate);
1134
1135            JournalTemplate[] array = new JournalTemplateImpl[3];
1136
1137            array[0] = (JournalTemplate)objArray[0];
1138            array[1] = (JournalTemplate)objArray[1];
1139            array[2] = (JournalTemplate)objArray[2];
1140
1141            return array;
1142        }
1143        catch (Exception e) {
1144            throw processException(e);
1145        }
1146        finally {
1147            closeSession(session);
1148        }
1149    }
1150
1151    public JournalTemplate findBySmallImageId(long smallImageId)
1152        throws NoSuchTemplateException, SystemException {
1153        JournalTemplate journalTemplate = fetchBySmallImageId(smallImageId);
1154
1155        if (journalTemplate == null) {
1156            StringBuilder msg = new StringBuilder();
1157
1158            msg.append("No JournalTemplate exists with the key {");
1159
1160            msg.append("smallImageId=" + smallImageId);
1161
1162            msg.append(StringPool.CLOSE_CURLY_BRACE);
1163
1164            if (_log.isWarnEnabled()) {
1165                _log.warn(msg.toString());
1166            }
1167
1168            throw new NoSuchTemplateException(msg.toString());
1169        }
1170
1171        return journalTemplate;
1172    }
1173
1174    public JournalTemplate fetchBySmallImageId(long smallImageId)
1175        throws SystemException {
1176        boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
1177        String finderClassName = JournalTemplate.class.getName();
1178        String finderMethodName = "fetchBySmallImageId";
1179        String[] finderParams = new String[] { Long.class.getName() };
1180        Object[] finderArgs = new Object[] { new Long(smallImageId) };
1181
1182        Object result = null;
1183
1184        if (finderClassNameCacheEnabled) {
1185            result = FinderCacheUtil.getResult(finderClassName,
1186                    finderMethodName, finderParams, finderArgs, this);
1187        }
1188
1189        if (result == null) {
1190            Session session = null;
1191
1192            try {
1193                session = openSession();
1194
1195                StringBuilder query = new StringBuilder();
1196
1197                query.append(
1198                    "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
1199
1200                query.append("smallImageId = ?");
1201
1202                query.append(" ");
1203
1204                query.append("ORDER BY ");
1205
1206                query.append("templateId ASC");
1207
1208                Query q = session.createQuery(query.toString());
1209
1210                QueryPos qPos = QueryPos.getInstance(q);
1211
1212                qPos.add(smallImageId);
1213
1214                List<JournalTemplate> list = q.list();
1215
1216                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1217                    finderClassName, finderMethodName, finderParams,
1218                    finderArgs, list);
1219
1220                if (list.size() == 0) {
1221                    return null;
1222                }
1223                else {
1224                    return list.get(0);
1225                }
1226            }
1227            catch (Exception e) {
1228                throw processException(e);
1229            }
1230            finally {
1231                closeSession(session);
1232            }
1233        }
1234        else {
1235            List<JournalTemplate> list = (List<JournalTemplate>)result;
1236
1237            if (list.size() == 0) {
1238                return null;
1239            }
1240            else {
1241                return list.get(0);
1242            }
1243        }
1244    }
1245
1246    public JournalTemplate findByG_T(long groupId, String templateId)
1247        throws NoSuchTemplateException, SystemException {
1248        JournalTemplate journalTemplate = fetchByG_T(groupId, templateId);
1249
1250        if (journalTemplate == null) {
1251            StringBuilder msg = new StringBuilder();
1252
1253            msg.append("No JournalTemplate exists with the key {");
1254
1255            msg.append("groupId=" + groupId);
1256
1257            msg.append(", ");
1258            msg.append("templateId=" + templateId);
1259
1260            msg.append(StringPool.CLOSE_CURLY_BRACE);
1261
1262            if (_log.isWarnEnabled()) {
1263                _log.warn(msg.toString());
1264            }
1265
1266            throw new NoSuchTemplateException(msg.toString());
1267        }
1268
1269        return journalTemplate;
1270    }
1271
1272    public JournalTemplate fetchByG_T(long groupId, String templateId)
1273        throws SystemException {
1274        boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
1275        String finderClassName = JournalTemplate.class.getName();
1276        String finderMethodName = "fetchByG_T";
1277        String[] finderParams = new String[] {
1278                Long.class.getName(), String.class.getName()
1279            };
1280        Object[] finderArgs = new Object[] { new Long(groupId), templateId };
1281
1282        Object result = null;
1283
1284        if (finderClassNameCacheEnabled) {
1285            result = FinderCacheUtil.getResult(finderClassName,
1286                    finderMethodName, finderParams, finderArgs, this);
1287        }
1288
1289        if (result == null) {
1290            Session session = null;
1291
1292            try {
1293                session = openSession();
1294
1295                StringBuilder query = new StringBuilder();
1296
1297                query.append(
1298                    "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
1299
1300                query.append("groupId = ?");
1301
1302                query.append(" AND ");
1303
1304                if (templateId == null) {
1305                    query.append("templateId IS NULL");
1306                }
1307                else {
1308                    query.append("templateId = ?");
1309                }
1310
1311                query.append(" ");
1312
1313                query.append("ORDER BY ");
1314
1315                query.append("templateId ASC");
1316
1317                Query q = session.createQuery(query.toString());
1318
1319                QueryPos qPos = QueryPos.getInstance(q);
1320
1321                qPos.add(groupId);
1322
1323                if (templateId != null) {
1324                    qPos.add(templateId);
1325                }
1326
1327                List<JournalTemplate> list = q.list();
1328
1329                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1330                    finderClassName, finderMethodName, finderParams,
1331                    finderArgs, list);
1332
1333                if (list.size() == 0) {
1334                    return null;
1335                }
1336                else {
1337                    return list.get(0);
1338                }
1339            }
1340            catch (Exception e) {
1341                throw processException(e);
1342            }
1343            finally {
1344                closeSession(session);
1345            }
1346        }
1347        else {
1348            List<JournalTemplate> list = (List<JournalTemplate>)result;
1349
1350            if (list.size() == 0) {
1351                return null;
1352            }
1353            else {
1354                return list.get(0);
1355            }
1356        }
1357    }
1358
1359    public List<JournalTemplate> findByG_S(long groupId, String structureId)
1360        throws SystemException {
1361        boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
1362        String finderClassName = JournalTemplate.class.getName();
1363        String finderMethodName = "findByG_S";
1364        String[] finderParams = new String[] {
1365                Long.class.getName(), String.class.getName()
1366            };
1367        Object[] finderArgs = new Object[] { new Long(groupId), structureId };
1368
1369        Object result = null;
1370
1371        if (finderClassNameCacheEnabled) {
1372            result = FinderCacheUtil.getResult(finderClassName,
1373                    finderMethodName, finderParams, finderArgs, this);
1374        }
1375
1376        if (result == null) {
1377            Session session = null;
1378
1379            try {
1380                session = openSession();
1381
1382                StringBuilder query = new StringBuilder();
1383
1384                query.append(
1385                    "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
1386
1387                query.append("groupId = ?");
1388
1389                query.append(" AND ");
1390
1391                if (structureId == null) {
1392                    query.append("structureId IS NULL");
1393                }
1394                else {
1395                    query.append("structureId = ?");
1396                }
1397
1398                query.append(" ");
1399
1400                query.append("ORDER BY ");
1401
1402                query.append("templateId ASC");
1403
1404                Query q = session.createQuery(query.toString());
1405
1406                QueryPos qPos = QueryPos.getInstance(q);
1407
1408                qPos.add(groupId);
1409
1410                if (structureId != null) {
1411                    qPos.add(structureId);
1412                }
1413
1414                List<JournalTemplate> list = q.list();
1415
1416                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1417                    finderClassName, finderMethodName, finderParams,
1418                    finderArgs, list);
1419
1420                return list;
1421            }
1422            catch (Exception e) {
1423                throw processException(e);
1424            }
1425            finally {
1426                closeSession(session);
1427            }
1428        }
1429        else {
1430            return (List<JournalTemplate>)result;
1431        }
1432    }
1433
1434    public List<JournalTemplate> findByG_S(long groupId, String structureId,
1435        int start, int end) throws SystemException {
1436        return findByG_S(groupId, structureId, start, end, null);
1437    }
1438
1439    public List<JournalTemplate> findByG_S(long groupId, String structureId,
1440        int start, int end, OrderByComparator obc) throws SystemException {
1441        boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
1442        String finderClassName = JournalTemplate.class.getName();
1443        String finderMethodName = "findByG_S";
1444        String[] finderParams = new String[] {
1445                Long.class.getName(), String.class.getName(),
1446                
1447                "java.lang.Integer", "java.lang.Integer",
1448                "com.liferay.portal.kernel.util.OrderByComparator"
1449            };
1450        Object[] finderArgs = new Object[] {
1451                new Long(groupId),
1452                
1453                structureId,
1454                
1455                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1456            };
1457
1458        Object result = null;
1459
1460        if (finderClassNameCacheEnabled) {
1461            result = FinderCacheUtil.getResult(finderClassName,
1462                    finderMethodName, finderParams, finderArgs, this);
1463        }
1464
1465        if (result == null) {
1466            Session session = null;
1467
1468            try {
1469                session = openSession();
1470
1471                StringBuilder query = new StringBuilder();
1472
1473                query.append(
1474                    "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
1475
1476                query.append("groupId = ?");
1477
1478                query.append(" AND ");
1479
1480                if (structureId == null) {
1481                    query.append("structureId IS NULL");
1482                }
1483                else {
1484                    query.append("structureId = ?");
1485                }
1486
1487                query.append(" ");
1488
1489                if (obc != null) {
1490                    query.append("ORDER BY ");
1491                    query.append(obc.getOrderBy());
1492                }
1493
1494                else {
1495                    query.append("ORDER BY ");
1496
1497                    query.append("templateId ASC");
1498                }
1499
1500                Query q = session.createQuery(query.toString());
1501
1502                QueryPos qPos = QueryPos.getInstance(q);
1503
1504                qPos.add(groupId);
1505
1506                if (structureId != null) {
1507                    qPos.add(structureId);
1508                }
1509
1510                List<JournalTemplate> list = (List<JournalTemplate>)QueryUtil.list(q,
1511                        getDialect(), start, end);
1512
1513                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1514                    finderClassName, finderMethodName, finderParams,
1515                    finderArgs, list);
1516
1517                return list;
1518            }
1519            catch (Exception e) {
1520                throw processException(e);
1521            }
1522            finally {
1523                closeSession(session);
1524            }
1525        }
1526        else {
1527            return (List<JournalTemplate>)result;
1528        }
1529    }
1530
1531    public JournalTemplate findByG_S_First(long groupId, String structureId,
1532        OrderByComparator obc) throws NoSuchTemplateException, SystemException {
1533        List<JournalTemplate> list = findByG_S(groupId, structureId, 0, 1, obc);
1534
1535        if (list.size() == 0) {
1536            StringBuilder msg = new StringBuilder();
1537
1538            msg.append("No JournalTemplate exists with the key {");
1539
1540            msg.append("groupId=" + groupId);
1541
1542            msg.append(", ");
1543            msg.append("structureId=" + structureId);
1544
1545            msg.append(StringPool.CLOSE_CURLY_BRACE);
1546
1547            throw new NoSuchTemplateException(msg.toString());
1548        }
1549        else {
1550            return list.get(0);
1551        }
1552    }
1553
1554    public JournalTemplate findByG_S_Last(long groupId, String structureId,
1555        OrderByComparator obc) throws NoSuchTemplateException, SystemException {
1556        int count = countByG_S(groupId, structureId);
1557
1558        List<JournalTemplate> list = findByG_S(groupId, structureId, count - 1,
1559                count, obc);
1560
1561        if (list.size() == 0) {
1562            StringBuilder msg = new StringBuilder();
1563
1564            msg.append("No JournalTemplate exists with the key {");
1565
1566            msg.append("groupId=" + groupId);
1567
1568            msg.append(", ");
1569            msg.append("structureId=" + structureId);
1570
1571            msg.append(StringPool.CLOSE_CURLY_BRACE);
1572
1573            throw new NoSuchTemplateException(msg.toString());
1574        }
1575        else {
1576            return list.get(0);
1577        }
1578    }
1579
1580    public JournalTemplate[] findByG_S_PrevAndNext(long id, long groupId,
1581        String structureId, OrderByComparator obc)
1582        throws NoSuchTemplateException, SystemException {
1583        JournalTemplate journalTemplate = findByPrimaryKey(id);
1584
1585        int count = countByG_S(groupId, structureId);
1586
1587        Session session = null;
1588
1589        try {
1590            session = openSession();
1591
1592            StringBuilder query = new StringBuilder();
1593
1594            query.append(
1595                "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
1596
1597            query.append("groupId = ?");
1598
1599            query.append(" AND ");
1600
1601            if (structureId == null) {
1602                query.append("structureId IS NULL");
1603            }
1604            else {
1605                query.append("structureId = ?");
1606            }
1607
1608            query.append(" ");
1609
1610            if (obc != null) {
1611                query.append("ORDER BY ");
1612                query.append(obc.getOrderBy());
1613            }
1614
1615            else {
1616                query.append("ORDER BY ");
1617
1618                query.append("templateId ASC");
1619            }
1620
1621            Query q = session.createQuery(query.toString());
1622
1623            QueryPos qPos = QueryPos.getInstance(q);
1624
1625            qPos.add(groupId);
1626
1627            if (structureId != null) {
1628                qPos.add(structureId);
1629            }
1630
1631            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1632                    journalTemplate);
1633
1634            JournalTemplate[] array = new JournalTemplateImpl[3];
1635
1636            array[0] = (JournalTemplate)objArray[0];
1637            array[1] = (JournalTemplate)objArray[1];
1638            array[2] = (JournalTemplate)objArray[2];
1639
1640            return array;
1641        }
1642        catch (Exception e) {
1643            throw processException(e);
1644        }
1645        finally {
1646            closeSession(session);
1647        }
1648    }
1649
1650    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1651        throws SystemException {
1652        Session session = null;
1653
1654        try {
1655            session = openSession();
1656
1657            dynamicQuery.compile(session);
1658
1659            return dynamicQuery.list();
1660        }
1661        catch (Exception e) {
1662            throw processException(e);
1663        }
1664        finally {
1665            closeSession(session);
1666        }
1667    }
1668
1669    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1670        int start, int end) throws SystemException {
1671        Session session = null;
1672
1673        try {
1674            session = openSession();
1675
1676            dynamicQuery.setLimit(start, end);
1677
1678            dynamicQuery.compile(session);
1679
1680            return dynamicQuery.list();
1681        }
1682        catch (Exception e) {
1683            throw processException(e);
1684        }
1685        finally {
1686            closeSession(session);
1687        }
1688    }
1689
1690    public List<JournalTemplate> findAll() throws SystemException {
1691        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1692    }
1693
1694    public List<JournalTemplate> findAll(int start, int end)
1695        throws SystemException {
1696        return findAll(start, end, null);
1697    }
1698
1699    public List<JournalTemplate> findAll(int start, int end,
1700        OrderByComparator obc) throws SystemException {
1701        boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
1702        String finderClassName = JournalTemplate.class.getName();
1703        String finderMethodName = "findAll";
1704        String[] finderParams = new String[] {
1705                "java.lang.Integer", "java.lang.Integer",
1706                "com.liferay.portal.kernel.util.OrderByComparator"
1707            };
1708        Object[] finderArgs = new Object[] {
1709                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1710            };
1711
1712        Object result = null;
1713
1714        if (finderClassNameCacheEnabled) {
1715            result = FinderCacheUtil.getResult(finderClassName,
1716                    finderMethodName, finderParams, finderArgs, this);
1717        }
1718
1719        if (result == null) {
1720            Session session = null;
1721
1722            try {
1723                session = openSession();
1724
1725                StringBuilder query = new StringBuilder();
1726
1727                query.append(
1728                    "FROM com.liferay.portlet.journal.model.JournalTemplate ");
1729
1730                if (obc != null) {
1731                    query.append("ORDER BY ");
1732                    query.append(obc.getOrderBy());
1733                }
1734
1735                else {
1736                    query.append("ORDER BY ");
1737
1738                    query.append("templateId ASC");
1739                }
1740
1741                Query q = session.createQuery(query.toString());
1742
1743                List<JournalTemplate> list = null;
1744
1745                if (obc == null) {
1746                    list = (List<JournalTemplate>)QueryUtil.list(q,
1747                            getDialect(), start, end, false);
1748
1749                    Collections.sort(list);
1750                }
1751                else {
1752                    list = (List<JournalTemplate>)QueryUtil.list(q,
1753                            getDialect(), start, end);
1754                }
1755
1756                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1757                    finderClassName, finderMethodName, finderParams,
1758                    finderArgs, list);
1759
1760                return list;
1761            }
1762            catch (Exception e) {
1763                throw processException(e);
1764            }
1765            finally {
1766                closeSession(session);
1767            }
1768        }
1769        else {
1770            return (List<JournalTemplate>)result;
1771        }
1772    }
1773
1774    public void removeByUuid(String uuid) throws SystemException {
1775        for (JournalTemplate journalTemplate : findByUuid(uuid)) {
1776            remove(journalTemplate);
1777        }
1778    }
1779
1780    public void removeByUUID_G(String uuid, long groupId)
1781        throws NoSuchTemplateException, SystemException {
1782        JournalTemplate journalTemplate = findByUUID_G(uuid, groupId);
1783
1784        remove(journalTemplate);
1785    }
1786
1787    public void removeByGroupId(long groupId) throws SystemException {
1788        for (JournalTemplate journalTemplate : findByGroupId(groupId)) {
1789            remove(journalTemplate);
1790        }
1791    }
1792
1793    public void removeByTemplateId(String templateId) throws SystemException {
1794        for (JournalTemplate journalTemplate : findByTemplateId(templateId)) {
1795            remove(journalTemplate);
1796        }
1797    }
1798
1799    public void removeBySmallImageId(long smallImageId)
1800        throws NoSuchTemplateException, SystemException {
1801        JournalTemplate journalTemplate = findBySmallImageId(smallImageId);
1802
1803        remove(journalTemplate);
1804    }
1805
1806    public void removeByG_T(long groupId, String templateId)
1807        throws NoSuchTemplateException, SystemException {
1808        JournalTemplate journalTemplate = findByG_T(groupId, templateId);
1809
1810        remove(journalTemplate);
1811    }
1812
1813    public void removeByG_S(long groupId, String structureId)
1814        throws SystemException {
1815        for (JournalTemplate journalTemplate : findByG_S(groupId, structureId)) {
1816            remove(journalTemplate);
1817        }
1818    }
1819
1820    public void removeAll() throws SystemException {
1821        for (JournalTemplate journalTemplate : findAll()) {
1822            remove(journalTemplate);
1823        }
1824    }
1825
1826    public int countByUuid(String uuid) throws SystemException {
1827        boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
1828        String finderClassName = JournalTemplate.class.getName();
1829        String finderMethodName = "countByUuid";
1830        String[] finderParams = new String[] { String.class.getName() };
1831        Object[] finderArgs = new Object[] { uuid };
1832
1833        Object result = null;
1834
1835        if (finderClassNameCacheEnabled) {
1836            result = FinderCacheUtil.getResult(finderClassName,
1837                    finderMethodName, finderParams, finderArgs, this);
1838        }
1839
1840        if (result == null) {
1841            Session session = null;
1842
1843            try {
1844                session = openSession();
1845
1846                StringBuilder query = new StringBuilder();
1847
1848                query.append("SELECT COUNT(*) ");
1849                query.append(
1850                    "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
1851
1852                if (uuid == null) {
1853                    query.append("uuid_ IS NULL");
1854                }
1855                else {
1856                    query.append("uuid_ = ?");
1857                }
1858
1859                query.append(" ");
1860
1861                Query q = session.createQuery(query.toString());
1862
1863                QueryPos qPos = QueryPos.getInstance(q);
1864
1865                if (uuid != null) {
1866                    qPos.add(uuid);
1867                }
1868
1869                Long count = null;
1870
1871                Iterator<Long> itr = q.list().iterator();
1872
1873                if (itr.hasNext()) {
1874                    count = itr.next();
1875                }
1876
1877                if (count == null) {
1878                    count = new Long(0);
1879                }
1880
1881                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1882                    finderClassName, finderMethodName, finderParams,
1883                    finderArgs, count);
1884
1885                return count.intValue();
1886            }
1887            catch (Exception e) {
1888                throw processException(e);
1889            }
1890            finally {
1891                closeSession(session);
1892            }
1893        }
1894        else {
1895            return ((Long)result).intValue();
1896        }
1897    }
1898
1899    public int countByUUID_G(String uuid, long groupId)
1900        throws SystemException {
1901        boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
1902        String finderClassName = JournalTemplate.class.getName();
1903        String finderMethodName = "countByUUID_G";
1904        String[] finderParams = new String[] {
1905                String.class.getName(), Long.class.getName()
1906            };
1907        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1908
1909        Object result = null;
1910
1911        if (finderClassNameCacheEnabled) {
1912            result = FinderCacheUtil.getResult(finderClassName,
1913                    finderMethodName, finderParams, finderArgs, this);
1914        }
1915
1916        if (result == null) {
1917            Session session = null;
1918
1919            try {
1920                session = openSession();
1921
1922                StringBuilder query = new StringBuilder();
1923
1924                query.append("SELECT COUNT(*) ");
1925                query.append(
1926                    "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
1927
1928                if (uuid == null) {
1929                    query.append("uuid_ IS NULL");
1930                }
1931                else {
1932                    query.append("uuid_ = ?");
1933                }
1934
1935                query.append(" AND ");
1936
1937                query.append("groupId = ?");
1938
1939                query.append(" ");
1940
1941                Query q = session.createQuery(query.toString());
1942
1943                QueryPos qPos = QueryPos.getInstance(q);
1944
1945                if (uuid != null) {
1946                    qPos.add(uuid);
1947                }
1948
1949                qPos.add(groupId);
1950
1951                Long count = null;
1952
1953                Iterator<Long> itr = q.list().iterator();
1954
1955                if (itr.hasNext()) {
1956                    count = itr.next();
1957                }
1958
1959                if (count == null) {
1960                    count = new Long(0);
1961                }
1962
1963                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1964                    finderClassName, finderMethodName, finderParams,
1965                    finderArgs, count);
1966
1967                return count.intValue();
1968            }
1969            catch (Exception e) {
1970                throw processException(e);
1971            }
1972            finally {
1973                closeSession(session);
1974            }
1975        }
1976        else {
1977            return ((Long)result).intValue();
1978        }
1979    }
1980
1981    public int countByGroupId(long groupId) throws SystemException {
1982        boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
1983        String finderClassName = JournalTemplate.class.getName();
1984        String finderMethodName = "countByGroupId";
1985        String[] finderParams = new String[] { Long.class.getName() };
1986        Object[] finderArgs = new Object[] { new Long(groupId) };
1987
1988        Object result = null;
1989
1990        if (finderClassNameCacheEnabled) {
1991            result = FinderCacheUtil.getResult(finderClassName,
1992                    finderMethodName, finderParams, finderArgs, this);
1993        }
1994
1995        if (result == null) {
1996            Session session = null;
1997
1998            try {
1999                session = openSession();
2000
2001                StringBuilder query = new StringBuilder();
2002
2003                query.append("SELECT COUNT(*) ");
2004                query.append(
2005                    "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
2006
2007                query.append("groupId = ?");
2008
2009                query.append(" ");
2010
2011                Query q = session.createQuery(query.toString());
2012
2013                QueryPos qPos = QueryPos.getInstance(q);
2014
2015                qPos.add(groupId);
2016
2017                Long count = null;
2018
2019                Iterator<Long> itr = q.list().iterator();
2020
2021                if (itr.hasNext()) {
2022                    count = itr.next();
2023                }
2024
2025                if (count == null) {
2026                    count = new Long(0);
2027                }
2028
2029                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2030                    finderClassName, finderMethodName, finderParams,
2031                    finderArgs, count);
2032
2033                return count.intValue();
2034            }
2035            catch (Exception e) {
2036                throw processException(e);
2037            }
2038            finally {
2039                closeSession(session);
2040            }
2041        }
2042        else {
2043            return ((Long)result).intValue();
2044        }
2045    }
2046
2047    public int countByTemplateId(String templateId) throws SystemException {
2048        boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
2049        String finderClassName = JournalTemplate.class.getName();
2050        String finderMethodName = "countByTemplateId";
2051        String[] finderParams = new String[] { String.class.getName() };
2052        Object[] finderArgs = new Object[] { templateId };
2053
2054        Object result = null;
2055
2056        if (finderClassNameCacheEnabled) {
2057            result = FinderCacheUtil.getResult(finderClassName,
2058                    finderMethodName, finderParams, finderArgs, this);
2059        }
2060
2061        if (result == null) {
2062            Session session = null;
2063
2064            try {
2065                session = openSession();
2066
2067                StringBuilder query = new StringBuilder();
2068
2069                query.append("SELECT COUNT(*) ");
2070                query.append(
2071                    "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
2072
2073                if (templateId == null) {
2074                    query.append("templateId IS NULL");
2075                }
2076                else {
2077                    query.append("templateId = ?");
2078                }
2079
2080                query.append(" ");
2081
2082                Query q = session.createQuery(query.toString());
2083
2084                QueryPos qPos = QueryPos.getInstance(q);
2085
2086                if (templateId != null) {
2087                    qPos.add(templateId);
2088                }
2089
2090                Long count = null;
2091
2092                Iterator<Long> itr = q.list().iterator();
2093
2094                if (itr.hasNext()) {
2095                    count = itr.next();
2096                }
2097
2098                if (count == null) {
2099                    count = new Long(0);
2100                }
2101
2102                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2103                    finderClassName, finderMethodName, finderParams,
2104                    finderArgs, count);
2105
2106                return count.intValue();
2107            }
2108            catch (Exception e) {
2109                throw processException(e);
2110            }
2111            finally {
2112                closeSession(session);
2113            }
2114        }
2115        else {
2116            return ((Long)result).intValue();
2117        }
2118    }
2119
2120    public int countBySmallImageId(long smallImageId) throws SystemException {
2121        boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
2122        String finderClassName = JournalTemplate.class.getName();
2123        String finderMethodName = "countBySmallImageId";
2124        String[] finderParams = new String[] { Long.class.getName() };
2125        Object[] finderArgs = new Object[] { new Long(smallImageId) };
2126
2127        Object result = null;
2128
2129        if (finderClassNameCacheEnabled) {
2130            result = FinderCacheUtil.getResult(finderClassName,
2131                    finderMethodName, finderParams, finderArgs, this);
2132        }
2133
2134        if (result == null) {
2135            Session session = null;
2136
2137            try {
2138                session = openSession();
2139
2140                StringBuilder query = new StringBuilder();
2141
2142                query.append("SELECT COUNT(*) ");
2143                query.append(
2144                    "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
2145
2146                query.append("smallImageId = ?");
2147
2148                query.append(" ");
2149
2150                Query q = session.createQuery(query.toString());
2151
2152                QueryPos qPos = QueryPos.getInstance(q);
2153
2154                qPos.add(smallImageId);
2155
2156                Long count = null;
2157
2158                Iterator<Long> itr = q.list().iterator();
2159
2160                if (itr.hasNext()) {
2161                    count = itr.next();
2162                }
2163
2164                if (count == null) {
2165                    count = new Long(0);
2166                }
2167
2168                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2169                    finderClassName, finderMethodName, finderParams,
2170                    finderArgs, count);
2171
2172                return count.intValue();
2173            }
2174            catch (Exception e) {
2175                throw processException(e);
2176            }
2177            finally {
2178                closeSession(session);
2179            }
2180        }
2181        else {
2182            return ((Long)result).intValue();
2183        }
2184    }
2185
2186    public int countByG_T(long groupId, String templateId)
2187        throws SystemException {
2188        boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
2189        String finderClassName = JournalTemplate.class.getName();
2190        String finderMethodName = "countByG_T";
2191        String[] finderParams = new String[] {
2192                Long.class.getName(), String.class.getName()
2193            };
2194        Object[] finderArgs = new Object[] { new Long(groupId), templateId };
2195
2196        Object result = null;
2197
2198        if (finderClassNameCacheEnabled) {
2199            result = FinderCacheUtil.getResult(finderClassName,
2200                    finderMethodName, finderParams, finderArgs, this);
2201        }
2202
2203        if (result == null) {
2204            Session session = null;
2205
2206            try {
2207                session = openSession();
2208
2209                StringBuilder query = new StringBuilder();
2210
2211                query.append("SELECT COUNT(*) ");
2212                query.append(
2213                    "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
2214
2215                query.append("groupId = ?");
2216
2217                query.append(" AND ");
2218
2219                if (templateId == null) {
2220                    query.append("templateId IS NULL");
2221                }
2222                else {
2223                    query.append("templateId = ?");
2224                }
2225
2226                query.append(" ");
2227
2228                Query q = session.createQuery(query.toString());
2229
2230                QueryPos qPos = QueryPos.getInstance(q);
2231
2232                qPos.add(groupId);
2233
2234                if (templateId != null) {
2235                    qPos.add(templateId);
2236                }
2237
2238                Long count = null;
2239
2240                Iterator<Long> itr = q.list().iterator();
2241
2242                if (itr.hasNext()) {
2243                    count = itr.next();
2244                }
2245
2246                if (count == null) {
2247                    count = new Long(0);
2248                }
2249
2250                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2251                    finderClassName, finderMethodName, finderParams,
2252                    finderArgs, count);
2253
2254                return count.intValue();
2255            }
2256            catch (Exception e) {
2257                throw processException(e);
2258            }
2259            finally {
2260                closeSession(session);
2261            }
2262        }
2263        else {
2264            return ((Long)result).intValue();
2265        }
2266    }
2267
2268    public int countByG_S(long groupId, String structureId)
2269        throws SystemException {
2270        boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
2271        String finderClassName = JournalTemplate.class.getName();
2272        String finderMethodName = "countByG_S";
2273        String[] finderParams = new String[] {
2274                Long.class.getName(), String.class.getName()
2275            };
2276        Object[] finderArgs = new Object[] { new Long(groupId), structureId };
2277
2278        Object result = null;
2279
2280        if (finderClassNameCacheEnabled) {
2281            result = FinderCacheUtil.getResult(finderClassName,
2282                    finderMethodName, finderParams, finderArgs, this);
2283        }
2284
2285        if (result == null) {
2286            Session session = null;
2287
2288            try {
2289                session = openSession();
2290
2291                StringBuilder query = new StringBuilder();
2292
2293                query.append("SELECT COUNT(*) ");
2294                query.append(
2295                    "FROM com.liferay.portlet.journal.model.JournalTemplate WHERE ");
2296
2297                query.append("groupId = ?");
2298
2299                query.append(" AND ");
2300
2301                if (structureId == null) {
2302                    query.append("structureId IS NULL");
2303                }
2304                else {
2305                    query.append("structureId = ?");
2306                }
2307
2308                query.append(" ");
2309
2310                Query q = session.createQuery(query.toString());
2311
2312                QueryPos qPos = QueryPos.getInstance(q);
2313
2314                qPos.add(groupId);
2315
2316                if (structureId != null) {
2317                    qPos.add(structureId);
2318                }
2319
2320                Long count = null;
2321
2322                Iterator<Long> itr = q.list().iterator();
2323
2324                if (itr.hasNext()) {
2325                    count = itr.next();
2326                }
2327
2328                if (count == null) {
2329                    count = new Long(0);
2330                }
2331
2332                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2333                    finderClassName, finderMethodName, finderParams,
2334                    finderArgs, count);
2335
2336                return count.intValue();
2337            }
2338            catch (Exception e) {
2339                throw processException(e);
2340            }
2341            finally {
2342                closeSession(session);
2343            }
2344        }
2345        else {
2346            return ((Long)result).intValue();
2347        }
2348    }
2349
2350    public int countAll() throws SystemException {
2351        boolean finderClassNameCacheEnabled = JournalTemplateModelImpl.CACHE_ENABLED;
2352        String finderClassName = JournalTemplate.class.getName();
2353        String finderMethodName = "countAll";
2354        String[] finderParams = new String[] {  };
2355        Object[] finderArgs = new Object[] {  };
2356
2357        Object result = null;
2358
2359        if (finderClassNameCacheEnabled) {
2360            result = FinderCacheUtil.getResult(finderClassName,
2361                    finderMethodName, finderParams, finderArgs, this);
2362        }
2363
2364        if (result == null) {
2365            Session session = null;
2366
2367            try {
2368                session = openSession();
2369
2370                Query q = session.createQuery(
2371                        "SELECT COUNT(*) FROM com.liferay.portlet.journal.model.JournalTemplate");
2372
2373                Long count = null;
2374
2375                Iterator<Long> itr = q.list().iterator();
2376
2377                if (itr.hasNext()) {
2378                    count = itr.next();
2379                }
2380
2381                if (count == null) {
2382                    count = new Long(0);
2383                }
2384
2385                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2386                    finderClassName, finderMethodName, finderParams,
2387                    finderArgs, count);
2388
2389                return count.intValue();
2390            }
2391            catch (Exception e) {
2392                throw processException(e);
2393            }
2394            finally {
2395                closeSession(session);
2396            }
2397        }
2398        else {
2399            return ((Long)result).intValue();
2400        }
2401    }
2402
2403    public void afterPropertiesSet() {
2404        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2405                    com.liferay.portal.util.PropsUtil.get(
2406                        "value.object.listener.com.liferay.portlet.journal.model.JournalTemplate")));
2407
2408        if (listenerClassNames.length > 0) {
2409            try {
2410                List<ModelListener> listenersList = new ArrayList<ModelListener>();
2411
2412                for (String listenerClassName : listenerClassNames) {
2413                    listenersList.add((ModelListener)Class.forName(
2414                            listenerClassName).newInstance());
2415                }
2416
2417                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2418            }
2419            catch (Exception e) {
2420                _log.error(e);
2421            }
2422        }
2423    }
2424
2425    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticlePersistence.impl")
2426    protected com.liferay.portlet.journal.service.persistence.JournalArticlePersistence journalArticlePersistence;
2427    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticleImagePersistence.impl")
2428    protected com.liferay.portlet.journal.service.persistence.JournalArticleImagePersistence journalArticleImagePersistence;
2429    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticleResourcePersistence.impl")
2430    protected com.liferay.portlet.journal.service.persistence.JournalArticleResourcePersistence journalArticleResourcePersistence;
2431    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalContentSearchPersistence.impl")
2432    protected com.liferay.portlet.journal.service.persistence.JournalContentSearchPersistence journalContentSearchPersistence;
2433    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalFeedPersistence.impl")
2434    protected com.liferay.portlet.journal.service.persistence.JournalFeedPersistence journalFeedPersistence;
2435    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalStructurePersistence.impl")
2436    protected com.liferay.portlet.journal.service.persistence.JournalStructurePersistence journalStructurePersistence;
2437    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalTemplatePersistence.impl")
2438    protected com.liferay.portlet.journal.service.persistence.JournalTemplatePersistence journalTemplatePersistence;
2439    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
2440    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
2441    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
2442    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
2443    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
2444    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
2445    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
2446    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
2447    private static Log _log = LogFactoryUtil.getLog(JournalTemplatePersistenceImpl.class);
2448}