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            public AnnouncementsFlagPersistenceImpl() {
841                    setModelClass(AnnouncementsFlag.class);
842            }
843    
844            /**
845             * Caches the announcements flag in the entity cache if it is enabled.
846             *
847             * @param announcementsFlag the announcements flag
848             */
849            @Override
850            public void cacheResult(AnnouncementsFlag announcementsFlag) {
851                    EntityCacheUtil.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
852                            AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey(),
853                            announcementsFlag);
854    
855                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
856                            new Object[] {
857                                    announcementsFlag.getUserId(), announcementsFlag.getEntryId(),
858                                    announcementsFlag.getValue()
859                            }, announcementsFlag);
860    
861                    announcementsFlag.resetOriginalValues();
862            }
863    
864            /**
865             * Caches the announcements flags in the entity cache if it is enabled.
866             *
867             * @param announcementsFlags the announcements flags
868             */
869            @Override
870            public void cacheResult(List<AnnouncementsFlag> announcementsFlags) {
871                    for (AnnouncementsFlag announcementsFlag : announcementsFlags) {
872                            if (EntityCacheUtil.getResult(
873                                                    AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
874                                                    AnnouncementsFlagImpl.class,
875                                                    announcementsFlag.getPrimaryKey()) == null) {
876                                    cacheResult(announcementsFlag);
877                            }
878                            else {
879                                    announcementsFlag.resetOriginalValues();
880                            }
881                    }
882            }
883    
884            /**
885             * Clears the cache for all announcements flags.
886             *
887             * <p>
888             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
889             * </p>
890             */
891            @Override
892            public void clearCache() {
893                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
894                            CacheRegistryUtil.clear(AnnouncementsFlagImpl.class.getName());
895                    }
896    
897                    EntityCacheUtil.clearCache(AnnouncementsFlagImpl.class.getName());
898    
899                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
900                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
901                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
902            }
903    
904            /**
905             * Clears the cache for the announcements flag.
906             *
907             * <p>
908             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
909             * </p>
910             */
911            @Override
912            public void clearCache(AnnouncementsFlag announcementsFlag) {
913                    EntityCacheUtil.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
914                            AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey());
915    
916                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
917                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
918    
919                    clearUniqueFindersCache(announcementsFlag);
920            }
921    
922            @Override
923            public void clearCache(List<AnnouncementsFlag> announcementsFlags) {
924                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
925                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
926    
927                    for (AnnouncementsFlag announcementsFlag : announcementsFlags) {
928                            EntityCacheUtil.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
929                                    AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey());
930    
931                            clearUniqueFindersCache(announcementsFlag);
932                    }
933            }
934    
935            protected void cacheUniqueFindersCache(AnnouncementsFlag announcementsFlag) {
936                    if (announcementsFlag.isNew()) {
937                            Object[] args = new Object[] {
938                                            announcementsFlag.getUserId(),
939                                            announcementsFlag.getEntryId(), announcementsFlag.getValue()
940                                    };
941    
942                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_E_V, args,
943                                    Long.valueOf(1));
944                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V, args,
945                                    announcementsFlag);
946                    }
947                    else {
948                            AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
949    
950                            if ((announcementsFlagModelImpl.getColumnBitmask() &
951                                            FINDER_PATH_FETCH_BY_U_E_V.getColumnBitmask()) != 0) {
952                                    Object[] args = new Object[] {
953                                                    announcementsFlag.getUserId(),
954                                                    announcementsFlag.getEntryId(),
955                                                    announcementsFlag.getValue()
956                                            };
957    
958                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_E_V, args,
959                                            Long.valueOf(1));
960                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V, args,
961                                            announcementsFlag);
962                            }
963                    }
964            }
965    
966            protected void clearUniqueFindersCache(AnnouncementsFlag announcementsFlag) {
967                    AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
968    
969                    Object[] args = new Object[] {
970                                    announcementsFlag.getUserId(), announcementsFlag.getEntryId(),
971                                    announcementsFlag.getValue()
972                            };
973    
974                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_E_V, args);
975                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V, args);
976    
977                    if ((announcementsFlagModelImpl.getColumnBitmask() &
978                                    FINDER_PATH_FETCH_BY_U_E_V.getColumnBitmask()) != 0) {
979                            args = new Object[] {
980                                            announcementsFlagModelImpl.getOriginalUserId(),
981                                            announcementsFlagModelImpl.getOriginalEntryId(),
982                                            announcementsFlagModelImpl.getOriginalValue()
983                                    };
984    
985                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_E_V, args);
986                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V, args);
987                    }
988            }
989    
990            /**
991             * Creates a new announcements flag with the primary key. Does not add the announcements flag to the database.
992             *
993             * @param flagId the primary key for the new announcements flag
994             * @return the new announcements flag
995             */
996            @Override
997            public AnnouncementsFlag create(long flagId) {
998                    AnnouncementsFlag announcementsFlag = new AnnouncementsFlagImpl();
999    
1000                    announcementsFlag.setNew(true);
1001                    announcementsFlag.setPrimaryKey(flagId);
1002    
1003                    return announcementsFlag;
1004            }
1005    
1006            /**
1007             * Removes the announcements flag with the primary key from the database. Also notifies the appropriate model listeners.
1008             *
1009             * @param flagId the primary key of the announcements flag
1010             * @return the announcements flag that was removed
1011             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a announcements flag with the primary key could not be found
1012             * @throws SystemException if a system exception occurred
1013             */
1014            @Override
1015            public AnnouncementsFlag remove(long flagId)
1016                    throws NoSuchFlagException, SystemException {
1017                    return remove((Serializable)flagId);
1018            }
1019    
1020            /**
1021             * Removes the announcements flag with the primary key from the database. Also notifies the appropriate model listeners.
1022             *
1023             * @param primaryKey the primary key of the announcements flag
1024             * @return the announcements flag that was removed
1025             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a announcements flag with the primary key could not be found
1026             * @throws SystemException if a system exception occurred
1027             */
1028            @Override
1029            public AnnouncementsFlag remove(Serializable primaryKey)
1030                    throws NoSuchFlagException, SystemException {
1031                    Session session = null;
1032    
1033                    try {
1034                            session = openSession();
1035    
1036                            AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
1037                                            primaryKey);
1038    
1039                            if (announcementsFlag == null) {
1040                                    if (_log.isWarnEnabled()) {
1041                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1042                                    }
1043    
1044                                    throw new NoSuchFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1045                                            primaryKey);
1046                            }
1047    
1048                            return remove(announcementsFlag);
1049                    }
1050                    catch (NoSuchFlagException nsee) {
1051                            throw nsee;
1052                    }
1053                    catch (Exception e) {
1054                            throw processException(e);
1055                    }
1056                    finally {
1057                            closeSession(session);
1058                    }
1059            }
1060    
1061            @Override
1062            protected AnnouncementsFlag removeImpl(AnnouncementsFlag announcementsFlag)
1063                    throws SystemException {
1064                    announcementsFlag = toUnwrappedModel(announcementsFlag);
1065    
1066                    Session session = null;
1067    
1068                    try {
1069                            session = openSession();
1070    
1071                            if (!session.contains(announcementsFlag)) {
1072                                    announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
1073                                                    announcementsFlag.getPrimaryKeyObj());
1074                            }
1075    
1076                            if (announcementsFlag != null) {
1077                                    session.delete(announcementsFlag);
1078                            }
1079                    }
1080                    catch (Exception e) {
1081                            throw processException(e);
1082                    }
1083                    finally {
1084                            closeSession(session);
1085                    }
1086    
1087                    if (announcementsFlag != null) {
1088                            clearCache(announcementsFlag);
1089                    }
1090    
1091                    return announcementsFlag;
1092            }
1093    
1094            @Override
1095            public AnnouncementsFlag updateImpl(
1096                    com.liferay.portlet.announcements.model.AnnouncementsFlag announcementsFlag)
1097                    throws SystemException {
1098                    announcementsFlag = toUnwrappedModel(announcementsFlag);
1099    
1100                    boolean isNew = announcementsFlag.isNew();
1101    
1102                    AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
1103    
1104                    Session session = null;
1105    
1106                    try {
1107                            session = openSession();
1108    
1109                            if (announcementsFlag.isNew()) {
1110                                    session.save(announcementsFlag);
1111    
1112                                    announcementsFlag.setNew(false);
1113                            }
1114                            else {
1115                                    session.merge(announcementsFlag);
1116                            }
1117                    }
1118                    catch (Exception e) {
1119                            throw processException(e);
1120                    }
1121                    finally {
1122                            closeSession(session);
1123                    }
1124    
1125                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1126    
1127                    if (isNew || !AnnouncementsFlagModelImpl.COLUMN_BITMASK_ENABLED) {
1128                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1129                    }
1130    
1131                    else {
1132                            if ((announcementsFlagModelImpl.getColumnBitmask() &
1133                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID.getColumnBitmask()) != 0) {
1134                                    Object[] args = new Object[] {
1135                                                    announcementsFlagModelImpl.getOriginalEntryId()
1136                                            };
1137    
1138                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
1139                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
1140                                            args);
1141    
1142                                    args = new Object[] { announcementsFlagModelImpl.getEntryId() };
1143    
1144                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
1145                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
1146                                            args);
1147                            }
1148                    }
1149    
1150                    EntityCacheUtil.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1151                            AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey(),
1152                            announcementsFlag);
1153    
1154                    clearUniqueFindersCache(announcementsFlag);
1155                    cacheUniqueFindersCache(announcementsFlag);
1156    
1157                    return announcementsFlag;
1158            }
1159    
1160            protected AnnouncementsFlag toUnwrappedModel(
1161                    AnnouncementsFlag announcementsFlag) {
1162                    if (announcementsFlag instanceof AnnouncementsFlagImpl) {
1163                            return announcementsFlag;
1164                    }
1165    
1166                    AnnouncementsFlagImpl announcementsFlagImpl = new AnnouncementsFlagImpl();
1167    
1168                    announcementsFlagImpl.setNew(announcementsFlag.isNew());
1169                    announcementsFlagImpl.setPrimaryKey(announcementsFlag.getPrimaryKey());
1170    
1171                    announcementsFlagImpl.setFlagId(announcementsFlag.getFlagId());
1172                    announcementsFlagImpl.setUserId(announcementsFlag.getUserId());
1173                    announcementsFlagImpl.setCreateDate(announcementsFlag.getCreateDate());
1174                    announcementsFlagImpl.setEntryId(announcementsFlag.getEntryId());
1175                    announcementsFlagImpl.setValue(announcementsFlag.getValue());
1176    
1177                    return announcementsFlagImpl;
1178            }
1179    
1180            /**
1181             * Returns the announcements flag with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1182             *
1183             * @param primaryKey the primary key of the announcements flag
1184             * @return the announcements flag
1185             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a announcements flag with the primary key could not be found
1186             * @throws SystemException if a system exception occurred
1187             */
1188            @Override
1189            public AnnouncementsFlag findByPrimaryKey(Serializable primaryKey)
1190                    throws NoSuchFlagException, SystemException {
1191                    AnnouncementsFlag announcementsFlag = fetchByPrimaryKey(primaryKey);
1192    
1193                    if (announcementsFlag == null) {
1194                            if (_log.isWarnEnabled()) {
1195                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1196                            }
1197    
1198                            throw new NoSuchFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1199                                    primaryKey);
1200                    }
1201    
1202                    return announcementsFlag;
1203            }
1204    
1205            /**
1206             * Returns the announcements flag with the primary key or throws a {@link com.liferay.portlet.announcements.NoSuchFlagException} if it could not be found.
1207             *
1208             * @param flagId the primary key of the announcements flag
1209             * @return the announcements flag
1210             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a announcements flag with the primary key could not be found
1211             * @throws SystemException if a system exception occurred
1212             */
1213            @Override
1214            public AnnouncementsFlag findByPrimaryKey(long flagId)
1215                    throws NoSuchFlagException, SystemException {
1216                    return findByPrimaryKey((Serializable)flagId);
1217            }
1218    
1219            /**
1220             * Returns the announcements flag with the primary key or returns <code>null</code> if it could not be found.
1221             *
1222             * @param primaryKey the primary key of the announcements flag
1223             * @return the announcements flag, or <code>null</code> if a announcements flag with the primary key could not be found
1224             * @throws SystemException if a system exception occurred
1225             */
1226            @Override
1227            public AnnouncementsFlag fetchByPrimaryKey(Serializable primaryKey)
1228                    throws SystemException {
1229                    AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)EntityCacheUtil.getResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1230                                    AnnouncementsFlagImpl.class, primaryKey);
1231    
1232                    if (announcementsFlag == _nullAnnouncementsFlag) {
1233                            return null;
1234                    }
1235    
1236                    if (announcementsFlag == null) {
1237                            Session session = null;
1238    
1239                            try {
1240                                    session = openSession();
1241    
1242                                    announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
1243                                                    primaryKey);
1244    
1245                                    if (announcementsFlag != null) {
1246                                            cacheResult(announcementsFlag);
1247                                    }
1248                                    else {
1249                                            EntityCacheUtil.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1250                                                    AnnouncementsFlagImpl.class, primaryKey,
1251                                                    _nullAnnouncementsFlag);
1252                                    }
1253                            }
1254                            catch (Exception e) {
1255                                    EntityCacheUtil.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
1256                                            AnnouncementsFlagImpl.class, primaryKey);
1257    
1258                                    throw processException(e);
1259                            }
1260                            finally {
1261                                    closeSession(session);
1262                            }
1263                    }
1264    
1265                    return announcementsFlag;
1266            }
1267    
1268            /**
1269             * Returns the announcements flag with the primary key or returns <code>null</code> if it could not be found.
1270             *
1271             * @param flagId the primary key of the announcements flag
1272             * @return the announcements flag, or <code>null</code> if a announcements flag with the primary key could not be found
1273             * @throws SystemException if a system exception occurred
1274             */
1275            @Override
1276            public AnnouncementsFlag fetchByPrimaryKey(long flagId)
1277                    throws SystemException {
1278                    return fetchByPrimaryKey((Serializable)flagId);
1279            }
1280    
1281            /**
1282             * Returns all the announcements flags.
1283             *
1284             * @return the announcements flags
1285             * @throws SystemException if a system exception occurred
1286             */
1287            @Override
1288            public List<AnnouncementsFlag> findAll() throws SystemException {
1289                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1290            }
1291    
1292            /**
1293             * Returns a range of all the announcements flags.
1294             *
1295             * <p>
1296             * 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.
1297             * </p>
1298             *
1299             * @param start the lower bound of the range of announcements flags
1300             * @param end the upper bound of the range of announcements flags (not inclusive)
1301             * @return the range of announcements flags
1302             * @throws SystemException if a system exception occurred
1303             */
1304            @Override
1305            public List<AnnouncementsFlag> findAll(int start, int end)
1306                    throws SystemException {
1307                    return findAll(start, end, null);
1308            }
1309    
1310            /**
1311             * Returns an ordered range of all the announcements flags.
1312             *
1313             * <p>
1314             * 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.
1315             * </p>
1316             *
1317             * @param start the lower bound of the range of announcements flags
1318             * @param end the upper bound of the range of announcements flags (not inclusive)
1319             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1320             * @return the ordered range of announcements flags
1321             * @throws SystemException if a system exception occurred
1322             */
1323            @Override
1324            public List<AnnouncementsFlag> findAll(int start, int end,
1325                    OrderByComparator orderByComparator) throws SystemException {
1326                    boolean pagination = true;
1327                    FinderPath finderPath = null;
1328                    Object[] finderArgs = null;
1329    
1330                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1331                                    (orderByComparator == null)) {
1332                            pagination = false;
1333                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1334                            finderArgs = FINDER_ARGS_EMPTY;
1335                    }
1336                    else {
1337                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1338                            finderArgs = new Object[] { start, end, orderByComparator };
1339                    }
1340    
1341                    List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(finderPath,
1342                                    finderArgs, this);
1343    
1344                    if (list == null) {
1345                            StringBundler query = null;
1346                            String sql = null;
1347    
1348                            if (orderByComparator != null) {
1349                                    query = new StringBundler(2 +
1350                                                    (orderByComparator.getOrderByFields().length * 3));
1351    
1352                                    query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG);
1353    
1354                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1355                                            orderByComparator);
1356    
1357                                    sql = query.toString();
1358                            }
1359                            else {
1360                                    sql = _SQL_SELECT_ANNOUNCEMENTSFLAG;
1361    
1362                                    if (pagination) {
1363                                            sql = sql.concat(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
1364                                    }
1365                            }
1366    
1367                            Session session = null;
1368    
1369                            try {
1370                                    session = openSession();
1371    
1372                                    Query q = session.createQuery(sql);
1373    
1374                                    if (!pagination) {
1375                                            list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1376                                                            getDialect(), start, end, false);
1377    
1378                                            Collections.sort(list);
1379    
1380                                            list = new UnmodifiableList<AnnouncementsFlag>(list);
1381                                    }
1382                                    else {
1383                                            list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1384                                                            getDialect(), start, end);
1385                                    }
1386    
1387                                    cacheResult(list);
1388    
1389                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1390                            }
1391                            catch (Exception e) {
1392                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1393    
1394                                    throw processException(e);
1395                            }
1396                            finally {
1397                                    closeSession(session);
1398                            }
1399                    }
1400    
1401                    return list;
1402            }
1403    
1404            /**
1405             * Removes all the announcements flags from the database.
1406             *
1407             * @throws SystemException if a system exception occurred
1408             */
1409            @Override
1410            public void removeAll() throws SystemException {
1411                    for (AnnouncementsFlag announcementsFlag : findAll()) {
1412                            remove(announcementsFlag);
1413                    }
1414            }
1415    
1416            /**
1417             * Returns the number of announcements flags.
1418             *
1419             * @return the number of announcements flags
1420             * @throws SystemException if a system exception occurred
1421             */
1422            @Override
1423            public int countAll() throws SystemException {
1424                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1425                                    FINDER_ARGS_EMPTY, this);
1426    
1427                    if (count == null) {
1428                            Session session = null;
1429    
1430                            try {
1431                                    session = openSession();
1432    
1433                                    Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSFLAG);
1434    
1435                                    count = (Long)q.uniqueResult();
1436    
1437                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1438                                            FINDER_ARGS_EMPTY, count);
1439                            }
1440                            catch (Exception e) {
1441                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1442                                            FINDER_ARGS_EMPTY);
1443    
1444                                    throw processException(e);
1445                            }
1446                            finally {
1447                                    closeSession(session);
1448                            }
1449                    }
1450    
1451                    return count.intValue();
1452            }
1453    
1454            /**
1455             * Initializes the announcements flag persistence.
1456             */
1457            public void afterPropertiesSet() {
1458                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1459                                            com.liferay.portal.util.PropsUtil.get(
1460                                                    "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsFlag")));
1461    
1462                    if (listenerClassNames.length > 0) {
1463                            try {
1464                                    List<ModelListener<AnnouncementsFlag>> listenersList = new ArrayList<ModelListener<AnnouncementsFlag>>();
1465    
1466                                    for (String listenerClassName : listenerClassNames) {
1467                                            listenersList.add((ModelListener<AnnouncementsFlag>)InstanceFactory.newInstance(
1468                                                            getClassLoader(), listenerClassName));
1469                                    }
1470    
1471                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1472                            }
1473                            catch (Exception e) {
1474                                    _log.error(e);
1475                            }
1476                    }
1477            }
1478    
1479            public void destroy() {
1480                    EntityCacheUtil.removeCache(AnnouncementsFlagImpl.class.getName());
1481                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1482                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1483                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1484            }
1485    
1486            private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag";
1487            private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE ";
1488            private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag";
1489            private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag WHERE ";
1490            private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsFlag.";
1491            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsFlag exists with the primary key ";
1492            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsFlag exists with the key {";
1493            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1494            private static Log _log = LogFactoryUtil.getLog(AnnouncementsFlagPersistenceImpl.class);
1495            private static AnnouncementsFlag _nullAnnouncementsFlag = new AnnouncementsFlagImpl() {
1496                            @Override
1497                            public Object clone() {
1498                                    return this;
1499                            }
1500    
1501                            @Override
1502                            public CacheModel<AnnouncementsFlag> toCacheModel() {
1503                                    return _nullAnnouncementsFlagCacheModel;
1504                            }
1505                    };
1506    
1507            private static CacheModel<AnnouncementsFlag> _nullAnnouncementsFlagCacheModel =
1508                    new CacheModel<AnnouncementsFlag>() {
1509                            @Override
1510                            public AnnouncementsFlag toEntityModel() {
1511                                    return _nullAnnouncementsFlag;
1512                            }
1513                    };
1514    }