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