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