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