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