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