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