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