001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.announcements.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.SQLQuery;
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.UnmodifiableList;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import com.liferay.portlet.announcements.NoSuchEntryException;
045    import com.liferay.portlet.announcements.model.AnnouncementsEntry;
046    import com.liferay.portlet.announcements.model.impl.AnnouncementsEntryImpl;
047    import com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    
055    /**
056     * The persistence implementation for the announcements entry service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see AnnouncementsEntryPersistence
064     * @see AnnouncementsEntryUtil
065     * @generated
066     */
067    public class AnnouncementsEntryPersistenceImpl extends BasePersistenceImpl<AnnouncementsEntry>
068            implements AnnouncementsEntryPersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * 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.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsEntryImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
080                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
081                            AnnouncementsEntryImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
084                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
085                            AnnouncementsEntryImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
088                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
091                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
092                            AnnouncementsEntryImpl.class,
093                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
094                            new String[] {
095                                    String.class.getName(),
096                                    
097                            Integer.class.getName(), Integer.class.getName(),
098                                    OrderByComparator.class.getName()
099                            });
100            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
101                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
102                            AnnouncementsEntryImpl.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
104                            new String[] { String.class.getName() },
105                            AnnouncementsEntryModelImpl.UUID_COLUMN_BITMASK |
106                            AnnouncementsEntryModelImpl.PRIORITY_COLUMN_BITMASK |
107                            AnnouncementsEntryModelImpl.MODIFIEDDATE_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
109                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
111                            new String[] { String.class.getName() });
112    
113            /**
114             * Returns all the announcements entries where uuid = &#63;.
115             *
116             * @param uuid the uuid
117             * @return the matching announcements entries
118             * @throws SystemException if a system exception occurred
119             */
120            public List<AnnouncementsEntry> findByUuid(String uuid)
121                    throws SystemException {
122                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123            }
124    
125            /**
126             * Returns a range of all the announcements entries where uuid = &#63;.
127             *
128             * <p>
129             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
130             * </p>
131             *
132             * @param uuid the uuid
133             * @param start the lower bound of the range of announcements entries
134             * @param end the upper bound of the range of announcements entries (not inclusive)
135             * @return the range of matching announcements entries
136             * @throws SystemException if a system exception occurred
137             */
138            public List<AnnouncementsEntry> findByUuid(String uuid, int start, int end)
139                    throws SystemException {
140                    return findByUuid(uuid, start, end, null);
141            }
142    
143            /**
144             * Returns an ordered range of all the announcements entries where uuid = &#63;.
145             *
146             * <p>
147             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
148             * </p>
149             *
150             * @param uuid the uuid
151             * @param start the lower bound of the range of announcements entries
152             * @param end the upper bound of the range of announcements entries (not inclusive)
153             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
154             * @return the ordered range of matching announcements entries
155             * @throws SystemException if a system exception occurred
156             */
157            public List<AnnouncementsEntry> findByUuid(String uuid, int start, int end,
158                    OrderByComparator orderByComparator) throws SystemException {
159                    boolean pagination = true;
160                    FinderPath finderPath = null;
161                    Object[] finderArgs = null;
162    
163                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
164                                    (orderByComparator == null)) {
165                            pagination = false;
166                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
167                            finderArgs = new Object[] { uuid };
168                    }
169                    else {
170                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
171                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
172                    }
173    
174                    List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(finderPath,
175                                    finderArgs, this);
176    
177                    if ((list != null) && !list.isEmpty()) {
178                            for (AnnouncementsEntry announcementsEntry : list) {
179                                    if (!Validator.equals(uuid, announcementsEntry.getUuid())) {
180                                            list = null;
181    
182                                            break;
183                                    }
184                            }
185                    }
186    
187                    if (list == null) {
188                            StringBundler query = null;
189    
190                            if (orderByComparator != null) {
191                                    query = new StringBundler(3 +
192                                                    (orderByComparator.getOrderByFields().length * 3));
193                            }
194                            else {
195                                    query = new StringBundler(3);
196                            }
197    
198                            query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
199    
200                            if (uuid == null) {
201                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
202                            }
203                            else {
204                                    if (uuid.equals(StringPool.BLANK)) {
205                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
206                                    }
207                                    else {
208                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
209                                    }
210                            }
211    
212                            if (orderByComparator != null) {
213                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
214                                            orderByComparator);
215                            }
216                            else
217                             if (pagination) {
218                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
219                            }
220    
221                            String sql = query.toString();
222    
223                            Session session = null;
224    
225                            try {
226                                    session = openSession();
227    
228                                    Query q = session.createQuery(sql);
229    
230                                    QueryPos qPos = QueryPos.getInstance(q);
231    
232                                    if (uuid != null) {
233                                            qPos.add(uuid);
234                                    }
235    
236                                    if (!pagination) {
237                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
238                                                            getDialect(), start, end, false);
239    
240                                            Collections.sort(list);
241    
242                                            list = new UnmodifiableList<AnnouncementsEntry>(list);
243                                    }
244                                    else {
245                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
246                                                            getDialect(), start, end);
247                                    }
248    
249                                    cacheResult(list);
250    
251                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
252                            }
253                            catch (Exception e) {
254                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
255    
256                                    throw processException(e);
257                            }
258                            finally {
259                                    closeSession(session);
260                            }
261                    }
262    
263                    return list;
264            }
265    
266            /**
267             * Returns the first announcements entry in the ordered set where uuid = &#63;.
268             *
269             * @param uuid the uuid
270             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
271             * @return the first matching announcements entry
272             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
273             * @throws SystemException if a system exception occurred
274             */
275            public AnnouncementsEntry findByUuid_First(String uuid,
276                    OrderByComparator orderByComparator)
277                    throws NoSuchEntryException, SystemException {
278                    AnnouncementsEntry announcementsEntry = fetchByUuid_First(uuid,
279                                    orderByComparator);
280    
281                    if (announcementsEntry != null) {
282                            return announcementsEntry;
283                    }
284    
285                    StringBundler msg = new StringBundler(4);
286    
287                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
288    
289                    msg.append("uuid=");
290                    msg.append(uuid);
291    
292                    msg.append(StringPool.CLOSE_CURLY_BRACE);
293    
294                    throw new NoSuchEntryException(msg.toString());
295            }
296    
297            /**
298             * Returns the first announcements entry in the ordered set where uuid = &#63;.
299             *
300             * @param uuid the uuid
301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
302             * @return the first matching announcements entry, or <code>null</code> if a matching announcements entry could not be found
303             * @throws SystemException if a system exception occurred
304             */
305            public AnnouncementsEntry fetchByUuid_First(String uuid,
306                    OrderByComparator orderByComparator) throws SystemException {
307                    List<AnnouncementsEntry> list = findByUuid(uuid, 0, 1, orderByComparator);
308    
309                    if (!list.isEmpty()) {
310                            return list.get(0);
311                    }
312    
313                    return null;
314            }
315    
316            /**
317             * Returns the last announcements entry in the ordered set where uuid = &#63;.
318             *
319             * @param uuid the uuid
320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
321             * @return the last matching announcements entry
322             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
323             * @throws SystemException if a system exception occurred
324             */
325            public AnnouncementsEntry findByUuid_Last(String uuid,
326                    OrderByComparator orderByComparator)
327                    throws NoSuchEntryException, SystemException {
328                    AnnouncementsEntry announcementsEntry = fetchByUuid_Last(uuid,
329                                    orderByComparator);
330    
331                    if (announcementsEntry != null) {
332                            return announcementsEntry;
333                    }
334    
335                    StringBundler msg = new StringBundler(4);
336    
337                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
338    
339                    msg.append("uuid=");
340                    msg.append(uuid);
341    
342                    msg.append(StringPool.CLOSE_CURLY_BRACE);
343    
344                    throw new NoSuchEntryException(msg.toString());
345            }
346    
347            /**
348             * Returns the last announcements entry in the ordered set where uuid = &#63;.
349             *
350             * @param uuid the uuid
351             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
352             * @return the last matching announcements entry, or <code>null</code> if a matching announcements entry could not be found
353             * @throws SystemException if a system exception occurred
354             */
355            public AnnouncementsEntry fetchByUuid_Last(String uuid,
356                    OrderByComparator orderByComparator) throws SystemException {
357                    int count = countByUuid(uuid);
358    
359                    List<AnnouncementsEntry> list = findByUuid(uuid, count - 1, count,
360                                    orderByComparator);
361    
362                    if (!list.isEmpty()) {
363                            return list.get(0);
364                    }
365    
366                    return null;
367            }
368    
369            /**
370             * Returns the announcements entries before and after the current announcements entry in the ordered set where uuid = &#63;.
371             *
372             * @param entryId the primary key of the current announcements entry
373             * @param uuid the uuid
374             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
375             * @return the previous, current, and next announcements entry
376             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
377             * @throws SystemException if a system exception occurred
378             */
379            public AnnouncementsEntry[] findByUuid_PrevAndNext(long entryId,
380                    String uuid, OrderByComparator orderByComparator)
381                    throws NoSuchEntryException, SystemException {
382                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
383    
384                    Session session = null;
385    
386                    try {
387                            session = openSession();
388    
389                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
390    
391                            array[0] = getByUuid_PrevAndNext(session, announcementsEntry, uuid,
392                                            orderByComparator, true);
393    
394                            array[1] = announcementsEntry;
395    
396                            array[2] = getByUuid_PrevAndNext(session, announcementsEntry, uuid,
397                                            orderByComparator, false);
398    
399                            return array;
400                    }
401                    catch (Exception e) {
402                            throw processException(e);
403                    }
404                    finally {
405                            closeSession(session);
406                    }
407            }
408    
409            protected AnnouncementsEntry getByUuid_PrevAndNext(Session session,
410                    AnnouncementsEntry announcementsEntry, String uuid,
411                    OrderByComparator orderByComparator, boolean previous) {
412                    StringBundler query = null;
413    
414                    if (orderByComparator != null) {
415                            query = new StringBundler(6 +
416                                            (orderByComparator.getOrderByFields().length * 6));
417                    }
418                    else {
419                            query = new StringBundler(3);
420                    }
421    
422                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
423    
424                    if (uuid == null) {
425                            query.append(_FINDER_COLUMN_UUID_UUID_1);
426                    }
427                    else {
428                            if (uuid.equals(StringPool.BLANK)) {
429                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
430                            }
431                            else {
432                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
433                            }
434                    }
435    
436                    if (orderByComparator != null) {
437                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
438    
439                            if (orderByConditionFields.length > 0) {
440                                    query.append(WHERE_AND);
441                            }
442    
443                            for (int i = 0; i < orderByConditionFields.length; i++) {
444                                    query.append(_ORDER_BY_ENTITY_ALIAS);
445                                    query.append(orderByConditionFields[i]);
446    
447                                    if ((i + 1) < orderByConditionFields.length) {
448                                            if (orderByComparator.isAscending() ^ previous) {
449                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
450                                            }
451                                            else {
452                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
453                                            }
454                                    }
455                                    else {
456                                            if (orderByComparator.isAscending() ^ previous) {
457                                                    query.append(WHERE_GREATER_THAN);
458                                            }
459                                            else {
460                                                    query.append(WHERE_LESSER_THAN);
461                                            }
462                                    }
463                            }
464    
465                            query.append(ORDER_BY_CLAUSE);
466    
467                            String[] orderByFields = orderByComparator.getOrderByFields();
468    
469                            for (int i = 0; i < orderByFields.length; i++) {
470                                    query.append(_ORDER_BY_ENTITY_ALIAS);
471                                    query.append(orderByFields[i]);
472    
473                                    if ((i + 1) < orderByFields.length) {
474                                            if (orderByComparator.isAscending() ^ previous) {
475                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
476                                            }
477                                            else {
478                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
479                                            }
480                                    }
481                                    else {
482                                            if (orderByComparator.isAscending() ^ previous) {
483                                                    query.append(ORDER_BY_ASC);
484                                            }
485                                            else {
486                                                    query.append(ORDER_BY_DESC);
487                                            }
488                                    }
489                            }
490                    }
491                    else {
492                            query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
493                    }
494    
495                    String sql = query.toString();
496    
497                    Query q = session.createQuery(sql);
498    
499                    q.setFirstResult(0);
500                    q.setMaxResults(2);
501    
502                    QueryPos qPos = QueryPos.getInstance(q);
503    
504                    if (uuid != null) {
505                            qPos.add(uuid);
506                    }
507    
508                    if (orderByComparator != null) {
509                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsEntry);
510    
511                            for (Object value : values) {
512                                    qPos.add(value);
513                            }
514                    }
515    
516                    List<AnnouncementsEntry> list = q.list();
517    
518                    if (list.size() == 2) {
519                            return list.get(1);
520                    }
521                    else {
522                            return null;
523                    }
524            }
525    
526            /**
527             * Returns all the announcements entries that the user has permission to view where uuid = &#63;.
528             *
529             * @param uuid the uuid
530             * @return the matching announcements entries that the user has permission to view
531             * @throws SystemException if a system exception occurred
532             */
533            public List<AnnouncementsEntry> filterFindByUuid(String uuid)
534                    throws SystemException {
535                    return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
536            }
537    
538            /**
539             * Returns a range of all the announcements entries that the user has permission to view where uuid = &#63;.
540             *
541             * <p>
542             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
543             * </p>
544             *
545             * @param uuid the uuid
546             * @param start the lower bound of the range of announcements entries
547             * @param end the upper bound of the range of announcements entries (not inclusive)
548             * @return the range of matching announcements entries that the user has permission to view
549             * @throws SystemException if a system exception occurred
550             */
551            public List<AnnouncementsEntry> filterFindByUuid(String uuid, int start,
552                    int end) throws SystemException {
553                    return filterFindByUuid(uuid, start, end, null);
554            }
555    
556            /**
557             * Returns an ordered range of all the announcements entries that the user has permissions to view where uuid = &#63;.
558             *
559             * <p>
560             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
561             * </p>
562             *
563             * @param uuid the uuid
564             * @param start the lower bound of the range of announcements entries
565             * @param end the upper bound of the range of announcements entries (not inclusive)
566             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
567             * @return the ordered range of matching announcements entries that the user has permission to view
568             * @throws SystemException if a system exception occurred
569             */
570            public List<AnnouncementsEntry> filterFindByUuid(String uuid, int start,
571                    int end, OrderByComparator orderByComparator) throws SystemException {
572                    if (!InlineSQLHelperUtil.isEnabled()) {
573                            return findByUuid(uuid, start, end, orderByComparator);
574                    }
575    
576                    StringBundler query = null;
577    
578                    if (orderByComparator != null) {
579                            query = new StringBundler(3 +
580                                            (orderByComparator.getOrderByFields().length * 3));
581                    }
582                    else {
583                            query = new StringBundler(3);
584                    }
585    
586                    if (getDB().isSupportsInlineDistinct()) {
587                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
588                    }
589                    else {
590                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_1);
591                    }
592    
593                    if (uuid == null) {
594                            query.append(_FINDER_COLUMN_UUID_UUID_1);
595                    }
596                    else {
597                            if (uuid.equals(StringPool.BLANK)) {
598                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
599                            }
600                            else {
601                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
602                            }
603                    }
604    
605                    if (!getDB().isSupportsInlineDistinct()) {
606                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_2);
607                    }
608    
609                    if (orderByComparator != null) {
610                            if (getDB().isSupportsInlineDistinct()) {
611                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
612                                            orderByComparator);
613                            }
614                            else {
615                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
616                                            orderByComparator);
617                            }
618                    }
619                    else {
620                            if (getDB().isSupportsInlineDistinct()) {
621                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
622                            }
623                            else {
624                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_SQL);
625                            }
626                    }
627    
628                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
629                                    AnnouncementsEntry.class.getName(),
630                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
631    
632                    Session session = null;
633    
634                    try {
635                            session = openSession();
636    
637                            SQLQuery q = session.createSQLQuery(sql);
638    
639                            if (getDB().isSupportsInlineDistinct()) {
640                                    q.addEntity(_FILTER_ENTITY_ALIAS, AnnouncementsEntryImpl.class);
641                            }
642                            else {
643                                    q.addEntity(_FILTER_ENTITY_TABLE, AnnouncementsEntryImpl.class);
644                            }
645    
646                            QueryPos qPos = QueryPos.getInstance(q);
647    
648                            if (uuid != null) {
649                                    qPos.add(uuid);
650                            }
651    
652                            return (List<AnnouncementsEntry>)QueryUtil.list(q, getDialect(),
653                                    start, end);
654                    }
655                    catch (Exception e) {
656                            throw processException(e);
657                    }
658                    finally {
659                            closeSession(session);
660                    }
661            }
662    
663            /**
664             * Returns the announcements entries before and after the current announcements entry in the ordered set of announcements entries that the user has permission to view where uuid = &#63;.
665             *
666             * @param entryId the primary key of the current announcements entry
667             * @param uuid the uuid
668             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
669             * @return the previous, current, and next announcements entry
670             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
671             * @throws SystemException if a system exception occurred
672             */
673            public AnnouncementsEntry[] filterFindByUuid_PrevAndNext(long entryId,
674                    String uuid, OrderByComparator orderByComparator)
675                    throws NoSuchEntryException, SystemException {
676                    if (!InlineSQLHelperUtil.isEnabled()) {
677                            return findByUuid_PrevAndNext(entryId, uuid, orderByComparator);
678                    }
679    
680                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
681    
682                    Session session = null;
683    
684                    try {
685                            session = openSession();
686    
687                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
688    
689                            array[0] = filterGetByUuid_PrevAndNext(session, announcementsEntry,
690                                            uuid, orderByComparator, true);
691    
692                            array[1] = announcementsEntry;
693    
694                            array[2] = filterGetByUuid_PrevAndNext(session, announcementsEntry,
695                                            uuid, orderByComparator, false);
696    
697                            return array;
698                    }
699                    catch (Exception e) {
700                            throw processException(e);
701                    }
702                    finally {
703                            closeSession(session);
704                    }
705            }
706    
707            protected AnnouncementsEntry filterGetByUuid_PrevAndNext(Session session,
708                    AnnouncementsEntry announcementsEntry, String uuid,
709                    OrderByComparator orderByComparator, boolean previous) {
710                    StringBundler query = null;
711    
712                    if (orderByComparator != null) {
713                            query = new StringBundler(6 +
714                                            (orderByComparator.getOrderByFields().length * 6));
715                    }
716                    else {
717                            query = new StringBundler(3);
718                    }
719    
720                    if (getDB().isSupportsInlineDistinct()) {
721                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
722                    }
723                    else {
724                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_1);
725                    }
726    
727                    if (uuid == null) {
728                            query.append(_FINDER_COLUMN_UUID_UUID_1);
729                    }
730                    else {
731                            if (uuid.equals(StringPool.BLANK)) {
732                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
733                            }
734                            else {
735                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
736                            }
737                    }
738    
739                    if (!getDB().isSupportsInlineDistinct()) {
740                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_2);
741                    }
742    
743                    if (orderByComparator != null) {
744                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
745    
746                            if (orderByConditionFields.length > 0) {
747                                    query.append(WHERE_AND);
748                            }
749    
750                            for (int i = 0; i < orderByConditionFields.length; i++) {
751                                    if (getDB().isSupportsInlineDistinct()) {
752                                            query.append(_ORDER_BY_ENTITY_ALIAS);
753                                    }
754                                    else {
755                                            query.append(_ORDER_BY_ENTITY_TABLE);
756                                    }
757    
758                                    query.append(orderByConditionFields[i]);
759    
760                                    if ((i + 1) < orderByConditionFields.length) {
761                                            if (orderByComparator.isAscending() ^ previous) {
762                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
763                                            }
764                                            else {
765                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
766                                            }
767                                    }
768                                    else {
769                                            if (orderByComparator.isAscending() ^ previous) {
770                                                    query.append(WHERE_GREATER_THAN);
771                                            }
772                                            else {
773                                                    query.append(WHERE_LESSER_THAN);
774                                            }
775                                    }
776                            }
777    
778                            query.append(ORDER_BY_CLAUSE);
779    
780                            String[] orderByFields = orderByComparator.getOrderByFields();
781    
782                            for (int i = 0; i < orderByFields.length; i++) {
783                                    if (getDB().isSupportsInlineDistinct()) {
784                                            query.append(_ORDER_BY_ENTITY_ALIAS);
785                                    }
786                                    else {
787                                            query.append(_ORDER_BY_ENTITY_TABLE);
788                                    }
789    
790                                    query.append(orderByFields[i]);
791    
792                                    if ((i + 1) < orderByFields.length) {
793                                            if (orderByComparator.isAscending() ^ previous) {
794                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
795                                            }
796                                            else {
797                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
798                                            }
799                                    }
800                                    else {
801                                            if (orderByComparator.isAscending() ^ previous) {
802                                                    query.append(ORDER_BY_ASC);
803                                            }
804                                            else {
805                                                    query.append(ORDER_BY_DESC);
806                                            }
807                                    }
808                            }
809                    }
810                    else {
811                            if (getDB().isSupportsInlineDistinct()) {
812                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
813                            }
814                            else {
815                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_SQL);
816                            }
817                    }
818    
819                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
820                                    AnnouncementsEntry.class.getName(),
821                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
822    
823                    SQLQuery q = session.createSQLQuery(sql);
824    
825                    q.setFirstResult(0);
826                    q.setMaxResults(2);
827    
828                    if (getDB().isSupportsInlineDistinct()) {
829                            q.addEntity(_FILTER_ENTITY_ALIAS, AnnouncementsEntryImpl.class);
830                    }
831                    else {
832                            q.addEntity(_FILTER_ENTITY_TABLE, AnnouncementsEntryImpl.class);
833                    }
834    
835                    QueryPos qPos = QueryPos.getInstance(q);
836    
837                    if (uuid != null) {
838                            qPos.add(uuid);
839                    }
840    
841                    if (orderByComparator != null) {
842                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsEntry);
843    
844                            for (Object value : values) {
845                                    qPos.add(value);
846                            }
847                    }
848    
849                    List<AnnouncementsEntry> list = q.list();
850    
851                    if (list.size() == 2) {
852                            return list.get(1);
853                    }
854                    else {
855                            return null;
856                    }
857            }
858    
859            /**
860             * Removes all the announcements entries where uuid = &#63; from the database.
861             *
862             * @param uuid the uuid
863             * @throws SystemException if a system exception occurred
864             */
865            public void removeByUuid(String uuid) throws SystemException {
866                    for (AnnouncementsEntry announcementsEntry : findByUuid(uuid,
867                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
868                            remove(announcementsEntry);
869                    }
870            }
871    
872            /**
873             * Returns the number of announcements entries where uuid = &#63;.
874             *
875             * @param uuid the uuid
876             * @return the number of matching announcements entries
877             * @throws SystemException if a system exception occurred
878             */
879            public int countByUuid(String uuid) throws SystemException {
880                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
881    
882                    Object[] finderArgs = new Object[] { uuid };
883    
884                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
885                                    this);
886    
887                    if (count == null) {
888                            StringBundler query = new StringBundler(2);
889    
890                            query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
891    
892                            if (uuid == null) {
893                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
894                            }
895                            else {
896                                    if (uuid.equals(StringPool.BLANK)) {
897                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
898                                    }
899                                    else {
900                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
901                                    }
902                            }
903    
904                            String sql = query.toString();
905    
906                            Session session = null;
907    
908                            try {
909                                    session = openSession();
910    
911                                    Query q = session.createQuery(sql);
912    
913                                    QueryPos qPos = QueryPos.getInstance(q);
914    
915                                    if (uuid != null) {
916                                            qPos.add(uuid);
917                                    }
918    
919                                    count = (Long)q.uniqueResult();
920    
921                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
922                            }
923                            catch (Exception e) {
924                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
925    
926                                    throw processException(e);
927                            }
928                            finally {
929                                    closeSession(session);
930                            }
931                    }
932    
933                    return count.intValue();
934            }
935    
936            /**
937             * Returns the number of announcements entries that the user has permission to view where uuid = &#63;.
938             *
939             * @param uuid the uuid
940             * @return the number of matching announcements entries that the user has permission to view
941             * @throws SystemException if a system exception occurred
942             */
943            public int filterCountByUuid(String uuid) throws SystemException {
944                    if (!InlineSQLHelperUtil.isEnabled()) {
945                            return countByUuid(uuid);
946                    }
947    
948                    StringBundler query = new StringBundler(2);
949    
950                    query.append(_FILTER_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
951    
952                    if (uuid == null) {
953                            query.append(_FINDER_COLUMN_UUID_UUID_1);
954                    }
955                    else {
956                            if (uuid.equals(StringPool.BLANK)) {
957                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
958                            }
959                            else {
960                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
961                            }
962                    }
963    
964                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
965                                    AnnouncementsEntry.class.getName(),
966                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
967    
968                    Session session = null;
969    
970                    try {
971                            session = openSession();
972    
973                            SQLQuery q = session.createSQLQuery(sql);
974    
975                            q.addScalar(COUNT_COLUMN_NAME,
976                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
977    
978                            QueryPos qPos = QueryPos.getInstance(q);
979    
980                            if (uuid != null) {
981                                    qPos.add(uuid);
982                            }
983    
984                            Long count = (Long)q.uniqueResult();
985    
986                            return count.intValue();
987                    }
988                    catch (Exception e) {
989                            throw processException(e);
990                    }
991                    finally {
992                            closeSession(session);
993                    }
994            }
995    
996            private static final String _FINDER_COLUMN_UUID_UUID_1 = "announcementsEntry.uuid IS NULL";
997            private static final String _FINDER_COLUMN_UUID_UUID_2 = "announcementsEntry.uuid = ?";
998            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(announcementsEntry.uuid IS NULL OR announcementsEntry.uuid = ?)";
999            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
1000                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
1001                            AnnouncementsEntryImpl.class,
1002                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1003                            new String[] {
1004                                    String.class.getName(), Long.class.getName(),
1005                                    
1006                            Integer.class.getName(), Integer.class.getName(),
1007                                    OrderByComparator.class.getName()
1008                            });
1009            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1010                    new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
1011                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
1012                            AnnouncementsEntryImpl.class,
1013                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1014                            new String[] { String.class.getName(), Long.class.getName() },
1015                            AnnouncementsEntryModelImpl.UUID_COLUMN_BITMASK |
1016                            AnnouncementsEntryModelImpl.COMPANYID_COLUMN_BITMASK |
1017                            AnnouncementsEntryModelImpl.PRIORITY_COLUMN_BITMASK |
1018                            AnnouncementsEntryModelImpl.MODIFIEDDATE_COLUMN_BITMASK);
1019            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
1020                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1021                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1022                            new String[] { String.class.getName(), Long.class.getName() });
1023    
1024            /**
1025             * Returns all the announcements entries where uuid = &#63; and companyId = &#63;.
1026             *
1027             * @param uuid the uuid
1028             * @param companyId the company ID
1029             * @return the matching announcements entries
1030             * @throws SystemException if a system exception occurred
1031             */
1032            public List<AnnouncementsEntry> findByUuid_C(String uuid, long companyId)
1033                    throws SystemException {
1034                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1035                            QueryUtil.ALL_POS, null);
1036            }
1037    
1038            /**
1039             * Returns a range of all the announcements entries where uuid = &#63; and companyId = &#63;.
1040             *
1041             * <p>
1042             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1043             * </p>
1044             *
1045             * @param uuid the uuid
1046             * @param companyId the company ID
1047             * @param start the lower bound of the range of announcements entries
1048             * @param end the upper bound of the range of announcements entries (not inclusive)
1049             * @return the range of matching announcements entries
1050             * @throws SystemException if a system exception occurred
1051             */
1052            public List<AnnouncementsEntry> findByUuid_C(String uuid, long companyId,
1053                    int start, int end) throws SystemException {
1054                    return findByUuid_C(uuid, companyId, start, end, null);
1055            }
1056    
1057            /**
1058             * Returns an ordered range of all the announcements entries where uuid = &#63; and companyId = &#63;.
1059             *
1060             * <p>
1061             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1062             * </p>
1063             *
1064             * @param uuid the uuid
1065             * @param companyId the company ID
1066             * @param start the lower bound of the range of announcements entries
1067             * @param end the upper bound of the range of announcements entries (not inclusive)
1068             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1069             * @return the ordered range of matching announcements entries
1070             * @throws SystemException if a system exception occurred
1071             */
1072            public List<AnnouncementsEntry> findByUuid_C(String uuid, long companyId,
1073                    int start, int end, OrderByComparator orderByComparator)
1074                    throws SystemException {
1075                    boolean pagination = true;
1076                    FinderPath finderPath = null;
1077                    Object[] finderArgs = null;
1078    
1079                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1080                                    (orderByComparator == null)) {
1081                            pagination = false;
1082                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1083                            finderArgs = new Object[] { uuid, companyId };
1084                    }
1085                    else {
1086                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1087                            finderArgs = new Object[] {
1088                                            uuid, companyId,
1089                                            
1090                                            start, end, orderByComparator
1091                                    };
1092                    }
1093    
1094                    List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(finderPath,
1095                                    finderArgs, this);
1096    
1097                    if ((list != null) && !list.isEmpty()) {
1098                            for (AnnouncementsEntry announcementsEntry : list) {
1099                                    if (!Validator.equals(uuid, announcementsEntry.getUuid()) ||
1100                                                    (companyId != announcementsEntry.getCompanyId())) {
1101                                            list = null;
1102    
1103                                            break;
1104                                    }
1105                            }
1106                    }
1107    
1108                    if (list == null) {
1109                            StringBundler query = null;
1110    
1111                            if (orderByComparator != null) {
1112                                    query = new StringBundler(4 +
1113                                                    (orderByComparator.getOrderByFields().length * 3));
1114                            }
1115                            else {
1116                                    query = new StringBundler(4);
1117                            }
1118    
1119                            query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1120    
1121                            if (uuid == null) {
1122                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1123                            }
1124                            else {
1125                                    if (uuid.equals(StringPool.BLANK)) {
1126                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1127                                    }
1128                                    else {
1129                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1130                                    }
1131                            }
1132    
1133                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1134    
1135                            if (orderByComparator != null) {
1136                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1137                                            orderByComparator);
1138                            }
1139                            else
1140                             if (pagination) {
1141                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1142                            }
1143    
1144                            String sql = query.toString();
1145    
1146                            Session session = null;
1147    
1148                            try {
1149                                    session = openSession();
1150    
1151                                    Query q = session.createQuery(sql);
1152    
1153                                    QueryPos qPos = QueryPos.getInstance(q);
1154    
1155                                    if (uuid != null) {
1156                                            qPos.add(uuid);
1157                                    }
1158    
1159                                    qPos.add(companyId);
1160    
1161                                    if (!pagination) {
1162                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1163                                                            getDialect(), start, end, false);
1164    
1165                                            Collections.sort(list);
1166    
1167                                            list = new UnmodifiableList<AnnouncementsEntry>(list);
1168                                    }
1169                                    else {
1170                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1171                                                            getDialect(), start, end);
1172                                    }
1173    
1174                                    cacheResult(list);
1175    
1176                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1177                            }
1178                            catch (Exception e) {
1179                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1180    
1181                                    throw processException(e);
1182                            }
1183                            finally {
1184                                    closeSession(session);
1185                            }
1186                    }
1187    
1188                    return list;
1189            }
1190    
1191            /**
1192             * Returns the first announcements entry in the ordered set where uuid = &#63; and companyId = &#63;.
1193             *
1194             * @param uuid the uuid
1195             * @param companyId the company ID
1196             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1197             * @return the first matching announcements entry
1198             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
1199             * @throws SystemException if a system exception occurred
1200             */
1201            public AnnouncementsEntry findByUuid_C_First(String uuid, long companyId,
1202                    OrderByComparator orderByComparator)
1203                    throws NoSuchEntryException, SystemException {
1204                    AnnouncementsEntry announcementsEntry = fetchByUuid_C_First(uuid,
1205                                    companyId, orderByComparator);
1206    
1207                    if (announcementsEntry != null) {
1208                            return announcementsEntry;
1209                    }
1210    
1211                    StringBundler msg = new StringBundler(6);
1212    
1213                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1214    
1215                    msg.append("uuid=");
1216                    msg.append(uuid);
1217    
1218                    msg.append(", companyId=");
1219                    msg.append(companyId);
1220    
1221                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1222    
1223                    throw new NoSuchEntryException(msg.toString());
1224            }
1225    
1226            /**
1227             * Returns the first announcements entry in the ordered set where uuid = &#63; and companyId = &#63;.
1228             *
1229             * @param uuid the uuid
1230             * @param companyId the company ID
1231             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1232             * @return the first matching announcements entry, or <code>null</code> if a matching announcements entry could not be found
1233             * @throws SystemException if a system exception occurred
1234             */
1235            public AnnouncementsEntry fetchByUuid_C_First(String uuid, long companyId,
1236                    OrderByComparator orderByComparator) throws SystemException {
1237                    List<AnnouncementsEntry> list = findByUuid_C(uuid, companyId, 0, 1,
1238                                    orderByComparator);
1239    
1240                    if (!list.isEmpty()) {
1241                            return list.get(0);
1242                    }
1243    
1244                    return null;
1245            }
1246    
1247            /**
1248             * Returns the last announcements entry in the ordered set where uuid = &#63; and companyId = &#63;.
1249             *
1250             * @param uuid the uuid
1251             * @param companyId the company ID
1252             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1253             * @return the last matching announcements entry
1254             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
1255             * @throws SystemException if a system exception occurred
1256             */
1257            public AnnouncementsEntry findByUuid_C_Last(String uuid, long companyId,
1258                    OrderByComparator orderByComparator)
1259                    throws NoSuchEntryException, SystemException {
1260                    AnnouncementsEntry announcementsEntry = fetchByUuid_C_Last(uuid,
1261                                    companyId, orderByComparator);
1262    
1263                    if (announcementsEntry != null) {
1264                            return announcementsEntry;
1265                    }
1266    
1267                    StringBundler msg = new StringBundler(6);
1268    
1269                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1270    
1271                    msg.append("uuid=");
1272                    msg.append(uuid);
1273    
1274                    msg.append(", companyId=");
1275                    msg.append(companyId);
1276    
1277                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1278    
1279                    throw new NoSuchEntryException(msg.toString());
1280            }
1281    
1282            /**
1283             * Returns the last announcements entry in the ordered set where uuid = &#63; and companyId = &#63;.
1284             *
1285             * @param uuid the uuid
1286             * @param companyId the company ID
1287             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1288             * @return the last matching announcements entry, or <code>null</code> if a matching announcements entry could not be found
1289             * @throws SystemException if a system exception occurred
1290             */
1291            public AnnouncementsEntry fetchByUuid_C_Last(String uuid, long companyId,
1292                    OrderByComparator orderByComparator) throws SystemException {
1293                    int count = countByUuid_C(uuid, companyId);
1294    
1295                    List<AnnouncementsEntry> list = findByUuid_C(uuid, companyId,
1296                                    count - 1, count, orderByComparator);
1297    
1298                    if (!list.isEmpty()) {
1299                            return list.get(0);
1300                    }
1301    
1302                    return null;
1303            }
1304    
1305            /**
1306             * Returns the announcements entries before and after the current announcements entry in the ordered set where uuid = &#63; and companyId = &#63;.
1307             *
1308             * @param entryId the primary key of the current announcements entry
1309             * @param uuid the uuid
1310             * @param companyId the company ID
1311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1312             * @return the previous, current, and next announcements entry
1313             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
1314             * @throws SystemException if a system exception occurred
1315             */
1316            public AnnouncementsEntry[] findByUuid_C_PrevAndNext(long entryId,
1317                    String uuid, long companyId, OrderByComparator orderByComparator)
1318                    throws NoSuchEntryException, SystemException {
1319                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1320    
1321                    Session session = null;
1322    
1323                    try {
1324                            session = openSession();
1325    
1326                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1327    
1328                            array[0] = getByUuid_C_PrevAndNext(session, announcementsEntry,
1329                                            uuid, companyId, orderByComparator, true);
1330    
1331                            array[1] = announcementsEntry;
1332    
1333                            array[2] = getByUuid_C_PrevAndNext(session, announcementsEntry,
1334                                            uuid, companyId, orderByComparator, false);
1335    
1336                            return array;
1337                    }
1338                    catch (Exception e) {
1339                            throw processException(e);
1340                    }
1341                    finally {
1342                            closeSession(session);
1343                    }
1344            }
1345    
1346            protected AnnouncementsEntry getByUuid_C_PrevAndNext(Session session,
1347                    AnnouncementsEntry announcementsEntry, String uuid, long companyId,
1348                    OrderByComparator orderByComparator, boolean previous) {
1349                    StringBundler query = null;
1350    
1351                    if (orderByComparator != null) {
1352                            query = new StringBundler(6 +
1353                                            (orderByComparator.getOrderByFields().length * 6));
1354                    }
1355                    else {
1356                            query = new StringBundler(3);
1357                    }
1358    
1359                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1360    
1361                    if (uuid == null) {
1362                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1363                    }
1364                    else {
1365                            if (uuid.equals(StringPool.BLANK)) {
1366                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1367                            }
1368                            else {
1369                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1370                            }
1371                    }
1372    
1373                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1374    
1375                    if (orderByComparator != null) {
1376                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1377    
1378                            if (orderByConditionFields.length > 0) {
1379                                    query.append(WHERE_AND);
1380                            }
1381    
1382                            for (int i = 0; i < orderByConditionFields.length; i++) {
1383                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1384                                    query.append(orderByConditionFields[i]);
1385    
1386                                    if ((i + 1) < orderByConditionFields.length) {
1387                                            if (orderByComparator.isAscending() ^ previous) {
1388                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1389                                            }
1390                                            else {
1391                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1392                                            }
1393                                    }
1394                                    else {
1395                                            if (orderByComparator.isAscending() ^ previous) {
1396                                                    query.append(WHERE_GREATER_THAN);
1397                                            }
1398                                            else {
1399                                                    query.append(WHERE_LESSER_THAN);
1400                                            }
1401                                    }
1402                            }
1403    
1404                            query.append(ORDER_BY_CLAUSE);
1405    
1406                            String[] orderByFields = orderByComparator.getOrderByFields();
1407    
1408                            for (int i = 0; i < orderByFields.length; i++) {
1409                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1410                                    query.append(orderByFields[i]);
1411    
1412                                    if ((i + 1) < orderByFields.length) {
1413                                            if (orderByComparator.isAscending() ^ previous) {
1414                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1415                                            }
1416                                            else {
1417                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1418                                            }
1419                                    }
1420                                    else {
1421                                            if (orderByComparator.isAscending() ^ previous) {
1422                                                    query.append(ORDER_BY_ASC);
1423                                            }
1424                                            else {
1425                                                    query.append(ORDER_BY_DESC);
1426                                            }
1427                                    }
1428                            }
1429                    }
1430                    else {
1431                            query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1432                    }
1433    
1434                    String sql = query.toString();
1435    
1436                    Query q = session.createQuery(sql);
1437    
1438                    q.setFirstResult(0);
1439                    q.setMaxResults(2);
1440    
1441                    QueryPos qPos = QueryPos.getInstance(q);
1442    
1443                    if (uuid != null) {
1444                            qPos.add(uuid);
1445                    }
1446    
1447                    qPos.add(companyId);
1448    
1449                    if (orderByComparator != null) {
1450                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsEntry);
1451    
1452                            for (Object value : values) {
1453                                    qPos.add(value);
1454                            }
1455                    }
1456    
1457                    List<AnnouncementsEntry> list = q.list();
1458    
1459                    if (list.size() == 2) {
1460                            return list.get(1);
1461                    }
1462                    else {
1463                            return null;
1464                    }
1465            }
1466    
1467            /**
1468             * Returns all the announcements entries that the user has permission to view where uuid = &#63; and companyId = &#63;.
1469             *
1470             * @param uuid the uuid
1471             * @param companyId the company ID
1472             * @return the matching announcements entries that the user has permission to view
1473             * @throws SystemException if a system exception occurred
1474             */
1475            public List<AnnouncementsEntry> filterFindByUuid_C(String uuid,
1476                    long companyId) throws SystemException {
1477                    return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1478                            QueryUtil.ALL_POS, null);
1479            }
1480    
1481            /**
1482             * Returns a range of all the announcements entries that the user has permission to view where uuid = &#63; and companyId = &#63;.
1483             *
1484             * <p>
1485             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1486             * </p>
1487             *
1488             * @param uuid the uuid
1489             * @param companyId the company ID
1490             * @param start the lower bound of the range of announcements entries
1491             * @param end the upper bound of the range of announcements entries (not inclusive)
1492             * @return the range of matching announcements entries that the user has permission to view
1493             * @throws SystemException if a system exception occurred
1494             */
1495            public List<AnnouncementsEntry> filterFindByUuid_C(String uuid,
1496                    long companyId, int start, int end) throws SystemException {
1497                    return filterFindByUuid_C(uuid, companyId, start, end, null);
1498            }
1499    
1500            /**
1501             * Returns an ordered range of all the announcements entries that the user has permissions to view where uuid = &#63; and companyId = &#63;.
1502             *
1503             * <p>
1504             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1505             * </p>
1506             *
1507             * @param uuid the uuid
1508             * @param companyId the company ID
1509             * @param start the lower bound of the range of announcements entries
1510             * @param end the upper bound of the range of announcements entries (not inclusive)
1511             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1512             * @return the ordered range of matching announcements entries that the user has permission to view
1513             * @throws SystemException if a system exception occurred
1514             */
1515            public List<AnnouncementsEntry> filterFindByUuid_C(String uuid,
1516                    long companyId, int start, int end, OrderByComparator orderByComparator)
1517                    throws SystemException {
1518                    if (!InlineSQLHelperUtil.isEnabled()) {
1519                            return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1520                    }
1521    
1522                    StringBundler query = null;
1523    
1524                    if (orderByComparator != null) {
1525                            query = new StringBundler(4 +
1526                                            (orderByComparator.getOrderByFields().length * 3));
1527                    }
1528                    else {
1529                            query = new StringBundler(4);
1530                    }
1531    
1532                    if (getDB().isSupportsInlineDistinct()) {
1533                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1534                    }
1535                    else {
1536                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_1);
1537                    }
1538    
1539                    if (uuid == null) {
1540                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1541                    }
1542                    else {
1543                            if (uuid.equals(StringPool.BLANK)) {
1544                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1545                            }
1546                            else {
1547                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1548                            }
1549                    }
1550    
1551                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1552    
1553                    if (!getDB().isSupportsInlineDistinct()) {
1554                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_2);
1555                    }
1556    
1557                    if (orderByComparator != null) {
1558                            if (getDB().isSupportsInlineDistinct()) {
1559                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1560                                            orderByComparator);
1561                            }
1562                            else {
1563                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1564                                            orderByComparator);
1565                            }
1566                    }
1567                    else {
1568                            if (getDB().isSupportsInlineDistinct()) {
1569                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1570                            }
1571                            else {
1572                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_SQL);
1573                            }
1574                    }
1575    
1576                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1577                                    AnnouncementsEntry.class.getName(),
1578                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1579    
1580                    Session session = null;
1581    
1582                    try {
1583                            session = openSession();
1584    
1585                            SQLQuery q = session.createSQLQuery(sql);
1586    
1587                            if (getDB().isSupportsInlineDistinct()) {
1588                                    q.addEntity(_FILTER_ENTITY_ALIAS, AnnouncementsEntryImpl.class);
1589                            }
1590                            else {
1591                                    q.addEntity(_FILTER_ENTITY_TABLE, AnnouncementsEntryImpl.class);
1592                            }
1593    
1594                            QueryPos qPos = QueryPos.getInstance(q);
1595    
1596                            if (uuid != null) {
1597                                    qPos.add(uuid);
1598                            }
1599    
1600                            qPos.add(companyId);
1601    
1602                            return (List<AnnouncementsEntry>)QueryUtil.list(q, getDialect(),
1603                                    start, end);
1604                    }
1605                    catch (Exception e) {
1606                            throw processException(e);
1607                    }
1608                    finally {
1609                            closeSession(session);
1610                    }
1611            }
1612    
1613            /**
1614             * Returns the announcements entries before and after the current announcements entry in the ordered set of announcements entries that the user has permission to view where uuid = &#63; and companyId = &#63;.
1615             *
1616             * @param entryId the primary key of the current announcements entry
1617             * @param uuid the uuid
1618             * @param companyId the company ID
1619             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1620             * @return the previous, current, and next announcements entry
1621             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
1622             * @throws SystemException if a system exception occurred
1623             */
1624            public AnnouncementsEntry[] filterFindByUuid_C_PrevAndNext(long entryId,
1625                    String uuid, long companyId, OrderByComparator orderByComparator)
1626                    throws NoSuchEntryException, SystemException {
1627                    if (!InlineSQLHelperUtil.isEnabled()) {
1628                            return findByUuid_C_PrevAndNext(entryId, uuid, companyId,
1629                                    orderByComparator);
1630                    }
1631    
1632                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1633    
1634                    Session session = null;
1635    
1636                    try {
1637                            session = openSession();
1638    
1639                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1640    
1641                            array[0] = filterGetByUuid_C_PrevAndNext(session,
1642                                            announcementsEntry, uuid, companyId, orderByComparator, true);
1643    
1644                            array[1] = announcementsEntry;
1645    
1646                            array[2] = filterGetByUuid_C_PrevAndNext(session,
1647                                            announcementsEntry, uuid, companyId, orderByComparator,
1648                                            false);
1649    
1650                            return array;
1651                    }
1652                    catch (Exception e) {
1653                            throw processException(e);
1654                    }
1655                    finally {
1656                            closeSession(session);
1657                    }
1658            }
1659    
1660            protected AnnouncementsEntry filterGetByUuid_C_PrevAndNext(
1661                    Session session, AnnouncementsEntry announcementsEntry, String uuid,
1662                    long companyId, OrderByComparator orderByComparator, boolean previous) {
1663                    StringBundler query = null;
1664    
1665                    if (orderByComparator != null) {
1666                            query = new StringBundler(6 +
1667                                            (orderByComparator.getOrderByFields().length * 6));
1668                    }
1669                    else {
1670                            query = new StringBundler(3);
1671                    }
1672    
1673                    if (getDB().isSupportsInlineDistinct()) {
1674                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
1675                    }
1676                    else {
1677                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_1);
1678                    }
1679    
1680                    if (uuid == null) {
1681                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1682                    }
1683                    else {
1684                            if (uuid.equals(StringPool.BLANK)) {
1685                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1686                            }
1687                            else {
1688                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1689                            }
1690                    }
1691    
1692                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1693    
1694                    if (!getDB().isSupportsInlineDistinct()) {
1695                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_2);
1696                    }
1697    
1698                    if (orderByComparator != null) {
1699                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1700    
1701                            if (orderByConditionFields.length > 0) {
1702                                    query.append(WHERE_AND);
1703                            }
1704    
1705                            for (int i = 0; i < orderByConditionFields.length; i++) {
1706                                    if (getDB().isSupportsInlineDistinct()) {
1707                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1708                                    }
1709                                    else {
1710                                            query.append(_ORDER_BY_ENTITY_TABLE);
1711                                    }
1712    
1713                                    query.append(orderByConditionFields[i]);
1714    
1715                                    if ((i + 1) < orderByConditionFields.length) {
1716                                            if (orderByComparator.isAscending() ^ previous) {
1717                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1718                                            }
1719                                            else {
1720                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1721                                            }
1722                                    }
1723                                    else {
1724                                            if (orderByComparator.isAscending() ^ previous) {
1725                                                    query.append(WHERE_GREATER_THAN);
1726                                            }
1727                                            else {
1728                                                    query.append(WHERE_LESSER_THAN);
1729                                            }
1730                                    }
1731                            }
1732    
1733                            query.append(ORDER_BY_CLAUSE);
1734    
1735                            String[] orderByFields = orderByComparator.getOrderByFields();
1736    
1737                            for (int i = 0; i < orderByFields.length; i++) {
1738                                    if (getDB().isSupportsInlineDistinct()) {
1739                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1740                                    }
1741                                    else {
1742                                            query.append(_ORDER_BY_ENTITY_TABLE);
1743                                    }
1744    
1745                                    query.append(orderByFields[i]);
1746    
1747                                    if ((i + 1) < orderByFields.length) {
1748                                            if (orderByComparator.isAscending() ^ previous) {
1749                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1750                                            }
1751                                            else {
1752                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1753                                            }
1754                                    }
1755                                    else {
1756                                            if (orderByComparator.isAscending() ^ previous) {
1757                                                    query.append(ORDER_BY_ASC);
1758                                            }
1759                                            else {
1760                                                    query.append(ORDER_BY_DESC);
1761                                            }
1762                                    }
1763                            }
1764                    }
1765                    else {
1766                            if (getDB().isSupportsInlineDistinct()) {
1767                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
1768                            }
1769                            else {
1770                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_SQL);
1771                            }
1772                    }
1773    
1774                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1775                                    AnnouncementsEntry.class.getName(),
1776                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1777    
1778                    SQLQuery q = session.createSQLQuery(sql);
1779    
1780                    q.setFirstResult(0);
1781                    q.setMaxResults(2);
1782    
1783                    if (getDB().isSupportsInlineDistinct()) {
1784                            q.addEntity(_FILTER_ENTITY_ALIAS, AnnouncementsEntryImpl.class);
1785                    }
1786                    else {
1787                            q.addEntity(_FILTER_ENTITY_TABLE, AnnouncementsEntryImpl.class);
1788                    }
1789    
1790                    QueryPos qPos = QueryPos.getInstance(q);
1791    
1792                    if (uuid != null) {
1793                            qPos.add(uuid);
1794                    }
1795    
1796                    qPos.add(companyId);
1797    
1798                    if (orderByComparator != null) {
1799                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsEntry);
1800    
1801                            for (Object value : values) {
1802                                    qPos.add(value);
1803                            }
1804                    }
1805    
1806                    List<AnnouncementsEntry> list = q.list();
1807    
1808                    if (list.size() == 2) {
1809                            return list.get(1);
1810                    }
1811                    else {
1812                            return null;
1813                    }
1814            }
1815    
1816            /**
1817             * Removes all the announcements entries where uuid = &#63; and companyId = &#63; from the database.
1818             *
1819             * @param uuid the uuid
1820             * @param companyId the company ID
1821             * @throws SystemException if a system exception occurred
1822             */
1823            public void removeByUuid_C(String uuid, long companyId)
1824                    throws SystemException {
1825                    for (AnnouncementsEntry announcementsEntry : findByUuid_C(uuid,
1826                                    companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1827                            remove(announcementsEntry);
1828                    }
1829            }
1830    
1831            /**
1832             * Returns the number of announcements entries where uuid = &#63; and companyId = &#63;.
1833             *
1834             * @param uuid the uuid
1835             * @param companyId the company ID
1836             * @return the number of matching announcements entries
1837             * @throws SystemException if a system exception occurred
1838             */
1839            public int countByUuid_C(String uuid, long companyId)
1840                    throws SystemException {
1841                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1842    
1843                    Object[] finderArgs = new Object[] { uuid, companyId };
1844    
1845                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1846                                    this);
1847    
1848                    if (count == null) {
1849                            StringBundler query = new StringBundler(3);
1850    
1851                            query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
1852    
1853                            if (uuid == null) {
1854                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1855                            }
1856                            else {
1857                                    if (uuid.equals(StringPool.BLANK)) {
1858                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1859                                    }
1860                                    else {
1861                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1862                                    }
1863                            }
1864    
1865                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1866    
1867                            String sql = query.toString();
1868    
1869                            Session session = null;
1870    
1871                            try {
1872                                    session = openSession();
1873    
1874                                    Query q = session.createQuery(sql);
1875    
1876                                    QueryPos qPos = QueryPos.getInstance(q);
1877    
1878                                    if (uuid != null) {
1879                                            qPos.add(uuid);
1880                                    }
1881    
1882                                    qPos.add(companyId);
1883    
1884                                    count = (Long)q.uniqueResult();
1885    
1886                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1887                            }
1888                            catch (Exception e) {
1889                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1890    
1891                                    throw processException(e);
1892                            }
1893                            finally {
1894                                    closeSession(session);
1895                            }
1896                    }
1897    
1898                    return count.intValue();
1899            }
1900    
1901            /**
1902             * Returns the number of announcements entries that the user has permission to view where uuid = &#63; and companyId = &#63;.
1903             *
1904             * @param uuid the uuid
1905             * @param companyId the company ID
1906             * @return the number of matching announcements entries that the user has permission to view
1907             * @throws SystemException if a system exception occurred
1908             */
1909            public int filterCountByUuid_C(String uuid, long companyId)
1910                    throws SystemException {
1911                    if (!InlineSQLHelperUtil.isEnabled()) {
1912                            return countByUuid_C(uuid, companyId);
1913                    }
1914    
1915                    StringBundler query = new StringBundler(3);
1916    
1917                    query.append(_FILTER_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
1918    
1919                    if (uuid == null) {
1920                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1921                    }
1922                    else {
1923                            if (uuid.equals(StringPool.BLANK)) {
1924                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1925                            }
1926                            else {
1927                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1928                            }
1929                    }
1930    
1931                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1932    
1933                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1934                                    AnnouncementsEntry.class.getName(),
1935                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1936    
1937                    Session session = null;
1938    
1939                    try {
1940                            session = openSession();
1941    
1942                            SQLQuery q = session.createSQLQuery(sql);
1943    
1944                            q.addScalar(COUNT_COLUMN_NAME,
1945                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1946    
1947                            QueryPos qPos = QueryPos.getInstance(q);
1948    
1949                            if (uuid != null) {
1950                                    qPos.add(uuid);
1951                            }
1952    
1953                            qPos.add(companyId);
1954    
1955                            Long count = (Long)q.uniqueResult();
1956    
1957                            return count.intValue();
1958                    }
1959                    catch (Exception e) {
1960                            throw processException(e);
1961                    }
1962                    finally {
1963                            closeSession(session);
1964                    }
1965            }
1966    
1967            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "announcementsEntry.uuid IS NULL AND ";
1968            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "announcementsEntry.uuid = ? AND ";
1969            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(announcementsEntry.uuid IS NULL OR announcementsEntry.uuid = ?) AND ";
1970            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "announcementsEntry.companyId = ?";
1971            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
1972                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
1973                            AnnouncementsEntryImpl.class,
1974                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
1975                            new String[] {
1976                                    Long.class.getName(),
1977                                    
1978                            Integer.class.getName(), Integer.class.getName(),
1979                                    OrderByComparator.class.getName()
1980                            });
1981            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1982                    new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
1983                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
1984                            AnnouncementsEntryImpl.class,
1985                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
1986                            new String[] { Long.class.getName() },
1987                            AnnouncementsEntryModelImpl.USERID_COLUMN_BITMASK |
1988                            AnnouncementsEntryModelImpl.PRIORITY_COLUMN_BITMASK |
1989                            AnnouncementsEntryModelImpl.MODIFIEDDATE_COLUMN_BITMASK);
1990            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
1991                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1992                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1993                            new String[] { Long.class.getName() });
1994    
1995            /**
1996             * Returns all the announcements entries where userId = &#63;.
1997             *
1998             * @param userId the user ID
1999             * @return the matching announcements entries
2000             * @throws SystemException if a system exception occurred
2001             */
2002            public List<AnnouncementsEntry> findByUserId(long userId)
2003                    throws SystemException {
2004                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2005            }
2006    
2007            /**
2008             * Returns a range of all the announcements entries where userId = &#63;.
2009             *
2010             * <p>
2011             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2012             * </p>
2013             *
2014             * @param userId the user ID
2015             * @param start the lower bound of the range of announcements entries
2016             * @param end the upper bound of the range of announcements entries (not inclusive)
2017             * @return the range of matching announcements entries
2018             * @throws SystemException if a system exception occurred
2019             */
2020            public List<AnnouncementsEntry> findByUserId(long userId, int start, int end)
2021                    throws SystemException {
2022                    return findByUserId(userId, start, end, null);
2023            }
2024    
2025            /**
2026             * Returns an ordered range of all the announcements entries where userId = &#63;.
2027             *
2028             * <p>
2029             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2030             * </p>
2031             *
2032             * @param userId the user ID
2033             * @param start the lower bound of the range of announcements entries
2034             * @param end the upper bound of the range of announcements entries (not inclusive)
2035             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2036             * @return the ordered range of matching announcements entries
2037             * @throws SystemException if a system exception occurred
2038             */
2039            public List<AnnouncementsEntry> findByUserId(long userId, int start,
2040                    int end, OrderByComparator orderByComparator) throws SystemException {
2041                    boolean pagination = true;
2042                    FinderPath finderPath = null;
2043                    Object[] finderArgs = null;
2044    
2045                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2046                                    (orderByComparator == null)) {
2047                            pagination = false;
2048                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
2049                            finderArgs = new Object[] { userId };
2050                    }
2051                    else {
2052                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
2053                            finderArgs = new Object[] { userId, start, end, orderByComparator };
2054                    }
2055    
2056                    List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(finderPath,
2057                                    finderArgs, this);
2058    
2059                    if ((list != null) && !list.isEmpty()) {
2060                            for (AnnouncementsEntry announcementsEntry : list) {
2061                                    if ((userId != announcementsEntry.getUserId())) {
2062                                            list = null;
2063    
2064                                            break;
2065                                    }
2066                            }
2067                    }
2068    
2069                    if (list == null) {
2070                            StringBundler query = null;
2071    
2072                            if (orderByComparator != null) {
2073                                    query = new StringBundler(3 +
2074                                                    (orderByComparator.getOrderByFields().length * 3));
2075                            }
2076                            else {
2077                                    query = new StringBundler(3);
2078                            }
2079    
2080                            query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
2081    
2082                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2083    
2084                            if (orderByComparator != null) {
2085                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2086                                            orderByComparator);
2087                            }
2088                            else
2089                             if (pagination) {
2090                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
2091                            }
2092    
2093                            String sql = query.toString();
2094    
2095                            Session session = null;
2096    
2097                            try {
2098                                    session = openSession();
2099    
2100                                    Query q = session.createQuery(sql);
2101    
2102                                    QueryPos qPos = QueryPos.getInstance(q);
2103    
2104                                    qPos.add(userId);
2105    
2106                                    if (!pagination) {
2107                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
2108                                                            getDialect(), start, end, false);
2109    
2110                                            Collections.sort(list);
2111    
2112                                            list = new UnmodifiableList<AnnouncementsEntry>(list);
2113                                    }
2114                                    else {
2115                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
2116                                                            getDialect(), start, end);
2117                                    }
2118    
2119                                    cacheResult(list);
2120    
2121                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2122                            }
2123                            catch (Exception e) {
2124                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2125    
2126                                    throw processException(e);
2127                            }
2128                            finally {
2129                                    closeSession(session);
2130                            }
2131                    }
2132    
2133                    return list;
2134            }
2135    
2136            /**
2137             * Returns the first announcements entry in the ordered set where userId = &#63;.
2138             *
2139             * @param userId the user ID
2140             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2141             * @return the first matching announcements entry
2142             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
2143             * @throws SystemException if a system exception occurred
2144             */
2145            public AnnouncementsEntry findByUserId_First(long userId,
2146                    OrderByComparator orderByComparator)
2147                    throws NoSuchEntryException, SystemException {
2148                    AnnouncementsEntry announcementsEntry = fetchByUserId_First(userId,
2149                                    orderByComparator);
2150    
2151                    if (announcementsEntry != null) {
2152                            return announcementsEntry;
2153                    }
2154    
2155                    StringBundler msg = new StringBundler(4);
2156    
2157                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2158    
2159                    msg.append("userId=");
2160                    msg.append(userId);
2161    
2162                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2163    
2164                    throw new NoSuchEntryException(msg.toString());
2165            }
2166    
2167            /**
2168             * Returns the first announcements entry in the ordered set where userId = &#63;.
2169             *
2170             * @param userId the user ID
2171             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2172             * @return the first matching announcements entry, or <code>null</code> if a matching announcements entry could not be found
2173             * @throws SystemException if a system exception occurred
2174             */
2175            public AnnouncementsEntry fetchByUserId_First(long userId,
2176                    OrderByComparator orderByComparator) throws SystemException {
2177                    List<AnnouncementsEntry> list = findByUserId(userId, 0, 1,
2178                                    orderByComparator);
2179    
2180                    if (!list.isEmpty()) {
2181                            return list.get(0);
2182                    }
2183    
2184                    return null;
2185            }
2186    
2187            /**
2188             * Returns the last announcements entry in the ordered set where userId = &#63;.
2189             *
2190             * @param userId the user ID
2191             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2192             * @return the last matching announcements entry
2193             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
2194             * @throws SystemException if a system exception occurred
2195             */
2196            public AnnouncementsEntry findByUserId_Last(long userId,
2197                    OrderByComparator orderByComparator)
2198                    throws NoSuchEntryException, SystemException {
2199                    AnnouncementsEntry announcementsEntry = fetchByUserId_Last(userId,
2200                                    orderByComparator);
2201    
2202                    if (announcementsEntry != null) {
2203                            return announcementsEntry;
2204                    }
2205    
2206                    StringBundler msg = new StringBundler(4);
2207    
2208                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2209    
2210                    msg.append("userId=");
2211                    msg.append(userId);
2212    
2213                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2214    
2215                    throw new NoSuchEntryException(msg.toString());
2216            }
2217    
2218            /**
2219             * Returns the last announcements entry in the ordered set where userId = &#63;.
2220             *
2221             * @param userId the user ID
2222             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2223             * @return the last matching announcements entry, or <code>null</code> if a matching announcements entry could not be found
2224             * @throws SystemException if a system exception occurred
2225             */
2226            public AnnouncementsEntry fetchByUserId_Last(long userId,
2227                    OrderByComparator orderByComparator) throws SystemException {
2228                    int count = countByUserId(userId);
2229    
2230                    List<AnnouncementsEntry> list = findByUserId(userId, count - 1, count,
2231                                    orderByComparator);
2232    
2233                    if (!list.isEmpty()) {
2234                            return list.get(0);
2235                    }
2236    
2237                    return null;
2238            }
2239    
2240            /**
2241             * Returns the announcements entries before and after the current announcements entry in the ordered set where userId = &#63;.
2242             *
2243             * @param entryId the primary key of the current announcements entry
2244             * @param userId the user ID
2245             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2246             * @return the previous, current, and next announcements entry
2247             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
2248             * @throws SystemException if a system exception occurred
2249             */
2250            public AnnouncementsEntry[] findByUserId_PrevAndNext(long entryId,
2251                    long userId, OrderByComparator orderByComparator)
2252                    throws NoSuchEntryException, SystemException {
2253                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
2254    
2255                    Session session = null;
2256    
2257                    try {
2258                            session = openSession();
2259    
2260                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
2261    
2262                            array[0] = getByUserId_PrevAndNext(session, announcementsEntry,
2263                                            userId, orderByComparator, true);
2264    
2265                            array[1] = announcementsEntry;
2266    
2267                            array[2] = getByUserId_PrevAndNext(session, announcementsEntry,
2268                                            userId, orderByComparator, false);
2269    
2270                            return array;
2271                    }
2272                    catch (Exception e) {
2273                            throw processException(e);
2274                    }
2275                    finally {
2276                            closeSession(session);
2277                    }
2278            }
2279    
2280            protected AnnouncementsEntry getByUserId_PrevAndNext(Session session,
2281                    AnnouncementsEntry announcementsEntry, long userId,
2282                    OrderByComparator orderByComparator, boolean previous) {
2283                    StringBundler query = null;
2284    
2285                    if (orderByComparator != null) {
2286                            query = new StringBundler(6 +
2287                                            (orderByComparator.getOrderByFields().length * 6));
2288                    }
2289                    else {
2290                            query = new StringBundler(3);
2291                    }
2292    
2293                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
2294    
2295                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2296    
2297                    if (orderByComparator != null) {
2298                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2299    
2300                            if (orderByConditionFields.length > 0) {
2301                                    query.append(WHERE_AND);
2302                            }
2303    
2304                            for (int i = 0; i < orderByConditionFields.length; i++) {
2305                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2306                                    query.append(orderByConditionFields[i]);
2307    
2308                                    if ((i + 1) < orderByConditionFields.length) {
2309                                            if (orderByComparator.isAscending() ^ previous) {
2310                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2311                                            }
2312                                            else {
2313                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2314                                            }
2315                                    }
2316                                    else {
2317                                            if (orderByComparator.isAscending() ^ previous) {
2318                                                    query.append(WHERE_GREATER_THAN);
2319                                            }
2320                                            else {
2321                                                    query.append(WHERE_LESSER_THAN);
2322                                            }
2323                                    }
2324                            }
2325    
2326                            query.append(ORDER_BY_CLAUSE);
2327    
2328                            String[] orderByFields = orderByComparator.getOrderByFields();
2329    
2330                            for (int i = 0; i < orderByFields.length; i++) {
2331                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2332                                    query.append(orderByFields[i]);
2333    
2334                                    if ((i + 1) < orderByFields.length) {
2335                                            if (orderByComparator.isAscending() ^ previous) {
2336                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2337                                            }
2338                                            else {
2339                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2340                                            }
2341                                    }
2342                                    else {
2343                                            if (orderByComparator.isAscending() ^ previous) {
2344                                                    query.append(ORDER_BY_ASC);
2345                                            }
2346                                            else {
2347                                                    query.append(ORDER_BY_DESC);
2348                                            }
2349                                    }
2350                            }
2351                    }
2352                    else {
2353                            query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
2354                    }
2355    
2356                    String sql = query.toString();
2357    
2358                    Query q = session.createQuery(sql);
2359    
2360                    q.setFirstResult(0);
2361                    q.setMaxResults(2);
2362    
2363                    QueryPos qPos = QueryPos.getInstance(q);
2364    
2365                    qPos.add(userId);
2366    
2367                    if (orderByComparator != null) {
2368                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsEntry);
2369    
2370                            for (Object value : values) {
2371                                    qPos.add(value);
2372                            }
2373                    }
2374    
2375                    List<AnnouncementsEntry> list = q.list();
2376    
2377                    if (list.size() == 2) {
2378                            return list.get(1);
2379                    }
2380                    else {
2381                            return null;
2382                    }
2383            }
2384    
2385            /**
2386             * Returns all the announcements entries that the user has permission to view where userId = &#63;.
2387             *
2388             * @param userId the user ID
2389             * @return the matching announcements entries that the user has permission to view
2390             * @throws SystemException if a system exception occurred
2391             */
2392            public List<AnnouncementsEntry> filterFindByUserId(long userId)
2393                    throws SystemException {
2394                    return filterFindByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2395                            null);
2396            }
2397    
2398            /**
2399             * Returns a range of all the announcements entries that the user has permission to view where userId = &#63;.
2400             *
2401             * <p>
2402             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2403             * </p>
2404             *
2405             * @param userId the user ID
2406             * @param start the lower bound of the range of announcements entries
2407             * @param end the upper bound of the range of announcements entries (not inclusive)
2408             * @return the range of matching announcements entries that the user has permission to view
2409             * @throws SystemException if a system exception occurred
2410             */
2411            public List<AnnouncementsEntry> filterFindByUserId(long userId, int start,
2412                    int end) throws SystemException {
2413                    return filterFindByUserId(userId, start, end, null);
2414            }
2415    
2416            /**
2417             * Returns an ordered range of all the announcements entries that the user has permissions to view where userId = &#63;.
2418             *
2419             * <p>
2420             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2421             * </p>
2422             *
2423             * @param userId the user ID
2424             * @param start the lower bound of the range of announcements entries
2425             * @param end the upper bound of the range of announcements entries (not inclusive)
2426             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2427             * @return the ordered range of matching announcements entries that the user has permission to view
2428             * @throws SystemException if a system exception occurred
2429             */
2430            public List<AnnouncementsEntry> filterFindByUserId(long userId, int start,
2431                    int end, OrderByComparator orderByComparator) throws SystemException {
2432                    if (!InlineSQLHelperUtil.isEnabled()) {
2433                            return findByUserId(userId, start, end, orderByComparator);
2434                    }
2435    
2436                    StringBundler query = null;
2437    
2438                    if (orderByComparator != null) {
2439                            query = new StringBundler(3 +
2440                                            (orderByComparator.getOrderByFields().length * 3));
2441                    }
2442                    else {
2443                            query = new StringBundler(3);
2444                    }
2445    
2446                    if (getDB().isSupportsInlineDistinct()) {
2447                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
2448                    }
2449                    else {
2450                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_1);
2451                    }
2452    
2453                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2454    
2455                    if (!getDB().isSupportsInlineDistinct()) {
2456                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_2);
2457                    }
2458    
2459                    if (orderByComparator != null) {
2460                            if (getDB().isSupportsInlineDistinct()) {
2461                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2462                                            orderByComparator);
2463                            }
2464                            else {
2465                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2466                                            orderByComparator);
2467                            }
2468                    }
2469                    else {
2470                            if (getDB().isSupportsInlineDistinct()) {
2471                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
2472                            }
2473                            else {
2474                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_SQL);
2475                            }
2476                    }
2477    
2478                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2479                                    AnnouncementsEntry.class.getName(),
2480                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2481    
2482                    Session session = null;
2483    
2484                    try {
2485                            session = openSession();
2486    
2487                            SQLQuery q = session.createSQLQuery(sql);
2488    
2489                            if (getDB().isSupportsInlineDistinct()) {
2490                                    q.addEntity(_FILTER_ENTITY_ALIAS, AnnouncementsEntryImpl.class);
2491                            }
2492                            else {
2493                                    q.addEntity(_FILTER_ENTITY_TABLE, AnnouncementsEntryImpl.class);
2494                            }
2495    
2496                            QueryPos qPos = QueryPos.getInstance(q);
2497    
2498                            qPos.add(userId);
2499    
2500                            return (List<AnnouncementsEntry>)QueryUtil.list(q, getDialect(),
2501                                    start, end);
2502                    }
2503                    catch (Exception e) {
2504                            throw processException(e);
2505                    }
2506                    finally {
2507                            closeSession(session);
2508                    }
2509            }
2510    
2511            /**
2512             * Returns the announcements entries before and after the current announcements entry in the ordered set of announcements entries that the user has permission to view where userId = &#63;.
2513             *
2514             * @param entryId the primary key of the current announcements entry
2515             * @param userId the user ID
2516             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2517             * @return the previous, current, and next announcements entry
2518             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
2519             * @throws SystemException if a system exception occurred
2520             */
2521            public AnnouncementsEntry[] filterFindByUserId_PrevAndNext(long entryId,
2522                    long userId, OrderByComparator orderByComparator)
2523                    throws NoSuchEntryException, SystemException {
2524                    if (!InlineSQLHelperUtil.isEnabled()) {
2525                            return findByUserId_PrevAndNext(entryId, userId, orderByComparator);
2526                    }
2527    
2528                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
2529    
2530                    Session session = null;
2531    
2532                    try {
2533                            session = openSession();
2534    
2535                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
2536    
2537                            array[0] = filterGetByUserId_PrevAndNext(session,
2538                                            announcementsEntry, userId, orderByComparator, true);
2539    
2540                            array[1] = announcementsEntry;
2541    
2542                            array[2] = filterGetByUserId_PrevAndNext(session,
2543                                            announcementsEntry, userId, orderByComparator, false);
2544    
2545                            return array;
2546                    }
2547                    catch (Exception e) {
2548                            throw processException(e);
2549                    }
2550                    finally {
2551                            closeSession(session);
2552                    }
2553            }
2554    
2555            protected AnnouncementsEntry filterGetByUserId_PrevAndNext(
2556                    Session session, AnnouncementsEntry announcementsEntry, long userId,
2557                    OrderByComparator orderByComparator, boolean previous) {
2558                    StringBundler query = null;
2559    
2560                    if (orderByComparator != null) {
2561                            query = new StringBundler(6 +
2562                                            (orderByComparator.getOrderByFields().length * 6));
2563                    }
2564                    else {
2565                            query = new StringBundler(3);
2566                    }
2567    
2568                    if (getDB().isSupportsInlineDistinct()) {
2569                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
2570                    }
2571                    else {
2572                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_1);
2573                    }
2574    
2575                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2576    
2577                    if (!getDB().isSupportsInlineDistinct()) {
2578                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_2);
2579                    }
2580    
2581                    if (orderByComparator != null) {
2582                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2583    
2584                            if (orderByConditionFields.length > 0) {
2585                                    query.append(WHERE_AND);
2586                            }
2587    
2588                            for (int i = 0; i < orderByConditionFields.length; i++) {
2589                                    if (getDB().isSupportsInlineDistinct()) {
2590                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2591                                    }
2592                                    else {
2593                                            query.append(_ORDER_BY_ENTITY_TABLE);
2594                                    }
2595    
2596                                    query.append(orderByConditionFields[i]);
2597    
2598                                    if ((i + 1) < orderByConditionFields.length) {
2599                                            if (orderByComparator.isAscending() ^ previous) {
2600                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2601                                            }
2602                                            else {
2603                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2604                                            }
2605                                    }
2606                                    else {
2607                                            if (orderByComparator.isAscending() ^ previous) {
2608                                                    query.append(WHERE_GREATER_THAN);
2609                                            }
2610                                            else {
2611                                                    query.append(WHERE_LESSER_THAN);
2612                                            }
2613                                    }
2614                            }
2615    
2616                            query.append(ORDER_BY_CLAUSE);
2617    
2618                            String[] orderByFields = orderByComparator.getOrderByFields();
2619    
2620                            for (int i = 0; i < orderByFields.length; i++) {
2621                                    if (getDB().isSupportsInlineDistinct()) {
2622                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2623                                    }
2624                                    else {
2625                                            query.append(_ORDER_BY_ENTITY_TABLE);
2626                                    }
2627    
2628                                    query.append(orderByFields[i]);
2629    
2630                                    if ((i + 1) < orderByFields.length) {
2631                                            if (orderByComparator.isAscending() ^ previous) {
2632                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2633                                            }
2634                                            else {
2635                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2636                                            }
2637                                    }
2638                                    else {
2639                                            if (orderByComparator.isAscending() ^ previous) {
2640                                                    query.append(ORDER_BY_ASC);
2641                                            }
2642                                            else {
2643                                                    query.append(ORDER_BY_DESC);
2644                                            }
2645                                    }
2646                            }
2647                    }
2648                    else {
2649                            if (getDB().isSupportsInlineDistinct()) {
2650                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
2651                            }
2652                            else {
2653                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_SQL);
2654                            }
2655                    }
2656    
2657                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2658                                    AnnouncementsEntry.class.getName(),
2659                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2660    
2661                    SQLQuery q = session.createSQLQuery(sql);
2662    
2663                    q.setFirstResult(0);
2664                    q.setMaxResults(2);
2665    
2666                    if (getDB().isSupportsInlineDistinct()) {
2667                            q.addEntity(_FILTER_ENTITY_ALIAS, AnnouncementsEntryImpl.class);
2668                    }
2669                    else {
2670                            q.addEntity(_FILTER_ENTITY_TABLE, AnnouncementsEntryImpl.class);
2671                    }
2672    
2673                    QueryPos qPos = QueryPos.getInstance(q);
2674    
2675                    qPos.add(userId);
2676    
2677                    if (orderByComparator != null) {
2678                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsEntry);
2679    
2680                            for (Object value : values) {
2681                                    qPos.add(value);
2682                            }
2683                    }
2684    
2685                    List<AnnouncementsEntry> list = q.list();
2686    
2687                    if (list.size() == 2) {
2688                            return list.get(1);
2689                    }
2690                    else {
2691                            return null;
2692                    }
2693            }
2694    
2695            /**
2696             * Removes all the announcements entries where userId = &#63; from the database.
2697             *
2698             * @param userId the user ID
2699             * @throws SystemException if a system exception occurred
2700             */
2701            public void removeByUserId(long userId) throws SystemException {
2702                    for (AnnouncementsEntry announcementsEntry : findByUserId(userId,
2703                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2704                            remove(announcementsEntry);
2705                    }
2706            }
2707    
2708            /**
2709             * Returns the number of announcements entries where userId = &#63;.
2710             *
2711             * @param userId the user ID
2712             * @return the number of matching announcements entries
2713             * @throws SystemException if a system exception occurred
2714             */
2715            public int countByUserId(long userId) throws SystemException {
2716                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
2717    
2718                    Object[] finderArgs = new Object[] { userId };
2719    
2720                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2721                                    this);
2722    
2723                    if (count == null) {
2724                            StringBundler query = new StringBundler(2);
2725    
2726                            query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2727    
2728                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2729    
2730                            String sql = query.toString();
2731    
2732                            Session session = null;
2733    
2734                            try {
2735                                    session = openSession();
2736    
2737                                    Query q = session.createQuery(sql);
2738    
2739                                    QueryPos qPos = QueryPos.getInstance(q);
2740    
2741                                    qPos.add(userId);
2742    
2743                                    count = (Long)q.uniqueResult();
2744    
2745                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2746                            }
2747                            catch (Exception e) {
2748                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2749    
2750                                    throw processException(e);
2751                            }
2752                            finally {
2753                                    closeSession(session);
2754                            }
2755                    }
2756    
2757                    return count.intValue();
2758            }
2759    
2760            /**
2761             * Returns the number of announcements entries that the user has permission to view where userId = &#63;.
2762             *
2763             * @param userId the user ID
2764             * @return the number of matching announcements entries that the user has permission to view
2765             * @throws SystemException if a system exception occurred
2766             */
2767            public int filterCountByUserId(long userId) throws SystemException {
2768                    if (!InlineSQLHelperUtil.isEnabled()) {
2769                            return countByUserId(userId);
2770                    }
2771    
2772                    StringBundler query = new StringBundler(2);
2773    
2774                    query.append(_FILTER_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
2775    
2776                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2777    
2778                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2779                                    AnnouncementsEntry.class.getName(),
2780                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2781    
2782                    Session session = null;
2783    
2784                    try {
2785                            session = openSession();
2786    
2787                            SQLQuery q = session.createSQLQuery(sql);
2788    
2789                            q.addScalar(COUNT_COLUMN_NAME,
2790                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2791    
2792                            QueryPos qPos = QueryPos.getInstance(q);
2793    
2794                            qPos.add(userId);
2795    
2796                            Long count = (Long)q.uniqueResult();
2797    
2798                            return count.intValue();
2799                    }
2800                    catch (Exception e) {
2801                            throw processException(e);
2802                    }
2803                    finally {
2804                            closeSession(session);
2805                    }
2806            }
2807    
2808            private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsEntry.userId = ?";
2809            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
2810                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
2811                            AnnouncementsEntryImpl.class,
2812                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
2813                            new String[] {
2814                                    Long.class.getName(), Long.class.getName(),
2815                                    
2816                            Integer.class.getName(), Integer.class.getName(),
2817                                    OrderByComparator.class.getName()
2818                            });
2819            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
2820                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
2821                            AnnouncementsEntryImpl.class,
2822                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
2823                            new String[] { Long.class.getName(), Long.class.getName() },
2824                            AnnouncementsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2825                            AnnouncementsEntryModelImpl.CLASSPK_COLUMN_BITMASK |
2826                            AnnouncementsEntryModelImpl.PRIORITY_COLUMN_BITMASK |
2827                            AnnouncementsEntryModelImpl.MODIFIEDDATE_COLUMN_BITMASK);
2828            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
2829                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2830                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
2831                            new String[] { Long.class.getName(), Long.class.getName() });
2832    
2833            /**
2834             * Returns all the announcements entries where classNameId = &#63; and classPK = &#63;.
2835             *
2836             * @param classNameId the class name ID
2837             * @param classPK the class p k
2838             * @return the matching announcements entries
2839             * @throws SystemException if a system exception occurred
2840             */
2841            public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK)
2842                    throws SystemException {
2843                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
2844                            QueryUtil.ALL_POS, null);
2845            }
2846    
2847            /**
2848             * Returns a range of all the announcements entries where classNameId = &#63; and classPK = &#63;.
2849             *
2850             * <p>
2851             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2852             * </p>
2853             *
2854             * @param classNameId the class name ID
2855             * @param classPK the class p k
2856             * @param start the lower bound of the range of announcements entries
2857             * @param end the upper bound of the range of announcements entries (not inclusive)
2858             * @return the range of matching announcements entries
2859             * @throws SystemException if a system exception occurred
2860             */
2861            public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
2862                    int start, int end) throws SystemException {
2863                    return findByC_C(classNameId, classPK, start, end, null);
2864            }
2865    
2866            /**
2867             * Returns an ordered range of all the announcements entries where classNameId = &#63; and classPK = &#63;.
2868             *
2869             * <p>
2870             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2871             * </p>
2872             *
2873             * @param classNameId the class name ID
2874             * @param classPK the class p k
2875             * @param start the lower bound of the range of announcements entries
2876             * @param end the upper bound of the range of announcements entries (not inclusive)
2877             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2878             * @return the ordered range of matching announcements entries
2879             * @throws SystemException if a system exception occurred
2880             */
2881            public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
2882                    int start, int end, OrderByComparator orderByComparator)
2883                    throws SystemException {
2884                    boolean pagination = true;
2885                    FinderPath finderPath = null;
2886                    Object[] finderArgs = null;
2887    
2888                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2889                                    (orderByComparator == null)) {
2890                            pagination = false;
2891                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
2892                            finderArgs = new Object[] { classNameId, classPK };
2893                    }
2894                    else {
2895                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
2896                            finderArgs = new Object[] {
2897                                            classNameId, classPK,
2898                                            
2899                                            start, end, orderByComparator
2900                                    };
2901                    }
2902    
2903                    List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(finderPath,
2904                                    finderArgs, this);
2905    
2906                    if ((list != null) && !list.isEmpty()) {
2907                            for (AnnouncementsEntry announcementsEntry : list) {
2908                                    if ((classNameId != announcementsEntry.getClassNameId()) ||
2909                                                    (classPK != announcementsEntry.getClassPK())) {
2910                                            list = null;
2911    
2912                                            break;
2913                                    }
2914                            }
2915                    }
2916    
2917                    if (list == null) {
2918                            StringBundler query = null;
2919    
2920                            if (orderByComparator != null) {
2921                                    query = new StringBundler(4 +
2922                                                    (orderByComparator.getOrderByFields().length * 3));
2923                            }
2924                            else {
2925                                    query = new StringBundler(4);
2926                            }
2927    
2928                            query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
2929    
2930                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2931    
2932                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2933    
2934                            if (orderByComparator != null) {
2935                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2936                                            orderByComparator);
2937                            }
2938                            else
2939                             if (pagination) {
2940                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
2941                            }
2942    
2943                            String sql = query.toString();
2944    
2945                            Session session = null;
2946    
2947                            try {
2948                                    session = openSession();
2949    
2950                                    Query q = session.createQuery(sql);
2951    
2952                                    QueryPos qPos = QueryPos.getInstance(q);
2953    
2954                                    qPos.add(classNameId);
2955    
2956                                    qPos.add(classPK);
2957    
2958                                    if (!pagination) {
2959                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
2960                                                            getDialect(), start, end, false);
2961    
2962                                            Collections.sort(list);
2963    
2964                                            list = new UnmodifiableList<AnnouncementsEntry>(list);
2965                                    }
2966                                    else {
2967                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
2968                                                            getDialect(), start, end);
2969                                    }
2970    
2971                                    cacheResult(list);
2972    
2973                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2974                            }
2975                            catch (Exception e) {
2976                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2977    
2978                                    throw processException(e);
2979                            }
2980                            finally {
2981                                    closeSession(session);
2982                            }
2983                    }
2984    
2985                    return list;
2986            }
2987    
2988            /**
2989             * Returns the first announcements entry in the ordered set where classNameId = &#63; and classPK = &#63;.
2990             *
2991             * @param classNameId the class name ID
2992             * @param classPK the class p k
2993             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2994             * @return the first matching announcements entry
2995             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
2996             * @throws SystemException if a system exception occurred
2997             */
2998            public AnnouncementsEntry findByC_C_First(long classNameId, long classPK,
2999                    OrderByComparator orderByComparator)
3000                    throws NoSuchEntryException, SystemException {
3001                    AnnouncementsEntry announcementsEntry = fetchByC_C_First(classNameId,
3002                                    classPK, orderByComparator);
3003    
3004                    if (announcementsEntry != null) {
3005                            return announcementsEntry;
3006                    }
3007    
3008                    StringBundler msg = new StringBundler(6);
3009    
3010                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3011    
3012                    msg.append("classNameId=");
3013                    msg.append(classNameId);
3014    
3015                    msg.append(", classPK=");
3016                    msg.append(classPK);
3017    
3018                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3019    
3020                    throw new NoSuchEntryException(msg.toString());
3021            }
3022    
3023            /**
3024             * Returns the first announcements entry in the ordered set where classNameId = &#63; and classPK = &#63;.
3025             *
3026             * @param classNameId the class name ID
3027             * @param classPK the class p k
3028             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3029             * @return the first matching announcements entry, or <code>null</code> if a matching announcements entry could not be found
3030             * @throws SystemException if a system exception occurred
3031             */
3032            public AnnouncementsEntry fetchByC_C_First(long classNameId, long classPK,
3033                    OrderByComparator orderByComparator) throws SystemException {
3034                    List<AnnouncementsEntry> list = findByC_C(classNameId, classPK, 0, 1,
3035                                    orderByComparator);
3036    
3037                    if (!list.isEmpty()) {
3038                            return list.get(0);
3039                    }
3040    
3041                    return null;
3042            }
3043    
3044            /**
3045             * Returns the last announcements entry in the ordered set where classNameId = &#63; and classPK = &#63;.
3046             *
3047             * @param classNameId the class name ID
3048             * @param classPK the class p k
3049             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3050             * @return the last matching announcements entry
3051             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
3052             * @throws SystemException if a system exception occurred
3053             */
3054            public AnnouncementsEntry findByC_C_Last(long classNameId, long classPK,
3055                    OrderByComparator orderByComparator)
3056                    throws NoSuchEntryException, SystemException {
3057                    AnnouncementsEntry announcementsEntry = fetchByC_C_Last(classNameId,
3058                                    classPK, orderByComparator);
3059    
3060                    if (announcementsEntry != null) {
3061                            return announcementsEntry;
3062                    }
3063    
3064                    StringBundler msg = new StringBundler(6);
3065    
3066                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3067    
3068                    msg.append("classNameId=");
3069                    msg.append(classNameId);
3070    
3071                    msg.append(", classPK=");
3072                    msg.append(classPK);
3073    
3074                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3075    
3076                    throw new NoSuchEntryException(msg.toString());
3077            }
3078    
3079            /**
3080             * Returns the last announcements entry in the ordered set where classNameId = &#63; and classPK = &#63;.
3081             *
3082             * @param classNameId the class name ID
3083             * @param classPK the class p k
3084             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3085             * @return the last matching announcements entry, or <code>null</code> if a matching announcements entry could not be found
3086             * @throws SystemException if a system exception occurred
3087             */
3088            public AnnouncementsEntry fetchByC_C_Last(long classNameId, long classPK,
3089                    OrderByComparator orderByComparator) throws SystemException {
3090                    int count = countByC_C(classNameId, classPK);
3091    
3092                    List<AnnouncementsEntry> list = findByC_C(classNameId, classPK,
3093                                    count - 1, count, orderByComparator);
3094    
3095                    if (!list.isEmpty()) {
3096                            return list.get(0);
3097                    }
3098    
3099                    return null;
3100            }
3101    
3102            /**
3103             * Returns the announcements entries before and after the current announcements entry in the ordered set where classNameId = &#63; and classPK = &#63;.
3104             *
3105             * @param entryId the primary key of the current announcements entry
3106             * @param classNameId the class name ID
3107             * @param classPK the class p k
3108             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3109             * @return the previous, current, and next announcements entry
3110             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
3111             * @throws SystemException if a system exception occurred
3112             */
3113            public AnnouncementsEntry[] findByC_C_PrevAndNext(long entryId,
3114                    long classNameId, long classPK, OrderByComparator orderByComparator)
3115                    throws NoSuchEntryException, SystemException {
3116                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
3117    
3118                    Session session = null;
3119    
3120                    try {
3121                            session = openSession();
3122    
3123                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
3124    
3125                            array[0] = getByC_C_PrevAndNext(session, announcementsEntry,
3126                                            classNameId, classPK, orderByComparator, true);
3127    
3128                            array[1] = announcementsEntry;
3129    
3130                            array[2] = getByC_C_PrevAndNext(session, announcementsEntry,
3131                                            classNameId, classPK, orderByComparator, false);
3132    
3133                            return array;
3134                    }
3135                    catch (Exception e) {
3136                            throw processException(e);
3137                    }
3138                    finally {
3139                            closeSession(session);
3140                    }
3141            }
3142    
3143            protected AnnouncementsEntry getByC_C_PrevAndNext(Session session,
3144                    AnnouncementsEntry announcementsEntry, long classNameId, long classPK,
3145                    OrderByComparator orderByComparator, boolean previous) {
3146                    StringBundler query = null;
3147    
3148                    if (orderByComparator != null) {
3149                            query = new StringBundler(6 +
3150                                            (orderByComparator.getOrderByFields().length * 6));
3151                    }
3152                    else {
3153                            query = new StringBundler(3);
3154                    }
3155    
3156                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
3157    
3158                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3159    
3160                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3161    
3162                    if (orderByComparator != null) {
3163                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3164    
3165                            if (orderByConditionFields.length > 0) {
3166                                    query.append(WHERE_AND);
3167                            }
3168    
3169                            for (int i = 0; i < orderByConditionFields.length; i++) {
3170                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3171                                    query.append(orderByConditionFields[i]);
3172    
3173                                    if ((i + 1) < orderByConditionFields.length) {
3174                                            if (orderByComparator.isAscending() ^ previous) {
3175                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3176                                            }
3177                                            else {
3178                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3179                                            }
3180                                    }
3181                                    else {
3182                                            if (orderByComparator.isAscending() ^ previous) {
3183                                                    query.append(WHERE_GREATER_THAN);
3184                                            }
3185                                            else {
3186                                                    query.append(WHERE_LESSER_THAN);
3187                                            }
3188                                    }
3189                            }
3190    
3191                            query.append(ORDER_BY_CLAUSE);
3192    
3193                            String[] orderByFields = orderByComparator.getOrderByFields();
3194    
3195                            for (int i = 0; i < orderByFields.length; i++) {
3196                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3197                                    query.append(orderByFields[i]);
3198    
3199                                    if ((i + 1) < orderByFields.length) {
3200                                            if (orderByComparator.isAscending() ^ previous) {
3201                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3202                                            }
3203                                            else {
3204                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3205                                            }
3206                                    }
3207                                    else {
3208                                            if (orderByComparator.isAscending() ^ previous) {
3209                                                    query.append(ORDER_BY_ASC);
3210                                            }
3211                                            else {
3212                                                    query.append(ORDER_BY_DESC);
3213                                            }
3214                                    }
3215                            }
3216                    }
3217                    else {
3218                            query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
3219                    }
3220    
3221                    String sql = query.toString();
3222    
3223                    Query q = session.createQuery(sql);
3224    
3225                    q.setFirstResult(0);
3226                    q.setMaxResults(2);
3227    
3228                    QueryPos qPos = QueryPos.getInstance(q);
3229    
3230                    qPos.add(classNameId);
3231    
3232                    qPos.add(classPK);
3233    
3234                    if (orderByComparator != null) {
3235                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsEntry);
3236    
3237                            for (Object value : values) {
3238                                    qPos.add(value);
3239                            }
3240                    }
3241    
3242                    List<AnnouncementsEntry> list = q.list();
3243    
3244                    if (list.size() == 2) {
3245                            return list.get(1);
3246                    }
3247                    else {
3248                            return null;
3249                    }
3250            }
3251    
3252            /**
3253             * Returns all the announcements entries that the user has permission to view where classNameId = &#63; and classPK = &#63;.
3254             *
3255             * @param classNameId the class name ID
3256             * @param classPK the class p k
3257             * @return the matching announcements entries that the user has permission to view
3258             * @throws SystemException if a system exception occurred
3259             */
3260            public List<AnnouncementsEntry> filterFindByC_C(long classNameId,
3261                    long classPK) throws SystemException {
3262                    return filterFindByC_C(classNameId, classPK, QueryUtil.ALL_POS,
3263                            QueryUtil.ALL_POS, null);
3264            }
3265    
3266            /**
3267             * Returns a range of all the announcements entries that the user has permission to view where classNameId = &#63; and classPK = &#63;.
3268             *
3269             * <p>
3270             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3271             * </p>
3272             *
3273             * @param classNameId the class name ID
3274             * @param classPK the class p k
3275             * @param start the lower bound of the range of announcements entries
3276             * @param end the upper bound of the range of announcements entries (not inclusive)
3277             * @return the range of matching announcements entries that the user has permission to view
3278             * @throws SystemException if a system exception occurred
3279             */
3280            public List<AnnouncementsEntry> filterFindByC_C(long classNameId,
3281                    long classPK, int start, int end) throws SystemException {
3282                    return filterFindByC_C(classNameId, classPK, start, end, null);
3283            }
3284    
3285            /**
3286             * Returns an ordered range of all the announcements entries that the user has permissions to view where classNameId = &#63; and classPK = &#63;.
3287             *
3288             * <p>
3289             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3290             * </p>
3291             *
3292             * @param classNameId the class name ID
3293             * @param classPK the class p k
3294             * @param start the lower bound of the range of announcements entries
3295             * @param end the upper bound of the range of announcements entries (not inclusive)
3296             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3297             * @return the ordered range of matching announcements entries that the user has permission to view
3298             * @throws SystemException if a system exception occurred
3299             */
3300            public List<AnnouncementsEntry> filterFindByC_C(long classNameId,
3301                    long classPK, int start, int end, OrderByComparator orderByComparator)
3302                    throws SystemException {
3303                    if (!InlineSQLHelperUtil.isEnabled()) {
3304                            return findByC_C(classNameId, classPK, start, end, orderByComparator);
3305                    }
3306    
3307                    StringBundler query = null;
3308    
3309                    if (orderByComparator != null) {
3310                            query = new StringBundler(4 +
3311                                            (orderByComparator.getOrderByFields().length * 3));
3312                    }
3313                    else {
3314                            query = new StringBundler(4);
3315                    }
3316    
3317                    if (getDB().isSupportsInlineDistinct()) {
3318                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
3319                    }
3320                    else {
3321                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_1);
3322                    }
3323    
3324                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3325    
3326                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3327    
3328                    if (!getDB().isSupportsInlineDistinct()) {
3329                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_2);
3330                    }
3331    
3332                    if (orderByComparator != null) {
3333                            if (getDB().isSupportsInlineDistinct()) {
3334                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3335                                            orderByComparator);
3336                            }
3337                            else {
3338                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3339                                            orderByComparator);
3340                            }
3341                    }
3342                    else {
3343                            if (getDB().isSupportsInlineDistinct()) {
3344                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
3345                            }
3346                            else {
3347                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_SQL);
3348                            }
3349                    }
3350    
3351                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3352                                    AnnouncementsEntry.class.getName(),
3353                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3354    
3355                    Session session = null;
3356    
3357                    try {
3358                            session = openSession();
3359    
3360                            SQLQuery q = session.createSQLQuery(sql);
3361    
3362                            if (getDB().isSupportsInlineDistinct()) {
3363                                    q.addEntity(_FILTER_ENTITY_ALIAS, AnnouncementsEntryImpl.class);
3364                            }
3365                            else {
3366                                    q.addEntity(_FILTER_ENTITY_TABLE, AnnouncementsEntryImpl.class);
3367                            }
3368    
3369                            QueryPos qPos = QueryPos.getInstance(q);
3370    
3371                            qPos.add(classNameId);
3372    
3373                            qPos.add(classPK);
3374    
3375                            return (List<AnnouncementsEntry>)QueryUtil.list(q, getDialect(),
3376                                    start, end);
3377                    }
3378                    catch (Exception e) {
3379                            throw processException(e);
3380                    }
3381                    finally {
3382                            closeSession(session);
3383                    }
3384            }
3385    
3386            /**
3387             * Returns the announcements entries before and after the current announcements entry in the ordered set of announcements entries that the user has permission to view where classNameId = &#63; and classPK = &#63;.
3388             *
3389             * @param entryId the primary key of the current announcements entry
3390             * @param classNameId the class name ID
3391             * @param classPK the class p k
3392             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3393             * @return the previous, current, and next announcements entry
3394             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
3395             * @throws SystemException if a system exception occurred
3396             */
3397            public AnnouncementsEntry[] filterFindByC_C_PrevAndNext(long entryId,
3398                    long classNameId, long classPK, OrderByComparator orderByComparator)
3399                    throws NoSuchEntryException, SystemException {
3400                    if (!InlineSQLHelperUtil.isEnabled()) {
3401                            return findByC_C_PrevAndNext(entryId, classNameId, classPK,
3402                                    orderByComparator);
3403                    }
3404    
3405                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
3406    
3407                    Session session = null;
3408    
3409                    try {
3410                            session = openSession();
3411    
3412                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
3413    
3414                            array[0] = filterGetByC_C_PrevAndNext(session, announcementsEntry,
3415                                            classNameId, classPK, orderByComparator, true);
3416    
3417                            array[1] = announcementsEntry;
3418    
3419                            array[2] = filterGetByC_C_PrevAndNext(session, announcementsEntry,
3420                                            classNameId, classPK, orderByComparator, false);
3421    
3422                            return array;
3423                    }
3424                    catch (Exception e) {
3425                            throw processException(e);
3426                    }
3427                    finally {
3428                            closeSession(session);
3429                    }
3430            }
3431    
3432            protected AnnouncementsEntry filterGetByC_C_PrevAndNext(Session session,
3433                    AnnouncementsEntry announcementsEntry, long classNameId, long classPK,
3434                    OrderByComparator orderByComparator, boolean previous) {
3435                    StringBundler query = null;
3436    
3437                    if (orderByComparator != null) {
3438                            query = new StringBundler(6 +
3439                                            (orderByComparator.getOrderByFields().length * 6));
3440                    }
3441                    else {
3442                            query = new StringBundler(3);
3443                    }
3444    
3445                    if (getDB().isSupportsInlineDistinct()) {
3446                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
3447                    }
3448                    else {
3449                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_1);
3450                    }
3451    
3452                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3453    
3454                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3455    
3456                    if (!getDB().isSupportsInlineDistinct()) {
3457                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_2);
3458                    }
3459    
3460                    if (orderByComparator != null) {
3461                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3462    
3463                            if (orderByConditionFields.length > 0) {
3464                                    query.append(WHERE_AND);
3465                            }
3466    
3467                            for (int i = 0; i < orderByConditionFields.length; i++) {
3468                                    if (getDB().isSupportsInlineDistinct()) {
3469                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3470                                    }
3471                                    else {
3472                                            query.append(_ORDER_BY_ENTITY_TABLE);
3473                                    }
3474    
3475                                    query.append(orderByConditionFields[i]);
3476    
3477                                    if ((i + 1) < orderByConditionFields.length) {
3478                                            if (orderByComparator.isAscending() ^ previous) {
3479                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3480                                            }
3481                                            else {
3482                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3483                                            }
3484                                    }
3485                                    else {
3486                                            if (orderByComparator.isAscending() ^ previous) {
3487                                                    query.append(WHERE_GREATER_THAN);
3488                                            }
3489                                            else {
3490                                                    query.append(WHERE_LESSER_THAN);
3491                                            }
3492                                    }
3493                            }
3494    
3495                            query.append(ORDER_BY_CLAUSE);
3496    
3497                            String[] orderByFields = orderByComparator.getOrderByFields();
3498    
3499                            for (int i = 0; i < orderByFields.length; i++) {
3500                                    if (getDB().isSupportsInlineDistinct()) {
3501                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3502                                    }
3503                                    else {
3504                                            query.append(_ORDER_BY_ENTITY_TABLE);
3505                                    }
3506    
3507                                    query.append(orderByFields[i]);
3508    
3509                                    if ((i + 1) < orderByFields.length) {
3510                                            if (orderByComparator.isAscending() ^ previous) {
3511                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3512                                            }
3513                                            else {
3514                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3515                                            }
3516                                    }
3517                                    else {
3518                                            if (orderByComparator.isAscending() ^ previous) {
3519                                                    query.append(ORDER_BY_ASC);
3520                                            }
3521                                            else {
3522                                                    query.append(ORDER_BY_DESC);
3523                                            }
3524                                    }
3525                            }
3526                    }
3527                    else {
3528                            if (getDB().isSupportsInlineDistinct()) {
3529                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
3530                            }
3531                            else {
3532                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_SQL);
3533                            }
3534                    }
3535    
3536                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3537                                    AnnouncementsEntry.class.getName(),
3538                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3539    
3540                    SQLQuery q = session.createSQLQuery(sql);
3541    
3542                    q.setFirstResult(0);
3543                    q.setMaxResults(2);
3544    
3545                    if (getDB().isSupportsInlineDistinct()) {
3546                            q.addEntity(_FILTER_ENTITY_ALIAS, AnnouncementsEntryImpl.class);
3547                    }
3548                    else {
3549                            q.addEntity(_FILTER_ENTITY_TABLE, AnnouncementsEntryImpl.class);
3550                    }
3551    
3552                    QueryPos qPos = QueryPos.getInstance(q);
3553    
3554                    qPos.add(classNameId);
3555    
3556                    qPos.add(classPK);
3557    
3558                    if (orderByComparator != null) {
3559                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsEntry);
3560    
3561                            for (Object value : values) {
3562                                    qPos.add(value);
3563                            }
3564                    }
3565    
3566                    List<AnnouncementsEntry> list = q.list();
3567    
3568                    if (list.size() == 2) {
3569                            return list.get(1);
3570                    }
3571                    else {
3572                            return null;
3573                    }
3574            }
3575    
3576            /**
3577             * Removes all the announcements entries where classNameId = &#63; and classPK = &#63; from the database.
3578             *
3579             * @param classNameId the class name ID
3580             * @param classPK the class p k
3581             * @throws SystemException if a system exception occurred
3582             */
3583            public void removeByC_C(long classNameId, long classPK)
3584                    throws SystemException {
3585                    for (AnnouncementsEntry announcementsEntry : findByC_C(classNameId,
3586                                    classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3587                            remove(announcementsEntry);
3588                    }
3589            }
3590    
3591            /**
3592             * Returns the number of announcements entries where classNameId = &#63; and classPK = &#63;.
3593             *
3594             * @param classNameId the class name ID
3595             * @param classPK the class p k
3596             * @return the number of matching announcements entries
3597             * @throws SystemException if a system exception occurred
3598             */
3599            public int countByC_C(long classNameId, long classPK)
3600                    throws SystemException {
3601                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
3602    
3603                    Object[] finderArgs = new Object[] { classNameId, classPK };
3604    
3605                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3606                                    this);
3607    
3608                    if (count == null) {
3609                            StringBundler query = new StringBundler(3);
3610    
3611                            query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
3612    
3613                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3614    
3615                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3616    
3617                            String sql = query.toString();
3618    
3619                            Session session = null;
3620    
3621                            try {
3622                                    session = openSession();
3623    
3624                                    Query q = session.createQuery(sql);
3625    
3626                                    QueryPos qPos = QueryPos.getInstance(q);
3627    
3628                                    qPos.add(classNameId);
3629    
3630                                    qPos.add(classPK);
3631    
3632                                    count = (Long)q.uniqueResult();
3633    
3634                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3635                            }
3636                            catch (Exception e) {
3637                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3638    
3639                                    throw processException(e);
3640                            }
3641                            finally {
3642                                    closeSession(session);
3643                            }
3644                    }
3645    
3646                    return count.intValue();
3647            }
3648    
3649            /**
3650             * Returns the number of announcements entries that the user has permission to view where classNameId = &#63; and classPK = &#63;.
3651             *
3652             * @param classNameId the class name ID
3653             * @param classPK the class p k
3654             * @return the number of matching announcements entries that the user has permission to view
3655             * @throws SystemException if a system exception occurred
3656             */
3657            public int filterCountByC_C(long classNameId, long classPK)
3658                    throws SystemException {
3659                    if (!InlineSQLHelperUtil.isEnabled()) {
3660                            return countByC_C(classNameId, classPK);
3661                    }
3662    
3663                    StringBundler query = new StringBundler(3);
3664    
3665                    query.append(_FILTER_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
3666    
3667                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3668    
3669                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3670    
3671                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3672                                    AnnouncementsEntry.class.getName(),
3673                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3674    
3675                    Session session = null;
3676    
3677                    try {
3678                            session = openSession();
3679    
3680                            SQLQuery q = session.createSQLQuery(sql);
3681    
3682                            q.addScalar(COUNT_COLUMN_NAME,
3683                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3684    
3685                            QueryPos qPos = QueryPos.getInstance(q);
3686    
3687                            qPos.add(classNameId);
3688    
3689                            qPos.add(classPK);
3690    
3691                            Long count = (Long)q.uniqueResult();
3692    
3693                            return count.intValue();
3694                    }
3695                    catch (Exception e) {
3696                            throw processException(e);
3697                    }
3698                    finally {
3699                            closeSession(session);
3700                    }
3701            }
3702    
3703            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "announcementsEntry.classNameId = ? AND ";
3704            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "announcementsEntry.classPK = ?";
3705            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_A = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
3706                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
3707                            AnnouncementsEntryImpl.class,
3708                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_A",
3709                            new String[] {
3710                                    Long.class.getName(), Long.class.getName(),
3711                                    Boolean.class.getName(),
3712                                    
3713                            Integer.class.getName(), Integer.class.getName(),
3714                                    OrderByComparator.class.getName()
3715                            });
3716            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_A = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
3717                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED,
3718                            AnnouncementsEntryImpl.class,
3719                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_A",
3720                            new String[] {
3721                                    Long.class.getName(), Long.class.getName(),
3722                                    Boolean.class.getName()
3723                            },
3724                            AnnouncementsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3725                            AnnouncementsEntryModelImpl.CLASSPK_COLUMN_BITMASK |
3726                            AnnouncementsEntryModelImpl.ALERT_COLUMN_BITMASK |
3727                            AnnouncementsEntryModelImpl.PRIORITY_COLUMN_BITMASK |
3728                            AnnouncementsEntryModelImpl.MODIFIEDDATE_COLUMN_BITMASK);
3729            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_A = new FinderPath(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
3730                            AnnouncementsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
3731                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_A",
3732                            new String[] {
3733                                    Long.class.getName(), Long.class.getName(),
3734                                    Boolean.class.getName()
3735                            });
3736    
3737            /**
3738             * Returns all the announcements entries where classNameId = &#63; and classPK = &#63; and alert = &#63;.
3739             *
3740             * @param classNameId the class name ID
3741             * @param classPK the class p k
3742             * @param alert the alert
3743             * @return the matching announcements entries
3744             * @throws SystemException if a system exception occurred
3745             */
3746            public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
3747                    boolean alert) throws SystemException {
3748                    return findByC_C_A(classNameId, classPK, alert, QueryUtil.ALL_POS,
3749                            QueryUtil.ALL_POS, null);
3750            }
3751    
3752            /**
3753             * Returns a range of all the announcements entries where classNameId = &#63; and classPK = &#63; and alert = &#63;.
3754             *
3755             * <p>
3756             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3757             * </p>
3758             *
3759             * @param classNameId the class name ID
3760             * @param classPK the class p k
3761             * @param alert the alert
3762             * @param start the lower bound of the range of announcements entries
3763             * @param end the upper bound of the range of announcements entries (not inclusive)
3764             * @return the range of matching announcements entries
3765             * @throws SystemException if a system exception occurred
3766             */
3767            public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
3768                    boolean alert, int start, int end) throws SystemException {
3769                    return findByC_C_A(classNameId, classPK, alert, start, end, null);
3770            }
3771    
3772            /**
3773             * Returns an ordered range of all the announcements entries where classNameId = &#63; and classPK = &#63; and alert = &#63;.
3774             *
3775             * <p>
3776             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3777             * </p>
3778             *
3779             * @param classNameId the class name ID
3780             * @param classPK the class p k
3781             * @param alert the alert
3782             * @param start the lower bound of the range of announcements entries
3783             * @param end the upper bound of the range of announcements entries (not inclusive)
3784             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3785             * @return the ordered range of matching announcements entries
3786             * @throws SystemException if a system exception occurred
3787             */
3788            public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
3789                    boolean alert, int start, int end, OrderByComparator orderByComparator)
3790                    throws SystemException {
3791                    boolean pagination = true;
3792                    FinderPath finderPath = null;
3793                    Object[] finderArgs = null;
3794    
3795                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3796                                    (orderByComparator == null)) {
3797                            pagination = false;
3798                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_A;
3799                            finderArgs = new Object[] { classNameId, classPK, alert };
3800                    }
3801                    else {
3802                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_A;
3803                            finderArgs = new Object[] {
3804                                            classNameId, classPK, alert,
3805                                            
3806                                            start, end, orderByComparator
3807                                    };
3808                    }
3809    
3810                    List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(finderPath,
3811                                    finderArgs, this);
3812    
3813                    if ((list != null) && !list.isEmpty()) {
3814                            for (AnnouncementsEntry announcementsEntry : list) {
3815                                    if ((classNameId != announcementsEntry.getClassNameId()) ||
3816                                                    (classPK != announcementsEntry.getClassPK()) ||
3817                                                    (alert != announcementsEntry.getAlert())) {
3818                                            list = null;
3819    
3820                                            break;
3821                                    }
3822                            }
3823                    }
3824    
3825                    if (list == null) {
3826                            StringBundler query = null;
3827    
3828                            if (orderByComparator != null) {
3829                                    query = new StringBundler(5 +
3830                                                    (orderByComparator.getOrderByFields().length * 3));
3831                            }
3832                            else {
3833                                    query = new StringBundler(5);
3834                            }
3835    
3836                            query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
3837    
3838                            query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
3839    
3840                            query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
3841    
3842                            query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
3843    
3844                            if (orderByComparator != null) {
3845                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3846                                            orderByComparator);
3847                            }
3848                            else
3849                             if (pagination) {
3850                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
3851                            }
3852    
3853                            String sql = query.toString();
3854    
3855                            Session session = null;
3856    
3857                            try {
3858                                    session = openSession();
3859    
3860                                    Query q = session.createQuery(sql);
3861    
3862                                    QueryPos qPos = QueryPos.getInstance(q);
3863    
3864                                    qPos.add(classNameId);
3865    
3866                                    qPos.add(classPK);
3867    
3868                                    qPos.add(alert);
3869    
3870                                    if (!pagination) {
3871                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
3872                                                            getDialect(), start, end, false);
3873    
3874                                            Collections.sort(list);
3875    
3876                                            list = new UnmodifiableList<AnnouncementsEntry>(list);
3877                                    }
3878                                    else {
3879                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
3880                                                            getDialect(), start, end);
3881                                    }
3882    
3883                                    cacheResult(list);
3884    
3885                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3886                            }
3887                            catch (Exception e) {
3888                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3889    
3890                                    throw processException(e);
3891                            }
3892                            finally {
3893                                    closeSession(session);
3894                            }
3895                    }
3896    
3897                    return list;
3898            }
3899    
3900            /**
3901             * Returns the first announcements entry in the ordered set where classNameId = &#63; and classPK = &#63; and alert = &#63;.
3902             *
3903             * @param classNameId the class name ID
3904             * @param classPK the class p k
3905             * @param alert the alert
3906             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3907             * @return the first matching announcements entry
3908             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
3909             * @throws SystemException if a system exception occurred
3910             */
3911            public AnnouncementsEntry findByC_C_A_First(long classNameId, long classPK,
3912                    boolean alert, OrderByComparator orderByComparator)
3913                    throws NoSuchEntryException, SystemException {
3914                    AnnouncementsEntry announcementsEntry = fetchByC_C_A_First(classNameId,
3915                                    classPK, alert, orderByComparator);
3916    
3917                    if (announcementsEntry != null) {
3918                            return announcementsEntry;
3919                    }
3920    
3921                    StringBundler msg = new StringBundler(8);
3922    
3923                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3924    
3925                    msg.append("classNameId=");
3926                    msg.append(classNameId);
3927    
3928                    msg.append(", classPK=");
3929                    msg.append(classPK);
3930    
3931                    msg.append(", alert=");
3932                    msg.append(alert);
3933    
3934                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3935    
3936                    throw new NoSuchEntryException(msg.toString());
3937            }
3938    
3939            /**
3940             * Returns the first announcements entry in the ordered set where classNameId = &#63; and classPK = &#63; and alert = &#63;.
3941             *
3942             * @param classNameId the class name ID
3943             * @param classPK the class p k
3944             * @param alert the alert
3945             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3946             * @return the first matching announcements entry, or <code>null</code> if a matching announcements entry could not be found
3947             * @throws SystemException if a system exception occurred
3948             */
3949            public AnnouncementsEntry fetchByC_C_A_First(long classNameId,
3950                    long classPK, boolean alert, OrderByComparator orderByComparator)
3951                    throws SystemException {
3952                    List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
3953                                    alert, 0, 1, orderByComparator);
3954    
3955                    if (!list.isEmpty()) {
3956                            return list.get(0);
3957                    }
3958    
3959                    return null;
3960            }
3961    
3962            /**
3963             * Returns the last announcements entry in the ordered set where classNameId = &#63; and classPK = &#63; and alert = &#63;.
3964             *
3965             * @param classNameId the class name ID
3966             * @param classPK the class p k
3967             * @param alert the alert
3968             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3969             * @return the last matching announcements entry
3970             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a matching announcements entry could not be found
3971             * @throws SystemException if a system exception occurred
3972             */
3973            public AnnouncementsEntry findByC_C_A_Last(long classNameId, long classPK,
3974                    boolean alert, OrderByComparator orderByComparator)
3975                    throws NoSuchEntryException, SystemException {
3976                    AnnouncementsEntry announcementsEntry = fetchByC_C_A_Last(classNameId,
3977                                    classPK, alert, orderByComparator);
3978    
3979                    if (announcementsEntry != null) {
3980                            return announcementsEntry;
3981                    }
3982    
3983                    StringBundler msg = new StringBundler(8);
3984    
3985                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3986    
3987                    msg.append("classNameId=");
3988                    msg.append(classNameId);
3989    
3990                    msg.append(", classPK=");
3991                    msg.append(classPK);
3992    
3993                    msg.append(", alert=");
3994                    msg.append(alert);
3995    
3996                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3997    
3998                    throw new NoSuchEntryException(msg.toString());
3999            }
4000    
4001            /**
4002             * Returns the last announcements entry in the ordered set where classNameId = &#63; and classPK = &#63; and alert = &#63;.
4003             *
4004             * @param classNameId the class name ID
4005             * @param classPK the class p k
4006             * @param alert the alert
4007             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4008             * @return the last matching announcements entry, or <code>null</code> if a matching announcements entry could not be found
4009             * @throws SystemException if a system exception occurred
4010             */
4011            public AnnouncementsEntry fetchByC_C_A_Last(long classNameId, long classPK,
4012                    boolean alert, OrderByComparator orderByComparator)
4013                    throws SystemException {
4014                    int count = countByC_C_A(classNameId, classPK, alert);
4015    
4016                    List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
4017                                    alert, count - 1, count, orderByComparator);
4018    
4019                    if (!list.isEmpty()) {
4020                            return list.get(0);
4021                    }
4022    
4023                    return null;
4024            }
4025    
4026            /**
4027             * Returns the announcements entries before and after the current announcements entry in the ordered set where classNameId = &#63; and classPK = &#63; and alert = &#63;.
4028             *
4029             * @param entryId the primary key of the current announcements entry
4030             * @param classNameId the class name ID
4031             * @param classPK the class p k
4032             * @param alert the alert
4033             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4034             * @return the previous, current, and next announcements entry
4035             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
4036             * @throws SystemException if a system exception occurred
4037             */
4038            public AnnouncementsEntry[] findByC_C_A_PrevAndNext(long entryId,
4039                    long classNameId, long classPK, boolean alert,
4040                    OrderByComparator orderByComparator)
4041                    throws NoSuchEntryException, SystemException {
4042                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
4043    
4044                    Session session = null;
4045    
4046                    try {
4047                            session = openSession();
4048    
4049                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
4050    
4051                            array[0] = getByC_C_A_PrevAndNext(session, announcementsEntry,
4052                                            classNameId, classPK, alert, orderByComparator, true);
4053    
4054                            array[1] = announcementsEntry;
4055    
4056                            array[2] = getByC_C_A_PrevAndNext(session, announcementsEntry,
4057                                            classNameId, classPK, alert, orderByComparator, false);
4058    
4059                            return array;
4060                    }
4061                    catch (Exception e) {
4062                            throw processException(e);
4063                    }
4064                    finally {
4065                            closeSession(session);
4066                    }
4067            }
4068    
4069            protected AnnouncementsEntry getByC_C_A_PrevAndNext(Session session,
4070                    AnnouncementsEntry announcementsEntry, long classNameId, long classPK,
4071                    boolean alert, OrderByComparator orderByComparator, boolean previous) {
4072                    StringBundler query = null;
4073    
4074                    if (orderByComparator != null) {
4075                            query = new StringBundler(6 +
4076                                            (orderByComparator.getOrderByFields().length * 6));
4077                    }
4078                    else {
4079                            query = new StringBundler(3);
4080                    }
4081    
4082                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
4083    
4084                    query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
4085    
4086                    query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
4087    
4088                    query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
4089    
4090                    if (orderByComparator != null) {
4091                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4092    
4093                            if (orderByConditionFields.length > 0) {
4094                                    query.append(WHERE_AND);
4095                            }
4096    
4097                            for (int i = 0; i < orderByConditionFields.length; i++) {
4098                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4099                                    query.append(orderByConditionFields[i]);
4100    
4101                                    if ((i + 1) < orderByConditionFields.length) {
4102                                            if (orderByComparator.isAscending() ^ previous) {
4103                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4104                                            }
4105                                            else {
4106                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4107                                            }
4108                                    }
4109                                    else {
4110                                            if (orderByComparator.isAscending() ^ previous) {
4111                                                    query.append(WHERE_GREATER_THAN);
4112                                            }
4113                                            else {
4114                                                    query.append(WHERE_LESSER_THAN);
4115                                            }
4116                                    }
4117                            }
4118    
4119                            query.append(ORDER_BY_CLAUSE);
4120    
4121                            String[] orderByFields = orderByComparator.getOrderByFields();
4122    
4123                            for (int i = 0; i < orderByFields.length; i++) {
4124                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4125                                    query.append(orderByFields[i]);
4126    
4127                                    if ((i + 1) < orderByFields.length) {
4128                                            if (orderByComparator.isAscending() ^ previous) {
4129                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4130                                            }
4131                                            else {
4132                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4133                                            }
4134                                    }
4135                                    else {
4136                                            if (orderByComparator.isAscending() ^ previous) {
4137                                                    query.append(ORDER_BY_ASC);
4138                                            }
4139                                            else {
4140                                                    query.append(ORDER_BY_DESC);
4141                                            }
4142                                    }
4143                            }
4144                    }
4145                    else {
4146                            query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
4147                    }
4148    
4149                    String sql = query.toString();
4150    
4151                    Query q = session.createQuery(sql);
4152    
4153                    q.setFirstResult(0);
4154                    q.setMaxResults(2);
4155    
4156                    QueryPos qPos = QueryPos.getInstance(q);
4157    
4158                    qPos.add(classNameId);
4159    
4160                    qPos.add(classPK);
4161    
4162                    qPos.add(alert);
4163    
4164                    if (orderByComparator != null) {
4165                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsEntry);
4166    
4167                            for (Object value : values) {
4168                                    qPos.add(value);
4169                            }
4170                    }
4171    
4172                    List<AnnouncementsEntry> list = q.list();
4173    
4174                    if (list.size() == 2) {
4175                            return list.get(1);
4176                    }
4177                    else {
4178                            return null;
4179                    }
4180            }
4181    
4182            /**
4183             * Returns all the announcements entries that the user has permission to view where classNameId = &#63; and classPK = &#63; and alert = &#63;.
4184             *
4185             * @param classNameId the class name ID
4186             * @param classPK the class p k
4187             * @param alert the alert
4188             * @return the matching announcements entries that the user has permission to view
4189             * @throws SystemException if a system exception occurred
4190             */
4191            public List<AnnouncementsEntry> filterFindByC_C_A(long classNameId,
4192                    long classPK, boolean alert) throws SystemException {
4193                    return filterFindByC_C_A(classNameId, classPK, alert,
4194                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4195            }
4196    
4197            /**
4198             * Returns a range of all the announcements entries that the user has permission to view where classNameId = &#63; and classPK = &#63; and alert = &#63;.
4199             *
4200             * <p>
4201             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4202             * </p>
4203             *
4204             * @param classNameId the class name ID
4205             * @param classPK the class p k
4206             * @param alert the alert
4207             * @param start the lower bound of the range of announcements entries
4208             * @param end the upper bound of the range of announcements entries (not inclusive)
4209             * @return the range of matching announcements entries that the user has permission to view
4210             * @throws SystemException if a system exception occurred
4211             */
4212            public List<AnnouncementsEntry> filterFindByC_C_A(long classNameId,
4213                    long classPK, boolean alert, int start, int end)
4214                    throws SystemException {
4215                    return filterFindByC_C_A(classNameId, classPK, alert, start, end, null);
4216            }
4217    
4218            /**
4219             * Returns an ordered range of all the announcements entries that the user has permissions to view where classNameId = &#63; and classPK = &#63; and alert = &#63;.
4220             *
4221             * <p>
4222             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4223             * </p>
4224             *
4225             * @param classNameId the class name ID
4226             * @param classPK the class p k
4227             * @param alert the alert
4228             * @param start the lower bound of the range of announcements entries
4229             * @param end the upper bound of the range of announcements entries (not inclusive)
4230             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4231             * @return the ordered range of matching announcements entries that the user has permission to view
4232             * @throws SystemException if a system exception occurred
4233             */
4234            public List<AnnouncementsEntry> filterFindByC_C_A(long classNameId,
4235                    long classPK, boolean alert, int start, int end,
4236                    OrderByComparator orderByComparator) throws SystemException {
4237                    if (!InlineSQLHelperUtil.isEnabled()) {
4238                            return findByC_C_A(classNameId, classPK, alert, start, end,
4239                                    orderByComparator);
4240                    }
4241    
4242                    StringBundler query = null;
4243    
4244                    if (orderByComparator != null) {
4245                            query = new StringBundler(5 +
4246                                            (orderByComparator.getOrderByFields().length * 3));
4247                    }
4248                    else {
4249                            query = new StringBundler(5);
4250                    }
4251    
4252                    if (getDB().isSupportsInlineDistinct()) {
4253                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
4254                    }
4255                    else {
4256                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_1);
4257                    }
4258    
4259                    query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
4260    
4261                    query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
4262    
4263                    query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
4264    
4265                    if (!getDB().isSupportsInlineDistinct()) {
4266                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_2);
4267                    }
4268    
4269                    if (orderByComparator != null) {
4270                            if (getDB().isSupportsInlineDistinct()) {
4271                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4272                                            orderByComparator);
4273                            }
4274                            else {
4275                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4276                                            orderByComparator);
4277                            }
4278                    }
4279                    else {
4280                            if (getDB().isSupportsInlineDistinct()) {
4281                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
4282                            }
4283                            else {
4284                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_SQL);
4285                            }
4286                    }
4287    
4288                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4289                                    AnnouncementsEntry.class.getName(),
4290                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4291    
4292                    Session session = null;
4293    
4294                    try {
4295                            session = openSession();
4296    
4297                            SQLQuery q = session.createSQLQuery(sql);
4298    
4299                            if (getDB().isSupportsInlineDistinct()) {
4300                                    q.addEntity(_FILTER_ENTITY_ALIAS, AnnouncementsEntryImpl.class);
4301                            }
4302                            else {
4303                                    q.addEntity(_FILTER_ENTITY_TABLE, AnnouncementsEntryImpl.class);
4304                            }
4305    
4306                            QueryPos qPos = QueryPos.getInstance(q);
4307    
4308                            qPos.add(classNameId);
4309    
4310                            qPos.add(classPK);
4311    
4312                            qPos.add(alert);
4313    
4314                            return (List<AnnouncementsEntry>)QueryUtil.list(q, getDialect(),
4315                                    start, end);
4316                    }
4317                    catch (Exception e) {
4318                            throw processException(e);
4319                    }
4320                    finally {
4321                            closeSession(session);
4322                    }
4323            }
4324    
4325            /**
4326             * Returns the announcements entries before and after the current announcements entry in the ordered set of announcements entries that the user has permission to view where classNameId = &#63; and classPK = &#63; and alert = &#63;.
4327             *
4328             * @param entryId the primary key of the current announcements entry
4329             * @param classNameId the class name ID
4330             * @param classPK the class p k
4331             * @param alert the alert
4332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4333             * @return the previous, current, and next announcements entry
4334             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
4335             * @throws SystemException if a system exception occurred
4336             */
4337            public AnnouncementsEntry[] filterFindByC_C_A_PrevAndNext(long entryId,
4338                    long classNameId, long classPK, boolean alert,
4339                    OrderByComparator orderByComparator)
4340                    throws NoSuchEntryException, SystemException {
4341                    if (!InlineSQLHelperUtil.isEnabled()) {
4342                            return findByC_C_A_PrevAndNext(entryId, classNameId, classPK,
4343                                    alert, orderByComparator);
4344                    }
4345    
4346                    AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
4347    
4348                    Session session = null;
4349    
4350                    try {
4351                            session = openSession();
4352    
4353                            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
4354    
4355                            array[0] = filterGetByC_C_A_PrevAndNext(session,
4356                                            announcementsEntry, classNameId, classPK, alert,
4357                                            orderByComparator, true);
4358    
4359                            array[1] = announcementsEntry;
4360    
4361                            array[2] = filterGetByC_C_A_PrevAndNext(session,
4362                                            announcementsEntry, classNameId, classPK, alert,
4363                                            orderByComparator, false);
4364    
4365                            return array;
4366                    }
4367                    catch (Exception e) {
4368                            throw processException(e);
4369                    }
4370                    finally {
4371                            closeSession(session);
4372                    }
4373            }
4374    
4375            protected AnnouncementsEntry filterGetByC_C_A_PrevAndNext(Session session,
4376                    AnnouncementsEntry announcementsEntry, long classNameId, long classPK,
4377                    boolean alert, OrderByComparator orderByComparator, boolean previous) {
4378                    StringBundler query = null;
4379    
4380                    if (orderByComparator != null) {
4381                            query = new StringBundler(6 +
4382                                            (orderByComparator.getOrderByFields().length * 6));
4383                    }
4384                    else {
4385                            query = new StringBundler(3);
4386                    }
4387    
4388                    if (getDB().isSupportsInlineDistinct()) {
4389                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE);
4390                    }
4391                    else {
4392                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_1);
4393                    }
4394    
4395                    query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
4396    
4397                    query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
4398    
4399                    query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
4400    
4401                    if (!getDB().isSupportsInlineDistinct()) {
4402                            query.append(_FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_2);
4403                    }
4404    
4405                    if (orderByComparator != null) {
4406                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4407    
4408                            if (orderByConditionFields.length > 0) {
4409                                    query.append(WHERE_AND);
4410                            }
4411    
4412                            for (int i = 0; i < orderByConditionFields.length; i++) {
4413                                    if (getDB().isSupportsInlineDistinct()) {
4414                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4415                                    }
4416                                    else {
4417                                            query.append(_ORDER_BY_ENTITY_TABLE);
4418                                    }
4419    
4420                                    query.append(orderByConditionFields[i]);
4421    
4422                                    if ((i + 1) < orderByConditionFields.length) {
4423                                            if (orderByComparator.isAscending() ^ previous) {
4424                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4425                                            }
4426                                            else {
4427                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4428                                            }
4429                                    }
4430                                    else {
4431                                            if (orderByComparator.isAscending() ^ previous) {
4432                                                    query.append(WHERE_GREATER_THAN);
4433                                            }
4434                                            else {
4435                                                    query.append(WHERE_LESSER_THAN);
4436                                            }
4437                                    }
4438                            }
4439    
4440                            query.append(ORDER_BY_CLAUSE);
4441    
4442                            String[] orderByFields = orderByComparator.getOrderByFields();
4443    
4444                            for (int i = 0; i < orderByFields.length; i++) {
4445                                    if (getDB().isSupportsInlineDistinct()) {
4446                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4447                                    }
4448                                    else {
4449                                            query.append(_ORDER_BY_ENTITY_TABLE);
4450                                    }
4451    
4452                                    query.append(orderByFields[i]);
4453    
4454                                    if ((i + 1) < orderByFields.length) {
4455                                            if (orderByComparator.isAscending() ^ previous) {
4456                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4457                                            }
4458                                            else {
4459                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4460                                            }
4461                                    }
4462                                    else {
4463                                            if (orderByComparator.isAscending() ^ previous) {
4464                                                    query.append(ORDER_BY_ASC);
4465                                            }
4466                                            else {
4467                                                    query.append(ORDER_BY_DESC);
4468                                            }
4469                                    }
4470                            }
4471                    }
4472                    else {
4473                            if (getDB().isSupportsInlineDistinct()) {
4474                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
4475                            }
4476                            else {
4477                                    query.append(AnnouncementsEntryModelImpl.ORDER_BY_SQL);
4478                            }
4479                    }
4480    
4481                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4482                                    AnnouncementsEntry.class.getName(),
4483                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4484    
4485                    SQLQuery q = session.createSQLQuery(sql);
4486    
4487                    q.setFirstResult(0);
4488                    q.setMaxResults(2);
4489    
4490                    if (getDB().isSupportsInlineDistinct()) {
4491                            q.addEntity(_FILTER_ENTITY_ALIAS, AnnouncementsEntryImpl.class);
4492                    }
4493                    else {
4494                            q.addEntity(_FILTER_ENTITY_TABLE, AnnouncementsEntryImpl.class);
4495                    }
4496    
4497                    QueryPos qPos = QueryPos.getInstance(q);
4498    
4499                    qPos.add(classNameId);
4500    
4501                    qPos.add(classPK);
4502    
4503                    qPos.add(alert);
4504    
4505                    if (orderByComparator != null) {
4506                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsEntry);
4507    
4508                            for (Object value : values) {
4509                                    qPos.add(value);
4510                            }
4511                    }
4512    
4513                    List<AnnouncementsEntry> list = q.list();
4514    
4515                    if (list.size() == 2) {
4516                            return list.get(1);
4517                    }
4518                    else {
4519                            return null;
4520                    }
4521            }
4522    
4523            /**
4524             * Removes all the announcements entries where classNameId = &#63; and classPK = &#63; and alert = &#63; from the database.
4525             *
4526             * @param classNameId the class name ID
4527             * @param classPK the class p k
4528             * @param alert the alert
4529             * @throws SystemException if a system exception occurred
4530             */
4531            public void removeByC_C_A(long classNameId, long classPK, boolean alert)
4532                    throws SystemException {
4533                    for (AnnouncementsEntry announcementsEntry : findByC_C_A(classNameId,
4534                                    classPK, alert, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4535                            remove(announcementsEntry);
4536                    }
4537            }
4538    
4539            /**
4540             * Returns the number of announcements entries where classNameId = &#63; and classPK = &#63; and alert = &#63;.
4541             *
4542             * @param classNameId the class name ID
4543             * @param classPK the class p k
4544             * @param alert the alert
4545             * @return the number of matching announcements entries
4546             * @throws SystemException if a system exception occurred
4547             */
4548            public int countByC_C_A(long classNameId, long classPK, boolean alert)
4549                    throws SystemException {
4550                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_A;
4551    
4552                    Object[] finderArgs = new Object[] { classNameId, classPK, alert };
4553    
4554                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4555                                    this);
4556    
4557                    if (count == null) {
4558                            StringBundler query = new StringBundler(4);
4559    
4560                            query.append(_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
4561    
4562                            query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
4563    
4564                            query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
4565    
4566                            query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
4567    
4568                            String sql = query.toString();
4569    
4570                            Session session = null;
4571    
4572                            try {
4573                                    session = openSession();
4574    
4575                                    Query q = session.createQuery(sql);
4576    
4577                                    QueryPos qPos = QueryPos.getInstance(q);
4578    
4579                                    qPos.add(classNameId);
4580    
4581                                    qPos.add(classPK);
4582    
4583                                    qPos.add(alert);
4584    
4585                                    count = (Long)q.uniqueResult();
4586    
4587                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4588                            }
4589                            catch (Exception e) {
4590                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4591    
4592                                    throw processException(e);
4593                            }
4594                            finally {
4595                                    closeSession(session);
4596                            }
4597                    }
4598    
4599                    return count.intValue();
4600            }
4601    
4602            /**
4603             * Returns the number of announcements entries that the user has permission to view where classNameId = &#63; and classPK = &#63; and alert = &#63;.
4604             *
4605             * @param classNameId the class name ID
4606             * @param classPK the class p k
4607             * @param alert the alert
4608             * @return the number of matching announcements entries that the user has permission to view
4609             * @throws SystemException if a system exception occurred
4610             */
4611            public int filterCountByC_C_A(long classNameId, long classPK, boolean alert)
4612                    throws SystemException {
4613                    if (!InlineSQLHelperUtil.isEnabled()) {
4614                            return countByC_C_A(classNameId, classPK, alert);
4615                    }
4616    
4617                    StringBundler query = new StringBundler(4);
4618    
4619                    query.append(_FILTER_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE);
4620    
4621                    query.append(_FINDER_COLUMN_C_C_A_CLASSNAMEID_2);
4622    
4623                    query.append(_FINDER_COLUMN_C_C_A_CLASSPK_2);
4624    
4625                    query.append(_FINDER_COLUMN_C_C_A_ALERT_2);
4626    
4627                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4628                                    AnnouncementsEntry.class.getName(),
4629                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4630    
4631                    Session session = null;
4632    
4633                    try {
4634                            session = openSession();
4635    
4636                            SQLQuery q = session.createSQLQuery(sql);
4637    
4638                            q.addScalar(COUNT_COLUMN_NAME,
4639                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4640    
4641                            QueryPos qPos = QueryPos.getInstance(q);
4642    
4643                            qPos.add(classNameId);
4644    
4645                            qPos.add(classPK);
4646    
4647                            qPos.add(alert);
4648    
4649                            Long count = (Long)q.uniqueResult();
4650    
4651                            return count.intValue();
4652                    }
4653                    catch (Exception e) {
4654                            throw processException(e);
4655                    }
4656                    finally {
4657                            closeSession(session);
4658                    }
4659            }
4660    
4661            private static final String _FINDER_COLUMN_C_C_A_CLASSNAMEID_2 = "announcementsEntry.classNameId = ? AND ";
4662            private static final String _FINDER_COLUMN_C_C_A_CLASSPK_2 = "announcementsEntry.classPK = ? AND ";
4663            private static final String _FINDER_COLUMN_C_C_A_ALERT_2 = "announcementsEntry.alert = ?";
4664    
4665            /**
4666             * Caches the announcements entry in the entity cache if it is enabled.
4667             *
4668             * @param announcementsEntry the announcements entry
4669             */
4670            public void cacheResult(AnnouncementsEntry announcementsEntry) {
4671                    EntityCacheUtil.putResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
4672                            AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey(),
4673                            announcementsEntry);
4674    
4675                    announcementsEntry.resetOriginalValues();
4676            }
4677    
4678            /**
4679             * Caches the announcements entries in the entity cache if it is enabled.
4680             *
4681             * @param announcementsEntries the announcements entries
4682             */
4683            public void cacheResult(List<AnnouncementsEntry> announcementsEntries) {
4684                    for (AnnouncementsEntry announcementsEntry : announcementsEntries) {
4685                            if (EntityCacheUtil.getResult(
4686                                                    AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
4687                                                    AnnouncementsEntryImpl.class,
4688                                                    announcementsEntry.getPrimaryKey()) == null) {
4689                                    cacheResult(announcementsEntry);
4690                            }
4691                            else {
4692                                    announcementsEntry.resetOriginalValues();
4693                            }
4694                    }
4695            }
4696    
4697            /**
4698             * Clears the cache for all announcements entries.
4699             *
4700             * <p>
4701             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4702             * </p>
4703             */
4704            @Override
4705            public void clearCache() {
4706                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
4707                            CacheRegistryUtil.clear(AnnouncementsEntryImpl.class.getName());
4708                    }
4709    
4710                    EntityCacheUtil.clearCache(AnnouncementsEntryImpl.class.getName());
4711    
4712                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4713                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4714                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4715            }
4716    
4717            /**
4718             * Clears the cache for the announcements entry.
4719             *
4720             * <p>
4721             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4722             * </p>
4723             */
4724            @Override
4725            public void clearCache(AnnouncementsEntry announcementsEntry) {
4726                    EntityCacheUtil.removeResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
4727                            AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey());
4728    
4729                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4730                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4731            }
4732    
4733            @Override
4734            public void clearCache(List<AnnouncementsEntry> announcementsEntries) {
4735                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4736                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4737    
4738                    for (AnnouncementsEntry announcementsEntry : announcementsEntries) {
4739                            EntityCacheUtil.removeResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
4740                                    AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey());
4741                    }
4742            }
4743    
4744            /**
4745             * Creates a new announcements entry with the primary key. Does not add the announcements entry to the database.
4746             *
4747             * @param entryId the primary key for the new announcements entry
4748             * @return the new announcements entry
4749             */
4750            public AnnouncementsEntry create(long entryId) {
4751                    AnnouncementsEntry announcementsEntry = new AnnouncementsEntryImpl();
4752    
4753                    announcementsEntry.setNew(true);
4754                    announcementsEntry.setPrimaryKey(entryId);
4755    
4756                    String uuid = PortalUUIDUtil.generate();
4757    
4758                    announcementsEntry.setUuid(uuid);
4759    
4760                    return announcementsEntry;
4761            }
4762    
4763            /**
4764             * Removes the announcements entry with the primary key from the database. Also notifies the appropriate model listeners.
4765             *
4766             * @param entryId the primary key of the announcements entry
4767             * @return the announcements entry that was removed
4768             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
4769             * @throws SystemException if a system exception occurred
4770             */
4771            public AnnouncementsEntry remove(long entryId)
4772                    throws NoSuchEntryException, SystemException {
4773                    return remove(Long.valueOf(entryId));
4774            }
4775    
4776            /**
4777             * Removes the announcements entry with the primary key from the database. Also notifies the appropriate model listeners.
4778             *
4779             * @param primaryKey the primary key of the announcements entry
4780             * @return the announcements entry that was removed
4781             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
4782             * @throws SystemException if a system exception occurred
4783             */
4784            @Override
4785            public AnnouncementsEntry remove(Serializable primaryKey)
4786                    throws NoSuchEntryException, SystemException {
4787                    Session session = null;
4788    
4789                    try {
4790                            session = openSession();
4791    
4792                            AnnouncementsEntry announcementsEntry = (AnnouncementsEntry)session.get(AnnouncementsEntryImpl.class,
4793                                            primaryKey);
4794    
4795                            if (announcementsEntry == null) {
4796                                    if (_log.isWarnEnabled()) {
4797                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4798                                    }
4799    
4800                                    throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4801                                            primaryKey);
4802                            }
4803    
4804                            return remove(announcementsEntry);
4805                    }
4806                    catch (NoSuchEntryException nsee) {
4807                            throw nsee;
4808                    }
4809                    catch (Exception e) {
4810                            throw processException(e);
4811                    }
4812                    finally {
4813                            closeSession(session);
4814                    }
4815            }
4816    
4817            @Override
4818            protected AnnouncementsEntry removeImpl(
4819                    AnnouncementsEntry announcementsEntry) throws SystemException {
4820                    announcementsEntry = toUnwrappedModel(announcementsEntry);
4821    
4822                    Session session = null;
4823    
4824                    try {
4825                            session = openSession();
4826    
4827                            if (!session.contains(announcementsEntry)) {
4828                                    announcementsEntry = (AnnouncementsEntry)session.get(AnnouncementsEntryImpl.class,
4829                                                    announcementsEntry.getPrimaryKeyObj());
4830                            }
4831    
4832                            if (announcementsEntry != null) {
4833                                    session.delete(announcementsEntry);
4834                            }
4835                    }
4836                    catch (Exception e) {
4837                            throw processException(e);
4838                    }
4839                    finally {
4840                            closeSession(session);
4841                    }
4842    
4843                    if (announcementsEntry != null) {
4844                            clearCache(announcementsEntry);
4845                    }
4846    
4847                    return announcementsEntry;
4848            }
4849    
4850            @Override
4851            public AnnouncementsEntry updateImpl(
4852                    com.liferay.portlet.announcements.model.AnnouncementsEntry announcementsEntry)
4853                    throws SystemException {
4854                    announcementsEntry = toUnwrappedModel(announcementsEntry);
4855    
4856                    boolean isNew = announcementsEntry.isNew();
4857    
4858                    AnnouncementsEntryModelImpl announcementsEntryModelImpl = (AnnouncementsEntryModelImpl)announcementsEntry;
4859    
4860                    if (Validator.isNull(announcementsEntry.getUuid())) {
4861                            String uuid = PortalUUIDUtil.generate();
4862    
4863                            announcementsEntry.setUuid(uuid);
4864                    }
4865    
4866                    Session session = null;
4867    
4868                    try {
4869                            session = openSession();
4870    
4871                            if (announcementsEntry.isNew()) {
4872                                    session.save(announcementsEntry);
4873    
4874                                    announcementsEntry.setNew(false);
4875                            }
4876                            else {
4877                                    session.merge(announcementsEntry);
4878                            }
4879                    }
4880                    catch (Exception e) {
4881                            throw processException(e);
4882                    }
4883                    finally {
4884                            closeSession(session);
4885                    }
4886    
4887                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4888    
4889                    if (isNew || !AnnouncementsEntryModelImpl.COLUMN_BITMASK_ENABLED) {
4890                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4891                    }
4892    
4893                    else {
4894                            if ((announcementsEntryModelImpl.getColumnBitmask() &
4895                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4896                                    Object[] args = new Object[] {
4897                                                    announcementsEntryModelImpl.getOriginalUuid()
4898                                            };
4899    
4900                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4901                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4902                                            args);
4903    
4904                                    args = new Object[] { announcementsEntryModelImpl.getUuid() };
4905    
4906                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4907                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4908                                            args);
4909                            }
4910    
4911                            if ((announcementsEntryModelImpl.getColumnBitmask() &
4912                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4913                                    Object[] args = new Object[] {
4914                                                    announcementsEntryModelImpl.getOriginalUuid(),
4915                                                    Long.valueOf(announcementsEntryModelImpl.getOriginalCompanyId())
4916                                            };
4917    
4918                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4919                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4920                                            args);
4921    
4922                                    args = new Object[] {
4923                                                    announcementsEntryModelImpl.getUuid(),
4924                                                    Long.valueOf(announcementsEntryModelImpl.getCompanyId())
4925                                            };
4926    
4927                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4928                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4929                                            args);
4930                            }
4931    
4932                            if ((announcementsEntryModelImpl.getColumnBitmask() &
4933                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
4934                                    Object[] args = new Object[] {
4935                                                    Long.valueOf(announcementsEntryModelImpl.getOriginalUserId())
4936                                            };
4937    
4938                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4939                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4940                                            args);
4941    
4942                                    args = new Object[] {
4943                                                    Long.valueOf(announcementsEntryModelImpl.getUserId())
4944                                            };
4945    
4946                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4947                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4948                                            args);
4949                            }
4950    
4951                            if ((announcementsEntryModelImpl.getColumnBitmask() &
4952                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
4953                                    Object[] args = new Object[] {
4954                                                    Long.valueOf(announcementsEntryModelImpl.getOriginalClassNameId()),
4955                                                    Long.valueOf(announcementsEntryModelImpl.getOriginalClassPK())
4956                                            };
4957    
4958                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4959                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4960                                            args);
4961    
4962                                    args = new Object[] {
4963                                                    Long.valueOf(announcementsEntryModelImpl.getClassNameId()),
4964                                                    Long.valueOf(announcementsEntryModelImpl.getClassPK())
4965                                            };
4966    
4967                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4968                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4969                                            args);
4970                            }
4971    
4972                            if ((announcementsEntryModelImpl.getColumnBitmask() &
4973                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_A.getColumnBitmask()) != 0) {
4974                                    Object[] args = new Object[] {
4975                                                    Long.valueOf(announcementsEntryModelImpl.getOriginalClassNameId()),
4976                                                    Long.valueOf(announcementsEntryModelImpl.getOriginalClassPK()),
4977                                                    Boolean.valueOf(announcementsEntryModelImpl.getOriginalAlert())
4978                                            };
4979    
4980                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_A, args);
4981                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_A,
4982                                            args);
4983    
4984                                    args = new Object[] {
4985                                                    Long.valueOf(announcementsEntryModelImpl.getClassNameId()),
4986                                                    Long.valueOf(announcementsEntryModelImpl.getClassPK()),
4987                                                    Boolean.valueOf(announcementsEntryModelImpl.getAlert())
4988                                            };
4989    
4990                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_A, args);
4991                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_A,
4992                                            args);
4993                            }
4994                    }
4995    
4996                    EntityCacheUtil.putResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
4997                            AnnouncementsEntryImpl.class, announcementsEntry.getPrimaryKey(),
4998                            announcementsEntry);
4999    
5000                    return announcementsEntry;
5001            }
5002    
5003            protected AnnouncementsEntry toUnwrappedModel(
5004                    AnnouncementsEntry announcementsEntry) {
5005                    if (announcementsEntry instanceof AnnouncementsEntryImpl) {
5006                            return announcementsEntry;
5007                    }
5008    
5009                    AnnouncementsEntryImpl announcementsEntryImpl = new AnnouncementsEntryImpl();
5010    
5011                    announcementsEntryImpl.setNew(announcementsEntry.isNew());
5012                    announcementsEntryImpl.setPrimaryKey(announcementsEntry.getPrimaryKey());
5013    
5014                    announcementsEntryImpl.setUuid(announcementsEntry.getUuid());
5015                    announcementsEntryImpl.setEntryId(announcementsEntry.getEntryId());
5016                    announcementsEntryImpl.setCompanyId(announcementsEntry.getCompanyId());
5017                    announcementsEntryImpl.setUserId(announcementsEntry.getUserId());
5018                    announcementsEntryImpl.setUserName(announcementsEntry.getUserName());
5019                    announcementsEntryImpl.setCreateDate(announcementsEntry.getCreateDate());
5020                    announcementsEntryImpl.setModifiedDate(announcementsEntry.getModifiedDate());
5021                    announcementsEntryImpl.setClassNameId(announcementsEntry.getClassNameId());
5022                    announcementsEntryImpl.setClassPK(announcementsEntry.getClassPK());
5023                    announcementsEntryImpl.setTitle(announcementsEntry.getTitle());
5024                    announcementsEntryImpl.setContent(announcementsEntry.getContent());
5025                    announcementsEntryImpl.setUrl(announcementsEntry.getUrl());
5026                    announcementsEntryImpl.setType(announcementsEntry.getType());
5027                    announcementsEntryImpl.setDisplayDate(announcementsEntry.getDisplayDate());
5028                    announcementsEntryImpl.setExpirationDate(announcementsEntry.getExpirationDate());
5029                    announcementsEntryImpl.setPriority(announcementsEntry.getPriority());
5030                    announcementsEntryImpl.setAlert(announcementsEntry.isAlert());
5031    
5032                    return announcementsEntryImpl;
5033            }
5034    
5035            /**
5036             * Returns the announcements entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
5037             *
5038             * @param primaryKey the primary key of the announcements entry
5039             * @return the announcements entry
5040             * @throws com.liferay.portal.NoSuchModelException if a announcements entry with the primary key could not be found
5041             * @throws SystemException if a system exception occurred
5042             */
5043            @Override
5044            public AnnouncementsEntry findByPrimaryKey(Serializable primaryKey)
5045                    throws NoSuchModelException, SystemException {
5046                    return findByPrimaryKey(((Long)primaryKey).longValue());
5047            }
5048    
5049            /**
5050             * Returns the announcements entry with the primary key or throws a {@link com.liferay.portlet.announcements.NoSuchEntryException} if it could not be found.
5051             *
5052             * @param entryId the primary key of the announcements entry
5053             * @return the announcements entry
5054             * @throws com.liferay.portlet.announcements.NoSuchEntryException if a announcements entry with the primary key could not be found
5055             * @throws SystemException if a system exception occurred
5056             */
5057            public AnnouncementsEntry findByPrimaryKey(long entryId)
5058                    throws NoSuchEntryException, SystemException {
5059                    AnnouncementsEntry announcementsEntry = fetchByPrimaryKey(entryId);
5060    
5061                    if (announcementsEntry == null) {
5062                            if (_log.isWarnEnabled()) {
5063                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
5064                            }
5065    
5066                            throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5067                                    entryId);
5068                    }
5069    
5070                    return announcementsEntry;
5071            }
5072    
5073            /**
5074             * Returns the announcements entry with the primary key or returns <code>null</code> if it could not be found.
5075             *
5076             * @param primaryKey the primary key of the announcements entry
5077             * @return the announcements entry, or <code>null</code> if a announcements entry with the primary key could not be found
5078             * @throws SystemException if a system exception occurred
5079             */
5080            @Override
5081            public AnnouncementsEntry fetchByPrimaryKey(Serializable primaryKey)
5082                    throws SystemException {
5083                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
5084            }
5085    
5086            /**
5087             * Returns the announcements entry with the primary key or returns <code>null</code> if it could not be found.
5088             *
5089             * @param entryId the primary key of the announcements entry
5090             * @return the announcements entry, or <code>null</code> if a announcements entry with the primary key could not be found
5091             * @throws SystemException if a system exception occurred
5092             */
5093            public AnnouncementsEntry fetchByPrimaryKey(long entryId)
5094                    throws SystemException {
5095                    AnnouncementsEntry announcementsEntry = (AnnouncementsEntry)EntityCacheUtil.getResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
5096                                    AnnouncementsEntryImpl.class, entryId);
5097    
5098                    if (announcementsEntry == _nullAnnouncementsEntry) {
5099                            return null;
5100                    }
5101    
5102                    if (announcementsEntry == null) {
5103                            Session session = null;
5104    
5105                            try {
5106                                    session = openSession();
5107    
5108                                    announcementsEntry = (AnnouncementsEntry)session.get(AnnouncementsEntryImpl.class,
5109                                                    Long.valueOf(entryId));
5110    
5111                                    if (announcementsEntry != null) {
5112                                            cacheResult(announcementsEntry);
5113                                    }
5114                                    else {
5115                                            EntityCacheUtil.putResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
5116                                                    AnnouncementsEntryImpl.class, entryId,
5117                                                    _nullAnnouncementsEntry);
5118                                    }
5119                            }
5120                            catch (Exception e) {
5121                                    EntityCacheUtil.removeResult(AnnouncementsEntryModelImpl.ENTITY_CACHE_ENABLED,
5122                                            AnnouncementsEntryImpl.class, entryId);
5123    
5124                                    throw processException(e);
5125                            }
5126                            finally {
5127                                    closeSession(session);
5128                            }
5129                    }
5130    
5131                    return announcementsEntry;
5132            }
5133    
5134            /**
5135             * Returns all the announcements entries.
5136             *
5137             * @return the announcements entries
5138             * @throws SystemException if a system exception occurred
5139             */
5140            public List<AnnouncementsEntry> findAll() throws SystemException {
5141                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5142            }
5143    
5144            /**
5145             * Returns a range of all the announcements entries.
5146             *
5147             * <p>
5148             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5149             * </p>
5150             *
5151             * @param start the lower bound of the range of announcements entries
5152             * @param end the upper bound of the range of announcements entries (not inclusive)
5153             * @return the range of announcements entries
5154             * @throws SystemException if a system exception occurred
5155             */
5156            public List<AnnouncementsEntry> findAll(int start, int end)
5157                    throws SystemException {
5158                    return findAll(start, end, null);
5159            }
5160    
5161            /**
5162             * Returns an ordered range of all the announcements entries.
5163             *
5164             * <p>
5165             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5166             * </p>
5167             *
5168             * @param start the lower bound of the range of announcements entries
5169             * @param end the upper bound of the range of announcements entries (not inclusive)
5170             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5171             * @return the ordered range of announcements entries
5172             * @throws SystemException if a system exception occurred
5173             */
5174            public List<AnnouncementsEntry> findAll(int start, int end,
5175                    OrderByComparator orderByComparator) throws SystemException {
5176                    boolean pagination = true;
5177                    FinderPath finderPath = null;
5178                    Object[] finderArgs = null;
5179    
5180                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5181                                    (orderByComparator == null)) {
5182                            pagination = false;
5183                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5184                            finderArgs = FINDER_ARGS_EMPTY;
5185                    }
5186                    else {
5187                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5188                            finderArgs = new Object[] { start, end, orderByComparator };
5189                    }
5190    
5191                    List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)FinderCacheUtil.getResult(finderPath,
5192                                    finderArgs, this);
5193    
5194                    if (list == null) {
5195                            StringBundler query = null;
5196                            String sql = null;
5197    
5198                            if (orderByComparator != null) {
5199                                    query = new StringBundler(2 +
5200                                                    (orderByComparator.getOrderByFields().length * 3));
5201    
5202                                    query.append(_SQL_SELECT_ANNOUNCEMENTSENTRY);
5203    
5204                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5205                                            orderByComparator);
5206    
5207                                    sql = query.toString();
5208                            }
5209                            else {
5210                                    sql = _SQL_SELECT_ANNOUNCEMENTSENTRY;
5211    
5212                                    if (pagination) {
5213                                            sql = sql.concat(AnnouncementsEntryModelImpl.ORDER_BY_JPQL);
5214                                    }
5215                            }
5216    
5217                            Session session = null;
5218    
5219                            try {
5220                                    session = openSession();
5221    
5222                                    Query q = session.createQuery(sql);
5223    
5224                                    if (!pagination) {
5225                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
5226                                                            getDialect(), start, end, false);
5227    
5228                                            Collections.sort(list);
5229    
5230                                            list = new UnmodifiableList<AnnouncementsEntry>(list);
5231                                    }
5232                                    else {
5233                                            list = (List<AnnouncementsEntry>)QueryUtil.list(q,
5234                                                            getDialect(), start, end);
5235                                    }
5236    
5237                                    cacheResult(list);
5238    
5239                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5240                            }
5241                            catch (Exception e) {
5242                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5243    
5244                                    throw processException(e);
5245                            }
5246                            finally {
5247                                    closeSession(session);
5248                            }
5249                    }
5250    
5251                    return list;
5252            }
5253    
5254            /**
5255             * Removes all the announcements entries from the database.
5256             *
5257             * @throws SystemException if a system exception occurred
5258             */
5259            public void removeAll() throws SystemException {
5260                    for (AnnouncementsEntry announcementsEntry : findAll()) {
5261                            remove(announcementsEntry);
5262                    }
5263            }
5264    
5265            /**
5266             * Returns the number of announcements entries.
5267             *
5268             * @return the number of announcements entries
5269             * @throws SystemException if a system exception occurred
5270             */
5271            public int countAll() throws SystemException {
5272                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5273                                    FINDER_ARGS_EMPTY, this);
5274    
5275                    if (count == null) {
5276                            Session session = null;
5277    
5278                            try {
5279                                    session = openSession();
5280    
5281                                    Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSENTRY);
5282    
5283                                    count = (Long)q.uniqueResult();
5284    
5285                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5286                                            FINDER_ARGS_EMPTY, count);
5287                            }
5288                            catch (Exception e) {
5289                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
5290                                            FINDER_ARGS_EMPTY);
5291    
5292                                    throw processException(e);
5293                            }
5294                            finally {
5295                                    closeSession(session);
5296                            }
5297                    }
5298    
5299                    return count.intValue();
5300            }
5301    
5302            /**
5303             * Initializes the announcements entry persistence.
5304             */
5305            public void afterPropertiesSet() {
5306                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5307                                            com.liferay.portal.util.PropsUtil.get(
5308                                                    "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsEntry")));
5309    
5310                    if (listenerClassNames.length > 0) {
5311                            try {
5312                                    List<ModelListener<AnnouncementsEntry>> listenersList = new ArrayList<ModelListener<AnnouncementsEntry>>();
5313    
5314                                    for (String listenerClassName : listenerClassNames) {
5315                                            listenersList.add((ModelListener<AnnouncementsEntry>)InstanceFactory.newInstance(
5316                                                            listenerClassName));
5317                                    }
5318    
5319                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5320                            }
5321                            catch (Exception e) {
5322                                    _log.error(e);
5323                            }
5324                    }
5325            }
5326    
5327            public void destroy() {
5328                    EntityCacheUtil.removeCache(AnnouncementsEntryImpl.class.getName());
5329                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5330                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5331                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5332            }
5333    
5334            private static final String _SQL_SELECT_ANNOUNCEMENTSENTRY = "SELECT announcementsEntry FROM AnnouncementsEntry announcementsEntry";
5335            private static final String _SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE = "SELECT announcementsEntry FROM AnnouncementsEntry announcementsEntry WHERE ";
5336            private static final String _SQL_COUNT_ANNOUNCEMENTSENTRY = "SELECT COUNT(announcementsEntry) FROM AnnouncementsEntry announcementsEntry";
5337            private static final String _SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE = "SELECT COUNT(announcementsEntry) FROM AnnouncementsEntry announcementsEntry WHERE ";
5338            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "announcementsEntry.entryId";
5339            private static final String _FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_WHERE = "SELECT DISTINCT {announcementsEntry.*} FROM AnnouncementsEntry announcementsEntry WHERE ";
5340            private static final String _FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_1 =
5341                    "SELECT {AnnouncementsEntry.*} FROM (SELECT DISTINCT announcementsEntry.entryId FROM AnnouncementsEntry announcementsEntry WHERE ";
5342            private static final String _FILTER_SQL_SELECT_ANNOUNCEMENTSENTRY_NO_INLINE_DISTINCT_WHERE_2 =
5343                    ") TEMP_TABLE INNER JOIN AnnouncementsEntry ON TEMP_TABLE.entryId = AnnouncementsEntry.entryId";
5344            private static final String _FILTER_SQL_COUNT_ANNOUNCEMENTSENTRY_WHERE = "SELECT COUNT(DISTINCT announcementsEntry.entryId) AS COUNT_VALUE FROM AnnouncementsEntry announcementsEntry WHERE ";
5345            private static final String _FILTER_ENTITY_ALIAS = "announcementsEntry";
5346            private static final String _FILTER_ENTITY_TABLE = "AnnouncementsEntry";
5347            private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsEntry.";
5348            private static final String _ORDER_BY_ENTITY_TABLE = "AnnouncementsEntry.";
5349            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsEntry exists with the primary key ";
5350            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsEntry exists with the key {";
5351            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5352            private static Log _log = LogFactoryUtil.getLog(AnnouncementsEntryPersistenceImpl.class);
5353            private static AnnouncementsEntry _nullAnnouncementsEntry = new AnnouncementsEntryImpl() {
5354                            @Override
5355                            public Object clone() {
5356                                    return this;
5357                            }
5358    
5359                            @Override
5360                            public CacheModel<AnnouncementsEntry> toCacheModel() {
5361                                    return _nullAnnouncementsEntryCacheModel;
5362                            }
5363                    };
5364    
5365            private static CacheModel<AnnouncementsEntry> _nullAnnouncementsEntryCacheModel =
5366                    new CacheModel<AnnouncementsEntry>() {
5367                            public AnnouncementsEntry toEntityModel() {
5368                                    return _nullAnnouncementsEntry;
5369                            }
5370                    };
5371    }