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