001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.announcements.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.BatchSessionUtil;
040    import com.liferay.portal.service.persistence.CompanyPersistence;
041    import com.liferay.portal.service.persistence.GroupPersistence;
042    import com.liferay.portal.service.persistence.OrganizationPersistence;
043    import com.liferay.portal.service.persistence.ResourcePersistence;
044    import com.liferay.portal.service.persistence.RolePersistence;
045    import com.liferay.portal.service.persistence.UserGroupPersistence;
046    import com.liferay.portal.service.persistence.UserPersistence;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.announcements.NoSuchEntryException;
050    import com.liferay.portlet.announcements.model.AnnouncementsEntry;
051    import com.liferay.portlet.announcements.model.impl.AnnouncementsEntryImpl;
052    import com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl;
053    
054    import java.io.Serializable;
055    
056    import java.util.ArrayList;
057    import java.util.Collections;
058    import java.util.List;
059    
060    /**
061     * The persistence implementation for the announcements entry service.
062     *
063     * <p>
064     * Never modify or reference this class directly. Always use {@link AnnouncementsEntryUtil} to access the announcements entry persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
065     * </p>
066     *
067     * <p>
068     * Caching information and settings can be found in <code>portal.properties</code>
069     * </p>
070     *
071     * @author Brian Wing Shun Chan
072     * @see AnnouncementsEntryPersistence
073     * @see AnnouncementsEntryUtil
074     * @generated
075     */
076    public class AnnouncementsEntryPersistenceImpl extends BasePersistenceImpl<AnnouncementsEntry>
077            implements AnnouncementsEntryPersistence {
078            public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsEntryImpl.class.getName();
079            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
080                    ".List";
081            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
082                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
083                            FINDER_CLASS_NAME_LIST, "findByUuid",
084                            new String[] {
085                                    String.class.getName(),
086                                    
087                            "java.lang.Integer", "java.lang.Integer",
088                                    "com.liferay.portal.kernel.util.OrderByComparator"
089                            });
090            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
091                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
092                            FINDER_CLASS_NAME_LIST, "countByUuid",
093                            new String[] { String.class.getName() });
094            public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
095                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
096                            FINDER_CLASS_NAME_LIST, "findByUserId",
097                            new String[] {
098                                    Long.class.getName(),
099                                    
100                            "java.lang.Integer", "java.lang.Integer",
101                                    "com.liferay.portal.kernel.util.OrderByComparator"
102                            });
103            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
104                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
105                            FINDER_CLASS_NAME_LIST, "countByUserId",
106                            new String[] { Long.class.getName() });
107            public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
108                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
109                            FINDER_CLASS_NAME_LIST, "findByC_C",
110                            new String[] {
111                                    Long.class.getName(), Long.class.getName(),
112                                    
113                            "java.lang.Integer", "java.lang.Integer",
114                                    "com.liferay.portal.kernel.util.OrderByComparator"
115                            });
116            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
117                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
118                            FINDER_CLASS_NAME_LIST, "countByC_C",
119                            new String[] { Long.class.getName(), Long.class.getName() });
120            public static final FinderPath FINDER_PATH_FIND_BY_C_C_A = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
121                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
122                            FINDER_CLASS_NAME_LIST, "findByC_C_A",
123                            new String[] {
124                                    Long.class.getName(), Long.class.getName(),
125                                    Boolean.class.getName(),
126                                    
127                            "java.lang.Integer", "java.lang.Integer",
128                                    "com.liferay.portal.kernel.util.OrderByComparator"
129                            });
130            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_A = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
131                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
132                            FINDER_CLASS_NAME_LIST, "countByC_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_ALL = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
138                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
139                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
140            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
141                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
142                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
143    
144            /**
145             * Caches the announcements entry in the entity cache if it is enabled.
146             *
147             * @param announcementsEntry the announcements entry to cache
148             */
149            public void cacheResult(AnnouncementsEntry announcementsEntry) {
150                    EntityCacheUtil.putResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
151                            AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey(),
152                            announcementsEntry);
153            }
154    
155            /**
156             * Caches the announcements entries in the entity cache if it is enabled.
157             *
158             * @param announcementsEntries the announcements entries to cache
159             */
160            public void cacheResult(List<AnnouncementsEntry> announcementsEntries) {
161                    for (AnnouncementsEntry announcementsEntry : announcementsEntries) {
162                            if (EntityCacheUtil.getResult(
163                                                    AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
164                                                    AnnouncementsEntryImpl.class,
165                                                    announcementsEntry.getPrimaryKey(), this) == null) {
166                                    cacheResult(announcementsEntry);
167                            }
168                    }
169            }
170    
171            /**
172             * Clears the cache for all announcements entries.
173             *
174             * <p>
175             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
176             * </p>
177             */
178            public void clearCache() {
179                    CacheRegistryUtil.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            /**
186             * Clears the cache for the announcements entry.
187             *
188             * <p>
189             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
190             * </p>
191             */
192            public void clearCache(AnnouncementsEntry announcementsEntry) {
193                    EntityCacheUtil.removeResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
194                            AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey());
195            }
196    
197            /**
198             * Creates a new announcements entry with the primary key. Does not add the announcements entry to the database.
199             *
200             * @param entryId the primary key for the new announcements entry
201             * @return the new announcements entry
202             */
203            public AnnouncementsEntry create(long entryId) {
204                    AnnouncementsEntry announcementsEntry = new AnnouncementsEntryImpl();
205    
206                    announcementsEntry.setNew(true);
207                    announcementsEntry.setPrimaryKey(entryId);
208    
209                    String uuid = PortalUUIDUtil.generate();
210    
211                    announcementsEntry.setUuid(uuid);
212    
213                    return announcementsEntry;
214            }
215    
216            /**
217             * Removes the announcements entry with the primary key from the database. Also notifies the appropriate model listeners.
218             *
219             * @param primaryKey the primary key of the announcements entry to remove
220             * @return the announcements entry that was removed
221             * @throws com.liferay.portal.NoSuchModelException if a announcements entry with the primary key could not be found
222             * @throws SystemException if a system exception occurred
223             */
224            public AnnouncementsEntry remove(Serializable primaryKey)
225                    throws NoSuchModelException, SystemException {
226                    return remove(((Long)primaryKey).longValue());
227            }
228    
229            /**
230             * Removes the announcements entry with the primary key from the database. Also notifies the appropriate model listeners.
231             *
232             * @param entryId the primary key of the announcements entry to remove
233             * @return the announcements entry that was removed
234             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
235             * @throws SystemException if a system exception occurred
236             */
237            public AnnouncementsEntry remove(long entryId)
238                    throws NoSuchEntryException, SystemException {
239                    Session session = null;
240    
241                    try {
242                            session = openSession();
243    
244                            AnnouncementsEntry announcementsEntry = (AnnouncementsEntry)session.get(AnnouncementsEntryImpl.class,
245                                            new Long(entryId));
246    
247                            if (announcementsEntry == null) {
248                                    if (_log.isWarnEnabled()) {
249                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
250                                    }
251    
252                                    throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
253                                            entryId);
254                            }
255    
256                            return remove(announcementsEntry);
257                    }
258                    catch (NoSuchEntryException nsee) {
259                            throw nsee;
260                    }
261                    catch (Exception e) {
262                            throw processException(e);
263                    }
264                    finally {
265                            closeSession(session);
266                    }
267            }
268    
269            protected AnnouncementsEntry removeImpl(
270                    AnnouncementsEntry announcementsEntry) throws SystemException {
271                    announcementsEntry = toUnwrappedModel(announcementsEntry);
272    
273                    Session session = null;
274    
275                    try {
276                            session = openSession();
277    
278                            BatchSessionUtil.delete(session, announcementsEntry);
279                    }
280                    catch (Exception e) {
281                            throw processException(e);
282                    }
283                    finally {
284                            closeSession(session);
285                    }
286    
287                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
288    
289                    EntityCacheUtil.removeResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
290                            AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey());
291    
292                    return announcementsEntry;
293            }
294    
295            public AnnouncementsEntry updateImpl(
296                    com.liferay.portlet.announcements.model.AnnouncementsEntry announcementsEntry,
297                    boolean merge) throws SystemException {
298                    announcementsEntry = toUnwrappedModel(announcementsEntry);
299    
300                    if (Validator.isNull(announcementsEntry.getUuid())) {
301                            String uuid = PortalUUIDUtil.generate();
302    
303                            announcementsEntry.setUuid(uuid);
304                    }
305    
306                    Session session = null;
307    
308                    try {
309                            session = openSession();
310    
311                            BatchSessionUtil.update(session, announcementsEntry, merge);
312    
313                            announcementsEntry.setNew(false);
314                    }
315                    catch (Exception e) {
316                            throw processException(e);
317                    }
318                    finally {
319                            closeSession(session);
320                    }
321    
322                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
323    
324                    EntityCacheUtil.putResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
325                            AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey(),
326                            announcementsEntry);
327    
328                    return announcementsEntry;
329            }
330    
331            protected AnnouncementsEntry toUnwrappedModel(
332                    AnnouncementsEntry announcementsEntry) {
333                    if (announcementsEntry instanceof AnnouncementsEntryImpl) {
334                            return announcementsEntry;
335                    }
336    
337                    AnnouncementsEntryImpl announcementsEntryImpl = new AnnouncementsEntryImpl();
338    
339                    announcementsEntryImpl.setNew(announcementsEntry.isNew());
340                    announcementsEntryImpl.setPrimaryKey(announcementsEntry.getPrimaryKey());
341    
342                    announcementsEntryImpl.setUuid(announcementsEntry.getUuid());
343                    announcementsEntryImpl.setEntryId(announcementsEntry.getEntryId());
344                    announcementsEntryImpl.setCompanyId(announcementsEntry.getCompanyId());
345                    announcementsEntryImpl.setUserId(announcementsEntry.getUserId());
346                    announcementsEntryImpl.setUserName(announcementsEntry.getUserName());
347                    announcementsEntryImpl.setCreateDate(announcementsEntry.getCreateDate());
348                    announcementsEntryImpl.setModifiedDate(announcementsEntry.getModifiedDate());
349                    announcementsEntryImpl.setClassNameId(announcementsEntry.getClassNameId());
350                    announcementsEntryImpl.setClassPK(announcementsEntry.getClassPK());
351                    announcementsEntryImpl.setTitle(announcementsEntry.getTitle());
352                    announcementsEntryImpl.setContent(announcementsEntry.getContent());
353                    announcementsEntryImpl.setUrl(announcementsEntry.getUrl());
354                    announcementsEntryImpl.setType(announcementsEntry.getType());
355                    announcementsEntryImpl.setDisplayDate(announcementsEntry.getDisplayDate());
356                    announcementsEntryImpl.setExpirationDate(announcementsEntry.getExpirationDate());
357                    announcementsEntryImpl.setPriority(announcementsEntry.getPriority());
358                    announcementsEntryImpl.setAlert(announcementsEntry.isAlert());
359    
360                    return announcementsEntryImpl;
361            }
362    
363            /**
364             * Finds the announcements entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
365             *
366             * @param primaryKey the primary key of the announcements entry to find
367             * @return the announcements entry
368             * @throws com.liferay.portal.NoSuchModelException if a announcements entry with the primary key could not be found
369             * @throws SystemException if a system exception occurred
370             */
371            public AnnouncementsEntry findByPrimaryKey(Serializable primaryKey)
372                    throws NoSuchModelException, SystemException {
373                    return findByPrimaryKey(((Long)primaryKey).longValue());
374            }
375    
376            /**
377             * Finds the announcements entry with the primary key or throws a {@link com.liferay.portlet.announcements.NoSuchEntryException} if it could not be found.
378             *
379             * @param entryId the primary key of the announcements entry to find
380             * @return the announcements entry
381             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
382             * @throws SystemException if a system exception occurred
383             */
384            public AnnouncementsEntry findByPrimaryKey(long entryId)
385                    throws NoSuchEntryException, SystemException {
386                    AnnouncementsEntry announcementsEntry = fetchByPrimaryKey(entryId);
387    
388                    if (announcementsEntry == null) {
389                            if (_log.isWarnEnabled()) {
390                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
391                            }
392    
393                            throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
394                                    entryId);
395                    }
396    
397                    return announcementsEntry;
398            }
399    
400            /**
401             * Finds the announcements entry with the primary key or returns <code>null</code> if it could not be found.
402             *
403             * @param primaryKey the primary key of the announcements entry to find
404             * @return the announcements entry, or <code>null</code> if a announcements entry with the primary key could not be found
405             * @throws SystemException if a system exception occurred
406             */
407            public AnnouncementsEntry fetchByPrimaryKey(Serializable primaryKey)
408                    throws SystemException {
409                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
410            }
411    
412            /**
413             * Finds the announcements entry with the primary key or returns <code>null</code> if it could not be found.
414             *
415             * @param entryId the primary key of the announcements entry to find
416             * @return the announcements entry, or <code>null</code> if a announcements entry with the primary key could not be found
417             * @throws SystemException if a system exception occurred
418             */
419            public AnnouncementsEntry fetchByPrimaryKey(long entryId)
420                    throws SystemException {
421                    AnnouncementsEntry announcementsEntry = (AnnouncementsEntry)EntityCacheUtil.getResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
422                                    AnnouncementsEntryImpl.class, entryId, this);
423    
424                    if (announcementsEntry == null) {
425                            Session session = null;
426    
427                            try {
428                                    session = openSession();
429    
430                                    announcementsEntry = (AnnouncementsEntry)session.get(AnnouncementsEntryImpl.class,
431                                                    new Long(entryId));
432                            }
433                            catch (Exception e) {
434                                    throw processException(e);
435                            }
436                            finally {
437                                    if (announcementsEntry != null) {
438                                            cacheResult(announcementsEntry);
439                                    }
440    
441                                    closeSession(session);
442                            }
443                    }
444    
445                    return announcementsEntry;
446            }
447    
448            /**
449             * Finds all the announcements entries where uuid = &#63;.
450             *
451             * @param uuid the uuid to search with
452             * @return the matching announcements entries
453             * @throws SystemException if a system exception occurred
454             */
455            public List<AnnouncementsEntry> findByUuid(String uuid)
456                    throws SystemException {
457                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
458            }
459    
460            /**
461             * Finds a range of all the announcements entries where uuid = &#63;.
462             *
463             * <p>
464             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
465             * </p>
466             *
467             * @param uuid the uuid to search with
468             * @param start the lower bound of the range of announcements entries to return
469             * @param end the upper bound of the range of announcements entries to return (not inclusive)
470             * @return the range of matching announcements entries
471             * @throws SystemException if a system exception occurred
472             */
473            public List<AnnouncementsEntry> findByUuid(String uuid, int start, int end)
474                    throws SystemException {
475                    return findByUuid(uuid, start, end, null);
476            }
477    
478            /**
479             * Finds an ordered range of all the announcements entries where uuid = &#63;.
480             *
481             * <p>
482             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
483             * </p>
484             *
485             * @param uuid the uuid to search with
486             * @param start the lower bound of the range of announcements entries to return
487             * @param end the upper bound of the range of announcements entries to return (not inclusive)
488             * @param orderByComparator the comparator to order the results by
489             * @return the ordered range of matching announcements entries
490             * @throws SystemException if a system exception occurred
491             */
492            public List<AnnouncementsEntry> findByUuid(String uuid, int start, int end,
493                    OrderByComparator orderByComparator) throws SystemException {
494                    Object[] finderArgs = new Object[] {
495                                    uuid,
496                                    
497                                    String.valueOf(start), String.valueOf(end),
498                                    String.valueOf(orderByComparator)
499                            };
500    
501                    List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
502                                    finderArgs, this);
503    
504                    if (list == null) {
505                            Session session = null;
506    
507                            try {
508                                    session = openSession();
509    
510                                    StringBundler query = null;
511    
512                                    if (orderByComparator != null) {
513                                            query = new StringBundler(3 +
514                                                            (orderByComparator.getOrderByFields().length * 3));
515                                    }
516                                    else {
517                                            query = new StringBundler(3);
518                                    }
519    
520                                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
521    
522                                    if (uuid == null) {
523                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
524                                    }
525                                    else {
526                                            if (uuid.equals(StringPool.BLANK)) {
527                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
528                                            }
529                                            else {
530                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
531                                            }
532                                    }
533    
534                                    if (orderByComparator != null) {
535                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
536                                                    orderByComparator);
537                                    }
538    
539                                    else {
540                                            query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
541                                    }
542    
543                                    String sql = query.toString();
544    
545                                    Query q = session.createQuery(sql);
546    
547                                    QueryPos qPos = QueryPos.getInstance(q);
548    
549                                    if (uuid != null) {
550                                            qPos.add(uuid);
551                                    }
552    
553                                    list = (List<AnnouncementsEntry>)QueryUtil.list(q,
554                                                    getDialect(), start, end);
555                            }
556                            catch (Exception e) {
557                                    throw processException(e);
558                            }
559                            finally {
560                                    if (list == null) {
561                                            list = new ArrayList<AnnouncementsEntry>();
562                                    }
563    
564                                    cacheResult(list);
565    
566                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
567                                            list);
568    
569                                    closeSession(session);
570                            }
571                    }
572    
573                    return list;
574            }
575    
576            /**
577             * Finds the first announcements entry in the ordered set where uuid = &#63;.
578             *
579             * <p>
580             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
581             * </p>
582             *
583             * @param uuid the uuid to search with
584             * @param orderByComparator the comparator to order the set by
585             * @return the first matching announcements entry
586             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
587             * @throws SystemException if a system exception occurred
588             */
589            public AnnouncementsEntry findByUuid_First(String uuid,
590                    OrderByComparator orderByComparator)
591                    throws NoSuchEntryException, SystemException {
592                    List<AnnouncementsEntry> list = findByUuid(uuid, 0, 1, orderByComparator);
593    
594                    if (list.isEmpty()) {
595                            StringBundler msg = new StringBundler(4);
596    
597                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
598    
599                            msg.append("uuid=");
600                            msg.append(uuid);
601    
602                            msg.append(StringPool.CLOSE_CURLY_BRACE);
603    
604                            throw new NoSuchEntryException(msg.toString());
605                    }
606                    else {
607                            return list.get(0);
608                    }
609            }
610    
611            /**
612             * Finds the last announcements entry in the ordered set where uuid = &#63;.
613             *
614             * <p>
615             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
616             * </p>
617             *
618             * @param uuid the uuid to search with
619             * @param orderByComparator the comparator to order the set by
620             * @return the last matching announcements entry
621             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
622             * @throws SystemException if a system exception occurred
623             */
624            public AnnouncementsEntry findByUuid_Last(String uuid,
625                    OrderByComparator orderByComparator)
626                    throws NoSuchEntryException, SystemException {
627                    int count = countByUuid(uuid);
628    
629                    List<AnnouncementsEntry> list = findByUuid(uuid, count - 1, count,
630                                    orderByComparator);
631    
632                    if (list.isEmpty()) {
633                            StringBundler msg = new StringBundler(4);
634    
635                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
636    
637                            msg.append("uuid=");
638                            msg.append(uuid);
639    
640                            msg.append(StringPool.CLOSE_CURLY_BRACE);
641    
642                            throw new NoSuchEntryException(msg.toString());
643                    }
644                    else {
645                            return list.get(0);
646                    }
647            }
648    
649            /**
650             * Finds the announcements entries before and after the current announcements entry in the ordered set where uuid = &#63;.
651             *
652             * <p>
653             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
654             * </p>
655             *
656             * @param entryId the primary key of the current announcements entry
657             * @param uuid the uuid to search with
658             * @param orderByComparator the comparator to order the set by
659             * @return the previous, current, and next announcements entry
660             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
661             * @throws SystemException if a system exception occurred
662             */
663            public AnnouncementsEntry[] findByUuid_PrevAndNext(long entryId,
664                    String uuid, OrderByComparator orderByComparator)
665                    throws NoSuchEntryException, SystemException {
666                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
667    
668                    Session session = null;
669    
670                    try {
671                            session = openSession();
672    
673                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
674    
675                            array[0] = getByUuid_PrevAndNext(session, announcementsEntry, uuid,
676                                            orderByComparator, true);
677    
678                            array[1] = announcementsEntry;
679    
680                            array[2] = getByUuid_PrevAndNext(session, announcementsEntry, uuid,
681                                            orderByComparator, false);
682    
683                            return array;
684                    }
685                    catch (Exception e) {
686                            throw processException(e);
687                    }
688                    finally {
689                            closeSession(session);
690                    }
691            }
692    
693            protected AnnouncementsEntry getByUuid_PrevAndNext(Session session,
694                    AnnouncementsEntry announcementsEntry, String uuid,
695                    OrderByComparator orderByComparator, boolean previous) {
696                    StringBundler query = null;
697    
698                    if (orderByComparator != null) {
699                            query = new StringBundler(6 +
700                                            (orderByComparator.getOrderByFields().length * 6));
701                    }
702                    else {
703                            query = new StringBundler(3);
704                    }
705    
706                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
707    
708                    if (uuid == null) {
709                            query.append(_FINDER_COLUMN_UUID_UUID_1);
710                    }
711                    else {
712                            if (uuid.equals(StringPool.BLANK)) {
713                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
714                            }
715                            else {
716                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
717                            }
718                    }
719    
720                    if (orderByComparator != null) {
721                            String[] orderByFields = orderByComparator.getOrderByFields();
722    
723                            if (orderByFields.length > 0) {
724                                    query.append(WHERE_AND);
725                            }
726    
727                            for (int i = 0; i < orderByFields.length; i++) {
728                                    query.append(_ORDER_BY_ENTITY_ALIAS);
729                                    query.append(orderByFields[i]);
730    
731                                    if ((i + 1) < orderByFields.length) {
732                                            if (orderByComparator.isAscending() ^ previous) {
733                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
734                                            }
735                                            else {
736                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
737                                            }
738                                    }
739                                    else {
740                                            if (orderByComparator.isAscending() ^ previous) {
741                                                    query.append(WHERE_GREATER_THAN);
742                                            }
743                                            else {
744                                                    query.append(WHERE_LESSER_THAN);
745                                            }
746                                    }
747                            }
748    
749                            query.append(ORDER_BY_CLAUSE);
750    
751                            for (int i = 0; i < orderByFields.length; i++) {
752                                    query.append(_ORDER_BY_ENTITY_ALIAS);
753                                    query.append(orderByFields[i]);
754    
755                                    if ((i + 1) < orderByFields.length) {
756                                            if (orderByComparator.isAscending() ^ previous) {
757                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
758                                            }
759                                            else {
760                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
761                                            }
762                                    }
763                                    else {
764                                            if (orderByComparator.isAscending() ^ previous) {
765                                                    query.append(ORDER_BY_ASC);
766                                            }
767                                            else {
768                                                    query.append(ORDER_BY_DESC);
769                                            }
770                                    }
771                            }
772                    }
773    
774                    else {
775                            query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
776                    }
777    
778                    String sql = query.toString();
779    
780                    Query q = session.createQuery(sql);
781    
782                    q.setFirstResult(0);
783                    q.setMaxResults(2);
784    
785                    QueryPos qPos = QueryPos.getInstance(q);
786    
787                    if (uuid != null) {
788                            qPos.add(uuid);
789                    }
790    
791                    if (orderByComparator != null) {
792                            Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
793    
794                            for (Object value : values) {
795                                    qPos.add(value);
796                            }
797                    }
798    
799                    List<AnnouncementsEntry> list = q.list();
800    
801                    if (list.size() == 2) {
802                            return list.get(1);
803                    }
804                    else {
805                            return null;
806                    }
807            }
808    
809            /**
810             * Finds all the announcements entries where userId = &#63;.
811             *
812             * @param userId the user id to search with
813             * @return the matching announcements entries
814             * @throws SystemException if a system exception occurred
815             */
816            public List<AnnouncementsEntry> findByUserId(long userId)
817                    throws SystemException {
818                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
819            }
820    
821            /**
822             * Finds a range of all the announcements entries where userId = &#63;.
823             *
824             * <p>
825             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
826             * </p>
827             *
828             * @param userId the user id to search with
829             * @param start the lower bound of the range of announcements entries to return
830             * @param end the upper bound of the range of announcements entries to return (not inclusive)
831             * @return the range of matching announcements entries
832             * @throws SystemException if a system exception occurred
833             */
834            public List<AnnouncementsEntry> findByUserId(long userId, int start, int end)
835                    throws SystemException {
836                    return findByUserId(userId, start, end, null);
837            }
838    
839            /**
840             * Finds an ordered range of all the announcements entries where userId = &#63;.
841             *
842             * <p>
843             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
844             * </p>
845             *
846             * @param userId the user id to search with
847             * @param start the lower bound of the range of announcements entries to return
848             * @param end the upper bound of the range of announcements entries to return (not inclusive)
849             * @param orderByComparator the comparator to order the results by
850             * @return the ordered range of matching announcements entries
851             * @throws SystemException if a system exception occurred
852             */
853            public List<AnnouncementsEntry> findByUserId(long userId, int start,
854                    int end, OrderByComparator orderByComparator) throws SystemException {
855                    Object[] finderArgs = new Object[] {
856                                    userId,
857                                    
858                                    String.valueOf(start), String.valueOf(end),
859                                    String.valueOf(orderByComparator)
860                            };
861    
862                    List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
863                                    finderArgs, this);
864    
865                    if (list == null) {
866                            Session session = null;
867    
868                            try {
869                                    session = openSession();
870    
871                                    StringBundler query = null;
872    
873                                    if (orderByComparator != null) {
874                                            query = new StringBundler(3 +
875                                                            (orderByComparator.getOrderByFields().length * 3));
876                                    }
877                                    else {
878                                            query = new StringBundler(3);
879                                    }
880    
881                                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
882    
883                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
884    
885                                    if (orderByComparator != null) {
886                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
887                                                    orderByComparator);
888                                    }
889    
890                                    else {
891                                            query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
892                                    }
893    
894                                    String sql = query.toString();
895    
896                                    Query q = session.createQuery(sql);
897    
898                                    QueryPos qPos = QueryPos.getInstance(q);
899    
900                                    qPos.add(userId);
901    
902                                    list = (List<AnnouncementsEntry>)QueryUtil.list(q,
903                                                    getDialect(), start, end);
904                            }
905                            catch (Exception e) {
906                                    throw processException(e);
907                            }
908                            finally {
909                                    if (list == null) {
910                                            list = new ArrayList<AnnouncementsEntry>();
911                                    }
912    
913                                    cacheResult(list);
914    
915                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
916                                            finderArgs, list);
917    
918                                    closeSession(session);
919                            }
920                    }
921    
922                    return list;
923            }
924    
925            /**
926             * Finds the first announcements entry in the ordered set where userId = &#63;.
927             *
928             * <p>
929             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
930             * </p>
931             *
932             * @param userId the user id to search with
933             * @param orderByComparator the comparator to order the set by
934             * @return the first matching announcements entry
935             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
936             * @throws SystemException if a system exception occurred
937             */
938            public AnnouncementsEntry findByUserId_First(long userId,
939                    OrderByComparator orderByComparator)
940                    throws NoSuchEntryException, SystemException {
941                    List<AnnouncementsEntry> list = findByUserId(userId, 0, 1,
942                                    orderByComparator);
943    
944                    if (list.isEmpty()) {
945                            StringBundler msg = new StringBundler(4);
946    
947                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
948    
949                            msg.append("userId=");
950                            msg.append(userId);
951    
952                            msg.append(StringPool.CLOSE_CURLY_BRACE);
953    
954                            throw new NoSuchEntryException(msg.toString());
955                    }
956                    else {
957                            return list.get(0);
958                    }
959            }
960    
961            /**
962             * Finds the last announcements entry in the ordered set where userId = &#63;.
963             *
964             * <p>
965             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
966             * </p>
967             *
968             * @param userId the user id to search with
969             * @param orderByComparator the comparator to order the set by
970             * @return the last matching announcements entry
971             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
972             * @throws SystemException if a system exception occurred
973             */
974            public AnnouncementsEntry findByUserId_Last(long userId,
975                    OrderByComparator orderByComparator)
976                    throws NoSuchEntryException, SystemException {
977                    int count = countByUserId(userId);
978    
979                    List<AnnouncementsEntry> list = findByUserId(userId, count - 1, count,
980                                    orderByComparator);
981    
982                    if (list.isEmpty()) {
983                            StringBundler msg = new StringBundler(4);
984    
985                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
986    
987                            msg.append("userId=");
988                            msg.append(userId);
989    
990                            msg.append(StringPool.CLOSE_CURLY_BRACE);
991    
992                            throw new NoSuchEntryException(msg.toString());
993                    }
994                    else {
995                            return list.get(0);
996                    }
997            }
998    
999            /**
1000             * Finds the announcements entries before and after the current announcements entry in the ordered set where userId = &#63;.
1001             *
1002             * <p>
1003             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1004             * </p>
1005             *
1006             * @param entryId the primary key of the current announcements entry
1007             * @param userId the user id to search with
1008             * @param orderByComparator the comparator to order the set by
1009             * @return the previous, current, and next announcements entry
1010             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
1011             * @throws SystemException if a system exception occurred
1012             */
1013            public AnnouncementsEntry[] findByUserId_PrevAndNext(long entryId,
1014                    long userId, OrderByComparator orderByComparator)
1015                    throws NoSuchEntryException, SystemException {
1016                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1017    
1018                    Session session = null;
1019    
1020                    try {
1021                            session = openSession();
1022    
1023                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1024    
1025                            array[0] = getByUserId_PrevAndNext(session, announcementsEntry,
1026                                            userId, orderByComparator, true);
1027    
1028                            array[1] = announcementsEntry;
1029    
1030                            array[2] = getByUserId_PrevAndNext(session, announcementsEntry,
1031                                            userId, orderByComparator, false);
1032    
1033                            return array;
1034                    }
1035                    catch (Exception e) {
1036                            throw processException(e);
1037                    }
1038                    finally {
1039                            closeSession(session);
1040                    }
1041            }
1042    
1043            protected AnnouncementsEntry getByUserId_PrevAndNext(Session session,
1044                    AnnouncementsEntry announcementsEntry, long userId,
1045                    OrderByComparator orderByComparator, boolean previous) {
1046                    StringBundler query = null;
1047    
1048                    if (orderByComparator != null) {
1049                            query = new StringBundler(6 +
1050                                            (orderByComparator.getOrderByFields().length * 6));
1051                    }
1052                    else {
1053                            query = new StringBundler(3);
1054                    }
1055    
1056                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1057    
1058                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1059    
1060                    if (orderByComparator != null) {
1061                            String[] orderByFields = orderByComparator.getOrderByFields();
1062    
1063                            if (orderByFields.length > 0) {
1064                                    query.append(WHERE_AND);
1065                            }
1066    
1067                            for (int i = 0; i < orderByFields.length; i++) {
1068                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1069                                    query.append(orderByFields[i]);
1070    
1071                                    if ((i + 1) < orderByFields.length) {
1072                                            if (orderByComparator.isAscending() ^ previous) {
1073                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1074                                            }
1075                                            else {
1076                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1077                                            }
1078                                    }
1079                                    else {
1080                                            if (orderByComparator.isAscending() ^ previous) {
1081                                                    query.append(WHERE_GREATER_THAN);
1082                                            }
1083                                            else {
1084                                                    query.append(WHERE_LESSER_THAN);
1085                                            }
1086                                    }
1087                            }
1088    
1089                            query.append(ORDER_BY_CLAUSE);
1090    
1091                            for (int i = 0; i < orderByFields.length; i++) {
1092                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1093                                    query.append(orderByFields[i]);
1094    
1095                                    if ((i + 1) < orderByFields.length) {
1096                                            if (orderByComparator.isAscending() ^ previous) {
1097                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1098                                            }
1099                                            else {
1100                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1101                                            }
1102                                    }
1103                                    else {
1104                                            if (orderByComparator.isAscending() ^ previous) {
1105                                                    query.append(ORDER_BY_ASC);
1106                                            }
1107                                            else {
1108                                                    query.append(ORDER_BY_DESC);
1109                                            }
1110                                    }
1111                            }
1112                    }
1113    
1114                    else {
1115                            query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1116                    }
1117    
1118                    String sql = query.toString();
1119    
1120                    Query q = session.createQuery(sql);
1121    
1122                    q.setFirstResult(0);
1123                    q.setMaxResults(2);
1124    
1125                    QueryPos qPos = QueryPos.getInstance(q);
1126    
1127                    qPos.add(userId);
1128    
1129                    if (orderByComparator != null) {
1130                            Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
1131    
1132                            for (Object value : values) {
1133                                    qPos.add(value);
1134                            }
1135                    }
1136    
1137                    List<AnnouncementsEntry> list = q.list();
1138    
1139                    if (list.size() == 2) {
1140                            return list.get(1);
1141                    }
1142                    else {
1143                            return null;
1144                    }
1145            }
1146    
1147            /**
1148             * Finds all the announcements entries where classNameId = &#63; and classPK = &#63;.
1149             *
1150             * @param classNameId the class name id to search with
1151             * @param classPK the class p k to search with
1152             * @return the matching announcements entries
1153             * @throws SystemException if a system exception occurred
1154             */
1155            public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK)
1156                    throws SystemException {
1157                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
1158                            QueryUtil.ALL_POS, null);
1159            }
1160    
1161            /**
1162             * Finds a range of all the announcements entries where classNameId = &#63; and classPK = &#63;.
1163             *
1164             * <p>
1165             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1166             * </p>
1167             *
1168             * @param classNameId the class name id to search with
1169             * @param classPK the class p k to search with
1170             * @param start the lower bound of the range of announcements entries to return
1171             * @param end the upper bound of the range of announcements entries to return (not inclusive)
1172             * @return the range of matching announcements entries
1173             * @throws SystemException if a system exception occurred
1174             */
1175            public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
1176                    int start, int end) throws SystemException {
1177                    return findByC_C(classNameId, classPK, start, end, null);
1178            }
1179    
1180            /**
1181             * Finds an ordered range of all the announcements entries where classNameId = &#63; and classPK = &#63;.
1182             *
1183             * <p>
1184             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1185             * </p>
1186             *
1187             * @param classNameId the class name id to search with
1188             * @param classPK the class p k to search with
1189             * @param start the lower bound of the range of announcements entries to return
1190             * @param end the upper bound of the range of announcements entries to return (not inclusive)
1191             * @param orderByComparator the comparator to order the results by
1192             * @return the ordered range of matching announcements entries
1193             * @throws SystemException if a system exception occurred
1194             */
1195            public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
1196                    int start, int end, OrderByComparator orderByComparator)
1197                    throws SystemException {
1198                    Object[] finderArgs = new Object[] {
1199                                    classNameId, classPK,
1200                                    
1201                                    String.valueOf(start), String.valueOf(end),
1202                                    String.valueOf(orderByComparator)
1203                            };
1204    
1205                    List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
1206                                    finderArgs, this);
1207    
1208                    if (list == null) {
1209                            Session session = null;
1210    
1211                            try {
1212                                    session = openSession();
1213    
1214                                    StringBundler query = null;
1215    
1216                                    if (orderByComparator != null) {
1217                                            query = new StringBundler(4 +
1218                                                            (orderByComparator.getOrderByFields().length * 3));
1219                                    }
1220                                    else {
1221                                            query = new StringBundler(4);
1222                                    }
1223    
1224                                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1225    
1226                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1227    
1228                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1229    
1230                                    if (orderByComparator != null) {
1231                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1232                                                    orderByComparator);
1233                                    }
1234    
1235                                    else {
1236                                            query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1237                                    }
1238    
1239                                    String sql = query.toString();
1240    
1241                                    Query q = session.createQuery(sql);
1242    
1243                                    QueryPos qPos = QueryPos.getInstance(q);
1244    
1245                                    qPos.add(classNameId);
1246    
1247                                    qPos.add(classPK);
1248    
1249                                    list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1250                                                    getDialect(), start, end);
1251                            }
1252                            catch (Exception e) {
1253                                    throw processException(e);
1254                            }
1255                            finally {
1256                                    if (list == null) {
1257                                            list = new ArrayList<AnnouncementsEntry>();
1258                                    }
1259    
1260                                    cacheResult(list);
1261    
1262                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
1263                                            list);
1264    
1265                                    closeSession(session);
1266                            }
1267                    }
1268    
1269                    return list;
1270            }
1271    
1272            /**
1273             * Finds the first announcements entry in the ordered set where classNameId = &#63; and classPK = &#63;.
1274             *
1275             * <p>
1276             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1277             * </p>
1278             *
1279             * @param classNameId the class name id to search with
1280             * @param classPK the class p k to search with
1281             * @param orderByComparator the comparator to order the set by
1282             * @return the first matching announcements entry
1283             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
1284             * @throws SystemException if a system exception occurred
1285             */
1286            public AnnouncementsEntry findByC_C_First(long classNameId, long classPK,
1287                    OrderByComparator orderByComparator)
1288                    throws NoSuchEntryException, SystemException {
1289                    List<AnnouncementsEntry> list = findByC_C(classNameId, classPK, 0, 1,
1290                                    orderByComparator);
1291    
1292                    if (list.isEmpty()) {
1293                            StringBundler msg = new StringBundler(6);
1294    
1295                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1296    
1297                            msg.append("classNameId=");
1298                            msg.append(classNameId);
1299    
1300                            msg.append(", classPK=");
1301                            msg.append(classPK);
1302    
1303                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1304    
1305                            throw new NoSuchEntryException(msg.toString());
1306                    }
1307                    else {
1308                            return list.get(0);
1309                    }
1310            }
1311    
1312            /**
1313             * Finds the last announcements entry in the ordered set where classNameId = &#63; and classPK = &#63;.
1314             *
1315             * <p>
1316             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1317             * </p>
1318             *
1319             * @param classNameId the class name id to search with
1320             * @param classPK the class p k to search with
1321             * @param orderByComparator the comparator to order the set by
1322             * @return the last matching announcements entry
1323             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
1324             * @throws SystemException if a system exception occurred
1325             */
1326            public AnnouncementsEntry findByC_C_Last(long classNameId, long classPK,
1327                    OrderByComparator orderByComparator)
1328                    throws NoSuchEntryException, SystemException {
1329                    int count = countByC_C(classNameId, classPK);
1330    
1331                    List<AnnouncementsEntry> list = findByC_C(classNameId, classPK,
1332                                    count - 1, count, orderByComparator);
1333    
1334                    if (list.isEmpty()) {
1335                            StringBundler msg = new StringBundler(6);
1336    
1337                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1338    
1339                            msg.append("classNameId=");
1340                            msg.append(classNameId);
1341    
1342                            msg.append(", classPK=");
1343                            msg.append(classPK);
1344    
1345                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1346    
1347                            throw new NoSuchEntryException(msg.toString());
1348                    }
1349                    else {
1350                            return list.get(0);
1351                    }
1352            }
1353    
1354            /**
1355             * Finds the announcements entries before and after the current announcements entry in the ordered set where classNameId = &#63; and classPK = &#63;.
1356             *
1357             * <p>
1358             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1359             * </p>
1360             *
1361             * @param entryId the primary key of the current announcements entry
1362             * @param classNameId the class name id to search with
1363             * @param classPK the class p k to search with
1364             * @param orderByComparator the comparator to order the set by
1365             * @return the previous, current, and next announcements entry
1366             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
1367             * @throws SystemException if a system exception occurred
1368             */
1369            public AnnouncementsEntry[] findByC_C_PrevAndNext(long entryId,
1370                    long classNameId, long classPK, OrderByComparator orderByComparator)
1371                    throws NoSuchEntryException, SystemException {
1372                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1373    
1374                    Session session = null;
1375    
1376                    try {
1377                            session = openSession();
1378    
1379                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1380    
1381                            array[0] = getByC_C_PrevAndNext(session, announcementsEntry,
1382                                            classNameId, classPK, orderByComparator, true);
1383    
1384                            array[1] = announcementsEntry;
1385    
1386                            array[2] = getByC_C_PrevAndNext(session, announcementsEntry,
1387                                            classNameId, classPK, orderByComparator, false);
1388    
1389                            return array;
1390                    }
1391                    catch (Exception e) {
1392                            throw processException(e);
1393                    }
1394                    finally {
1395                            closeSession(session);
1396                    }
1397            }
1398    
1399            protected AnnouncementsEntry getByC_C_PrevAndNext(Session session,
1400                    AnnouncementsEntry announcementsEntry, long classNameId, long classPK,
1401                    OrderByComparator orderByComparator, boolean previous) {
1402                    StringBundler query = null;
1403    
1404                    if (orderByComparator != null) {
1405                            query = new StringBundler(6 +
1406                                            (orderByComparator.getOrderByFields().length * 6));
1407                    }
1408                    else {
1409                            query = new StringBundler(3);
1410                    }
1411    
1412                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1413    
1414                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1415    
1416                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1417    
1418                    if (orderByComparator != null) {
1419                            String[] orderByFields = orderByComparator.getOrderByFields();
1420    
1421                            if (orderByFields.length > 0) {
1422                                    query.append(WHERE_AND);
1423                            }
1424    
1425                            for (int i = 0; i < orderByFields.length; i++) {
1426                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1427                                    query.append(orderByFields[i]);
1428    
1429                                    if ((i + 1) < orderByFields.length) {
1430                                            if (orderByComparator.isAscending() ^ previous) {
1431                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1432                                            }
1433                                            else {
1434                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1435                                            }
1436                                    }
1437                                    else {
1438                                            if (orderByComparator.isAscending() ^ previous) {
1439                                                    query.append(WHERE_GREATER_THAN);
1440                                            }
1441                                            else {
1442                                                    query.append(WHERE_LESSER_THAN);
1443                                            }
1444                                    }
1445                            }
1446    
1447                            query.append(ORDER_BY_CLAUSE);
1448    
1449                            for (int i = 0; i < orderByFields.length; i++) {
1450                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1451                                    query.append(orderByFields[i]);
1452    
1453                                    if ((i + 1) < orderByFields.length) {
1454                                            if (orderByComparator.isAscending() ^ previous) {
1455                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1456                                            }
1457                                            else {
1458                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1459                                            }
1460                                    }
1461                                    else {
1462                                            if (orderByComparator.isAscending() ^ previous) {
1463                                                    query.append(ORDER_BY_ASC);
1464                                            }
1465                                            else {
1466                                                    query.append(ORDER_BY_DESC);
1467                                            }
1468                                    }
1469                            }
1470                    }
1471    
1472                    else {
1473                            query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1474                    }
1475    
1476                    String sql = query.toString();
1477    
1478                    Query q = session.createQuery(sql);
1479    
1480                    q.setFirstResult(0);
1481                    q.setMaxResults(2);
1482    
1483                    QueryPos qPos = QueryPos.getInstance(q);
1484    
1485                    qPos.add(classNameId);
1486    
1487                    qPos.add(classPK);
1488    
1489                    if (orderByComparator != null) {
1490                            Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
1491    
1492                            for (Object value : values) {
1493                                    qPos.add(value);
1494                            }
1495                    }
1496    
1497                    List<AnnouncementsEntry> list = q.list();
1498    
1499                    if (list.size() == 2) {
1500                            return list.get(1);
1501                    }
1502                    else {
1503                            return null;
1504                    }
1505            }
1506    
1507            /**
1508             * Finds all the announcements entries where classNameId = &#63; and classPK = &#63; and alert = &#63;.
1509             *
1510             * @param classNameId the class name id to search with
1511             * @param classPK the class p k to search with
1512             * @param alert the alert to search with
1513             * @return the matching announcements entries
1514             * @throws SystemException if a system exception occurred
1515             */
1516            public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1517                    boolean alert) throws SystemException {
1518                    return findByC_C_A(classNameId, classPK, alert, QueryUtil.ALL_POS,
1519                            QueryUtil.ALL_POS, null);
1520            }
1521    
1522            /**
1523             * Finds a range of all the announcements entries where classNameId = &#63; and classPK = &#63; and alert = &#63;.
1524             *
1525             * <p>
1526             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1527             * </p>
1528             *
1529             * @param classNameId the class name id to search with
1530             * @param classPK the class p k to search with
1531             * @param alert the alert to search with
1532             * @param start the lower bound of the range of announcements entries to return
1533             * @param end the upper bound of the range of announcements entries to return (not inclusive)
1534             * @return the range of matching announcements entries
1535             * @throws SystemException if a system exception occurred
1536             */
1537            public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1538                    boolean alert, int start, int end) throws SystemException {
1539                    return findByC_C_A(classNameId, classPK, alert, start, end, null);
1540            }
1541    
1542            /**
1543             * Finds an ordered range of all the announcements entries where classNameId = &#63; and classPK = &#63; and alert = &#63;.
1544             *
1545             * <p>
1546             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1547             * </p>
1548             *
1549             * @param classNameId the class name id to search with
1550             * @param classPK the class p k to search with
1551             * @param alert the alert to search with
1552             * @param start the lower bound of the range of announcements entries to return
1553             * @param end the upper bound of the range of announcements entries to return (not inclusive)
1554             * @param orderByComparator the comparator to order the results by
1555             * @return the ordered range of matching announcements entries
1556             * @throws SystemException if a system exception occurred
1557             */
1558            public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1559                    boolean alert, int start, int end, OrderByComparator orderByComparator)
1560                    throws SystemException {
1561                    Object[] finderArgs = new Object[] {
1562                                    classNameId, classPK, alert,
1563                                    
1564                                    String.valueOf(start), String.valueOf(end),
1565                                    String.valueOf(orderByComparator)
1566                            };
1567    
1568                    List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_A,
1569                                    finderArgs, this);
1570    
1571                    if (list == null) {
1572                            Session session = null;
1573    
1574                            try {
1575                                    session = openSession();
1576    
1577                                    StringBundler query = null;
1578    
1579                                    if (orderByComparator != null) {
1580                                            query = new StringBundler(5 +
1581                                                            (orderByComparator.getOrderByFields().length * 3));
1582                                    }
1583                                    else {
1584                                            query = new StringBundler(5);
1585                                    }
1586    
1587                                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1588    
1589                                    query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
1590    
1591                                    query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
1592    
1593                                    query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
1594    
1595                                    if (orderByComparator != null) {
1596                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1597                                                    orderByComparator);
1598                                    }
1599    
1600                                    else {
1601                                            query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1602                                    }
1603    
1604                                    String sql = query.toString();
1605    
1606                                    Query q = session.createQuery(sql);
1607    
1608                                    QueryPos qPos = QueryPos.getInstance(q);
1609    
1610                                    qPos.add(classNameId);
1611    
1612                                    qPos.add(classPK);
1613    
1614                                    qPos.add(alert);
1615    
1616                                    list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1617                                                    getDialect(), start, end);
1618                            }
1619                            catch (Exception e) {
1620                                    throw processException(e);
1621                            }
1622                            finally {
1623                                    if (list == null) {
1624                                            list = new ArrayList<AnnouncementsEntry>();
1625                                    }
1626    
1627                                    cacheResult(list);
1628    
1629                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_A,
1630                                            finderArgs, list);
1631    
1632                                    closeSession(session);
1633                            }
1634                    }
1635    
1636                    return list;
1637            }
1638    
1639            /**
1640             * Finds the first announcements entry in the ordered set where classNameId = &#63; and classPK = &#63; and alert = &#63;.
1641             *
1642             * <p>
1643             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1644             * </p>
1645             *
1646             * @param classNameId the class name id to search with
1647             * @param classPK the class p k to search with
1648             * @param alert the alert to search with
1649             * @param orderByComparator the comparator to order the set by
1650             * @return the first matching announcements entry
1651             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
1652             * @throws SystemException if a system exception occurred
1653             */
1654            public AnnouncementsEntry findByC_C_A_First(long classNameId, long classPK,
1655                    boolean alert, OrderByComparator orderByComparator)
1656                    throws NoSuchEntryException, SystemException {
1657                    List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
1658                                    alert, 0, 1, orderByComparator);
1659    
1660                    if (list.isEmpty()) {
1661                            StringBundler msg = new StringBundler(8);
1662    
1663                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1664    
1665                            msg.append("classNameId=");
1666                            msg.append(classNameId);
1667    
1668                            msg.append(", classPK=");
1669                            msg.append(classPK);
1670    
1671                            msg.append(", alert=");
1672                            msg.append(alert);
1673    
1674                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1675    
1676                            throw new NoSuchEntryException(msg.toString());
1677                    }
1678                    else {
1679                            return list.get(0);
1680                    }
1681            }
1682    
1683            /**
1684             * Finds the last announcements entry in the ordered set where classNameId = &#63; and classPK = &#63; and alert = &#63;.
1685             *
1686             * <p>
1687             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1688             * </p>
1689             *
1690             * @param classNameId the class name id to search with
1691             * @param classPK the class p k to search with
1692             * @param alert the alert to search with
1693             * @param orderByComparator the comparator to order the set by
1694             * @return the last matching announcements entry
1695             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
1696             * @throws SystemException if a system exception occurred
1697             */
1698            public AnnouncementsEntry findByC_C_A_Last(long classNameId, long classPK,
1699                    boolean alert, OrderByComparator orderByComparator)
1700                    throws NoSuchEntryException, SystemException {
1701                    int count = countByC_C_A(classNameId, classPK, alert);
1702    
1703                    List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
1704                                    alert, count - 1, count, orderByComparator);
1705    
1706                    if (list.isEmpty()) {
1707                            StringBundler msg = new StringBundler(8);
1708    
1709                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1710    
1711                            msg.append("classNameId=");
1712                            msg.append(classNameId);
1713    
1714                            msg.append(", classPK=");
1715                            msg.append(classPK);
1716    
1717                            msg.append(", alert=");
1718                            msg.append(alert);
1719    
1720                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1721    
1722                            throw new NoSuchEntryException(msg.toString());
1723                    }
1724                    else {
1725                            return list.get(0);
1726                    }
1727            }
1728    
1729            /**
1730             * Finds the announcements entries before and after the current announcements entry in the ordered set where classNameId = &#63; and classPK = &#63; and alert = &#63;.
1731             *
1732             * <p>
1733             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1734             * </p>
1735             *
1736             * @param entryId the primary key of the current announcements entry
1737             * @param classNameId the class name id to search with
1738             * @param classPK the class p k to search with
1739             * @param alert the alert to search with
1740             * @param orderByComparator the comparator to order the set by
1741             * @return the previous, current, and next announcements entry
1742             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
1743             * @throws SystemException if a system exception occurred
1744             */
1745            public AnnouncementsEntry[] findByC_C_A_PrevAndNext(long entryId,
1746                    long classNameId, long classPK, boolean alert,
1747                    OrderByComparator orderByComparator)
1748                    throws NoSuchEntryException, SystemException {
1749                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1750    
1751                    Session session = null;
1752    
1753                    try {
1754                            session = openSession();
1755    
1756                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1757    
1758                            array[0] = getByC_C_A_PrevAndNext(session, announcementsEntry,
1759                                            classNameId, classPK, alert, orderByComparator, true);
1760    
1761                            array[1] = announcementsEntry;
1762    
1763                            array[2] = getByC_C_A_PrevAndNext(session, announcementsEntry,
1764                                            classNameId, classPK, alert, orderByComparator, false);
1765    
1766                            return array;
1767                    }
1768                    catch (Exception e) {
1769                            throw processException(e);
1770                    }
1771                    finally {
1772                            closeSession(session);
1773                    }
1774            }
1775    
1776            protected AnnouncementsEntry getByC_C_A_PrevAndNext(Session session,
1777                    AnnouncementsEntry announcementsEntry, long classNameId, long classPK,
1778                    boolean alert, OrderByComparator orderByComparator, boolean previous) {
1779                    StringBundler query = null;
1780    
1781                    if (orderByComparator != null) {
1782                            query = new StringBundler(6 +
1783                                            (orderByComparator.getOrderByFields().length * 6));
1784                    }
1785                    else {
1786                            query = new StringBundler(3);
1787                    }
1788    
1789                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1790    
1791                    query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
1792    
1793                    query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
1794    
1795                    query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
1796    
1797                    if (orderByComparator != null) {
1798                            String[] orderByFields = orderByComparator.getOrderByFields();
1799    
1800                            if (orderByFields.length > 0) {
1801                                    query.append(WHERE_AND);
1802                            }
1803    
1804                            for (int i = 0; i < orderByFields.length; i++) {
1805                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1806                                    query.append(orderByFields[i]);
1807    
1808                                    if ((i + 1) < orderByFields.length) {
1809                                            if (orderByComparator.isAscending() ^ previous) {
1810                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1811                                            }
1812                                            else {
1813                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1814                                            }
1815                                    }
1816                                    else {
1817                                            if (orderByComparator.isAscending() ^ previous) {
1818                                                    query.append(WHERE_GREATER_THAN);
1819                                            }
1820                                            else {
1821                                                    query.append(WHERE_LESSER_THAN);
1822                                            }
1823                                    }
1824                            }
1825    
1826                            query.append(ORDER_BY_CLAUSE);
1827    
1828                            for (int i = 0; i < orderByFields.length; i++) {
1829                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1830                                    query.append(orderByFields[i]);
1831    
1832                                    if ((i + 1) < orderByFields.length) {
1833                                            if (orderByComparator.isAscending() ^ previous) {
1834                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1835                                            }
1836                                            else {
1837                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1838                                            }
1839                                    }
1840                                    else {
1841                                            if (orderByComparator.isAscending() ^ previous) {
1842                                                    query.append(ORDER_BY_ASC);
1843                                            }
1844                                            else {
1845                                                    query.append(ORDER_BY_DESC);
1846                                            }
1847                                    }
1848                            }
1849                    }
1850    
1851                    else {
1852                            query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1853                    }
1854    
1855                    String sql = query.toString();
1856    
1857                    Query q = session.createQuery(sql);
1858    
1859                    q.setFirstResult(0);
1860                    q.setMaxResults(2);
1861    
1862                    QueryPos qPos = QueryPos.getInstance(q);
1863    
1864                    qPos.add(classNameId);
1865    
1866                    qPos.add(classPK);
1867    
1868                    qPos.add(alert);
1869    
1870                    if (orderByComparator != null) {
1871                            Object[] values = orderByComparator.getOrderByValues(announcementsEntry);
1872    
1873                            for (Object value : values) {
1874                                    qPos.add(value);
1875                            }
1876                    }
1877    
1878                    List<AnnouncementsEntry> list = q.list();
1879    
1880                    if (list.size() == 2) {
1881                            return list.get(1);
1882                    }
1883                    else {
1884                            return null;
1885                    }
1886            }
1887    
1888            /**
1889             * Finds all the announcements entries.
1890             *
1891             * @return the announcements entries
1892             * @throws SystemException if a system exception occurred
1893             */
1894            public List<AnnouncementsEntry> findAll() throws SystemException {
1895                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1896            }
1897    
1898            /**
1899             * Finds a range of all the announcements entries.
1900             *
1901             * <p>
1902             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1903             * </p>
1904             *
1905             * @param start the lower bound of the range of announcements entries to return
1906             * @param end the upper bound of the range of announcements entries to return (not inclusive)
1907             * @return the range of announcements entries
1908             * @throws SystemException if a system exception occurred
1909             */
1910            public List<AnnouncementsEntry> findAll(int start, int end)
1911                    throws SystemException {
1912                    return findAll(start, end, null);
1913            }
1914    
1915            /**
1916             * Finds an ordered range of all the announcements entries.
1917             *
1918             * <p>
1919             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1920             * </p>
1921             *
1922             * @param start the lower bound of the range of announcements entries to return
1923             * @param end the upper bound of the range of announcements entries to return (not inclusive)
1924             * @param orderByComparator the comparator to order the results by
1925             * @return the ordered range of announcements entries
1926             * @throws SystemException if a system exception occurred
1927             */
1928            public List<AnnouncementsEntry> findAll(int start, int end,
1929                    OrderByComparator orderByComparator) throws SystemException {
1930                    Object[] finderArgs = new Object[] {
1931                                    String.valueOf(start), String.valueOf(end),
1932                                    String.valueOf(orderByComparator)
1933                            };
1934    
1935                    List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1936                                    finderArgs, this);
1937    
1938                    if (list == null) {
1939                            Session session = null;
1940    
1941                            try {
1942                                    session = openSession();
1943    
1944                                    StringBundler query = null;
1945                                    String sql = null;
1946    
1947                                    if (orderByComparator != null) {
1948                                            query = new StringBundler(2 +
1949                                                            (orderByComparator.getOrderByFields().length * 3));
1950    
1951                                            query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY);
1952    
1953                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1954                                                    orderByComparator);
1955    
1956                                            sql = query.toString();
1957                                    }
1958                                    else {
1959                                            sql = _SQL_SELECT_ANNOUNCEMENTSENTRY.concat(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1960                                    }
1961    
1962                                    Query q = session.createQuery(sql);
1963    
1964                                    if (orderByComparator == null) {
1965                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1966                                                            getDialect(), start, end, false);
1967    
1968                                            Collections.sort(list);
1969                                    }
1970                                    else {
1971                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1972                                                            getDialect(), start, end);
1973                                    }
1974                            }
1975                            catch (Exception e) {
1976                                    throw processException(e);
1977                            }
1978                            finally {
1979                                    if (list == null) {
1980                                            list = new ArrayList<AnnouncementsEntry>();
1981                                    }
1982    
1983                                    cacheResult(list);
1984    
1985                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1986    
1987                                    closeSession(session);
1988                            }
1989                    }
1990    
1991                    return list;
1992            }
1993    
1994            /**
1995             * Removes all the announcements entries where uuid = &#63; from the database.
1996             *
1997             * @param uuid the uuid to search with
1998             * @throws SystemException if a system exception occurred
1999             */
2000            public void removeByUuid(String uuid) throws SystemException {
2001                    for (AnnouncementsEntry announcementsEntry : findByUuid(uuid)) {
2002                            remove(announcementsEntry);
2003                    }
2004            }
2005    
2006            /**
2007             * Removes all the announcements entries where userId = &#63; from the database.
2008             *
2009             * @param userId the user id to search with
2010             * @throws SystemException if a system exception occurred
2011             */
2012            public void removeByUserId(long userId) throws SystemException {
2013                    for (AnnouncementsEntry announcementsEntry : findByUserId(userId)) {
2014                            remove(announcementsEntry);
2015                    }
2016            }
2017    
2018            /**
2019             * Removes all the announcements entries where classNameId = &#63; and classPK = &#63; from the database.
2020             *
2021             * @param classNameId the class name id to search with
2022             * @param classPK the class p k to search with
2023             * @throws SystemException if a system exception occurred
2024             */
2025            public void removeByC_C(long classNameId, long classPK)
2026                    throws SystemException {
2027                    for (AnnouncementsEntry announcementsEntry : findByC_C(classNameId,
2028                                    classPK)) {
2029                            remove(announcementsEntry);
2030                    }
2031            }
2032    
2033            /**
2034             * Removes all the announcements entries where classNameId = &#63; and classPK = &#63; and alert = &#63; from the database.
2035             *
2036             * @param classNameId the class name id to search with
2037             * @param classPK the class p k to search with
2038             * @param alert the alert to search with
2039             * @throws SystemException if a system exception occurred
2040             */
2041            public void removeByC_C_A(long classNameId, long classPK, boolean alert)
2042                    throws SystemException {
2043                    for (AnnouncementsEntry announcementsEntry : findByC_C_A(classNameId,
2044                                    classPK, alert)) {
2045                            remove(announcementsEntry);
2046                    }
2047            }
2048    
2049            /**
2050             * Removes all the announcements entries from the database.
2051             *
2052             * @throws SystemException if a system exception occurred
2053             */
2054            public void removeAll() throws SystemException {
2055                    for (AnnouncementsEntry announcementsEntry : findAll()) {
2056                            remove(announcementsEntry);
2057                    }
2058            }
2059    
2060            /**
2061             * Counts all the announcements entries where uuid = &#63;.
2062             *
2063             * @param uuid the uuid to search with
2064             * @return the number of matching announcements entries
2065             * @throws SystemException if a system exception occurred
2066             */
2067            public int countByUuid(String uuid) throws SystemException {
2068                    Object[] finderArgs = new Object[] { uuid };
2069    
2070                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2071                                    finderArgs, this);
2072    
2073                    if (count == null) {
2074                            Session session = null;
2075    
2076                            try {
2077                                    session = openSession();
2078    
2079                                    StringBundler query = new StringBundler(2);
2080    
2081                                    query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2082    
2083                                    if (uuid == null) {
2084                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
2085                                    }
2086                                    else {
2087                                            if (uuid.equals(StringPool.BLANK)) {
2088                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
2089                                            }
2090                                            else {
2091                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
2092                                            }
2093                                    }
2094    
2095                                    String sql = query.toString();
2096    
2097                                    Query q = session.createQuery(sql);
2098    
2099                                    QueryPos qPos = QueryPos.getInstance(q);
2100    
2101                                    if (uuid != null) {
2102                                            qPos.add(uuid);
2103                                    }
2104    
2105                                    count = (Long)q.uniqueResult();
2106                            }
2107                            catch (Exception e) {
2108                                    throw processException(e);
2109                            }
2110                            finally {
2111                                    if (count == null) {
2112                                            count = Long.valueOf(0);
2113                                    }
2114    
2115                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2116                                            finderArgs, count);
2117    
2118                                    closeSession(session);
2119                            }
2120                    }
2121    
2122                    return count.intValue();
2123            }
2124    
2125            /**
2126             * Counts all the announcements entries where userId = &#63;.
2127             *
2128             * @param userId the user id to search with
2129             * @return the number of matching announcements entries
2130             * @throws SystemException if a system exception occurred
2131             */
2132            public int countByUserId(long userId) throws SystemException {
2133                    Object[] finderArgs = new Object[] { userId };
2134    
2135                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2136                                    finderArgs, this);
2137    
2138                    if (count == null) {
2139                            Session session = null;
2140    
2141                            try {
2142                                    session = openSession();
2143    
2144                                    StringBundler query = new StringBundler(2);
2145    
2146                                    query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2147    
2148                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2149    
2150                                    String sql = query.toString();
2151    
2152                                    Query q = session.createQuery(sql);
2153    
2154                                    QueryPos qPos = QueryPos.getInstance(q);
2155    
2156                                    qPos.add(userId);
2157    
2158                                    count = (Long)q.uniqueResult();
2159                            }
2160                            catch (Exception e) {
2161                                    throw processException(e);
2162                            }
2163                            finally {
2164                                    if (count == null) {
2165                                            count = Long.valueOf(0);
2166                                    }
2167    
2168                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2169                                            finderArgs, count);
2170    
2171                                    closeSession(session);
2172                            }
2173                    }
2174    
2175                    return count.intValue();
2176            }
2177    
2178            /**
2179             * Counts all the announcements entries where classNameId = &#63; and classPK = &#63;.
2180             *
2181             * @param classNameId the class name id to search with
2182             * @param classPK the class p k to search with
2183             * @return the number of matching announcements entries
2184             * @throws SystemException if a system exception occurred
2185             */
2186            public int countByC_C(long classNameId, long classPK)
2187                    throws SystemException {
2188                    Object[] finderArgs = new Object[] { classNameId, classPK };
2189    
2190                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
2191                                    finderArgs, this);
2192    
2193                    if (count == null) {
2194                            Session session = null;
2195    
2196                            try {
2197                                    session = openSession();
2198    
2199                                    StringBundler query = new StringBundler(3);
2200    
2201                                    query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2202    
2203                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2204    
2205                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2206    
2207                                    String sql = query.toString();
2208    
2209                                    Query q = session.createQuery(sql);
2210    
2211                                    QueryPos qPos = QueryPos.getInstance(q);
2212    
2213                                    qPos.add(classNameId);
2214    
2215                                    qPos.add(classPK);
2216    
2217                                    count = (Long)q.uniqueResult();
2218                            }
2219                            catch (Exception e) {
2220                                    throw processException(e);
2221                            }
2222                            finally {
2223                                    if (count == null) {
2224                                            count = Long.valueOf(0);
2225                                    }
2226    
2227                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
2228                                            count);
2229    
2230                                    closeSession(session);
2231                            }
2232                    }
2233    
2234                    return count.intValue();
2235            }
2236    
2237            /**
2238             * Counts all the announcements entries where classNameId = &#63; and classPK = &#63; and alert = &#63;.
2239             *
2240             * @param classNameId the class name id to search with
2241             * @param classPK the class p k to search with
2242             * @param alert the alert to search with
2243             * @return the number of matching announcements entries
2244             * @throws SystemException if a system exception occurred
2245             */
2246            public int countByC_C_A(long classNameId, long classPK, boolean alert)
2247                    throws SystemException {
2248                    Object[] finderArgs = new Object[] { classNameId, classPK, alert };
2249    
2250                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_A,
2251                                    finderArgs, this);
2252    
2253                    if (count == null) {
2254                            Session session = null;
2255    
2256                            try {
2257                                    session = openSession();
2258    
2259                                    StringBundler query = new StringBundler(4);
2260    
2261                                    query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2262    
2263                                    query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
2264    
2265                                    query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
2266    
2267                                    query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
2268    
2269                                    String sql = query.toString();
2270    
2271                                    Query q = session.createQuery(sql);
2272    
2273                                    QueryPos qPos = QueryPos.getInstance(q);
2274    
2275                                    qPos.add(classNameId);
2276    
2277                                    qPos.add(classPK);
2278    
2279                                    qPos.add(alert);
2280    
2281                                    count = (Long)q.uniqueResult();
2282                            }
2283                            catch (Exception e) {
2284                                    throw processException(e);
2285                            }
2286                            finally {
2287                                    if (count == null) {
2288                                            count = Long.valueOf(0);
2289                                    }
2290    
2291                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_A,
2292                                            finderArgs, count);
2293    
2294                                    closeSession(session);
2295                            }
2296                    }
2297    
2298                    return count.intValue();
2299            }
2300    
2301            /**
2302             * Counts all the announcements entries.
2303             *
2304             * @return the number of announcements entries
2305             * @throws SystemException if a system exception occurred
2306             */
2307            public int countAll() throws SystemException {
2308                    Object[] finderArgs = new Object[0];
2309    
2310                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2311                                    finderArgs, this);
2312    
2313                    if (count == null) {
2314                            Session session = null;
2315    
2316                            try {
2317                                    session = openSession();
2318    
2319                                    Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSENTRY);
2320    
2321                                    count = (Long)q.uniqueResult();
2322                            }
2323                            catch (Exception e) {
2324                                    throw processException(e);
2325                            }
2326                            finally {
2327                                    if (count == null) {
2328                                            count = Long.valueOf(0);
2329                                    }
2330    
2331                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2332                                            count);
2333    
2334                                    closeSession(session);
2335                            }
2336                    }
2337    
2338                    return count.intValue();
2339            }
2340    
2341            /**
2342             * Initializes the announcements entry persistence.
2343             */
2344            public void afterPropertiesSet() {
2345                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2346                                            com.liferay.portal.util.PropsUtil.get(
2347                                                    "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsEntry")));
2348    
2349                    if (listenerClassNames.length > 0) {
2350                            try {
2351                                    List<ModelListener<AnnouncementsEntry>> listenersList = new ArrayList<ModelListener<AnnouncementsEntry>>();
2352    
2353                                    for (String listenerClassName : listenerClassNames) {
2354                                            listenersList.add((ModelListener<AnnouncementsEntry>)InstanceFactory.newInstance(
2355                                                            listenerClassName));
2356                                    }
2357    
2358                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2359                            }
2360                            catch (Exception e) {
2361                                    _log.error(e);
2362                            }
2363                    }
2364            }
2365    
2366            public void destroy() {
2367                    EntityCacheUtil.removeCache(AnnouncementsEntryImpl.class.getName());
2368                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2369                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2370            }
2371    
2372            @BeanReference(type = AnnouncementsDeliveryPersistence.class)
2373            protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
2374            @BeanReference(type = AnnouncementsEntryPersistence.class)
2375            protected AnnouncementsEntryPersistence announcementsEntryPersistence;
2376            @BeanReference(type = AnnouncementsFlagPersistence.class)
2377            protected AnnouncementsFlagPersistence announcementsFlagPersistence;
2378            @BeanReference(type = CompanyPersistence.class)
2379            protected CompanyPersistence companyPersistence;
2380            @BeanReference(type = GroupPersistence.class)
2381            protected GroupPersistence groupPersistence;
2382            @BeanReference(type = OrganizationPersistence.class)
2383            protected OrganizationPersistence organizationPersistence;
2384            @BeanReference(type = ResourcePersistence.class)
2385            protected ResourcePersistence resourcePersistence;
2386            @BeanReference(type = RolePersistence.class)
2387            protected RolePersistence rolePersistence;
2388            @BeanReference(type = UserPersistence.class)
2389            protected UserPersistence userPersistence;
2390            @BeanReference(type = UserGroupPersistence.class)
2391            protected UserGroupPersistence userGroupPersistence;
2392            private static final String _SQL_SELECT_ANNOUNCEMENTSENTRY = "SELECT announcementsEntry FROM AnnouncementsEntry announcementsEntry";
2393            private static final String _SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE = "SELECT announcementsEntry FROM AnnouncementsEntry announcementsEntry WHERE ";
2394            private static final String _SQL_COUNT_ANNOUNCEMENTSENTRY = "SELECT COUNT(announcementsEntry) FROM AnnouncementsEntry announcementsEntry";
2395            private static final String _SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE = "SELECT COUNT(announcementsEntry) FROM AnnouncementsEntry announcementsEntry WHERE ";
2396            private static final String _FINDER_COLUMN_UUID_UUID_1 = "announcementsEntry.uuid IS NULL";
2397            private static final String _FINDER_COLUMN_UUID_UUID_2 = "announcementsEntry.uuid = ?";
2398            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(announcementsEntry.uuid IS NULL OR announcementsEntry.uuid = ?)";
2399            private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsEntry.userId = ?";
2400            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "announcementsEntry.classNameId = ? AND ";
2401            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "announcementsEntry.classPK = ?";
2402            private static final String _FINDER_COLUMN_C_C_A_CLASSNAMEID_2 = "announcementsEntry.classNameId = ? AND ";
2403            private static final String _FINDER_COLUMN_C_C_A_CLASSPK_2 = "announcementsEntry.classPK = ? AND ";
2404            private static final String _FINDER_COLUMN_C_C_A_ALERT_2 = "announcementsEntry.alert = ?";
2405            private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsEntry.";
2406            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsEntry exists with the primary key ";
2407            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsEntry exists with the key {";
2408            private static Log _log = LogFactoryUtil.getLog(AnnouncementsEntryPersistenceImpl.class);
2409    }