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