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