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