1
14
15 package com.liferay.portlet.announcements.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.CompanyPersistence;
41 import com.liferay.portal.service.persistence.GroupPersistence;
42 import com.liferay.portal.service.persistence.OrganizationPersistence;
43 import com.liferay.portal.service.persistence.ResourcePersistence;
44 import com.liferay.portal.service.persistence.RolePersistence;
45 import com.liferay.portal.service.persistence.UserGroupPersistence;
46 import com.liferay.portal.service.persistence.UserPersistence;
47 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
48
49 import com.liferay.portlet.announcements.NoSuchEntryException;
50 import com.liferay.portlet.announcements.model.AnnouncementsEntry;
51 import com.liferay.portlet.announcements.model.impl.AnnouncementsEntryImpl;
52 import com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl;
53
54 import java.io.Serializable;
55
56 import java.util.ArrayList;
57 import java.util.Collections;
58 import java.util.List;
59
60
73 public class AnnouncementsEntryPersistenceImpl extends BasePersistenceImpl<AnnouncementsEntry>
74 implements AnnouncementsEntryPersistence {
75 public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsEntryImpl.class.getName();
76 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
77 ".List";
78 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
79 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
80 FINDER_CLASS_NAME_LIST, "findByUuid",
81 new String[] {
82 String.class.getName(),
83
84 "java.lang.Integer", "java.lang.Integer",
85 "com.liferay.portal.kernel.util.OrderByComparator"
86 });
87 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
88 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
89 FINDER_CLASS_NAME_LIST, "countByUuid",
90 new String[] { String.class.getName() });
91 public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
92 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
93 FINDER_CLASS_NAME_LIST, "findByUserId",
94 new String[] {
95 Long.class.getName(),
96
97 "java.lang.Integer", "java.lang.Integer",
98 "com.liferay.portal.kernel.util.OrderByComparator"
99 });
100 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
101 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
102 FINDER_CLASS_NAME_LIST, "countByUserId",
103 new String[] { Long.class.getName() });
104 public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
105 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
106 FINDER_CLASS_NAME_LIST, "findByC_C",
107 new String[] {
108 Long.class.getName(), Long.class.getName(),
109
110 "java.lang.Integer", "java.lang.Integer",
111 "com.liferay.portal.kernel.util.OrderByComparator"
112 });
113 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
114 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
115 FINDER_CLASS_NAME_LIST, "countByC_C",
116 new String[] { Long.class.getName(), Long.class.getName() });
117 public static final FinderPath FINDER_PATH_FIND_BY_C_C_A = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
118 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
119 FINDER_CLASS_NAME_LIST, "findByC_C_A",
120 new String[] {
121 Long.class.getName(), Long.class.getName(),
122 Boolean.class.getName(),
123
124 "java.lang.Integer", "java.lang.Integer",
125 "com.liferay.portal.kernel.util.OrderByComparator"
126 });
127 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_A = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
128 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
129 FINDER_CLASS_NAME_LIST, "countByC_C_A",
130 new String[] {
131 Long.class.getName(), Long.class.getName(),
132 Boolean.class.getName()
133 });
134 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
135 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
136 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
137 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
138 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
139 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
140
141 public void cacheResult(AnnouncementsEntry announcementsEntry) {
142 EntityCacheUtil.putResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
143 AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey(),
144 announcementsEntry);
145 }
146
147 public void cacheResult(List<AnnouncementsEntry> announcementsEntries) {
148 for (AnnouncementsEntry announcementsEntry : announcementsEntries) {
149 if (EntityCacheUtil.getResult(
150 AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
151 AnnouncementsEntryImpl.class,
152 announcementsEntry.getPrimaryKey(), this) == null) {
153 cacheResult(announcementsEntry);
154 }
155 }
156 }
157
158 public void clearCache() {
159 CacheRegistry.clear(AnnouncementsEntryImpl.class.getName());
160 EntityCacheUtil.clearCache(AnnouncementsEntryImpl.class.getName());
161 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
162 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
163 }
164
165 public void clearCache(AnnouncementsEntry announcementsEntry) {
166 EntityCacheUtil.removeResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
167 AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey());
168 }
169
170 public AnnouncementsEntry create(long entryId) {
171 AnnouncementsEntry announcementsEntry = new AnnouncementsEntryImpl();
172
173 announcementsEntry.setNew(true);
174 announcementsEntry.setPrimaryKey(entryId);
175
176 String uuid = PortalUUIDUtil.generate();
177
178 announcementsEntry.setUuid(uuid);
179
180 return announcementsEntry;
181 }
182
183 public AnnouncementsEntry remove(Serializable primaryKey)
184 throws NoSuchModelException, SystemException {
185 return remove(((Long)primaryKey).longValue());
186 }
187
188 public AnnouncementsEntry remove(long entryId)
189 throws NoSuchEntryException, SystemException {
190 Session session = null;
191
192 try {
193 session = openSession();
194
195 AnnouncementsEntry announcementsEntry = (AnnouncementsEntry)session.get(AnnouncementsEntryImpl.class,
196 new Long(entryId));
197
198 if (announcementsEntry == null) {
199 if (_log.isWarnEnabled()) {
200 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
201 }
202
203 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
204 entryId);
205 }
206
207 return remove(announcementsEntry);
208 }
209 catch (NoSuchEntryException nsee) {
210 throw nsee;
211 }
212 catch (Exception e) {
213 throw processException(e);
214 }
215 finally {
216 closeSession(session);
217 }
218 }
219
220 protected AnnouncementsEntry removeImpl(
221 AnnouncementsEntry announcementsEntry) throws SystemException {
222 announcementsEntry = toUnwrappedModel(announcementsEntry);
223
224 Session session = null;
225
226 try {
227 session = openSession();
228
229 BatchSessionUtil.delete(session, announcementsEntry);
230 }
231 catch (Exception e) {
232 throw processException(e);
233 }
234 finally {
235 closeSession(session);
236 }
237
238 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
239
240 EntityCacheUtil.removeResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
241 AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey());
242
243 return announcementsEntry;
244 }
245
246
249 public AnnouncementsEntry update(AnnouncementsEntry announcementsEntry)
250 throws SystemException {
251 if (_log.isWarnEnabled()) {
252 _log.warn(
253 "Using the deprecated update(AnnouncementsEntry announcementsEntry) method. Use update(AnnouncementsEntry announcementsEntry, boolean merge) instead.");
254 }
255
256 return update(announcementsEntry, false);
257 }
258
259 public AnnouncementsEntry updateImpl(
260 com.liferay.portlet.announcements.model.AnnouncementsEntry announcementsEntry,
261 boolean merge) throws SystemException {
262 announcementsEntry = toUnwrappedModel(announcementsEntry);
263
264 if (Validator.isNull(announcementsEntry.getUuid())) {
265 String uuid = PortalUUIDUtil.generate();
266
267 announcementsEntry.setUuid(uuid);
268 }
269
270 Session session = null;
271
272 try {
273 session = openSession();
274
275 BatchSessionUtil.update(session, announcementsEntry, merge);
276
277 announcementsEntry.setNew(false);
278 }
279 catch (Exception e) {
280 throw processException(e);
281 }
282 finally {
283 closeSession(session);
284 }
285
286 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
287
288 EntityCacheUtil.putResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
289 AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey(),
290 announcementsEntry);
291
292 return announcementsEntry;
293 }
294
295 protected AnnouncementsEntry toUnwrappedModel(
296 AnnouncementsEntry announcementsEntry) {
297 if (announcementsEntry instanceof AnnouncementsEntryImpl) {
298 return announcementsEntry;
299 }
300
301 AnnouncementsEntryImpl announcementsEntryImpl = new AnnouncementsEntryImpl();
302
303 announcementsEntryImpl.setNew(announcementsEntry.isNew());
304 announcementsEntryImpl.setPrimaryKey(announcementsEntry.getPrimaryKey());
305
306 announcementsEntryImpl.setUuid(announcementsEntry.getUuid());
307 announcementsEntryImpl.setEntryId(announcementsEntry.getEntryId());
308 announcementsEntryImpl.setCompanyId(announcementsEntry.getCompanyId());
309 announcementsEntryImpl.setUserId(announcementsEntry.getUserId());
310 announcementsEntryImpl.setUserName(announcementsEntry.getUserName());
311 announcementsEntryImpl.setCreateDate(announcementsEntry.getCreateDate());
312 announcementsEntryImpl.setModifiedDate(announcementsEntry.getModifiedDate());
313 announcementsEntryImpl.setClassNameId(announcementsEntry.getClassNameId());
314 announcementsEntryImpl.setClassPK(announcementsEntry.getClassPK());
315 announcementsEntryImpl.setTitle(announcementsEntry.getTitle());
316 announcementsEntryImpl.setContent(announcementsEntry.getContent());
317 announcementsEntryImpl.setUrl(announcementsEntry.getUrl());
318 announcementsEntryImpl.setType(announcementsEntry.getType());
319 announcementsEntryImpl.setDisplayDate(announcementsEntry.getDisplayDate());
320 announcementsEntryImpl.setExpirationDate(announcementsEntry.getExpirationDate());
321 announcementsEntryImpl.setPriority(announcementsEntry.getPriority());
322 announcementsEntryImpl.setAlert(announcementsEntry.isAlert());
323
324 return announcementsEntryImpl;
325 }
326
327 public AnnouncementsEntry findByPrimaryKey(Serializable primaryKey)
328 throws NoSuchModelException, SystemException {
329 return findByPrimaryKey(((Long)primaryKey).longValue());
330 }
331
332 public AnnouncementsEntry findByPrimaryKey(long entryId)
333 throws NoSuchEntryException, SystemException {
334 AnnouncementsEntry announcementsEntry = fetchByPrimaryKey(entryId);
335
336 if (announcementsEntry == null) {
337 if (_log.isWarnEnabled()) {
338 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
339 }
340
341 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
342 entryId);
343 }
344
345 return announcementsEntry;
346 }
347
348 public AnnouncementsEntry fetchByPrimaryKey(Serializable primaryKey)
349 throws SystemException {
350 return fetchByPrimaryKey(((Long)primaryKey).longValue());
351 }
352
353 public AnnouncementsEntry fetchByPrimaryKey(long entryId)
354 throws SystemException {
355 AnnouncementsEntry announcementsEntry = (AnnouncementsEntry)EntityCacheUtil.getResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
356 AnnouncementsEntryImpl.class, entryId, this);
357
358 if (announcementsEntry == null) {
359 Session session = null;
360
361 try {
362 session = openSession();
363
364 announcementsEntry = (AnnouncementsEntry)session.get(AnnouncementsEntryImpl.class,
365 new Long(entryId));
366 }
367 catch (Exception e) {
368 throw processException(e);
369 }
370 finally {
371 if (announcementsEntry != null) {
372 cacheResult(announcementsEntry);
373 }
374
375 closeSession(session);
376 }
377 }
378
379 return announcementsEntry;
380 }
381
382 public List<AnnouncementsEntry> findByUuid(String uuid)
383 throws SystemException {
384 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
385 }
386
387 public List<AnnouncementsEntry> findByUuid(String uuid, int start, int end)
388 throws SystemException {
389 return findByUuid(uuid, start, end, null);
390 }
391
392 public List<AnnouncementsEntry> findByUuid(String uuid, int start, int end,
393 OrderByComparator orderByComparator) throws SystemException {
394 Object[] finderArgs = new Object[] {
395 uuid,
396
397 String.valueOf(start), String.valueOf(end),
398 String.valueOf(orderByComparator)
399 };
400
401 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
402 finderArgs, this);
403
404 if (list == null) {
405 StringBundler query = null;
406
407 if (orderByComparator != null) {
408 query = new StringBundler(3 +
409 (orderByComparator.getOrderByFields().length * 3));
410 }
411 else {
412 query = new StringBundler(3);
413 }
414
415 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
416
417 if (uuid == null) {
418 query.append(_FINDER_COLUMN_UUID_UUID_1);
419 }
420 else {
421 if (uuid.equals(StringPool.BLANK)) {
422 query.append(_FINDER_COLUMN_UUID_UUID_3);
423 }
424 else {
425 query.append(_FINDER_COLUMN_UUID_UUID_2);
426 }
427 }
428
429 if (orderByComparator != null) {
430 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
431 orderByComparator);
432 }
433
434 else {
435 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
436 }
437
438 String sql = query.toString();
439
440 Session session = null;
441
442 try {
443 session = openSession();
444
445 Query q = session.createQuery(sql);
446
447 QueryPos qPos = QueryPos.getInstance(q);
448
449 if (uuid != null) {
450 qPos.add(uuid);
451 }
452
453 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
454 getDialect(), start, end);
455 }
456 catch (Exception e) {
457 throw processException(e);
458 }
459 finally {
460 if (list == null) {
461 list = new ArrayList<AnnouncementsEntry>();
462 }
463
464 cacheResult(list);
465
466 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
467 list);
468
469 closeSession(session);
470 }
471 }
472
473 return list;
474 }
475
476 public AnnouncementsEntry findByUuid_First(String uuid,
477 OrderByComparator orderByComparator)
478 throws NoSuchEntryException, SystemException {
479 List<AnnouncementsEntry> list = findByUuid(uuid, 0, 1, orderByComparator);
480
481 if (list.isEmpty()) {
482 StringBundler msg = new StringBundler(4);
483
484 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
485
486 msg.append("uuid=");
487 msg.append(uuid);
488
489 msg.append(StringPool.CLOSE_CURLY_BRACE);
490
491 throw new NoSuchEntryException(msg.toString());
492 }
493 else {
494 return list.get(0);
495 }
496 }
497
498 public AnnouncementsEntry findByUuid_Last(String uuid,
499 OrderByComparator orderByComparator)
500 throws NoSuchEntryException, SystemException {
501 int count = countByUuid(uuid);
502
503 List<AnnouncementsEntry> list = findByUuid(uuid, count - 1, count,
504 orderByComparator);
505
506 if (list.isEmpty()) {
507 StringBundler msg = new StringBundler(4);
508
509 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
510
511 msg.append("uuid=");
512 msg.append(uuid);
513
514 msg.append(StringPool.CLOSE_CURLY_BRACE);
515
516 throw new NoSuchEntryException(msg.toString());
517 }
518 else {
519 return list.get(0);
520 }
521 }
522
523 public AnnouncementsEntry[] findByUuid_PrevAndNext(long entryId,
524 String uuid, OrderByComparator orderByComparator)
525 throws NoSuchEntryException, SystemException {
526 AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
527
528 Session session = null;
529
530 try {
531 session = openSession();
532
533 AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
534
535 array[0] = getByUuid_PrevAndNext(session, announcementsEntry, uuid,
536 orderByComparator, true);
537
538 array[1] = announcementsEntry;
539
540 array[2] = getByUuid_PrevAndNext(session, announcementsEntry, uuid,
541 orderByComparator, false);
542
543 return array;
544 }
545 catch (Exception e) {
546 throw processException(e);
547 }
548 finally {
549 closeSession(session);
550 }
551 }
552
553 protected AnnouncementsEntry getByUuid_PrevAndNext(Session session,
554 AnnouncementsEntry announcementsEntry, String uuid,
555 OrderByComparator orderByComparator, boolean previous) {
556 StringBundler query = null;
557
558 if (orderByComparator != null) {
559 query = new StringBundler(6 +
560 (orderByComparator.getOrderByFields().length * 6));
561 }
562 else {
563 query = new StringBundler(3);
564 }
565
566 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
567
568 if (uuid == null) {
569 query.append(_FINDER_COLUMN_UUID_UUID_1);
570 }
571 else {
572 if (uuid.equals(StringPool.BLANK)) {
573 query.append(_FINDER_COLUMN_UUID_UUID_3);
574 }
575 else {
576 query.append(_FINDER_COLUMN_UUID_UUID_2);
577 }
578 }
579
580 if (orderByComparator != null) {
581 String[] orderByFields = orderByComparator.getOrderByFields();
582
583 if (orderByFields.length > 0) {
584 query.append(WHERE_AND);
585 }
586
587 for (int i = 0; i < orderByFields.length; i++) {
588 query.append(_ORDER_BY_ENTITY_ALIAS);
589 query.append(orderByFields[i]);
590
591 if ((i + 1) < orderByFields.length) {
592 if (orderByComparator.isAscending() ^ previous) {
593 query.append(WHERE_GREATER_THAN_HAS_NEXT);
594 }
595 else {
596 query.append(WHERE_LESSER_THAN_HAS_NEXT);
597 }
598 }
599 else {
600 if (orderByComparator.isAscending() ^ previous) {
601 query.append(WHERE_GREATER_THAN);
602 }
603 else {
604 query.append(WHERE_LESSER_THAN);
605 }
606 }
607 }
608
609 query.append(ORDER_BY_CLAUSE);
610
611 for (int i = 0; i < orderByFields.length; i++) {
612 query.append(_ORDER_BY_ENTITY_ALIAS);
613 query.append(orderByFields[i]);
614
615 if ((i + 1) < orderByFields.length) {
616 if (orderByComparator.isAscending() ^ previous) {
617 query.append(ORDER_BY_ASC_HAS_NEXT);
618 }
619 else {
620 query.append(ORDER_BY_DESC_HAS_NEXT);
621 }
622 }
623 else {
624 if (orderByComparator.isAscending() ^ previous) {
625 query.append(ORDER_BY_ASC);
626 }
627 else {
628 query.append(ORDER_BY_DESC);
629 }
630 }
631 }
632 }
633
634 else {
635 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
636 }
637
638 String sql = query.toString();
639
640 Query q = session.createQuery(sql);
641
642 q.setFirstResult(0);
643 q.setMaxResults(2);
644
645 QueryPos qPos = QueryPos.getInstance(q);
646
647 if (uuid != null) {
648 qPos.add(uuid);
649 }
650
651 if (orderByComparator != null) {
652 Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
653
654 for (Object value : values) {
655 qPos.add(value);
656 }
657 }
658
659 List<AnnouncementsEntry> list = q.list();
660
661 if (list.size() == 2) {
662 return list.get(1);
663 }
664 else {
665 return null;
666 }
667 }
668
669 public List<AnnouncementsEntry> findByUserId(long userId)
670 throws SystemException {
671 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
672 }
673
674 public List<AnnouncementsEntry> findByUserId(long userId, int start, int end)
675 throws SystemException {
676 return findByUserId(userId, start, end, null);
677 }
678
679 public List<AnnouncementsEntry> findByUserId(long userId, int start,
680 int end, OrderByComparator orderByComparator) throws SystemException {
681 Object[] finderArgs = new Object[] {
682 userId,
683
684 String.valueOf(start), String.valueOf(end),
685 String.valueOf(orderByComparator)
686 };
687
688 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
689 finderArgs, this);
690
691 if (list == null) {
692 StringBundler query = null;
693
694 if (orderByComparator != null) {
695 query = new StringBundler(3 +
696 (orderByComparator.getOrderByFields().length * 3));
697 }
698 else {
699 query = new StringBundler(3);
700 }
701
702 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
703
704 query.append(_FINDER_COLUMN_USERID_USERID_2);
705
706 if (orderByComparator != null) {
707 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
708 orderByComparator);
709 }
710
711 else {
712 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
713 }
714
715 String sql = query.toString();
716
717 Session session = null;
718
719 try {
720 session = openSession();
721
722 Query q = session.createQuery(sql);
723
724 QueryPos qPos = QueryPos.getInstance(q);
725
726 qPos.add(userId);
727
728 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
729 getDialect(), start, end);
730 }
731 catch (Exception e) {
732 throw processException(e);
733 }
734 finally {
735 if (list == null) {
736 list = new ArrayList<AnnouncementsEntry>();
737 }
738
739 cacheResult(list);
740
741 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
742 finderArgs, list);
743
744 closeSession(session);
745 }
746 }
747
748 return list;
749 }
750
751 public AnnouncementsEntry findByUserId_First(long userId,
752 OrderByComparator orderByComparator)
753 throws NoSuchEntryException, SystemException {
754 List<AnnouncementsEntry> list = findByUserId(userId, 0, 1,
755 orderByComparator);
756
757 if (list.isEmpty()) {
758 StringBundler msg = new StringBundler(4);
759
760 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
761
762 msg.append("userId=");
763 msg.append(userId);
764
765 msg.append(StringPool.CLOSE_CURLY_BRACE);
766
767 throw new NoSuchEntryException(msg.toString());
768 }
769 else {
770 return list.get(0);
771 }
772 }
773
774 public AnnouncementsEntry findByUserId_Last(long userId,
775 OrderByComparator orderByComparator)
776 throws NoSuchEntryException, SystemException {
777 int count = countByUserId(userId);
778
779 List<AnnouncementsEntry> list = findByUserId(userId, count - 1, count,
780 orderByComparator);
781
782 if (list.isEmpty()) {
783 StringBundler msg = new StringBundler(4);
784
785 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
786
787 msg.append("userId=");
788 msg.append(userId);
789
790 msg.append(StringPool.CLOSE_CURLY_BRACE);
791
792 throw new NoSuchEntryException(msg.toString());
793 }
794 else {
795 return list.get(0);
796 }
797 }
798
799 public AnnouncementsEntry[] findByUserId_PrevAndNext(long entryId,
800 long userId, OrderByComparator orderByComparator)
801 throws NoSuchEntryException, SystemException {
802 AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
803
804 Session session = null;
805
806 try {
807 session = openSession();
808
809 AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
810
811 array[0] = getByUserId_PrevAndNext(session, announcementsEntry,
812 userId, orderByComparator, true);
813
814 array[1] = announcementsEntry;
815
816 array[2] = getByUserId_PrevAndNext(session, announcementsEntry,
817 userId, orderByComparator, false);
818
819 return array;
820 }
821 catch (Exception e) {
822 throw processException(e);
823 }
824 finally {
825 closeSession(session);
826 }
827 }
828
829 protected AnnouncementsEntry getByUserId_PrevAndNext(Session session,
830 AnnouncementsEntry announcementsEntry, long userId,
831 OrderByComparator orderByComparator, boolean previous) {
832 StringBundler query = null;
833
834 if (orderByComparator != null) {
835 query = new StringBundler(6 +
836 (orderByComparator.getOrderByFields().length * 6));
837 }
838 else {
839 query = new StringBundler(3);
840 }
841
842 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
843
844 query.append(_FINDER_COLUMN_USERID_USERID_2);
845
846 if (orderByComparator != null) {
847 String[] orderByFields = orderByComparator.getOrderByFields();
848
849 if (orderByFields.length > 0) {
850 query.append(WHERE_AND);
851 }
852
853 for (int i = 0; i < orderByFields.length; i++) {
854 query.append(_ORDER_BY_ENTITY_ALIAS);
855 query.append(orderByFields[i]);
856
857 if ((i + 1) < orderByFields.length) {
858 if (orderByComparator.isAscending() ^ previous) {
859 query.append(WHERE_GREATER_THAN_HAS_NEXT);
860 }
861 else {
862 query.append(WHERE_LESSER_THAN_HAS_NEXT);
863 }
864 }
865 else {
866 if (orderByComparator.isAscending() ^ previous) {
867 query.append(WHERE_GREATER_THAN);
868 }
869 else {
870 query.append(WHERE_LESSER_THAN);
871 }
872 }
873 }
874
875 query.append(ORDER_BY_CLAUSE);
876
877 for (int i = 0; i < orderByFields.length; i++) {
878 query.append(_ORDER_BY_ENTITY_ALIAS);
879 query.append(orderByFields[i]);
880
881 if ((i + 1) < orderByFields.length) {
882 if (orderByComparator.isAscending() ^ previous) {
883 query.append(ORDER_BY_ASC_HAS_NEXT);
884 }
885 else {
886 query.append(ORDER_BY_DESC_HAS_NEXT);
887 }
888 }
889 else {
890 if (orderByComparator.isAscending() ^ previous) {
891 query.append(ORDER_BY_ASC);
892 }
893 else {
894 query.append(ORDER_BY_DESC);
895 }
896 }
897 }
898 }
899
900 else {
901 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
902 }
903
904 String sql = query.toString();
905
906 Query q = session.createQuery(sql);
907
908 q.setFirstResult(0);
909 q.setMaxResults(2);
910
911 QueryPos qPos = QueryPos.getInstance(q);
912
913 qPos.add(userId);
914
915 if (orderByComparator != null) {
916 Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
917
918 for (Object value : values) {
919 qPos.add(value);
920 }
921 }
922
923 List<AnnouncementsEntry> list = q.list();
924
925 if (list.size() == 2) {
926 return list.get(1);
927 }
928 else {
929 return null;
930 }
931 }
932
933 public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK)
934 throws SystemException {
935 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
936 QueryUtil.ALL_POS, null);
937 }
938
939 public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
940 int start, int end) throws SystemException {
941 return findByC_C(classNameId, classPK, start, end, null);
942 }
943
944 public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
945 int start, int end, OrderByComparator orderByComparator)
946 throws SystemException {
947 Object[] finderArgs = new Object[] {
948 classNameId, classPK,
949
950 String.valueOf(start), String.valueOf(end),
951 String.valueOf(orderByComparator)
952 };
953
954 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
955 finderArgs, this);
956
957 if (list == null) {
958 StringBundler query = null;
959
960 if (orderByComparator != null) {
961 query = new StringBundler(4 +
962 (orderByComparator.getOrderByFields().length * 3));
963 }
964 else {
965 query = new StringBundler(4);
966 }
967
968 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
969
970 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
971
972 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
973
974 if (orderByComparator != null) {
975 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
976 orderByComparator);
977 }
978
979 else {
980 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
981 }
982
983 String sql = query.toString();
984
985 Session session = null;
986
987 try {
988 session = openSession();
989
990 Query q = session.createQuery(sql);
991
992 QueryPos qPos = QueryPos.getInstance(q);
993
994 qPos.add(classNameId);
995
996 qPos.add(classPK);
997
998 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
999 getDialect(), start, end);
1000 }
1001 catch (Exception e) {
1002 throw processException(e);
1003 }
1004 finally {
1005 if (list == null) {
1006 list = new ArrayList<AnnouncementsEntry>();
1007 }
1008
1009 cacheResult(list);
1010
1011 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
1012 list);
1013
1014 closeSession(session);
1015 }
1016 }
1017
1018 return list;
1019 }
1020
1021 public AnnouncementsEntry findByC_C_First(long classNameId, long classPK,
1022 OrderByComparator orderByComparator)
1023 throws NoSuchEntryException, SystemException {
1024 List<AnnouncementsEntry> list = findByC_C(classNameId, classPK, 0, 1,
1025 orderByComparator);
1026
1027 if (list.isEmpty()) {
1028 StringBundler msg = new StringBundler(6);
1029
1030 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1031
1032 msg.append("classNameId=");
1033 msg.append(classNameId);
1034
1035 msg.append(", classPK=");
1036 msg.append(classPK);
1037
1038 msg.append(StringPool.CLOSE_CURLY_BRACE);
1039
1040 throw new NoSuchEntryException(msg.toString());
1041 }
1042 else {
1043 return list.get(0);
1044 }
1045 }
1046
1047 public AnnouncementsEntry findByC_C_Last(long classNameId, long classPK,
1048 OrderByComparator orderByComparator)
1049 throws NoSuchEntryException, SystemException {
1050 int count = countByC_C(classNameId, classPK);
1051
1052 List<AnnouncementsEntry> list = findByC_C(classNameId, classPK,
1053 count - 1, count, orderByComparator);
1054
1055 if (list.isEmpty()) {
1056 StringBundler msg = new StringBundler(6);
1057
1058 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1059
1060 msg.append("classNameId=");
1061 msg.append(classNameId);
1062
1063 msg.append(", classPK=");
1064 msg.append(classPK);
1065
1066 msg.append(StringPool.CLOSE_CURLY_BRACE);
1067
1068 throw new NoSuchEntryException(msg.toString());
1069 }
1070 else {
1071 return list.get(0);
1072 }
1073 }
1074
1075 public AnnouncementsEntry[] findByC_C_PrevAndNext(long entryId,
1076 long classNameId, long classPK, OrderByComparator orderByComparator)
1077 throws NoSuchEntryException, SystemException {
1078 AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1079
1080 Session session = null;
1081
1082 try {
1083 session = openSession();
1084
1085 AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1086
1087 array[0] = getByC_C_PrevAndNext(session, announcementsEntry,
1088 classNameId, classPK, orderByComparator, true);
1089
1090 array[1] = announcementsEntry;
1091
1092 array[2] = getByC_C_PrevAndNext(session, announcementsEntry,
1093 classNameId, classPK, orderByComparator, false);
1094
1095 return array;
1096 }
1097 catch (Exception e) {
1098 throw processException(e);
1099 }
1100 finally {
1101 closeSession(session);
1102 }
1103 }
1104
1105 protected AnnouncementsEntry getByC_C_PrevAndNext(Session session,
1106 AnnouncementsEntry announcementsEntry, long classNameId, long classPK,
1107 OrderByComparator orderByComparator, boolean previous) {
1108 StringBundler query = null;
1109
1110 if (orderByComparator != null) {
1111 query = new StringBundler(6 +
1112 (orderByComparator.getOrderByFields().length * 6));
1113 }
1114 else {
1115 query = new StringBundler(3);
1116 }
1117
1118 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1119
1120 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1121
1122 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1123
1124 if (orderByComparator != null) {
1125 String[] orderByFields = orderByComparator.getOrderByFields();
1126
1127 if (orderByFields.length > 0) {
1128 query.append(WHERE_AND);
1129 }
1130
1131 for (int i = 0; i < orderByFields.length; i++) {
1132 query.append(_ORDER_BY_ENTITY_ALIAS);
1133 query.append(orderByFields[i]);
1134
1135 if ((i + 1) < orderByFields.length) {
1136 if (orderByComparator.isAscending() ^ previous) {
1137 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1138 }
1139 else {
1140 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1141 }
1142 }
1143 else {
1144 if (orderByComparator.isAscending() ^ previous) {
1145 query.append(WHERE_GREATER_THAN);
1146 }
1147 else {
1148 query.append(WHERE_LESSER_THAN);
1149 }
1150 }
1151 }
1152
1153 query.append(ORDER_BY_CLAUSE);
1154
1155 for (int i = 0; i < orderByFields.length; i++) {
1156 query.append(_ORDER_BY_ENTITY_ALIAS);
1157 query.append(orderByFields[i]);
1158
1159 if ((i + 1) < orderByFields.length) {
1160 if (orderByComparator.isAscending() ^ previous) {
1161 query.append(ORDER_BY_ASC_HAS_NEXT);
1162 }
1163 else {
1164 query.append(ORDER_BY_DESC_HAS_NEXT);
1165 }
1166 }
1167 else {
1168 if (orderByComparator.isAscending() ^ previous) {
1169 query.append(ORDER_BY_ASC);
1170 }
1171 else {
1172 query.append(ORDER_BY_DESC);
1173 }
1174 }
1175 }
1176 }
1177
1178 else {
1179 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1180 }
1181
1182 String sql = query.toString();
1183
1184 Query q = session.createQuery(sql);
1185
1186 q.setFirstResult(0);
1187 q.setMaxResults(2);
1188
1189 QueryPos qPos = QueryPos.getInstance(q);
1190
1191 qPos.add(classNameId);
1192
1193 qPos.add(classPK);
1194
1195 if (orderByComparator != null) {
1196 Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
1197
1198 for (Object value : values) {
1199 qPos.add(value);
1200 }
1201 }
1202
1203 List<AnnouncementsEntry> list = q.list();
1204
1205 if (list.size() == 2) {
1206 return list.get(1);
1207 }
1208 else {
1209 return null;
1210 }
1211 }
1212
1213 public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1214 boolean alert) throws SystemException {
1215 return findByC_C_A(classNameId, classPK, alert, QueryUtil.ALL_POS,
1216 QueryUtil.ALL_POS, null);
1217 }
1218
1219 public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1220 boolean alert, int start, int end) throws SystemException {
1221 return findByC_C_A(classNameId, classPK, alert, start, end, null);
1222 }
1223
1224 public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1225 boolean alert, int start, int end, OrderByComparator orderByComparator)
1226 throws SystemException {
1227 Object[] finderArgs = new Object[] {
1228 classNameId, classPK, alert,
1229
1230 String.valueOf(start), String.valueOf(end),
1231 String.valueOf(orderByComparator)
1232 };
1233
1234 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_A,
1235 finderArgs, this);
1236
1237 if (list == null) {
1238 StringBundler query = null;
1239
1240 if (orderByComparator != null) {
1241 query = new StringBundler(5 +
1242 (orderByComparator.getOrderByFields().length * 3));
1243 }
1244 else {
1245 query = new StringBundler(5);
1246 }
1247
1248 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1249
1250 query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
1251
1252 query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
1253
1254 query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
1255
1256 if (orderByComparator != null) {
1257 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1258 orderByComparator);
1259 }
1260
1261 else {
1262 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1263 }
1264
1265 String sql = query.toString();
1266
1267 Session session = null;
1268
1269 try {
1270 session = openSession();
1271
1272 Query q = session.createQuery(sql);
1273
1274 QueryPos qPos = QueryPos.getInstance(q);
1275
1276 qPos.add(classNameId);
1277
1278 qPos.add(classPK);
1279
1280 qPos.add(alert);
1281
1282 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1283 getDialect(), start, end);
1284 }
1285 catch (Exception e) {
1286 throw processException(e);
1287 }
1288 finally {
1289 if (list == null) {
1290 list = new ArrayList<AnnouncementsEntry>();
1291 }
1292
1293 cacheResult(list);
1294
1295 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_A,
1296 finderArgs, list);
1297
1298 closeSession(session);
1299 }
1300 }
1301
1302 return list;
1303 }
1304
1305 public AnnouncementsEntry findByC_C_A_First(long classNameId, long classPK,
1306 boolean alert, OrderByComparator orderByComparator)
1307 throws NoSuchEntryException, SystemException {
1308 List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
1309 alert, 0, 1, orderByComparator);
1310
1311 if (list.isEmpty()) {
1312 StringBundler msg = new StringBundler(8);
1313
1314 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1315
1316 msg.append("classNameId=");
1317 msg.append(classNameId);
1318
1319 msg.append(", classPK=");
1320 msg.append(classPK);
1321
1322 msg.append(", alert=");
1323 msg.append(alert);
1324
1325 msg.append(StringPool.CLOSE_CURLY_BRACE);
1326
1327 throw new NoSuchEntryException(msg.toString());
1328 }
1329 else {
1330 return list.get(0);
1331 }
1332 }
1333
1334 public AnnouncementsEntry findByC_C_A_Last(long classNameId, long classPK,
1335 boolean alert, OrderByComparator orderByComparator)
1336 throws NoSuchEntryException, SystemException {
1337 int count = countByC_C_A(classNameId, classPK, alert);
1338
1339 List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
1340 alert, count - 1, count, orderByComparator);
1341
1342 if (list.isEmpty()) {
1343 StringBundler msg = new StringBundler(8);
1344
1345 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1346
1347 msg.append("classNameId=");
1348 msg.append(classNameId);
1349
1350 msg.append(", classPK=");
1351 msg.append(classPK);
1352
1353 msg.append(", alert=");
1354 msg.append(alert);
1355
1356 msg.append(StringPool.CLOSE_CURLY_BRACE);
1357
1358 throw new NoSuchEntryException(msg.toString());
1359 }
1360 else {
1361 return list.get(0);
1362 }
1363 }
1364
1365 public AnnouncementsEntry[] findByC_C_A_PrevAndNext(long entryId,
1366 long classNameId, long classPK, boolean alert,
1367 OrderByComparator orderByComparator)
1368 throws NoSuchEntryException, SystemException {
1369 AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1370
1371 Session session = null;
1372
1373 try {
1374 session = openSession();
1375
1376 AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1377
1378 array[0] = getByC_C_A_PrevAndNext(session, announcementsEntry,
1379 classNameId, classPK, alert, orderByComparator, true);
1380
1381 array[1] = announcementsEntry;
1382
1383 array[2] = getByC_C_A_PrevAndNext(session, announcementsEntry,
1384 classNameId, classPK, alert, orderByComparator, false);
1385
1386 return array;
1387 }
1388 catch (Exception e) {
1389 throw processException(e);
1390 }
1391 finally {
1392 closeSession(session);
1393 }
1394 }
1395
1396 protected AnnouncementsEntry getByC_C_A_PrevAndNext(Session session,
1397 AnnouncementsEntry announcementsEntry, long classNameId, long classPK,
1398 boolean alert, OrderByComparator orderByComparator, boolean previous) {
1399 StringBundler query = null;
1400
1401 if (orderByComparator != null) {
1402 query = new StringBundler(6 +
1403 (orderByComparator.getOrderByFields().length * 6));
1404 }
1405 else {
1406 query = new StringBundler(3);
1407 }
1408
1409 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1410
1411 query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
1412
1413 query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
1414
1415 query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
1416
1417 if (orderByComparator != null) {
1418 String[] orderByFields = orderByComparator.getOrderByFields();
1419
1420 if (orderByFields.length > 0) {
1421 query.append(WHERE_AND);
1422 }
1423
1424 for (int i = 0; i < orderByFields.length; i++) {
1425 query.append(_ORDER_BY_ENTITY_ALIAS);
1426 query.append(orderByFields[i]);
1427
1428 if ((i + 1) < orderByFields.length) {
1429 if (orderByComparator.isAscending() ^ previous) {
1430 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1431 }
1432 else {
1433 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1434 }
1435 }
1436 else {
1437 if (orderByComparator.isAscending() ^ previous) {
1438 query.append(WHERE_GREATER_THAN);
1439 }
1440 else {
1441 query.append(WHERE_LESSER_THAN);
1442 }
1443 }
1444 }
1445
1446 query.append(ORDER_BY_CLAUSE);
1447
1448 for (int i = 0; i < orderByFields.length; i++) {
1449 query.append(_ORDER_BY_ENTITY_ALIAS);
1450 query.append(orderByFields[i]);
1451
1452 if ((i + 1) < orderByFields.length) {
1453 if (orderByComparator.isAscending() ^ previous) {
1454 query.append(ORDER_BY_ASC_HAS_NEXT);
1455 }
1456 else {
1457 query.append(ORDER_BY_DESC_HAS_NEXT);
1458 }
1459 }
1460 else {
1461 if (orderByComparator.isAscending() ^ previous) {
1462 query.append(ORDER_BY_ASC);
1463 }
1464 else {
1465 query.append(ORDER_BY_DESC);
1466 }
1467 }
1468 }
1469 }
1470
1471 else {
1472 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1473 }
1474
1475 String sql = query.toString();
1476
1477 Query q = session.createQuery(sql);
1478
1479 q.setFirstResult(0);
1480 q.setMaxResults(2);
1481
1482 QueryPos qPos = QueryPos.getInstance(q);
1483
1484 qPos.add(classNameId);
1485
1486 qPos.add(classPK);
1487
1488 qPos.add(alert);
1489
1490 if (orderByComparator != null) {
1491 Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
1492
1493 for (Object value : values) {
1494 qPos.add(value);
1495 }
1496 }
1497
1498 List<AnnouncementsEntry> list = q.list();
1499
1500 if (list.size() == 2) {
1501 return list.get(1);
1502 }
1503 else {
1504 return null;
1505 }
1506 }
1507
1508 public List<AnnouncementsEntry> findAll() throws SystemException {
1509 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1510 }
1511
1512 public List<AnnouncementsEntry> findAll(int start, int end)
1513 throws SystemException {
1514 return findAll(start, end, null);
1515 }
1516
1517 public List<AnnouncementsEntry> findAll(int start, int end,
1518 OrderByComparator orderByComparator) throws SystemException {
1519 Object[] finderArgs = new Object[] {
1520 String.valueOf(start), String.valueOf(end),
1521 String.valueOf(orderByComparator)
1522 };
1523
1524 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1525 finderArgs, this);
1526
1527 if (list == null) {
1528 StringBundler query = null;
1529 String sql = null;
1530
1531 if (orderByComparator != null) {
1532 query = new StringBundler(2 +
1533 (orderByComparator.getOrderByFields().length * 3));
1534
1535 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY);
1536
1537 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1538 orderByComparator);
1539
1540 sql = query.toString();
1541 }
1542 else {
1543 sql = _SQL_SELECT_ANNOUNCEMENTSENTRY.concat(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1544 }
1545
1546 Session session = null;
1547
1548 try {
1549 session = openSession();
1550
1551 Query q = session.createQuery(sql);
1552
1553 if (orderByComparator == null) {
1554 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1555 getDialect(), start, end, false);
1556
1557 Collections.sort(list);
1558 }
1559 else {
1560 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1561 getDialect(), start, end);
1562 }
1563 }
1564 catch (Exception e) {
1565 throw processException(e);
1566 }
1567 finally {
1568 if (list == null) {
1569 list = new ArrayList<AnnouncementsEntry>();
1570 }
1571
1572 cacheResult(list);
1573
1574 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1575
1576 closeSession(session);
1577 }
1578 }
1579
1580 return list;
1581 }
1582
1583 public void removeByUuid(String uuid) throws SystemException {
1584 for (AnnouncementsEntry announcementsEntry : findByUuid(uuid)) {
1585 remove(announcementsEntry);
1586 }
1587 }
1588
1589 public void removeByUserId(long userId) throws SystemException {
1590 for (AnnouncementsEntry announcementsEntry : findByUserId(userId)) {
1591 remove(announcementsEntry);
1592 }
1593 }
1594
1595 public void removeByC_C(long classNameId, long classPK)
1596 throws SystemException {
1597 for (AnnouncementsEntry announcementsEntry : findByC_C(classNameId,
1598 classPK)) {
1599 remove(announcementsEntry);
1600 }
1601 }
1602
1603 public void removeByC_C_A(long classNameId, long classPK, boolean alert)
1604 throws SystemException {
1605 for (AnnouncementsEntry announcementsEntry : findByC_C_A(classNameId,
1606 classPK, alert)) {
1607 remove(announcementsEntry);
1608 }
1609 }
1610
1611 public void removeAll() throws SystemException {
1612 for (AnnouncementsEntry announcementsEntry : findAll()) {
1613 remove(announcementsEntry);
1614 }
1615 }
1616
1617 public int countByUuid(String uuid) throws SystemException {
1618 Object[] finderArgs = new Object[] { uuid };
1619
1620 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1621 finderArgs, this);
1622
1623 if (count == null) {
1624 StringBundler query = new StringBundler(2);
1625
1626 query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
1627
1628 if (uuid == null) {
1629 query.append(_FINDER_COLUMN_UUID_UUID_1);
1630 }
1631 else {
1632 if (uuid.equals(StringPool.BLANK)) {
1633 query.append(_FINDER_COLUMN_UUID_UUID_3);
1634 }
1635 else {
1636 query.append(_FINDER_COLUMN_UUID_UUID_2);
1637 }
1638 }
1639
1640 String sql = query.toString();
1641
1642 Session session = null;
1643
1644 try {
1645 session = openSession();
1646
1647 Query q = session.createQuery(sql);
1648
1649 QueryPos qPos = QueryPos.getInstance(q);
1650
1651 if (uuid != null) {
1652 qPos.add(uuid);
1653 }
1654
1655 count = (Long)q.uniqueResult();
1656 }
1657 catch (Exception e) {
1658 throw processException(e);
1659 }
1660 finally {
1661 if (count == null) {
1662 count = Long.valueOf(0);
1663 }
1664
1665 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1666 finderArgs, count);
1667
1668 closeSession(session);
1669 }
1670 }
1671
1672 return count.intValue();
1673 }
1674
1675 public int countByUserId(long userId) throws SystemException {
1676 Object[] finderArgs = new Object[] { userId };
1677
1678 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1679 finderArgs, this);
1680
1681 if (count == null) {
1682 StringBundler query = new StringBundler(2);
1683
1684 query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
1685
1686 query.append(_FINDER_COLUMN_USERID_USERID_2);
1687
1688 String sql = query.toString();
1689
1690 Session session = null;
1691
1692 try {
1693 session = openSession();
1694
1695 Query q = session.createQuery(sql);
1696
1697 QueryPos qPos = QueryPos.getInstance(q);
1698
1699 qPos.add(userId);
1700
1701 count = (Long)q.uniqueResult();
1702 }
1703 catch (Exception e) {
1704 throw processException(e);
1705 }
1706 finally {
1707 if (count == null) {
1708 count = Long.valueOf(0);
1709 }
1710
1711 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1712 finderArgs, count);
1713
1714 closeSession(session);
1715 }
1716 }
1717
1718 return count.intValue();
1719 }
1720
1721 public int countByC_C(long classNameId, long classPK)
1722 throws SystemException {
1723 Object[] finderArgs = new Object[] { classNameId, classPK };
1724
1725 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1726 finderArgs, this);
1727
1728 if (count == null) {
1729 StringBundler query = new StringBundler(3);
1730
1731 query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
1732
1733 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1734
1735 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1736
1737 String sql = query.toString();
1738
1739 Session session = null;
1740
1741 try {
1742 session = openSession();
1743
1744 Query q = session.createQuery(sql);
1745
1746 QueryPos qPos = QueryPos.getInstance(q);
1747
1748 qPos.add(classNameId);
1749
1750 qPos.add(classPK);
1751
1752 count = (Long)q.uniqueResult();
1753 }
1754 catch (Exception e) {
1755 throw processException(e);
1756 }
1757 finally {
1758 if (count == null) {
1759 count = Long.valueOf(0);
1760 }
1761
1762 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1763 count);
1764
1765 closeSession(session);
1766 }
1767 }
1768
1769 return count.intValue();
1770 }
1771
1772 public int countByC_C_A(long classNameId, long classPK, boolean alert)
1773 throws SystemException {
1774 Object[] finderArgs = new Object[] { classNameId, classPK, alert };
1775
1776 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_A,
1777 finderArgs, this);
1778
1779 if (count == null) {
1780 StringBundler query = new StringBundler(4);
1781
1782 query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
1783
1784 query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
1785
1786 query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
1787
1788 query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
1789
1790 String sql = query.toString();
1791
1792 Session session = null;
1793
1794 try {
1795 session = openSession();
1796
1797 Query q = session.createQuery(sql);
1798
1799 QueryPos qPos = QueryPos.getInstance(q);
1800
1801 qPos.add(classNameId);
1802
1803 qPos.add(classPK);
1804
1805 qPos.add(alert);
1806
1807 count = (Long)q.uniqueResult();
1808 }
1809 catch (Exception e) {
1810 throw processException(e);
1811 }
1812 finally {
1813 if (count == null) {
1814 count = Long.valueOf(0);
1815 }
1816
1817 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_A,
1818 finderArgs, count);
1819
1820 closeSession(session);
1821 }
1822 }
1823
1824 return count.intValue();
1825 }
1826
1827 public int countAll() throws SystemException {
1828 Object[] finderArgs = new Object[0];
1829
1830 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1831 finderArgs, this);
1832
1833 if (count == null) {
1834 Session session = null;
1835
1836 try {
1837 session = openSession();
1838
1839 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSENTRY);
1840
1841 count = (Long)q.uniqueResult();
1842 }
1843 catch (Exception e) {
1844 throw processException(e);
1845 }
1846 finally {
1847 if (count == null) {
1848 count = Long.valueOf(0);
1849 }
1850
1851 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1852 count);
1853
1854 closeSession(session);
1855 }
1856 }
1857
1858 return count.intValue();
1859 }
1860
1861 public void afterPropertiesSet() {
1862 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1863 com.liferay.portal.util.PropsUtil.get(
1864 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsEntry")));
1865
1866 if (listenerClassNames.length > 0) {
1867 try {
1868 List<ModelListener<AnnouncementsEntry>> listenersList = new ArrayList<ModelListener<AnnouncementsEntry>>();
1869
1870 for (String listenerClassName : listenerClassNames) {
1871 listenersList.add((ModelListener<AnnouncementsEntry>)InstanceFactory.newInstance(
1872 listenerClassName));
1873 }
1874
1875 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1876 }
1877 catch (Exception e) {
1878 _log.error(e);
1879 }
1880 }
1881 }
1882
1883 public void destroy() {
1884 EntityCacheUtil.removeCache(AnnouncementsEntryImpl.class.getName());
1885 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1886 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1887 }
1888
1889 @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1890 protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1891 @BeanReference(type = AnnouncementsEntryPersistence.class)
1892 protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1893 @BeanReference(type = AnnouncementsFlagPersistence.class)
1894 protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1895 @BeanReference(type = CompanyPersistence.class)
1896 protected CompanyPersistence companyPersistence;
1897 @BeanReference(type = GroupPersistence.class)
1898 protected GroupPersistence groupPersistence;
1899 @BeanReference(type = OrganizationPersistence.class)
1900 protected OrganizationPersistence organizationPersistence;
1901 @BeanReference(type = ResourcePersistence.class)
1902 protected ResourcePersistence resourcePersistence;
1903 @BeanReference(type = RolePersistence.class)
1904 protected RolePersistence rolePersistence;
1905 @BeanReference(type = UserPersistence.class)
1906 protected UserPersistence userPersistence;
1907 @BeanReference(type = UserGroupPersistence.class)
1908 protected UserGroupPersistence userGroupPersistence;
1909 private static final String _SQL_SELECT_ANNOUNCEMENTSENTRY = "SELECT announcementsEntry FROM AnnouncementsEntry announcementsEntry";
1910 private static final String _SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE = "SELECT announcementsEntry FROM AnnouncementsEntry announcementsEntry WHERE ";
1911 private static final String _SQL_COUNT_ANNOUNCEMENTSENTRY = "SELECT COUNT(announcementsEntry) FROM AnnouncementsEntry announcementsEntry";
1912 private static final String _SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE = "SELECT COUNT(announcementsEntry) FROM AnnouncementsEntry announcementsEntry WHERE ";
1913 private static final String _FINDER_COLUMN_UUID_UUID_1 = "announcementsEntry.uuid IS NULL";
1914 private static final String _FINDER_COLUMN_UUID_UUID_2 = "announcementsEntry.uuid = ?";
1915 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(announcementsEntry.uuid IS NULL OR announcementsEntry.uuid = ?)";
1916 private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsEntry.userId = ?";
1917 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "announcementsEntry.classNameId = ? AND ";
1918 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "announcementsEntry.classPK = ?";
1919 private static final String _FINDER_COLUMN_C_C_A_CLASSNAMEID_2 = "announcementsEntry.classNameId = ? AND ";
1920 private static final String _FINDER_COLUMN_C_C_A_CLASSPK_2 = "announcementsEntry.classPK = ? AND ";
1921 private static final String _FINDER_COLUMN_C_C_A_ALERT_2 = "announcementsEntry.alert = ?";
1922 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsEntry.";
1923 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsEntry exists with the primary key ";
1924 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsEntry exists with the key {";
1925 private static Log _log = LogFactoryUtil.getLog(AnnouncementsEntryPersistenceImpl.class);
1926}