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