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 BatchSessionUtil.delete(session, announcementsEntry);
279 }
280 catch (Exception e) {
281 throw processException(e);
282 }
283 finally {
284 closeSession(session);
285 }
286
287 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
288
289 EntityCacheUtil.removeResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
290 AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey());
291
292 return announcementsEntry;
293 }
294
295 public AnnouncementsEntry updateImpl(
296 com.liferay.portlet.announcements.model.AnnouncementsEntry announcementsEntry,
297 boolean merge) throws SystemException {
298 announcementsEntry = toUnwrappedModel(announcementsEntry);
299
300 if (Validator.isNull(announcementsEntry.getUuid())) {
301 String uuid = PortalUUIDUtil.generate();
302
303 announcementsEntry.setUuid(uuid);
304 }
305
306 Session session = null;
307
308 try {
309 session = openSession();
310
311 BatchSessionUtil.update(session, announcementsEntry, merge);
312
313 announcementsEntry.setNew(false);
314 }
315 catch (Exception e) {
316 throw processException(e);
317 }
318 finally {
319 closeSession(session);
320 }
321
322 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
323
324 EntityCacheUtil.putResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
325 AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey(),
326 announcementsEntry);
327
328 return announcementsEntry;
329 }
330
331 protected AnnouncementsEntry toUnwrappedModel(
332 AnnouncementsEntry announcementsEntry) {
333 if (announcementsEntry instanceof AnnouncementsEntryImpl) {
334 return announcementsEntry;
335 }
336
337 AnnouncementsEntryImpl announcementsEntryImpl = new AnnouncementsEntryImpl();
338
339 announcementsEntryImpl.setNew(announcementsEntry.isNew());
340 announcementsEntryImpl.setPrimaryKey(announcementsEntry.getPrimaryKey());
341
342 announcementsEntryImpl.setUuid(announcementsEntry.getUuid());
343 announcementsEntryImpl.setEntryId(announcementsEntry.getEntryId());
344 announcementsEntryImpl.setCompanyId(announcementsEntry.getCompanyId());
345 announcementsEntryImpl.setUserId(announcementsEntry.getUserId());
346 announcementsEntryImpl.setUserName(announcementsEntry.getUserName());
347 announcementsEntryImpl.setCreateDate(announcementsEntry.getCreateDate());
348 announcementsEntryImpl.setModifiedDate(announcementsEntry.getModifiedDate());
349 announcementsEntryImpl.setClassNameId(announcementsEntry.getClassNameId());
350 announcementsEntryImpl.setClassPK(announcementsEntry.getClassPK());
351 announcementsEntryImpl.setTitle(announcementsEntry.getTitle());
352 announcementsEntryImpl.setContent(announcementsEntry.getContent());
353 announcementsEntryImpl.setUrl(announcementsEntry.getUrl());
354 announcementsEntryImpl.setType(announcementsEntry.getType());
355 announcementsEntryImpl.setDisplayDate(announcementsEntry.getDisplayDate());
356 announcementsEntryImpl.setExpirationDate(announcementsEntry.getExpirationDate());
357 announcementsEntryImpl.setPriority(announcementsEntry.getPriority());
358 announcementsEntryImpl.setAlert(announcementsEntry.isAlert());
359
360 return announcementsEntryImpl;
361 }
362
363
371 public AnnouncementsEntry findByPrimaryKey(Serializable primaryKey)
372 throws NoSuchModelException, SystemException {
373 return findByPrimaryKey(((Long)primaryKey).longValue());
374 }
375
376
384 public AnnouncementsEntry findByPrimaryKey(long entryId)
385 throws NoSuchEntryException, SystemException {
386 AnnouncementsEntry announcementsEntry = fetchByPrimaryKey(entryId);
387
388 if (announcementsEntry == null) {
389 if (_log.isWarnEnabled()) {
390 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
391 }
392
393 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
394 entryId);
395 }
396
397 return announcementsEntry;
398 }
399
400
407 public AnnouncementsEntry fetchByPrimaryKey(Serializable primaryKey)
408 throws SystemException {
409 return fetchByPrimaryKey(((Long)primaryKey).longValue());
410 }
411
412
419 public AnnouncementsEntry fetchByPrimaryKey(long entryId)
420 throws SystemException {
421 AnnouncementsEntry announcementsEntry = (AnnouncementsEntry)EntityCacheUtil.getResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
422 AnnouncementsEntryImpl.class, entryId, this);
423
424 if (announcementsEntry == null) {
425 Session session = null;
426
427 try {
428 session = openSession();
429
430 announcementsEntry = (AnnouncementsEntry)session.get(AnnouncementsEntryImpl.class,
431 new Long(entryId));
432 }
433 catch (Exception e) {
434 throw processException(e);
435 }
436 finally {
437 if (announcementsEntry != null) {
438 cacheResult(announcementsEntry);
439 }
440
441 closeSession(session);
442 }
443 }
444
445 return announcementsEntry;
446 }
447
448
455 public List<AnnouncementsEntry> findByUuid(String uuid)
456 throws SystemException {
457 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
458 }
459
460
473 public List<AnnouncementsEntry> findByUuid(String uuid, int start, int end)
474 throws SystemException {
475 return findByUuid(uuid, start, end, null);
476 }
477
478
492 public List<AnnouncementsEntry> findByUuid(String uuid, int start, int end,
493 OrderByComparator orderByComparator) throws SystemException {
494 Object[] finderArgs = new Object[] {
495 uuid,
496
497 String.valueOf(start), String.valueOf(end),
498 String.valueOf(orderByComparator)
499 };
500
501 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
502 finderArgs, this);
503
504 if (list == null) {
505 Session session = null;
506
507 try {
508 session = openSession();
509
510 StringBundler query = null;
511
512 if (orderByComparator != null) {
513 query = new StringBundler(3 +
514 (orderByComparator.getOrderByFields().length * 3));
515 }
516 else {
517 query = new StringBundler(3);
518 }
519
520 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
521
522 if (uuid == null) {
523 query.append(_FINDER_COLUMN_UUID_UUID_1);
524 }
525 else {
526 if (uuid.equals(StringPool.BLANK)) {
527 query.append(_FINDER_COLUMN_UUID_UUID_3);
528 }
529 else {
530 query.append(_FINDER_COLUMN_UUID_UUID_2);
531 }
532 }
533
534 if (orderByComparator != null) {
535 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
536 orderByComparator);
537 }
538
539 else {
540 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
541 }
542
543 String sql = query.toString();
544
545 Query q = session.createQuery(sql);
546
547 QueryPos qPos = QueryPos.getInstance(q);
548
549 if (uuid != null) {
550 qPos.add(uuid);
551 }
552
553 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
554 getDialect(), start, end);
555 }
556 catch (Exception e) {
557 throw processException(e);
558 }
559 finally {
560 if (list == null) {
561 list = new ArrayList<AnnouncementsEntry>();
562 }
563
564 cacheResult(list);
565
566 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
567 list);
568
569 closeSession(session);
570 }
571 }
572
573 return list;
574 }
575
576
589 public AnnouncementsEntry findByUuid_First(String uuid,
590 OrderByComparator orderByComparator)
591 throws NoSuchEntryException, SystemException {
592 List<AnnouncementsEntry> list = findByUuid(uuid, 0, 1, orderByComparator);
593
594 if (list.isEmpty()) {
595 StringBundler msg = new StringBundler(4);
596
597 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
598
599 msg.append("uuid=");
600 msg.append(uuid);
601
602 msg.append(StringPool.CLOSE_CURLY_BRACE);
603
604 throw new NoSuchEntryException(msg.toString());
605 }
606 else {
607 return list.get(0);
608 }
609 }
610
611
624 public AnnouncementsEntry findByUuid_Last(String uuid,
625 OrderByComparator orderByComparator)
626 throws NoSuchEntryException, SystemException {
627 int count = countByUuid(uuid);
628
629 List<AnnouncementsEntry> list = findByUuid(uuid, count - 1, count,
630 orderByComparator);
631
632 if (list.isEmpty()) {
633 StringBundler msg = new StringBundler(4);
634
635 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
636
637 msg.append("uuid=");
638 msg.append(uuid);
639
640 msg.append(StringPool.CLOSE_CURLY_BRACE);
641
642 throw new NoSuchEntryException(msg.toString());
643 }
644 else {
645 return list.get(0);
646 }
647 }
648
649
663 public AnnouncementsEntry[] findByUuid_PrevAndNext(long entryId,
664 String uuid, OrderByComparator orderByComparator)
665 throws NoSuchEntryException, SystemException {
666 AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
667
668 Session session = null;
669
670 try {
671 session = openSession();
672
673 AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
674
675 array[0] = getByUuid_PrevAndNext(session, announcementsEntry, uuid,
676 orderByComparator, true);
677
678 array[1] = announcementsEntry;
679
680 array[2] = getByUuid_PrevAndNext(session, announcementsEntry, uuid,
681 orderByComparator, false);
682
683 return array;
684 }
685 catch (Exception e) {
686 throw processException(e);
687 }
688 finally {
689 closeSession(session);
690 }
691 }
692
693 protected AnnouncementsEntry getByUuid_PrevAndNext(Session session,
694 AnnouncementsEntry announcementsEntry, String uuid,
695 OrderByComparator orderByComparator, boolean previous) {
696 StringBundler query = null;
697
698 if (orderByComparator != null) {
699 query = new StringBundler(6 +
700 (orderByComparator.getOrderByFields().length * 6));
701 }
702 else {
703 query = new StringBundler(3);
704 }
705
706 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
707
708 if (uuid == null) {
709 query.append(_FINDER_COLUMN_UUID_UUID_1);
710 }
711 else {
712 if (uuid.equals(StringPool.BLANK)) {
713 query.append(_FINDER_COLUMN_UUID_UUID_3);
714 }
715 else {
716 query.append(_FINDER_COLUMN_UUID_UUID_2);
717 }
718 }
719
720 if (orderByComparator != null) {
721 String[] orderByFields = orderByComparator.getOrderByFields();
722
723 if (orderByFields.length > 0) {
724 query.append(WHERE_AND);
725 }
726
727 for (int i = 0; i < orderByFields.length; i++) {
728 query.append(_ORDER_BY_ENTITY_ALIAS);
729 query.append(orderByFields[i]);
730
731 if ((i + 1) < orderByFields.length) {
732 if (orderByComparator.isAscending() ^ previous) {
733 query.append(WHERE_GREATER_THAN_HAS_NEXT);
734 }
735 else {
736 query.append(WHERE_LESSER_THAN_HAS_NEXT);
737 }
738 }
739 else {
740 if (orderByComparator.isAscending() ^ previous) {
741 query.append(WHERE_GREATER_THAN);
742 }
743 else {
744 query.append(WHERE_LESSER_THAN);
745 }
746 }
747 }
748
749 query.append(ORDER_BY_CLAUSE);
750
751 for (int i = 0; i < orderByFields.length; i++) {
752 query.append(_ORDER_BY_ENTITY_ALIAS);
753 query.append(orderByFields[i]);
754
755 if ((i + 1) < orderByFields.length) {
756 if (orderByComparator.isAscending() ^ previous) {
757 query.append(ORDER_BY_ASC_HAS_NEXT);
758 }
759 else {
760 query.append(ORDER_BY_DESC_HAS_NEXT);
761 }
762 }
763 else {
764 if (orderByComparator.isAscending() ^ previous) {
765 query.append(ORDER_BY_ASC);
766 }
767 else {
768 query.append(ORDER_BY_DESC);
769 }
770 }
771 }
772 }
773
774 else {
775 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
776 }
777
778 String sql = query.toString();
779
780 Query q = session.createQuery(sql);
781
782 q.setFirstResult(0);
783 q.setMaxResults(2);
784
785 QueryPos qPos = QueryPos.getInstance(q);
786
787 if (uuid != null) {
788 qPos.add(uuid);
789 }
790
791 if (orderByComparator != null) {
792 Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
793
794 for (Object value : values) {
795 qPos.add(value);
796 }
797 }
798
799 List<AnnouncementsEntry> list = q.list();
800
801 if (list.size() == 2) {
802 return list.get(1);
803 }
804 else {
805 return null;
806 }
807 }
808
809
816 public List<AnnouncementsEntry> findByUserId(long userId)
817 throws SystemException {
818 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
819 }
820
821
834 public List<AnnouncementsEntry> findByUserId(long userId, int start, int end)
835 throws SystemException {
836 return findByUserId(userId, start, end, null);
837 }
838
839
853 public List<AnnouncementsEntry> findByUserId(long userId, int start,
854 int end, OrderByComparator orderByComparator) throws SystemException {
855 Object[] finderArgs = new Object[] {
856 userId,
857
858 String.valueOf(start), String.valueOf(end),
859 String.valueOf(orderByComparator)
860 };
861
862 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
863 finderArgs, this);
864
865 if (list == null) {
866 Session session = null;
867
868 try {
869 session = openSession();
870
871 StringBundler query = null;
872
873 if (orderByComparator != null) {
874 query = new StringBundler(3 +
875 (orderByComparator.getOrderByFields().length * 3));
876 }
877 else {
878 query = new StringBundler(3);
879 }
880
881 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
882
883 query.append(_FINDER_COLUMN_USERID_USERID_2);
884
885 if (orderByComparator != null) {
886 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
887 orderByComparator);
888 }
889
890 else {
891 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
892 }
893
894 String sql = query.toString();
895
896 Query q = session.createQuery(sql);
897
898 QueryPos qPos = QueryPos.getInstance(q);
899
900 qPos.add(userId);
901
902 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
903 getDialect(), start, end);
904 }
905 catch (Exception e) {
906 throw processException(e);
907 }
908 finally {
909 if (list == null) {
910 list = new ArrayList<AnnouncementsEntry>();
911 }
912
913 cacheResult(list);
914
915 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
916 finderArgs, list);
917
918 closeSession(session);
919 }
920 }
921
922 return list;
923 }
924
925
938 public AnnouncementsEntry findByUserId_First(long userId,
939 OrderByComparator orderByComparator)
940 throws NoSuchEntryException, SystemException {
941 List<AnnouncementsEntry> list = findByUserId(userId, 0, 1,
942 orderByComparator);
943
944 if (list.isEmpty()) {
945 StringBundler msg = new StringBundler(4);
946
947 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
948
949 msg.append("userId=");
950 msg.append(userId);
951
952 msg.append(StringPool.CLOSE_CURLY_BRACE);
953
954 throw new NoSuchEntryException(msg.toString());
955 }
956 else {
957 return list.get(0);
958 }
959 }
960
961
974 public AnnouncementsEntry findByUserId_Last(long userId,
975 OrderByComparator orderByComparator)
976 throws NoSuchEntryException, SystemException {
977 int count = countByUserId(userId);
978
979 List<AnnouncementsEntry> list = findByUserId(userId, count - 1, count,
980 orderByComparator);
981
982 if (list.isEmpty()) {
983 StringBundler msg = new StringBundler(4);
984
985 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
986
987 msg.append("userId=");
988 msg.append(userId);
989
990 msg.append(StringPool.CLOSE_CURLY_BRACE);
991
992 throw new NoSuchEntryException(msg.toString());
993 }
994 else {
995 return list.get(0);
996 }
997 }
998
999
1013 public AnnouncementsEntry[] findByUserId_PrevAndNext(long entryId,
1014 long userId, OrderByComparator orderByComparator)
1015 throws NoSuchEntryException, SystemException {
1016 AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1017
1018 Session session = null;
1019
1020 try {
1021 session = openSession();
1022
1023 AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1024
1025 array[0] = getByUserId_PrevAndNext(session, announcementsEntry,
1026 userId, orderByComparator, true);
1027
1028 array[1] = announcementsEntry;
1029
1030 array[2] = getByUserId_PrevAndNext(session, announcementsEntry,
1031 userId, orderByComparator, false);
1032
1033 return array;
1034 }
1035 catch (Exception e) {
1036 throw processException(e);
1037 }
1038 finally {
1039 closeSession(session);
1040 }
1041 }
1042
1043 protected AnnouncementsEntry getByUserId_PrevAndNext(Session session,
1044 AnnouncementsEntry announcementsEntry, long userId,
1045 OrderByComparator orderByComparator, boolean previous) {
1046 StringBundler query = null;
1047
1048 if (orderByComparator != null) {
1049 query = new StringBundler(6 +
1050 (orderByComparator.getOrderByFields().length * 6));
1051 }
1052 else {
1053 query = new StringBundler(3);
1054 }
1055
1056 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1057
1058 query.append(_FINDER_COLUMN_USERID_USERID_2);
1059
1060 if (orderByComparator != null) {
1061 String[] orderByFields = orderByComparator.getOrderByFields();
1062
1063 if (orderByFields.length > 0) {
1064 query.append(WHERE_AND);
1065 }
1066
1067 for (int i = 0; i < orderByFields.length; i++) {
1068 query.append(_ORDER_BY_ENTITY_ALIAS);
1069 query.append(orderByFields[i]);
1070
1071 if ((i + 1) < orderByFields.length) {
1072 if (orderByComparator.isAscending() ^ previous) {
1073 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1074 }
1075 else {
1076 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1077 }
1078 }
1079 else {
1080 if (orderByComparator.isAscending() ^ previous) {
1081 query.append(WHERE_GREATER_THAN);
1082 }
1083 else {
1084 query.append(WHERE_LESSER_THAN);
1085 }
1086 }
1087 }
1088
1089 query.append(ORDER_BY_CLAUSE);
1090
1091 for (int i = 0; i < orderByFields.length; i++) {
1092 query.append(_ORDER_BY_ENTITY_ALIAS);
1093 query.append(orderByFields[i]);
1094
1095 if ((i + 1) < orderByFields.length) {
1096 if (orderByComparator.isAscending() ^ previous) {
1097 query.append(ORDER_BY_ASC_HAS_NEXT);
1098 }
1099 else {
1100 query.append(ORDER_BY_DESC_HAS_NEXT);
1101 }
1102 }
1103 else {
1104 if (orderByComparator.isAscending() ^ previous) {
1105 query.append(ORDER_BY_ASC);
1106 }
1107 else {
1108 query.append(ORDER_BY_DESC);
1109 }
1110 }
1111 }
1112 }
1113
1114 else {
1115 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1116 }
1117
1118 String sql = query.toString();
1119
1120 Query q = session.createQuery(sql);
1121
1122 q.setFirstResult(0);
1123 q.setMaxResults(2);
1124
1125 QueryPos qPos = QueryPos.getInstance(q);
1126
1127 qPos.add(userId);
1128
1129 if (orderByComparator != null) {
1130 Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
1131
1132 for (Object value : values) {
1133 qPos.add(value);
1134 }
1135 }
1136
1137 List<AnnouncementsEntry> list = q.list();
1138
1139 if (list.size() == 2) {
1140 return list.get(1);
1141 }
1142 else {
1143 return null;
1144 }
1145 }
1146
1147
1155 public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK)
1156 throws SystemException {
1157 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
1158 QueryUtil.ALL_POS, null);
1159 }
1160
1161
1175 public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
1176 int start, int end) throws SystemException {
1177 return findByC_C(classNameId, classPK, start, end, null);
1178 }
1179
1180
1195 public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
1196 int start, int end, OrderByComparator orderByComparator)
1197 throws SystemException {
1198 Object[] finderArgs = new Object[] {
1199 classNameId, classPK,
1200
1201 String.valueOf(start), String.valueOf(end),
1202 String.valueOf(orderByComparator)
1203 };
1204
1205 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
1206 finderArgs, this);
1207
1208 if (list == null) {
1209 Session session = null;
1210
1211 try {
1212 session = openSession();
1213
1214 StringBundler query = null;
1215
1216 if (orderByComparator != null) {
1217 query = new StringBundler(4 +
1218 (orderByComparator.getOrderByFields().length * 3));
1219 }
1220 else {
1221 query = new StringBundler(4);
1222 }
1223
1224 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1225
1226 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1227
1228 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1229
1230 if (orderByComparator != null) {
1231 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1232 orderByComparator);
1233 }
1234
1235 else {
1236 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1237 }
1238
1239 String sql = query.toString();
1240
1241 Query q = session.createQuery(sql);
1242
1243 QueryPos qPos = QueryPos.getInstance(q);
1244
1245 qPos.add(classNameId);
1246
1247 qPos.add(classPK);
1248
1249 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1250 getDialect(), start, end);
1251 }
1252 catch (Exception e) {
1253 throw processException(e);
1254 }
1255 finally {
1256 if (list == null) {
1257 list = new ArrayList<AnnouncementsEntry>();
1258 }
1259
1260 cacheResult(list);
1261
1262 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
1263 list);
1264
1265 closeSession(session);
1266 }
1267 }
1268
1269 return list;
1270 }
1271
1272
1286 public AnnouncementsEntry findByC_C_First(long classNameId, long classPK,
1287 OrderByComparator orderByComparator)
1288 throws NoSuchEntryException, SystemException {
1289 List<AnnouncementsEntry> list = findByC_C(classNameId, classPK, 0, 1,
1290 orderByComparator);
1291
1292 if (list.isEmpty()) {
1293 StringBundler msg = new StringBundler(6);
1294
1295 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1296
1297 msg.append("classNameId=");
1298 msg.append(classNameId);
1299
1300 msg.append(", classPK=");
1301 msg.append(classPK);
1302
1303 msg.append(StringPool.CLOSE_CURLY_BRACE);
1304
1305 throw new NoSuchEntryException(msg.toString());
1306 }
1307 else {
1308 return list.get(0);
1309 }
1310 }
1311
1312
1326 public AnnouncementsEntry findByC_C_Last(long classNameId, long classPK,
1327 OrderByComparator orderByComparator)
1328 throws NoSuchEntryException, SystemException {
1329 int count = countByC_C(classNameId, classPK);
1330
1331 List<AnnouncementsEntry> list = findByC_C(classNameId, classPK,
1332 count - 1, count, orderByComparator);
1333
1334 if (list.isEmpty()) {
1335 StringBundler msg = new StringBundler(6);
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(StringPool.CLOSE_CURLY_BRACE);
1346
1347 throw new NoSuchEntryException(msg.toString());
1348 }
1349 else {
1350 return list.get(0);
1351 }
1352 }
1353
1354
1369 public AnnouncementsEntry[] findByC_C_PrevAndNext(long entryId,
1370 long classNameId, long classPK, OrderByComparator orderByComparator)
1371 throws NoSuchEntryException, SystemException {
1372 AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1373
1374 Session session = null;
1375
1376 try {
1377 session = openSession();
1378
1379 AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1380
1381 array[0] = getByC_C_PrevAndNext(session, announcementsEntry,
1382 classNameId, classPK, orderByComparator, true);
1383
1384 array[1] = announcementsEntry;
1385
1386 array[2] = getByC_C_PrevAndNext(session, announcementsEntry,
1387 classNameId, classPK, orderByComparator, false);
1388
1389 return array;
1390 }
1391 catch (Exception e) {
1392 throw processException(e);
1393 }
1394 finally {
1395 closeSession(session);
1396 }
1397 }
1398
1399 protected AnnouncementsEntry getByC_C_PrevAndNext(Session session,
1400 AnnouncementsEntry announcementsEntry, long classNameId, long classPK,
1401 OrderByComparator orderByComparator, boolean previous) {
1402 StringBundler query = null;
1403
1404 if (orderByComparator != null) {
1405 query = new StringBundler(6 +
1406 (orderByComparator.getOrderByFields().length * 6));
1407 }
1408 else {
1409 query = new StringBundler(3);
1410 }
1411
1412 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1413
1414 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1415
1416 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1417
1418 if (orderByComparator != null) {
1419 String[] orderByFields = orderByComparator.getOrderByFields();
1420
1421 if (orderByFields.length > 0) {
1422 query.append(WHERE_AND);
1423 }
1424
1425 for (int i = 0; i < orderByFields.length; i++) {
1426 query.append(_ORDER_BY_ENTITY_ALIAS);
1427 query.append(orderByFields[i]);
1428
1429 if ((i + 1) < orderByFields.length) {
1430 if (orderByComparator.isAscending() ^ previous) {
1431 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1432 }
1433 else {
1434 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1435 }
1436 }
1437 else {
1438 if (orderByComparator.isAscending() ^ previous) {
1439 query.append(WHERE_GREATER_THAN);
1440 }
1441 else {
1442 query.append(WHERE_LESSER_THAN);
1443 }
1444 }
1445 }
1446
1447 query.append(ORDER_BY_CLAUSE);
1448
1449 for (int i = 0; i < orderByFields.length; i++) {
1450 query.append(_ORDER_BY_ENTITY_ALIAS);
1451 query.append(orderByFields[i]);
1452
1453 if ((i + 1) < orderByFields.length) {
1454 if (orderByComparator.isAscending() ^ previous) {
1455 query.append(ORDER_BY_ASC_HAS_NEXT);
1456 }
1457 else {
1458 query.append(ORDER_BY_DESC_HAS_NEXT);
1459 }
1460 }
1461 else {
1462 if (orderByComparator.isAscending() ^ previous) {
1463 query.append(ORDER_BY_ASC);
1464 }
1465 else {
1466 query.append(ORDER_BY_DESC);
1467 }
1468 }
1469 }
1470 }
1471
1472 else {
1473 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1474 }
1475
1476 String sql = query.toString();
1477
1478 Query q = session.createQuery(sql);
1479
1480 q.setFirstResult(0);
1481 q.setMaxResults(2);
1482
1483 QueryPos qPos = QueryPos.getInstance(q);
1484
1485 qPos.add(classNameId);
1486
1487 qPos.add(classPK);
1488
1489 if (orderByComparator != null) {
1490 Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
1491
1492 for (Object value : values) {
1493 qPos.add(value);
1494 }
1495 }
1496
1497 List<AnnouncementsEntry> list = q.list();
1498
1499 if (list.size() == 2) {
1500 return list.get(1);
1501 }
1502 else {
1503 return null;
1504 }
1505 }
1506
1507
1516 public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1517 boolean alert) throws SystemException {
1518 return findByC_C_A(classNameId, classPK, alert, QueryUtil.ALL_POS,
1519 QueryUtil.ALL_POS, null);
1520 }
1521
1522
1537 public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1538 boolean alert, int start, int end) throws SystemException {
1539 return findByC_C_A(classNameId, classPK, alert, start, end, null);
1540 }
1541
1542
1558 public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1559 boolean alert, int start, int end, OrderByComparator orderByComparator)
1560 throws SystemException {
1561 Object[] finderArgs = new Object[] {
1562 classNameId, classPK, alert,
1563
1564 String.valueOf(start), String.valueOf(end),
1565 String.valueOf(orderByComparator)
1566 };
1567
1568 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_A,
1569 finderArgs, this);
1570
1571 if (list == null) {
1572 Session session = null;
1573
1574 try {
1575 session = openSession();
1576
1577 StringBundler query = null;
1578
1579 if (orderByComparator != null) {
1580 query = new StringBundler(5 +
1581 (orderByComparator.getOrderByFields().length * 3));
1582 }
1583 else {
1584 query = new StringBundler(5);
1585 }
1586
1587 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1588
1589 query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
1590
1591 query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
1592
1593 query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
1594
1595 if (orderByComparator != null) {
1596 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1597 orderByComparator);
1598 }
1599
1600 else {
1601 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1602 }
1603
1604 String sql = query.toString();
1605
1606 Query q = session.createQuery(sql);
1607
1608 QueryPos qPos = QueryPos.getInstance(q);
1609
1610 qPos.add(classNameId);
1611
1612 qPos.add(classPK);
1613
1614 qPos.add(alert);
1615
1616 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1617 getDialect(), start, end);
1618 }
1619 catch (Exception e) {
1620 throw processException(e);
1621 }
1622 finally {
1623 if (list == null) {
1624 list = new ArrayList<AnnouncementsEntry>();
1625 }
1626
1627 cacheResult(list);
1628
1629 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_A,
1630 finderArgs, list);
1631
1632 closeSession(session);
1633 }
1634 }
1635
1636 return list;
1637 }
1638
1639
1654 public AnnouncementsEntry findByC_C_A_First(long classNameId, long classPK,
1655 boolean alert, OrderByComparator orderByComparator)
1656 throws NoSuchEntryException, SystemException {
1657 List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
1658 alert, 0, 1, orderByComparator);
1659
1660 if (list.isEmpty()) {
1661 StringBundler msg = new StringBundler(8);
1662
1663 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1664
1665 msg.append("classNameId=");
1666 msg.append(classNameId);
1667
1668 msg.append(", classPK=");
1669 msg.append(classPK);
1670
1671 msg.append(", alert=");
1672 msg.append(alert);
1673
1674 msg.append(StringPool.CLOSE_CURLY_BRACE);
1675
1676 throw new NoSuchEntryException(msg.toString());
1677 }
1678 else {
1679 return list.get(0);
1680 }
1681 }
1682
1683
1698 public AnnouncementsEntry findByC_C_A_Last(long classNameId, long classPK,
1699 boolean alert, OrderByComparator orderByComparator)
1700 throws NoSuchEntryException, SystemException {
1701 int count = countByC_C_A(classNameId, classPK, alert);
1702
1703 List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
1704 alert, count - 1, count, orderByComparator);
1705
1706 if (list.isEmpty()) {
1707 StringBundler msg = new StringBundler(8);
1708
1709 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1710
1711 msg.append("classNameId=");
1712 msg.append(classNameId);
1713
1714 msg.append(", classPK=");
1715 msg.append(classPK);
1716
1717 msg.append(", alert=");
1718 msg.append(alert);
1719
1720 msg.append(StringPool.CLOSE_CURLY_BRACE);
1721
1722 throw new NoSuchEntryException(msg.toString());
1723 }
1724 else {
1725 return list.get(0);
1726 }
1727 }
1728
1729
1745 public AnnouncementsEntry[] findByC_C_A_PrevAndNext(long entryId,
1746 long classNameId, long classPK, boolean alert,
1747 OrderByComparator orderByComparator)
1748 throws NoSuchEntryException, SystemException {
1749 AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1750
1751 Session session = null;
1752
1753 try {
1754 session = openSession();
1755
1756 AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1757
1758 array[0] = getByC_C_A_PrevAndNext(session, announcementsEntry,
1759 classNameId, classPK, alert, orderByComparator, true);
1760
1761 array[1] = announcementsEntry;
1762
1763 array[2] = getByC_C_A_PrevAndNext(session, announcementsEntry,
1764 classNameId, classPK, alert, orderByComparator, false);
1765
1766 return array;
1767 }
1768 catch (Exception e) {
1769 throw processException(e);
1770 }
1771 finally {
1772 closeSession(session);
1773 }
1774 }
1775
1776 protected AnnouncementsEntry getByC_C_A_PrevAndNext(Session session,
1777 AnnouncementsEntry announcementsEntry, long classNameId, long classPK,
1778 boolean alert, OrderByComparator orderByComparator, boolean previous) {
1779 StringBundler query = null;
1780
1781 if (orderByComparator != null) {
1782 query = new StringBundler(6 +
1783 (orderByComparator.getOrderByFields().length * 6));
1784 }
1785 else {
1786 query = new StringBundler(3);
1787 }
1788
1789 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1790
1791 query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
1792
1793 query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
1794
1795 query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
1796
1797 if (orderByComparator != null) {
1798 String[] orderByFields = orderByComparator.getOrderByFields();
1799
1800 if (orderByFields.length > 0) {
1801 query.append(WHERE_AND);
1802 }
1803
1804 for (int i = 0; i < orderByFields.length; i++) {
1805 query.append(_ORDER_BY_ENTITY_ALIAS);
1806 query.append(orderByFields[i]);
1807
1808 if ((i + 1) < orderByFields.length) {
1809 if (orderByComparator.isAscending() ^ previous) {
1810 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1811 }
1812 else {
1813 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1814 }
1815 }
1816 else {
1817 if (orderByComparator.isAscending() ^ previous) {
1818 query.append(WHERE_GREATER_THAN);
1819 }
1820 else {
1821 query.append(WHERE_LESSER_THAN);
1822 }
1823 }
1824 }
1825
1826 query.append(ORDER_BY_CLAUSE);
1827
1828 for (int i = 0; i < orderByFields.length; i++) {
1829 query.append(_ORDER_BY_ENTITY_ALIAS);
1830 query.append(orderByFields[i]);
1831
1832 if ((i + 1) < orderByFields.length) {
1833 if (orderByComparator.isAscending() ^ previous) {
1834 query.append(ORDER_BY_ASC_HAS_NEXT);
1835 }
1836 else {
1837 query.append(ORDER_BY_DESC_HAS_NEXT);
1838 }
1839 }
1840 else {
1841 if (orderByComparator.isAscending() ^ previous) {
1842 query.append(ORDER_BY_ASC);
1843 }
1844 else {
1845 query.append(ORDER_BY_DESC);
1846 }
1847 }
1848 }
1849 }
1850
1851 else {
1852 query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1853 }
1854
1855 String sql = query.toString();
1856
1857 Query q = session.createQuery(sql);
1858
1859 q.setFirstResult(0);
1860 q.setMaxResults(2);
1861
1862 QueryPos qPos = QueryPos.getInstance(q);
1863
1864 qPos.add(classNameId);
1865
1866 qPos.add(classPK);
1867
1868 qPos.add(alert);
1869
1870 if (orderByComparator != null) {
1871 Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
1872
1873 for (Object value : values) {
1874 qPos.add(value);
1875 }
1876 }
1877
1878 List<AnnouncementsEntry> list = q.list();
1879
1880 if (list.size() == 2) {
1881 return list.get(1);
1882 }
1883 else {
1884 return null;
1885 }
1886 }
1887
1888
1894 public List<AnnouncementsEntry> findAll() throws SystemException {
1895 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1896 }
1897
1898
1910 public List<AnnouncementsEntry> findAll(int start, int end)
1911 throws SystemException {
1912 return findAll(start, end, null);
1913 }
1914
1915
1928 public List<AnnouncementsEntry> findAll(int start, int end,
1929 OrderByComparator orderByComparator) throws SystemException {
1930 Object[] finderArgs = new Object[] {
1931 String.valueOf(start), String.valueOf(end),
1932 String.valueOf(orderByComparator)
1933 };
1934
1935 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1936 finderArgs, this);
1937
1938 if (list == null) {
1939 Session session = null;
1940
1941 try {
1942 session = openSession();
1943
1944 StringBundler query = null;
1945 String sql = null;
1946
1947 if (orderByComparator != null) {
1948 query = new StringBundler(2 +
1949 (orderByComparator.getOrderByFields().length * 3));
1950
1951 query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY);
1952
1953 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1954 orderByComparator);
1955
1956 sql = query.toString();
1957 }
1958 else {
1959 sql = _SQL_SELECT_ANNOUNCEMENTSENTRY.concat(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1960 }
1961
1962 Query q = session.createQuery(sql);
1963
1964 if (orderByComparator == null) {
1965 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1966 getDialect(), start, end, false);
1967
1968 Collections.sort(list);
1969 }
1970 else {
1971 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1972 getDialect(), start, end);
1973 }
1974 }
1975 catch (Exception e) {
1976 throw processException(e);
1977 }
1978 finally {
1979 if (list == null) {
1980 list = new ArrayList<AnnouncementsEntry>();
1981 }
1982
1983 cacheResult(list);
1984
1985 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1986
1987 closeSession(session);
1988 }
1989 }
1990
1991 return list;
1992 }
1993
1994
2000 public void removeByUuid(String uuid) throws SystemException {
2001 for (AnnouncementsEntry announcementsEntry : findByUuid(uuid)) {
2002 remove(announcementsEntry);
2003 }
2004 }
2005
2006
2012 public void removeByUserId(long userId) throws SystemException {
2013 for (AnnouncementsEntry announcementsEntry : findByUserId(userId)) {
2014 remove(announcementsEntry);
2015 }
2016 }
2017
2018
2025 public void removeByC_C(long classNameId, long classPK)
2026 throws SystemException {
2027 for (AnnouncementsEntry announcementsEntry : findByC_C(classNameId,
2028 classPK)) {
2029 remove(announcementsEntry);
2030 }
2031 }
2032
2033
2041 public void removeByC_C_A(long classNameId, long classPK, boolean alert)
2042 throws SystemException {
2043 for (AnnouncementsEntry announcementsEntry : findByC_C_A(classNameId,
2044 classPK, alert)) {
2045 remove(announcementsEntry);
2046 }
2047 }
2048
2049
2054 public void removeAll() throws SystemException {
2055 for (AnnouncementsEntry announcementsEntry : findAll()) {
2056 remove(announcementsEntry);
2057 }
2058 }
2059
2060
2067 public int countByUuid(String uuid) throws SystemException {
2068 Object[] finderArgs = new Object[] { uuid };
2069
2070 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2071 finderArgs, this);
2072
2073 if (count == null) {
2074 Session session = null;
2075
2076 try {
2077 session = openSession();
2078
2079 StringBundler query = new StringBundler(2);
2080
2081 query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2082
2083 if (uuid == null) {
2084 query.append(_FINDER_COLUMN_UUID_UUID_1);
2085 }
2086 else {
2087 if (uuid.equals(StringPool.BLANK)) {
2088 query.append(_FINDER_COLUMN_UUID_UUID_3);
2089 }
2090 else {
2091 query.append(_FINDER_COLUMN_UUID_UUID_2);
2092 }
2093 }
2094
2095 String sql = query.toString();
2096
2097 Query q = session.createQuery(sql);
2098
2099 QueryPos qPos = QueryPos.getInstance(q);
2100
2101 if (uuid != null) {
2102 qPos.add(uuid);
2103 }
2104
2105 count = (Long)q.uniqueResult();
2106 }
2107 catch (Exception e) {
2108 throw processException(e);
2109 }
2110 finally {
2111 if (count == null) {
2112 count = Long.valueOf(0);
2113 }
2114
2115 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2116 finderArgs, count);
2117
2118 closeSession(session);
2119 }
2120 }
2121
2122 return count.intValue();
2123 }
2124
2125
2132 public int countByUserId(long userId) throws SystemException {
2133 Object[] finderArgs = new Object[] { userId };
2134
2135 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2136 finderArgs, this);
2137
2138 if (count == null) {
2139 Session session = null;
2140
2141 try {
2142 session = openSession();
2143
2144 StringBundler query = new StringBundler(2);
2145
2146 query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2147
2148 query.append(_FINDER_COLUMN_USERID_USERID_2);
2149
2150 String sql = query.toString();
2151
2152 Query q = session.createQuery(sql);
2153
2154 QueryPos qPos = QueryPos.getInstance(q);
2155
2156 qPos.add(userId);
2157
2158 count = (Long)q.uniqueResult();
2159 }
2160 catch (Exception e) {
2161 throw processException(e);
2162 }
2163 finally {
2164 if (count == null) {
2165 count = Long.valueOf(0);
2166 }
2167
2168 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2169 finderArgs, count);
2170
2171 closeSession(session);
2172 }
2173 }
2174
2175 return count.intValue();
2176 }
2177
2178
2186 public int countByC_C(long classNameId, long classPK)
2187 throws SystemException {
2188 Object[] finderArgs = new Object[] { classNameId, classPK };
2189
2190 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
2191 finderArgs, this);
2192
2193 if (count == null) {
2194 Session session = null;
2195
2196 try {
2197 session = openSession();
2198
2199 StringBundler query = new StringBundler(3);
2200
2201 query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2202
2203 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2204
2205 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2206
2207 String sql = query.toString();
2208
2209 Query q = session.createQuery(sql);
2210
2211 QueryPos qPos = QueryPos.getInstance(q);
2212
2213 qPos.add(classNameId);
2214
2215 qPos.add(classPK);
2216
2217 count = (Long)q.uniqueResult();
2218 }
2219 catch (Exception e) {
2220 throw processException(e);
2221 }
2222 finally {
2223 if (count == null) {
2224 count = Long.valueOf(0);
2225 }
2226
2227 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
2228 count);
2229
2230 closeSession(session);
2231 }
2232 }
2233
2234 return count.intValue();
2235 }
2236
2237
2246 public int countByC_C_A(long classNameId, long classPK, boolean alert)
2247 throws SystemException {
2248 Object[] finderArgs = new Object[] { classNameId, classPK, alert };
2249
2250 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_A,
2251 finderArgs, this);
2252
2253 if (count == null) {
2254 Session session = null;
2255
2256 try {
2257 session = openSession();
2258
2259 StringBundler query = new StringBundler(4);
2260
2261 query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2262
2263 query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
2264
2265 query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
2266
2267 query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
2268
2269 String sql = query.toString();
2270
2271 Query q = session.createQuery(sql);
2272
2273 QueryPos qPos = QueryPos.getInstance(q);
2274
2275 qPos.add(classNameId);
2276
2277 qPos.add(classPK);
2278
2279 qPos.add(alert);
2280
2281 count = (Long)q.uniqueResult();
2282 }
2283 catch (Exception e) {
2284 throw processException(e);
2285 }
2286 finally {
2287 if (count == null) {
2288 count = Long.valueOf(0);
2289 }
2290
2291 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_A,
2292 finderArgs, count);
2293
2294 closeSession(session);
2295 }
2296 }
2297
2298 return count.intValue();
2299 }
2300
2301
2307 public int countAll() throws SystemException {
2308 Object[] finderArgs = new Object[0];
2309
2310 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2311 finderArgs, this);
2312
2313 if (count == null) {
2314 Session session = null;
2315
2316 try {
2317 session = openSession();
2318
2319 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSENTRY);
2320
2321 count = (Long)q.uniqueResult();
2322 }
2323 catch (Exception e) {
2324 throw processException(e);
2325 }
2326 finally {
2327 if (count == null) {
2328 count = Long.valueOf(0);
2329 }
2330
2331 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2332 count);
2333
2334 closeSession(session);
2335 }
2336 }
2337
2338 return count.intValue();
2339 }
2340
2341
2344 public void afterPropertiesSet() {
2345 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2346 com.liferay.portal.util.PropsUtil.get(
2347 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsEntry")));
2348
2349 if (listenerClassNames.length > 0) {
2350 try {
2351 List<ModelListener<AnnouncementsEntry>> listenersList = new ArrayList<ModelListener<AnnouncementsEntry>>();
2352
2353 for (String listenerClassName : listenerClassNames) {
2354 listenersList.add((ModelListener<AnnouncementsEntry>)InstanceFactory.newInstance(
2355 listenerClassName));
2356 }
2357
2358 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2359 }
2360 catch (Exception e) {
2361 _log.error(e);
2362 }
2363 }
2364 }
2365
2366 public void destroy() {
2367 EntityCacheUtil.removeCache(AnnouncementsEntryImpl.class.getName());
2368 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2369 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2370 }
2371
2372 @BeanReference(type = AnnouncementsDeliveryPersistence.class)
2373 protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
2374 @BeanReference(type = AnnouncementsEntryPersistence.class)
2375 protected AnnouncementsEntryPersistence announcementsEntryPersistence;
2376 @BeanReference(type = AnnouncementsFlagPersistence.class)
2377 protected AnnouncementsFlagPersistence announcementsFlagPersistence;
2378 @BeanReference(type = CompanyPersistence.class)
2379 protected CompanyPersistence companyPersistence;
2380 @BeanReference(type = GroupPersistence.class)
2381 protected GroupPersistence groupPersistence;
2382 @BeanReference(type = OrganizationPersistence.class)
2383 protected OrganizationPersistence organizationPersistence;
2384 @BeanReference(type = ResourcePersistence.class)
2385 protected ResourcePersistence resourcePersistence;
2386 @BeanReference(type = RolePersistence.class)
2387 protected RolePersistence rolePersistence;
2388 @BeanReference(type = UserPersistence.class)
2389 protected UserPersistence userPersistence;
2390 @BeanReference(type = UserGroupPersistence.class)
2391 protected UserGroupPersistence userGroupPersistence;
2392 private static final String _SQL_SELECT_ANNOUNCEMENTSENTRY = "SELECT announcementsEntry FROM AnnouncementsEntry announcementsEntry";
2393 private static final String _SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE = "SELECT announcementsEntry FROM AnnouncementsEntry announcementsEntry WHERE ";
2394 private static final String _SQL_COUNT_ANNOUNCEMENTSENTRY = "SELECT COUNT(announcementsEntry) FROM AnnouncementsEntry announcementsEntry";
2395 private static final String _SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE = "SELECT COUNT(announcementsEntry) FROM AnnouncementsEntry announcementsEntry WHERE ";
2396 private static final String _FINDER_COLUMN_UUID_UUID_1 = "announcementsEntry.uuid IS NULL";
2397 private static final String _FINDER_COLUMN_UUID_UUID_2 = "announcementsEntry.uuid = ?";
2398 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(announcementsEntry.uuid IS NULL OR announcementsEntry.uuid = ?)";
2399 private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsEntry.userId = ?";
2400 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "announcementsEntry.classNameId = ? AND ";
2401 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "announcementsEntry.classPK = ?";
2402 private static final String _FINDER_COLUMN_C_C_A_CLASSNAMEID_2 = "announcementsEntry.classNameId = ? AND ";
2403 private static final String _FINDER_COLUMN_C_C_A_CLASSPK_2 = "announcementsEntry.classPK = ? AND ";
2404 private static final String _FINDER_COLUMN_C_C_A_ALERT_2 = "announcementsEntry.alert = ?";
2405 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsEntry.";
2406 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsEntry exists with the primary key ";
2407 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsEntry exists with the key {";
2408 private static Log _log = LogFactoryUtil.getLog(AnnouncementsEntryPersistenceImpl.class);
2409 }