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.setUserId(announcementsFlag.getUserId());
1172                    announcementsFlagImpl.setCreateDate(announcementsFlag.getCreateDate());
1173                    announcementsFlagImpl.setEntryId(announcementsFlag.getEntryId());
1174                    announcementsFlagImpl.setValue(announcementsFlag.getValue());
1175    
1176                    return announcementsFlagImpl;
1177            }
1178    
1179            /**
1180             * Returns the announcements flag with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1181             *
1182             * @param primaryKey the primary key of the announcements flag
1183             * @return the announcements flag
1184             * @throws NoSuchFlagException if a announcements flag with the primary key could not be found
1185             */
1186            @Override
1187            public AnnouncementsFlag findByPrimaryKey(Serializable primaryKey)
1188                    throws NoSuchFlagException {
1189                    AnnouncementsFlag announcementsFlag = fetchByPrimaryKey(primaryKey);
1190    
1191                    if (announcementsFlag == null) {
1192                            if (_log.isWarnEnabled()) {
1193                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1194                            }
1195    
1196                            throw new NoSuchFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1197                                    primaryKey);
1198                    }
1199    
1200                    return announcementsFlag;
1201            }
1202    
1203            /**
1204             * Returns the announcements flag with the primary key or throws a {@link NoSuchFlagException} if it could not be found.
1205             *
1206             * @param flagId the primary key of the announcements flag
1207             * @return the announcements flag
1208             * @throws NoSuchFlagException if a announcements flag with the primary key could not be found
1209             */
1210            @Override
1211            public AnnouncementsFlag findByPrimaryKey(long flagId)
1212                    throws NoSuchFlagException {
1213                    return findByPrimaryKey((Serializable)flagId);
1214            }
1215    
1216            /**
1217             * Returns the announcements flag with the primary key or returns <code>null</code> if it could not be found.
1218             *
1219             * @param primaryKey the primary key of the announcements flag
1220             * @return the announcements flag, or <code>null</code> if a announcements flag with the primary key could not be found
1221             */
1222            @Override
1223            public AnnouncementsFlag fetchByPrimaryKey(Serializable primaryKey) {
1224                    AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)entityCache.getResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1225                                    AnnouncementsFlagImpl.class, primaryKey);
1226    
1227                    if (announcementsFlag == _nullAnnouncementsFlag) {
1228                            return null;
1229                    }
1230    
1231                    if (announcementsFlag == null) {
1232                            Session session = null;
1233    
1234                            try {
1235                                    session = openSession();
1236    
1237                                    announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
1238                                                    primaryKey);
1239    
1240                                    if (announcementsFlag != null) {
1241                                            cacheResult(announcementsFlag);
1242                                    }
1243                                    else {
1244                                            entityCache.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1245                                                    AnnouncementsFlagImpl.class, primaryKey,
1246                                                    _nullAnnouncementsFlag);
1247                                    }
1248                            }
1249                            catch (Exception e) {
1250                                    entityCache.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1251                                            AnnouncementsFlagImpl.class, primaryKey);
1252    
1253                                    throw processException(e);
1254                            }
1255                            finally {
1256                                    closeSession(session);
1257                            }
1258                    }
1259    
1260                    return announcementsFlag;
1261            }
1262    
1263            /**
1264             * Returns the announcements flag with the primary key or returns <code>null</code> if it could not be found.
1265             *
1266             * @param flagId the primary key of the announcements flag
1267             * @return the announcements flag, or <code>null</code> if a announcements flag with the primary key could not be found
1268             */
1269            @Override
1270            public AnnouncementsFlag fetchByPrimaryKey(long flagId) {
1271                    return fetchByPrimaryKey((Serializable)flagId);
1272            }
1273    
1274            @Override
1275            public Map<Serializable, AnnouncementsFlag> fetchByPrimaryKeys(
1276                    Set<Serializable> primaryKeys) {
1277                    if (primaryKeys.isEmpty()) {
1278                            return Collections.emptyMap();
1279                    }
1280    
1281                    Map<Serializable, AnnouncementsFlag> map = new HashMap<Serializable, AnnouncementsFlag>();
1282    
1283                    if (primaryKeys.size() == 1) {
1284                            Iterator<Serializable> iterator = primaryKeys.iterator();
1285    
1286                            Serializable primaryKey = iterator.next();
1287    
1288                            AnnouncementsFlag announcementsFlag = fetchByPrimaryKey(primaryKey);
1289    
1290                            if (announcementsFlag != null) {
1291                                    map.put(primaryKey, announcementsFlag);
1292                            }
1293    
1294                            return map;
1295                    }
1296    
1297                    Set<Serializable> uncachedPrimaryKeys = null;
1298    
1299                    for (Serializable primaryKey : primaryKeys) {
1300                            AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)entityCache.getResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1301                                            AnnouncementsFlagImpl.class, primaryKey);
1302    
1303                            if (announcementsFlag == null) {
1304                                    if (uncachedPrimaryKeys == null) {
1305                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1306                                    }
1307    
1308                                    uncachedPrimaryKeys.add(primaryKey);
1309                            }
1310                            else {
1311                                    map.put(primaryKey, announcementsFlag);
1312                            }
1313                    }
1314    
1315                    if (uncachedPrimaryKeys == null) {
1316                            return map;
1317                    }
1318    
1319                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1320                                    1);
1321    
1322                    query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE_PKS_IN);
1323    
1324                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1325                            query.append(String.valueOf(primaryKey));
1326    
1327                            query.append(StringPool.COMMA);
1328                    }
1329    
1330                    query.setIndex(query.index() - 1);
1331    
1332                    query.append(StringPool.CLOSE_PARENTHESIS);
1333    
1334                    String sql = query.toString();
1335    
1336                    Session session = null;
1337    
1338                    try {
1339                            session = openSession();
1340    
1341                            Query q = session.createQuery(sql);
1342    
1343                            for (AnnouncementsFlag announcementsFlag : (List<AnnouncementsFlag>)q.list()) {
1344                                    map.put(announcementsFlag.getPrimaryKeyObj(), announcementsFlag);
1345    
1346                                    cacheResult(announcementsFlag);
1347    
1348                                    uncachedPrimaryKeys.remove(announcementsFlag.getPrimaryKeyObj());
1349                            }
1350    
1351                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1352                                    entityCache.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1353                                            AnnouncementsFlagImpl.class, primaryKey,
1354                                            _nullAnnouncementsFlag);
1355                            }
1356                    }
1357                    catch (Exception e) {
1358                            throw processException(e);
1359                    }
1360                    finally {
1361                            closeSession(session);
1362                    }
1363    
1364                    return map;
1365            }
1366    
1367            /**
1368             * Returns all the announcements flags.
1369             *
1370             * @return the announcements flags
1371             */
1372            @Override
1373            public List<AnnouncementsFlag> findAll() {
1374                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1375            }
1376    
1377            /**
1378             * Returns a range of all the announcements flags.
1379             *
1380             * <p>
1381             * 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.
1382             * </p>
1383             *
1384             * @param start the lower bound of the range of announcements flags
1385             * @param end the upper bound of the range of announcements flags (not inclusive)
1386             * @return the range of announcements flags
1387             */
1388            @Override
1389            public List<AnnouncementsFlag> findAll(int start, int end) {
1390                    return findAll(start, end, null);
1391            }
1392    
1393            /**
1394             * Returns an ordered range of all the announcements flags.
1395             *
1396             * <p>
1397             * 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.
1398             * </p>
1399             *
1400             * @param start the lower bound of the range of announcements flags
1401             * @param end the upper bound of the range of announcements flags (not inclusive)
1402             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1403             * @return the ordered range of announcements flags
1404             */
1405            @Override
1406            public List<AnnouncementsFlag> findAll(int start, int end,
1407                    OrderByComparator<AnnouncementsFlag> orderByComparator) {
1408                    return findAll(start, end, orderByComparator, true);
1409            }
1410    
1411            /**
1412             * Returns an ordered range of all the announcements flags.
1413             *
1414             * <p>
1415             * 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.
1416             * </p>
1417             *
1418             * @param start the lower bound of the range of announcements flags
1419             * @param end the upper bound of the range of announcements flags (not inclusive)
1420             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1421             * @param retrieveFromCache whether to retrieve from the finder cache
1422             * @return the ordered range of announcements flags
1423             */
1424            @Override
1425            public List<AnnouncementsFlag> findAll(int start, int end,
1426                    OrderByComparator<AnnouncementsFlag> orderByComparator,
1427                    boolean retrieveFromCache) {
1428                    boolean pagination = true;
1429                    FinderPath finderPath = null;
1430                    Object[] finderArgs = null;
1431    
1432                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1433                                    (orderByComparator == null)) {
1434                            pagination = false;
1435                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1436                            finderArgs = FINDER_ARGS_EMPTY;
1437                    }
1438                    else {
1439                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1440                            finderArgs = new Object[] { start, end, orderByComparator };
1441                    }
1442    
1443                    List<AnnouncementsFlag> list = null;
1444    
1445                    if (retrieveFromCache) {
1446                            list = (List<AnnouncementsFlag>)finderCache.getResult(finderPath,
1447                                            finderArgs, this);
1448                    }
1449    
1450                    if (list == null) {
1451                            StringBundler query = null;
1452                            String sql = null;
1453    
1454                            if (orderByComparator != null) {
1455                                    query = new StringBundler(2 +
1456                                                    (orderByComparator.getOrderByFields().length * 3));
1457    
1458                                    query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG);
1459    
1460                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1461                                            orderByComparator);
1462    
1463                                    sql = query.toString();
1464                            }
1465                            else {
1466                                    sql = _SQL_SELECT_ANNOUNCEMENTSFLAG;
1467    
1468                                    if (pagination) {
1469                                            sql = sql.concat(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
1470                                    }
1471                            }
1472    
1473                            Session session = null;
1474    
1475                            try {
1476                                    session = openSession();
1477    
1478                                    Query q = session.createQuery(sql);
1479    
1480                                    if (!pagination) {
1481                                            list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1482                                                            getDialect(), start, end, false);
1483    
1484                                            Collections.sort(list);
1485    
1486                                            list = Collections.unmodifiableList(list);
1487                                    }
1488                                    else {
1489                                            list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1490                                                            getDialect(), start, end);
1491                                    }
1492    
1493                                    cacheResult(list);
1494    
1495                                    finderCache.putResult(finderPath, finderArgs, list);
1496                            }
1497                            catch (Exception e) {
1498                                    finderCache.removeResult(finderPath, finderArgs);
1499    
1500                                    throw processException(e);
1501                            }
1502                            finally {
1503                                    closeSession(session);
1504                            }
1505                    }
1506    
1507                    return list;
1508            }
1509    
1510            /**
1511             * Removes all the announcements flags from the database.
1512             *
1513             */
1514            @Override
1515            public void removeAll() {
1516                    for (AnnouncementsFlag announcementsFlag : findAll()) {
1517                            remove(announcementsFlag);
1518                    }
1519            }
1520    
1521            /**
1522             * Returns the number of announcements flags.
1523             *
1524             * @return the number of announcements flags
1525             */
1526            @Override
1527            public int countAll() {
1528                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1529                                    FINDER_ARGS_EMPTY, this);
1530    
1531                    if (count == null) {
1532                            Session session = null;
1533    
1534                            try {
1535                                    session = openSession();
1536    
1537                                    Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSFLAG);
1538    
1539                                    count = (Long)q.uniqueResult();
1540    
1541                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1542                                            count);
1543                            }
1544                            catch (Exception e) {
1545                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1546                                            FINDER_ARGS_EMPTY);
1547    
1548                                    throw processException(e);
1549                            }
1550                            finally {
1551                                    closeSession(session);
1552                            }
1553                    }
1554    
1555                    return count.intValue();
1556            }
1557    
1558            @Override
1559            protected Map<String, Integer> getTableColumnsMap() {
1560                    return AnnouncementsFlagModelImpl.TABLE_COLUMNS_MAP;
1561            }
1562    
1563            /**
1564             * Initializes the announcements flag persistence.
1565             */
1566            public void afterPropertiesSet() {
1567            }
1568    
1569            public void destroy() {
1570                    entityCache.removeCache(AnnouncementsFlagImpl.class.getName());
1571                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1572                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1573                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1574            }
1575    
1576            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1577            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1578            private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag";
1579            private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE_PKS_IN = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE flagId IN (";
1580            private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE ";
1581            private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag";
1582            private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag WHERE ";
1583            private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsFlag.";
1584            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsFlag exists with the primary key ";
1585            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsFlag exists with the key {";
1586            private static final Log _log = LogFactoryUtil.getLog(AnnouncementsFlagPersistenceImpl.class);
1587            private static final AnnouncementsFlag _nullAnnouncementsFlag = new AnnouncementsFlagImpl() {
1588                            @Override
1589                            public Object clone() {
1590                                    return this;
1591                            }
1592    
1593                            @Override
1594                            public CacheModel<AnnouncementsFlag> toCacheModel() {
1595                                    return _nullAnnouncementsFlagCacheModel;
1596                            }
1597                    };
1598    
1599            private static final CacheModel<AnnouncementsFlag> _nullAnnouncementsFlagCacheModel =
1600                    new CacheModel<AnnouncementsFlag>() {
1601                            @Override
1602                            public AnnouncementsFlag toEntityModel() {
1603                                    return _nullAnnouncementsFlag;
1604                            }
1605                    };
1606    }