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_WITHOUT_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_WITH_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    
353                    else {
354                            if ((announcementsFlagModelImpl.getColumnBitmask() &
355                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID.getColumnBitmask()) != 0) {
356                                    Object[] args = new Object[] {
357                                                    Long.valueOf(announcementsFlagModelImpl.getOriginalEntryId())
358                                            };
359    
360                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
361                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
362                                            args);
363    
364                                    args = new Object[] {
365                                                    Long.valueOf(announcementsFlagModelImpl.getEntryId())
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                    }
373    
374                    EntityCacheUtil.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
375                            AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey(),
376                            announcementsFlag);
377    
378                    if (isNew) {
379                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
380                                    new Object[] {
381                                            Long.valueOf(announcementsFlag.getUserId()),
382                                            Long.valueOf(announcementsFlag.getEntryId()),
383                                            Integer.valueOf(announcementsFlag.getValue())
384                                    }, announcementsFlag);
385                    }
386                    else {
387                            if ((announcementsFlagModelImpl.getColumnBitmask() &
388                                            FINDER_PATH_FETCH_BY_U_E_V.getColumnBitmask()) != 0) {
389                                    Object[] args = new Object[] {
390                                                    Long.valueOf(announcementsFlagModelImpl.getOriginalUserId()),
391                                                    Long.valueOf(announcementsFlagModelImpl.getOriginalEntryId()),
392                                                    Integer.valueOf(announcementsFlagModelImpl.getOriginalValue())
393                                            };
394    
395                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_E_V, args);
396                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V, args);
397    
398                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
399                                            new Object[] {
400                                                    Long.valueOf(announcementsFlag.getUserId()),
401                                                    Long.valueOf(announcementsFlag.getEntryId()),
402                                                    Integer.valueOf(announcementsFlag.getValue())
403                                            }, announcementsFlag);
404                            }
405                    }
406    
407                    return announcementsFlag;
408            }
409    
410            protected AnnouncementsFlag toUnwrappedModel(
411                    AnnouncementsFlag announcementsFlag) {
412                    if (announcementsFlag instanceof AnnouncementsFlagImpl) {
413                            return announcementsFlag;
414                    }
415    
416                    AnnouncementsFlagImpl announcementsFlagImpl = new AnnouncementsFlagImpl();
417    
418                    announcementsFlagImpl.setNew(announcementsFlag.isNew());
419                    announcementsFlagImpl.setPrimaryKey(announcementsFlag.getPrimaryKey());
420    
421                    announcementsFlagImpl.setFlagId(announcementsFlag.getFlagId());
422                    announcementsFlagImpl.setUserId(announcementsFlag.getUserId());
423                    announcementsFlagImpl.setCreateDate(announcementsFlag.getCreateDate());
424                    announcementsFlagImpl.setEntryId(announcementsFlag.getEntryId());
425                    announcementsFlagImpl.setValue(announcementsFlag.getValue());
426    
427                    return announcementsFlagImpl;
428            }
429    
430            /**
431             * Returns the announcements flag with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
432             *
433             * @param primaryKey the primary key of the announcements flag
434             * @return the announcements flag
435             * @throws com.liferay.portal.NoSuchModelException if a announcements flag with the primary key could not be found
436             * @throws SystemException if a system exception occurred
437             */
438            @Override
439            public AnnouncementsFlag findByPrimaryKey(Serializable primaryKey)
440                    throws NoSuchModelException, SystemException {
441                    return findByPrimaryKey(((Long)primaryKey).longValue());
442            }
443    
444            /**
445             * Returns the announcements flag with the primary key or throws a {@link com.liferay.portlet.announcements.NoSuchFlagException} if it could not be found.
446             *
447             * @param flagId the primary key of the announcements flag
448             * @return the announcements flag
449             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a announcements flag with the primary key could not be found
450             * @throws SystemException if a system exception occurred
451             */
452            public AnnouncementsFlag findByPrimaryKey(long flagId)
453                    throws NoSuchFlagException, SystemException {
454                    AnnouncementsFlag announcementsFlag = fetchByPrimaryKey(flagId);
455    
456                    if (announcementsFlag == null) {
457                            if (_log.isWarnEnabled()) {
458                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + flagId);
459                            }
460    
461                            throw new NoSuchFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
462                                    flagId);
463                    }
464    
465                    return announcementsFlag;
466            }
467    
468            /**
469             * Returns the announcements flag with the primary key or returns <code>null</code> if it could not be found.
470             *
471             * @param primaryKey the primary key of the announcements flag
472             * @return the announcements flag, or <code>null</code> if a announcements flag with the primary key could not be found
473             * @throws SystemException if a system exception occurred
474             */
475            @Override
476            public AnnouncementsFlag fetchByPrimaryKey(Serializable primaryKey)
477                    throws SystemException {
478                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
479            }
480    
481            /**
482             * Returns the announcements flag with the primary key or returns <code>null</code> if it could not be found.
483             *
484             * @param flagId the primary key of the announcements flag
485             * @return the announcements flag, or <code>null</code> if a announcements flag with the primary key could not be found
486             * @throws SystemException if a system exception occurred
487             */
488            public AnnouncementsFlag fetchByPrimaryKey(long flagId)
489                    throws SystemException {
490                    AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)EntityCacheUtil.getResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
491                                    AnnouncementsFlagImpl.class, flagId);
492    
493                    if (announcementsFlag == _nullAnnouncementsFlag) {
494                            return null;
495                    }
496    
497                    if (announcementsFlag == null) {
498                            Session session = null;
499    
500                            boolean hasException = false;
501    
502                            try {
503                                    session = openSession();
504    
505                                    announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
506                                                    Long.valueOf(flagId));
507                            }
508                            catch (Exception e) {
509                                    hasException = true;
510    
511                                    throw processException(e);
512                            }
513                            finally {
514                                    if (announcementsFlag != null) {
515                                            cacheResult(announcementsFlag);
516                                    }
517                                    else if (!hasException) {
518                                            EntityCacheUtil.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
519                                                    AnnouncementsFlagImpl.class, flagId,
520                                                    _nullAnnouncementsFlag);
521                                    }
522    
523                                    closeSession(session);
524                            }
525                    }
526    
527                    return announcementsFlag;
528            }
529    
530            /**
531             * Returns all the announcements flags where entryId = &#63;.
532             *
533             * @param entryId the entry ID
534             * @return the matching announcements flags
535             * @throws SystemException if a system exception occurred
536             */
537            public List<AnnouncementsFlag> findByEntryId(long entryId)
538                    throws SystemException {
539                    return findByEntryId(entryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
540            }
541    
542            /**
543             * Returns a range of all the announcements flags where entryId = &#63;.
544             *
545             * <p>
546             * 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.
547             * </p>
548             *
549             * @param entryId the entry ID
550             * @param start the lower bound of the range of announcements flags
551             * @param end the upper bound of the range of announcements flags (not inclusive)
552             * @return the range of matching announcements flags
553             * @throws SystemException if a system exception occurred
554             */
555            public List<AnnouncementsFlag> findByEntryId(long entryId, int start,
556                    int end) throws SystemException {
557                    return findByEntryId(entryId, start, end, null);
558            }
559    
560            /**
561             * Returns an ordered range of all the announcements flags where entryId = &#63;.
562             *
563             * <p>
564             * 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.
565             * </p>
566             *
567             * @param entryId the entry ID
568             * @param start the lower bound of the range of announcements flags
569             * @param end the upper bound of the range of announcements flags (not inclusive)
570             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
571             * @return the ordered range of matching announcements flags
572             * @throws SystemException if a system exception occurred
573             */
574            public List<AnnouncementsFlag> findByEntryId(long entryId, int start,
575                    int end, OrderByComparator orderByComparator) throws SystemException {
576                    FinderPath finderPath = null;
577                    Object[] finderArgs = null;
578    
579                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
580                                    (orderByComparator == null)) {
581                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID;
582                            finderArgs = new Object[] { entryId };
583                    }
584                    else {
585                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ENTRYID;
586                            finderArgs = new Object[] { entryId, start, end, orderByComparator };
587                    }
588    
589                    List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(finderPath,
590                                    finderArgs, this);
591    
592                    if (list == null) {
593                            StringBundler query = null;
594    
595                            if (orderByComparator != null) {
596                                    query = new StringBundler(3 +
597                                                    (orderByComparator.getOrderByFields().length * 3));
598                            }
599                            else {
600                                    query = new StringBundler(3);
601                            }
602    
603                            query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
604    
605                            query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
606    
607                            if (orderByComparator != null) {
608                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
609                                            orderByComparator);
610                            }
611    
612                            else {
613                                    query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
614                            }
615    
616                            String sql = query.toString();
617    
618                            Session session = null;
619    
620                            try {
621                                    session = openSession();
622    
623                                    Query q = session.createQuery(sql);
624    
625                                    QueryPos qPos = QueryPos.getInstance(q);
626    
627                                    qPos.add(entryId);
628    
629                                    list = (List<AnnouncementsFlag>)QueryUtil.list(q, getDialect(),
630                                                    start, end);
631                            }
632                            catch (Exception e) {
633                                    throw processException(e);
634                            }
635                            finally {
636                                    if (list == null) {
637                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
638                                    }
639                                    else {
640                                            cacheResult(list);
641    
642                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
643                                    }
644    
645                                    closeSession(session);
646                            }
647                    }
648    
649                    return list;
650            }
651    
652            /**
653             * Returns the first announcements flag in the ordered set where entryId = &#63;.
654             *
655             * <p>
656             * 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.
657             * </p>
658             *
659             * @param entryId the entry ID
660             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
661             * @return the first matching announcements flag
662             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a matching announcements flag could not be found
663             * @throws SystemException if a system exception occurred
664             */
665            public AnnouncementsFlag findByEntryId_First(long entryId,
666                    OrderByComparator orderByComparator)
667                    throws NoSuchFlagException, SystemException {
668                    List<AnnouncementsFlag> list = findByEntryId(entryId, 0, 1,
669                                    orderByComparator);
670    
671                    if (list.isEmpty()) {
672                            StringBundler msg = new StringBundler(4);
673    
674                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
675    
676                            msg.append("entryId=");
677                            msg.append(entryId);
678    
679                            msg.append(StringPool.CLOSE_CURLY_BRACE);
680    
681                            throw new NoSuchFlagException(msg.toString());
682                    }
683                    else {
684                            return list.get(0);
685                    }
686            }
687    
688            /**
689             * Returns the last announcements flag in the ordered set where entryId = &#63;.
690             *
691             * <p>
692             * 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.
693             * </p>
694             *
695             * @param entryId the entry ID
696             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
697             * @return the last matching announcements flag
698             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a matching announcements flag could not be found
699             * @throws SystemException if a system exception occurred
700             */
701            public AnnouncementsFlag findByEntryId_Last(long entryId,
702                    OrderByComparator orderByComparator)
703                    throws NoSuchFlagException, SystemException {
704                    int count = countByEntryId(entryId);
705    
706                    List<AnnouncementsFlag> list = findByEntryId(entryId, count - 1, count,
707                                    orderByComparator);
708    
709                    if (list.isEmpty()) {
710                            StringBundler msg = new StringBundler(4);
711    
712                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
713    
714                            msg.append("entryId=");
715                            msg.append(entryId);
716    
717                            msg.append(StringPool.CLOSE_CURLY_BRACE);
718    
719                            throw new NoSuchFlagException(msg.toString());
720                    }
721                    else {
722                            return list.get(0);
723                    }
724            }
725    
726            /**
727             * Returns the announcements flags before and after the current announcements flag in the ordered set where entryId = &#63;.
728             *
729             * <p>
730             * 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.
731             * </p>
732             *
733             * @param flagId the primary key of the current announcements flag
734             * @param entryId the entry ID
735             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
736             * @return the previous, current, and next announcements flag
737             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a announcements flag with the primary key could not be found
738             * @throws SystemException if a system exception occurred
739             */
740            public AnnouncementsFlag[] findByEntryId_PrevAndNext(long flagId,
741                    long entryId, OrderByComparator orderByComparator)
742                    throws NoSuchFlagException, SystemException {
743                    AnnouncementsFlag announcementsFlag = findByPrimaryKey(flagId);
744    
745                    Session session = null;
746    
747                    try {
748                            session = openSession();
749    
750                            AnnouncementsFlag[] array = new AnnouncementsFlagImpl[3];
751    
752                            array[0] = getByEntryId_PrevAndNext(session, announcementsFlag,
753                                            entryId, orderByComparator, true);
754    
755                            array[1] = announcementsFlag;
756    
757                            array[2] = getByEntryId_PrevAndNext(session, announcementsFlag,
758                                            entryId, orderByComparator, false);
759    
760                            return array;
761                    }
762                    catch (Exception e) {
763                            throw processException(e);
764                    }
765                    finally {
766                            closeSession(session);
767                    }
768            }
769    
770            protected AnnouncementsFlag getByEntryId_PrevAndNext(Session session,
771                    AnnouncementsFlag announcementsFlag, long entryId,
772                    OrderByComparator orderByComparator, boolean previous) {
773                    StringBundler query = null;
774    
775                    if (orderByComparator != null) {
776                            query = new StringBundler(6 +
777                                            (orderByComparator.getOrderByFields().length * 6));
778                    }
779                    else {
780                            query = new StringBundler(3);
781                    }
782    
783                    query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
784    
785                    query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
786    
787                    if (orderByComparator != null) {
788                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
789    
790                            if (orderByConditionFields.length > 0) {
791                                    query.append(WHERE_AND);
792                            }
793    
794                            for (int i = 0; i < orderByConditionFields.length; i++) {
795                                    query.append(_ORDER_BY_ENTITY_ALIAS);
796                                    query.append(orderByConditionFields[i]);
797    
798                                    if ((i + 1) < orderByConditionFields.length) {
799                                            if (orderByComparator.isAscending() ^ previous) {
800                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
801                                            }
802                                            else {
803                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
804                                            }
805                                    }
806                                    else {
807                                            if (orderByComparator.isAscending() ^ previous) {
808                                                    query.append(WHERE_GREATER_THAN);
809                                            }
810                                            else {
811                                                    query.append(WHERE_LESSER_THAN);
812                                            }
813                                    }
814                            }
815    
816                            query.append(ORDER_BY_CLAUSE);
817    
818                            String[] orderByFields = orderByComparator.getOrderByFields();
819    
820                            for (int i = 0; i < orderByFields.length; i++) {
821                                    query.append(_ORDER_BY_ENTITY_ALIAS);
822                                    query.append(orderByFields[i]);
823    
824                                    if ((i + 1) < orderByFields.length) {
825                                            if (orderByComparator.isAscending() ^ previous) {
826                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
827                                            }
828                                            else {
829                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
830                                            }
831                                    }
832                                    else {
833                                            if (orderByComparator.isAscending() ^ previous) {
834                                                    query.append(ORDER_BY_ASC);
835                                            }
836                                            else {
837                                                    query.append(ORDER_BY_DESC);
838                                            }
839                                    }
840                            }
841                    }
842    
843                    else {
844                            query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
845                    }
846    
847                    String sql = query.toString();
848    
849                    Query q = session.createQuery(sql);
850    
851                    q.setFirstResult(0);
852                    q.setMaxResults(2);
853    
854                    QueryPos qPos = QueryPos.getInstance(q);
855    
856                    qPos.add(entryId);
857    
858                    if (orderByComparator != null) {
859                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsFlag);
860    
861                            for (Object value : values) {
862                                    qPos.add(value);
863                            }
864                    }
865    
866                    List<AnnouncementsFlag> list = q.list();
867    
868                    if (list.size() == 2) {
869                            return list.get(1);
870                    }
871                    else {
872                            return null;
873                    }
874            }
875    
876            /**
877             * 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.
878             *
879             * @param userId the user ID
880             * @param entryId the entry ID
881             * @param value the value
882             * @return the matching announcements flag
883             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a matching announcements flag could not be found
884             * @throws SystemException if a system exception occurred
885             */
886            public AnnouncementsFlag findByU_E_V(long userId, long entryId, int value)
887                    throws NoSuchFlagException, SystemException {
888                    AnnouncementsFlag announcementsFlag = fetchByU_E_V(userId, entryId,
889                                    value);
890    
891                    if (announcementsFlag == null) {
892                            StringBundler msg = new StringBundler(8);
893    
894                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
895    
896                            msg.append("userId=");
897                            msg.append(userId);
898    
899                            msg.append(", entryId=");
900                            msg.append(entryId);
901    
902                            msg.append(", value=");
903                            msg.append(value);
904    
905                            msg.append(StringPool.CLOSE_CURLY_BRACE);
906    
907                            if (_log.isWarnEnabled()) {
908                                    _log.warn(msg.toString());
909                            }
910    
911                            throw new NoSuchFlagException(msg.toString());
912                    }
913    
914                    return announcementsFlag;
915            }
916    
917            /**
918             * 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.
919             *
920             * @param userId the user ID
921             * @param entryId the entry ID
922             * @param value the value
923             * @return the matching announcements flag, or <code>null</code> if a matching announcements flag could not be found
924             * @throws SystemException if a system exception occurred
925             */
926            public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value)
927                    throws SystemException {
928                    return fetchByU_E_V(userId, entryId, value, true);
929            }
930    
931            /**
932             * 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.
933             *
934             * @param userId the user ID
935             * @param entryId the entry ID
936             * @param value the value
937             * @param retrieveFromCache whether to use the finder cache
938             * @return the matching announcements flag, or <code>null</code> if a matching announcements flag could not be found
939             * @throws SystemException if a system exception occurred
940             */
941            public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value,
942                    boolean retrieveFromCache) throws SystemException {
943                    Object[] finderArgs = new Object[] { userId, entryId, value };
944    
945                    Object result = null;
946    
947                    if (retrieveFromCache) {
948                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_E_V,
949                                            finderArgs, this);
950                    }
951    
952                    if (result == null) {
953                            StringBundler query = new StringBundler(5);
954    
955                            query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
956    
957                            query.append(_FINDER_COLUMN_U_E_V_USERID_2);
958    
959                            query.append(_FINDER_COLUMN_U_E_V_ENTRYID_2);
960    
961                            query.append(_FINDER_COLUMN_U_E_V_VALUE_2);
962    
963                            query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
964    
965                            String sql = query.toString();
966    
967                            Session session = null;
968    
969                            try {
970                                    session = openSession();
971    
972                                    Query q = session.createQuery(sql);
973    
974                                    QueryPos qPos = QueryPos.getInstance(q);
975    
976                                    qPos.add(userId);
977    
978                                    qPos.add(entryId);
979    
980                                    qPos.add(value);
981    
982                                    List<AnnouncementsFlag> list = q.list();
983    
984                                    result = list;
985    
986                                    AnnouncementsFlag announcementsFlag = null;
987    
988                                    if (list.isEmpty()) {
989                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
990                                                    finderArgs, list);
991                                    }
992                                    else {
993                                            announcementsFlag = list.get(0);
994    
995                                            cacheResult(announcementsFlag);
996    
997                                            if ((announcementsFlag.getUserId() != userId) ||
998                                                            (announcementsFlag.getEntryId() != entryId) ||
999                                                            (announcementsFlag.getValue() != value)) {
1000                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
1001                                                            finderArgs, announcementsFlag);
1002                                            }
1003                                    }
1004    
1005                                    return announcementsFlag;
1006                            }
1007                            catch (Exception e) {
1008                                    throw processException(e);
1009                            }
1010                            finally {
1011                                    if (result == null) {
1012                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V,
1013                                                    finderArgs);
1014                                    }
1015    
1016                                    closeSession(session);
1017                            }
1018                    }
1019                    else {
1020                            if (result instanceof List<?>) {
1021                                    return null;
1022                            }
1023                            else {
1024                                    return (AnnouncementsFlag)result;
1025                            }
1026                    }
1027            }
1028    
1029            /**
1030             * Returns all the announcements flags.
1031             *
1032             * @return the announcements flags
1033             * @throws SystemException if a system exception occurred
1034             */
1035            public List<AnnouncementsFlag> findAll() throws SystemException {
1036                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1037            }
1038    
1039            /**
1040             * Returns a range of all the announcements flags.
1041             *
1042             * <p>
1043             * 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.
1044             * </p>
1045             *
1046             * @param start the lower bound of the range of announcements flags
1047             * @param end the upper bound of the range of announcements flags (not inclusive)
1048             * @return the range of announcements flags
1049             * @throws SystemException if a system exception occurred
1050             */
1051            public List<AnnouncementsFlag> findAll(int start, int end)
1052                    throws SystemException {
1053                    return findAll(start, end, null);
1054            }
1055    
1056            /**
1057             * Returns an ordered range of all the announcements flags.
1058             *
1059             * <p>
1060             * 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.
1061             * </p>
1062             *
1063             * @param start the lower bound of the range of announcements flags
1064             * @param end the upper bound of the range of announcements flags (not inclusive)
1065             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1066             * @return the ordered range of announcements flags
1067             * @throws SystemException if a system exception occurred
1068             */
1069            public List<AnnouncementsFlag> findAll(int start, int end,
1070                    OrderByComparator orderByComparator) throws SystemException {
1071                    FinderPath finderPath = null;
1072                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1073    
1074                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1075                                    (orderByComparator == null)) {
1076                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1077                            finderArgs = FINDER_ARGS_EMPTY;
1078                    }
1079                    else {
1080                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1081                            finderArgs = new Object[] { start, end, orderByComparator };
1082                    }
1083    
1084                    List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(finderPath,
1085                                    finderArgs, this);
1086    
1087                    if (list == null) {
1088                            StringBundler query = null;
1089                            String sql = null;
1090    
1091                            if (orderByComparator != null) {
1092                                    query = new StringBundler(2 +
1093                                                    (orderByComparator.getOrderByFields().length * 3));
1094    
1095                                    query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG);
1096    
1097                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1098                                            orderByComparator);
1099    
1100                                    sql = query.toString();
1101                            }
1102                            else {
1103                                    sql = _SQL_SELECT_ANNOUNCEMENTSFLAG.concat(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
1104                            }
1105    
1106                            Session session = null;
1107    
1108                            try {
1109                                    session = openSession();
1110    
1111                                    Query q = session.createQuery(sql);
1112    
1113                                    if (orderByComparator == null) {
1114                                            list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1115                                                            getDialect(), start, end, false);
1116    
1117                                            Collections.sort(list);
1118                                    }
1119                                    else {
1120                                            list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1121                                                            getDialect(), start, end);
1122                                    }
1123                            }
1124                            catch (Exception e) {
1125                                    throw processException(e);
1126                            }
1127                            finally {
1128                                    if (list == null) {
1129                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1130                                    }
1131                                    else {
1132                                            cacheResult(list);
1133    
1134                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1135                                    }
1136    
1137                                    closeSession(session);
1138                            }
1139                    }
1140    
1141                    return list;
1142            }
1143    
1144            /**
1145             * Removes all the announcements flags where entryId = &#63; from the database.
1146             *
1147             * @param entryId the entry ID
1148             * @throws SystemException if a system exception occurred
1149             */
1150            public void removeByEntryId(long entryId) throws SystemException {
1151                    for (AnnouncementsFlag announcementsFlag : findByEntryId(entryId)) {
1152                            remove(announcementsFlag);
1153                    }
1154            }
1155    
1156            /**
1157             * Removes the announcements flag where userId = &#63; and entryId = &#63; and value = &#63; from the database.
1158             *
1159             * @param userId the user ID
1160             * @param entryId the entry ID
1161             * @param value the value
1162             * @throws SystemException if a system exception occurred
1163             */
1164            public void removeByU_E_V(long userId, long entryId, int value)
1165                    throws NoSuchFlagException, SystemException {
1166                    AnnouncementsFlag announcementsFlag = findByU_E_V(userId, entryId, value);
1167    
1168                    remove(announcementsFlag);
1169            }
1170    
1171            /**
1172             * Removes all the announcements flags from the database.
1173             *
1174             * @throws SystemException if a system exception occurred
1175             */
1176            public void removeAll() throws SystemException {
1177                    for (AnnouncementsFlag announcementsFlag : findAll()) {
1178                            remove(announcementsFlag);
1179                    }
1180            }
1181    
1182            /**
1183             * Returns the number of announcements flags where entryId = &#63;.
1184             *
1185             * @param entryId the entry ID
1186             * @return the number of matching announcements flags
1187             * @throws SystemException if a system exception occurred
1188             */
1189            public int countByEntryId(long entryId) throws SystemException {
1190                    Object[] finderArgs = new Object[] { entryId };
1191    
1192                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ENTRYID,
1193                                    finderArgs, this);
1194    
1195                    if (count == null) {
1196                            StringBundler query = new StringBundler(2);
1197    
1198                            query.append(_SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE);
1199    
1200                            query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
1201    
1202                            String sql = query.toString();
1203    
1204                            Session session = null;
1205    
1206                            try {
1207                                    session = openSession();
1208    
1209                                    Query q = session.createQuery(sql);
1210    
1211                                    QueryPos qPos = QueryPos.getInstance(q);
1212    
1213                                    qPos.add(entryId);
1214    
1215                                    count = (Long)q.uniqueResult();
1216                            }
1217                            catch (Exception e) {
1218                                    throw processException(e);
1219                            }
1220                            finally {
1221                                    if (count == null) {
1222                                            count = Long.valueOf(0);
1223                                    }
1224    
1225                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ENTRYID,
1226                                            finderArgs, count);
1227    
1228                                    closeSession(session);
1229                            }
1230                    }
1231    
1232                    return count.intValue();
1233            }
1234    
1235            /**
1236             * Returns the number of announcements flags where userId = &#63; and entryId = &#63; and value = &#63;.
1237             *
1238             * @param userId the user ID
1239             * @param entryId the entry ID
1240             * @param value the value
1241             * @return the number of matching announcements flags
1242             * @throws SystemException if a system exception occurred
1243             */
1244            public int countByU_E_V(long userId, long entryId, int value)
1245                    throws SystemException {
1246                    Object[] finderArgs = new Object[] { userId, entryId, value };
1247    
1248                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_E_V,
1249                                    finderArgs, this);
1250    
1251                    if (count == null) {
1252                            StringBundler query = new StringBundler(4);
1253    
1254                            query.append(_SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE);
1255    
1256                            query.append(_FINDER_COLUMN_U_E_V_USERID_2);
1257    
1258                            query.append(_FINDER_COLUMN_U_E_V_ENTRYID_2);
1259    
1260                            query.append(_FINDER_COLUMN_U_E_V_VALUE_2);
1261    
1262                            String sql = query.toString();
1263    
1264                            Session session = null;
1265    
1266                            try {
1267                                    session = openSession();
1268    
1269                                    Query q = session.createQuery(sql);
1270    
1271                                    QueryPos qPos = QueryPos.getInstance(q);
1272    
1273                                    qPos.add(userId);
1274    
1275                                    qPos.add(entryId);
1276    
1277                                    qPos.add(value);
1278    
1279                                    count = (Long)q.uniqueResult();
1280                            }
1281                            catch (Exception e) {
1282                                    throw processException(e);
1283                            }
1284                            finally {
1285                                    if (count == null) {
1286                                            count = Long.valueOf(0);
1287                                    }
1288    
1289                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_E_V,
1290                                            finderArgs, count);
1291    
1292                                    closeSession(session);
1293                            }
1294                    }
1295    
1296                    return count.intValue();
1297            }
1298    
1299            /**
1300             * Returns the number of announcements flags.
1301             *
1302             * @return the number of announcements flags
1303             * @throws SystemException if a system exception occurred
1304             */
1305            public int countAll() throws SystemException {
1306                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1307                                    FINDER_ARGS_EMPTY, this);
1308    
1309                    if (count == null) {
1310                            Session session = null;
1311    
1312                            try {
1313                                    session = openSession();
1314    
1315                                    Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSFLAG);
1316    
1317                                    count = (Long)q.uniqueResult();
1318                            }
1319                            catch (Exception e) {
1320                                    throw processException(e);
1321                            }
1322                            finally {
1323                                    if (count == null) {
1324                                            count = Long.valueOf(0);
1325                                    }
1326    
1327                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1328                                            FINDER_ARGS_EMPTY, count);
1329    
1330                                    closeSession(session);
1331                            }
1332                    }
1333    
1334                    return count.intValue();
1335            }
1336    
1337            /**
1338             * Initializes the announcements flag persistence.
1339             */
1340            public void afterPropertiesSet() {
1341                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1342                                            com.liferay.portal.util.PropsUtil.get(
1343                                                    "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsFlag")));
1344    
1345                    if (listenerClassNames.length > 0) {
1346                            try {
1347                                    List<ModelListener<AnnouncementsFlag>> listenersList = new ArrayList<ModelListener<AnnouncementsFlag>>();
1348    
1349                                    for (String listenerClassName : listenerClassNames) {
1350                                            listenersList.add((ModelListener<AnnouncementsFlag>)InstanceFactory.newInstance(
1351                                                            listenerClassName));
1352                                    }
1353    
1354                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1355                            }
1356                            catch (Exception e) {
1357                                    _log.error(e);
1358                            }
1359                    }
1360            }
1361    
1362            public void destroy() {
1363                    EntityCacheUtil.removeCache(AnnouncementsFlagImpl.class.getName());
1364                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1365                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1366            }
1367    
1368            @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1369            protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1370            @BeanReference(type = AnnouncementsEntryPersistence.class)
1371            protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1372            @BeanReference(type = AnnouncementsFlagPersistence.class)
1373            protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1374            @BeanReference(type = ResourcePersistence.class)
1375            protected ResourcePersistence resourcePersistence;
1376            @BeanReference(type = UserPersistence.class)
1377            protected UserPersistence userPersistence;
1378            private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag";
1379            private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE ";
1380            private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag";
1381            private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag WHERE ";
1382            private static final String _FINDER_COLUMN_ENTRYID_ENTRYID_2 = "announcementsFlag.entryId = ?";
1383            private static final String _FINDER_COLUMN_U_E_V_USERID_2 = "announcementsFlag.userId = ? AND ";
1384            private static final String _FINDER_COLUMN_U_E_V_ENTRYID_2 = "announcementsFlag.entryId = ? AND ";
1385            private static final String _FINDER_COLUMN_U_E_V_VALUE_2 = "announcementsFlag.value = ?";
1386            private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsFlag.";
1387            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsFlag exists with the primary key ";
1388            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsFlag exists with the key {";
1389            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1390            private static Log _log = LogFactoryUtil.getLog(AnnouncementsFlagPersistenceImpl.class);
1391            private static AnnouncementsFlag _nullAnnouncementsFlag = new AnnouncementsFlagImpl() {
1392                            @Override
1393                            public Object clone() {
1394                                    return this;
1395                            }
1396    
1397                            @Override
1398                            public CacheModel<AnnouncementsFlag> toCacheModel() {
1399                                    return _nullAnnouncementsFlagCacheModel;
1400                            }
1401                    };
1402    
1403            private static CacheModel<AnnouncementsFlag> _nullAnnouncementsFlagCacheModel =
1404                    new CacheModel<AnnouncementsFlag>() {
1405                            public AnnouncementsFlag toEntityModel() {
1406                                    return _nullAnnouncementsFlag;
1407                            }
1408                    };
1409    }