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