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