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