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