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