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