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                     "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
423 
424                 if (uuid == null) {
425                     query.append("uuid_ IS NULL");
426                 }
427                 else {
428                     query.append("uuid_ = ?");
429                 }
430 
431                 query.append(" ");
432 
433                 query.append("ORDER BY ");
434 
435                 query.append("priority ASC, ");
436                 query.append("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                     "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
494 
495                 if (uuid == null) {
496                     query.append("uuid_ IS NULL");
497                 }
498                 else {
499                     query.append("uuid_ = ?");
500                 }
501 
502                 query.append(" ");
503 
504                 if (obc != null) {
505                     query.append("ORDER BY ");
506                     query.append(obc.getOrderBy());
507                 }
508 
509                 else {
510                     query.append("ORDER BY ");
511 
512                     query.append("priority ASC, ");
513                     query.append("modifiedDate ASC");
514                 }
515 
516                 Query q = session.createQuery(query.toString());
517 
518                 QueryPos qPos = QueryPos.getInstance(q);
519 
520                 if (uuid != null) {
521                     qPos.add(uuid);
522                 }
523 
524                 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
525                         getDialect(), start, end);
526             }
527             catch (Exception e) {
528                 throw processException(e);
529             }
530             finally {
531                 if (list == null) {
532                     list = new ArrayList<AnnouncementsEntry>();
533                 }
534 
535                 cacheResult(list);
536 
537                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
538                     finderArgs, list);
539 
540                 closeSession(session);
541             }
542         }
543 
544         return list;
545     }
546 
547     public AnnouncementsEntry findByUuid_First(String uuid,
548         OrderByComparator obc) throws NoSuchEntryException, SystemException {
549         List<AnnouncementsEntry> list = findByUuid(uuid, 0, 1, obc);
550 
551         if (list.isEmpty()) {
552             StringBuilder msg = new StringBuilder();
553 
554             msg.append("No AnnouncementsEntry exists with the key {");
555 
556             msg.append("uuid=" + uuid);
557 
558             msg.append(StringPool.CLOSE_CURLY_BRACE);
559 
560             throw new NoSuchEntryException(msg.toString());
561         }
562         else {
563             return list.get(0);
564         }
565     }
566 
567     public AnnouncementsEntry findByUuid_Last(String uuid, OrderByComparator obc)
568         throws NoSuchEntryException, SystemException {
569         int count = countByUuid(uuid);
570 
571         List<AnnouncementsEntry> list = findByUuid(uuid, count - 1, count, obc);
572 
573         if (list.isEmpty()) {
574             StringBuilder msg = new StringBuilder();
575 
576             msg.append("No AnnouncementsEntry exists with the key {");
577 
578             msg.append("uuid=" + uuid);
579 
580             msg.append(StringPool.CLOSE_CURLY_BRACE);
581 
582             throw new NoSuchEntryException(msg.toString());
583         }
584         else {
585             return list.get(0);
586         }
587     }
588 
589     public AnnouncementsEntry[] findByUuid_PrevAndNext(long entryId,
590         String uuid, OrderByComparator obc)
591         throws NoSuchEntryException, SystemException {
592         AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
593 
594         int count = countByUuid(uuid);
595 
596         Session session = null;
597 
598         try {
599             session = openSession();
600 
601             StringBuilder query = new StringBuilder();
602 
603             query.append(
604                 "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
605 
606             if (uuid == null) {
607                 query.append("uuid_ IS NULL");
608             }
609             else {
610                 query.append("uuid_ = ?");
611             }
612 
613             query.append(" ");
614 
615             if (obc != null) {
616                 query.append("ORDER BY ");
617                 query.append(obc.getOrderBy());
618             }
619 
620             else {
621                 query.append("ORDER BY ");
622 
623                 query.append("priority ASC, ");
624                 query.append("modifiedDate ASC");
625             }
626 
627             Query q = session.createQuery(query.toString());
628 
629             QueryPos qPos = QueryPos.getInstance(q);
630 
631             if (uuid != null) {
632                 qPos.add(uuid);
633             }
634 
635             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
636                     announcementsEntry);
637 
638             AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
639 
640             array[0] = (AnnouncementsEntry)objArray[0];
641             array[1] = (AnnouncementsEntry)objArray[1];
642             array[2] = (AnnouncementsEntry)objArray[2];
643 
644             return array;
645         }
646         catch (Exception e) {
647             throw processException(e);
648         }
649         finally {
650             closeSession(session);
651         }
652     }
653 
654     public List<AnnouncementsEntry> findByUserId(long userId)
655         throws SystemException {
656         Object[] finderArgs = new Object[] { new Long(userId) };
657 
658         List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
659                 finderArgs, this);
660 
661         if (list == null) {
662             Session session = null;
663 
664             try {
665                 session = openSession();
666 
667                 StringBuilder query = new StringBuilder();
668 
669                 query.append(
670                     "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
671 
672                 query.append("userId = ?");
673 
674                 query.append(" ");
675 
676                 query.append("ORDER BY ");
677 
678                 query.append("priority ASC, ");
679                 query.append("modifiedDate ASC");
680 
681                 Query q = session.createQuery(query.toString());
682 
683                 QueryPos qPos = QueryPos.getInstance(q);
684 
685                 qPos.add(userId);
686 
687                 list = q.list();
688             }
689             catch (Exception e) {
690                 throw processException(e);
691             }
692             finally {
693                 if (list == null) {
694                     list = new ArrayList<AnnouncementsEntry>();
695                 }
696 
697                 cacheResult(list);
698 
699                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
700                     finderArgs, list);
701 
702                 closeSession(session);
703             }
704         }
705 
706         return list;
707     }
708 
709     public List<AnnouncementsEntry> findByUserId(long userId, int start, int end)
710         throws SystemException {
711         return findByUserId(userId, start, end, null);
712     }
713 
714     public List<AnnouncementsEntry> findByUserId(long userId, int start,
715         int end, OrderByComparator obc) throws SystemException {
716         Object[] finderArgs = new Object[] {
717                 new Long(userId),
718                 
719                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
720             };
721 
722         List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
723                 finderArgs, this);
724 
725         if (list == null) {
726             Session session = null;
727 
728             try {
729                 session = openSession();
730 
731                 StringBuilder query = new StringBuilder();
732 
733                 query.append(
734                     "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
735 
736                 query.append("userId = ?");
737 
738                 query.append(" ");
739 
740                 if (obc != null) {
741                     query.append("ORDER BY ");
742                     query.append(obc.getOrderBy());
743                 }
744 
745                 else {
746                     query.append("ORDER BY ");
747 
748                     query.append("priority ASC, ");
749                     query.append("modifiedDate ASC");
750                 }
751 
752                 Query q = session.createQuery(query.toString());
753 
754                 QueryPos qPos = QueryPos.getInstance(q);
755 
756                 qPos.add(userId);
757 
758                 list = (List<AnnouncementsEntry>)QueryUtil.list(q,
759                         getDialect(), start, end);
760             }
761             catch (Exception e) {
762                 throw processException(e);
763             }
764             finally {
765                 if (list == null) {
766                     list = new ArrayList<AnnouncementsEntry>();
767                 }
768 
769                 cacheResult(list);
770 
771                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
772                     finderArgs, list);
773 
774                 closeSession(session);
775             }
776         }
777 
778         return list;
779     }
780 
781     public AnnouncementsEntry findByUserId_First(long userId,
782         OrderByComparator obc) throws NoSuchEntryException, SystemException {
783         List<AnnouncementsEntry> list = findByUserId(userId, 0, 1, obc);
784 
785         if (list.isEmpty()) {
786             StringBuilder msg = new StringBuilder();
787 
788             msg.append("No AnnouncementsEntry exists with the key {");
789 
790             msg.append("userId=" + userId);
791 
792             msg.append(StringPool.CLOSE_CURLY_BRACE);
793 
794             throw new NoSuchEntryException(msg.toString());
795         }
796         else {
797             return list.get(0);
798         }
799     }
800 
801     public AnnouncementsEntry findByUserId_Last(long userId,
802         OrderByComparator obc) throws NoSuchEntryException, SystemException {
803         int count = countByUserId(userId);
804 
805         List<AnnouncementsEntry> list = findByUserId(userId, count - 1, count,
806                 obc);
807 
808         if (list.isEmpty()) {
809             StringBuilder msg = new StringBuilder();
810 
811             msg.append("No AnnouncementsEntry exists with the key {");
812 
813             msg.append("userId=" + userId);
814 
815             msg.append(StringPool.CLOSE_CURLY_BRACE);
816 
817             throw new NoSuchEntryException(msg.toString());
818         }
819         else {
820             return list.get(0);
821         }
822     }
823 
824     public AnnouncementsEntry[] findByUserId_PrevAndNext(long entryId,
825         long userId, OrderByComparator obc)
826         throws NoSuchEntryException, SystemException {
827         AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
828 
829         int count = countByUserId(userId);
830 
831         Session session = null;
832 
833         try {
834             session = openSession();
835 
836             StringBuilder query = new StringBuilder();
837 
838             query.append(
839                 "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
840 
841             query.append("userId = ?");
842 
843             query.append(" ");
844 
845             if (obc != null) {
846                 query.append("ORDER BY ");
847                 query.append(obc.getOrderBy());
848             }
849 
850             else {
851                 query.append("ORDER BY ");
852 
853                 query.append("priority ASC, ");
854                 query.append("modifiedDate ASC");
855             }
856 
857             Query q = session.createQuery(query.toString());
858 
859             QueryPos qPos = QueryPos.getInstance(q);
860 
861             qPos.add(userId);
862 
863             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
864                     announcementsEntry);
865 
866             AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
867 
868             array[0] = (AnnouncementsEntry)objArray[0];
869             array[1] = (AnnouncementsEntry)objArray[1];
870             array[2] = (AnnouncementsEntry)objArray[2];
871 
872             return array;
873         }
874         catch (Exception e) {
875             throw processException(e);
876         }
877         finally {
878             closeSession(session);
879         }
880     }
881 
882     public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK)
883         throws SystemException {
884         Object[] finderArgs = new Object[] {
885                 new Long(classNameId), new Long(classPK)
886             };
887 
888         List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
889                 finderArgs, this);
890 
891         if (list == null) {
892             Session session = null;
893 
894             try {
895                 session = openSession();
896 
897                 StringBuilder query = new StringBuilder();
898 
899                 query.append(
900                     "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
901 
902                 query.append("classNameId = ?");
903 
904                 query.append(" AND ");
905 
906                 query.append("classPK = ?");
907 
908                 query.append(" ");
909 
910                 query.append("ORDER BY ");
911 
912                 query.append("priority ASC, ");
913                 query.append("modifiedDate ASC");
914 
915                 Query q = session.createQuery(query.toString());
916 
917                 QueryPos qPos = QueryPos.getInstance(q);
918 
919                 qPos.add(classNameId);
920 
921                 qPos.add(classPK);
922 
923                 list = q.list();
924             }
925             catch (Exception e) {
926                 throw processException(e);
927             }
928             finally {
929                 if (list == null) {
930                     list = new ArrayList<AnnouncementsEntry>();
931                 }
932 
933                 cacheResult(list);
934 
935                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
936                     list);
937 
938                 closeSession(session);
939             }
940         }
941 
942         return list;
943     }
944 
945     public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
946         int start, int end) throws SystemException {
947         return findByC_C(classNameId, classPK, start, end, null);
948     }
949 
950     public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
951         int start, int end, OrderByComparator obc) throws SystemException {
952         Object[] finderArgs = new Object[] {
953                 new Long(classNameId), new Long(classPK),
954                 
955                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
956             };
957 
958         List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C,
959                 finderArgs, this);
960 
961         if (list == null) {
962             Session session = null;
963 
964             try {
965                 session = openSession();
966 
967                 StringBuilder query = new StringBuilder();
968 
969                 query.append(
970                     "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
971 
972                 query.append("classNameId = ?");
973 
974                 query.append(" AND ");
975 
976                 query.append("classPK = ?");
977 
978                 query.append(" ");
979 
980                 if (obc != null) {
981                     query.append("ORDER BY ");
982                     query.append(obc.getOrderBy());
983                 }
984 
985                 else {
986                     query.append("ORDER BY ");
987 
988                     query.append("priority ASC, ");
989                     query.append("modifiedDate ASC");
990                 }
991 
992                 Query q = session.createQuery(query.toString());
993 
994                 QueryPos qPos = QueryPos.getInstance(q);
995 
996                 qPos.add(classNameId);
997 
998                 qPos.add(classPK);
999 
1000                list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1001                        getDialect(), start, end);
1002            }
1003            catch (Exception e) {
1004                throw processException(e);
1005            }
1006            finally {
1007                if (list == null) {
1008                    list = new ArrayList<AnnouncementsEntry>();
1009                }
1010
1011                cacheResult(list);
1012
1013                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C,
1014                    finderArgs, list);
1015
1016                closeSession(session);
1017            }
1018        }
1019
1020        return list;
1021    }
1022
1023    public AnnouncementsEntry findByC_C_First(long classNameId, long classPK,
1024        OrderByComparator obc) throws NoSuchEntryException, SystemException {
1025        List<AnnouncementsEntry> list = findByC_C(classNameId, classPK, 0, 1,
1026                obc);
1027
1028        if (list.isEmpty()) {
1029            StringBuilder msg = new StringBuilder();
1030
1031            msg.append("No AnnouncementsEntry exists with the key {");
1032
1033            msg.append("classNameId=" + classNameId);
1034
1035            msg.append(", ");
1036            msg.append("classPK=" + classPK);
1037
1038            msg.append(StringPool.CLOSE_CURLY_BRACE);
1039
1040            throw new NoSuchEntryException(msg.toString());
1041        }
1042        else {
1043            return list.get(0);
1044        }
1045    }
1046
1047    public AnnouncementsEntry findByC_C_Last(long classNameId, long classPK,
1048        OrderByComparator obc) throws NoSuchEntryException, SystemException {
1049        int count = countByC_C(classNameId, classPK);
1050
1051        List<AnnouncementsEntry> list = findByC_C(classNameId, classPK,
1052                count - 1, count, obc);
1053
1054        if (list.isEmpty()) {
1055            StringBuilder msg = new StringBuilder();
1056
1057            msg.append("No AnnouncementsEntry exists with the key {");
1058
1059            msg.append("classNameId=" + classNameId);
1060
1061            msg.append(", ");
1062            msg.append("classPK=" + classPK);
1063
1064            msg.append(StringPool.CLOSE_CURLY_BRACE);
1065
1066            throw new NoSuchEntryException(msg.toString());
1067        }
1068        else {
1069            return list.get(0);
1070        }
1071    }
1072
1073    public AnnouncementsEntry[] findByC_C_PrevAndNext(long entryId,
1074        long classNameId, long classPK, OrderByComparator obc)
1075        throws NoSuchEntryException, SystemException {
1076        AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1077
1078        int count = countByC_C(classNameId, classPK);
1079
1080        Session session = null;
1081
1082        try {
1083            session = openSession();
1084
1085            StringBuilder query = new StringBuilder();
1086
1087            query.append(
1088                "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1089
1090            query.append("classNameId = ?");
1091
1092            query.append(" AND ");
1093
1094            query.append("classPK = ?");
1095
1096            query.append(" ");
1097
1098            if (obc != null) {
1099                query.append("ORDER BY ");
1100                query.append(obc.getOrderBy());
1101            }
1102
1103            else {
1104                query.append("ORDER BY ");
1105
1106                query.append("priority ASC, ");
1107                query.append("modifiedDate ASC");
1108            }
1109
1110            Query q = session.createQuery(query.toString());
1111
1112            QueryPos qPos = QueryPos.getInstance(q);
1113
1114            qPos.add(classNameId);
1115
1116            qPos.add(classPK);
1117
1118            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1119                    announcementsEntry);
1120
1121            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1122
1123            array[0] = (AnnouncementsEntry)objArray[0];
1124            array[1] = (AnnouncementsEntry)objArray[1];
1125            array[2] = (AnnouncementsEntry)objArray[2];
1126
1127            return array;
1128        }
1129        catch (Exception e) {
1130            throw processException(e);
1131        }
1132        finally {
1133            closeSession(session);
1134        }
1135    }
1136
1137    public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1138        boolean alert) throws SystemException {
1139        Object[] finderArgs = new Object[] {
1140                new Long(classNameId), new Long(classPK), Boolean.valueOf(alert)
1141            };
1142
1143        List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_A,
1144                finderArgs, this);
1145
1146        if (list == null) {
1147            Session session = null;
1148
1149            try {
1150                session = openSession();
1151
1152                StringBuilder query = new StringBuilder();
1153
1154                query.append(
1155                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1156
1157                query.append("classNameId = ?");
1158
1159                query.append(" AND ");
1160
1161                query.append("classPK = ?");
1162
1163                query.append(" AND ");
1164
1165                query.append("alert = ?");
1166
1167                query.append(" ");
1168
1169                query.append("ORDER BY ");
1170
1171                query.append("priority ASC, ");
1172                query.append("modifiedDate ASC");
1173
1174                Query q = session.createQuery(query.toString());
1175
1176                QueryPos qPos = QueryPos.getInstance(q);
1177
1178                qPos.add(classNameId);
1179
1180                qPos.add(classPK);
1181
1182                qPos.add(alert);
1183
1184                list = q.list();
1185            }
1186            catch (Exception e) {
1187                throw processException(e);
1188            }
1189            finally {
1190                if (list == null) {
1191                    list = new ArrayList<AnnouncementsEntry>();
1192                }
1193
1194                cacheResult(list);
1195
1196                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_A,
1197                    finderArgs, list);
1198
1199                closeSession(session);
1200            }
1201        }
1202
1203        return list;
1204    }
1205
1206    public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1207        boolean alert, int start, int end) throws SystemException {
1208        return findByC_C_A(classNameId, classPK, alert, start, end, null);
1209    }
1210
1211    public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1212        boolean alert, int start, int end, OrderByComparator obc)
1213        throws SystemException {
1214        Object[] finderArgs = new Object[] {
1215                new Long(classNameId), new Long(classPK), Boolean.valueOf(alert),
1216                
1217                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1218            };
1219
1220        List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C_A,
1221                finderArgs, this);
1222
1223        if (list == null) {
1224            Session session = null;
1225
1226            try {
1227                session = openSession();
1228
1229                StringBuilder query = new StringBuilder();
1230
1231                query.append(
1232                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1233
1234                query.append("classNameId = ?");
1235
1236                query.append(" AND ");
1237
1238                query.append("classPK = ?");
1239
1240                query.append(" AND ");
1241
1242                query.append("alert = ?");
1243
1244                query.append(" ");
1245
1246                if (obc != null) {
1247                    query.append("ORDER BY ");
1248                    query.append(obc.getOrderBy());
1249                }
1250
1251                else {
1252                    query.append("ORDER BY ");
1253
1254                    query.append("priority ASC, ");
1255                    query.append("modifiedDate ASC");
1256                }
1257
1258                Query q = session.createQuery(query.toString());
1259
1260                QueryPos qPos = QueryPos.getInstance(q);
1261
1262                qPos.add(classNameId);
1263
1264                qPos.add(classPK);
1265
1266                qPos.add(alert);
1267
1268                list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1269                        getDialect(), start, end);
1270            }
1271            catch (Exception e) {
1272                throw processException(e);
1273            }
1274            finally {
1275                if (list == null) {
1276                    list = new ArrayList<AnnouncementsEntry>();
1277                }
1278
1279                cacheResult(list);
1280
1281                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C_A,
1282                    finderArgs, list);
1283
1284                closeSession(session);
1285            }
1286        }
1287
1288        return list;
1289    }
1290
1291    public AnnouncementsEntry findByC_C_A_First(long classNameId, long classPK,
1292        boolean alert, OrderByComparator obc)
1293        throws NoSuchEntryException, SystemException {
1294        List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
1295                alert, 0, 1, obc);
1296
1297        if (list.isEmpty()) {
1298            StringBuilder msg = new StringBuilder();
1299
1300            msg.append("No AnnouncementsEntry exists with the key {");
1301
1302            msg.append("classNameId=" + classNameId);
1303
1304            msg.append(", ");
1305            msg.append("classPK=" + classPK);
1306
1307            msg.append(", ");
1308            msg.append("alert=" + alert);
1309
1310            msg.append(StringPool.CLOSE_CURLY_BRACE);
1311
1312            throw new NoSuchEntryException(msg.toString());
1313        }
1314        else {
1315            return list.get(0);
1316        }
1317    }
1318
1319    public AnnouncementsEntry findByC_C_A_Last(long classNameId, long classPK,
1320        boolean alert, OrderByComparator obc)
1321        throws NoSuchEntryException, SystemException {
1322        int count = countByC_C_A(classNameId, classPK, alert);
1323
1324        List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
1325                alert, count - 1, count, obc);
1326
1327        if (list.isEmpty()) {
1328            StringBuilder msg = new StringBuilder();
1329
1330            msg.append("No AnnouncementsEntry exists with the key {");
1331
1332            msg.append("classNameId=" + classNameId);
1333
1334            msg.append(", ");
1335            msg.append("classPK=" + classPK);
1336
1337            msg.append(", ");
1338            msg.append("alert=" + alert);
1339
1340            msg.append(StringPool.CLOSE_CURLY_BRACE);
1341
1342            throw new NoSuchEntryException(msg.toString());
1343        }
1344        else {
1345            return list.get(0);
1346        }
1347    }
1348
1349    public AnnouncementsEntry[] findByC_C_A_PrevAndNext(long entryId,
1350        long classNameId, long classPK, boolean alert, OrderByComparator obc)
1351        throws NoSuchEntryException, SystemException {
1352        AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1353
1354        int count = countByC_C_A(classNameId, classPK, alert);
1355
1356        Session session = null;
1357
1358        try {
1359            session = openSession();
1360
1361            StringBuilder query = new StringBuilder();
1362
1363            query.append(
1364                "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1365
1366            query.append("classNameId = ?");
1367
1368            query.append(" AND ");
1369
1370            query.append("classPK = ?");
1371
1372            query.append(" AND ");
1373
1374            query.append("alert = ?");
1375
1376            query.append(" ");
1377
1378            if (obc != null) {
1379                query.append("ORDER BY ");
1380                query.append(obc.getOrderBy());
1381            }
1382
1383            else {
1384                query.append("ORDER BY ");
1385
1386                query.append("priority ASC, ");
1387                query.append("modifiedDate ASC");
1388            }
1389
1390            Query q = session.createQuery(query.toString());
1391
1392            QueryPos qPos = QueryPos.getInstance(q);
1393
1394            qPos.add(classNameId);
1395
1396            qPos.add(classPK);
1397
1398            qPos.add(alert);
1399
1400            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1401                    announcementsEntry);
1402
1403            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1404
1405            array[0] = (AnnouncementsEntry)objArray[0];
1406            array[1] = (AnnouncementsEntry)objArray[1];
1407            array[2] = (AnnouncementsEntry)objArray[2];
1408
1409            return array;
1410        }
1411        catch (Exception e) {
1412            throw processException(e);
1413        }
1414        finally {
1415            closeSession(session);
1416        }
1417    }
1418
1419    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1420        throws SystemException {
1421        Session session = null;
1422
1423        try {
1424            session = openSession();
1425
1426            dynamicQuery.compile(session);
1427
1428            return dynamicQuery.list();
1429        }
1430        catch (Exception e) {
1431            throw processException(e);
1432        }
1433        finally {
1434            closeSession(session);
1435        }
1436    }
1437
1438    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1439        int start, int end) throws SystemException {
1440        Session session = null;
1441
1442        try {
1443            session = openSession();
1444
1445            dynamicQuery.setLimit(start, end);
1446
1447            dynamicQuery.compile(session);
1448
1449            return dynamicQuery.list();
1450        }
1451        catch (Exception e) {
1452            throw processException(e);
1453        }
1454        finally {
1455            closeSession(session);
1456        }
1457    }
1458
1459    public List<AnnouncementsEntry> findAll() throws SystemException {
1460        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1461    }
1462
1463    public List<AnnouncementsEntry> findAll(int start, int end)
1464        throws SystemException {
1465        return findAll(start, end, null);
1466    }
1467
1468    public List<AnnouncementsEntry> findAll(int start, int end,
1469        OrderByComparator obc) throws SystemException {
1470        Object[] finderArgs = new Object[] {
1471                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1472            };
1473
1474        List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1475                finderArgs, this);
1476
1477        if (list == null) {
1478            Session session = null;
1479
1480            try {
1481                session = openSession();
1482
1483                StringBuilder query = new StringBuilder();
1484
1485                query.append(
1486                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry ");
1487
1488                if (obc != null) {
1489                    query.append("ORDER BY ");
1490                    query.append(obc.getOrderBy());
1491                }
1492
1493                else {
1494                    query.append("ORDER BY ");
1495
1496                    query.append("priority ASC, ");
1497                    query.append("modifiedDate ASC");
1498                }
1499
1500                Query q = session.createQuery(query.toString());
1501
1502                if (obc == null) {
1503                    list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1504                            getDialect(), start, end, false);
1505
1506                    Collections.sort(list);
1507                }
1508                else {
1509                    list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1510                            getDialect(), start, end);
1511                }
1512            }
1513            catch (Exception e) {
1514                throw processException(e);
1515            }
1516            finally {
1517                if (list == null) {
1518                    list = new ArrayList<AnnouncementsEntry>();
1519                }
1520
1521                cacheResult(list);
1522
1523                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1524
1525                closeSession(session);
1526            }
1527        }
1528
1529        return list;
1530    }
1531
1532    public void removeByUuid(String uuid) throws SystemException {
1533        for (AnnouncementsEntry announcementsEntry : findByUuid(uuid)) {
1534            remove(announcementsEntry);
1535        }
1536    }
1537
1538    public void removeByUserId(long userId) throws SystemException {
1539        for (AnnouncementsEntry announcementsEntry : findByUserId(userId)) {
1540            remove(announcementsEntry);
1541        }
1542    }
1543
1544    public void removeByC_C(long classNameId, long classPK)
1545        throws SystemException {
1546        for (AnnouncementsEntry announcementsEntry : findByC_C(classNameId,
1547                classPK)) {
1548            remove(announcementsEntry);
1549        }
1550    }
1551
1552    public void removeByC_C_A(long classNameId, long classPK, boolean alert)
1553        throws SystemException {
1554        for (AnnouncementsEntry announcementsEntry : findByC_C_A(classNameId,
1555                classPK, alert)) {
1556            remove(announcementsEntry);
1557        }
1558    }
1559
1560    public void removeAll() throws SystemException {
1561        for (AnnouncementsEntry announcementsEntry : findAll()) {
1562            remove(announcementsEntry);
1563        }
1564    }
1565
1566    public int countByUuid(String uuid) throws SystemException {
1567        Object[] finderArgs = new Object[] { uuid };
1568
1569        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1570                finderArgs, this);
1571
1572        if (count == null) {
1573            Session session = null;
1574
1575            try {
1576                session = openSession();
1577
1578                StringBuilder query = new StringBuilder();
1579
1580                query.append("SELECT COUNT(*) ");
1581                query.append(
1582                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1583
1584                if (uuid == null) {
1585                    query.append("uuid_ IS NULL");
1586                }
1587                else {
1588                    query.append("uuid_ = ?");
1589                }
1590
1591                query.append(" ");
1592
1593                Query q = session.createQuery(query.toString());
1594
1595                QueryPos qPos = QueryPos.getInstance(q);
1596
1597                if (uuid != null) {
1598                    qPos.add(uuid);
1599                }
1600
1601                count = (Long)q.uniqueResult();
1602            }
1603            catch (Exception e) {
1604                throw processException(e);
1605            }
1606            finally {
1607                if (count == null) {
1608                    count = Long.valueOf(0);
1609                }
1610
1611                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1612                    finderArgs, count);
1613
1614                closeSession(session);
1615            }
1616        }
1617
1618        return count.intValue();
1619    }
1620
1621    public int countByUserId(long userId) throws SystemException {
1622        Object[] finderArgs = new Object[] { new Long(userId) };
1623
1624        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1625                finderArgs, this);
1626
1627        if (count == null) {
1628            Session session = null;
1629
1630            try {
1631                session = openSession();
1632
1633                StringBuilder query = new StringBuilder();
1634
1635                query.append("SELECT COUNT(*) ");
1636                query.append(
1637                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1638
1639                query.append("userId = ?");
1640
1641                query.append(" ");
1642
1643                Query q = session.createQuery(query.toString());
1644
1645                QueryPos qPos = QueryPos.getInstance(q);
1646
1647                qPos.add(userId);
1648
1649                count = (Long)q.uniqueResult();
1650            }
1651            catch (Exception e) {
1652                throw processException(e);
1653            }
1654            finally {
1655                if (count == null) {
1656                    count = Long.valueOf(0);
1657                }
1658
1659                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1660                    finderArgs, count);
1661
1662                closeSession(session);
1663            }
1664        }
1665
1666        return count.intValue();
1667    }
1668
1669    public int countByC_C(long classNameId, long classPK)
1670        throws SystemException {
1671        Object[] finderArgs = new Object[] {
1672                new Long(classNameId), new Long(classPK)
1673            };
1674
1675        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1676                finderArgs, this);
1677
1678        if (count == null) {
1679            Session session = null;
1680
1681            try {
1682                session = openSession();
1683
1684                StringBuilder query = new StringBuilder();
1685
1686                query.append("SELECT COUNT(*) ");
1687                query.append(
1688                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1689
1690                query.append("classNameId = ?");
1691
1692                query.append(" AND ");
1693
1694                query.append("classPK = ?");
1695
1696                query.append(" ");
1697
1698                Query q = session.createQuery(query.toString());
1699
1700                QueryPos qPos = QueryPos.getInstance(q);
1701
1702                qPos.add(classNameId);
1703
1704                qPos.add(classPK);
1705
1706                count = (Long)q.uniqueResult();
1707            }
1708            catch (Exception e) {
1709                throw processException(e);
1710            }
1711            finally {
1712                if (count == null) {
1713                    count = Long.valueOf(0);
1714                }
1715
1716                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1717                    count);
1718
1719                closeSession(session);
1720            }
1721        }
1722
1723        return count.intValue();
1724    }
1725
1726    public int countByC_C_A(long classNameId, long classPK, boolean alert)
1727        throws SystemException {
1728        Object[] finderArgs = new Object[] {
1729                new Long(classNameId), new Long(classPK), Boolean.valueOf(alert)
1730            };
1731
1732        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_A,
1733                finderArgs, this);
1734
1735        if (count == null) {
1736            Session session = null;
1737
1738            try {
1739                session = openSession();
1740
1741                StringBuilder query = new StringBuilder();
1742
1743                query.append("SELECT COUNT(*) ");
1744                query.append(
1745                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1746
1747                query.append("classNameId = ?");
1748
1749                query.append(" AND ");
1750
1751                query.append("classPK = ?");
1752
1753                query.append(" AND ");
1754
1755                query.append("alert = ?");
1756
1757                query.append(" ");
1758
1759                Query q = session.createQuery(query.toString());
1760
1761                QueryPos qPos = QueryPos.getInstance(q);
1762
1763                qPos.add(classNameId);
1764
1765                qPos.add(classPK);
1766
1767                qPos.add(alert);
1768
1769                count = (Long)q.uniqueResult();
1770            }
1771            catch (Exception e) {
1772                throw processException(e);
1773            }
1774            finally {
1775                if (count == null) {
1776                    count = Long.valueOf(0);
1777                }
1778
1779                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_A,
1780                    finderArgs, count);
1781
1782                closeSession(session);
1783            }
1784        }
1785
1786        return count.intValue();
1787    }
1788
1789    public int countAll() throws SystemException {
1790        Object[] finderArgs = new Object[0];
1791
1792        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1793                finderArgs, this);
1794
1795        if (count == null) {
1796            Session session = null;
1797
1798            try {
1799                session = openSession();
1800
1801                Query q = session.createQuery(
1802                        "SELECT COUNT(*) FROM com.liferay.portlet.announcements.model.AnnouncementsEntry");
1803
1804                count = (Long)q.uniqueResult();
1805            }
1806            catch (Exception e) {
1807                throw processException(e);
1808            }
1809            finally {
1810                if (count == null) {
1811                    count = Long.valueOf(0);
1812                }
1813
1814                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1815                    count);
1816
1817                closeSession(session);
1818            }
1819        }
1820
1821        return count.intValue();
1822    }
1823
1824    public void afterPropertiesSet() {
1825        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1826                    com.liferay.portal.util.PropsUtil.get(
1827                        "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsEntry")));
1828
1829        if (listenerClassNames.length > 0) {
1830            try {
1831                List<ModelListener<AnnouncementsEntry>> listenersList = new ArrayList<ModelListener<AnnouncementsEntry>>();
1832
1833                for (String listenerClassName : listenerClassNames) {
1834                    listenersList.add((ModelListener<AnnouncementsEntry>)Class.forName(
1835                            listenerClassName).newInstance());
1836                }
1837
1838                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1839            }
1840            catch (Exception e) {
1841                _log.error(e);
1842            }
1843        }
1844    }
1845
1846    @BeanReference(name = "com.liferay.portlet.announcements.service.persistence.AnnouncementsDeliveryPersistence.impl")
1847    protected com.liferay.portlet.announcements.service.persistence.AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1848    @BeanReference(name = "com.liferay.portlet.announcements.service.persistence.AnnouncementsEntryPersistence.impl")
1849    protected com.liferay.portlet.announcements.service.persistence.AnnouncementsEntryPersistence announcementsEntryPersistence;
1850    @BeanReference(name = "com.liferay.portlet.announcements.service.persistence.AnnouncementsFlagPersistence.impl")
1851    protected com.liferay.portlet.announcements.service.persistence.AnnouncementsFlagPersistence announcementsFlagPersistence;
1852    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1853    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1854    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1855    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1856    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1857    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1858    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1859    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1860    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1861    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1862    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1863    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1864    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1865    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1866    private static Log _log = LogFactoryUtil.getLog(AnnouncementsEntryPersistenceImpl.class);
1867}