001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    
350                    else {
351                            if ((announcementsDeliveryModelImpl.getColumnBitmask() &
352                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
353                                    Object[] args = new Object[] {
354                                                    Long.valueOf(announcementsDeliveryModelImpl.getOriginalUserId())
355                                            };
356    
357                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
358                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
359                                            args);
360    
361                                    args = new Object[] {
362                                                    Long.valueOf(announcementsDeliveryModelImpl.getUserId())
363                                            };
364    
365                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
366                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
367                                            args);
368                            }
369                    }
370    
371                    EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
372                            AnnouncementsDeliveryImpl.class,
373                            announcementsDelivery.getPrimaryKey(), announcementsDelivery);
374    
375                    if (isNew) {
376                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
377                                    new Object[] {
378                                            Long.valueOf(announcementsDelivery.getUserId()),
379                                            
380                                    announcementsDelivery.getType()
381                                    }, announcementsDelivery);
382                    }
383                    else {
384                            if ((announcementsDeliveryModelImpl.getColumnBitmask() &
385                                            FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
386                                    Object[] args = new Object[] {
387                                                    Long.valueOf(announcementsDeliveryModelImpl.getOriginalUserId()),
388                                                    
389                                                    announcementsDeliveryModelImpl.getOriginalType()
390                                            };
391    
392                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
393    
394                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
395    
396                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
397                                            new Object[] {
398                                                    Long.valueOf(announcementsDelivery.getUserId()),
399                                                    
400                                            announcementsDelivery.getType()
401                                            }, announcementsDelivery);
402                            }
403                    }
404    
405                    return announcementsDelivery;
406            }
407    
408            protected AnnouncementsDelivery toUnwrappedModel(
409                    AnnouncementsDelivery announcementsDelivery) {
410                    if (announcementsDelivery instanceof AnnouncementsDeliveryImpl) {
411                            return announcementsDelivery;
412                    }
413    
414                    AnnouncementsDeliveryImpl announcementsDeliveryImpl = new AnnouncementsDeliveryImpl();
415    
416                    announcementsDeliveryImpl.setNew(announcementsDelivery.isNew());
417                    announcementsDeliveryImpl.setPrimaryKey(announcementsDelivery.getPrimaryKey());
418    
419                    announcementsDeliveryImpl.setDeliveryId(announcementsDelivery.getDeliveryId());
420                    announcementsDeliveryImpl.setCompanyId(announcementsDelivery.getCompanyId());
421                    announcementsDeliveryImpl.setUserId(announcementsDelivery.getUserId());
422                    announcementsDeliveryImpl.setType(announcementsDelivery.getType());
423                    announcementsDeliveryImpl.setEmail(announcementsDelivery.isEmail());
424                    announcementsDeliveryImpl.setSms(announcementsDelivery.isSms());
425                    announcementsDeliveryImpl.setWebsite(announcementsDelivery.isWebsite());
426    
427                    return announcementsDeliveryImpl;
428            }
429    
430            /**
431             * Returns the announcements delivery with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
432             *
433             * @param primaryKey the primary key of the announcements delivery
434             * @return the announcements delivery
435             * @throws com.liferay.portal.NoSuchModelException if a announcements delivery with the primary key could not be found
436             * @throws SystemException if a system exception occurred
437             */
438            @Override
439            public AnnouncementsDelivery findByPrimaryKey(Serializable primaryKey)
440                    throws NoSuchModelException, SystemException {
441                    return findByPrimaryKey(((Long)primaryKey).longValue());
442            }
443    
444            /**
445             * Returns the announcements delivery with the primary key or throws a {@link com.liferay.portlet.announcements.NoSuchDeliveryException} if it could not be found.
446             *
447             * @param deliveryId the primary key of the announcements delivery
448             * @return the announcements delivery
449             * @throws com.liferay.portlet.announcements.NoSuchDeliveryException if a announcements delivery with the primary key could not be found
450             * @throws SystemException if a system exception occurred
451             */
452            public AnnouncementsDelivery findByPrimaryKey(long deliveryId)
453                    throws NoSuchDeliveryException, SystemException {
454                    AnnouncementsDelivery announcementsDelivery = fetchByPrimaryKey(deliveryId);
455    
456                    if (announcementsDelivery == null) {
457                            if (_log.isWarnEnabled()) {
458                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + deliveryId);
459                            }
460    
461                            throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
462                                    deliveryId);
463                    }
464    
465                    return announcementsDelivery;
466            }
467    
468            /**
469             * Returns the announcements delivery with the primary key or returns <code>null</code> if it could not be found.
470             *
471             * @param primaryKey the primary key of the announcements delivery
472             * @return the announcements delivery, or <code>null</code> if a announcements delivery with the primary key could not be found
473             * @throws SystemException if a system exception occurred
474             */
475            @Override
476            public AnnouncementsDelivery fetchByPrimaryKey(Serializable primaryKey)
477                    throws SystemException {
478                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
479            }
480    
481            /**
482             * Returns the announcements delivery with the primary key or returns <code>null</code> if it could not be found.
483             *
484             * @param deliveryId the primary key of the announcements delivery
485             * @return the announcements delivery, or <code>null</code> if a announcements delivery with the primary key could not be found
486             * @throws SystemException if a system exception occurred
487             */
488            public AnnouncementsDelivery fetchByPrimaryKey(long deliveryId)
489                    throws SystemException {
490                    AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)EntityCacheUtil.getResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
491                                    AnnouncementsDeliveryImpl.class, deliveryId);
492    
493                    if (announcementsDelivery == _nullAnnouncementsDelivery) {
494                            return null;
495                    }
496    
497                    if (announcementsDelivery == null) {
498                            Session session = null;
499    
500                            boolean hasException = false;
501    
502                            try {
503                                    session = openSession();
504    
505                                    announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
506                                                    Long.valueOf(deliveryId));
507                            }
508                            catch (Exception e) {
509                                    hasException = true;
510    
511                                    throw processException(e);
512                            }
513                            finally {
514                                    if (announcementsDelivery != null) {
515                                            cacheResult(announcementsDelivery);
516                                    }
517                                    else if (!hasException) {
518                                            EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
519                                                    AnnouncementsDeliveryImpl.class, deliveryId,
520                                                    _nullAnnouncementsDelivery);
521                                    }
522    
523                                    closeSession(session);
524                            }
525                    }
526    
527                    return announcementsDelivery;
528            }
529    
530            /**
531             * Returns all the announcements deliveries where userId = &#63;.
532             *
533             * @param userId the user ID
534             * @return the matching announcements deliveries
535             * @throws SystemException if a system exception occurred
536             */
537            public List<AnnouncementsDelivery> findByUserId(long userId)
538                    throws SystemException {
539                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
540            }
541    
542            /**
543             * Returns a range of all the announcements deliveries where userId = &#63;.
544             *
545             * <p>
546             * 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.
547             * </p>
548             *
549             * @param userId the user ID
550             * @param start the lower bound of the range of announcements deliveries
551             * @param end the upper bound of the range of announcements deliveries (not inclusive)
552             * @return the range of matching announcements deliveries
553             * @throws SystemException if a system exception occurred
554             */
555            public List<AnnouncementsDelivery> findByUserId(long userId, int start,
556                    int end) throws SystemException {
557                    return findByUserId(userId, start, end, null);
558            }
559    
560            /**
561             * Returns an ordered range of all the announcements deliveries where userId = &#63;.
562             *
563             * <p>
564             * 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.
565             * </p>
566             *
567             * @param userId the user ID
568             * @param start the lower bound of the range of announcements deliveries
569             * @param end the upper bound of the range of announcements deliveries (not inclusive)
570             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
571             * @return the ordered range of matching announcements deliveries
572             * @throws SystemException if a system exception occurred
573             */
574            public List<AnnouncementsDelivery> findByUserId(long userId, int start,
575                    int end, OrderByComparator orderByComparator) throws SystemException {
576                    FinderPath finderPath = null;
577                    Object[] finderArgs = null;
578    
579                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
580                                    (orderByComparator == null)) {
581                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
582                            finderArgs = new Object[] { userId };
583                    }
584                    else {
585                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
586                            finderArgs = new Object[] { userId, start, end, orderByComparator };
587                    }
588    
589                    List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
590                                    finderArgs, this);
591    
592                    if ((list != null) && !list.isEmpty()) {
593                            for (AnnouncementsDelivery announcementsDelivery : list) {
594                                    if ((userId != announcementsDelivery.getUserId())) {
595                                            list = null;
596    
597                                            break;
598                                    }
599                            }
600                    }
601    
602                    if (list == null) {
603                            StringBundler query = null;
604    
605                            if (orderByComparator != null) {
606                                    query = new StringBundler(3 +
607                                                    (orderByComparator.getOrderByFields().length * 3));
608                            }
609                            else {
610                                    query = new StringBundler(2);
611                            }
612    
613                            query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
614    
615                            query.append(_FINDER_COLUMN_USERID_USERID_2);
616    
617                            if (orderByComparator != null) {
618                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
619                                            orderByComparator);
620                            }
621    
622                            String sql = query.toString();
623    
624                            Session session = null;
625    
626                            try {
627                                    session = openSession();
628    
629                                    Query q = session.createQuery(sql);
630    
631                                    QueryPos qPos = QueryPos.getInstance(q);
632    
633                                    qPos.add(userId);
634    
635                                    list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
636                                                    getDialect(), start, end);
637                            }
638                            catch (Exception e) {
639                                    throw processException(e);
640                            }
641                            finally {
642                                    if (list == null) {
643                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
644                                    }
645                                    else {
646                                            cacheResult(list);
647    
648                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
649                                    }
650    
651                                    closeSession(session);
652                            }
653                    }
654    
655                    return list;
656            }
657    
658            /**
659             * Returns the first announcements delivery in the ordered set where userId = &#63;.
660             *
661             * @param userId the user ID
662             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
663             * @return the first matching announcements delivery
664             * @throws com.liferay.portlet.announcements.NoSuchDeliveryException if a matching announcements delivery could not be found
665             * @throws SystemException if a system exception occurred
666             */
667            public AnnouncementsDelivery findByUserId_First(long userId,
668                    OrderByComparator orderByComparator)
669                    throws NoSuchDeliveryException, SystemException {
670                    AnnouncementsDelivery announcementsDelivery = fetchByUserId_First(userId,
671                                    orderByComparator);
672    
673                    if (announcementsDelivery != null) {
674                            return announcementsDelivery;
675                    }
676    
677                    StringBundler msg = new StringBundler(4);
678    
679                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
680    
681                    msg.append("userId=");
682                    msg.append(userId);
683    
684                    msg.append(StringPool.CLOSE_CURLY_BRACE);
685    
686                    throw new NoSuchDeliveryException(msg.toString());
687            }
688    
689            /**
690             * Returns the first announcements delivery in the ordered set where userId = &#63;.
691             *
692             * @param userId the user ID
693             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
694             * @return the first matching announcements delivery, or <code>null</code> if a matching announcements delivery could not be found
695             * @throws SystemException if a system exception occurred
696             */
697            public AnnouncementsDelivery fetchByUserId_First(long userId,
698                    OrderByComparator orderByComparator) throws SystemException {
699                    List<AnnouncementsDelivery> list = findByUserId(userId, 0, 1,
700                                    orderByComparator);
701    
702                    if (!list.isEmpty()) {
703                            return list.get(0);
704                    }
705    
706                    return null;
707            }
708    
709            /**
710             * Returns the last announcements delivery in the ordered set where userId = &#63;.
711             *
712             * @param userId the user ID
713             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
714             * @return the last matching announcements delivery
715             * @throws com.liferay.portlet.announcements.NoSuchDeliveryException if a matching announcements delivery could not be found
716             * @throws SystemException if a system exception occurred
717             */
718            public AnnouncementsDelivery findByUserId_Last(long userId,
719                    OrderByComparator orderByComparator)
720                    throws NoSuchDeliveryException, SystemException {
721                    AnnouncementsDelivery announcementsDelivery = fetchByUserId_Last(userId,
722                                    orderByComparator);
723    
724                    if (announcementsDelivery != null) {
725                            return announcementsDelivery;
726                    }
727    
728                    StringBundler msg = new StringBundler(4);
729    
730                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
731    
732                    msg.append("userId=");
733                    msg.append(userId);
734    
735                    msg.append(StringPool.CLOSE_CURLY_BRACE);
736    
737                    throw new NoSuchDeliveryException(msg.toString());
738            }
739    
740            /**
741             * Returns the last announcements delivery in the ordered set where userId = &#63;.
742             *
743             * @param userId the user ID
744             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
745             * @return the last matching announcements delivery, or <code>null</code> if a matching announcements delivery could not be found
746             * @throws SystemException if a system exception occurred
747             */
748            public AnnouncementsDelivery fetchByUserId_Last(long userId,
749                    OrderByComparator orderByComparator) throws SystemException {
750                    int count = countByUserId(userId);
751    
752                    List<AnnouncementsDelivery> list = findByUserId(userId, count - 1,
753                                    count, orderByComparator);
754    
755                    if (!list.isEmpty()) {
756                            return list.get(0);
757                    }
758    
759                    return null;
760            }
761    
762            /**
763             * Returns the announcements deliveries before and after the current announcements delivery in the ordered set where userId = &#63;.
764             *
765             * @param deliveryId the primary key of the current announcements delivery
766             * @param userId the user ID
767             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
768             * @return the previous, current, and next announcements delivery
769             * @throws com.liferay.portlet.announcements.NoSuchDeliveryException if a announcements delivery with the primary key could not be found
770             * @throws SystemException if a system exception occurred
771             */
772            public AnnouncementsDelivery[] findByUserId_PrevAndNext(long deliveryId,
773                    long userId, OrderByComparator orderByComparator)
774                    throws NoSuchDeliveryException, SystemException {
775                    AnnouncementsDelivery announcementsDelivery = findByPrimaryKey(deliveryId);
776    
777                    Session session = null;
778    
779                    try {
780                            session = openSession();
781    
782                            AnnouncementsDelivery[] array = new AnnouncementsDeliveryImpl[3];
783    
784                            array[0] = getByUserId_PrevAndNext(session, announcementsDelivery,
785                                            userId, orderByComparator, true);
786    
787                            array[1] = announcementsDelivery;
788    
789                            array[2] = getByUserId_PrevAndNext(session, announcementsDelivery,
790                                            userId, orderByComparator, false);
791    
792                            return array;
793                    }
794                    catch (Exception e) {
795                            throw processException(e);
796                    }
797                    finally {
798                            closeSession(session);
799                    }
800            }
801    
802            protected AnnouncementsDelivery getByUserId_PrevAndNext(Session session,
803                    AnnouncementsDelivery announcementsDelivery, long userId,
804                    OrderByComparator orderByComparator, boolean previous) {
805                    StringBundler query = null;
806    
807                    if (orderByComparator != null) {
808                            query = new StringBundler(6 +
809                                            (orderByComparator.getOrderByFields().length * 6));
810                    }
811                    else {
812                            query = new StringBundler(3);
813                    }
814    
815                    query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
816    
817                    query.append(_FINDER_COLUMN_USERID_USERID_2);
818    
819                    if (orderByComparator != null) {
820                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
821    
822                            if (orderByConditionFields.length > 0) {
823                                    query.append(WHERE_AND);
824                            }
825    
826                            for (int i = 0; i < orderByConditionFields.length; i++) {
827                                    query.append(_ORDER_BY_ENTITY_ALIAS);
828                                    query.append(orderByConditionFields[i]);
829    
830                                    if ((i + 1) < orderByConditionFields.length) {
831                                            if (orderByComparator.isAscending() ^ previous) {
832                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
833                                            }
834                                            else {
835                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
836                                            }
837                                    }
838                                    else {
839                                            if (orderByComparator.isAscending() ^ previous) {
840                                                    query.append(WHERE_GREATER_THAN);
841                                            }
842                                            else {
843                                                    query.append(WHERE_LESSER_THAN);
844                                            }
845                                    }
846                            }
847    
848                            query.append(ORDER_BY_CLAUSE);
849    
850                            String[] orderByFields = orderByComparator.getOrderByFields();
851    
852                            for (int i = 0; i < orderByFields.length; i++) {
853                                    query.append(_ORDER_BY_ENTITY_ALIAS);
854                                    query.append(orderByFields[i]);
855    
856                                    if ((i + 1) < orderByFields.length) {
857                                            if (orderByComparator.isAscending() ^ previous) {
858                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
859                                            }
860                                            else {
861                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
862                                            }
863                                    }
864                                    else {
865                                            if (orderByComparator.isAscending() ^ previous) {
866                                                    query.append(ORDER_BY_ASC);
867                                            }
868                                            else {
869                                                    query.append(ORDER_BY_DESC);
870                                            }
871                                    }
872                            }
873                    }
874    
875                    String sql = query.toString();
876    
877                    Query q = session.createQuery(sql);
878    
879                    q.setFirstResult(0);
880                    q.setMaxResults(2);
881    
882                    QueryPos qPos = QueryPos.getInstance(q);
883    
884                    qPos.add(userId);
885    
886                    if (orderByComparator != null) {
887                            Object[] values = orderByComparator.getOrderByConditionValues(announcementsDelivery);
888    
889                            for (Object value : values) {
890                                    qPos.add(value);
891                            }
892                    }
893    
894                    List<AnnouncementsDelivery> list = q.list();
895    
896                    if (list.size() == 2) {
897                            return list.get(1);
898                    }
899                    else {
900                            return null;
901                    }
902            }
903    
904            /**
905             * 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.
906             *
907             * @param userId the user ID
908             * @param type the type
909             * @return the matching announcements delivery
910             * @throws com.liferay.portlet.announcements.NoSuchDeliveryException if a matching announcements delivery could not be found
911             * @throws SystemException if a system exception occurred
912             */
913            public AnnouncementsDelivery findByU_T(long userId, String type)
914                    throws NoSuchDeliveryException, SystemException {
915                    AnnouncementsDelivery announcementsDelivery = fetchByU_T(userId, type);
916    
917                    if (announcementsDelivery == null) {
918                            StringBundler msg = new StringBundler(6);
919    
920                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
921    
922                            msg.append("userId=");
923                            msg.append(userId);
924    
925                            msg.append(", type=");
926                            msg.append(type);
927    
928                            msg.append(StringPool.CLOSE_CURLY_BRACE);
929    
930                            if (_log.isWarnEnabled()) {
931                                    _log.warn(msg.toString());
932                            }
933    
934                            throw new NoSuchDeliveryException(msg.toString());
935                    }
936    
937                    return announcementsDelivery;
938            }
939    
940            /**
941             * 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.
942             *
943             * @param userId the user ID
944             * @param type the type
945             * @return the matching announcements delivery, or <code>null</code> if a matching announcements delivery could not be found
946             * @throws SystemException if a system exception occurred
947             */
948            public AnnouncementsDelivery fetchByU_T(long userId, String type)
949                    throws SystemException {
950                    return fetchByU_T(userId, type, true);
951            }
952    
953            /**
954             * 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.
955             *
956             * @param userId the user ID
957             * @param type the type
958             * @param retrieveFromCache whether to use the finder cache
959             * @return the matching announcements delivery, or <code>null</code> if a matching announcements delivery could not be found
960             * @throws SystemException if a system exception occurred
961             */
962            public AnnouncementsDelivery fetchByU_T(long userId, String type,
963                    boolean retrieveFromCache) throws SystemException {
964                    Object[] finderArgs = new Object[] { userId, type };
965    
966                    Object result = null;
967    
968                    if (retrieveFromCache) {
969                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
970                                            finderArgs, this);
971                    }
972    
973                    if (result instanceof AnnouncementsDelivery) {
974                            AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)result;
975    
976                            if ((userId != announcementsDelivery.getUserId()) ||
977                                            !Validator.equals(type, announcementsDelivery.getType())) {
978                                    result = null;
979                            }
980                    }
981    
982                    if (result == null) {
983                            StringBundler query = new StringBundler(3);
984    
985                            query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
986    
987                            query.append(_FINDER_COLUMN_U_T_USERID_2);
988    
989                            if (type == null) {
990                                    query.append(_FINDER_COLUMN_U_T_TYPE_1);
991                            }
992                            else {
993                                    if (type.equals(StringPool.BLANK)) {
994                                            query.append(_FINDER_COLUMN_U_T_TYPE_3);
995                                    }
996                                    else {
997                                            query.append(_FINDER_COLUMN_U_T_TYPE_2);
998                                    }
999                            }
1000    
1001                            String sql = query.toString();
1002    
1003                            Session session = null;
1004    
1005                            try {
1006                                    session = openSession();
1007    
1008                                    Query q = session.createQuery(sql);
1009    
1010                                    QueryPos qPos = QueryPos.getInstance(q);
1011    
1012                                    qPos.add(userId);
1013    
1014                                    if (type != null) {
1015                                            qPos.add(type);
1016                                    }
1017    
1018                                    List<AnnouncementsDelivery> list = q.list();
1019    
1020                                    result = list;
1021    
1022                                    AnnouncementsDelivery announcementsDelivery = null;
1023    
1024                                    if (list.isEmpty()) {
1025                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
1026                                                    finderArgs, list);
1027                                    }
1028                                    else {
1029                                            announcementsDelivery = list.get(0);
1030    
1031                                            cacheResult(announcementsDelivery);
1032    
1033                                            if ((announcementsDelivery.getUserId() != userId) ||
1034                                                            (announcementsDelivery.getType() == null) ||
1035                                                            !announcementsDelivery.getType().equals(type)) {
1036                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
1037                                                            finderArgs, announcementsDelivery);
1038                                            }
1039                                    }
1040    
1041                                    return announcementsDelivery;
1042                            }
1043                            catch (Exception e) {
1044                                    throw processException(e);
1045                            }
1046                            finally {
1047                                    if (result == null) {
1048                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
1049                                                    finderArgs);
1050                                    }
1051    
1052                                    closeSession(session);
1053                            }
1054                    }
1055                    else {
1056                            if (result instanceof List<?>) {
1057                                    return null;
1058                            }
1059                            else {
1060                                    return (AnnouncementsDelivery)result;
1061                            }
1062                    }
1063            }
1064    
1065            /**
1066             * Returns all the announcements deliveries.
1067             *
1068             * @return the announcements deliveries
1069             * @throws SystemException if a system exception occurred
1070             */
1071            public List<AnnouncementsDelivery> findAll() throws SystemException {
1072                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1073            }
1074    
1075            /**
1076             * Returns a range of all the announcements deliveries.
1077             *
1078             * <p>
1079             * 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.
1080             * </p>
1081             *
1082             * @param start the lower bound of the range of announcements deliveries
1083             * @param end the upper bound of the range of announcements deliveries (not inclusive)
1084             * @return the range of announcements deliveries
1085             * @throws SystemException if a system exception occurred
1086             */
1087            public List<AnnouncementsDelivery> findAll(int start, int end)
1088                    throws SystemException {
1089                    return findAll(start, end, null);
1090            }
1091    
1092            /**
1093             * Returns an ordered range of all the announcements deliveries.
1094             *
1095             * <p>
1096             * 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.
1097             * </p>
1098             *
1099             * @param start the lower bound of the range of announcements deliveries
1100             * @param end the upper bound of the range of announcements deliveries (not inclusive)
1101             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1102             * @return the ordered range of announcements deliveries
1103             * @throws SystemException if a system exception occurred
1104             */
1105            public List<AnnouncementsDelivery> findAll(int start, int end,
1106                    OrderByComparator orderByComparator) throws SystemException {
1107                    FinderPath finderPath = null;
1108                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1109    
1110                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1111                                    (orderByComparator == null)) {
1112                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1113                            finderArgs = FINDER_ARGS_EMPTY;
1114                    }
1115                    else {
1116                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1117                            finderArgs = new Object[] { start, end, orderByComparator };
1118                    }
1119    
1120                    List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
1121                                    finderArgs, this);
1122    
1123                    if (list == null) {
1124                            StringBundler query = null;
1125                            String sql = null;
1126    
1127                            if (orderByComparator != null) {
1128                                    query = new StringBundler(2 +
1129                                                    (orderByComparator.getOrderByFields().length * 3));
1130    
1131                                    query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY);
1132    
1133                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1134                                            orderByComparator);
1135    
1136                                    sql = query.toString();
1137                            }
1138                            else {
1139                                    sql = _SQL_SELECT_ANNOUNCEMENTSDELIVERY;
1140                            }
1141    
1142                            Session session = null;
1143    
1144                            try {
1145                                    session = openSession();
1146    
1147                                    Query q = session.createQuery(sql);
1148    
1149                                    if (orderByComparator == null) {
1150                                            list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1151                                                            getDialect(), start, end, false);
1152    
1153                                            Collections.sort(list);
1154                                    }
1155                                    else {
1156                                            list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1157                                                            getDialect(), start, end);
1158                                    }
1159                            }
1160                            catch (Exception e) {
1161                                    throw processException(e);
1162                            }
1163                            finally {
1164                                    if (list == null) {
1165                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1166                                    }
1167                                    else {
1168                                            cacheResult(list);
1169    
1170                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1171                                    }
1172    
1173                                    closeSession(session);
1174                            }
1175                    }
1176    
1177                    return list;
1178            }
1179    
1180            /**
1181             * Removes all the announcements deliveries where userId = &#63; from the database.
1182             *
1183             * @param userId the user ID
1184             * @throws SystemException if a system exception occurred
1185             */
1186            public void removeByUserId(long userId) throws SystemException {
1187                    for (AnnouncementsDelivery announcementsDelivery : findByUserId(userId)) {
1188                            remove(announcementsDelivery);
1189                    }
1190            }
1191    
1192            /**
1193             * Removes the announcements delivery where userId = &#63; and type = &#63; from the database.
1194             *
1195             * @param userId the user ID
1196             * @param type the type
1197             * @return the announcements delivery that was removed
1198             * @throws SystemException if a system exception occurred
1199             */
1200            public AnnouncementsDelivery removeByU_T(long userId, String type)
1201                    throws NoSuchDeliveryException, SystemException {
1202                    AnnouncementsDelivery announcementsDelivery = findByU_T(userId, type);
1203    
1204                    return remove(announcementsDelivery);
1205            }
1206    
1207            /**
1208             * Removes all the announcements deliveries from the database.
1209             *
1210             * @throws SystemException if a system exception occurred
1211             */
1212            public void removeAll() throws SystemException {
1213                    for (AnnouncementsDelivery announcementsDelivery : findAll()) {
1214                            remove(announcementsDelivery);
1215                    }
1216            }
1217    
1218            /**
1219             * Returns the number of announcements deliveries where userId = &#63;.
1220             *
1221             * @param userId the user ID
1222             * @return the number of matching announcements deliveries
1223             * @throws SystemException if a system exception occurred
1224             */
1225            public int countByUserId(long userId) throws SystemException {
1226                    Object[] finderArgs = new Object[] { userId };
1227    
1228                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1229                                    finderArgs, this);
1230    
1231                    if (count == null) {
1232                            StringBundler query = new StringBundler(2);
1233    
1234                            query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
1235    
1236                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1237    
1238                            String sql = query.toString();
1239    
1240                            Session session = null;
1241    
1242                            try {
1243                                    session = openSession();
1244    
1245                                    Query q = session.createQuery(sql);
1246    
1247                                    QueryPos qPos = QueryPos.getInstance(q);
1248    
1249                                    qPos.add(userId);
1250    
1251                                    count = (Long)q.uniqueResult();
1252                            }
1253                            catch (Exception e) {
1254                                    throw processException(e);
1255                            }
1256                            finally {
1257                                    if (count == null) {
1258                                            count = Long.valueOf(0);
1259                                    }
1260    
1261                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1262                                            finderArgs, count);
1263    
1264                                    closeSession(session);
1265                            }
1266                    }
1267    
1268                    return count.intValue();
1269            }
1270    
1271            /**
1272             * Returns the number of announcements deliveries where userId = &#63; and type = &#63;.
1273             *
1274             * @param userId the user ID
1275             * @param type the type
1276             * @return the number of matching announcements deliveries
1277             * @throws SystemException if a system exception occurred
1278             */
1279            public int countByU_T(long userId, String type) throws SystemException {
1280                    Object[] finderArgs = new Object[] { userId, type };
1281    
1282                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
1283                                    finderArgs, this);
1284    
1285                    if (count == null) {
1286                            StringBundler query = new StringBundler(3);
1287    
1288                            query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
1289    
1290                            query.append(_FINDER_COLUMN_U_T_USERID_2);
1291    
1292                            if (type == null) {
1293                                    query.append(_FINDER_COLUMN_U_T_TYPE_1);
1294                            }
1295                            else {
1296                                    if (type.equals(StringPool.BLANK)) {
1297                                            query.append(_FINDER_COLUMN_U_T_TYPE_3);
1298                                    }
1299                                    else {
1300                                            query.append(_FINDER_COLUMN_U_T_TYPE_2);
1301                                    }
1302                            }
1303    
1304                            String sql = query.toString();
1305    
1306                            Session session = null;
1307    
1308                            try {
1309                                    session = openSession();
1310    
1311                                    Query q = session.createQuery(sql);
1312    
1313                                    QueryPos qPos = QueryPos.getInstance(q);
1314    
1315                                    qPos.add(userId);
1316    
1317                                    if (type != null) {
1318                                            qPos.add(type);
1319                                    }
1320    
1321                                    count = (Long)q.uniqueResult();
1322                            }
1323                            catch (Exception e) {
1324                                    throw processException(e);
1325                            }
1326                            finally {
1327                                    if (count == null) {
1328                                            count = Long.valueOf(0);
1329                                    }
1330    
1331                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
1332                                            count);
1333    
1334                                    closeSession(session);
1335                            }
1336                    }
1337    
1338                    return count.intValue();
1339            }
1340    
1341            /**
1342             * Returns the number of announcements deliveries.
1343             *
1344             * @return the number of announcements deliveries
1345             * @throws SystemException if a system exception occurred
1346             */
1347            public int countAll() throws SystemException {
1348                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1349                                    FINDER_ARGS_EMPTY, this);
1350    
1351                    if (count == null) {
1352                            Session session = null;
1353    
1354                            try {
1355                                    session = openSession();
1356    
1357                                    Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSDELIVERY);
1358    
1359                                    count = (Long)q.uniqueResult();
1360                            }
1361                            catch (Exception e) {
1362                                    throw processException(e);
1363                            }
1364                            finally {
1365                                    if (count == null) {
1366                                            count = Long.valueOf(0);
1367                                    }
1368    
1369                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1370                                            FINDER_ARGS_EMPTY, count);
1371    
1372                                    closeSession(session);
1373                            }
1374                    }
1375    
1376                    return count.intValue();
1377            }
1378    
1379            /**
1380             * Initializes the announcements delivery persistence.
1381             */
1382            public void afterPropertiesSet() {
1383                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1384                                            com.liferay.portal.util.PropsUtil.get(
1385                                                    "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsDelivery")));
1386    
1387                    if (listenerClassNames.length > 0) {
1388                            try {
1389                                    List<ModelListener<AnnouncementsDelivery>> listenersList = new ArrayList<ModelListener<AnnouncementsDelivery>>();
1390    
1391                                    for (String listenerClassName : listenerClassNames) {
1392                                            listenersList.add((ModelListener<AnnouncementsDelivery>)InstanceFactory.newInstance(
1393                                                            listenerClassName));
1394                                    }
1395    
1396                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1397                            }
1398                            catch (Exception e) {
1399                                    _log.error(e);
1400                            }
1401                    }
1402            }
1403    
1404            public void destroy() {
1405                    EntityCacheUtil.removeCache(AnnouncementsDeliveryImpl.class.getName());
1406                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1407                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1408            }
1409    
1410            @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1411            protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1412            @BeanReference(type = AnnouncementsEntryPersistence.class)
1413            protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1414            @BeanReference(type = AnnouncementsFlagPersistence.class)
1415            protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1416            @BeanReference(type = ResourcePersistence.class)
1417            protected ResourcePersistence resourcePersistence;
1418            @BeanReference(type = UserPersistence.class)
1419            protected UserPersistence userPersistence;
1420            private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery";
1421            private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1422            private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery";
1423            private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1424            private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsDelivery.userId = ?";
1425            private static final String _FINDER_COLUMN_U_T_USERID_2 = "announcementsDelivery.userId = ? AND ";
1426            private static final String _FINDER_COLUMN_U_T_TYPE_1 = "announcementsDelivery.type IS NULL";
1427            private static final String _FINDER_COLUMN_U_T_TYPE_2 = "announcementsDelivery.type = ?";
1428            private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(announcementsDelivery.type IS NULL OR announcementsDelivery.type = ?)";
1429            private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsDelivery.";
1430            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsDelivery exists with the primary key ";
1431            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsDelivery exists with the key {";
1432            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1433            private static Log _log = LogFactoryUtil.getLog(AnnouncementsDeliveryPersistenceImpl.class);
1434            private static AnnouncementsDelivery _nullAnnouncementsDelivery = new AnnouncementsDeliveryImpl() {
1435                            @Override
1436                            public Object clone() {
1437                                    return this;
1438                            }
1439    
1440                            @Override
1441                            public CacheModel<AnnouncementsDelivery> toCacheModel() {
1442                                    return _nullAnnouncementsDeliveryCacheModel;
1443                            }
1444                    };
1445    
1446            private static CacheModel<AnnouncementsDelivery> _nullAnnouncementsDeliveryCacheModel =
1447                    new CacheModel<AnnouncementsDelivery>() {
1448                            public AnnouncementsDelivery toEntityModel() {
1449                                    return _nullAnnouncementsDelivery;
1450                            }
1451                    };
1452    }