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