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            /**
845             * Caches the announcements delivery in the entity cache if it is enabled.
846             *
847             * @param announcementsDelivery the announcements delivery
848             */
849            @Override
850            public void cacheResult(AnnouncementsDelivery announcementsDelivery) {
851                    EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
852                            AnnouncementsDeliveryImpl.class,
853                            announcementsDelivery.getPrimaryKey(), announcementsDelivery);
854    
855                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
856                            new Object[] {
857                                    announcementsDelivery.getUserId(),
858                                    announcementsDelivery.getType()
859                            }, announcementsDelivery);
860    
861                    announcementsDelivery.resetOriginalValues();
862            }
863    
864            /**
865             * Caches the announcements deliveries in the entity cache if it is enabled.
866             *
867             * @param announcementsDeliveries the announcements deliveries
868             */
869            @Override
870            public void cacheResult(List<AnnouncementsDelivery> announcementsDeliveries) {
871                    for (AnnouncementsDelivery announcementsDelivery : announcementsDeliveries) {
872                            if (EntityCacheUtil.getResult(
873                                                    AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
874                                                    AnnouncementsDeliveryImpl.class,
875                                                    announcementsDelivery.getPrimaryKey()) == null) {
876                                    cacheResult(announcementsDelivery);
877                            }
878                            else {
879                                    announcementsDelivery.resetOriginalValues();
880                            }
881                    }
882            }
883    
884            /**
885             * Clears the cache for all announcements deliveries.
886             *
887             * <p>
888             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
889             * </p>
890             */
891            @Override
892            public void clearCache() {
893                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
894                            CacheRegistryUtil.clear(AnnouncementsDeliveryImpl.class.getName());
895                    }
896    
897                    EntityCacheUtil.clearCache(AnnouncementsDeliveryImpl.class.getName());
898    
899                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
900                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
901                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
902            }
903    
904            /**
905             * Clears the cache for the announcements delivery.
906             *
907             * <p>
908             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
909             * </p>
910             */
911            @Override
912            public void clearCache(AnnouncementsDelivery announcementsDelivery) {
913                    EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
914                            AnnouncementsDeliveryImpl.class,
915                            announcementsDelivery.getPrimaryKey());
916    
917                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
918                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
919    
920                    clearUniqueFindersCache(announcementsDelivery);
921            }
922    
923            @Override
924            public void clearCache(List<AnnouncementsDelivery> announcementsDeliveries) {
925                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
926                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
927    
928                    for (AnnouncementsDelivery announcementsDelivery : announcementsDeliveries) {
929                            EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
930                                    AnnouncementsDeliveryImpl.class,
931                                    announcementsDelivery.getPrimaryKey());
932    
933                            clearUniqueFindersCache(announcementsDelivery);
934                    }
935            }
936    
937            protected void cacheUniqueFindersCache(
938                    AnnouncementsDelivery announcementsDelivery) {
939                    if (announcementsDelivery.isNew()) {
940                            Object[] args = new Object[] {
941                                            announcementsDelivery.getUserId(),
942                                            announcementsDelivery.getType()
943                                    };
944    
945                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
946                                    Long.valueOf(1));
947                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
948                                    announcementsDelivery);
949                    }
950                    else {
951                            AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
952    
953                            if ((announcementsDeliveryModelImpl.getColumnBitmask() &
954                                            FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
955                                    Object[] args = new Object[] {
956                                                    announcementsDelivery.getUserId(),
957                                                    announcementsDelivery.getType()
958                                            };
959    
960                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
961                                            Long.valueOf(1));
962                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
963                                            announcementsDelivery);
964                            }
965                    }
966            }
967    
968            protected void clearUniqueFindersCache(
969                    AnnouncementsDelivery announcementsDelivery) {
970                    AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
971    
972                    Object[] args = new Object[] {
973                                    announcementsDelivery.getUserId(),
974                                    announcementsDelivery.getType()
975                            };
976    
977                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
978                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
979    
980                    if ((announcementsDeliveryModelImpl.getColumnBitmask() &
981                                    FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
982                            args = new Object[] {
983                                            announcementsDeliveryModelImpl.getOriginalUserId(),
984                                            announcementsDeliveryModelImpl.getOriginalType()
985                                    };
986    
987                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
988                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
989                    }
990            }
991    
992            /**
993             * Creates a new announcements delivery with the primary key. Does not add the announcements delivery to the database.
994             *
995             * @param deliveryId the primary key for the new announcements delivery
996             * @return the new announcements delivery
997             */
998            @Override
999            public AnnouncementsDelivery create(long deliveryId) {
1000                    AnnouncementsDelivery announcementsDelivery = new AnnouncementsDeliveryImpl();
1001    
1002                    announcementsDelivery.setNew(true);
1003                    announcementsDelivery.setPrimaryKey(deliveryId);
1004    
1005                    return announcementsDelivery;
1006            }
1007    
1008            /**
1009             * Removes the announcements delivery with the primary key from the database. Also notifies the appropriate model listeners.
1010             *
1011             * @param deliveryId the primary key of the announcements delivery
1012             * @return the announcements delivery that was removed
1013             * @throws com.liferay.portlet.announcements.NoSuchDeliveryException if a announcements delivery with the primary key could not be found
1014             * @throws SystemException if a system exception occurred
1015             */
1016            @Override
1017            public AnnouncementsDelivery remove(long deliveryId)
1018                    throws NoSuchDeliveryException, SystemException {
1019                    return remove((Serializable)deliveryId);
1020            }
1021    
1022            /**
1023             * Removes the announcements delivery with the primary key from the database. Also notifies the appropriate model listeners.
1024             *
1025             * @param primaryKey the primary key of the announcements delivery
1026             * @return the announcements delivery that was removed
1027             * @throws com.liferay.portlet.announcements.NoSuchDeliveryException if a announcements delivery with the primary key could not be found
1028             * @throws SystemException if a system exception occurred
1029             */
1030            @Override
1031            public AnnouncementsDelivery remove(Serializable primaryKey)
1032                    throws NoSuchDeliveryException, SystemException {
1033                    Session session = null;
1034    
1035                    try {
1036                            session = openSession();
1037    
1038                            AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
1039                                            primaryKey);
1040    
1041                            if (announcementsDelivery == null) {
1042                                    if (_log.isWarnEnabled()) {
1043                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1044                                    }
1045    
1046                                    throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1047                                            primaryKey);
1048                            }
1049    
1050                            return remove(announcementsDelivery);
1051                    }
1052                    catch (NoSuchDeliveryException nsee) {
1053                            throw nsee;
1054                    }
1055                    catch (Exception e) {
1056                            throw processException(e);
1057                    }
1058                    finally {
1059                            closeSession(session);
1060                    }
1061            }
1062    
1063            @Override
1064            protected AnnouncementsDelivery removeImpl(
1065                    AnnouncementsDelivery announcementsDelivery) throws SystemException {
1066                    announcementsDelivery = toUnwrappedModel(announcementsDelivery);
1067    
1068                    Session session = null;
1069    
1070                    try {
1071                            session = openSession();
1072    
1073                            if (!session.contains(announcementsDelivery)) {
1074                                    announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
1075                                                    announcementsDelivery.getPrimaryKeyObj());
1076                            }
1077    
1078                            if (announcementsDelivery != null) {
1079                                    session.delete(announcementsDelivery);
1080                            }
1081                    }
1082                    catch (Exception e) {
1083                            throw processException(e);
1084                    }
1085                    finally {
1086                            closeSession(session);
1087                    }
1088    
1089                    if (announcementsDelivery != null) {
1090                            clearCache(announcementsDelivery);
1091                    }
1092    
1093                    return announcementsDelivery;
1094            }
1095    
1096            @Override
1097            public AnnouncementsDelivery updateImpl(
1098                    com.liferay.portlet.announcements.model.AnnouncementsDelivery announcementsDelivery)
1099                    throws SystemException {
1100                    announcementsDelivery = toUnwrappedModel(announcementsDelivery);
1101    
1102                    boolean isNew = announcementsDelivery.isNew();
1103    
1104                    AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
1105    
1106                    Session session = null;
1107    
1108                    try {
1109                            session = openSession();
1110    
1111                            if (announcementsDelivery.isNew()) {
1112                                    session.save(announcementsDelivery);
1113    
1114                                    announcementsDelivery.setNew(false);
1115                            }
1116                            else {
1117                                    session.merge(announcementsDelivery);
1118                            }
1119                    }
1120                    catch (Exception e) {
1121                            throw processException(e);
1122                    }
1123                    finally {
1124                            closeSession(session);
1125                    }
1126    
1127                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1128    
1129                    if (isNew || !AnnouncementsDeliveryModelImpl.COLUMN_BITMASK_ENABLED) {
1130                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1131                    }
1132    
1133                    else {
1134                            if ((announcementsDeliveryModelImpl.getColumnBitmask() &
1135                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1136                                    Object[] args = new Object[] {
1137                                                    announcementsDeliveryModelImpl.getOriginalUserId()
1138                                            };
1139    
1140                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1141                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1142                                            args);
1143    
1144                                    args = new Object[] { announcementsDeliveryModelImpl.getUserId() };
1145    
1146                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1147                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1148                                            args);
1149                            }
1150                    }
1151    
1152                    EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1153                            AnnouncementsDeliveryImpl.class,
1154                            announcementsDelivery.getPrimaryKey(), announcementsDelivery);
1155    
1156                    clearUniqueFindersCache(announcementsDelivery);
1157                    cacheUniqueFindersCache(announcementsDelivery);
1158    
1159                    return announcementsDelivery;
1160            }
1161    
1162            protected AnnouncementsDelivery toUnwrappedModel(
1163                    AnnouncementsDelivery announcementsDelivery) {
1164                    if (announcementsDelivery instanceof AnnouncementsDeliveryImpl) {
1165                            return announcementsDelivery;
1166                    }
1167    
1168                    AnnouncementsDeliveryImpl announcementsDeliveryImpl = new AnnouncementsDeliveryImpl();
1169    
1170                    announcementsDeliveryImpl.setNew(announcementsDelivery.isNew());
1171                    announcementsDeliveryImpl.setPrimaryKey(announcementsDelivery.getPrimaryKey());
1172    
1173                    announcementsDeliveryImpl.setDeliveryId(announcementsDelivery.getDeliveryId());
1174                    announcementsDeliveryImpl.setCompanyId(announcementsDelivery.getCompanyId());
1175                    announcementsDeliveryImpl.setUserId(announcementsDelivery.getUserId());
1176                    announcementsDeliveryImpl.setType(announcementsDelivery.getType());
1177                    announcementsDeliveryImpl.setEmail(announcementsDelivery.isEmail());
1178                    announcementsDeliveryImpl.setSms(announcementsDelivery.isSms());
1179                    announcementsDeliveryImpl.setWebsite(announcementsDelivery.isWebsite());
1180    
1181                    return announcementsDeliveryImpl;
1182            }
1183    
1184            /**
1185             * Returns the announcements delivery with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1186             *
1187             * @param primaryKey the primary key of the announcements delivery
1188             * @return the announcements delivery
1189             * @throws com.liferay.portlet.announcements.NoSuchDeliveryException if a announcements delivery with the primary key could not be found
1190             * @throws SystemException if a system exception occurred
1191             */
1192            @Override
1193            public AnnouncementsDelivery findByPrimaryKey(Serializable primaryKey)
1194                    throws NoSuchDeliveryException, SystemException {
1195                    AnnouncementsDelivery announcementsDelivery = fetchByPrimaryKey(primaryKey);
1196    
1197                    if (announcementsDelivery == null) {
1198                            if (_log.isWarnEnabled()) {
1199                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1200                            }
1201    
1202                            throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1203                                    primaryKey);
1204                    }
1205    
1206                    return announcementsDelivery;
1207            }
1208    
1209            /**
1210             * Returns the announcements delivery with the primary key or throws a {@link com.liferay.portlet.announcements.NoSuchDeliveryException} if it could not be found.
1211             *
1212             * @param deliveryId the primary key of the announcements delivery
1213             * @return the announcements delivery
1214             * @throws com.liferay.portlet.announcements.NoSuchDeliveryException if a announcements delivery with the primary key could not be found
1215             * @throws SystemException if a system exception occurred
1216             */
1217            @Override
1218            public AnnouncementsDelivery findByPrimaryKey(long deliveryId)
1219                    throws NoSuchDeliveryException, SystemException {
1220                    return findByPrimaryKey((Serializable)deliveryId);
1221            }
1222    
1223            /**
1224             * Returns the announcements delivery with the primary key or returns <code>null</code> if it could not be found.
1225             *
1226             * @param primaryKey the primary key of the announcements delivery
1227             * @return the announcements delivery, or <code>null</code> if a announcements delivery with the primary key could not be found
1228             * @throws SystemException if a system exception occurred
1229             */
1230            @Override
1231            public AnnouncementsDelivery fetchByPrimaryKey(Serializable primaryKey)
1232                    throws SystemException {
1233                    AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)EntityCacheUtil.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                                            EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1254                                                    AnnouncementsDeliveryImpl.class, primaryKey,
1255                                                    _nullAnnouncementsDelivery);
1256                                    }
1257                            }
1258                            catch (Exception e) {
1259                                    EntityCacheUtil.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             * @throws SystemException if a system exception occurred
1278             */
1279            @Override
1280            public AnnouncementsDelivery fetchByPrimaryKey(long deliveryId)
1281                    throws SystemException {
1282                    return fetchByPrimaryKey((Serializable)deliveryId);
1283            }
1284    
1285            /**
1286             * Returns all the announcements deliveries.
1287             *
1288             * @return the announcements deliveries
1289             * @throws SystemException if a system exception occurred
1290             */
1291            @Override
1292            public List<AnnouncementsDelivery> findAll() throws SystemException {
1293                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1294            }
1295    
1296            /**
1297             * Returns a range of all the announcements deliveries.
1298             *
1299             * <p>
1300             * 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.
1301             * </p>
1302             *
1303             * @param start the lower bound of the range of announcements deliveries
1304             * @param end the upper bound of the range of announcements deliveries (not inclusive)
1305             * @return the range of announcements deliveries
1306             * @throws SystemException if a system exception occurred
1307             */
1308            @Override
1309            public List<AnnouncementsDelivery> findAll(int start, int end)
1310                    throws SystemException {
1311                    return findAll(start, end, null);
1312            }
1313    
1314            /**
1315             * Returns an ordered range of all the announcements deliveries.
1316             *
1317             * <p>
1318             * 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.
1319             * </p>
1320             *
1321             * @param start the lower bound of the range of announcements deliveries
1322             * @param end the upper bound of the range of announcements deliveries (not inclusive)
1323             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1324             * @return the ordered range of announcements deliveries
1325             * @throws SystemException if a system exception occurred
1326             */
1327            @Override
1328            public List<AnnouncementsDelivery> findAll(int start, int end,
1329                    OrderByComparator orderByComparator) throws SystemException {
1330                    boolean pagination = true;
1331                    FinderPath finderPath = null;
1332                    Object[] finderArgs = null;
1333    
1334                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1335                                    (orderByComparator == null)) {
1336                            pagination = false;
1337                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1338                            finderArgs = FINDER_ARGS_EMPTY;
1339                    }
1340                    else {
1341                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1342                            finderArgs = new Object[] { start, end, orderByComparator };
1343                    }
1344    
1345                    List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
1346                                    finderArgs, this);
1347    
1348                    if (list == null) {
1349                            StringBundler query = null;
1350                            String sql = null;
1351    
1352                            if (orderByComparator != null) {
1353                                    query = new StringBundler(2 +
1354                                                    (orderByComparator.getOrderByFields().length * 3));
1355    
1356                                    query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY);
1357    
1358                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1359                                            orderByComparator);
1360    
1361                                    sql = query.toString();
1362                            }
1363                            else {
1364                                    sql = _SQL_SELECT_ANNOUNCEMENTSDELIVERY;
1365    
1366                                    if (pagination) {
1367                                            sql = sql.concat(AnnouncementsDeliveryModelImpl.ORDER_BY_JPQL);
1368                                    }
1369                            }
1370    
1371                            Session session = null;
1372    
1373                            try {
1374                                    session = openSession();
1375    
1376                                    Query q = session.createQuery(sql);
1377    
1378                                    if (!pagination) {
1379                                            list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1380                                                            getDialect(), start, end, false);
1381    
1382                                            Collections.sort(list);
1383    
1384                                            list = new UnmodifiableList<AnnouncementsDelivery>(list);
1385                                    }
1386                                    else {
1387                                            list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1388                                                            getDialect(), start, end);
1389                                    }
1390    
1391                                    cacheResult(list);
1392    
1393                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1394                            }
1395                            catch (Exception e) {
1396                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1397    
1398                                    throw processException(e);
1399                            }
1400                            finally {
1401                                    closeSession(session);
1402                            }
1403                    }
1404    
1405                    return list;
1406            }
1407    
1408            /**
1409             * Removes all the announcements deliveries from the database.
1410             *
1411             * @throws SystemException if a system exception occurred
1412             */
1413            @Override
1414            public void removeAll() throws SystemException {
1415                    for (AnnouncementsDelivery announcementsDelivery : findAll()) {
1416                            remove(announcementsDelivery);
1417                    }
1418            }
1419    
1420            /**
1421             * Returns the number of announcements deliveries.
1422             *
1423             * @return the number of announcements deliveries
1424             * @throws SystemException if a system exception occurred
1425             */
1426            @Override
1427            public int countAll() throws SystemException {
1428                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1429                                    FINDER_ARGS_EMPTY, this);
1430    
1431                    if (count == null) {
1432                            Session session = null;
1433    
1434                            try {
1435                                    session = openSession();
1436    
1437                                    Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSDELIVERY);
1438    
1439                                    count = (Long)q.uniqueResult();
1440    
1441                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1442                                            FINDER_ARGS_EMPTY, count);
1443                            }
1444                            catch (Exception e) {
1445                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1446                                            FINDER_ARGS_EMPTY);
1447    
1448                                    throw processException(e);
1449                            }
1450                            finally {
1451                                    closeSession(session);
1452                            }
1453                    }
1454    
1455                    return count.intValue();
1456            }
1457    
1458            @Override
1459            protected Set<String> getBadColumnNames() {
1460                    return _badColumnNames;
1461            }
1462    
1463            /**
1464             * Initializes the announcements delivery persistence.
1465             */
1466            public void afterPropertiesSet() {
1467                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1468                                            com.liferay.portal.util.PropsUtil.get(
1469                                                    "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsDelivery")));
1470    
1471                    if (listenerClassNames.length > 0) {
1472                            try {
1473                                    List<ModelListener<AnnouncementsDelivery>> listenersList = new ArrayList<ModelListener<AnnouncementsDelivery>>();
1474    
1475                                    for (String listenerClassName : listenerClassNames) {
1476                                            listenersList.add((ModelListener<AnnouncementsDelivery>)InstanceFactory.newInstance(
1477                                                            getClassLoader(), listenerClassName));
1478                                    }
1479    
1480                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1481                            }
1482                            catch (Exception e) {
1483                                    _log.error(e);
1484                            }
1485                    }
1486            }
1487    
1488            public void destroy() {
1489                    EntityCacheUtil.removeCache(AnnouncementsDeliveryImpl.class.getName());
1490                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1491                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1492                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1493            }
1494    
1495            private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery";
1496            private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1497            private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery";
1498            private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1499            private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsDelivery.";
1500            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsDelivery exists with the primary key ";
1501            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsDelivery exists with the key {";
1502            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1503            private static Log _log = LogFactoryUtil.getLog(AnnouncementsDeliveryPersistenceImpl.class);
1504            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1505                                    "type"
1506                            });
1507            private static AnnouncementsDelivery _nullAnnouncementsDelivery = new AnnouncementsDeliveryImpl() {
1508                            @Override
1509                            public Object clone() {
1510                                    return this;
1511                            }
1512    
1513                            @Override
1514                            public CacheModel<AnnouncementsDelivery> toCacheModel() {
1515                                    return _nullAnnouncementsDeliveryCacheModel;
1516                            }
1517                    };
1518    
1519            private static CacheModel<AnnouncementsDelivery> _nullAnnouncementsDeliveryCacheModel =
1520                    new CacheModel<AnnouncementsDelivery>() {
1521                            @Override
1522                            public AnnouncementsDelivery toEntityModel() {
1523                                    return _nullAnnouncementsDelivery;
1524                            }
1525                    };
1526    }