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