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