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.EntityCache;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCache;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.model.CacheModel;
034    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
035    
036    import com.liferay.portlet.announcements.NoSuchFlagException;
037    import com.liferay.portlet.announcements.model.AnnouncementsFlag;
038    import com.liferay.portlet.announcements.model.impl.AnnouncementsFlagImpl;
039    import com.liferay.portlet.announcements.model.impl.AnnouncementsFlagModelImpl;
040    import com.liferay.portlet.announcements.service.persistence.AnnouncementsFlagPersistence;
041    
042    import java.io.Serializable;
043    
044    import java.util.Collections;
045    import java.util.HashMap;
046    import java.util.HashSet;
047    import java.util.Iterator;
048    import java.util.List;
049    import java.util.Map;
050    import java.util.Set;
051    
052    /**
053     * The persistence implementation for the announcements flag service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see AnnouncementsFlagPersistence
061     * @see com.liferay.portlet.announcements.service.persistence.AnnouncementsFlagUtil
062     * @generated
063     */
064    @ProviderType
065    public class AnnouncementsFlagPersistenceImpl extends BasePersistenceImpl<AnnouncementsFlag>
066            implements AnnouncementsFlagPersistence {
067            /*
068             * NOTE FOR DEVELOPERS:
069             *
070             * Never modify or reference this class directly. Always use {@link AnnouncementsFlagUtil} to access the announcements flag persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
071             */
072            public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsFlagImpl.class.getName();
073            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List1";
075            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List2";
077            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
078                            AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
079                            AnnouncementsFlagImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
082                            AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
083                            AnnouncementsFlagImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
086                            AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ENTRYID = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
089                            AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
090                            AnnouncementsFlagImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByEntryId",
092                            new String[] {
093                                    Long.class.getName(),
094                                    
095                            Integer.class.getName(), Integer.class.getName(),
096                                    OrderByComparator.class.getName()
097                            });
098            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID =
099                    new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
100                            AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
101                            AnnouncementsFlagImpl.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByEntryId",
103                            new String[] { Long.class.getName() },
104                            AnnouncementsFlagModelImpl.ENTRYID_COLUMN_BITMASK |
105                            AnnouncementsFlagModelImpl.USERID_COLUMN_BITMASK |
106                            AnnouncementsFlagModelImpl.CREATEDATE_COLUMN_BITMASK);
107            public static final FinderPath FINDER_PATH_COUNT_BY_ENTRYID = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
108                            AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByEntryId",
110                            new String[] { Long.class.getName() });
111    
112            /**
113             * Returns all the announcements flags where entryId = &#63;.
114             *
115             * @param entryId the entry ID
116             * @return the matching announcements flags
117             */
118            @Override
119            public List<AnnouncementsFlag> findByEntryId(long entryId) {
120                    return findByEntryId(entryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121            }
122    
123            /**
124             * Returns a range of all the announcements flags where entryId = &#63;.
125             *
126             * <p>
127             * 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 AnnouncementsFlagModelImpl}. 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.
128             * </p>
129             *
130             * @param entryId the entry ID
131             * @param start the lower bound of the range of announcements flags
132             * @param end the upper bound of the range of announcements flags (not inclusive)
133             * @return the range of matching announcements flags
134             */
135            @Override
136            public List<AnnouncementsFlag> findByEntryId(long entryId, int start,
137                    int end) {
138                    return findByEntryId(entryId, start, end, null);
139            }
140    
141            /**
142             * Returns an ordered range of all the announcements flags where entryId = &#63;.
143             *
144             * <p>
145             * 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 AnnouncementsFlagModelImpl}. 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.
146             * </p>
147             *
148             * @param entryId the entry ID
149             * @param start the lower bound of the range of announcements flags
150             * @param end the upper bound of the range of announcements flags (not inclusive)
151             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
152             * @return the ordered range of matching announcements flags
153             */
154            @Override
155            public List<AnnouncementsFlag> findByEntryId(long entryId, int start,
156                    int end, OrderByComparator<AnnouncementsFlag> orderByComparator) {
157                    return findByEntryId(entryId, start, end, orderByComparator, true);
158            }
159    
160            /**
161             * Returns an ordered range of all the announcements flags where entryId = &#63;.
162             *
163             * <p>
164             * 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 AnnouncementsFlagModelImpl}. 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.
165             * </p>
166             *
167             * @param entryId the entry ID
168             * @param start the lower bound of the range of announcements flags
169             * @param end the upper bound of the range of announcements flags (not inclusive)
170             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
171             * @param retrieveFromCache whether to retrieve from the finder cache
172             * @return the ordered range of matching announcements flags
173             */
174            @Override
175            public List<AnnouncementsFlag> findByEntryId(long entryId, int start,
176                    int end, OrderByComparator<AnnouncementsFlag> orderByComparator,
177                    boolean retrieveFromCache) {
178                    boolean pagination = true;
179                    FinderPath finderPath = null;
180                    Object[] finderArgs = null;
181    
182                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
183                                    (orderByComparator == null)) {
184                            pagination = false;
185                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID;
186                            finderArgs = new Object[] { entryId };
187                    }
188                    else {
189                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ENTRYID;
190                            finderArgs = new Object[] { entryId, start, end, orderByComparator };
191                    }
192    
193                    List<AnnouncementsFlag> list = null;
194    
195                    if (retrieveFromCache) {
196                            list = (List<AnnouncementsFlag>)finderCache.getResult(finderPath,
197                                            finderArgs, this);
198    
199                            if ((list != null) && !list.isEmpty()) {
200                                    for (AnnouncementsFlag announcementsFlag : list) {
201                                            if ((entryId != announcementsFlag.getEntryId())) {
202                                                    list = null;
203    
204                                                    break;
205                                            }
206                                    }
207                            }
208                    }
209    
210                    if (list == null) {
211                            StringBundler query = null;
212    
213                            if (orderByComparator != null) {
214                                    query = new StringBundler(3 +
215                                                    (orderByComparator.getOrderByFields().length * 3));
216                            }
217                            else {
218                                    query = new StringBundler(3);
219                            }
220    
221                            query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
222    
223                            query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
224    
225                            if (orderByComparator != null) {
226                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
227                                            orderByComparator);
228                            }
229                            else
230                             if (pagination) {
231                                    query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
232                            }
233    
234                            String sql = query.toString();
235    
236                            Session session = null;
237    
238                            try {
239                                    session = openSession();
240    
241                                    Query q = session.createQuery(sql);
242    
243                                    QueryPos qPos = QueryPos.getInstance(q);
244    
245                                    qPos.add(entryId);
246    
247                                    if (!pagination) {
248                                            list = (List<AnnouncementsFlag>)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<AnnouncementsFlag>)QueryUtil.list(q,
257                                                            getDialect(), start, end);
258                                    }
259    
260                                    cacheResult(list);
261    
262                                    finderCache.putResult(finderPath, finderArgs, list);
263                            }
264                            catch (Exception e) {
265                                    finderCache.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 flag in the ordered set where entryId = &#63;.
279             *
280             * @param entryId the entry ID
281             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
282             * @return the first matching announcements flag
283             * @throws NoSuchFlagException if a matching announcements flag could not be found
284             */
285            @Override
286            public AnnouncementsFlag findByEntryId_First(long entryId,
287                    OrderByComparator<AnnouncementsFlag> orderByComparator)
288                    throws NoSuchFlagException {
289                    AnnouncementsFlag announcementsFlag = fetchByEntryId_First(entryId,
290                                    orderByComparator);
291    
292                    if (announcementsFlag != null) {
293                            return announcementsFlag;
294                    }
295    
296                    StringBundler msg = new StringBundler(4);
297    
298                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
299    
300                    msg.append("entryId=");
301                    msg.append(entryId);
302    
303                    msg.append(StringPool.CLOSE_CURLY_BRACE);
304    
305                    throw new NoSuchFlagException(msg.toString());
306            }
307    
308            /**
309             * Returns the first announcements flag in the ordered set where entryId = &#63;.
310             *
311             * @param entryId the entry ID
312             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
313             * @return the first matching announcements flag, or <code>null</code> if a matching announcements flag could not be found
314             */
315            @Override
316            public AnnouncementsFlag fetchByEntryId_First(long entryId,
317                    OrderByComparator<AnnouncementsFlag> orderByComparator) {
318                    List<AnnouncementsFlag> list = findByEntryId(entryId, 0, 1,
319                                    orderByComparator);
320    
321                    if (!list.isEmpty()) {
322                            return list.get(0);
323                    }
324    
325                    return null;
326            }
327    
328            /**
329             * Returns the last announcements flag in the ordered set where entryId = &#63;.
330             *
331             * @param entryId the entry ID
332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
333             * @return the last matching announcements flag
334             * @throws NoSuchFlagException if a matching announcements flag could not be found
335             */
336            @Override
337            public AnnouncementsFlag findByEntryId_Last(long entryId,
338                    OrderByComparator<AnnouncementsFlag> orderByComparator)
339                    throws NoSuchFlagException {
340                    AnnouncementsFlag announcementsFlag = fetchByEntryId_Last(entryId,
341                                    orderByComparator);
342    
343                    if (announcementsFlag != null) {
344                            return announcementsFlag;
345                    }
346    
347                    StringBundler msg = new StringBundler(4);
348    
349                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
350    
351                    msg.append("entryId=");
352                    msg.append(entryId);
353    
354                    msg.append(StringPool.CLOSE_CURLY_BRACE);
355    
356                    throw new NoSuchFlagException(msg.toString());
357            }
358    
359            /**
360             * Returns the last announcements flag in the ordered set where entryId = &#63;.
361             *
362             * @param entryId the entry ID
363             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
364             * @return the last matching announcements flag, or <code>null</code> if a matching announcements flag could not be found
365             */
366            @Override
367            public AnnouncementsFlag fetchByEntryId_Last(long entryId,
368                    OrderByComparator<AnnouncementsFlag> orderByComparator) {
369                    int count = countByEntryId(entryId);
370    
371                    if (count == 0) {
372                            return null;
373                    }
374    
375                    List<AnnouncementsFlag> list = findByEntryId(entryId, count - 1, count,
376                                    orderByComparator);
377    
378                    if (!list.isEmpty()) {
379                            return list.get(0);
380                    }
381    
382                    return null;
383            }
384    
385            /**
386             * Returns the announcements flags before and after the current announcements flag in the ordered set where entryId = &#63;.
387             *
388             * @param flagId the primary key of the current announcements flag
389             * @param entryId the entry ID
390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
391             * @return the previous, current, and next announcements flag
392             * @throws NoSuchFlagException if a announcements flag with the primary key could not be found
393             */
394            @Override
395            public AnnouncementsFlag[] findByEntryId_PrevAndNext(long flagId,
396                    long entryId, OrderByComparator<AnnouncementsFlag> orderByComparator)
397                    throws NoSuchFlagException {
398                    AnnouncementsFlag announcementsFlag = findByPrimaryKey(flagId);
399    
400                    Session session = null;
401    
402                    try {
403                            session = openSession();
404    
405                            AnnouncementsFlag[] array = new AnnouncementsFlagImpl[3];
406    
407                            array[0] = getByEntryId_PrevAndNext(session, announcementsFlag,
408                                            entryId, orderByComparator, true);
409    
410                            array[1] = announcementsFlag;
411    
412                            array[2] = getByEntryId_PrevAndNext(session, announcementsFlag,
413                                            entryId, orderByComparator, false);
414    
415                            return array;
416                    }
417                    catch (Exception e) {
418                            throw processException(e);
419                    }
420                    finally {
421                            closeSession(session);
422                    }
423            }
424    
425            protected AnnouncementsFlag getByEntryId_PrevAndNext(Session session,
426                    AnnouncementsFlag announcementsFlag, long entryId,
427                    OrderByComparator<AnnouncementsFlag> orderByComparator, 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_ANNOUNCEMENTSFLAG_WHERE);
439    
440                    query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
441    
442                    if (orderByComparator != null) {
443                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
444    
445                            if (orderByConditionFields.length > 0) {
446                                    query.append(WHERE_AND);
447                            }
448    
449                            for (int i = 0; i < orderByConditionFields.length; i++) {
450                                    query.append(_ORDER_BY_ENTITY_ALIAS);
451                                    query.append(orderByConditionFields[i]);
452    
453                                    if ((i + 1) < orderByConditionFields.length) {
454                                            if (orderByComparator.isAscending() ^ previous) {
455                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
456                                            }
457                                            else {
458                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
459                                            }
460                                    }
461                                    else {
462                                            if (orderByComparator.isAscending() ^ previous) {
463                                                    query.append(WHERE_GREATER_THAN);
464                                            }
465                                            else {
466                                                    query.append(WHERE_LESSER_THAN);
467                                            }
468                                    }
469                            }
470    
471                            query.append(ORDER_BY_CLAUSE);
472    
473                            String[] orderByFields = orderByComparator.getOrderByFields();
474    
475                            for (int i = 0; i < orderByFields.length; i++) {
476                                    query.append(_ORDER_BY_ENTITY_ALIAS);
477                                    query.append(orderByFields[i]);
478    
479                                    if ((i + 1) < orderByFields.length) {
480                                            if (orderByComparator.isAscending() ^ previous) {
481                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
482                                            }
483                                            else {
484                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
485                                            }
486                                    }
487                                    else {
488                                            if (orderByComparator.isAscending() ^ previous) {
489                                                    query.append(ORDER_BY_ASC);
490                                            }
491                                            else {
492                                                    query.append(ORDER_BY_DESC);
493                                            }
494                                    }
495                            }
496                    }
497                    else {
498                            query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
499                    }
500    
501                    String sql = query.toString();
502    
503                    Query q = session.createQuery(sql);
504    
505                    q.setFirstResult(0);
506                    q.setMaxResults(2);
507    
508                    QueryPos qPos = QueryPos.getInstance(q);
509    
510                    qPos.add(entryId);
511    
512                    if (orderByComparator != null) {
513                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsFlag);
514    
515                            for (Object value : values) {
516                                    qPos.add(value);
517                            }
518                    }
519    
520                    List<AnnouncementsFlag> list = q.list();
521    
522                    if (list.size() == 2) {
523                            return list.get(1);
524                    }
525                    else {
526                            return null;
527                    }
528            }
529    
530            /**
531             * Removes all the announcements flags where entryId = &#63; from the database.
532             *
533             * @param entryId the entry ID
534             */
535            @Override
536            public void removeByEntryId(long entryId) {
537                    for (AnnouncementsFlag announcementsFlag : findByEntryId(entryId,
538                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
539                            remove(announcementsFlag);
540                    }
541            }
542    
543            /**
544             * Returns the number of announcements flags where entryId = &#63;.
545             *
546             * @param entryId the entry ID
547             * @return the number of matching announcements flags
548             */
549            @Override
550            public int countByEntryId(long entryId) {
551                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ENTRYID;
552    
553                    Object[] finderArgs = new Object[] { entryId };
554    
555                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
556    
557                    if (count == null) {
558                            StringBundler query = new StringBundler(2);
559    
560                            query.append(_SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE);
561    
562                            query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
563    
564                            String sql = query.toString();
565    
566                            Session session = null;
567    
568                            try {
569                                    session = openSession();
570    
571                                    Query q = session.createQuery(sql);
572    
573                                    QueryPos qPos = QueryPos.getInstance(q);
574    
575                                    qPos.add(entryId);
576    
577                                    count = (Long)q.uniqueResult();
578    
579                                    finderCache.putResult(finderPath, finderArgs, count);
580                            }
581                            catch (Exception e) {
582                                    finderCache.removeResult(finderPath, finderArgs);
583    
584                                    throw processException(e);
585                            }
586                            finally {
587                                    closeSession(session);
588                            }
589                    }
590    
591                    return count.intValue();
592            }
593    
594            private static final String _FINDER_COLUMN_ENTRYID_ENTRYID_2 = "announcementsFlag.entryId = ?";
595            public static final FinderPath FINDER_PATH_FETCH_BY_U_E_V = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
596                            AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
597                            AnnouncementsFlagImpl.class, FINDER_CLASS_NAME_ENTITY,
598                            "fetchByU_E_V",
599                            new String[] {
600                                    Long.class.getName(), Long.class.getName(),
601                                    Integer.class.getName()
602                            },
603                            AnnouncementsFlagModelImpl.USERID_COLUMN_BITMASK |
604                            AnnouncementsFlagModelImpl.ENTRYID_COLUMN_BITMASK |
605                            AnnouncementsFlagModelImpl.VALUE_COLUMN_BITMASK);
606            public static final FinderPath FINDER_PATH_COUNT_BY_U_E_V = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
607                            AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
608                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_E_V",
609                            new String[] {
610                                    Long.class.getName(), Long.class.getName(),
611                                    Integer.class.getName()
612                            });
613    
614            /**
615             * Returns the announcements flag where userId = &#63; and entryId = &#63; and value = &#63; or throws a {@link NoSuchFlagException} if it could not be found.
616             *
617             * @param userId the user ID
618             * @param entryId the entry ID
619             * @param value the value
620             * @return the matching announcements flag
621             * @throws NoSuchFlagException if a matching announcements flag could not be found
622             */
623            @Override
624            public AnnouncementsFlag findByU_E_V(long userId, long entryId, int value)
625                    throws NoSuchFlagException {
626                    AnnouncementsFlag announcementsFlag = fetchByU_E_V(userId, entryId,
627                                    value);
628    
629                    if (announcementsFlag == null) {
630                            StringBundler msg = new StringBundler(8);
631    
632                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
633    
634                            msg.append("userId=");
635                            msg.append(userId);
636    
637                            msg.append(", entryId=");
638                            msg.append(entryId);
639    
640                            msg.append(", value=");
641                            msg.append(value);
642    
643                            msg.append(StringPool.CLOSE_CURLY_BRACE);
644    
645                            if (_log.isWarnEnabled()) {
646                                    _log.warn(msg.toString());
647                            }
648    
649                            throw new NoSuchFlagException(msg.toString());
650                    }
651    
652                    return announcementsFlag;
653            }
654    
655            /**
656             * Returns the announcements flag where userId = &#63; and entryId = &#63; and value = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
657             *
658             * @param userId the user ID
659             * @param entryId the entry ID
660             * @param value the value
661             * @return the matching announcements flag, or <code>null</code> if a matching announcements flag could not be found
662             */
663            @Override
664            public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value) {
665                    return fetchByU_E_V(userId, entryId, value, true);
666            }
667    
668            /**
669             * Returns the announcements flag where userId = &#63; and entryId = &#63; and value = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
670             *
671             * @param userId the user ID
672             * @param entryId the entry ID
673             * @param value the value
674             * @param retrieveFromCache whether to retrieve from the finder cache
675             * @return the matching announcements flag, or <code>null</code> if a matching announcements flag could not be found
676             */
677            @Override
678            public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value,
679                    boolean retrieveFromCache) {
680                    Object[] finderArgs = new Object[] { userId, entryId, value };
681    
682                    Object result = null;
683    
684                    if (retrieveFromCache) {
685                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_U_E_V,
686                                            finderArgs, this);
687                    }
688    
689                    if (result instanceof AnnouncementsFlag) {
690                            AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)result;
691    
692                            if ((userId != announcementsFlag.getUserId()) ||
693                                            (entryId != announcementsFlag.getEntryId()) ||
694                                            (value != announcementsFlag.getValue())) {
695                                    result = null;
696                            }
697                    }
698    
699                    if (result == null) {
700                            StringBundler query = new StringBundler(5);
701    
702                            query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
703    
704                            query.append(_FINDER_COLUMN_U_E_V_USERID_2);
705    
706                            query.append(_FINDER_COLUMN_U_E_V_ENTRYID_2);
707    
708                            query.append(_FINDER_COLUMN_U_E_V_VALUE_2);
709    
710                            String sql = query.toString();
711    
712                            Session session = null;
713    
714                            try {
715                                    session = openSession();
716    
717                                    Query q = session.createQuery(sql);
718    
719                                    QueryPos qPos = QueryPos.getInstance(q);
720    
721                                    qPos.add(userId);
722    
723                                    qPos.add(entryId);
724    
725                                    qPos.add(value);
726    
727                                    List<AnnouncementsFlag> list = q.list();
728    
729                                    if (list.isEmpty()) {
730                                            finderCache.putResult(FINDER_PATH_FETCH_BY_U_E_V,
731                                                    finderArgs, list);
732                                    }
733                                    else {
734                                            AnnouncementsFlag announcementsFlag = list.get(0);
735    
736                                            result = announcementsFlag;
737    
738                                            cacheResult(announcementsFlag);
739    
740                                            if ((announcementsFlag.getUserId() != userId) ||
741                                                            (announcementsFlag.getEntryId() != entryId) ||
742                                                            (announcementsFlag.getValue() != value)) {
743                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_E_V,
744                                                            finderArgs, announcementsFlag);
745                                            }
746                                    }
747                            }
748                            catch (Exception e) {
749                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_U_E_V, finderArgs);
750    
751                                    throw processException(e);
752                            }
753                            finally {
754                                    closeSession(session);
755                            }
756                    }
757    
758                    if (result instanceof List<?>) {
759                            return null;
760                    }
761                    else {
762                            return (AnnouncementsFlag)result;
763                    }
764            }
765    
766            /**
767             * Removes the announcements flag where userId = &#63; and entryId = &#63; and value = &#63; from the database.
768             *
769             * @param userId the user ID
770             * @param entryId the entry ID
771             * @param value the value
772             * @return the announcements flag that was removed
773             */
774            @Override
775            public AnnouncementsFlag removeByU_E_V(long userId, long entryId, int value)
776                    throws NoSuchFlagException {
777                    AnnouncementsFlag announcementsFlag = findByU_E_V(userId, entryId, value);
778    
779                    return remove(announcementsFlag);
780            }
781    
782            /**
783             * Returns the number of announcements flags where userId = &#63; and entryId = &#63; and value = &#63;.
784             *
785             * @param userId the user ID
786             * @param entryId the entry ID
787             * @param value the value
788             * @return the number of matching announcements flags
789             */
790            @Override
791            public int countByU_E_V(long userId, long entryId, int value) {
792                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_E_V;
793    
794                    Object[] finderArgs = new Object[] { userId, entryId, value };
795    
796                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
797    
798                    if (count == null) {
799                            StringBundler query = new StringBundler(4);
800    
801                            query.append(_SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE);
802    
803                            query.append(_FINDER_COLUMN_U_E_V_USERID_2);
804    
805                            query.append(_FINDER_COLUMN_U_E_V_ENTRYID_2);
806    
807                            query.append(_FINDER_COLUMN_U_E_V_VALUE_2);
808    
809                            String sql = query.toString();
810    
811                            Session session = null;
812    
813                            try {
814                                    session = openSession();
815    
816                                    Query q = session.createQuery(sql);
817    
818                                    QueryPos qPos = QueryPos.getInstance(q);
819    
820                                    qPos.add(userId);
821    
822                                    qPos.add(entryId);
823    
824                                    qPos.add(value);
825    
826                                    count = (Long)q.uniqueResult();
827    
828                                    finderCache.putResult(finderPath, finderArgs, count);
829                            }
830                            catch (Exception e) {
831                                    finderCache.removeResult(finderPath, finderArgs);
832    
833                                    throw processException(e);
834                            }
835                            finally {
836                                    closeSession(session);
837                            }
838                    }
839    
840                    return count.intValue();
841            }
842    
843            private static final String _FINDER_COLUMN_U_E_V_USERID_2 = "announcementsFlag.userId = ? AND ";
844            private static final String _FINDER_COLUMN_U_E_V_ENTRYID_2 = "announcementsFlag.entryId = ? AND ";
845            private static final String _FINDER_COLUMN_U_E_V_VALUE_2 = "announcementsFlag.value = ?";
846    
847            public AnnouncementsFlagPersistenceImpl() {
848                    setModelClass(AnnouncementsFlag.class);
849            }
850    
851            /**
852             * Caches the announcements flag in the entity cache if it is enabled.
853             *
854             * @param announcementsFlag the announcements flag
855             */
856            @Override
857            public void cacheResult(AnnouncementsFlag announcementsFlag) {
858                    entityCache.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
859                            AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey(),
860                            announcementsFlag);
861    
862                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_E_V,
863                            new Object[] {
864                                    announcementsFlag.getUserId(), announcementsFlag.getEntryId(),
865                                    announcementsFlag.getValue()
866                            }, announcementsFlag);
867    
868                    announcementsFlag.resetOriginalValues();
869            }
870    
871            /**
872             * Caches the announcements flags in the entity cache if it is enabled.
873             *
874             * @param announcementsFlags the announcements flags
875             */
876            @Override
877            public void cacheResult(List<AnnouncementsFlag> announcementsFlags) {
878                    for (AnnouncementsFlag announcementsFlag : announcementsFlags) {
879                            if (entityCache.getResult(
880                                                    AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
881                                                    AnnouncementsFlagImpl.class,
882                                                    announcementsFlag.getPrimaryKey()) == null) {
883                                    cacheResult(announcementsFlag);
884                            }
885                            else {
886                                    announcementsFlag.resetOriginalValues();
887                            }
888                    }
889            }
890    
891            /**
892             * Clears the cache for all announcements flags.
893             *
894             * <p>
895             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
896             * </p>
897             */
898            @Override
899            public void clearCache() {
900                    entityCache.clearCache(AnnouncementsFlagImpl.class);
901    
902                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
903                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
904                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
905            }
906    
907            /**
908             * Clears the cache for the announcements flag.
909             *
910             * <p>
911             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
912             * </p>
913             */
914            @Override
915            public void clearCache(AnnouncementsFlag announcementsFlag) {
916                    entityCache.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
917                            AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey());
918    
919                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
920                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
921    
922                    clearUniqueFindersCache((AnnouncementsFlagModelImpl)announcementsFlag);
923            }
924    
925            @Override
926            public void clearCache(List<AnnouncementsFlag> announcementsFlags) {
927                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
928                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
929    
930                    for (AnnouncementsFlag announcementsFlag : announcementsFlags) {
931                            entityCache.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
932                                    AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey());
933    
934                            clearUniqueFindersCache((AnnouncementsFlagModelImpl)announcementsFlag);
935                    }
936            }
937    
938            protected void cacheUniqueFindersCache(
939                    AnnouncementsFlagModelImpl announcementsFlagModelImpl, boolean isNew) {
940                    if (isNew) {
941                            Object[] args = new Object[] {
942                                            announcementsFlagModelImpl.getUserId(),
943                                            announcementsFlagModelImpl.getEntryId(),
944                                            announcementsFlagModelImpl.getValue()
945                                    };
946    
947                            finderCache.putResult(FINDER_PATH_COUNT_BY_U_E_V, args,
948                                    Long.valueOf(1));
949                            finderCache.putResult(FINDER_PATH_FETCH_BY_U_E_V, args,
950                                    announcementsFlagModelImpl);
951                    }
952                    else {
953                            if ((announcementsFlagModelImpl.getColumnBitmask() &
954                                            FINDER_PATH_FETCH_BY_U_E_V.getColumnBitmask()) != 0) {
955                                    Object[] args = new Object[] {
956                                                    announcementsFlagModelImpl.getUserId(),
957                                                    announcementsFlagModelImpl.getEntryId(),
958                                                    announcementsFlagModelImpl.getValue()
959                                            };
960    
961                                    finderCache.putResult(FINDER_PATH_COUNT_BY_U_E_V, args,
962                                            Long.valueOf(1));
963                                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_E_V, args,
964                                            announcementsFlagModelImpl);
965                            }
966                    }
967            }
968    
969            protected void clearUniqueFindersCache(
970                    AnnouncementsFlagModelImpl announcementsFlagModelImpl) {
971                    Object[] args = new Object[] {
972                                    announcementsFlagModelImpl.getUserId(),
973                                    announcementsFlagModelImpl.getEntryId(),
974                                    announcementsFlagModelImpl.getValue()
975                            };
976    
977                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_E_V, args);
978                    finderCache.removeResult(FINDER_PATH_FETCH_BY_U_E_V, args);
979    
980                    if ((announcementsFlagModelImpl.getColumnBitmask() &
981                                    FINDER_PATH_FETCH_BY_U_E_V.getColumnBitmask()) != 0) {
982                            args = new Object[] {
983                                            announcementsFlagModelImpl.getOriginalUserId(),
984                                            announcementsFlagModelImpl.getOriginalEntryId(),
985                                            announcementsFlagModelImpl.getOriginalValue()
986                                    };
987    
988                            finderCache.removeResult(FINDER_PATH_COUNT_BY_U_E_V, args);
989                            finderCache.removeResult(FINDER_PATH_FETCH_BY_U_E_V, args);
990                    }
991            }
992    
993            /**
994             * Creates a new announcements flag with the primary key. Does not add the announcements flag to the database.
995             *
996             * @param flagId the primary key for the new announcements flag
997             * @return the new announcements flag
998             */
999            @Override
1000            public AnnouncementsFlag create(long flagId) {
1001                    AnnouncementsFlag announcementsFlag = new AnnouncementsFlagImpl();
1002    
1003                    announcementsFlag.setNew(true);
1004                    announcementsFlag.setPrimaryKey(flagId);
1005    
1006                    return announcementsFlag;
1007            }
1008    
1009            /**
1010             * Removes the announcements flag with the primary key from the database. Also notifies the appropriate model listeners.
1011             *
1012             * @param flagId the primary key of the announcements flag
1013             * @return the announcements flag that was removed
1014             * @throws NoSuchFlagException if a announcements flag with the primary key could not be found
1015             */
1016            @Override
1017            public AnnouncementsFlag remove(long flagId) throws NoSuchFlagException {
1018                    return remove((Serializable)flagId);
1019            }
1020    
1021            /**
1022             * Removes the announcements flag with the primary key from the database. Also notifies the appropriate model listeners.
1023             *
1024             * @param primaryKey the primary key of the announcements flag
1025             * @return the announcements flag that was removed
1026             * @throws NoSuchFlagException if a announcements flag with the primary key could not be found
1027             */
1028            @Override
1029            public AnnouncementsFlag remove(Serializable primaryKey)
1030                    throws NoSuchFlagException {
1031                    Session session = null;
1032    
1033                    try {
1034                            session = openSession();
1035    
1036                            AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
1037                                            primaryKey);
1038    
1039                            if (announcementsFlag == null) {
1040                                    if (_log.isWarnEnabled()) {
1041                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1042                                    }
1043    
1044                                    throw new NoSuchFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1045                                            primaryKey);
1046                            }
1047    
1048                            return remove(announcementsFlag);
1049                    }
1050                    catch (NoSuchFlagException nsee) {
1051                            throw nsee;
1052                    }
1053                    catch (Exception e) {
1054                            throw processException(e);
1055                    }
1056                    finally {
1057                            closeSession(session);
1058                    }
1059            }
1060    
1061            @Override
1062            protected AnnouncementsFlag removeImpl(AnnouncementsFlag announcementsFlag) {
1063                    announcementsFlag = toUnwrappedModel(announcementsFlag);
1064    
1065                    Session session = null;
1066    
1067                    try {
1068                            session = openSession();
1069    
1070                            if (!session.contains(announcementsFlag)) {
1071                                    announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
1072                                                    announcementsFlag.getPrimaryKeyObj());
1073                            }
1074    
1075                            if (announcementsFlag != null) {
1076                                    session.delete(announcementsFlag);
1077                            }
1078                    }
1079                    catch (Exception e) {
1080                            throw processException(e);
1081                    }
1082                    finally {
1083                            closeSession(session);
1084                    }
1085    
1086                    if (announcementsFlag != null) {
1087                            clearCache(announcementsFlag);
1088                    }
1089    
1090                    return announcementsFlag;
1091            }
1092    
1093            @Override
1094            public AnnouncementsFlag updateImpl(AnnouncementsFlag announcementsFlag) {
1095                    announcementsFlag = toUnwrappedModel(announcementsFlag);
1096    
1097                    boolean isNew = announcementsFlag.isNew();
1098    
1099                    AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
1100    
1101                    Session session = null;
1102    
1103                    try {
1104                            session = openSession();
1105    
1106                            if (announcementsFlag.isNew()) {
1107                                    session.save(announcementsFlag);
1108    
1109                                    announcementsFlag.setNew(false);
1110                            }
1111                            else {
1112                                    announcementsFlag = (AnnouncementsFlag)session.merge(announcementsFlag);
1113                            }
1114                    }
1115                    catch (Exception e) {
1116                            throw processException(e);
1117                    }
1118                    finally {
1119                            closeSession(session);
1120                    }
1121    
1122                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1123    
1124                    if (isNew || !AnnouncementsFlagModelImpl.COLUMN_BITMASK_ENABLED) {
1125                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1126                    }
1127    
1128                    else {
1129                            if ((announcementsFlagModelImpl.getColumnBitmask() &
1130                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID.getColumnBitmask()) != 0) {
1131                                    Object[] args = new Object[] {
1132                                                    announcementsFlagModelImpl.getOriginalEntryId()
1133                                            };
1134    
1135                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
1136                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
1137                                            args);
1138    
1139                                    args = new Object[] { announcementsFlagModelImpl.getEntryId() };
1140    
1141                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
1142                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
1143                                            args);
1144                            }
1145                    }
1146    
1147                    entityCache.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1148                            AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey(),
1149                            announcementsFlag, false);
1150    
1151                    clearUniqueFindersCache(announcementsFlagModelImpl);
1152                    cacheUniqueFindersCache(announcementsFlagModelImpl, isNew);
1153    
1154                    announcementsFlag.resetOriginalValues();
1155    
1156                    return announcementsFlag;
1157            }
1158    
1159            protected AnnouncementsFlag toUnwrappedModel(
1160                    AnnouncementsFlag announcementsFlag) {
1161                    if (announcementsFlag instanceof AnnouncementsFlagImpl) {
1162                            return announcementsFlag;
1163                    }
1164    
1165                    AnnouncementsFlagImpl announcementsFlagImpl = new AnnouncementsFlagImpl();
1166    
1167                    announcementsFlagImpl.setNew(announcementsFlag.isNew());
1168                    announcementsFlagImpl.setPrimaryKey(announcementsFlag.getPrimaryKey());
1169    
1170                    announcementsFlagImpl.setFlagId(announcementsFlag.getFlagId());
1171                    announcementsFlagImpl.setCompanyId(announcementsFlag.getCompanyId());
1172                    announcementsFlagImpl.setUserId(announcementsFlag.getUserId());
1173                    announcementsFlagImpl.setCreateDate(announcementsFlag.getCreateDate());
1174                    announcementsFlagImpl.setEntryId(announcementsFlag.getEntryId());
1175                    announcementsFlagImpl.setValue(announcementsFlag.getValue());
1176    
1177                    return announcementsFlagImpl;
1178            }
1179    
1180            /**
1181             * Returns the announcements flag with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1182             *
1183             * @param primaryKey the primary key of the announcements flag
1184             * @return the announcements flag
1185             * @throws NoSuchFlagException if a announcements flag with the primary key could not be found
1186             */
1187            @Override
1188            public AnnouncementsFlag findByPrimaryKey(Serializable primaryKey)
1189                    throws NoSuchFlagException {
1190                    AnnouncementsFlag announcementsFlag = fetchByPrimaryKey(primaryKey);
1191    
1192                    if (announcementsFlag == null) {
1193                            if (_log.isWarnEnabled()) {
1194                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1195                            }
1196    
1197                            throw new NoSuchFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1198                                    primaryKey);
1199                    }
1200    
1201                    return announcementsFlag;
1202            }
1203    
1204            /**
1205             * Returns the announcements flag with the primary key or throws a {@link NoSuchFlagException} if it could not be found.
1206             *
1207             * @param flagId the primary key of the announcements flag
1208             * @return the announcements flag
1209             * @throws NoSuchFlagException if a announcements flag with the primary key could not be found
1210             */
1211            @Override
1212            public AnnouncementsFlag findByPrimaryKey(long flagId)
1213                    throws NoSuchFlagException {
1214                    return findByPrimaryKey((Serializable)flagId);
1215            }
1216    
1217            /**
1218             * Returns the announcements flag with the primary key or returns <code>null</code> if it could not be found.
1219             *
1220             * @param primaryKey the primary key of the announcements flag
1221             * @return the announcements flag, or <code>null</code> if a announcements flag with the primary key could not be found
1222             */
1223            @Override
1224            public AnnouncementsFlag fetchByPrimaryKey(Serializable primaryKey) {
1225                    AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)entityCache.getResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1226                                    AnnouncementsFlagImpl.class, primaryKey);
1227    
1228                    if (announcementsFlag == _nullAnnouncementsFlag) {
1229                            return null;
1230                    }
1231    
1232                    if (announcementsFlag == null) {
1233                            Session session = null;
1234    
1235                            try {
1236                                    session = openSession();
1237    
1238                                    announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
1239                                                    primaryKey);
1240    
1241                                    if (announcementsFlag != null) {
1242                                            cacheResult(announcementsFlag);
1243                                    }
1244                                    else {
1245                                            entityCache.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1246                                                    AnnouncementsFlagImpl.class, primaryKey,
1247                                                    _nullAnnouncementsFlag);
1248                                    }
1249                            }
1250                            catch (Exception e) {
1251                                    entityCache.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1252                                            AnnouncementsFlagImpl.class, primaryKey);
1253    
1254                                    throw processException(e);
1255                            }
1256                            finally {
1257                                    closeSession(session);
1258                            }
1259                    }
1260    
1261                    return announcementsFlag;
1262            }
1263    
1264            /**
1265             * Returns the announcements flag with the primary key or returns <code>null</code> if it could not be found.
1266             *
1267             * @param flagId the primary key of the announcements flag
1268             * @return the announcements flag, or <code>null</code> if a announcements flag with the primary key could not be found
1269             */
1270            @Override
1271            public AnnouncementsFlag fetchByPrimaryKey(long flagId) {
1272                    return fetchByPrimaryKey((Serializable)flagId);
1273            }
1274    
1275            @Override
1276            public Map<Serializable, AnnouncementsFlag> fetchByPrimaryKeys(
1277                    Set<Serializable> primaryKeys) {
1278                    if (primaryKeys.isEmpty()) {
1279                            return Collections.emptyMap();
1280                    }
1281    
1282                    Map<Serializable, AnnouncementsFlag> map = new HashMap<Serializable, AnnouncementsFlag>();
1283    
1284                    if (primaryKeys.size() == 1) {
1285                            Iterator<Serializable> iterator = primaryKeys.iterator();
1286    
1287                            Serializable primaryKey = iterator.next();
1288    
1289                            AnnouncementsFlag announcementsFlag = fetchByPrimaryKey(primaryKey);
1290    
1291                            if (announcementsFlag != null) {
1292                                    map.put(primaryKey, announcementsFlag);
1293                            }
1294    
1295                            return map;
1296                    }
1297    
1298                    Set<Serializable> uncachedPrimaryKeys = null;
1299    
1300                    for (Serializable primaryKey : primaryKeys) {
1301                            AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)entityCache.getResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1302                                            AnnouncementsFlagImpl.class, primaryKey);
1303    
1304                            if (announcementsFlag == null) {
1305                                    if (uncachedPrimaryKeys == null) {
1306                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1307                                    }
1308    
1309                                    uncachedPrimaryKeys.add(primaryKey);
1310                            }
1311                            else {
1312                                    map.put(primaryKey, announcementsFlag);
1313                            }
1314                    }
1315    
1316                    if (uncachedPrimaryKeys == null) {
1317                            return map;
1318                    }
1319    
1320                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1321                                    1);
1322    
1323                    query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE_PKS_IN);
1324    
1325                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1326                            query.append(String.valueOf(primaryKey));
1327    
1328                            query.append(StringPool.COMMA);
1329                    }
1330    
1331                    query.setIndex(query.index() - 1);
1332    
1333                    query.append(StringPool.CLOSE_PARENTHESIS);
1334    
1335                    String sql = query.toString();
1336    
1337                    Session session = null;
1338    
1339                    try {
1340                            session = openSession();
1341    
1342                            Query q = session.createQuery(sql);
1343    
1344                            for (AnnouncementsFlag announcementsFlag : (List<AnnouncementsFlag>)q.list()) {
1345                                    map.put(announcementsFlag.getPrimaryKeyObj(), announcementsFlag);
1346    
1347                                    cacheResult(announcementsFlag);
1348    
1349                                    uncachedPrimaryKeys.remove(announcementsFlag.getPrimaryKeyObj());
1350                            }
1351    
1352                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1353                                    entityCache.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1354                                            AnnouncementsFlagImpl.class, primaryKey,
1355                                            _nullAnnouncementsFlag);
1356                            }
1357                    }
1358                    catch (Exception e) {
1359                            throw processException(e);
1360                    }
1361                    finally {
1362                            closeSession(session);
1363                    }
1364    
1365                    return map;
1366            }
1367    
1368            /**
1369             * Returns all the announcements flags.
1370             *
1371             * @return the announcements flags
1372             */
1373            @Override
1374            public List<AnnouncementsFlag> findAll() {
1375                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1376            }
1377    
1378            /**
1379             * Returns a range of all the announcements flags.
1380             *
1381             * <p>
1382             * 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 AnnouncementsFlagModelImpl}. 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.
1383             * </p>
1384             *
1385             * @param start the lower bound of the range of announcements flags
1386             * @param end the upper bound of the range of announcements flags (not inclusive)
1387             * @return the range of announcements flags
1388             */
1389            @Override
1390            public List<AnnouncementsFlag> findAll(int start, int end) {
1391                    return findAll(start, end, null);
1392            }
1393    
1394            /**
1395             * Returns an ordered range of all the announcements flags.
1396             *
1397             * <p>
1398             * 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 AnnouncementsFlagModelImpl}. 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.
1399             * </p>
1400             *
1401             * @param start the lower bound of the range of announcements flags
1402             * @param end the upper bound of the range of announcements flags (not inclusive)
1403             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1404             * @return the ordered range of announcements flags
1405             */
1406            @Override
1407            public List<AnnouncementsFlag> findAll(int start, int end,
1408                    OrderByComparator<AnnouncementsFlag> orderByComparator) {
1409                    return findAll(start, end, orderByComparator, true);
1410            }
1411    
1412            /**
1413             * Returns an ordered range of all the announcements flags.
1414             *
1415             * <p>
1416             * 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 AnnouncementsFlagModelImpl}. 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.
1417             * </p>
1418             *
1419             * @param start the lower bound of the range of announcements flags
1420             * @param end the upper bound of the range of announcements flags (not inclusive)
1421             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1422             * @param retrieveFromCache whether to retrieve from the finder cache
1423             * @return the ordered range of announcements flags
1424             */
1425            @Override
1426            public List<AnnouncementsFlag> findAll(int start, int end,
1427                    OrderByComparator<AnnouncementsFlag> orderByComparator,
1428                    boolean retrieveFromCache) {
1429                    boolean pagination = true;
1430                    FinderPath finderPath = null;
1431                    Object[] finderArgs = null;
1432    
1433                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1434                                    (orderByComparator == null)) {
1435                            pagination = false;
1436                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1437                            finderArgs = FINDER_ARGS_EMPTY;
1438                    }
1439                    else {
1440                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1441                            finderArgs = new Object[] { start, end, orderByComparator };
1442                    }
1443    
1444                    List<AnnouncementsFlag> list = null;
1445    
1446                    if (retrieveFromCache) {
1447                            list = (List<AnnouncementsFlag>)finderCache.getResult(finderPath,
1448                                            finderArgs, this);
1449                    }
1450    
1451                    if (list == null) {
1452                            StringBundler query = null;
1453                            String sql = null;
1454    
1455                            if (orderByComparator != null) {
1456                                    query = new StringBundler(2 +
1457                                                    (orderByComparator.getOrderByFields().length * 3));
1458    
1459                                    query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG);
1460    
1461                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1462                                            orderByComparator);
1463    
1464                                    sql = query.toString();
1465                            }
1466                            else {
1467                                    sql = _SQL_SELECT_ANNOUNCEMENTSFLAG;
1468    
1469                                    if (pagination) {
1470                                            sql = sql.concat(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
1471                                    }
1472                            }
1473    
1474                            Session session = null;
1475    
1476                            try {
1477                                    session = openSession();
1478    
1479                                    Query q = session.createQuery(sql);
1480    
1481                                    if (!pagination) {
1482                                            list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1483                                                            getDialect(), start, end, false);
1484    
1485                                            Collections.sort(list);
1486    
1487                                            list = Collections.unmodifiableList(list);
1488                                    }
1489                                    else {
1490                                            list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1491                                                            getDialect(), start, end);
1492                                    }
1493    
1494                                    cacheResult(list);
1495    
1496                                    finderCache.putResult(finderPath, finderArgs, list);
1497                            }
1498                            catch (Exception e) {
1499                                    finderCache.removeResult(finderPath, finderArgs);
1500    
1501                                    throw processException(e);
1502                            }
1503                            finally {
1504                                    closeSession(session);
1505                            }
1506                    }
1507    
1508                    return list;
1509            }
1510    
1511            /**
1512             * Removes all the announcements flags from the database.
1513             *
1514             */
1515            @Override
1516            public void removeAll() {
1517                    for (AnnouncementsFlag announcementsFlag : findAll()) {
1518                            remove(announcementsFlag);
1519                    }
1520            }
1521    
1522            /**
1523             * Returns the number of announcements flags.
1524             *
1525             * @return the number of announcements flags
1526             */
1527            @Override
1528            public int countAll() {
1529                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1530                                    FINDER_ARGS_EMPTY, this);
1531    
1532                    if (count == null) {
1533                            Session session = null;
1534    
1535                            try {
1536                                    session = openSession();
1537    
1538                                    Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSFLAG);
1539    
1540                                    count = (Long)q.uniqueResult();
1541    
1542                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1543                                            count);
1544                            }
1545                            catch (Exception e) {
1546                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1547                                            FINDER_ARGS_EMPTY);
1548    
1549                                    throw processException(e);
1550                            }
1551                            finally {
1552                                    closeSession(session);
1553                            }
1554                    }
1555    
1556                    return count.intValue();
1557            }
1558    
1559            @Override
1560            protected Map<String, Integer> getTableColumnsMap() {
1561                    return AnnouncementsFlagModelImpl.TABLE_COLUMNS_MAP;
1562            }
1563    
1564            /**
1565             * Initializes the announcements flag persistence.
1566             */
1567            public void afterPropertiesSet() {
1568            }
1569    
1570            public void destroy() {
1571                    entityCache.removeCache(AnnouncementsFlagImpl.class.getName());
1572                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1573                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1574                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1575            }
1576    
1577            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1578            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1579            private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag";
1580            private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE_PKS_IN = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE flagId IN (";
1581            private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE ";
1582            private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag";
1583            private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag WHERE ";
1584            private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsFlag.";
1585            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsFlag exists with the primary key ";
1586            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsFlag exists with the key {";
1587            private static final Log _log = LogFactoryUtil.getLog(AnnouncementsFlagPersistenceImpl.class);
1588            private static final AnnouncementsFlag _nullAnnouncementsFlag = new AnnouncementsFlagImpl() {
1589                            @Override
1590                            public Object clone() {
1591                                    return this;
1592                            }
1593    
1594                            @Override
1595                            public CacheModel<AnnouncementsFlag> toCacheModel() {
1596                                    return _nullAnnouncementsFlagCacheModel;
1597                            }
1598                    };
1599    
1600            private static final CacheModel<AnnouncementsFlag> _nullAnnouncementsFlagCacheModel =
1601                    new CacheModel<AnnouncementsFlag>() {
1602                            @Override
1603                            public AnnouncementsFlag toEntityModel() {
1604                                    return _nullAnnouncementsFlag;
1605                            }
1606                    };
1607    }