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