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