001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V,
204                            new Object[] {
205                                    Long.valueOf(announcementsFlag.getUserId()),
206                                    Long.valueOf(announcementsFlag.getEntryId()),
207                                    Integer.valueOf(announcementsFlag.getValue())
208                            });
209            }
210    
211            /**
212             * Creates a new announcements flag with the primary key. Does not add the announcements flag to the database.
213             *
214             * @param flagId the primary key for the new announcements flag
215             * @return the new announcements flag
216             */
217            public AnnouncementsFlag create(long flagId) {
218                    AnnouncementsFlag announcementsFlag = new AnnouncementsFlagImpl();
219    
220                    announcementsFlag.setNew(true);
221                    announcementsFlag.setPrimaryKey(flagId);
222    
223                    return announcementsFlag;
224            }
225    
226            /**
227             * Removes the announcements flag with the primary key from the database. Also notifies the appropriate model listeners.
228             *
229             * @param primaryKey the primary key of the announcements flag
230             * @return the announcements flag that was removed
231             * @throws com.liferay.portal.NoSuchModelException if a announcements flag with the primary key could not be found
232             * @throws SystemException if a system exception occurred
233             */
234            @Override
235            public AnnouncementsFlag remove(Serializable primaryKey)
236                    throws NoSuchModelException, SystemException {
237                    return remove(((Long)primaryKey).longValue());
238            }
239    
240            /**
241             * Removes the announcements flag with the primary key from the database. Also notifies the appropriate model listeners.
242             *
243             * @param flagId the primary key of the announcements flag
244             * @return the announcements flag that was removed
245             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a announcements flag with the primary key could not be found
246             * @throws SystemException if a system exception occurred
247             */
248            public AnnouncementsFlag remove(long flagId)
249                    throws NoSuchFlagException, SystemException {
250                    Session session = null;
251    
252                    try {
253                            session = openSession();
254    
255                            AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
256                                            Long.valueOf(flagId));
257    
258                            if (announcementsFlag == null) {
259                                    if (_log.isWarnEnabled()) {
260                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + flagId);
261                                    }
262    
263                                    throw new NoSuchFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
264                                            flagId);
265                            }
266    
267                            return announcementsFlagPersistence.remove(announcementsFlag);
268                    }
269                    catch (NoSuchFlagException nsee) {
270                            throw nsee;
271                    }
272                    catch (Exception e) {
273                            throw processException(e);
274                    }
275                    finally {
276                            closeSession(session);
277                    }
278            }
279    
280            /**
281             * Removes the announcements flag from the database. Also notifies the appropriate model listeners.
282             *
283             * @param announcementsFlag the announcements flag
284             * @return the announcements flag that was removed
285             * @throws SystemException if a system exception occurred
286             */
287            @Override
288            public AnnouncementsFlag remove(AnnouncementsFlag announcementsFlag)
289                    throws SystemException {
290                    return super.remove(announcementsFlag);
291            }
292    
293            @Override
294            protected AnnouncementsFlag removeImpl(AnnouncementsFlag announcementsFlag)
295                    throws SystemException {
296                    announcementsFlag = toUnwrappedModel(announcementsFlag);
297    
298                    Session session = null;
299    
300                    try {
301                            session = openSession();
302    
303                            BatchSessionUtil.delete(session, announcementsFlag);
304                    }
305                    catch (Exception e) {
306                            throw processException(e);
307                    }
308                    finally {
309                            closeSession(session);
310                    }
311    
312                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
313                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
314    
315                    AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
316    
317                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V,
318                            new Object[] {
319                                    Long.valueOf(announcementsFlagModelImpl.getUserId()),
320                                    Long.valueOf(announcementsFlagModelImpl.getEntryId()),
321                                    Integer.valueOf(announcementsFlagModelImpl.getValue())
322                            });
323    
324                    EntityCacheUtil.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
325                            AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey());
326    
327                    return announcementsFlag;
328            }
329    
330            @Override
331            public AnnouncementsFlag updateImpl(
332                    com.liferay.portlet.announcements.model.AnnouncementsFlag announcementsFlag,
333                    boolean merge) throws SystemException {
334                    announcementsFlag = toUnwrappedModel(announcementsFlag);
335    
336                    boolean isNew = announcementsFlag.isNew();
337    
338                    AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
339    
340                    Session session = null;
341    
342                    try {
343                            session = openSession();
344    
345                            BatchSessionUtil.update(session, announcementsFlag, merge);
346    
347                            announcementsFlag.setNew(false);
348                    }
349                    catch (Exception e) {
350                            throw processException(e);
351                    }
352                    finally {
353                            closeSession(session);
354                    }
355    
356                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
357    
358                    if (isNew || !AnnouncementsFlagModelImpl.COLUMN_BITMASK_ENABLED) {
359                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
360                    }
361    
362                    else {
363                            if ((announcementsFlagModelImpl.getColumnBitmask() &
364                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID.getColumnBitmask()) != 0) {
365                                    Object[] args = new Object[] {
366                                                    Long.valueOf(announcementsFlagModelImpl.getOriginalEntryId())
367                                            };
368    
369                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
370                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
371                                            args);
372    
373                                    args = new Object[] {
374                                                    Long.valueOf(announcementsFlagModelImpl.getEntryId())
375                                            };
376    
377                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
378                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
379                                            args);
380                            }
381                    }
382    
383                    EntityCacheUtil.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
384                            AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey(),
385                            announcementsFlag);
386    
387                    if (isNew) {
388                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
389                                    new Object[] {
390                                            Long.valueOf(announcementsFlag.getUserId()),
391                                            Long.valueOf(announcementsFlag.getEntryId()),
392                                            Integer.valueOf(announcementsFlag.getValue())
393                                    }, announcementsFlag);
394                    }
395                    else {
396                            if ((announcementsFlagModelImpl.getColumnBitmask() &
397                                            FINDER_PATH_FETCH_BY_U_E_V.getColumnBitmask()) != 0) {
398                                    Object[] args = new Object[] {
399                                                    Long.valueOf(announcementsFlagModelImpl.getOriginalUserId()),
400                                                    Long.valueOf(announcementsFlagModelImpl.getOriginalEntryId()),
401                                                    Integer.valueOf(announcementsFlagModelImpl.getOriginalValue())
402                                            };
403    
404                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_E_V, args);
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) {
602                            StringBundler query = null;
603    
604                            if (orderByComparator != null) {
605                                    query = new StringBundler(3 +
606                                                    (orderByComparator.getOrderByFields().length * 3));
607                            }
608                            else {
609                                    query = new StringBundler(3);
610                            }
611    
612                            query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
613    
614                            query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
615    
616                            if (orderByComparator != null) {
617                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
618                                            orderByComparator);
619                            }
620    
621                            else {
622                                    query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
623                            }
624    
625                            String sql = query.toString();
626    
627                            Session session = null;
628    
629                            try {
630                                    session = openSession();
631    
632                                    Query q = session.createQuery(sql);
633    
634                                    QueryPos qPos = QueryPos.getInstance(q);
635    
636                                    qPos.add(entryId);
637    
638                                    list = (List<AnnouncementsFlag>)QueryUtil.list(q, getDialect(),
639                                                    start, end);
640                            }
641                            catch (Exception e) {
642                                    throw processException(e);
643                            }
644                            finally {
645                                    if (list == null) {
646                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
647                                    }
648                                    else {
649                                            cacheResult(list);
650    
651                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
652                                    }
653    
654                                    closeSession(session);
655                            }
656                    }
657    
658                    return list;
659            }
660    
661            /**
662             * Returns the first announcements flag in the ordered set where entryId = &#63;.
663             *
664             * <p>
665             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
666             * </p>
667             *
668             * @param entryId the entry ID
669             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
670             * @return the first matching announcements flag
671             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a matching announcements flag could not be found
672             * @throws SystemException if a system exception occurred
673             */
674            public AnnouncementsFlag findByEntryId_First(long entryId,
675                    OrderByComparator orderByComparator)
676                    throws NoSuchFlagException, SystemException {
677                    List<AnnouncementsFlag> list = findByEntryId(entryId, 0, 1,
678                                    orderByComparator);
679    
680                    if (list.isEmpty()) {
681                            StringBundler msg = new StringBundler(4);
682    
683                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
684    
685                            msg.append("entryId=");
686                            msg.append(entryId);
687    
688                            msg.append(StringPool.CLOSE_CURLY_BRACE);
689    
690                            throw new NoSuchFlagException(msg.toString());
691                    }
692                    else {
693                            return list.get(0);
694                    }
695            }
696    
697            /**
698             * Returns the last announcements flag in the ordered set where entryId = &#63;.
699             *
700             * <p>
701             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
702             * </p>
703             *
704             * @param entryId the entry ID
705             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
706             * @return the last matching announcements flag
707             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a matching announcements flag could not be found
708             * @throws SystemException if a system exception occurred
709             */
710            public AnnouncementsFlag findByEntryId_Last(long entryId,
711                    OrderByComparator orderByComparator)
712                    throws NoSuchFlagException, SystemException {
713                    int count = countByEntryId(entryId);
714    
715                    List<AnnouncementsFlag> list = findByEntryId(entryId, count - 1, count,
716                                    orderByComparator);
717    
718                    if (list.isEmpty()) {
719                            StringBundler msg = new StringBundler(4);
720    
721                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
722    
723                            msg.append("entryId=");
724                            msg.append(entryId);
725    
726                            msg.append(StringPool.CLOSE_CURLY_BRACE);
727    
728                            throw new NoSuchFlagException(msg.toString());
729                    }
730                    else {
731                            return list.get(0);
732                    }
733            }
734    
735            /**
736             * Returns the announcements flags before and after the current announcements flag in the ordered set where entryId = &#63;.
737             *
738             * <p>
739             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
740             * </p>
741             *
742             * @param flagId the primary key of the current announcements flag
743             * @param entryId the entry ID
744             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
745             * @return the previous, current, and next announcements flag
746             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a announcements flag with the primary key could not be found
747             * @throws SystemException if a system exception occurred
748             */
749            public AnnouncementsFlag[] findByEntryId_PrevAndNext(long flagId,
750                    long entryId, OrderByComparator orderByComparator)
751                    throws NoSuchFlagException, SystemException {
752                    AnnouncementsFlag announcementsFlag = findByPrimaryKey(flagId);
753    
754                    Session session = null;
755    
756                    try {
757                            session = openSession();
758    
759                            AnnouncementsFlag[] array = new AnnouncementsFlagImpl[3];
760    
761                            array[0] = getByEntryId_PrevAndNext(session, announcementsFlag,
762                                            entryId, orderByComparator, true);
763    
764                            array[1] = announcementsFlag;
765    
766                            array[2] = getByEntryId_PrevAndNext(session, announcementsFlag,
767                                            entryId, orderByComparator, false);
768    
769                            return array;
770                    }
771                    catch (Exception e) {
772                            throw processException(e);
773                    }
774                    finally {
775                            closeSession(session);
776                    }
777            }
778    
779            protected AnnouncementsFlag getByEntryId_PrevAndNext(Session session,
780                    AnnouncementsFlag announcementsFlag, long entryId,
781                    OrderByComparator orderByComparator, boolean previous) {
782                    StringBundler query = null;
783    
784                    if (orderByComparator != null) {
785                            query = new StringBundler(6 +
786                                            (orderByComparator.getOrderByFields().length * 6));
787                    }
788                    else {
789                            query = new StringBundler(3);
790                    }
791    
792                    query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
793    
794                    query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
795    
796                    if (orderByComparator != null) {
797                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
798    
799                            if (orderByConditionFields.length > 0) {
800                                    query.append(WHERE_AND);
801                            }
802    
803                            for (int i = 0; i < orderByConditionFields.length; i++) {
804                                    query.append(_ORDER_BY_ENTITY_ALIAS);
805                                    query.append(orderByConditionFields[i]);
806    
807                                    if ((i + 1) < orderByConditionFields.length) {
808                                            if (orderByComparator.isAscending() ^ previous) {
809                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
810                                            }
811                                            else {
812                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
813                                            }
814                                    }
815                                    else {
816                                            if (orderByComparator.isAscending() ^ previous) {
817                                                    query.append(WHERE_GREATER_THAN);
818                                            }
819                                            else {
820                                                    query.append(WHERE_LESSER_THAN);
821                                            }
822                                    }
823                            }
824    
825                            query.append(ORDER_BY_CLAUSE);
826    
827                            String[] orderByFields = orderByComparator.getOrderByFields();
828    
829                            for (int i = 0; i < orderByFields.length; i++) {
830                                    query.append(_ORDER_BY_ENTITY_ALIAS);
831                                    query.append(orderByFields[i]);
832    
833                                    if ((i + 1) < orderByFields.length) {
834                                            if (orderByComparator.isAscending() ^ previous) {
835                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
836                                            }
837                                            else {
838                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
839                                            }
840                                    }
841                                    else {
842                                            if (orderByComparator.isAscending() ^ previous) {
843                                                    query.append(ORDER_BY_ASC);
844                                            }
845                                            else {
846                                                    query.append(ORDER_BY_DESC);
847                                            }
848                                    }
849                            }
850                    }
851    
852                    else {
853                            query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
854                    }
855    
856                    String sql = query.toString();
857    
858                    Query q = session.createQuery(sql);
859    
860                    q.setFirstResult(0);
861                    q.setMaxResults(2);
862    
863                    QueryPos qPos = QueryPos.getInstance(q);
864    
865                    qPos.add(entryId);
866    
867                    if (orderByComparator != null) {
868                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsFlag);
869    
870                            for (Object value : values) {
871                                    qPos.add(value);
872                            }
873                    }
874    
875                    List<AnnouncementsFlag> list = q.list();
876    
877                    if (list.size() == 2) {
878                            return list.get(1);
879                    }
880                    else {
881                            return null;
882                    }
883            }
884    
885            /**
886             * Returns the announcements flag where userId = &#63; and entryId = &#63; and value = &#63; or throws a {@link com.liferay.portlet.announcements.NoSuchFlagException} if it could not be found.
887             *
888             * @param userId the user ID
889             * @param entryId the entry ID
890             * @param value the value
891             * @return the matching announcements flag
892             * @throws com.liferay.portlet.announcements.NoSuchFlagException if a matching announcements flag could not be found
893             * @throws SystemException if a system exception occurred
894             */
895            public AnnouncementsFlag findByU_E_V(long userId, long entryId, int value)
896                    throws NoSuchFlagException, SystemException {
897                    AnnouncementsFlag announcementsFlag = fetchByU_E_V(userId, entryId,
898                                    value);
899    
900                    if (announcementsFlag == null) {
901                            StringBundler msg = new StringBundler(8);
902    
903                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
904    
905                            msg.append("userId=");
906                            msg.append(userId);
907    
908                            msg.append(", entryId=");
909                            msg.append(entryId);
910    
911                            msg.append(", value=");
912                            msg.append(value);
913    
914                            msg.append(StringPool.CLOSE_CURLY_BRACE);
915    
916                            if (_log.isWarnEnabled()) {
917                                    _log.warn(msg.toString());
918                            }
919    
920                            throw new NoSuchFlagException(msg.toString());
921                    }
922    
923                    return announcementsFlag;
924            }
925    
926            /**
927             * Returns the announcements flag where userId = &#63; and entryId = &#63; and value = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
928             *
929             * @param userId the user ID
930             * @param entryId the entry ID
931             * @param value the value
932             * @return the matching announcements flag, or <code>null</code> if a matching announcements flag could not be found
933             * @throws SystemException if a system exception occurred
934             */
935            public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value)
936                    throws SystemException {
937                    return fetchByU_E_V(userId, entryId, value, true);
938            }
939    
940            /**
941             * Returns the announcements flag where userId = &#63; and entryId = &#63; and value = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
942             *
943             * @param userId the user ID
944             * @param entryId the entry ID
945             * @param value the value
946             * @param retrieveFromCache whether to use the finder cache
947             * @return the matching announcements flag, or <code>null</code> if a matching announcements flag could not be found
948             * @throws SystemException if a system exception occurred
949             */
950            public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value,
951                    boolean retrieveFromCache) throws SystemException {
952                    Object[] finderArgs = new Object[] { userId, entryId, value };
953    
954                    Object result = null;
955    
956                    if (retrieveFromCache) {
957                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_E_V,
958                                            finderArgs, this);
959                    }
960    
961                    if (result == null) {
962                            StringBundler query = new StringBundler(5);
963    
964                            query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
965    
966                            query.append(_FINDER_COLUMN_U_E_V_USERID_2);
967    
968                            query.append(_FINDER_COLUMN_U_E_V_ENTRYID_2);
969    
970                            query.append(_FINDER_COLUMN_U_E_V_VALUE_2);
971    
972                            query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
973    
974                            String sql = query.toString();
975    
976                            Session session = null;
977    
978                            try {
979                                    session = openSession();
980    
981                                    Query q = session.createQuery(sql);
982    
983                                    QueryPos qPos = QueryPos.getInstance(q);
984    
985                                    qPos.add(userId);
986    
987                                    qPos.add(entryId);
988    
989                                    qPos.add(value);
990    
991                                    List<AnnouncementsFlag> list = q.list();
992    
993                                    result = list;
994    
995                                    AnnouncementsFlag announcementsFlag = null;
996    
997                                    if (list.isEmpty()) {
998                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
999                                                    finderArgs, list);
1000                                    }
1001                                    else {
1002                                            announcementsFlag = list.get(0);
1003    
1004                                            cacheResult(announcementsFlag);
1005    
1006                                            if ((announcementsFlag.getUserId() != userId) ||
1007                                                            (announcementsFlag.getEntryId() != entryId) ||
1008                                                            (announcementsFlag.getValue() != value)) {
1009                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
1010                                                            finderArgs, announcementsFlag);
1011                                            }
1012                                    }
1013    
1014                                    return announcementsFlag;
1015                            }
1016                            catch (Exception e) {
1017                                    throw processException(e);
1018                            }
1019                            finally {
1020                                    if (result == null) {
1021                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V,
1022                                                    finderArgs);
1023                                    }
1024    
1025                                    closeSession(session);
1026                            }
1027                    }
1028                    else {
1029                            if (result instanceof List<?>) {
1030                                    return null;
1031                            }
1032                            else {
1033                                    return (AnnouncementsFlag)result;
1034                            }
1035                    }
1036            }
1037    
1038            /**
1039             * Returns all the announcements flags.
1040             *
1041             * @return the announcements flags
1042             * @throws SystemException if a system exception occurred
1043             */
1044            public List<AnnouncementsFlag> findAll() throws SystemException {
1045                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1046            }
1047    
1048            /**
1049             * Returns a range of all the announcements flags.
1050             *
1051             * <p>
1052             * 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.
1053             * </p>
1054             *
1055             * @param start the lower bound of the range of announcements flags
1056             * @param end the upper bound of the range of announcements flags (not inclusive)
1057             * @return the range of announcements flags
1058             * @throws SystemException if a system exception occurred
1059             */
1060            public List<AnnouncementsFlag> findAll(int start, int end)
1061                    throws SystemException {
1062                    return findAll(start, end, null);
1063            }
1064    
1065            /**
1066             * Returns an ordered range of all the announcements flags.
1067             *
1068             * <p>
1069             * 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.
1070             * </p>
1071             *
1072             * @param start the lower bound of the range of announcements flags
1073             * @param end the upper bound of the range of announcements flags (not inclusive)
1074             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1075             * @return the ordered range of announcements flags
1076             * @throws SystemException if a system exception occurred
1077             */
1078            public List<AnnouncementsFlag> findAll(int start, int end,
1079                    OrderByComparator orderByComparator) throws SystemException {
1080                    FinderPath finderPath = null;
1081                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1082    
1083                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1084                                    (orderByComparator == null)) {
1085                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1086                            finderArgs = FINDER_ARGS_EMPTY;
1087                    }
1088                    else {
1089                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1090                            finderArgs = new Object[] { start, end, orderByComparator };
1091                    }
1092    
1093                    List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(finderPath,
1094                                    finderArgs, this);
1095    
1096                    if (list == null) {
1097                            StringBundler query = null;
1098                            String sql = null;
1099    
1100                            if (orderByComparator != null) {
1101                                    query = new StringBundler(2 +
1102                                                    (orderByComparator.getOrderByFields().length * 3));
1103    
1104                                    query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG);
1105    
1106                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1107                                            orderByComparator);
1108    
1109                                    sql = query.toString();
1110                            }
1111                            else {
1112                                    sql = _SQL_SELECT_ANNOUNCEMENTSFLAG.concat(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
1113                            }
1114    
1115                            Session session = null;
1116    
1117                            try {
1118                                    session = openSession();
1119    
1120                                    Query q = session.createQuery(sql);
1121    
1122                                    if (orderByComparator == null) {
1123                                            list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1124                                                            getDialect(), start, end, false);
1125    
1126                                            Collections.sort(list);
1127                                    }
1128                                    else {
1129                                            list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1130                                                            getDialect(), start, end);
1131                                    }
1132                            }
1133                            catch (Exception e) {
1134                                    throw processException(e);
1135                            }
1136                            finally {
1137                                    if (list == null) {
1138                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1139                                    }
1140                                    else {
1141                                            cacheResult(list);
1142    
1143                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1144                                    }
1145    
1146                                    closeSession(session);
1147                            }
1148                    }
1149    
1150                    return list;
1151            }
1152    
1153            /**
1154             * Removes all the announcements flags where entryId = &#63; from the database.
1155             *
1156             * @param entryId the entry ID
1157             * @throws SystemException if a system exception occurred
1158             */
1159            public void removeByEntryId(long entryId) throws SystemException {
1160                    for (AnnouncementsFlag announcementsFlag : findByEntryId(entryId)) {
1161                            announcementsFlagPersistence.remove(announcementsFlag);
1162                    }
1163            }
1164    
1165            /**
1166             * Removes the announcements flag where userId = &#63; and entryId = &#63; and value = &#63; from the database.
1167             *
1168             * @param userId the user ID
1169             * @param entryId the entry ID
1170             * @param value the value
1171             * @throws SystemException if a system exception occurred
1172             */
1173            public void removeByU_E_V(long userId, long entryId, int value)
1174                    throws NoSuchFlagException, SystemException {
1175                    AnnouncementsFlag announcementsFlag = findByU_E_V(userId, entryId, value);
1176    
1177                    announcementsFlagPersistence.remove(announcementsFlag);
1178            }
1179    
1180            /**
1181             * Removes all the announcements flags from the database.
1182             *
1183             * @throws SystemException if a system exception occurred
1184             */
1185            public void removeAll() throws SystemException {
1186                    for (AnnouncementsFlag announcementsFlag : findAll()) {
1187                            announcementsFlagPersistence.remove(announcementsFlag);
1188                    }
1189            }
1190    
1191            /**
1192             * Returns the number of announcements flags where entryId = &#63;.
1193             *
1194             * @param entryId the entry ID
1195             * @return the number of matching announcements flags
1196             * @throws SystemException if a system exception occurred
1197             */
1198            public int countByEntryId(long entryId) throws SystemException {
1199                    Object[] finderArgs = new Object[] { entryId };
1200    
1201                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ENTRYID,
1202                                    finderArgs, this);
1203    
1204                    if (count == null) {
1205                            StringBundler query = new StringBundler(2);
1206    
1207                            query.append(_SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE);
1208    
1209                            query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
1210    
1211                            String sql = query.toString();
1212    
1213                            Session session = null;
1214    
1215                            try {
1216                                    session = openSession();
1217    
1218                                    Query q = session.createQuery(sql);
1219    
1220                                    QueryPos qPos = QueryPos.getInstance(q);
1221    
1222                                    qPos.add(entryId);
1223    
1224                                    count = (Long)q.uniqueResult();
1225                            }
1226                            catch (Exception e) {
1227                                    throw processException(e);
1228                            }
1229                            finally {
1230                                    if (count == null) {
1231                                            count = Long.valueOf(0);
1232                                    }
1233    
1234                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ENTRYID,
1235                                            finderArgs, count);
1236    
1237                                    closeSession(session);
1238                            }
1239                    }
1240    
1241                    return count.intValue();
1242            }
1243    
1244            /**
1245             * Returns the number of announcements flags where userId = &#63; and entryId = &#63; and value = &#63;.
1246             *
1247             * @param userId the user ID
1248             * @param entryId the entry ID
1249             * @param value the value
1250             * @return the number of matching announcements flags
1251             * @throws SystemException if a system exception occurred
1252             */
1253            public int countByU_E_V(long userId, long entryId, int value)
1254                    throws SystemException {
1255                    Object[] finderArgs = new Object[] { userId, entryId, value };
1256    
1257                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_E_V,
1258                                    finderArgs, this);
1259    
1260                    if (count == null) {
1261                            StringBundler query = new StringBundler(4);
1262    
1263                            query.append(_SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE);
1264    
1265                            query.append(_FINDER_COLUMN_U_E_V_USERID_2);
1266    
1267                            query.append(_FINDER_COLUMN_U_E_V_ENTRYID_2);
1268    
1269                            query.append(_FINDER_COLUMN_U_E_V_VALUE_2);
1270    
1271                            String sql = query.toString();
1272    
1273                            Session session = null;
1274    
1275                            try {
1276                                    session = openSession();
1277    
1278                                    Query q = session.createQuery(sql);
1279    
1280                                    QueryPos qPos = QueryPos.getInstance(q);
1281    
1282                                    qPos.add(userId);
1283    
1284                                    qPos.add(entryId);
1285    
1286                                    qPos.add(value);
1287    
1288                                    count = (Long)q.uniqueResult();
1289                            }
1290                            catch (Exception e) {
1291                                    throw processException(e);
1292                            }
1293                            finally {
1294                                    if (count == null) {
1295                                            count = Long.valueOf(0);
1296                                    }
1297    
1298                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_E_V,
1299                                            finderArgs, count);
1300    
1301                                    closeSession(session);
1302                            }
1303                    }
1304    
1305                    return count.intValue();
1306            }
1307    
1308            /**
1309             * Returns the number of announcements flags.
1310             *
1311             * @return the number of announcements flags
1312             * @throws SystemException if a system exception occurred
1313             */
1314            public int countAll() throws SystemException {
1315                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1316                                    FINDER_ARGS_EMPTY, this);
1317    
1318                    if (count == null) {
1319                            Session session = null;
1320    
1321                            try {
1322                                    session = openSession();
1323    
1324                                    Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSFLAG);
1325    
1326                                    count = (Long)q.uniqueResult();
1327                            }
1328                            catch (Exception e) {
1329                                    throw processException(e);
1330                            }
1331                            finally {
1332                                    if (count == null) {
1333                                            count = Long.valueOf(0);
1334                                    }
1335    
1336                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1337                                            FINDER_ARGS_EMPTY, count);
1338    
1339                                    closeSession(session);
1340                            }
1341                    }
1342    
1343                    return count.intValue();
1344            }
1345    
1346            /**
1347             * Initializes the announcements flag persistence.
1348             */
1349            public void afterPropertiesSet() {
1350                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1351                                            com.liferay.portal.util.PropsUtil.get(
1352                                                    "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsFlag")));
1353    
1354                    if (listenerClassNames.length > 0) {
1355                            try {
1356                                    List<ModelListener<AnnouncementsFlag>> listenersList = new ArrayList<ModelListener<AnnouncementsFlag>>();
1357    
1358                                    for (String listenerClassName : listenerClassNames) {
1359                                            listenersList.add((ModelListener<AnnouncementsFlag>)InstanceFactory.newInstance(
1360                                                            listenerClassName));
1361                                    }
1362    
1363                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1364                            }
1365                            catch (Exception e) {
1366                                    _log.error(e);
1367                            }
1368                    }
1369            }
1370    
1371            public void destroy() {
1372                    EntityCacheUtil.removeCache(AnnouncementsFlagImpl.class.getName());
1373                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1374                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1375            }
1376    
1377            @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1378            protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1379            @BeanReference(type = AnnouncementsEntryPersistence.class)
1380            protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1381            @BeanReference(type = AnnouncementsFlagPersistence.class)
1382            protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1383            @BeanReference(type = ResourcePersistence.class)
1384            protected ResourcePersistence resourcePersistence;
1385            @BeanReference(type = UserPersistence.class)
1386            protected UserPersistence userPersistence;
1387            private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag";
1388            private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE ";
1389            private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag";
1390            private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag WHERE ";
1391            private static final String _FINDER_COLUMN_ENTRYID_ENTRYID_2 = "announcementsFlag.entryId = ?";
1392            private static final String _FINDER_COLUMN_U_E_V_USERID_2 = "announcementsFlag.userId = ? AND ";
1393            private static final String _FINDER_COLUMN_U_E_V_ENTRYID_2 = "announcementsFlag.entryId = ? AND ";
1394            private static final String _FINDER_COLUMN_U_E_V_VALUE_2 = "announcementsFlag.value = ?";
1395            private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsFlag.";
1396            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsFlag exists with the primary key ";
1397            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsFlag exists with the key {";
1398            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1399            private static Log _log = LogFactoryUtil.getLog(AnnouncementsFlagPersistenceImpl.class);
1400            private static AnnouncementsFlag _nullAnnouncementsFlag = new AnnouncementsFlagImpl() {
1401                            @Override
1402                            public Object clone() {
1403                                    return this;
1404                            }
1405    
1406                            @Override
1407                            public CacheModel<AnnouncementsFlag> toCacheModel() {
1408                                    return _nullAnnouncementsFlagCacheModel;
1409                            }
1410                    };
1411    
1412            private static CacheModel<AnnouncementsFlag> _nullAnnouncementsFlagCacheModel =
1413                    new CacheModel<AnnouncementsFlag>() {
1414                            public AnnouncementsFlag toEntityModel() {
1415                                    return _nullAnnouncementsFlag;
1416                            }
1417                    };
1418    }