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