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