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