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