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