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