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