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