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