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