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