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