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