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