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