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
076 public class AnnouncementsEntryPersistenceImpl extends BasePersistenceImpl<AnnouncementsEntry>
077 implements AnnouncementsEntryPersistence {
078 public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsEntryImpl.class.getName();
079 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
080 ".List";
081 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
082 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
083 FINDER_CLASS_NAME_LIST, "findByUuid",
084 new String[] {
085 String.class.getName(),
086
087 "java.lang.Integer", "java.lang.Integer",
088 "com.liferay.portal.kernel.util.OrderByComparator"
089 });
090 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
091 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
092 FINDER_CLASS_NAME_LIST, "countByUuid",
093 new String[] { String.class.getName() });
094 public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
095 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
096 FINDER_CLASS_NAME_LIST, "findByUserId",
097 new String[] {
098 Long.class.getName(),
099
100 "java.lang.Integer", "java.lang.Integer",
101 "com.liferay.portal.kernel.util.OrderByComparator"
102 });
103 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
104 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
105 FINDER_CLASS_NAME_LIST, "countByUserId",
106 new String[] { Long.class.getName() });
107 public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
108 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
109 FINDER_CLASS_NAME_LIST, "findByC_C",
110 new String[] {
111 Long.class.getName(), Long.class.getName(),
112
113 "java.lang.Integer", "java.lang.Integer",
114 "com.liferay.portal.kernel.util.OrderByComparator"
115 });
116 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
117 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
118 FINDER_CLASS_NAME_LIST, "countByC_C",
119 new String[] { Long.class.getName(), Long.class.getName() });
120 public static final FinderPath FINDER_PATH_FIND_BY_C_C_A = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
121 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
122 FINDER_CLASS_NAME_LIST, "findByC_C_A",
123 new String[] {
124 Long.class.getName(), Long.class.getName(),
125 Boolean.class.getName(),
126
127 "java.lang.Integer", "java.lang.Integer",
128 "com.liferay.portal.kernel.util.OrderByComparator"
129 });
130 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_A = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
131 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
132 FINDER_CLASS_NAME_LIST, "countByC_C_A",
133 new String[] {
134 Long.class.getName(), Long.class.getName(),
135 Boolean.class.getName()
136 });
137 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
138 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
139 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
140 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
141 AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
142 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
143
144
149 public void cacheResult(AnnouncementsEntry announcementsEntry) {
150 EntityCacheUtil.putResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
151 AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey(),
152 announcementsEntry);
153 }
154
155
160 public void cacheResult(List<AnnouncementsEntry> announcementsEntries) {
161 for (AnnouncementsEntry announcementsEntry : announcementsEntries) {
162 if (EntityCacheUtil.getResult(
163 AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
164 AnnouncementsEntryImpl.class,
165 announcementsEntry.getPrimaryKey(), this) == null) {
166 cacheResult(announcementsEntry);
167 }
168 }
169 }
170
171
178 public void clearCache() {
179 CacheRegistryUtil.clear(AnnouncementsEntryImpl.class.getName());
180 EntityCacheUtil.clearCache(AnnouncementsEntryImpl.class.getName());
181 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
182 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
183 }
184
185
192 public void clearCache(AnnouncementsEntry announcementsEntry) {
193 EntityCacheUtil.removeResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
194 AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey());
195 }
196
197
203 public AnnouncementsEntry create(long entryId) {
204 AnnouncementsEntry announcementsEntry = new AnnouncementsEntryImpl();
205
206 announcementsEntry.setNew(true);
207 announcementsEntry.setPrimaryKey(entryId);
208
209 String uuid = PortalUUIDUtil.generate();
210
211 announcementsEntry.setUuid(uuid);
212
213 return announcementsEntry;
214 }
215
216
224 public AnnouncementsEntry remove(Serializable primaryKey)
225 throws NoSuchModelException, SystemException {
226 return remove(((Long)primaryKey).longValue());
227 }
228
229
237 public AnnouncementsEntry remove(long entryId)
238 throws NoSuchEntryException, SystemException {
239 Session session = null;
240
241 try {
242 session = openSession();
243
244 AnnouncementsEntry announcementsEntry = (AnnouncementsEntry)session.get(AnnouncementsEntryImpl.class,
245 new Long(entryId));
246
247 if (announcementsEntry == null) {
248 if (_log.isWarnEnabled()) {
249 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
250 }
251
252 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
253 entryId);
254 }
255
256 return remove(announcementsEntry);
257 }
258 catch (NoSuchEntryException nsee) {
259 throw nsee;
260 }
261 catch (Exception e) {
262 throw processException(e);
263 }
264 finally {
265 closeSession(session);
266 }
267 }
268
269 protected AnnouncementsEntry removeImpl(
270 AnnouncementsEntry announcementsEntry) throws SystemException {
271 announcementsEntry = toUnwrappedModel(announcementsEntry);
272
273 Session session = null;
274
275 try {
276 session = openSession();
277
278 if (announcementsEntry.isCachedModel() ||
279 BatchSessionUtil.isEnabled()) {
280 Object staleObject = session.get(AnnouncementsEntryImpl.class,
281 announcementsEntry.getPrimaryKeyObj());
282
283 if (staleObject != null) {
284 session.evict(staleObject);
285 }
286 }
287
288 session.delete(announcementsEntry);
289
290 session.flush();
291 }
292 catch (Exception e) {
293 throw processException(e);
294 }
295 finally {
296 closeSession(session);
297 }
298
299 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
300
301 EntityCacheUtil.removeResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
302 AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey());
303
304 return announcementsEntry;
305 }
306
307 public AnnouncementsEntry updateImpl(
308 com.liferay.portlet.announcements.model.AnnouncementsEntry announcementsEntry,
309 boolean merge) throws SystemException {
310 announcementsEntry = toUnwrappedModel(announcementsEntry);
311
312 if (Validator.isNull(announcementsEntry.getUuid())) {
313 String uuid = PortalUUIDUtil.generate();
314
315 announcementsEntry.setUuid(uuid);
316 }
317
318 Session session = null;
319
320 try {
321 session = openSession();
322
323 BatchSessionUtil.update(session, announcementsEntry, merge);
324
325 announcementsEntry.setNew(false);
326 }
327 catch (Exception e) {
328 throw processException(e);
329 }
330 finally {
331 closeSession(session);
332 }
333
334 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
335
336 EntityCacheUtil.putResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
337 AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey(),
338 announcementsEntry);
339
340 return announcementsEntry;
341 }
342
343 protected AnnouncementsEntry toUnwrappedModel(
344 AnnouncementsEntry announcementsEntry) {
345 if (announcementsEntry instanceof AnnouncementsEntryImpl) {
346 return announcementsEntry;
347 }
348
349 AnnouncementsEntryImpl announcementsEntryImpl = new AnnouncementsEntryImpl();
350
351 announcementsEntryImpl.setNew(announcementsEntry.isNew());
352 announcementsEntryImpl.setPrimaryKey(announcementsEntry.getPrimaryKey());
353
354 announcementsEntryImpl.setUuid(announcementsEntry.getUuid());
355 announcementsEntryImpl.setEntryId(announcementsEntry.getEntryId());
356 announcementsEntryImpl.setCompanyId(announcementsEntry.getCompanyId());
357 announcementsEntryImpl.setUserId(announcementsEntry.getUserId());
358 announcementsEntryImpl.setUserName(announcementsEntry.getUserName());
359 announcementsEntryImpl.setCreateDate(announcementsEntry.getCreateDate());
360 announcementsEntryImpl.setModifiedDate(announcementsEntry.getModifiedDate());
361 announcementsEntryImpl.setClassNameId(announcementsEntry.getClassNameId());
362 announcementsEntryImpl.setClassPK(announcementsEntry.getClassPK());
363 announcementsEntryImpl.setTitle(announcementsEntry.getTitle());
364 announcementsEntryImpl.setContent(announcementsEntry.getContent());
365 announcementsEntryImpl.setUrl(announcementsEntry.getUrl());
366 announcementsEntryImpl.setType(announcementsEntry.getType());
367 announcementsEntryImpl.setDisplayDate(announcementsEntry.getDisplayDate());
368 announcementsEntryImpl.setExpirationDate(announcementsEntry.getExpirationDate());
369 announcementsEntryImpl.setPriority(announcementsEntry.getPriority());
370 announcementsEntryImpl.setAlert(announcementsEntry.isAlert());
371
372 return announcementsEntryImpl;
373 }
374
375
383 public AnnouncementsEntry findByPrimaryKey(Serializable primaryKey)
384 throws NoSuchModelException, SystemException {
385 return findByPrimaryKey(((Long)primaryKey).longValue());
386 }
387
388
396 public AnnouncementsEntry findByPrimaryKey(long entryId)
397 throws NoSuchEntryException, SystemException {
398 AnnouncementsEntry announcementsEntry = fetchByPrimaryKey(entryId);
399
400 if (announcementsEntry == null) {
401 if (_log.isWarnEnabled()) {
402 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
403 }
404
405 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
406 entryId);
407 }
408
409 return announcementsEntry;
410 }
411
412
419 public AnnouncementsEntry fetchByPrimaryKey(Serializable primaryKey)
420 throws SystemException {
421 return fetchByPrimaryKey(((Long)primaryKey).longValue());
422 }
423
424
431 public AnnouncementsEntry fetchByPrimaryKey(long entryId)
432 throws SystemException {
433 AnnouncementsEntry announcementsEntry = (AnnouncementsEntry)EntityCacheUtil.getResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
434 AnnouncementsEntryImpl.class, entryId, this);
435
436 if (announcementsEntry == null) {
437 Session session = null;
438
439 try {
440 session = openSession();
441
442 announcementsEntry = (AnnouncementsEntry)session.get(AnnouncementsEntryImpl.class,
443 new Long(entryId));
444 }
445 catch (Exception e) {
446 throw processException(e);
447 }
448 finally {
449 if (announcementsEntry != null) {
450 cacheResult(announcementsEntry);
451 }
452
453 closeSession(session);
454 }
455 }
456
457 return announcementsEntry;
458 }
459
460
467 public List<AnnouncementsEntry> findByUuid(String uuid)
468 throws SystemException {
469 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
470 }
471
472
485 public List<AnnouncementsEntry> findByUuid(String uuid, int start, int end)
486 throws SystemException {
487 return findByUuid(uuid, start, end, null);
488 }
489
490
504 public List<AnnouncementsEntry> findByUuid(String uuid, int start, int end,
505 OrderByComparator orderByComparator) throws SystemException {
506 Object[] finderArgs = new Object[] {
507 uuid,
508
509 String.valueOf(start), String.valueOf(end),
510 String.valueOf(orderByComparator)
511 };
512
513 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
514 finderArgs, this);
515
516 if (list == null) {
517 Session session = null;
518
519 try {
520 session = openSession();
521
522 StringBundler query = null;
523
524 if (orderByComparator != null) {
525 query = new StringBundler(3 +
526 (orderByComparator.getOrderByFields().length * 3));
527 }
528 else {
529 query = new StringBundler(3);
530 }
531
532 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
533
534 if (uuid == null) {
535 query.append(_FINDER_COLUMN_UUID_UUID_1);
536 }
537 else {
538 if (uuid.equals(StringPool.BLANK)) {
539 query.append(_FINDER_COLUMN_UUID_UUID_3);
540 }
541 else {
542 query.append(_FINDER_COLUMN_UUID_UUID_2);
543 }
544 }
545
546 if (orderByComparator != null) {
547 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
548 orderByComparator);
549 }
550
551 else {
552 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
553 }
554
555 String sql = query.toString();
556
557 Query q = session.createQuery(sql);
558
559 QueryPos qPos = QueryPos.getInstance(q);
560
561 if (uuid != null) {
562 qPos.add(uuid);
563 }
564
565 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
566 getDialect(), start, end);
567 }
568 catch (Exception e) {
569 throw processException(e);
570 }
571 finally {
572 if (list == null) {
573 list = new ArrayList<AnnouncementsEntry>();
574 }
575
576 cacheResult(list);
577
578 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
579 list);
580
581 closeSession(session);
582 }
583 }
584
585 return list;
586 }
587
588
601 public AnnouncementsEntry findByUuid_First(String uuid,
602 OrderByComparator orderByComparator)
603 throws NoSuchEntryException, SystemException {
604 List<AnnouncementsEntry> list = findByUuid(uuid, 0, 1, orderByComparator);
605
606 if (list.isEmpty()) {
607 StringBundler msg = new StringBundler(4);
608
609 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
610
611 msg.append("uuid=");
612 msg.append(uuid);
613
614 msg.append(StringPool.CLOSE_CURLY_BRACE);
615
616 throw new NoSuchEntryException(msg.toString());
617 }
618 else {
619 return list.get(0);
620 }
621 }
622
623
636 public AnnouncementsEntry findByUuid_Last(String uuid,
637 OrderByComparator orderByComparator)
638 throws NoSuchEntryException, SystemException {
639 int count = countByUuid(uuid);
640
641 List<AnnouncementsEntry> list = findByUuid(uuid, count - 1, count,
642 orderByComparator);
643
644 if (list.isEmpty()) {
645 StringBundler msg = new StringBundler(4);
646
647 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
648
649 msg.append("uuid=");
650 msg.append(uuid);
651
652 msg.append(StringPool.CLOSE_CURLY_BRACE);
653
654 throw new NoSuchEntryException(msg.toString());
655 }
656 else {
657 return list.get(0);
658 }
659 }
660
661
675 public AnnouncementsEntry[] findByUuid_PrevAndNext(long entryId,
676 String uuid, OrderByComparator orderByComparator)
677 throws NoSuchEntryException, SystemException {
678 AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
679
680 Session session = null;
681
682 try {
683 session = openSession();
684
685 AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
686
687 array[0] = getByUuid_PrevAndNext(session, announcementsEntry, uuid,
688 orderByComparator, true);
689
690 array[1] = announcementsEntry;
691
692 array[2] = getByUuid_PrevAndNext(session, announcementsEntry, uuid,
693 orderByComparator, false);
694
695 return array;
696 }
697 catch (Exception e) {
698 throw processException(e);
699 }
700 finally {
701 closeSession(session);
702 }
703 }
704
705 protected AnnouncementsEntry getByUuid_PrevAndNext(Session session,
706 AnnouncementsEntry announcementsEntry, String uuid,
707 OrderByComparator orderByComparator, boolean previous) {
708 StringBundler query = null;
709
710 if (orderByComparator != null) {
711 query = new StringBundler(6 +
712 (orderByComparator.getOrderByFields().length * 6));
713 }
714 else {
715 query = new StringBundler(3);
716 }
717
718 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
719
720 if (uuid == null) {
721 query.append(_FINDER_COLUMN_UUID_UUID_1);
722 }
723 else {
724 if (uuid.equals(StringPool.BLANK)) {
725 query.append(_FINDER_COLUMN_UUID_UUID_3);
726 }
727 else {
728 query.append(_FINDER_COLUMN_UUID_UUID_2);
729 }
730 }
731
732 if (orderByComparator != null) {
733 String[] orderByFields = orderByComparator.getOrderByFields();
734
735 if (orderByFields.length > 0) {
736 query.append(WHERE_AND);
737 }
738
739 for (int i = 0; i < orderByFields.length; i++) {
740 query.append(_ORDER_BY_ENTITY_ALIAS);
741 query.append(orderByFields[i]);
742
743 if ((i + 1) < orderByFields.length) {
744 if (orderByComparator.isAscending() ^ previous) {
745 query.append(WHERE_GREATER_THAN_HAS_NEXT);
746 }
747 else {
748 query.append(WHERE_LESSER_THAN_HAS_NEXT);
749 }
750 }
751 else {
752 if (orderByComparator.isAscending() ^ previous) {
753 query.append(WHERE_GREATER_THAN);
754 }
755 else {
756 query.append(WHERE_LESSER_THAN);
757 }
758 }
759 }
760
761 query.append(ORDER_BY_CLAUSE);
762
763 for (int i = 0; i < orderByFields.length; i++) {
764 query.append(_ORDER_BY_ENTITY_ALIAS);
765 query.append(orderByFields[i]);
766
767 if ((i + 1) < orderByFields.length) {
768 if (orderByComparator.isAscending() ^ previous) {
769 query.append(ORDER_BY_ASC_HAS_NEXT);
770 }
771 else {
772 query.append(ORDER_BY_DESC_HAS_NEXT);
773 }
774 }
775 else {
776 if (orderByComparator.isAscending() ^ previous) {
777 query.append(ORDER_BY_ASC);
778 }
779 else {
780 query.append(ORDER_BY_DESC);
781 }
782 }
783 }
784 }
785
786 else {
787 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
788 }
789
790 String sql = query.toString();
791
792 Query q = session.createQuery(sql);
793
794 q.setFirstResult(0);
795 q.setMaxResults(2);
796
797 QueryPos qPos = QueryPos.getInstance(q);
798
799 if (uuid != null) {
800 qPos.add(uuid);
801 }
802
803 if (orderByComparator != null) {
804 Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
805
806 for (Object value : values) {
807 qPos.add(value);
808 }
809 }
810
811 List<AnnouncementsEntry> list = q.list();
812
813 if (list.size() == 2) {
814 return list.get(1);
815 }
816 else {
817 return null;
818 }
819 }
820
821
828 public List<AnnouncementsEntry> findByUserId(long userId)
829 throws SystemException {
830 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
831 }
832
833
846 public List<AnnouncementsEntry> findByUserId(long userId, int start, int end)
847 throws SystemException {
848 return findByUserId(userId, start, end, null);
849 }
850
851
865 public List<AnnouncementsEntry> findByUserId(long userId, int start,
866 int end, OrderByComparator orderByComparator) throws SystemException {
867 Object[] finderArgs = new Object[] {
868 userId,
869
870 String.valueOf(start), String.valueOf(end),
871 String.valueOf(orderByComparator)
872 };
873
874 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
875 finderArgs, this);
876
877 if (list == null) {
878 Session session = null;
879
880 try {
881 session = openSession();
882
883 StringBundler query = null;
884
885 if (orderByComparator != null) {
886 query = new StringBundler(3 +
887 (orderByComparator.getOrderByFields().length * 3));
888 }
889 else {
890 query = new StringBundler(3);
891 }
892
893 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
894
895 query.append(_FINDER_COLUMN_USERID_USERID_2);
896
897 if (orderByComparator != null) {
898 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
899 orderByComparator);
900 }
901
902 else {
903 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
904 }
905
906 String sql = query.toString();
907
908 Query q = session.createQuery(sql);
909
910 QueryPos qPos = QueryPos.getInstance(q);
911
912 qPos.add(userId);
913
914 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
915 getDialect(), start, end);
916 }
917 catch (Exception e) {
918 throw processException(e);
919 }
920 finally {
921 if (list == null) {
922 list = new ArrayList<AnnouncementsEntry>();
923 }
924
925 cacheResult(list);
926
927 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
928 finderArgs, list);
929
930 closeSession(session);
931 }
932 }
933
934 return list;
935 }
936
937
950 public AnnouncementsEntry findByUserId_First(long userId,
951 OrderByComparator orderByComparator)
952 throws NoSuchEntryException, SystemException {
953 List<AnnouncementsEntry> list = findByUserId(userId, 0, 1,
954 orderByComparator);
955
956 if (list.isEmpty()) {
957 StringBundler msg = new StringBundler(4);
958
959 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
960
961 msg.append("userId=");
962 msg.append(userId);
963
964 msg.append(StringPool.CLOSE_CURLY_BRACE);
965
966 throw new NoSuchEntryException(msg.toString());
967 }
968 else {
969 return list.get(0);
970 }
971 }
972
973
986 public AnnouncementsEntry findByUserId_Last(long userId,
987 OrderByComparator orderByComparator)
988 throws NoSuchEntryException, SystemException {
989 int count = countByUserId(userId);
990
991 List<AnnouncementsEntry> list = findByUserId(userId, count - 1, count,
992 orderByComparator);
993
994 if (list.isEmpty()) {
995 StringBundler msg = new StringBundler(4);
996
997 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
998
999 msg.append("userId=");
1000 msg.append(userId);
1001
1002 msg.append(StringPool.CLOSE_CURLY_BRACE);
1003
1004 throw new NoSuchEntryException(msg.toString());
1005 }
1006 else {
1007 return list.get(0);
1008 }
1009 }
1010
1011
1025 public AnnouncementsEntry[] findByUserId_PrevAndNext(long entryId,
1026 long userId, OrderByComparator orderByComparator)
1027 throws NoSuchEntryException, SystemException {
1028 AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1029
1030 Session session = null;
1031
1032 try {
1033 session = openSession();
1034
1035 AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1036
1037 array[0] = getByUserId_PrevAndNext(session, announcementsEntry,
1038 userId, orderByComparator, true);
1039
1040 array[1] = announcementsEntry;
1041
1042 array[2] = getByUserId_PrevAndNext(session, announcementsEntry,
1043 userId, orderByComparator, false);
1044
1045 return array;
1046 }
1047 catch (Exception e) {
1048 throw processException(e);
1049 }
1050 finally {
1051 closeSession(session);
1052 }
1053 }
1054
1055 protected AnnouncementsEntry getByUserId_PrevAndNext(Session session,
1056 AnnouncementsEntry announcementsEntry, long userId,
1057 OrderByComparator orderByComparator, boolean previous) {
1058 StringBundler query = null;
1059
1060 if (orderByComparator != null) {
1061 query = new StringBundler(6 +
1062 (orderByComparator.getOrderByFields().length * 6));
1063 }
1064 else {
1065 query = new StringBundler(3);
1066 }
1067
1068 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1069
1070 query.append(_FINDER_COLUMN_USERID_USERID_2);
1071
1072 if (orderByComparator != null) {
1073 String[] orderByFields = orderByComparator.getOrderByFields();
1074
1075 if (orderByFields.length > 0) {
1076 query.append(WHERE_AND);
1077 }
1078
1079 for (int i = 0; i < orderByFields.length; i++) {
1080 query.append(_ORDER_BY_ENTITY_ALIAS);
1081 query.append(orderByFields[i]);
1082
1083 if ((i + 1) < orderByFields.length) {
1084 if (orderByComparator.isAscending() ^ previous) {
1085 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1086 }
1087 else {
1088 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1089 }
1090 }
1091 else {
1092 if (orderByComparator.isAscending() ^ previous) {
1093 query.append(WHERE_GREATER_THAN);
1094 }
1095 else {
1096 query.append(WHERE_LESSER_THAN);
1097 }
1098 }
1099 }
1100
1101 query.append(ORDER_BY_CLAUSE);
1102
1103 for (int i = 0; i < orderByFields.length; i++) {
1104 query.append(_ORDER_BY_ENTITY_ALIAS);
1105 query.append(orderByFields[i]);
1106
1107 if ((i + 1) < orderByFields.length) {
1108 if (orderByComparator.isAscending() ^ previous) {
1109 query.append(ORDER_BY_ASC_HAS_NEXT);
1110 }
1111 else {
1112 query.append(ORDER_BY_DESC_HAS_NEXT);
1113 }
1114 }
1115 else {
1116 if (orderByComparator.isAscending() ^ previous) {
1117 query.append(ORDER_BY_ASC);
1118 }
1119 else {
1120 query.append(ORDER_BY_DESC);
1121 }
1122 }
1123 }
1124 }
1125
1126 else {
1127 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1128 }
1129
1130 String sql = query.toString();
1131
1132 Query q = session.createQuery(sql);
1133
1134 q.setFirstResult(0);
1135 q.setMaxResults(2);
1136
1137 QueryPos qPos = QueryPos.getInstance(q);
1138
1139 qPos.add(userId);
1140
1141 if (orderByComparator != null) {
1142 Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
1143
1144 for (Object value : values) {
1145 qPos.add(value);
1146 }
1147 }
1148
1149 List<AnnouncementsEntry> list = q.list();
1150
1151 if (list.size() == 2) {
1152 return list.get(1);
1153 }
1154 else {
1155 return null;
1156 }
1157 }
1158
1159
1167 public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK)
1168 throws SystemException {
1169 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
1170 QueryUtil.ALL_POS, null);
1171 }
1172
1173
1187 public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
1188 int start, int end) throws SystemException {
1189 return findByC_C(classNameId, classPK, start, end, null);
1190 }
1191
1192
1207 public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
1208 int start, int end, OrderByComparator orderByComparator)
1209 throws SystemException {
1210 Object[] finderArgs = new Object[] {
1211 classNameId, classPK,
1212
1213 String.valueOf(start), String.valueOf(end),
1214 String.valueOf(orderByComparator)
1215 };
1216
1217 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
1218 finderArgs, this);
1219
1220 if (list == null) {
1221 Session session = null;
1222
1223 try {
1224 session = openSession();
1225
1226 StringBundler query = null;
1227
1228 if (orderByComparator != null) {
1229 query = new StringBundler(4 +
1230 (orderByComparator.getOrderByFields().length * 3));
1231 }
1232 else {
1233 query = new StringBundler(4);
1234 }
1235
1236 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1237
1238 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1239
1240 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1241
1242 if (orderByComparator != null) {
1243 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1244 orderByComparator);
1245 }
1246
1247 else {
1248 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1249 }
1250
1251 String sql = query.toString();
1252
1253 Query q = session.createQuery(sql);
1254
1255 QueryPos qPos = QueryPos.getInstance(q);
1256
1257 qPos.add(classNameId);
1258
1259 qPos.add(classPK);
1260
1261 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1262 getDialect(), start, end);
1263 }
1264 catch (Exception e) {
1265 throw processException(e);
1266 }
1267 finally {
1268 if (list == null) {
1269 list = new ArrayList<AnnouncementsEntry>();
1270 }
1271
1272 cacheResult(list);
1273
1274 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
1275 list);
1276
1277 closeSession(session);
1278 }
1279 }
1280
1281 return list;
1282 }
1283
1284
1298 public AnnouncementsEntry findByC_C_First(long classNameId, long classPK,
1299 OrderByComparator orderByComparator)
1300 throws NoSuchEntryException, SystemException {
1301 List<AnnouncementsEntry> list = findByC_C(classNameId, classPK, 0, 1,
1302 orderByComparator);
1303
1304 if (list.isEmpty()) {
1305 StringBundler msg = new StringBundler(6);
1306
1307 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1308
1309 msg.append("classNameId=");
1310 msg.append(classNameId);
1311
1312 msg.append(", classPK=");
1313 msg.append(classPK);
1314
1315 msg.append(StringPool.CLOSE_CURLY_BRACE);
1316
1317 throw new NoSuchEntryException(msg.toString());
1318 }
1319 else {
1320 return list.get(0);
1321 }
1322 }
1323
1324
1338 public AnnouncementsEntry findByC_C_Last(long classNameId, long classPK,
1339 OrderByComparator orderByComparator)
1340 throws NoSuchEntryException, SystemException {
1341 int count = countByC_C(classNameId, classPK);
1342
1343 List<AnnouncementsEntry> list = findByC_C(classNameId, classPK,
1344 count - 1, count, orderByComparator);
1345
1346 if (list.isEmpty()) {
1347 StringBundler msg = new StringBundler(6);
1348
1349 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1350
1351 msg.append("classNameId=");
1352 msg.append(classNameId);
1353
1354 msg.append(", classPK=");
1355 msg.append(classPK);
1356
1357 msg.append(StringPool.CLOSE_CURLY_BRACE);
1358
1359 throw new NoSuchEntryException(msg.toString());
1360 }
1361 else {
1362 return list.get(0);
1363 }
1364 }
1365
1366
1381 public AnnouncementsEntry[] findByC_C_PrevAndNext(long entryId,
1382 long classNameId, long classPK, OrderByComparator orderByComparator)
1383 throws NoSuchEntryException, SystemException {
1384 AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1385
1386 Session session = null;
1387
1388 try {
1389 session = openSession();
1390
1391 AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1392
1393 array[0] = getByC_C_PrevAndNext(session, announcementsEntry,
1394 classNameId, classPK, orderByComparator, true);
1395
1396 array[1] = announcementsEntry;
1397
1398 array[2] = getByC_C_PrevAndNext(session, announcementsEntry,
1399 classNameId, classPK, orderByComparator, false);
1400
1401 return array;
1402 }
1403 catch (Exception e) {
1404 throw processException(e);
1405 }
1406 finally {
1407 closeSession(session);
1408 }
1409 }
1410
1411 protected AnnouncementsEntry getByC_C_PrevAndNext(Session session,
1412 AnnouncementsEntry announcementsEntry, long classNameId, long classPK,
1413 OrderByComparator orderByComparator, boolean previous) {
1414 StringBundler query = null;
1415
1416 if (orderByComparator != null) {
1417 query = new StringBundler(6 +
1418 (orderByComparator.getOrderByFields().length * 6));
1419 }
1420 else {
1421 query = new StringBundler(3);
1422 }
1423
1424 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1425
1426 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1427
1428 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1429
1430 if (orderByComparator != null) {
1431 String[] orderByFields = orderByComparator.getOrderByFields();
1432
1433 if (orderByFields.length > 0) {
1434 query.append(WHERE_AND);
1435 }
1436
1437 for (int i = 0; i < orderByFields.length; i++) {
1438 query.append(_ORDER_BY_ENTITY_ALIAS);
1439 query.append(orderByFields[i]);
1440
1441 if ((i + 1) < orderByFields.length) {
1442 if (orderByComparator.isAscending() ^ previous) {
1443 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1444 }
1445 else {
1446 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1447 }
1448 }
1449 else {
1450 if (orderByComparator.isAscending() ^ previous) {
1451 query.append(WHERE_GREATER_THAN);
1452 }
1453 else {
1454 query.append(WHERE_LESSER_THAN);
1455 }
1456 }
1457 }
1458
1459 query.append(ORDER_BY_CLAUSE);
1460
1461 for (int i = 0; i < orderByFields.length; i++) {
1462 query.append(_ORDER_BY_ENTITY_ALIAS);
1463 query.append(orderByFields[i]);
1464
1465 if ((i + 1) < orderByFields.length) {
1466 if (orderByComparator.isAscending() ^ previous) {
1467 query.append(ORDER_BY_ASC_HAS_NEXT);
1468 }
1469 else {
1470 query.append(ORDER_BY_DESC_HAS_NEXT);
1471 }
1472 }
1473 else {
1474 if (orderByComparator.isAscending() ^ previous) {
1475 query.append(ORDER_BY_ASC);
1476 }
1477 else {
1478 query.append(ORDER_BY_DESC);
1479 }
1480 }
1481 }
1482 }
1483
1484 else {
1485 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1486 }
1487
1488 String sql = query.toString();
1489
1490 Query q = session.createQuery(sql);
1491
1492 q.setFirstResult(0);
1493 q.setMaxResults(2);
1494
1495 QueryPos qPos = QueryPos.getInstance(q);
1496
1497 qPos.add(classNameId);
1498
1499 qPos.add(classPK);
1500
1501 if (orderByComparator != null) {
1502 Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
1503
1504 for (Object value : values) {
1505 qPos.add(value);
1506 }
1507 }
1508
1509 List<AnnouncementsEntry> list = q.list();
1510
1511 if (list.size() == 2) {
1512 return list.get(1);
1513 }
1514 else {
1515 return null;
1516 }
1517 }
1518
1519
1528 public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1529 boolean alert) throws SystemException {
1530 return findByC_C_A(classNameId, classPK, alert, QueryUtil.ALL_POS,
1531 QueryUtil.ALL_POS, null);
1532 }
1533
1534
1549 public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1550 boolean alert, int start, int end) throws SystemException {
1551 return findByC_C_A(classNameId, classPK, alert, start, end, null);
1552 }
1553
1554
1570 public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1571 boolean alert, int start, int end, OrderByComparator orderByComparator)
1572 throws SystemException {
1573 Object[] finderArgs = new Object[] {
1574 classNameId, classPK, alert,
1575
1576 String.valueOf(start), String.valueOf(end),
1577 String.valueOf(orderByComparator)
1578 };
1579
1580 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_A,
1581 finderArgs, this);
1582
1583 if (list == null) {
1584 Session session = null;
1585
1586 try {
1587 session = openSession();
1588
1589 StringBundler query = null;
1590
1591 if (orderByComparator != null) {
1592 query = new StringBundler(5 +
1593 (orderByComparator.getOrderByFields().length * 3));
1594 }
1595 else {
1596 query = new StringBundler(5);
1597 }
1598
1599 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1600
1601 query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
1602
1603 query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
1604
1605 query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
1606
1607 if (orderByComparator != null) {
1608 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1609 orderByComparator);
1610 }
1611
1612 else {
1613 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1614 }
1615
1616 String sql = query.toString();
1617
1618 Query q = session.createQuery(sql);
1619
1620 QueryPos qPos = QueryPos.getInstance(q);
1621
1622 qPos.add(classNameId);
1623
1624 qPos.add(classPK);
1625
1626 qPos.add(alert);
1627
1628 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1629 getDialect(), start, end);
1630 }
1631 catch (Exception e) {
1632 throw processException(e);
1633 }
1634 finally {
1635 if (list == null) {
1636 list = new ArrayList<AnnouncementsEntry>();
1637 }
1638
1639 cacheResult(list);
1640
1641 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_A,
1642 finderArgs, list);
1643
1644 closeSession(session);
1645 }
1646 }
1647
1648 return list;
1649 }
1650
1651
1666 public AnnouncementsEntry findByC_C_A_First(long classNameId, long classPK,
1667 boolean alert, OrderByComparator orderByComparator)
1668 throws NoSuchEntryException, SystemException {
1669 List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
1670 alert, 0, 1, orderByComparator);
1671
1672 if (list.isEmpty()) {
1673 StringBundler msg = new StringBundler(8);
1674
1675 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1676
1677 msg.append("classNameId=");
1678 msg.append(classNameId);
1679
1680 msg.append(", classPK=");
1681 msg.append(classPK);
1682
1683 msg.append(", alert=");
1684 msg.append(alert);
1685
1686 msg.append(StringPool.CLOSE_CURLY_BRACE);
1687
1688 throw new NoSuchEntryException(msg.toString());
1689 }
1690 else {
1691 return list.get(0);
1692 }
1693 }
1694
1695
1710 public AnnouncementsEntry findByC_C_A_Last(long classNameId, long classPK,
1711 boolean alert, OrderByComparator orderByComparator)
1712 throws NoSuchEntryException, SystemException {
1713 int count = countByC_C_A(classNameId, classPK, alert);
1714
1715 List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
1716 alert, count - 1, count, orderByComparator);
1717
1718 if (list.isEmpty()) {
1719 StringBundler msg = new StringBundler(8);
1720
1721 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1722
1723 msg.append("classNameId=");
1724 msg.append(classNameId);
1725
1726 msg.append(", classPK=");
1727 msg.append(classPK);
1728
1729 msg.append(", alert=");
1730 msg.append(alert);
1731
1732 msg.append(StringPool.CLOSE_CURLY_BRACE);
1733
1734 throw new NoSuchEntryException(msg.toString());
1735 }
1736 else {
1737 return list.get(0);
1738 }
1739 }
1740
1741
1757 public AnnouncementsEntry[] findByC_C_A_PrevAndNext(long entryId,
1758 long classNameId, long classPK, boolean alert,
1759 OrderByComparator orderByComparator)
1760 throws NoSuchEntryException, SystemException {
1761 AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1762
1763 Session session = null;
1764
1765 try {
1766 session = openSession();
1767
1768 AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1769
1770 array[0] = getByC_C_A_PrevAndNext(session, announcementsEntry,
1771 classNameId, classPK, alert, orderByComparator, true);
1772
1773 array[1] = announcementsEntry;
1774
1775 array[2] = getByC_C_A_PrevAndNext(session, announcementsEntry,
1776 classNameId, classPK, alert, orderByComparator, false);
1777
1778 return array;
1779 }
1780 catch (Exception e) {
1781 throw processException(e);
1782 }
1783 finally {
1784 closeSession(session);
1785 }
1786 }
1787
1788 protected AnnouncementsEntry getByC_C_A_PrevAndNext(Session session,
1789 AnnouncementsEntry announcementsEntry, long classNameId, long classPK,
1790 boolean alert, OrderByComparator orderByComparator, boolean previous) {
1791 StringBundler query = null;
1792
1793 if (orderByComparator != null) {
1794 query = new StringBundler(6 +
1795 (orderByComparator.getOrderByFields().length * 6));
1796 }
1797 else {
1798 query = new StringBundler(3);
1799 }
1800
1801 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1802
1803 query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
1804
1805 query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
1806
1807 query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
1808
1809 if (orderByComparator != null) {
1810 String[] orderByFields = orderByComparator.getOrderByFields();
1811
1812 if (orderByFields.length > 0) {
1813 query.append(WHERE_AND);
1814 }
1815
1816 for (int i = 0; i < orderByFields.length; i++) {
1817 query.append(_ORDER_BY_ENTITY_ALIAS);
1818 query.append(orderByFields[i]);
1819
1820 if ((i + 1) < orderByFields.length) {
1821 if (orderByComparator.isAscending() ^ previous) {
1822 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1823 }
1824 else {
1825 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1826 }
1827 }
1828 else {
1829 if (orderByComparator.isAscending() ^ previous) {
1830 query.append(WHERE_GREATER_THAN);
1831 }
1832 else {
1833 query.append(WHERE_LESSER_THAN);
1834 }
1835 }
1836 }
1837
1838 query.append(ORDER_BY_CLAUSE);
1839
1840 for (int i = 0; i < orderByFields.length; i++) {
1841 query.append(_ORDER_BY_ENTITY_ALIAS);
1842 query.append(orderByFields[i]);
1843
1844 if ((i + 1) < orderByFields.length) {
1845 if (orderByComparator.isAscending() ^ previous) {
1846 query.append(ORDER_BY_ASC_HAS_NEXT);
1847 }
1848 else {
1849 query.append(ORDER_BY_DESC_HAS_NEXT);
1850 }
1851 }
1852 else {
1853 if (orderByComparator.isAscending() ^ previous) {
1854 query.append(ORDER_BY_ASC);
1855 }
1856 else {
1857 query.append(ORDER_BY_DESC);
1858 }
1859 }
1860 }
1861 }
1862
1863 else {
1864 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1865 }
1866
1867 String sql = query.toString();
1868
1869 Query q = session.createQuery(sql);
1870
1871 q.setFirstResult(0);
1872 q.setMaxResults(2);
1873
1874 QueryPos qPos = QueryPos.getInstance(q);
1875
1876 qPos.add(classNameId);
1877
1878 qPos.add(classPK);
1879
1880 qPos.add(alert);
1881
1882 if (orderByComparator != null) {
1883 Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
1884
1885 for (Object value : values) {
1886 qPos.add(value);
1887 }
1888 }
1889
1890 List<AnnouncementsEntry> list = q.list();
1891
1892 if (list.size() == 2) {
1893 return list.get(1);
1894 }
1895 else {
1896 return null;
1897 }
1898 }
1899
1900
1906 public List<AnnouncementsEntry> findAll() throws SystemException {
1907 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1908 }
1909
1910
1922 public List<AnnouncementsEntry> findAll(int start, int end)
1923 throws SystemException {
1924 return findAll(start, end, null);
1925 }
1926
1927
1940 public List<AnnouncementsEntry> findAll(int start, int end,
1941 OrderByComparator orderByComparator) throws SystemException {
1942 Object[] finderArgs = new Object[] {
1943 String.valueOf(start), String.valueOf(end),
1944 String.valueOf(orderByComparator)
1945 };
1946
1947 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1948 finderArgs, this);
1949
1950 if (list == null) {
1951 Session session = null;
1952
1953 try {
1954 session = openSession();
1955
1956 StringBundler query = null;
1957 String sql = null;
1958
1959 if (orderByComparator != null) {
1960 query = new StringBundler(2 +
1961 (orderByComparator.getOrderByFields().length * 3));
1962
1963 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY);
1964
1965 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1966 orderByComparator);
1967
1968 sql = query.toString();
1969 }
1970 else {
1971 sql = _SQL_SELECT_ANNOUNCEMENTSENTRY.concat(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1972 }
1973
1974 Query q = session.createQuery(sql);
1975
1976 if (orderByComparator == null) {
1977 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1978 getDialect(), start, end, false);
1979
1980 Collections.sort(list);
1981 }
1982 else {
1983 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1984 getDialect(), start, end);
1985 }
1986 }
1987 catch (Exception e) {
1988 throw processException(e);
1989 }
1990 finally {
1991 if (list == null) {
1992 list = new ArrayList<AnnouncementsEntry>();
1993 }
1994
1995 cacheResult(list);
1996
1997 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1998
1999 closeSession(session);
2000 }
2001 }
2002
2003 return list;
2004 }
2005
2006
2012 public void removeByUuid(String uuid) throws SystemException {
2013 for (AnnouncementsEntry announcementsEntry : findByUuid(uuid)) {
2014 remove(announcementsEntry);
2015 }
2016 }
2017
2018
2024 public void removeByUserId(long userId) throws SystemException {
2025 for (AnnouncementsEntry announcementsEntry : findByUserId(userId)) {
2026 remove(announcementsEntry);
2027 }
2028 }
2029
2030
2037 public void removeByC_C(long classNameId, long classPK)
2038 throws SystemException {
2039 for (AnnouncementsEntry announcementsEntry : findByC_C(classNameId,
2040 classPK)) {
2041 remove(announcementsEntry);
2042 }
2043 }
2044
2045
2053 public void removeByC_C_A(long classNameId, long classPK, boolean alert)
2054 throws SystemException {
2055 for (AnnouncementsEntry announcementsEntry : findByC_C_A(classNameId,
2056 classPK, alert)) {
2057 remove(announcementsEntry);
2058 }
2059 }
2060
2061
2066 public void removeAll() throws SystemException {
2067 for (AnnouncementsEntry announcementsEntry : findAll()) {
2068 remove(announcementsEntry);
2069 }
2070 }
2071
2072
2079 public int countByUuid(String uuid) throws SystemException {
2080 Object[] finderArgs = new Object[] { uuid };
2081
2082 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2083 finderArgs, this);
2084
2085 if (count == null) {
2086 Session session = null;
2087
2088 try {
2089 session = openSession();
2090
2091 StringBundler query = new StringBundler(2);
2092
2093 query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2094
2095 if (uuid == null) {
2096 query.append(_FINDER_COLUMN_UUID_UUID_1);
2097 }
2098 else {
2099 if (uuid.equals(StringPool.BLANK)) {
2100 query.append(_FINDER_COLUMN_UUID_UUID_3);
2101 }
2102 else {
2103 query.append(_FINDER_COLUMN_UUID_UUID_2);
2104 }
2105 }
2106
2107 String sql = query.toString();
2108
2109 Query q = session.createQuery(sql);
2110
2111 QueryPos qPos = QueryPos.getInstance(q);
2112
2113 if (uuid != null) {
2114 qPos.add(uuid);
2115 }
2116
2117 count = (Long)q.uniqueResult();
2118 }
2119 catch (Exception e) {
2120 throw processException(e);
2121 }
2122 finally {
2123 if (count == null) {
2124 count = Long.valueOf(0);
2125 }
2126
2127 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2128 finderArgs, count);
2129
2130 closeSession(session);
2131 }
2132 }
2133
2134 return count.intValue();
2135 }
2136
2137
2144 public int countByUserId(long userId) throws SystemException {
2145 Object[] finderArgs = new Object[] { userId };
2146
2147 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2148 finderArgs, this);
2149
2150 if (count == null) {
2151 Session session = null;
2152
2153 try {
2154 session = openSession();
2155
2156 StringBundler query = new StringBundler(2);
2157
2158 query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2159
2160 query.append(_FINDER_COLUMN_USERID_USERID_2);
2161
2162 String sql = query.toString();
2163
2164 Query q = session.createQuery(sql);
2165
2166 QueryPos qPos = QueryPos.getInstance(q);
2167
2168 qPos.add(userId);
2169
2170 count = (Long)q.uniqueResult();
2171 }
2172 catch (Exception e) {
2173 throw processException(e);
2174 }
2175 finally {
2176 if (count == null) {
2177 count = Long.valueOf(0);
2178 }
2179
2180 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2181 finderArgs, count);
2182
2183 closeSession(session);
2184 }
2185 }
2186
2187 return count.intValue();
2188 }
2189
2190
2198 public int countByC_C(long classNameId, long classPK)
2199 throws SystemException {
2200 Object[] finderArgs = new Object[] { classNameId, classPK };
2201
2202 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
2203 finderArgs, this);
2204
2205 if (count == null) {
2206 Session session = null;
2207
2208 try {
2209 session = openSession();
2210
2211 StringBundler query = new StringBundler(3);
2212
2213 query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2214
2215 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2216
2217 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2218
2219 String sql = query.toString();
2220
2221 Query q = session.createQuery(sql);
2222
2223 QueryPos qPos = QueryPos.getInstance(q);
2224
2225 qPos.add(classNameId);
2226
2227 qPos.add(classPK);
2228
2229 count = (Long)q.uniqueResult();
2230 }
2231 catch (Exception e) {
2232 throw processException(e);
2233 }
2234 finally {
2235 if (count == null) {
2236 count = Long.valueOf(0);
2237 }
2238
2239 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
2240 count);
2241
2242 closeSession(session);
2243 }
2244 }
2245
2246 return count.intValue();
2247 }
2248
2249
2258 public int countByC_C_A(long classNameId, long classPK, boolean alert)
2259 throws SystemException {
2260 Object[] finderArgs = new Object[] { classNameId, classPK, alert };
2261
2262 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_A,
2263 finderArgs, this);
2264
2265 if (count == null) {
2266 Session session = null;
2267
2268 try {
2269 session = openSession();
2270
2271 StringBundler query = new StringBundler(4);
2272
2273 query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2274
2275 query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
2276
2277 query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
2278
2279 query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
2280
2281 String sql = query.toString();
2282
2283 Query q = session.createQuery(sql);
2284
2285 QueryPos qPos = QueryPos.getInstance(q);
2286
2287 qPos.add(classNameId);
2288
2289 qPos.add(classPK);
2290
2291 qPos.add(alert);
2292
2293 count = (Long)q.uniqueResult();
2294 }
2295 catch (Exception e) {
2296 throw processException(e);
2297 }
2298 finally {
2299 if (count == null) {
2300 count = Long.valueOf(0);
2301 }
2302
2303 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_A,
2304 finderArgs, count);
2305
2306 closeSession(session);
2307 }
2308 }
2309
2310 return count.intValue();
2311 }
2312
2313
2319 public int countAll() throws SystemException {
2320 Object[] finderArgs = new Object[0];
2321
2322 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2323 finderArgs, this);
2324
2325 if (count == null) {
2326 Session session = null;
2327
2328 try {
2329 session = openSession();
2330
2331 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSENTRY);
2332
2333 count = (Long)q.uniqueResult();
2334 }
2335 catch (Exception e) {
2336 throw processException(e);
2337 }
2338 finally {
2339 if (count == null) {
2340 count = Long.valueOf(0);
2341 }
2342
2343 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2344 count);
2345
2346 closeSession(session);
2347 }
2348 }
2349
2350 return count.intValue();
2351 }
2352
2353
2356 public void afterPropertiesSet() {
2357 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2358 com.liferay.portal.util.PropsUtil.get(
2359 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsEntry")));
2360
2361 if (listenerClassNames.length > 0) {
2362 try {
2363 List<ModelListener<AnnouncementsEntry>> listenersList = new ArrayList<ModelListener<AnnouncementsEntry>>();
2364
2365 for (String listenerClassName : listenerClassNames) {
2366 listenersList.add((ModelListener<AnnouncementsEntry>)InstanceFactory.newInstance(
2367 listenerClassName));
2368 }
2369
2370 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2371 }
2372 catch (Exception e) {
2373 _log.error(e);
2374 }
2375 }
2376 }
2377
2378 @BeanReference(type = AnnouncementsDeliveryPersistence.class)
2379 protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
2380 @BeanReference(type = AnnouncementsEntryPersistence.class)
2381 protected AnnouncementsEntryPersistence announcementsEntryPersistence;
2382 @BeanReference(type = AnnouncementsFlagPersistence.class)
2383 protected AnnouncementsFlagPersistence announcementsFlagPersistence;
2384 @BeanReference(type = CompanyPersistence.class)
2385 protected CompanyPersistence companyPersistence;
2386 @BeanReference(type = GroupPersistence.class)
2387 protected GroupPersistence groupPersistence;
2388 @BeanReference(type = OrganizationPersistence.class)
2389 protected OrganizationPersistence organizationPersistence;
2390 @BeanReference(type = ResourcePersistence.class)
2391 protected ResourcePersistence resourcePersistence;
2392 @BeanReference(type = RolePersistence.class)
2393 protected RolePersistence rolePersistence;
2394 @BeanReference(type = UserPersistence.class)
2395 protected UserPersistence userPersistence;
2396 @BeanReference(type = UserGroupPersistence.class)
2397 protected UserGroupPersistence userGroupPersistence;
2398 private static final String _SQL_SELECT_ANNOUNCEMENTSENTRY = "SELECT announcementsEntry FROM AnnouncementsEntry announcementsEntry";
2399 private static final String _SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE = "SELECT announcementsEntry FROM AnnouncementsEntry announcementsEntry WHERE ";
2400 private static final String _SQL_COUNT_ANNOUNCEMENTSENTRY = "SELECT COUNT(announcementsEntry) FROM AnnouncementsEntry announcementsEntry";
2401 private static final String _SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE = "SELECT COUNT(announcementsEntry) FROM AnnouncementsEntry announcementsEntry WHERE ";
2402 private static final String _FINDER_COLUMN_UUID_UUID_1 = "announcementsEntry.uuid IS NULL";
2403 private static final String _FINDER_COLUMN_UUID_UUID_2 = "announcementsEntry.uuid = ?";
2404 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(announcementsEntry.uuid IS NULL OR announcementsEntry.uuid = ?)";
2405 private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsEntry.userId = ?";
2406 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "announcementsEntry.classNameId = ? AND ";
2407 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "announcementsEntry.classPK = ?";
2408 private static final String _FINDER_COLUMN_C_C_A_CLASSNAMEID_2 = "announcementsEntry.classNameId = ? AND ";
2409 private static final String _FINDER_COLUMN_C_C_A_CLASSPK_2 = "announcementsEntry.classPK = ? AND ";
2410 private static final String _FINDER_COLUMN_C_C_A_ALERT_2 = "announcementsEntry.alert = ?";
2411 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsEntry.";
2412 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsEntry exists with the primary key ";
2413 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsEntry exists with the key {";
2414 private static Log _log = LogFactoryUtil.getLog(AnnouncementsEntryPersistenceImpl.class);
2415 }