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