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