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