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