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