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