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.NoSuchUserNotificationEventException;
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.SetUtil;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.MVCCModel;
040    import com.liferay.portal.model.UserNotificationEvent;
041    import com.liferay.portal.model.impl.UserNotificationEventImpl;
042    import com.liferay.portal.model.impl.UserNotificationEventModelImpl;
043    import com.liferay.portal.service.persistence.CompanyProvider;
044    import com.liferay.portal.service.persistence.UserNotificationEventPersistence;
045    
046    import java.io.Serializable;
047    
048    import java.util.Collections;
049    import java.util.HashMap;
050    import java.util.HashSet;
051    import java.util.Iterator;
052    import java.util.List;
053    import java.util.Map;
054    import java.util.Set;
055    
056    /**
057     * The persistence implementation for the user notification event service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see UserNotificationEventPersistence
065     * @see com.liferay.portal.service.persistence.UserNotificationEventUtil
066     * @generated
067     */
068    @ProviderType
069    public class UserNotificationEventPersistenceImpl extends BasePersistenceImpl<UserNotificationEvent>
070            implements UserNotificationEventPersistence {
071            /*
072             * NOTE FOR DEVELOPERS:
073             *
074             * Never modify or reference this class directly. Always use {@link UserNotificationEventUtil} to access the user notification event persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
075             */
076            public static final String FINDER_CLASS_NAME_ENTITY = UserNotificationEventImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List1";
079            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List2";
081            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
082                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
083                            UserNotificationEventImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
086                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
087                            UserNotificationEventImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
090                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
092            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
093                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
094                            UserNotificationEventImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
096                            new String[] {
097                                    String.class.getName(),
098                                    
099                            Integer.class.getName(), Integer.class.getName(),
100                                    OrderByComparator.class.getName()
101                            });
102            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
103                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
104                            UserNotificationEventImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
106                            new String[] { String.class.getName() },
107                            UserNotificationEventModelImpl.UUID_COLUMN_BITMASK |
108                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
109            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
110                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
112                            new String[] { String.class.getName() });
113    
114            /**
115             * Returns all the user notification events where uuid = &#63;.
116             *
117             * @param uuid the uuid
118             * @return the matching user notification events
119             */
120            @Override
121            public List<UserNotificationEvent> findByUuid(String uuid) {
122                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123            }
124    
125            /**
126             * Returns a range of all the user notification events where uuid = &#63;.
127             *
128             * <p>
129             * 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 UserNotificationEventModelImpl}. 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.
130             * </p>
131             *
132             * @param uuid the uuid
133             * @param start the lower bound of the range of user notification events
134             * @param end the upper bound of the range of user notification events (not inclusive)
135             * @return the range of matching user notification events
136             */
137            @Override
138            public List<UserNotificationEvent> findByUuid(String uuid, int start,
139                    int end) {
140                    return findByUuid(uuid, start, end, null);
141            }
142    
143            /**
144             * Returns an ordered range of all the user notification events where uuid = &#63;.
145             *
146             * <p>
147             * 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 UserNotificationEventModelImpl}. 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.
148             * </p>
149             *
150             * @param uuid the uuid
151             * @param start the lower bound of the range of user notification events
152             * @param end the upper bound of the range of user notification events (not inclusive)
153             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
154             * @return the ordered range of matching user notification events
155             */
156            @Override
157            public List<UserNotificationEvent> findByUuid(String uuid, int start,
158                    int end, OrderByComparator<UserNotificationEvent> orderByComparator) {
159                    return findByUuid(uuid, start, end, orderByComparator, true);
160            }
161    
162            /**
163             * Returns an ordered range of all the user notification events where uuid = &#63;.
164             *
165             * <p>
166             * 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 UserNotificationEventModelImpl}. 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.
167             * </p>
168             *
169             * @param uuid the uuid
170             * @param start the lower bound of the range of user notification events
171             * @param end the upper bound of the range of user notification events (not inclusive)
172             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
173             * @param retrieveFromCache whether to retrieve from the finder cache
174             * @return the ordered range of matching user notification events
175             */
176            @Override
177            public List<UserNotificationEvent> findByUuid(String uuid, int start,
178                    int end, OrderByComparator<UserNotificationEvent> orderByComparator,
179                    boolean retrieveFromCache) {
180                    boolean pagination = true;
181                    FinderPath finderPath = null;
182                    Object[] finderArgs = null;
183    
184                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
185                                    (orderByComparator == null)) {
186                            pagination = false;
187                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
188                            finderArgs = new Object[] { uuid };
189                    }
190                    else {
191                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
192                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
193                    }
194    
195                    List<UserNotificationEvent> list = null;
196    
197                    if (retrieveFromCache) {
198                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
199                                            finderArgs, this);
200    
201                            if ((list != null) && !list.isEmpty()) {
202                                    for (UserNotificationEvent userNotificationEvent : list) {
203                                            if (!Validator.equals(uuid, userNotificationEvent.getUuid())) {
204                                                    list = null;
205    
206                                                    break;
207                                            }
208                                    }
209                            }
210                    }
211    
212                    if (list == null) {
213                            StringBundler query = null;
214    
215                            if (orderByComparator != null) {
216                                    query = new StringBundler(3 +
217                                                    (orderByComparator.getOrderByFields().length * 3));
218                            }
219                            else {
220                                    query = new StringBundler(3);
221                            }
222    
223                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
224    
225                            boolean bindUuid = false;
226    
227                            if (uuid == null) {
228                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
229                            }
230                            else if (uuid.equals(StringPool.BLANK)) {
231                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
232                            }
233                            else {
234                                    bindUuid = true;
235    
236                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
237                            }
238    
239                            if (orderByComparator != null) {
240                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
241                                            orderByComparator);
242                            }
243                            else
244                             if (pagination) {
245                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
246                            }
247    
248                            String sql = query.toString();
249    
250                            Session session = null;
251    
252                            try {
253                                    session = openSession();
254    
255                                    Query q = session.createQuery(sql);
256    
257                                    QueryPos qPos = QueryPos.getInstance(q);
258    
259                                    if (bindUuid) {
260                                            qPos.add(uuid);
261                                    }
262    
263                                    if (!pagination) {
264                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
265                                                            getDialect(), start, end, false);
266    
267                                            Collections.sort(list);
268    
269                                            list = Collections.unmodifiableList(list);
270                                    }
271                                    else {
272                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
273                                                            getDialect(), start, end);
274                                    }
275    
276                                    cacheResult(list);
277    
278                                    finderCache.putResult(finderPath, finderArgs, list);
279                            }
280                            catch (Exception e) {
281                                    finderCache.removeResult(finderPath, finderArgs);
282    
283                                    throw processException(e);
284                            }
285                            finally {
286                                    closeSession(session);
287                            }
288                    }
289    
290                    return list;
291            }
292    
293            /**
294             * Returns the first user notification event in the ordered set where uuid = &#63;.
295             *
296             * @param uuid the uuid
297             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
298             * @return the first matching user notification event
299             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
300             */
301            @Override
302            public UserNotificationEvent findByUuid_First(String uuid,
303                    OrderByComparator<UserNotificationEvent> orderByComparator)
304                    throws NoSuchUserNotificationEventException {
305                    UserNotificationEvent userNotificationEvent = fetchByUuid_First(uuid,
306                                    orderByComparator);
307    
308                    if (userNotificationEvent != null) {
309                            return userNotificationEvent;
310                    }
311    
312                    StringBundler msg = new StringBundler(4);
313    
314                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
315    
316                    msg.append("uuid=");
317                    msg.append(uuid);
318    
319                    msg.append(StringPool.CLOSE_CURLY_BRACE);
320    
321                    throw new NoSuchUserNotificationEventException(msg.toString());
322            }
323    
324            /**
325             * Returns the first user notification event in the ordered set where uuid = &#63;.
326             *
327             * @param uuid the uuid
328             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
329             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
330             */
331            @Override
332            public UserNotificationEvent fetchByUuid_First(String uuid,
333                    OrderByComparator<UserNotificationEvent> orderByComparator) {
334                    List<UserNotificationEvent> list = findByUuid(uuid, 0, 1,
335                                    orderByComparator);
336    
337                    if (!list.isEmpty()) {
338                            return list.get(0);
339                    }
340    
341                    return null;
342            }
343    
344            /**
345             * Returns the last user notification event in the ordered set where uuid = &#63;.
346             *
347             * @param uuid the uuid
348             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
349             * @return the last matching user notification event
350             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
351             */
352            @Override
353            public UserNotificationEvent findByUuid_Last(String uuid,
354                    OrderByComparator<UserNotificationEvent> orderByComparator)
355                    throws NoSuchUserNotificationEventException {
356                    UserNotificationEvent userNotificationEvent = fetchByUuid_Last(uuid,
357                                    orderByComparator);
358    
359                    if (userNotificationEvent != null) {
360                            return userNotificationEvent;
361                    }
362    
363                    StringBundler msg = new StringBundler(4);
364    
365                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
366    
367                    msg.append("uuid=");
368                    msg.append(uuid);
369    
370                    msg.append(StringPool.CLOSE_CURLY_BRACE);
371    
372                    throw new NoSuchUserNotificationEventException(msg.toString());
373            }
374    
375            /**
376             * Returns the last user notification event in the ordered set where uuid = &#63;.
377             *
378             * @param uuid the uuid
379             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
380             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
381             */
382            @Override
383            public UserNotificationEvent fetchByUuid_Last(String uuid,
384                    OrderByComparator<UserNotificationEvent> orderByComparator) {
385                    int count = countByUuid(uuid);
386    
387                    if (count == 0) {
388                            return null;
389                    }
390    
391                    List<UserNotificationEvent> list = findByUuid(uuid, count - 1, count,
392                                    orderByComparator);
393    
394                    if (!list.isEmpty()) {
395                            return list.get(0);
396                    }
397    
398                    return null;
399            }
400    
401            /**
402             * Returns the user notification events before and after the current user notification event in the ordered set where uuid = &#63;.
403             *
404             * @param userNotificationEventId the primary key of the current user notification event
405             * @param uuid the uuid
406             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
407             * @return the previous, current, and next user notification event
408             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
409             */
410            @Override
411            public UserNotificationEvent[] findByUuid_PrevAndNext(
412                    long userNotificationEventId, String uuid,
413                    OrderByComparator<UserNotificationEvent> orderByComparator)
414                    throws NoSuchUserNotificationEventException {
415                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
416    
417                    Session session = null;
418    
419                    try {
420                            session = openSession();
421    
422                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
423    
424                            array[0] = getByUuid_PrevAndNext(session, userNotificationEvent,
425                                            uuid, orderByComparator, true);
426    
427                            array[1] = userNotificationEvent;
428    
429                            array[2] = getByUuid_PrevAndNext(session, userNotificationEvent,
430                                            uuid, orderByComparator, false);
431    
432                            return array;
433                    }
434                    catch (Exception e) {
435                            throw processException(e);
436                    }
437                    finally {
438                            closeSession(session);
439                    }
440            }
441    
442            protected UserNotificationEvent getByUuid_PrevAndNext(Session session,
443                    UserNotificationEvent userNotificationEvent, String uuid,
444                    OrderByComparator<UserNotificationEvent> orderByComparator,
445                    boolean previous) {
446                    StringBundler query = null;
447    
448                    if (orderByComparator != null) {
449                            query = new StringBundler(6 +
450                                            (orderByComparator.getOrderByFields().length * 6));
451                    }
452                    else {
453                            query = new StringBundler(3);
454                    }
455    
456                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
457    
458                    boolean bindUuid = false;
459    
460                    if (uuid == null) {
461                            query.append(_FINDER_COLUMN_UUID_UUID_1);
462                    }
463                    else if (uuid.equals(StringPool.BLANK)) {
464                            query.append(_FINDER_COLUMN_UUID_UUID_3);
465                    }
466                    else {
467                            bindUuid = true;
468    
469                            query.append(_FINDER_COLUMN_UUID_UUID_2);
470                    }
471    
472                    if (orderByComparator != null) {
473                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
474    
475                            if (orderByConditionFields.length > 0) {
476                                    query.append(WHERE_AND);
477                            }
478    
479                            for (int i = 0; i < orderByConditionFields.length; i++) {
480                                    query.append(_ORDER_BY_ENTITY_ALIAS);
481                                    query.append(orderByConditionFields[i]);
482    
483                                    if ((i + 1) < orderByConditionFields.length) {
484                                            if (orderByComparator.isAscending() ^ previous) {
485                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
486                                            }
487                                            else {
488                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
489                                            }
490                                    }
491                                    else {
492                                            if (orderByComparator.isAscending() ^ previous) {
493                                                    query.append(WHERE_GREATER_THAN);
494                                            }
495                                            else {
496                                                    query.append(WHERE_LESSER_THAN);
497                                            }
498                                    }
499                            }
500    
501                            query.append(ORDER_BY_CLAUSE);
502    
503                            String[] orderByFields = orderByComparator.getOrderByFields();
504    
505                            for (int i = 0; i < orderByFields.length; i++) {
506                                    query.append(_ORDER_BY_ENTITY_ALIAS);
507                                    query.append(orderByFields[i]);
508    
509                                    if ((i + 1) < orderByFields.length) {
510                                            if (orderByComparator.isAscending() ^ previous) {
511                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
512                                            }
513                                            else {
514                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
515                                            }
516                                    }
517                                    else {
518                                            if (orderByComparator.isAscending() ^ previous) {
519                                                    query.append(ORDER_BY_ASC);
520                                            }
521                                            else {
522                                                    query.append(ORDER_BY_DESC);
523                                            }
524                                    }
525                            }
526                    }
527                    else {
528                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
529                    }
530    
531                    String sql = query.toString();
532    
533                    Query q = session.createQuery(sql);
534    
535                    q.setFirstResult(0);
536                    q.setMaxResults(2);
537    
538                    QueryPos qPos = QueryPos.getInstance(q);
539    
540                    if (bindUuid) {
541                            qPos.add(uuid);
542                    }
543    
544                    if (orderByComparator != null) {
545                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
546    
547                            for (Object value : values) {
548                                    qPos.add(value);
549                            }
550                    }
551    
552                    List<UserNotificationEvent> list = q.list();
553    
554                    if (list.size() == 2) {
555                            return list.get(1);
556                    }
557                    else {
558                            return null;
559                    }
560            }
561    
562            /**
563             * Removes all the user notification events where uuid = &#63; from the database.
564             *
565             * @param uuid the uuid
566             */
567            @Override
568            public void removeByUuid(String uuid) {
569                    for (UserNotificationEvent userNotificationEvent : findByUuid(uuid,
570                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
571                            remove(userNotificationEvent);
572                    }
573            }
574    
575            /**
576             * Returns the number of user notification events where uuid = &#63;.
577             *
578             * @param uuid the uuid
579             * @return the number of matching user notification events
580             */
581            @Override
582            public int countByUuid(String uuid) {
583                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
584    
585                    Object[] finderArgs = new Object[] { uuid };
586    
587                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
588    
589                    if (count == null) {
590                            StringBundler query = new StringBundler(2);
591    
592                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
593    
594                            boolean bindUuid = false;
595    
596                            if (uuid == null) {
597                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
598                            }
599                            else if (uuid.equals(StringPool.BLANK)) {
600                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
601                            }
602                            else {
603                                    bindUuid = true;
604    
605                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
606                            }
607    
608                            String sql = query.toString();
609    
610                            Session session = null;
611    
612                            try {
613                                    session = openSession();
614    
615                                    Query q = session.createQuery(sql);
616    
617                                    QueryPos qPos = QueryPos.getInstance(q);
618    
619                                    if (bindUuid) {
620                                            qPos.add(uuid);
621                                    }
622    
623                                    count = (Long)q.uniqueResult();
624    
625                                    finderCache.putResult(finderPath, finderArgs, count);
626                            }
627                            catch (Exception e) {
628                                    finderCache.removeResult(finderPath, finderArgs);
629    
630                                    throw processException(e);
631                            }
632                            finally {
633                                    closeSession(session);
634                            }
635                    }
636    
637                    return count.intValue();
638            }
639    
640            private static final String _FINDER_COLUMN_UUID_UUID_1 = "userNotificationEvent.uuid IS NULL";
641            private static final String _FINDER_COLUMN_UUID_UUID_2 = "userNotificationEvent.uuid = ?";
642            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(userNotificationEvent.uuid IS NULL OR userNotificationEvent.uuid = '')";
643            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
644                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
645                            UserNotificationEventImpl.class,
646                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
647                            new String[] {
648                                    String.class.getName(), Long.class.getName(),
649                                    
650                            Integer.class.getName(), Integer.class.getName(),
651                                    OrderByComparator.class.getName()
652                            });
653            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
654                    new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
655                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
656                            UserNotificationEventImpl.class,
657                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
658                            new String[] { String.class.getName(), Long.class.getName() },
659                            UserNotificationEventModelImpl.UUID_COLUMN_BITMASK |
660                            UserNotificationEventModelImpl.COMPANYID_COLUMN_BITMASK |
661                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
662            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
663                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
664                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
665                            new String[] { String.class.getName(), Long.class.getName() });
666    
667            /**
668             * Returns all the user notification events where uuid = &#63; and companyId = &#63;.
669             *
670             * @param uuid the uuid
671             * @param companyId the company ID
672             * @return the matching user notification events
673             */
674            @Override
675            public List<UserNotificationEvent> findByUuid_C(String uuid, long companyId) {
676                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
677                            QueryUtil.ALL_POS, null);
678            }
679    
680            /**
681             * Returns a range of all the user notification events where uuid = &#63; and companyId = &#63;.
682             *
683             * <p>
684             * 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 UserNotificationEventModelImpl}. 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.
685             * </p>
686             *
687             * @param uuid the uuid
688             * @param companyId the company ID
689             * @param start the lower bound of the range of user notification events
690             * @param end the upper bound of the range of user notification events (not inclusive)
691             * @return the range of matching user notification events
692             */
693            @Override
694            public List<UserNotificationEvent> findByUuid_C(String uuid,
695                    long companyId, int start, int end) {
696                    return findByUuid_C(uuid, companyId, start, end, null);
697            }
698    
699            /**
700             * Returns an ordered range of all the user notification events where uuid = &#63; and companyId = &#63;.
701             *
702             * <p>
703             * 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 UserNotificationEventModelImpl}. 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.
704             * </p>
705             *
706             * @param uuid the uuid
707             * @param companyId the company ID
708             * @param start the lower bound of the range of user notification events
709             * @param end the upper bound of the range of user notification events (not inclusive)
710             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
711             * @return the ordered range of matching user notification events
712             */
713            @Override
714            public List<UserNotificationEvent> findByUuid_C(String uuid,
715                    long companyId, int start, int end,
716                    OrderByComparator<UserNotificationEvent> orderByComparator) {
717                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
718            }
719    
720            /**
721             * Returns an ordered range of all the user notification events where uuid = &#63; and companyId = &#63;.
722             *
723             * <p>
724             * 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 UserNotificationEventModelImpl}. 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.
725             * </p>
726             *
727             * @param uuid the uuid
728             * @param companyId the company ID
729             * @param start the lower bound of the range of user notification events
730             * @param end the upper bound of the range of user notification events (not inclusive)
731             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
732             * @param retrieveFromCache whether to retrieve from the finder cache
733             * @return the ordered range of matching user notification events
734             */
735            @Override
736            public List<UserNotificationEvent> findByUuid_C(String uuid,
737                    long companyId, int start, int end,
738                    OrderByComparator<UserNotificationEvent> orderByComparator,
739                    boolean retrieveFromCache) {
740                    boolean pagination = true;
741                    FinderPath finderPath = null;
742                    Object[] finderArgs = null;
743    
744                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
745                                    (orderByComparator == null)) {
746                            pagination = false;
747                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
748                            finderArgs = new Object[] { uuid, companyId };
749                    }
750                    else {
751                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
752                            finderArgs = new Object[] {
753                                            uuid, companyId,
754                                            
755                                            start, end, orderByComparator
756                                    };
757                    }
758    
759                    List<UserNotificationEvent> list = null;
760    
761                    if (retrieveFromCache) {
762                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
763                                            finderArgs, this);
764    
765                            if ((list != null) && !list.isEmpty()) {
766                                    for (UserNotificationEvent userNotificationEvent : list) {
767                                            if (!Validator.equals(uuid, userNotificationEvent.getUuid()) ||
768                                                            (companyId != userNotificationEvent.getCompanyId())) {
769                                                    list = null;
770    
771                                                    break;
772                                            }
773                                    }
774                            }
775                    }
776    
777                    if (list == null) {
778                            StringBundler query = null;
779    
780                            if (orderByComparator != null) {
781                                    query = new StringBundler(4 +
782                                                    (orderByComparator.getOrderByFields().length * 3));
783                            }
784                            else {
785                                    query = new StringBundler(4);
786                            }
787    
788                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
789    
790                            boolean bindUuid = false;
791    
792                            if (uuid == null) {
793                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
794                            }
795                            else if (uuid.equals(StringPool.BLANK)) {
796                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
797                            }
798                            else {
799                                    bindUuid = true;
800    
801                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
802                            }
803    
804                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
805    
806                            if (orderByComparator != null) {
807                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
808                                            orderByComparator);
809                            }
810                            else
811                             if (pagination) {
812                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
813                            }
814    
815                            String sql = query.toString();
816    
817                            Session session = null;
818    
819                            try {
820                                    session = openSession();
821    
822                                    Query q = session.createQuery(sql);
823    
824                                    QueryPos qPos = QueryPos.getInstance(q);
825    
826                                    if (bindUuid) {
827                                            qPos.add(uuid);
828                                    }
829    
830                                    qPos.add(companyId);
831    
832                                    if (!pagination) {
833                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
834                                                            getDialect(), start, end, false);
835    
836                                            Collections.sort(list);
837    
838                                            list = Collections.unmodifiableList(list);
839                                    }
840                                    else {
841                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
842                                                            getDialect(), start, end);
843                                    }
844    
845                                    cacheResult(list);
846    
847                                    finderCache.putResult(finderPath, finderArgs, list);
848                            }
849                            catch (Exception e) {
850                                    finderCache.removeResult(finderPath, finderArgs);
851    
852                                    throw processException(e);
853                            }
854                            finally {
855                                    closeSession(session);
856                            }
857                    }
858    
859                    return list;
860            }
861    
862            /**
863             * Returns the first user notification event in the ordered set where uuid = &#63; and companyId = &#63;.
864             *
865             * @param uuid the uuid
866             * @param companyId the company ID
867             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
868             * @return the first matching user notification event
869             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
870             */
871            @Override
872            public UserNotificationEvent findByUuid_C_First(String uuid,
873                    long companyId,
874                    OrderByComparator<UserNotificationEvent> orderByComparator)
875                    throws NoSuchUserNotificationEventException {
876                    UserNotificationEvent userNotificationEvent = fetchByUuid_C_First(uuid,
877                                    companyId, orderByComparator);
878    
879                    if (userNotificationEvent != null) {
880                            return userNotificationEvent;
881                    }
882    
883                    StringBundler msg = new StringBundler(6);
884    
885                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
886    
887                    msg.append("uuid=");
888                    msg.append(uuid);
889    
890                    msg.append(", companyId=");
891                    msg.append(companyId);
892    
893                    msg.append(StringPool.CLOSE_CURLY_BRACE);
894    
895                    throw new NoSuchUserNotificationEventException(msg.toString());
896            }
897    
898            /**
899             * Returns the first user notification event in the ordered set where uuid = &#63; and companyId = &#63;.
900             *
901             * @param uuid the uuid
902             * @param companyId the company ID
903             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
904             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
905             */
906            @Override
907            public UserNotificationEvent fetchByUuid_C_First(String uuid,
908                    long companyId,
909                    OrderByComparator<UserNotificationEvent> orderByComparator) {
910                    List<UserNotificationEvent> list = findByUuid_C(uuid, companyId, 0, 1,
911                                    orderByComparator);
912    
913                    if (!list.isEmpty()) {
914                            return list.get(0);
915                    }
916    
917                    return null;
918            }
919    
920            /**
921             * Returns the last user notification event in the ordered set where uuid = &#63; and companyId = &#63;.
922             *
923             * @param uuid the uuid
924             * @param companyId the company ID
925             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
926             * @return the last matching user notification event
927             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
928             */
929            @Override
930            public UserNotificationEvent findByUuid_C_Last(String uuid, long companyId,
931                    OrderByComparator<UserNotificationEvent> orderByComparator)
932                    throws NoSuchUserNotificationEventException {
933                    UserNotificationEvent userNotificationEvent = fetchByUuid_C_Last(uuid,
934                                    companyId, orderByComparator);
935    
936                    if (userNotificationEvent != null) {
937                            return userNotificationEvent;
938                    }
939    
940                    StringBundler msg = new StringBundler(6);
941    
942                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
943    
944                    msg.append("uuid=");
945                    msg.append(uuid);
946    
947                    msg.append(", companyId=");
948                    msg.append(companyId);
949    
950                    msg.append(StringPool.CLOSE_CURLY_BRACE);
951    
952                    throw new NoSuchUserNotificationEventException(msg.toString());
953            }
954    
955            /**
956             * Returns the last user notification event in the ordered set where uuid = &#63; and companyId = &#63;.
957             *
958             * @param uuid the uuid
959             * @param companyId the company ID
960             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
961             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
962             */
963            @Override
964            public UserNotificationEvent fetchByUuid_C_Last(String uuid,
965                    long companyId,
966                    OrderByComparator<UserNotificationEvent> orderByComparator) {
967                    int count = countByUuid_C(uuid, companyId);
968    
969                    if (count == 0) {
970                            return null;
971                    }
972    
973                    List<UserNotificationEvent> list = findByUuid_C(uuid, companyId,
974                                    count - 1, count, orderByComparator);
975    
976                    if (!list.isEmpty()) {
977                            return list.get(0);
978                    }
979    
980                    return null;
981            }
982    
983            /**
984             * Returns the user notification events before and after the current user notification event in the ordered set where uuid = &#63; and companyId = &#63;.
985             *
986             * @param userNotificationEventId the primary key of the current user notification event
987             * @param uuid the uuid
988             * @param companyId the company ID
989             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
990             * @return the previous, current, and next user notification event
991             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
992             */
993            @Override
994            public UserNotificationEvent[] findByUuid_C_PrevAndNext(
995                    long userNotificationEventId, String uuid, long companyId,
996                    OrderByComparator<UserNotificationEvent> orderByComparator)
997                    throws NoSuchUserNotificationEventException {
998                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
999    
1000                    Session session = null;
1001    
1002                    try {
1003                            session = openSession();
1004    
1005                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
1006    
1007                            array[0] = getByUuid_C_PrevAndNext(session, userNotificationEvent,
1008                                            uuid, companyId, orderByComparator, true);
1009    
1010                            array[1] = userNotificationEvent;
1011    
1012                            array[2] = getByUuid_C_PrevAndNext(session, userNotificationEvent,
1013                                            uuid, companyId, orderByComparator, false);
1014    
1015                            return array;
1016                    }
1017                    catch (Exception e) {
1018                            throw processException(e);
1019                    }
1020                    finally {
1021                            closeSession(session);
1022                    }
1023            }
1024    
1025            protected UserNotificationEvent getByUuid_C_PrevAndNext(Session session,
1026                    UserNotificationEvent userNotificationEvent, String uuid,
1027                    long companyId,
1028                    OrderByComparator<UserNotificationEvent> orderByComparator,
1029                    boolean previous) {
1030                    StringBundler query = null;
1031    
1032                    if (orderByComparator != null) {
1033                            query = new StringBundler(6 +
1034                                            (orderByComparator.getOrderByFields().length * 6));
1035                    }
1036                    else {
1037                            query = new StringBundler(3);
1038                    }
1039    
1040                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1041    
1042                    boolean bindUuid = false;
1043    
1044                    if (uuid == null) {
1045                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1046                    }
1047                    else if (uuid.equals(StringPool.BLANK)) {
1048                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1049                    }
1050                    else {
1051                            bindUuid = true;
1052    
1053                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1054                    }
1055    
1056                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1057    
1058                    if (orderByComparator != null) {
1059                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1060    
1061                            if (orderByConditionFields.length > 0) {
1062                                    query.append(WHERE_AND);
1063                            }
1064    
1065                            for (int i = 0; i < orderByConditionFields.length; i++) {
1066                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1067                                    query.append(orderByConditionFields[i]);
1068    
1069                                    if ((i + 1) < orderByConditionFields.length) {
1070                                            if (orderByComparator.isAscending() ^ previous) {
1071                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1072                                            }
1073                                            else {
1074                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1075                                            }
1076                                    }
1077                                    else {
1078                                            if (orderByComparator.isAscending() ^ previous) {
1079                                                    query.append(WHERE_GREATER_THAN);
1080                                            }
1081                                            else {
1082                                                    query.append(WHERE_LESSER_THAN);
1083                                            }
1084                                    }
1085                            }
1086    
1087                            query.append(ORDER_BY_CLAUSE);
1088    
1089                            String[] orderByFields = orderByComparator.getOrderByFields();
1090    
1091                            for (int i = 0; i < orderByFields.length; i++) {
1092                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1093                                    query.append(orderByFields[i]);
1094    
1095                                    if ((i + 1) < orderByFields.length) {
1096                                            if (orderByComparator.isAscending() ^ previous) {
1097                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1098                                            }
1099                                            else {
1100                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1101                                            }
1102                                    }
1103                                    else {
1104                                            if (orderByComparator.isAscending() ^ previous) {
1105                                                    query.append(ORDER_BY_ASC);
1106                                            }
1107                                            else {
1108                                                    query.append(ORDER_BY_DESC);
1109                                            }
1110                                    }
1111                            }
1112                    }
1113                    else {
1114                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1115                    }
1116    
1117                    String sql = query.toString();
1118    
1119                    Query q = session.createQuery(sql);
1120    
1121                    q.setFirstResult(0);
1122                    q.setMaxResults(2);
1123    
1124                    QueryPos qPos = QueryPos.getInstance(q);
1125    
1126                    if (bindUuid) {
1127                            qPos.add(uuid);
1128                    }
1129    
1130                    qPos.add(companyId);
1131    
1132                    if (orderByComparator != null) {
1133                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
1134    
1135                            for (Object value : values) {
1136                                    qPos.add(value);
1137                            }
1138                    }
1139    
1140                    List<UserNotificationEvent> list = q.list();
1141    
1142                    if (list.size() == 2) {
1143                            return list.get(1);
1144                    }
1145                    else {
1146                            return null;
1147                    }
1148            }
1149    
1150            /**
1151             * Removes all the user notification events where uuid = &#63; and companyId = &#63; from the database.
1152             *
1153             * @param uuid the uuid
1154             * @param companyId the company ID
1155             */
1156            @Override
1157            public void removeByUuid_C(String uuid, long companyId) {
1158                    for (UserNotificationEvent userNotificationEvent : findByUuid_C(uuid,
1159                                    companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1160                            remove(userNotificationEvent);
1161                    }
1162            }
1163    
1164            /**
1165             * Returns the number of user notification events where uuid = &#63; and companyId = &#63;.
1166             *
1167             * @param uuid the uuid
1168             * @param companyId the company ID
1169             * @return the number of matching user notification events
1170             */
1171            @Override
1172            public int countByUuid_C(String uuid, long companyId) {
1173                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1174    
1175                    Object[] finderArgs = new Object[] { uuid, companyId };
1176    
1177                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1178    
1179                    if (count == null) {
1180                            StringBundler query = new StringBundler(3);
1181    
1182                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
1183    
1184                            boolean bindUuid = false;
1185    
1186                            if (uuid == null) {
1187                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1188                            }
1189                            else if (uuid.equals(StringPool.BLANK)) {
1190                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1191                            }
1192                            else {
1193                                    bindUuid = true;
1194    
1195                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1196                            }
1197    
1198                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1199    
1200                            String sql = query.toString();
1201    
1202                            Session session = null;
1203    
1204                            try {
1205                                    session = openSession();
1206    
1207                                    Query q = session.createQuery(sql);
1208    
1209                                    QueryPos qPos = QueryPos.getInstance(q);
1210    
1211                                    if (bindUuid) {
1212                                            qPos.add(uuid);
1213                                    }
1214    
1215                                    qPos.add(companyId);
1216    
1217                                    count = (Long)q.uniqueResult();
1218    
1219                                    finderCache.putResult(finderPath, finderArgs, count);
1220                            }
1221                            catch (Exception e) {
1222                                    finderCache.removeResult(finderPath, finderArgs);
1223    
1224                                    throw processException(e);
1225                            }
1226                            finally {
1227                                    closeSession(session);
1228                            }
1229                    }
1230    
1231                    return count.intValue();
1232            }
1233    
1234            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "userNotificationEvent.uuid IS NULL AND ";
1235            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "userNotificationEvent.uuid = ? AND ";
1236            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(userNotificationEvent.uuid IS NULL OR userNotificationEvent.uuid = '') AND ";
1237            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "userNotificationEvent.companyId = ?";
1238            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1239                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1240                            UserNotificationEventImpl.class,
1241                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
1242                            new String[] {
1243                                    Long.class.getName(),
1244                                    
1245                            Integer.class.getName(), Integer.class.getName(),
1246                                    OrderByComparator.class.getName()
1247                            });
1248            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1249                    new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1250                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1251                            UserNotificationEventImpl.class,
1252                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
1253                            new String[] { Long.class.getName() },
1254                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
1255                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
1256            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1257                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
1258                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1259                            new String[] { Long.class.getName() });
1260    
1261            /**
1262             * Returns all the user notification events where userId = &#63;.
1263             *
1264             * @param userId the user ID
1265             * @return the matching user notification events
1266             */
1267            @Override
1268            public List<UserNotificationEvent> findByUserId(long userId) {
1269                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1270            }
1271    
1272            /**
1273             * Returns a range of all the user notification events where userId = &#63;.
1274             *
1275             * <p>
1276             * 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 UserNotificationEventModelImpl}. 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.
1277             * </p>
1278             *
1279             * @param userId the user ID
1280             * @param start the lower bound of the range of user notification events
1281             * @param end the upper bound of the range of user notification events (not inclusive)
1282             * @return the range of matching user notification events
1283             */
1284            @Override
1285            public List<UserNotificationEvent> findByUserId(long userId, int start,
1286                    int end) {
1287                    return findByUserId(userId, start, end, null);
1288            }
1289    
1290            /**
1291             * Returns an ordered range of all the user notification events where userId = &#63;.
1292             *
1293             * <p>
1294             * 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 UserNotificationEventModelImpl}. 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.
1295             * </p>
1296             *
1297             * @param userId the user ID
1298             * @param start the lower bound of the range of user notification events
1299             * @param end the upper bound of the range of user notification events (not inclusive)
1300             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1301             * @return the ordered range of matching user notification events
1302             */
1303            @Override
1304            public List<UserNotificationEvent> findByUserId(long userId, int start,
1305                    int end, OrderByComparator<UserNotificationEvent> orderByComparator) {
1306                    return findByUserId(userId, start, end, orderByComparator, true);
1307            }
1308    
1309            /**
1310             * Returns an ordered range of all the user notification events where userId = &#63;.
1311             *
1312             * <p>
1313             * 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 UserNotificationEventModelImpl}. 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.
1314             * </p>
1315             *
1316             * @param userId the user ID
1317             * @param start the lower bound of the range of user notification events
1318             * @param end the upper bound of the range of user notification events (not inclusive)
1319             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1320             * @param retrieveFromCache whether to retrieve from the finder cache
1321             * @return the ordered range of matching user notification events
1322             */
1323            @Override
1324            public List<UserNotificationEvent> findByUserId(long userId, int start,
1325                    int end, OrderByComparator<UserNotificationEvent> orderByComparator,
1326                    boolean retrieveFromCache) {
1327                    boolean pagination = true;
1328                    FinderPath finderPath = null;
1329                    Object[] finderArgs = null;
1330    
1331                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1332                                    (orderByComparator == null)) {
1333                            pagination = false;
1334                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1335                            finderArgs = new Object[] { userId };
1336                    }
1337                    else {
1338                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1339                            finderArgs = new Object[] { userId, start, end, orderByComparator };
1340                    }
1341    
1342                    List<UserNotificationEvent> list = null;
1343    
1344                    if (retrieveFromCache) {
1345                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
1346                                            finderArgs, this);
1347    
1348                            if ((list != null) && !list.isEmpty()) {
1349                                    for (UserNotificationEvent userNotificationEvent : list) {
1350                                            if ((userId != userNotificationEvent.getUserId())) {
1351                                                    list = null;
1352    
1353                                                    break;
1354                                            }
1355                                    }
1356                            }
1357                    }
1358    
1359                    if (list == null) {
1360                            StringBundler query = null;
1361    
1362                            if (orderByComparator != null) {
1363                                    query = new StringBundler(3 +
1364                                                    (orderByComparator.getOrderByFields().length * 3));
1365                            }
1366                            else {
1367                                    query = new StringBundler(3);
1368                            }
1369    
1370                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1371    
1372                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1373    
1374                            if (orderByComparator != null) {
1375                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1376                                            orderByComparator);
1377                            }
1378                            else
1379                             if (pagination) {
1380                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1381                            }
1382    
1383                            String sql = query.toString();
1384    
1385                            Session session = null;
1386    
1387                            try {
1388                                    session = openSession();
1389    
1390                                    Query q = session.createQuery(sql);
1391    
1392                                    QueryPos qPos = QueryPos.getInstance(q);
1393    
1394                                    qPos.add(userId);
1395    
1396                                    if (!pagination) {
1397                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
1398                                                            getDialect(), start, end, false);
1399    
1400                                            Collections.sort(list);
1401    
1402                                            list = Collections.unmodifiableList(list);
1403                                    }
1404                                    else {
1405                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
1406                                                            getDialect(), start, end);
1407                                    }
1408    
1409                                    cacheResult(list);
1410    
1411                                    finderCache.putResult(finderPath, finderArgs, list);
1412                            }
1413                            catch (Exception e) {
1414                                    finderCache.removeResult(finderPath, finderArgs);
1415    
1416                                    throw processException(e);
1417                            }
1418                            finally {
1419                                    closeSession(session);
1420                            }
1421                    }
1422    
1423                    return list;
1424            }
1425    
1426            /**
1427             * Returns the first user notification event in the ordered set where userId = &#63;.
1428             *
1429             * @param userId the user ID
1430             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1431             * @return the first matching user notification event
1432             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
1433             */
1434            @Override
1435            public UserNotificationEvent findByUserId_First(long userId,
1436                    OrderByComparator<UserNotificationEvent> orderByComparator)
1437                    throws NoSuchUserNotificationEventException {
1438                    UserNotificationEvent userNotificationEvent = fetchByUserId_First(userId,
1439                                    orderByComparator);
1440    
1441                    if (userNotificationEvent != null) {
1442                            return userNotificationEvent;
1443                    }
1444    
1445                    StringBundler msg = new StringBundler(4);
1446    
1447                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1448    
1449                    msg.append("userId=");
1450                    msg.append(userId);
1451    
1452                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1453    
1454                    throw new NoSuchUserNotificationEventException(msg.toString());
1455            }
1456    
1457            /**
1458             * Returns the first user notification event in the ordered set where userId = &#63;.
1459             *
1460             * @param userId the user ID
1461             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1462             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
1463             */
1464            @Override
1465            public UserNotificationEvent fetchByUserId_First(long userId,
1466                    OrderByComparator<UserNotificationEvent> orderByComparator) {
1467                    List<UserNotificationEvent> list = findByUserId(userId, 0, 1,
1468                                    orderByComparator);
1469    
1470                    if (!list.isEmpty()) {
1471                            return list.get(0);
1472                    }
1473    
1474                    return null;
1475            }
1476    
1477            /**
1478             * Returns the last user notification event in the ordered set where userId = &#63;.
1479             *
1480             * @param userId the user ID
1481             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1482             * @return the last matching user notification event
1483             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
1484             */
1485            @Override
1486            public UserNotificationEvent findByUserId_Last(long userId,
1487                    OrderByComparator<UserNotificationEvent> orderByComparator)
1488                    throws NoSuchUserNotificationEventException {
1489                    UserNotificationEvent userNotificationEvent = fetchByUserId_Last(userId,
1490                                    orderByComparator);
1491    
1492                    if (userNotificationEvent != null) {
1493                            return userNotificationEvent;
1494                    }
1495    
1496                    StringBundler msg = new StringBundler(4);
1497    
1498                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1499    
1500                    msg.append("userId=");
1501                    msg.append(userId);
1502    
1503                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1504    
1505                    throw new NoSuchUserNotificationEventException(msg.toString());
1506            }
1507    
1508            /**
1509             * Returns the last user notification event in the ordered set where userId = &#63;.
1510             *
1511             * @param userId the user ID
1512             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1513             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
1514             */
1515            @Override
1516            public UserNotificationEvent fetchByUserId_Last(long userId,
1517                    OrderByComparator<UserNotificationEvent> orderByComparator) {
1518                    int count = countByUserId(userId);
1519    
1520                    if (count == 0) {
1521                            return null;
1522                    }
1523    
1524                    List<UserNotificationEvent> list = findByUserId(userId, count - 1,
1525                                    count, orderByComparator);
1526    
1527                    if (!list.isEmpty()) {
1528                            return list.get(0);
1529                    }
1530    
1531                    return null;
1532            }
1533    
1534            /**
1535             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63;.
1536             *
1537             * @param userNotificationEventId the primary key of the current user notification event
1538             * @param userId the user ID
1539             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1540             * @return the previous, current, and next user notification event
1541             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
1542             */
1543            @Override
1544            public UserNotificationEvent[] findByUserId_PrevAndNext(
1545                    long userNotificationEventId, long userId,
1546                    OrderByComparator<UserNotificationEvent> orderByComparator)
1547                    throws NoSuchUserNotificationEventException {
1548                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
1549    
1550                    Session session = null;
1551    
1552                    try {
1553                            session = openSession();
1554    
1555                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
1556    
1557                            array[0] = getByUserId_PrevAndNext(session, userNotificationEvent,
1558                                            userId, orderByComparator, true);
1559    
1560                            array[1] = userNotificationEvent;
1561    
1562                            array[2] = getByUserId_PrevAndNext(session, userNotificationEvent,
1563                                            userId, orderByComparator, false);
1564    
1565                            return array;
1566                    }
1567                    catch (Exception e) {
1568                            throw processException(e);
1569                    }
1570                    finally {
1571                            closeSession(session);
1572                    }
1573            }
1574    
1575            protected UserNotificationEvent getByUserId_PrevAndNext(Session session,
1576                    UserNotificationEvent userNotificationEvent, long userId,
1577                    OrderByComparator<UserNotificationEvent> orderByComparator,
1578                    boolean previous) {
1579                    StringBundler query = null;
1580    
1581                    if (orderByComparator != null) {
1582                            query = new StringBundler(6 +
1583                                            (orderByComparator.getOrderByFields().length * 6));
1584                    }
1585                    else {
1586                            query = new StringBundler(3);
1587                    }
1588    
1589                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1590    
1591                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1592    
1593                    if (orderByComparator != null) {
1594                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1595    
1596                            if (orderByConditionFields.length > 0) {
1597                                    query.append(WHERE_AND);
1598                            }
1599    
1600                            for (int i = 0; i < orderByConditionFields.length; i++) {
1601                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1602                                    query.append(orderByConditionFields[i]);
1603    
1604                                    if ((i + 1) < orderByConditionFields.length) {
1605                                            if (orderByComparator.isAscending() ^ previous) {
1606                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1607                                            }
1608                                            else {
1609                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1610                                            }
1611                                    }
1612                                    else {
1613                                            if (orderByComparator.isAscending() ^ previous) {
1614                                                    query.append(WHERE_GREATER_THAN);
1615                                            }
1616                                            else {
1617                                                    query.append(WHERE_LESSER_THAN);
1618                                            }
1619                                    }
1620                            }
1621    
1622                            query.append(ORDER_BY_CLAUSE);
1623    
1624                            String[] orderByFields = orderByComparator.getOrderByFields();
1625    
1626                            for (int i = 0; i < orderByFields.length; i++) {
1627                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1628                                    query.append(orderByFields[i]);
1629    
1630                                    if ((i + 1) < orderByFields.length) {
1631                                            if (orderByComparator.isAscending() ^ previous) {
1632                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1633                                            }
1634                                            else {
1635                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1636                                            }
1637                                    }
1638                                    else {
1639                                            if (orderByComparator.isAscending() ^ previous) {
1640                                                    query.append(ORDER_BY_ASC);
1641                                            }
1642                                            else {
1643                                                    query.append(ORDER_BY_DESC);
1644                                            }
1645                                    }
1646                            }
1647                    }
1648                    else {
1649                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1650                    }
1651    
1652                    String sql = query.toString();
1653    
1654                    Query q = session.createQuery(sql);
1655    
1656                    q.setFirstResult(0);
1657                    q.setMaxResults(2);
1658    
1659                    QueryPos qPos = QueryPos.getInstance(q);
1660    
1661                    qPos.add(userId);
1662    
1663                    if (orderByComparator != null) {
1664                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
1665    
1666                            for (Object value : values) {
1667                                    qPos.add(value);
1668                            }
1669                    }
1670    
1671                    List<UserNotificationEvent> list = q.list();
1672    
1673                    if (list.size() == 2) {
1674                            return list.get(1);
1675                    }
1676                    else {
1677                            return null;
1678                    }
1679            }
1680    
1681            /**
1682             * Removes all the user notification events where userId = &#63; from the database.
1683             *
1684             * @param userId the user ID
1685             */
1686            @Override
1687            public void removeByUserId(long userId) {
1688                    for (UserNotificationEvent userNotificationEvent : findByUserId(
1689                                    userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1690                            remove(userNotificationEvent);
1691                    }
1692            }
1693    
1694            /**
1695             * Returns the number of user notification events where userId = &#63;.
1696             *
1697             * @param userId the user ID
1698             * @return the number of matching user notification events
1699             */
1700            @Override
1701            public int countByUserId(long userId) {
1702                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
1703    
1704                    Object[] finderArgs = new Object[] { userId };
1705    
1706                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1707    
1708                    if (count == null) {
1709                            StringBundler query = new StringBundler(2);
1710    
1711                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
1712    
1713                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1714    
1715                            String sql = query.toString();
1716    
1717                            Session session = null;
1718    
1719                            try {
1720                                    session = openSession();
1721    
1722                                    Query q = session.createQuery(sql);
1723    
1724                                    QueryPos qPos = QueryPos.getInstance(q);
1725    
1726                                    qPos.add(userId);
1727    
1728                                    count = (Long)q.uniqueResult();
1729    
1730                                    finderCache.putResult(finderPath, finderArgs, count);
1731                            }
1732                            catch (Exception e) {
1733                                    finderCache.removeResult(finderPath, finderArgs);
1734    
1735                                    throw processException(e);
1736                            }
1737                            finally {
1738                                    closeSession(session);
1739                            }
1740                    }
1741    
1742                    return count.intValue();
1743            }
1744    
1745            private static final String _FINDER_COLUMN_USERID_USERID_2 = "userNotificationEvent.userId = ?";
1746            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1747                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1748                            UserNotificationEventImpl.class,
1749                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
1750                            new String[] {
1751                                    String.class.getName(),
1752                                    
1753                            Integer.class.getName(), Integer.class.getName(),
1754                                    OrderByComparator.class.getName()
1755                            });
1756            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1757                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1758                            UserNotificationEventImpl.class,
1759                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
1760                            new String[] { String.class.getName() },
1761                            UserNotificationEventModelImpl.TYPE_COLUMN_BITMASK |
1762                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
1763            public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1764                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
1765                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
1766                            new String[] { String.class.getName() });
1767    
1768            /**
1769             * Returns all the user notification events where type = &#63;.
1770             *
1771             * @param type the type
1772             * @return the matching user notification events
1773             */
1774            @Override
1775            public List<UserNotificationEvent> findByType(String type) {
1776                    return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1777            }
1778    
1779            /**
1780             * Returns a range of all the user notification events where type = &#63;.
1781             *
1782             * <p>
1783             * 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 UserNotificationEventModelImpl}. 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.
1784             * </p>
1785             *
1786             * @param type the type
1787             * @param start the lower bound of the range of user notification events
1788             * @param end the upper bound of the range of user notification events (not inclusive)
1789             * @return the range of matching user notification events
1790             */
1791            @Override
1792            public List<UserNotificationEvent> findByType(String type, int start,
1793                    int end) {
1794                    return findByType(type, start, end, null);
1795            }
1796    
1797            /**
1798             * Returns an ordered range of all the user notification events where type = &#63;.
1799             *
1800             * <p>
1801             * 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 UserNotificationEventModelImpl}. 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.
1802             * </p>
1803             *
1804             * @param type the type
1805             * @param start the lower bound of the range of user notification events
1806             * @param end the upper bound of the range of user notification events (not inclusive)
1807             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1808             * @return the ordered range of matching user notification events
1809             */
1810            @Override
1811            public List<UserNotificationEvent> findByType(String type, int start,
1812                    int end, OrderByComparator<UserNotificationEvent> orderByComparator) {
1813                    return findByType(type, start, end, orderByComparator, true);
1814            }
1815    
1816            /**
1817             * Returns an ordered range of all the user notification events where type = &#63;.
1818             *
1819             * <p>
1820             * 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 UserNotificationEventModelImpl}. 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.
1821             * </p>
1822             *
1823             * @param type the type
1824             * @param start the lower bound of the range of user notification events
1825             * @param end the upper bound of the range of user notification events (not inclusive)
1826             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1827             * @param retrieveFromCache whether to retrieve from the finder cache
1828             * @return the ordered range of matching user notification events
1829             */
1830            @Override
1831            public List<UserNotificationEvent> findByType(String type, int start,
1832                    int end, OrderByComparator<UserNotificationEvent> orderByComparator,
1833                    boolean retrieveFromCache) {
1834                    boolean pagination = true;
1835                    FinderPath finderPath = null;
1836                    Object[] finderArgs = null;
1837    
1838                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1839                                    (orderByComparator == null)) {
1840                            pagination = false;
1841                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
1842                            finderArgs = new Object[] { type };
1843                    }
1844                    else {
1845                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
1846                            finderArgs = new Object[] { type, start, end, orderByComparator };
1847                    }
1848    
1849                    List<UserNotificationEvent> list = null;
1850    
1851                    if (retrieveFromCache) {
1852                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
1853                                            finderArgs, this);
1854    
1855                            if ((list != null) && !list.isEmpty()) {
1856                                    for (UserNotificationEvent userNotificationEvent : list) {
1857                                            if (!Validator.equals(type, userNotificationEvent.getType())) {
1858                                                    list = null;
1859    
1860                                                    break;
1861                                            }
1862                                    }
1863                            }
1864                    }
1865    
1866                    if (list == null) {
1867                            StringBundler query = null;
1868    
1869                            if (orderByComparator != null) {
1870                                    query = new StringBundler(3 +
1871                                                    (orderByComparator.getOrderByFields().length * 3));
1872                            }
1873                            else {
1874                                    query = new StringBundler(3);
1875                            }
1876    
1877                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1878    
1879                            boolean bindType = false;
1880    
1881                            if (type == null) {
1882                                    query.append(_FINDER_COLUMN_TYPE_TYPE_1);
1883                            }
1884                            else if (type.equals(StringPool.BLANK)) {
1885                                    query.append(_FINDER_COLUMN_TYPE_TYPE_3);
1886                            }
1887                            else {
1888                                    bindType = true;
1889    
1890                                    query.append(_FINDER_COLUMN_TYPE_TYPE_2);
1891                            }
1892    
1893                            if (orderByComparator != null) {
1894                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1895                                            orderByComparator);
1896                            }
1897                            else
1898                             if (pagination) {
1899                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1900                            }
1901    
1902                            String sql = query.toString();
1903    
1904                            Session session = null;
1905    
1906                            try {
1907                                    session = openSession();
1908    
1909                                    Query q = session.createQuery(sql);
1910    
1911                                    QueryPos qPos = QueryPos.getInstance(q);
1912    
1913                                    if (bindType) {
1914                                            qPos.add(type);
1915                                    }
1916    
1917                                    if (!pagination) {
1918                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
1919                                                            getDialect(), start, end, false);
1920    
1921                                            Collections.sort(list);
1922    
1923                                            list = Collections.unmodifiableList(list);
1924                                    }
1925                                    else {
1926                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
1927                                                            getDialect(), start, end);
1928                                    }
1929    
1930                                    cacheResult(list);
1931    
1932                                    finderCache.putResult(finderPath, finderArgs, list);
1933                            }
1934                            catch (Exception e) {
1935                                    finderCache.removeResult(finderPath, finderArgs);
1936    
1937                                    throw processException(e);
1938                            }
1939                            finally {
1940                                    closeSession(session);
1941                            }
1942                    }
1943    
1944                    return list;
1945            }
1946    
1947            /**
1948             * Returns the first user notification event in the ordered set where type = &#63;.
1949             *
1950             * @param type the type
1951             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1952             * @return the first matching user notification event
1953             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
1954             */
1955            @Override
1956            public UserNotificationEvent findByType_First(String type,
1957                    OrderByComparator<UserNotificationEvent> orderByComparator)
1958                    throws NoSuchUserNotificationEventException {
1959                    UserNotificationEvent userNotificationEvent = fetchByType_First(type,
1960                                    orderByComparator);
1961    
1962                    if (userNotificationEvent != null) {
1963                            return userNotificationEvent;
1964                    }
1965    
1966                    StringBundler msg = new StringBundler(4);
1967    
1968                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1969    
1970                    msg.append("type=");
1971                    msg.append(type);
1972    
1973                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1974    
1975                    throw new NoSuchUserNotificationEventException(msg.toString());
1976            }
1977    
1978            /**
1979             * Returns the first user notification event in the ordered set where type = &#63;.
1980             *
1981             * @param type the type
1982             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1983             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
1984             */
1985            @Override
1986            public UserNotificationEvent fetchByType_First(String type,
1987                    OrderByComparator<UserNotificationEvent> orderByComparator) {
1988                    List<UserNotificationEvent> list = findByType(type, 0, 1,
1989                                    orderByComparator);
1990    
1991                    if (!list.isEmpty()) {
1992                            return list.get(0);
1993                    }
1994    
1995                    return null;
1996            }
1997    
1998            /**
1999             * Returns the last user notification event in the ordered set where type = &#63;.
2000             *
2001             * @param type the type
2002             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2003             * @return the last matching user notification event
2004             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
2005             */
2006            @Override
2007            public UserNotificationEvent findByType_Last(String type,
2008                    OrderByComparator<UserNotificationEvent> orderByComparator)
2009                    throws NoSuchUserNotificationEventException {
2010                    UserNotificationEvent userNotificationEvent = fetchByType_Last(type,
2011                                    orderByComparator);
2012    
2013                    if (userNotificationEvent != null) {
2014                            return userNotificationEvent;
2015                    }
2016    
2017                    StringBundler msg = new StringBundler(4);
2018    
2019                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2020    
2021                    msg.append("type=");
2022                    msg.append(type);
2023    
2024                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2025    
2026                    throw new NoSuchUserNotificationEventException(msg.toString());
2027            }
2028    
2029            /**
2030             * Returns the last user notification event in the ordered set where type = &#63;.
2031             *
2032             * @param type the type
2033             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2034             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
2035             */
2036            @Override
2037            public UserNotificationEvent fetchByType_Last(String type,
2038                    OrderByComparator<UserNotificationEvent> orderByComparator) {
2039                    int count = countByType(type);
2040    
2041                    if (count == 0) {
2042                            return null;
2043                    }
2044    
2045                    List<UserNotificationEvent> list = findByType(type, count - 1, count,
2046                                    orderByComparator);
2047    
2048                    if (!list.isEmpty()) {
2049                            return list.get(0);
2050                    }
2051    
2052                    return null;
2053            }
2054    
2055            /**
2056             * Returns the user notification events before and after the current user notification event in the ordered set where type = &#63;.
2057             *
2058             * @param userNotificationEventId the primary key of the current user notification event
2059             * @param type the type
2060             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2061             * @return the previous, current, and next user notification event
2062             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
2063             */
2064            @Override
2065            public UserNotificationEvent[] findByType_PrevAndNext(
2066                    long userNotificationEventId, String type,
2067                    OrderByComparator<UserNotificationEvent> orderByComparator)
2068                    throws NoSuchUserNotificationEventException {
2069                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
2070    
2071                    Session session = null;
2072    
2073                    try {
2074                            session = openSession();
2075    
2076                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
2077    
2078                            array[0] = getByType_PrevAndNext(session, userNotificationEvent,
2079                                            type, orderByComparator, true);
2080    
2081                            array[1] = userNotificationEvent;
2082    
2083                            array[2] = getByType_PrevAndNext(session, userNotificationEvent,
2084                                            type, orderByComparator, false);
2085    
2086                            return array;
2087                    }
2088                    catch (Exception e) {
2089                            throw processException(e);
2090                    }
2091                    finally {
2092                            closeSession(session);
2093                    }
2094            }
2095    
2096            protected UserNotificationEvent getByType_PrevAndNext(Session session,
2097                    UserNotificationEvent userNotificationEvent, String type,
2098                    OrderByComparator<UserNotificationEvent> orderByComparator,
2099                    boolean previous) {
2100                    StringBundler query = null;
2101    
2102                    if (orderByComparator != null) {
2103                            query = new StringBundler(6 +
2104                                            (orderByComparator.getOrderByFields().length * 6));
2105                    }
2106                    else {
2107                            query = new StringBundler(3);
2108                    }
2109    
2110                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
2111    
2112                    boolean bindType = false;
2113    
2114                    if (type == null) {
2115                            query.append(_FINDER_COLUMN_TYPE_TYPE_1);
2116                    }
2117                    else if (type.equals(StringPool.BLANK)) {
2118                            query.append(_FINDER_COLUMN_TYPE_TYPE_3);
2119                    }
2120                    else {
2121                            bindType = true;
2122    
2123                            query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2124                    }
2125    
2126                    if (orderByComparator != null) {
2127                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2128    
2129                            if (orderByConditionFields.length > 0) {
2130                                    query.append(WHERE_AND);
2131                            }
2132    
2133                            for (int i = 0; i < orderByConditionFields.length; i++) {
2134                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2135                                    query.append(orderByConditionFields[i]);
2136    
2137                                    if ((i + 1) < orderByConditionFields.length) {
2138                                            if (orderByComparator.isAscending() ^ previous) {
2139                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2140                                            }
2141                                            else {
2142                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2143                                            }
2144                                    }
2145                                    else {
2146                                            if (orderByComparator.isAscending() ^ previous) {
2147                                                    query.append(WHERE_GREATER_THAN);
2148                                            }
2149                                            else {
2150                                                    query.append(WHERE_LESSER_THAN);
2151                                            }
2152                                    }
2153                            }
2154    
2155                            query.append(ORDER_BY_CLAUSE);
2156    
2157                            String[] orderByFields = orderByComparator.getOrderByFields();
2158    
2159                            for (int i = 0; i < orderByFields.length; i++) {
2160                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2161                                    query.append(orderByFields[i]);
2162    
2163                                    if ((i + 1) < orderByFields.length) {
2164                                            if (orderByComparator.isAscending() ^ previous) {
2165                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2166                                            }
2167                                            else {
2168                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2169                                            }
2170                                    }
2171                                    else {
2172                                            if (orderByComparator.isAscending() ^ previous) {
2173                                                    query.append(ORDER_BY_ASC);
2174                                            }
2175                                            else {
2176                                                    query.append(ORDER_BY_DESC);
2177                                            }
2178                                    }
2179                            }
2180                    }
2181                    else {
2182                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
2183                    }
2184    
2185                    String sql = query.toString();
2186    
2187                    Query q = session.createQuery(sql);
2188    
2189                    q.setFirstResult(0);
2190                    q.setMaxResults(2);
2191    
2192                    QueryPos qPos = QueryPos.getInstance(q);
2193    
2194                    if (bindType) {
2195                            qPos.add(type);
2196                    }
2197    
2198                    if (orderByComparator != null) {
2199                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
2200    
2201                            for (Object value : values) {
2202                                    qPos.add(value);
2203                            }
2204                    }
2205    
2206                    List<UserNotificationEvent> list = q.list();
2207    
2208                    if (list.size() == 2) {
2209                            return list.get(1);
2210                    }
2211                    else {
2212                            return null;
2213                    }
2214            }
2215    
2216            /**
2217             * Removes all the user notification events where type = &#63; from the database.
2218             *
2219             * @param type the type
2220             */
2221            @Override
2222            public void removeByType(String type) {
2223                    for (UserNotificationEvent userNotificationEvent : findByType(type,
2224                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2225                            remove(userNotificationEvent);
2226                    }
2227            }
2228    
2229            /**
2230             * Returns the number of user notification events where type = &#63;.
2231             *
2232             * @param type the type
2233             * @return the number of matching user notification events
2234             */
2235            @Override
2236            public int countByType(String type) {
2237                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
2238    
2239                    Object[] finderArgs = new Object[] { type };
2240    
2241                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2242    
2243                    if (count == null) {
2244                            StringBundler query = new StringBundler(2);
2245    
2246                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
2247    
2248                            boolean bindType = false;
2249    
2250                            if (type == null) {
2251                                    query.append(_FINDER_COLUMN_TYPE_TYPE_1);
2252                            }
2253                            else if (type.equals(StringPool.BLANK)) {
2254                                    query.append(_FINDER_COLUMN_TYPE_TYPE_3);
2255                            }
2256                            else {
2257                                    bindType = true;
2258    
2259                                    query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2260                            }
2261    
2262                            String sql = query.toString();
2263    
2264                            Session session = null;
2265    
2266                            try {
2267                                    session = openSession();
2268    
2269                                    Query q = session.createQuery(sql);
2270    
2271                                    QueryPos qPos = QueryPos.getInstance(q);
2272    
2273                                    if (bindType) {
2274                                            qPos.add(type);
2275                                    }
2276    
2277                                    count = (Long)q.uniqueResult();
2278    
2279                                    finderCache.putResult(finderPath, finderArgs, count);
2280                            }
2281                            catch (Exception e) {
2282                                    finderCache.removeResult(finderPath, finderArgs);
2283    
2284                                    throw processException(e);
2285                            }
2286                            finally {
2287                                    closeSession(session);
2288                            }
2289                    }
2290    
2291                    return count.intValue();
2292            }
2293    
2294            private static final String _FINDER_COLUMN_TYPE_TYPE_1 = "userNotificationEvent.type IS NULL";
2295            private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "userNotificationEvent.type = ?";
2296            private static final String _FINDER_COLUMN_TYPE_TYPE_3 = "(userNotificationEvent.type IS NULL OR userNotificationEvent.type = '')";
2297            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_DT = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2298                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
2299                            UserNotificationEventImpl.class,
2300                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_DT",
2301                            new String[] {
2302                                    Long.class.getName(), Integer.class.getName(),
2303                                    
2304                            Integer.class.getName(), Integer.class.getName(),
2305                                    OrderByComparator.class.getName()
2306                            });
2307            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2308                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
2309                            UserNotificationEventImpl.class,
2310                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_DT",
2311                            new String[] { Long.class.getName(), Integer.class.getName() },
2312                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
2313                            UserNotificationEventModelImpl.DELIVERYTYPE_COLUMN_BITMASK |
2314                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
2315            public static final FinderPath FINDER_PATH_COUNT_BY_U_DT = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2316                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
2317                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_DT",
2318                            new String[] { Long.class.getName(), Integer.class.getName() });
2319    
2320            /**
2321             * Returns all the user notification events where userId = &#63; and deliveryType = &#63;.
2322             *
2323             * @param userId the user ID
2324             * @param deliveryType the delivery type
2325             * @return the matching user notification events
2326             */
2327            @Override
2328            public List<UserNotificationEvent> findByU_DT(long userId, int deliveryType) {
2329                    return findByU_DT(userId, deliveryType, QueryUtil.ALL_POS,
2330                            QueryUtil.ALL_POS, null);
2331            }
2332    
2333            /**
2334             * Returns a range of all the user notification events where userId = &#63; and deliveryType = &#63;.
2335             *
2336             * <p>
2337             * 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 UserNotificationEventModelImpl}. 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.
2338             * </p>
2339             *
2340             * @param userId the user ID
2341             * @param deliveryType the delivery type
2342             * @param start the lower bound of the range of user notification events
2343             * @param end the upper bound of the range of user notification events (not inclusive)
2344             * @return the range of matching user notification events
2345             */
2346            @Override
2347            public List<UserNotificationEvent> findByU_DT(long userId,
2348                    int deliveryType, int start, int end) {
2349                    return findByU_DT(userId, deliveryType, start, end, null);
2350            }
2351    
2352            /**
2353             * Returns an ordered range of all the user notification events where userId = &#63; and deliveryType = &#63;.
2354             *
2355             * <p>
2356             * 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 UserNotificationEventModelImpl}. 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.
2357             * </p>
2358             *
2359             * @param userId the user ID
2360             * @param deliveryType the delivery type
2361             * @param start the lower bound of the range of user notification events
2362             * @param end the upper bound of the range of user notification events (not inclusive)
2363             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2364             * @return the ordered range of matching user notification events
2365             */
2366            @Override
2367            public List<UserNotificationEvent> findByU_DT(long userId,
2368                    int deliveryType, int start, int end,
2369                    OrderByComparator<UserNotificationEvent> orderByComparator) {
2370                    return findByU_DT(userId, deliveryType, start, end, orderByComparator,
2371                            true);
2372            }
2373    
2374            /**
2375             * Returns an ordered range of all the user notification events where userId = &#63; and deliveryType = &#63;.
2376             *
2377             * <p>
2378             * 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 UserNotificationEventModelImpl}. 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.
2379             * </p>
2380             *
2381             * @param userId the user ID
2382             * @param deliveryType the delivery type
2383             * @param start the lower bound of the range of user notification events
2384             * @param end the upper bound of the range of user notification events (not inclusive)
2385             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2386             * @param retrieveFromCache whether to retrieve from the finder cache
2387             * @return the ordered range of matching user notification events
2388             */
2389            @Override
2390            public List<UserNotificationEvent> findByU_DT(long userId,
2391                    int deliveryType, int start, int end,
2392                    OrderByComparator<UserNotificationEvent> orderByComparator,
2393                    boolean retrieveFromCache) {
2394                    boolean pagination = true;
2395                    FinderPath finderPath = null;
2396                    Object[] finderArgs = null;
2397    
2398                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2399                                    (orderByComparator == null)) {
2400                            pagination = false;
2401                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT;
2402                            finderArgs = new Object[] { userId, deliveryType };
2403                    }
2404                    else {
2405                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_DT;
2406                            finderArgs = new Object[] {
2407                                            userId, deliveryType,
2408                                            
2409                                            start, end, orderByComparator
2410                                    };
2411                    }
2412    
2413                    List<UserNotificationEvent> list = null;
2414    
2415                    if (retrieveFromCache) {
2416                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
2417                                            finderArgs, this);
2418    
2419                            if ((list != null) && !list.isEmpty()) {
2420                                    for (UserNotificationEvent userNotificationEvent : list) {
2421                                            if ((userId != userNotificationEvent.getUserId()) ||
2422                                                            (deliveryType != userNotificationEvent.getDeliveryType())) {
2423                                                    list = null;
2424    
2425                                                    break;
2426                                            }
2427                                    }
2428                            }
2429                    }
2430    
2431                    if (list == null) {
2432                            StringBundler query = null;
2433    
2434                            if (orderByComparator != null) {
2435                                    query = new StringBundler(4 +
2436                                                    (orderByComparator.getOrderByFields().length * 3));
2437                            }
2438                            else {
2439                                    query = new StringBundler(4);
2440                            }
2441    
2442                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
2443    
2444                            query.append(_FINDER_COLUMN_U_DT_USERID_2);
2445    
2446                            query.append(_FINDER_COLUMN_U_DT_DELIVERYTYPE_2);
2447    
2448                            if (orderByComparator != null) {
2449                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2450                                            orderByComparator);
2451                            }
2452                            else
2453                             if (pagination) {
2454                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
2455                            }
2456    
2457                            String sql = query.toString();
2458    
2459                            Session session = null;
2460    
2461                            try {
2462                                    session = openSession();
2463    
2464                                    Query q = session.createQuery(sql);
2465    
2466                                    QueryPos qPos = QueryPos.getInstance(q);
2467    
2468                                    qPos.add(userId);
2469    
2470                                    qPos.add(deliveryType);
2471    
2472                                    if (!pagination) {
2473                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
2474                                                            getDialect(), start, end, false);
2475    
2476                                            Collections.sort(list);
2477    
2478                                            list = Collections.unmodifiableList(list);
2479                                    }
2480                                    else {
2481                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
2482                                                            getDialect(), start, end);
2483                                    }
2484    
2485                                    cacheResult(list);
2486    
2487                                    finderCache.putResult(finderPath, finderArgs, list);
2488                            }
2489                            catch (Exception e) {
2490                                    finderCache.removeResult(finderPath, finderArgs);
2491    
2492                                    throw processException(e);
2493                            }
2494                            finally {
2495                                    closeSession(session);
2496                            }
2497                    }
2498    
2499                    return list;
2500            }
2501    
2502            /**
2503             * Returns the first user notification event in the ordered set where userId = &#63; and deliveryType = &#63;.
2504             *
2505             * @param userId the user ID
2506             * @param deliveryType the delivery type
2507             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2508             * @return the first matching user notification event
2509             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
2510             */
2511            @Override
2512            public UserNotificationEvent findByU_DT_First(long userId,
2513                    int deliveryType,
2514                    OrderByComparator<UserNotificationEvent> orderByComparator)
2515                    throws NoSuchUserNotificationEventException {
2516                    UserNotificationEvent userNotificationEvent = fetchByU_DT_First(userId,
2517                                    deliveryType, orderByComparator);
2518    
2519                    if (userNotificationEvent != null) {
2520                            return userNotificationEvent;
2521                    }
2522    
2523                    StringBundler msg = new StringBundler(6);
2524    
2525                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2526    
2527                    msg.append("userId=");
2528                    msg.append(userId);
2529    
2530                    msg.append(", deliveryType=");
2531                    msg.append(deliveryType);
2532    
2533                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2534    
2535                    throw new NoSuchUserNotificationEventException(msg.toString());
2536            }
2537    
2538            /**
2539             * Returns the first user notification event in the ordered set where userId = &#63; and deliveryType = &#63;.
2540             *
2541             * @param userId the user ID
2542             * @param deliveryType the delivery type
2543             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2544             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
2545             */
2546            @Override
2547            public UserNotificationEvent fetchByU_DT_First(long userId,
2548                    int deliveryType,
2549                    OrderByComparator<UserNotificationEvent> orderByComparator) {
2550                    List<UserNotificationEvent> list = findByU_DT(userId, deliveryType, 0,
2551                                    1, orderByComparator);
2552    
2553                    if (!list.isEmpty()) {
2554                            return list.get(0);
2555                    }
2556    
2557                    return null;
2558            }
2559    
2560            /**
2561             * Returns the last user notification event in the ordered set where userId = &#63; and deliveryType = &#63;.
2562             *
2563             * @param userId the user ID
2564             * @param deliveryType the delivery type
2565             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2566             * @return the last matching user notification event
2567             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
2568             */
2569            @Override
2570            public UserNotificationEvent findByU_DT_Last(long userId, int deliveryType,
2571                    OrderByComparator<UserNotificationEvent> orderByComparator)
2572                    throws NoSuchUserNotificationEventException {
2573                    UserNotificationEvent userNotificationEvent = fetchByU_DT_Last(userId,
2574                                    deliveryType, orderByComparator);
2575    
2576                    if (userNotificationEvent != null) {
2577                            return userNotificationEvent;
2578                    }
2579    
2580                    StringBundler msg = new StringBundler(6);
2581    
2582                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2583    
2584                    msg.append("userId=");
2585                    msg.append(userId);
2586    
2587                    msg.append(", deliveryType=");
2588                    msg.append(deliveryType);
2589    
2590                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2591    
2592                    throw new NoSuchUserNotificationEventException(msg.toString());
2593            }
2594    
2595            /**
2596             * Returns the last user notification event in the ordered set where userId = &#63; and deliveryType = &#63;.
2597             *
2598             * @param userId the user ID
2599             * @param deliveryType the delivery type
2600             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2601             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
2602             */
2603            @Override
2604            public UserNotificationEvent fetchByU_DT_Last(long userId,
2605                    int deliveryType,
2606                    OrderByComparator<UserNotificationEvent> orderByComparator) {
2607                    int count = countByU_DT(userId, deliveryType);
2608    
2609                    if (count == 0) {
2610                            return null;
2611                    }
2612    
2613                    List<UserNotificationEvent> list = findByU_DT(userId, deliveryType,
2614                                    count - 1, count, orderByComparator);
2615    
2616                    if (!list.isEmpty()) {
2617                            return list.get(0);
2618                    }
2619    
2620                    return null;
2621            }
2622    
2623            /**
2624             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63; and deliveryType = &#63;.
2625             *
2626             * @param userNotificationEventId the primary key of the current user notification event
2627             * @param userId the user ID
2628             * @param deliveryType the delivery type
2629             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2630             * @return the previous, current, and next user notification event
2631             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
2632             */
2633            @Override
2634            public UserNotificationEvent[] findByU_DT_PrevAndNext(
2635                    long userNotificationEventId, long userId, int deliveryType,
2636                    OrderByComparator<UserNotificationEvent> orderByComparator)
2637                    throws NoSuchUserNotificationEventException {
2638                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
2639    
2640                    Session session = null;
2641    
2642                    try {
2643                            session = openSession();
2644    
2645                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
2646    
2647                            array[0] = getByU_DT_PrevAndNext(session, userNotificationEvent,
2648                                            userId, deliveryType, orderByComparator, true);
2649    
2650                            array[1] = userNotificationEvent;
2651    
2652                            array[2] = getByU_DT_PrevAndNext(session, userNotificationEvent,
2653                                            userId, deliveryType, orderByComparator, false);
2654    
2655                            return array;
2656                    }
2657                    catch (Exception e) {
2658                            throw processException(e);
2659                    }
2660                    finally {
2661                            closeSession(session);
2662                    }
2663            }
2664    
2665            protected UserNotificationEvent getByU_DT_PrevAndNext(Session session,
2666                    UserNotificationEvent userNotificationEvent, long userId,
2667                    int deliveryType,
2668                    OrderByComparator<UserNotificationEvent> orderByComparator,
2669                    boolean previous) {
2670                    StringBundler query = null;
2671    
2672                    if (orderByComparator != null) {
2673                            query = new StringBundler(6 +
2674                                            (orderByComparator.getOrderByFields().length * 6));
2675                    }
2676                    else {
2677                            query = new StringBundler(3);
2678                    }
2679    
2680                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
2681    
2682                    query.append(_FINDER_COLUMN_U_DT_USERID_2);
2683    
2684                    query.append(_FINDER_COLUMN_U_DT_DELIVERYTYPE_2);
2685    
2686                    if (orderByComparator != null) {
2687                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2688    
2689                            if (orderByConditionFields.length > 0) {
2690                                    query.append(WHERE_AND);
2691                            }
2692    
2693                            for (int i = 0; i < orderByConditionFields.length; i++) {
2694                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2695                                    query.append(orderByConditionFields[i]);
2696    
2697                                    if ((i + 1) < orderByConditionFields.length) {
2698                                            if (orderByComparator.isAscending() ^ previous) {
2699                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2700                                            }
2701                                            else {
2702                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2703                                            }
2704                                    }
2705                                    else {
2706                                            if (orderByComparator.isAscending() ^ previous) {
2707                                                    query.append(WHERE_GREATER_THAN);
2708                                            }
2709                                            else {
2710                                                    query.append(WHERE_LESSER_THAN);
2711                                            }
2712                                    }
2713                            }
2714    
2715                            query.append(ORDER_BY_CLAUSE);
2716    
2717                            String[] orderByFields = orderByComparator.getOrderByFields();
2718    
2719                            for (int i = 0; i < orderByFields.length; i++) {
2720                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2721                                    query.append(orderByFields[i]);
2722    
2723                                    if ((i + 1) < orderByFields.length) {
2724                                            if (orderByComparator.isAscending() ^ previous) {
2725                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2726                                            }
2727                                            else {
2728                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2729                                            }
2730                                    }
2731                                    else {
2732                                            if (orderByComparator.isAscending() ^ previous) {
2733                                                    query.append(ORDER_BY_ASC);
2734                                            }
2735                                            else {
2736                                                    query.append(ORDER_BY_DESC);
2737                                            }
2738                                    }
2739                            }
2740                    }
2741                    else {
2742                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
2743                    }
2744    
2745                    String sql = query.toString();
2746    
2747                    Query q = session.createQuery(sql);
2748    
2749                    q.setFirstResult(0);
2750                    q.setMaxResults(2);
2751    
2752                    QueryPos qPos = QueryPos.getInstance(q);
2753    
2754                    qPos.add(userId);
2755    
2756                    qPos.add(deliveryType);
2757    
2758                    if (orderByComparator != null) {
2759                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
2760    
2761                            for (Object value : values) {
2762                                    qPos.add(value);
2763                            }
2764                    }
2765    
2766                    List<UserNotificationEvent> list = q.list();
2767    
2768                    if (list.size() == 2) {
2769                            return list.get(1);
2770                    }
2771                    else {
2772                            return null;
2773                    }
2774            }
2775    
2776            /**
2777             * Removes all the user notification events where userId = &#63; and deliveryType = &#63; from the database.
2778             *
2779             * @param userId the user ID
2780             * @param deliveryType the delivery type
2781             */
2782            @Override
2783            public void removeByU_DT(long userId, int deliveryType) {
2784                    for (UserNotificationEvent userNotificationEvent : findByU_DT(userId,
2785                                    deliveryType, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2786                            remove(userNotificationEvent);
2787                    }
2788            }
2789    
2790            /**
2791             * Returns the number of user notification events where userId = &#63; and deliveryType = &#63;.
2792             *
2793             * @param userId the user ID
2794             * @param deliveryType the delivery type
2795             * @return the number of matching user notification events
2796             */
2797            @Override
2798            public int countByU_DT(long userId, int deliveryType) {
2799                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_DT;
2800    
2801                    Object[] finderArgs = new Object[] { userId, deliveryType };
2802    
2803                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2804    
2805                    if (count == null) {
2806                            StringBundler query = new StringBundler(3);
2807    
2808                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
2809    
2810                            query.append(_FINDER_COLUMN_U_DT_USERID_2);
2811    
2812                            query.append(_FINDER_COLUMN_U_DT_DELIVERYTYPE_2);
2813    
2814                            String sql = query.toString();
2815    
2816                            Session session = null;
2817    
2818                            try {
2819                                    session = openSession();
2820    
2821                                    Query q = session.createQuery(sql);
2822    
2823                                    QueryPos qPos = QueryPos.getInstance(q);
2824    
2825                                    qPos.add(userId);
2826    
2827                                    qPos.add(deliveryType);
2828    
2829                                    count = (Long)q.uniqueResult();
2830    
2831                                    finderCache.putResult(finderPath, finderArgs, count);
2832                            }
2833                            catch (Exception e) {
2834                                    finderCache.removeResult(finderPath, finderArgs);
2835    
2836                                    throw processException(e);
2837                            }
2838                            finally {
2839                                    closeSession(session);
2840                            }
2841                    }
2842    
2843                    return count.intValue();
2844            }
2845    
2846            private static final String _FINDER_COLUMN_U_DT_USERID_2 = "userNotificationEvent.userId = ? AND ";
2847            private static final String _FINDER_COLUMN_U_DT_DELIVERYTYPE_2 = "userNotificationEvent.deliveryType = ?";
2848            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_D = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2849                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
2850                            UserNotificationEventImpl.class,
2851                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_D",
2852                            new String[] {
2853                                    Long.class.getName(), Boolean.class.getName(),
2854                                    
2855                            Integer.class.getName(), Integer.class.getName(),
2856                                    OrderByComparator.class.getName()
2857                            });
2858            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_D = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2859                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
2860                            UserNotificationEventImpl.class,
2861                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_D",
2862                            new String[] { Long.class.getName(), Boolean.class.getName() },
2863                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
2864                            UserNotificationEventModelImpl.DELIVERED_COLUMN_BITMASK |
2865                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
2866            public static final FinderPath FINDER_PATH_COUNT_BY_U_D = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2867                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
2868                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_D",
2869                            new String[] { Long.class.getName(), Boolean.class.getName() });
2870    
2871            /**
2872             * Returns all the user notification events where userId = &#63; and delivered = &#63;.
2873             *
2874             * @param userId the user ID
2875             * @param delivered the delivered
2876             * @return the matching user notification events
2877             */
2878            @Override
2879            public List<UserNotificationEvent> findByU_D(long userId, boolean delivered) {
2880                    return findByU_D(userId, delivered, QueryUtil.ALL_POS,
2881                            QueryUtil.ALL_POS, null);
2882            }
2883    
2884            /**
2885             * Returns a range of all the user notification events where userId = &#63; and delivered = &#63;.
2886             *
2887             * <p>
2888             * 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 UserNotificationEventModelImpl}. 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.
2889             * </p>
2890             *
2891             * @param userId the user ID
2892             * @param delivered the delivered
2893             * @param start the lower bound of the range of user notification events
2894             * @param end the upper bound of the range of user notification events (not inclusive)
2895             * @return the range of matching user notification events
2896             */
2897            @Override
2898            public List<UserNotificationEvent> findByU_D(long userId,
2899                    boolean delivered, int start, int end) {
2900                    return findByU_D(userId, delivered, start, end, null);
2901            }
2902    
2903            /**
2904             * Returns an ordered range of all the user notification events where userId = &#63; and delivered = &#63;.
2905             *
2906             * <p>
2907             * 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 UserNotificationEventModelImpl}. 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.
2908             * </p>
2909             *
2910             * @param userId the user ID
2911             * @param delivered the delivered
2912             * @param start the lower bound of the range of user notification events
2913             * @param end the upper bound of the range of user notification events (not inclusive)
2914             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2915             * @return the ordered range of matching user notification events
2916             */
2917            @Override
2918            public List<UserNotificationEvent> findByU_D(long userId,
2919                    boolean delivered, int start, int end,
2920                    OrderByComparator<UserNotificationEvent> orderByComparator) {
2921                    return findByU_D(userId, delivered, start, end, orderByComparator, true);
2922            }
2923    
2924            /**
2925             * Returns an ordered range of all the user notification events where userId = &#63; and delivered = &#63;.
2926             *
2927             * <p>
2928             * 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 UserNotificationEventModelImpl}. 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.
2929             * </p>
2930             *
2931             * @param userId the user ID
2932             * @param delivered the delivered
2933             * @param start the lower bound of the range of user notification events
2934             * @param end the upper bound of the range of user notification events (not inclusive)
2935             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2936             * @param retrieveFromCache whether to retrieve from the finder cache
2937             * @return the ordered range of matching user notification events
2938             */
2939            @Override
2940            public List<UserNotificationEvent> findByU_D(long userId,
2941                    boolean delivered, int start, int end,
2942                    OrderByComparator<UserNotificationEvent> orderByComparator,
2943                    boolean retrieveFromCache) {
2944                    boolean pagination = true;
2945                    FinderPath finderPath = null;
2946                    Object[] finderArgs = null;
2947    
2948                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2949                                    (orderByComparator == null)) {
2950                            pagination = false;
2951                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_D;
2952                            finderArgs = new Object[] { userId, delivered };
2953                    }
2954                    else {
2955                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_D;
2956                            finderArgs = new Object[] {
2957                                            userId, delivered,
2958                                            
2959                                            start, end, orderByComparator
2960                                    };
2961                    }
2962    
2963                    List<UserNotificationEvent> list = null;
2964    
2965                    if (retrieveFromCache) {
2966                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
2967                                            finderArgs, this);
2968    
2969                            if ((list != null) && !list.isEmpty()) {
2970                                    for (UserNotificationEvent userNotificationEvent : list) {
2971                                            if ((userId != userNotificationEvent.getUserId()) ||
2972                                                            (delivered != userNotificationEvent.getDelivered())) {
2973                                                    list = null;
2974    
2975                                                    break;
2976                                            }
2977                                    }
2978                            }
2979                    }
2980    
2981                    if (list == null) {
2982                            StringBundler query = null;
2983    
2984                            if (orderByComparator != null) {
2985                                    query = new StringBundler(4 +
2986                                                    (orderByComparator.getOrderByFields().length * 3));
2987                            }
2988                            else {
2989                                    query = new StringBundler(4);
2990                            }
2991    
2992                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
2993    
2994                            query.append(_FINDER_COLUMN_U_D_USERID_2);
2995    
2996                            query.append(_FINDER_COLUMN_U_D_DELIVERED_2);
2997    
2998                            if (orderByComparator != null) {
2999                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3000                                            orderByComparator);
3001                            }
3002                            else
3003                             if (pagination) {
3004                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
3005                            }
3006    
3007                            String sql = query.toString();
3008    
3009                            Session session = null;
3010    
3011                            try {
3012                                    session = openSession();
3013    
3014                                    Query q = session.createQuery(sql);
3015    
3016                                    QueryPos qPos = QueryPos.getInstance(q);
3017    
3018                                    qPos.add(userId);
3019    
3020                                    qPos.add(delivered);
3021    
3022                                    if (!pagination) {
3023                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
3024                                                            getDialect(), start, end, false);
3025    
3026                                            Collections.sort(list);
3027    
3028                                            list = Collections.unmodifiableList(list);
3029                                    }
3030                                    else {
3031                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
3032                                                            getDialect(), start, end);
3033                                    }
3034    
3035                                    cacheResult(list);
3036    
3037                                    finderCache.putResult(finderPath, finderArgs, list);
3038                            }
3039                            catch (Exception e) {
3040                                    finderCache.removeResult(finderPath, finderArgs);
3041    
3042                                    throw processException(e);
3043                            }
3044                            finally {
3045                                    closeSession(session);
3046                            }
3047                    }
3048    
3049                    return list;
3050            }
3051    
3052            /**
3053             * Returns the first user notification event in the ordered set where userId = &#63; and delivered = &#63;.
3054             *
3055             * @param userId the user ID
3056             * @param delivered the delivered
3057             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3058             * @return the first matching user notification event
3059             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
3060             */
3061            @Override
3062            public UserNotificationEvent findByU_D_First(long userId,
3063                    boolean delivered,
3064                    OrderByComparator<UserNotificationEvent> orderByComparator)
3065                    throws NoSuchUserNotificationEventException {
3066                    UserNotificationEvent userNotificationEvent = fetchByU_D_First(userId,
3067                                    delivered, orderByComparator);
3068    
3069                    if (userNotificationEvent != null) {
3070                            return userNotificationEvent;
3071                    }
3072    
3073                    StringBundler msg = new StringBundler(6);
3074    
3075                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3076    
3077                    msg.append("userId=");
3078                    msg.append(userId);
3079    
3080                    msg.append(", delivered=");
3081                    msg.append(delivered);
3082    
3083                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3084    
3085                    throw new NoSuchUserNotificationEventException(msg.toString());
3086            }
3087    
3088            /**
3089             * Returns the first user notification event in the ordered set where userId = &#63; and delivered = &#63;.
3090             *
3091             * @param userId the user ID
3092             * @param delivered the delivered
3093             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3094             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
3095             */
3096            @Override
3097            public UserNotificationEvent fetchByU_D_First(long userId,
3098                    boolean delivered,
3099                    OrderByComparator<UserNotificationEvent> orderByComparator) {
3100                    List<UserNotificationEvent> list = findByU_D(userId, delivered, 0, 1,
3101                                    orderByComparator);
3102    
3103                    if (!list.isEmpty()) {
3104                            return list.get(0);
3105                    }
3106    
3107                    return null;
3108            }
3109    
3110            /**
3111             * Returns the last user notification event in the ordered set where userId = &#63; and delivered = &#63;.
3112             *
3113             * @param userId the user ID
3114             * @param delivered the delivered
3115             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3116             * @return the last matching user notification event
3117             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
3118             */
3119            @Override
3120            public UserNotificationEvent findByU_D_Last(long userId, boolean delivered,
3121                    OrderByComparator<UserNotificationEvent> orderByComparator)
3122                    throws NoSuchUserNotificationEventException {
3123                    UserNotificationEvent userNotificationEvent = fetchByU_D_Last(userId,
3124                                    delivered, orderByComparator);
3125    
3126                    if (userNotificationEvent != null) {
3127                            return userNotificationEvent;
3128                    }
3129    
3130                    StringBundler msg = new StringBundler(6);
3131    
3132                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3133    
3134                    msg.append("userId=");
3135                    msg.append(userId);
3136    
3137                    msg.append(", delivered=");
3138                    msg.append(delivered);
3139    
3140                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3141    
3142                    throw new NoSuchUserNotificationEventException(msg.toString());
3143            }
3144    
3145            /**
3146             * Returns the last user notification event in the ordered set where userId = &#63; and delivered = &#63;.
3147             *
3148             * @param userId the user ID
3149             * @param delivered the delivered
3150             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3151             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
3152             */
3153            @Override
3154            public UserNotificationEvent fetchByU_D_Last(long userId,
3155                    boolean delivered,
3156                    OrderByComparator<UserNotificationEvent> orderByComparator) {
3157                    int count = countByU_D(userId, delivered);
3158    
3159                    if (count == 0) {
3160                            return null;
3161                    }
3162    
3163                    List<UserNotificationEvent> list = findByU_D(userId, delivered,
3164                                    count - 1, count, orderByComparator);
3165    
3166                    if (!list.isEmpty()) {
3167                            return list.get(0);
3168                    }
3169    
3170                    return null;
3171            }
3172    
3173            /**
3174             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63; and delivered = &#63;.
3175             *
3176             * @param userNotificationEventId the primary key of the current user notification event
3177             * @param userId the user ID
3178             * @param delivered the delivered
3179             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3180             * @return the previous, current, and next user notification event
3181             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
3182             */
3183            @Override
3184            public UserNotificationEvent[] findByU_D_PrevAndNext(
3185                    long userNotificationEventId, long userId, boolean delivered,
3186                    OrderByComparator<UserNotificationEvent> orderByComparator)
3187                    throws NoSuchUserNotificationEventException {
3188                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
3189    
3190                    Session session = null;
3191    
3192                    try {
3193                            session = openSession();
3194    
3195                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
3196    
3197                            array[0] = getByU_D_PrevAndNext(session, userNotificationEvent,
3198                                            userId, delivered, orderByComparator, true);
3199    
3200                            array[1] = userNotificationEvent;
3201    
3202                            array[2] = getByU_D_PrevAndNext(session, userNotificationEvent,
3203                                            userId, delivered, orderByComparator, false);
3204    
3205                            return array;
3206                    }
3207                    catch (Exception e) {
3208                            throw processException(e);
3209                    }
3210                    finally {
3211                            closeSession(session);
3212                    }
3213            }
3214    
3215            protected UserNotificationEvent getByU_D_PrevAndNext(Session session,
3216                    UserNotificationEvent userNotificationEvent, long userId,
3217                    boolean delivered,
3218                    OrderByComparator<UserNotificationEvent> orderByComparator,
3219                    boolean previous) {
3220                    StringBundler query = null;
3221    
3222                    if (orderByComparator != null) {
3223                            query = new StringBundler(6 +
3224                                            (orderByComparator.getOrderByFields().length * 6));
3225                    }
3226                    else {
3227                            query = new StringBundler(3);
3228                    }
3229    
3230                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
3231    
3232                    query.append(_FINDER_COLUMN_U_D_USERID_2);
3233    
3234                    query.append(_FINDER_COLUMN_U_D_DELIVERED_2);
3235    
3236                    if (orderByComparator != null) {
3237                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3238    
3239                            if (orderByConditionFields.length > 0) {
3240                                    query.append(WHERE_AND);
3241                            }
3242    
3243                            for (int i = 0; i < orderByConditionFields.length; i++) {
3244                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3245                                    query.append(orderByConditionFields[i]);
3246    
3247                                    if ((i + 1) < orderByConditionFields.length) {
3248                                            if (orderByComparator.isAscending() ^ previous) {
3249                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3250                                            }
3251                                            else {
3252                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3253                                            }
3254                                    }
3255                                    else {
3256                                            if (orderByComparator.isAscending() ^ previous) {
3257                                                    query.append(WHERE_GREATER_THAN);
3258                                            }
3259                                            else {
3260                                                    query.append(WHERE_LESSER_THAN);
3261                                            }
3262                                    }
3263                            }
3264    
3265                            query.append(ORDER_BY_CLAUSE);
3266    
3267                            String[] orderByFields = orderByComparator.getOrderByFields();
3268    
3269                            for (int i = 0; i < orderByFields.length; i++) {
3270                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3271                                    query.append(orderByFields[i]);
3272    
3273                                    if ((i + 1) < orderByFields.length) {
3274                                            if (orderByComparator.isAscending() ^ previous) {
3275                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3276                                            }
3277                                            else {
3278                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3279                                            }
3280                                    }
3281                                    else {
3282                                            if (orderByComparator.isAscending() ^ previous) {
3283                                                    query.append(ORDER_BY_ASC);
3284                                            }
3285                                            else {
3286                                                    query.append(ORDER_BY_DESC);
3287                                            }
3288                                    }
3289                            }
3290                    }
3291                    else {
3292                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
3293                    }
3294    
3295                    String sql = query.toString();
3296    
3297                    Query q = session.createQuery(sql);
3298    
3299                    q.setFirstResult(0);
3300                    q.setMaxResults(2);
3301    
3302                    QueryPos qPos = QueryPos.getInstance(q);
3303    
3304                    qPos.add(userId);
3305    
3306                    qPos.add(delivered);
3307    
3308                    if (orderByComparator != null) {
3309                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
3310    
3311                            for (Object value : values) {
3312                                    qPos.add(value);
3313                            }
3314                    }
3315    
3316                    List<UserNotificationEvent> list = q.list();
3317    
3318                    if (list.size() == 2) {
3319                            return list.get(1);
3320                    }
3321                    else {
3322                            return null;
3323                    }
3324            }
3325    
3326            /**
3327             * Removes all the user notification events where userId = &#63; and delivered = &#63; from the database.
3328             *
3329             * @param userId the user ID
3330             * @param delivered the delivered
3331             */
3332            @Override
3333            public void removeByU_D(long userId, boolean delivered) {
3334                    for (UserNotificationEvent userNotificationEvent : findByU_D(userId,
3335                                    delivered, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3336                            remove(userNotificationEvent);
3337                    }
3338            }
3339    
3340            /**
3341             * Returns the number of user notification events where userId = &#63; and delivered = &#63;.
3342             *
3343             * @param userId the user ID
3344             * @param delivered the delivered
3345             * @return the number of matching user notification events
3346             */
3347            @Override
3348            public int countByU_D(long userId, boolean delivered) {
3349                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_D;
3350    
3351                    Object[] finderArgs = new Object[] { userId, delivered };
3352    
3353                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3354    
3355                    if (count == null) {
3356                            StringBundler query = new StringBundler(3);
3357    
3358                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
3359    
3360                            query.append(_FINDER_COLUMN_U_D_USERID_2);
3361    
3362                            query.append(_FINDER_COLUMN_U_D_DELIVERED_2);
3363    
3364                            String sql = query.toString();
3365    
3366                            Session session = null;
3367    
3368                            try {
3369                                    session = openSession();
3370    
3371                                    Query q = session.createQuery(sql);
3372    
3373                                    QueryPos qPos = QueryPos.getInstance(q);
3374    
3375                                    qPos.add(userId);
3376    
3377                                    qPos.add(delivered);
3378    
3379                                    count = (Long)q.uniqueResult();
3380    
3381                                    finderCache.putResult(finderPath, finderArgs, count);
3382                            }
3383                            catch (Exception e) {
3384                                    finderCache.removeResult(finderPath, finderArgs);
3385    
3386                                    throw processException(e);
3387                            }
3388                            finally {
3389                                    closeSession(session);
3390                            }
3391                    }
3392    
3393                    return count.intValue();
3394            }
3395    
3396            private static final String _FINDER_COLUMN_U_D_USERID_2 = "userNotificationEvent.userId = ? AND ";
3397            private static final String _FINDER_COLUMN_U_D_DELIVERED_2 = "userNotificationEvent.delivered = ?";
3398            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
3399                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
3400                            UserNotificationEventImpl.class,
3401                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_A",
3402                            new String[] {
3403                                    Long.class.getName(), Boolean.class.getName(),
3404                                    
3405                            Integer.class.getName(), Integer.class.getName(),
3406                                    OrderByComparator.class.getName()
3407                            });
3408            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
3409                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
3410                            UserNotificationEventImpl.class,
3411                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_A",
3412                            new String[] { Long.class.getName(), Boolean.class.getName() },
3413                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
3414                            UserNotificationEventModelImpl.ARCHIVED_COLUMN_BITMASK |
3415                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
3416            public static final FinderPath FINDER_PATH_COUNT_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
3417                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
3418                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_A",
3419                            new String[] { Long.class.getName(), Boolean.class.getName() });
3420    
3421            /**
3422             * Returns all the user notification events where userId = &#63; and archived = &#63;.
3423             *
3424             * @param userId the user ID
3425             * @param archived the archived
3426             * @return the matching user notification events
3427             */
3428            @Override
3429            public List<UserNotificationEvent> findByU_A(long userId, boolean archived) {
3430                    return findByU_A(userId, archived, QueryUtil.ALL_POS,
3431                            QueryUtil.ALL_POS, null);
3432            }
3433    
3434            /**
3435             * Returns a range of all the user notification events where userId = &#63; and archived = &#63;.
3436             *
3437             * <p>
3438             * 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 UserNotificationEventModelImpl}. 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.
3439             * </p>
3440             *
3441             * @param userId the user ID
3442             * @param archived the archived
3443             * @param start the lower bound of the range of user notification events
3444             * @param end the upper bound of the range of user notification events (not inclusive)
3445             * @return the range of matching user notification events
3446             */
3447            @Override
3448            public List<UserNotificationEvent> findByU_A(long userId, boolean archived,
3449                    int start, int end) {
3450                    return findByU_A(userId, archived, start, end, null);
3451            }
3452    
3453            /**
3454             * Returns an ordered range of all the user notification events where userId = &#63; and archived = &#63;.
3455             *
3456             * <p>
3457             * 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 UserNotificationEventModelImpl}. 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.
3458             * </p>
3459             *
3460             * @param userId the user ID
3461             * @param archived the archived
3462             * @param start the lower bound of the range of user notification events
3463             * @param end the upper bound of the range of user notification events (not inclusive)
3464             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3465             * @return the ordered range of matching user notification events
3466             */
3467            @Override
3468            public List<UserNotificationEvent> findByU_A(long userId, boolean archived,
3469                    int start, int end,
3470                    OrderByComparator<UserNotificationEvent> orderByComparator) {
3471                    return findByU_A(userId, archived, start, end, orderByComparator, true);
3472            }
3473    
3474            /**
3475             * Returns an ordered range of all the user notification events where userId = &#63; and archived = &#63;.
3476             *
3477             * <p>
3478             * 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 UserNotificationEventModelImpl}. 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.
3479             * </p>
3480             *
3481             * @param userId the user ID
3482             * @param archived the archived
3483             * @param start the lower bound of the range of user notification events
3484             * @param end the upper bound of the range of user notification events (not inclusive)
3485             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3486             * @param retrieveFromCache whether to retrieve from the finder cache
3487             * @return the ordered range of matching user notification events
3488             */
3489            @Override
3490            public List<UserNotificationEvent> findByU_A(long userId, boolean archived,
3491                    int start, int end,
3492                    OrderByComparator<UserNotificationEvent> orderByComparator,
3493                    boolean retrieveFromCache) {
3494                    boolean pagination = true;
3495                    FinderPath finderPath = null;
3496                    Object[] finderArgs = null;
3497    
3498                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3499                                    (orderByComparator == null)) {
3500                            pagination = false;
3501                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A;
3502                            finderArgs = new Object[] { userId, archived };
3503                    }
3504                    else {
3505                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_A;
3506                            finderArgs = new Object[] {
3507                                            userId, archived,
3508                                            
3509                                            start, end, orderByComparator
3510                                    };
3511                    }
3512    
3513                    List<UserNotificationEvent> list = null;
3514    
3515                    if (retrieveFromCache) {
3516                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
3517                                            finderArgs, this);
3518    
3519                            if ((list != null) && !list.isEmpty()) {
3520                                    for (UserNotificationEvent userNotificationEvent : list) {
3521                                            if ((userId != userNotificationEvent.getUserId()) ||
3522                                                            (archived != userNotificationEvent.getArchived())) {
3523                                                    list = null;
3524    
3525                                                    break;
3526                                            }
3527                                    }
3528                            }
3529                    }
3530    
3531                    if (list == null) {
3532                            StringBundler query = null;
3533    
3534                            if (orderByComparator != null) {
3535                                    query = new StringBundler(4 +
3536                                                    (orderByComparator.getOrderByFields().length * 3));
3537                            }
3538                            else {
3539                                    query = new StringBundler(4);
3540                            }
3541    
3542                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
3543    
3544                            query.append(_FINDER_COLUMN_U_A_USERID_2);
3545    
3546                            query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
3547    
3548                            if (orderByComparator != null) {
3549                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3550                                            orderByComparator);
3551                            }
3552                            else
3553                             if (pagination) {
3554                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
3555                            }
3556    
3557                            String sql = query.toString();
3558    
3559                            Session session = null;
3560    
3561                            try {
3562                                    session = openSession();
3563    
3564                                    Query q = session.createQuery(sql);
3565    
3566                                    QueryPos qPos = QueryPos.getInstance(q);
3567    
3568                                    qPos.add(userId);
3569    
3570                                    qPos.add(archived);
3571    
3572                                    if (!pagination) {
3573                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
3574                                                            getDialect(), start, end, false);
3575    
3576                                            Collections.sort(list);
3577    
3578                                            list = Collections.unmodifiableList(list);
3579                                    }
3580                                    else {
3581                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
3582                                                            getDialect(), start, end);
3583                                    }
3584    
3585                                    cacheResult(list);
3586    
3587                                    finderCache.putResult(finderPath, finderArgs, list);
3588                            }
3589                            catch (Exception e) {
3590                                    finderCache.removeResult(finderPath, finderArgs);
3591    
3592                                    throw processException(e);
3593                            }
3594                            finally {
3595                                    closeSession(session);
3596                            }
3597                    }
3598    
3599                    return list;
3600            }
3601    
3602            /**
3603             * Returns the first user notification event in the ordered set where userId = &#63; and archived = &#63;.
3604             *
3605             * @param userId the user ID
3606             * @param archived the archived
3607             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3608             * @return the first matching user notification event
3609             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
3610             */
3611            @Override
3612            public UserNotificationEvent findByU_A_First(long userId, boolean archived,
3613                    OrderByComparator<UserNotificationEvent> orderByComparator)
3614                    throws NoSuchUserNotificationEventException {
3615                    UserNotificationEvent userNotificationEvent = fetchByU_A_First(userId,
3616                                    archived, orderByComparator);
3617    
3618                    if (userNotificationEvent != null) {
3619                            return userNotificationEvent;
3620                    }
3621    
3622                    StringBundler msg = new StringBundler(6);
3623    
3624                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3625    
3626                    msg.append("userId=");
3627                    msg.append(userId);
3628    
3629                    msg.append(", archived=");
3630                    msg.append(archived);
3631    
3632                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3633    
3634                    throw new NoSuchUserNotificationEventException(msg.toString());
3635            }
3636    
3637            /**
3638             * Returns the first user notification event in the ordered set where userId = &#63; and archived = &#63;.
3639             *
3640             * @param userId the user ID
3641             * @param archived the archived
3642             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3643             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
3644             */
3645            @Override
3646            public UserNotificationEvent fetchByU_A_First(long userId,
3647                    boolean archived,
3648                    OrderByComparator<UserNotificationEvent> orderByComparator) {
3649                    List<UserNotificationEvent> list = findByU_A(userId, archived, 0, 1,
3650                                    orderByComparator);
3651    
3652                    if (!list.isEmpty()) {
3653                            return list.get(0);
3654                    }
3655    
3656                    return null;
3657            }
3658    
3659            /**
3660             * Returns the last user notification event in the ordered set where userId = &#63; and archived = &#63;.
3661             *
3662             * @param userId the user ID
3663             * @param archived the archived
3664             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3665             * @return the last matching user notification event
3666             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
3667             */
3668            @Override
3669            public UserNotificationEvent findByU_A_Last(long userId, boolean archived,
3670                    OrderByComparator<UserNotificationEvent> orderByComparator)
3671                    throws NoSuchUserNotificationEventException {
3672                    UserNotificationEvent userNotificationEvent = fetchByU_A_Last(userId,
3673                                    archived, orderByComparator);
3674    
3675                    if (userNotificationEvent != null) {
3676                            return userNotificationEvent;
3677                    }
3678    
3679                    StringBundler msg = new StringBundler(6);
3680    
3681                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3682    
3683                    msg.append("userId=");
3684                    msg.append(userId);
3685    
3686                    msg.append(", archived=");
3687                    msg.append(archived);
3688    
3689                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3690    
3691                    throw new NoSuchUserNotificationEventException(msg.toString());
3692            }
3693    
3694            /**
3695             * Returns the last user notification event in the ordered set where userId = &#63; and archived = &#63;.
3696             *
3697             * @param userId the user ID
3698             * @param archived the archived
3699             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3700             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
3701             */
3702            @Override
3703            public UserNotificationEvent fetchByU_A_Last(long userId, boolean archived,
3704                    OrderByComparator<UserNotificationEvent> orderByComparator) {
3705                    int count = countByU_A(userId, archived);
3706    
3707                    if (count == 0) {
3708                            return null;
3709                    }
3710    
3711                    List<UserNotificationEvent> list = findByU_A(userId, archived,
3712                                    count - 1, count, orderByComparator);
3713    
3714                    if (!list.isEmpty()) {
3715                            return list.get(0);
3716                    }
3717    
3718                    return null;
3719            }
3720    
3721            /**
3722             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63; and archived = &#63;.
3723             *
3724             * @param userNotificationEventId the primary key of the current user notification event
3725             * @param userId the user ID
3726             * @param archived the archived
3727             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3728             * @return the previous, current, and next user notification event
3729             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
3730             */
3731            @Override
3732            public UserNotificationEvent[] findByU_A_PrevAndNext(
3733                    long userNotificationEventId, long userId, boolean archived,
3734                    OrderByComparator<UserNotificationEvent> orderByComparator)
3735                    throws NoSuchUserNotificationEventException {
3736                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
3737    
3738                    Session session = null;
3739    
3740                    try {
3741                            session = openSession();
3742    
3743                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
3744    
3745                            array[0] = getByU_A_PrevAndNext(session, userNotificationEvent,
3746                                            userId, archived, orderByComparator, true);
3747    
3748                            array[1] = userNotificationEvent;
3749    
3750                            array[2] = getByU_A_PrevAndNext(session, userNotificationEvent,
3751                                            userId, archived, orderByComparator, false);
3752    
3753                            return array;
3754                    }
3755                    catch (Exception e) {
3756                            throw processException(e);
3757                    }
3758                    finally {
3759                            closeSession(session);
3760                    }
3761            }
3762    
3763            protected UserNotificationEvent getByU_A_PrevAndNext(Session session,
3764                    UserNotificationEvent userNotificationEvent, long userId,
3765                    boolean archived,
3766                    OrderByComparator<UserNotificationEvent> orderByComparator,
3767                    boolean previous) {
3768                    StringBundler query = null;
3769    
3770                    if (orderByComparator != null) {
3771                            query = new StringBundler(6 +
3772                                            (orderByComparator.getOrderByFields().length * 6));
3773                    }
3774                    else {
3775                            query = new StringBundler(3);
3776                    }
3777    
3778                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
3779    
3780                    query.append(_FINDER_COLUMN_U_A_USERID_2);
3781    
3782                    query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
3783    
3784                    if (orderByComparator != null) {
3785                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3786    
3787                            if (orderByConditionFields.length > 0) {
3788                                    query.append(WHERE_AND);
3789                            }
3790    
3791                            for (int i = 0; i < orderByConditionFields.length; i++) {
3792                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3793                                    query.append(orderByConditionFields[i]);
3794    
3795                                    if ((i + 1) < orderByConditionFields.length) {
3796                                            if (orderByComparator.isAscending() ^ previous) {
3797                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3798                                            }
3799                                            else {
3800                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3801                                            }
3802                                    }
3803                                    else {
3804                                            if (orderByComparator.isAscending() ^ previous) {
3805                                                    query.append(WHERE_GREATER_THAN);
3806                                            }
3807                                            else {
3808                                                    query.append(WHERE_LESSER_THAN);
3809                                            }
3810                                    }
3811                            }
3812    
3813                            query.append(ORDER_BY_CLAUSE);
3814    
3815                            String[] orderByFields = orderByComparator.getOrderByFields();
3816    
3817                            for (int i = 0; i < orderByFields.length; i++) {
3818                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3819                                    query.append(orderByFields[i]);
3820    
3821                                    if ((i + 1) < orderByFields.length) {
3822                                            if (orderByComparator.isAscending() ^ previous) {
3823                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3824                                            }
3825                                            else {
3826                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3827                                            }
3828                                    }
3829                                    else {
3830                                            if (orderByComparator.isAscending() ^ previous) {
3831                                                    query.append(ORDER_BY_ASC);
3832                                            }
3833                                            else {
3834                                                    query.append(ORDER_BY_DESC);
3835                                            }
3836                                    }
3837                            }
3838                    }
3839                    else {
3840                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
3841                    }
3842    
3843                    String sql = query.toString();
3844    
3845                    Query q = session.createQuery(sql);
3846    
3847                    q.setFirstResult(0);
3848                    q.setMaxResults(2);
3849    
3850                    QueryPos qPos = QueryPos.getInstance(q);
3851    
3852                    qPos.add(userId);
3853    
3854                    qPos.add(archived);
3855    
3856                    if (orderByComparator != null) {
3857                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
3858    
3859                            for (Object value : values) {
3860                                    qPos.add(value);
3861                            }
3862                    }
3863    
3864                    List<UserNotificationEvent> list = q.list();
3865    
3866                    if (list.size() == 2) {
3867                            return list.get(1);
3868                    }
3869                    else {
3870                            return null;
3871                    }
3872            }
3873    
3874            /**
3875             * Removes all the user notification events where userId = &#63; and archived = &#63; from the database.
3876             *
3877             * @param userId the user ID
3878             * @param archived the archived
3879             */
3880            @Override
3881            public void removeByU_A(long userId, boolean archived) {
3882                    for (UserNotificationEvent userNotificationEvent : findByU_A(userId,
3883                                    archived, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3884                            remove(userNotificationEvent);
3885                    }
3886            }
3887    
3888            /**
3889             * Returns the number of user notification events where userId = &#63; and archived = &#63;.
3890             *
3891             * @param userId the user ID
3892             * @param archived the archived
3893             * @return the number of matching user notification events
3894             */
3895            @Override
3896            public int countByU_A(long userId, boolean archived) {
3897                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_A;
3898    
3899                    Object[] finderArgs = new Object[] { userId, archived };
3900    
3901                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3902    
3903                    if (count == null) {
3904                            StringBundler query = new StringBundler(3);
3905    
3906                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
3907    
3908                            query.append(_FINDER_COLUMN_U_A_USERID_2);
3909    
3910                            query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
3911    
3912                            String sql = query.toString();
3913    
3914                            Session session = null;
3915    
3916                            try {
3917                                    session = openSession();
3918    
3919                                    Query q = session.createQuery(sql);
3920    
3921                                    QueryPos qPos = QueryPos.getInstance(q);
3922    
3923                                    qPos.add(userId);
3924    
3925                                    qPos.add(archived);
3926    
3927                                    count = (Long)q.uniqueResult();
3928    
3929                                    finderCache.putResult(finderPath, finderArgs, count);
3930                            }
3931                            catch (Exception e) {
3932                                    finderCache.removeResult(finderPath, finderArgs);
3933    
3934                                    throw processException(e);
3935                            }
3936                            finally {
3937                                    closeSession(session);
3938                            }
3939                    }
3940    
3941                    return count.intValue();
3942            }
3943    
3944            private static final String _FINDER_COLUMN_U_A_USERID_2 = "userNotificationEvent.userId = ? AND ";
3945            private static final String _FINDER_COLUMN_U_A_ARCHIVED_2 = "userNotificationEvent.archived = ?";
3946            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_DT_D = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
3947                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
3948                            UserNotificationEventImpl.class,
3949                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_DT_D",
3950                            new String[] {
3951                                    Long.class.getName(), Integer.class.getName(),
3952                                    Boolean.class.getName(),
3953                                    
3954                            Integer.class.getName(), Integer.class.getName(),
3955                                    OrderByComparator.class.getName()
3956                            });
3957            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_D =
3958                    new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
3959                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
3960                            UserNotificationEventImpl.class,
3961                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_DT_D",
3962                            new String[] {
3963                                    Long.class.getName(), Integer.class.getName(),
3964                                    Boolean.class.getName()
3965                            },
3966                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
3967                            UserNotificationEventModelImpl.DELIVERYTYPE_COLUMN_BITMASK |
3968                            UserNotificationEventModelImpl.DELIVERED_COLUMN_BITMASK |
3969                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
3970            public static final FinderPath FINDER_PATH_COUNT_BY_U_DT_D = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
3971                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
3972                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_DT_D",
3973                            new String[] {
3974                                    Long.class.getName(), Integer.class.getName(),
3975                                    Boolean.class.getName()
3976                            });
3977    
3978            /**
3979             * Returns all the user notification events where userId = &#63; and deliveryType = &#63; and delivered = &#63;.
3980             *
3981             * @param userId the user ID
3982             * @param deliveryType the delivery type
3983             * @param delivered the delivered
3984             * @return the matching user notification events
3985             */
3986            @Override
3987            public List<UserNotificationEvent> findByU_DT_D(long userId,
3988                    int deliveryType, boolean delivered) {
3989                    return findByU_DT_D(userId, deliveryType, delivered, QueryUtil.ALL_POS,
3990                            QueryUtil.ALL_POS, null);
3991            }
3992    
3993            /**
3994             * Returns a range of all the user notification events where userId = &#63; and deliveryType = &#63; and delivered = &#63;.
3995             *
3996             * <p>
3997             * 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 UserNotificationEventModelImpl}. 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.
3998             * </p>
3999             *
4000             * @param userId the user ID
4001             * @param deliveryType the delivery type
4002             * @param delivered the delivered
4003             * @param start the lower bound of the range of user notification events
4004             * @param end the upper bound of the range of user notification events (not inclusive)
4005             * @return the range of matching user notification events
4006             */
4007            @Override
4008            public List<UserNotificationEvent> findByU_DT_D(long userId,
4009                    int deliveryType, boolean delivered, int start, int end) {
4010                    return findByU_DT_D(userId, deliveryType, delivered, start, end, null);
4011            }
4012    
4013            /**
4014             * Returns an ordered range of all the user notification events where userId = &#63; and deliveryType = &#63; and delivered = &#63;.
4015             *
4016             * <p>
4017             * 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 UserNotificationEventModelImpl}. 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.
4018             * </p>
4019             *
4020             * @param userId the user ID
4021             * @param deliveryType the delivery type
4022             * @param delivered the delivered
4023             * @param start the lower bound of the range of user notification events
4024             * @param end the upper bound of the range of user notification events (not inclusive)
4025             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4026             * @return the ordered range of matching user notification events
4027             */
4028            @Override
4029            public List<UserNotificationEvent> findByU_DT_D(long userId,
4030                    int deliveryType, boolean delivered, int start, int end,
4031                    OrderByComparator<UserNotificationEvent> orderByComparator) {
4032                    return findByU_DT_D(userId, deliveryType, delivered, start, end,
4033                            orderByComparator, true);
4034            }
4035    
4036            /**
4037             * Returns an ordered range of all the user notification events where userId = &#63; and deliveryType = &#63; and delivered = &#63;.
4038             *
4039             * <p>
4040             * 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 UserNotificationEventModelImpl}. 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.
4041             * </p>
4042             *
4043             * @param userId the user ID
4044             * @param deliveryType the delivery type
4045             * @param delivered the delivered
4046             * @param start the lower bound of the range of user notification events
4047             * @param end the upper bound of the range of user notification events (not inclusive)
4048             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4049             * @param retrieveFromCache whether to retrieve from the finder cache
4050             * @return the ordered range of matching user notification events
4051             */
4052            @Override
4053            public List<UserNotificationEvent> findByU_DT_D(long userId,
4054                    int deliveryType, boolean delivered, int start, int end,
4055                    OrderByComparator<UserNotificationEvent> orderByComparator,
4056                    boolean retrieveFromCache) {
4057                    boolean pagination = true;
4058                    FinderPath finderPath = null;
4059                    Object[] finderArgs = null;
4060    
4061                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4062                                    (orderByComparator == null)) {
4063                            pagination = false;
4064                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_D;
4065                            finderArgs = new Object[] { userId, deliveryType, delivered };
4066                    }
4067                    else {
4068                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_DT_D;
4069                            finderArgs = new Object[] {
4070                                            userId, deliveryType, delivered,
4071                                            
4072                                            start, end, orderByComparator
4073                                    };
4074                    }
4075    
4076                    List<UserNotificationEvent> list = null;
4077    
4078                    if (retrieveFromCache) {
4079                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
4080                                            finderArgs, this);
4081    
4082                            if ((list != null) && !list.isEmpty()) {
4083                                    for (UserNotificationEvent userNotificationEvent : list) {
4084                                            if ((userId != userNotificationEvent.getUserId()) ||
4085                                                            (deliveryType != userNotificationEvent.getDeliveryType()) ||
4086                                                            (delivered != userNotificationEvent.getDelivered())) {
4087                                                    list = null;
4088    
4089                                                    break;
4090                                            }
4091                                    }
4092                            }
4093                    }
4094    
4095                    if (list == null) {
4096                            StringBundler query = null;
4097    
4098                            if (orderByComparator != null) {
4099                                    query = new StringBundler(5 +
4100                                                    (orderByComparator.getOrderByFields().length * 3));
4101                            }
4102                            else {
4103                                    query = new StringBundler(5);
4104                            }
4105    
4106                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
4107    
4108                            query.append(_FINDER_COLUMN_U_DT_D_USERID_2);
4109    
4110                            query.append(_FINDER_COLUMN_U_DT_D_DELIVERYTYPE_2);
4111    
4112                            query.append(_FINDER_COLUMN_U_DT_D_DELIVERED_2);
4113    
4114                            if (orderByComparator != null) {
4115                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4116                                            orderByComparator);
4117                            }
4118                            else
4119                             if (pagination) {
4120                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
4121                            }
4122    
4123                            String sql = query.toString();
4124    
4125                            Session session = null;
4126    
4127                            try {
4128                                    session = openSession();
4129    
4130                                    Query q = session.createQuery(sql);
4131    
4132                                    QueryPos qPos = QueryPos.getInstance(q);
4133    
4134                                    qPos.add(userId);
4135    
4136                                    qPos.add(deliveryType);
4137    
4138                                    qPos.add(delivered);
4139    
4140                                    if (!pagination) {
4141                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
4142                                                            getDialect(), start, end, false);
4143    
4144                                            Collections.sort(list);
4145    
4146                                            list = Collections.unmodifiableList(list);
4147                                    }
4148                                    else {
4149                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
4150                                                            getDialect(), start, end);
4151                                    }
4152    
4153                                    cacheResult(list);
4154    
4155                                    finderCache.putResult(finderPath, finderArgs, list);
4156                            }
4157                            catch (Exception e) {
4158                                    finderCache.removeResult(finderPath, finderArgs);
4159    
4160                                    throw processException(e);
4161                            }
4162                            finally {
4163                                    closeSession(session);
4164                            }
4165                    }
4166    
4167                    return list;
4168            }
4169    
4170            /**
4171             * Returns the first user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and delivered = &#63;.
4172             *
4173             * @param userId the user ID
4174             * @param deliveryType the delivery type
4175             * @param delivered the delivered
4176             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4177             * @return the first matching user notification event
4178             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
4179             */
4180            @Override
4181            public UserNotificationEvent findByU_DT_D_First(long userId,
4182                    int deliveryType, boolean delivered,
4183                    OrderByComparator<UserNotificationEvent> orderByComparator)
4184                    throws NoSuchUserNotificationEventException {
4185                    UserNotificationEvent userNotificationEvent = fetchByU_DT_D_First(userId,
4186                                    deliveryType, delivered, orderByComparator);
4187    
4188                    if (userNotificationEvent != null) {
4189                            return userNotificationEvent;
4190                    }
4191    
4192                    StringBundler msg = new StringBundler(8);
4193    
4194                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4195    
4196                    msg.append("userId=");
4197                    msg.append(userId);
4198    
4199                    msg.append(", deliveryType=");
4200                    msg.append(deliveryType);
4201    
4202                    msg.append(", delivered=");
4203                    msg.append(delivered);
4204    
4205                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4206    
4207                    throw new NoSuchUserNotificationEventException(msg.toString());
4208            }
4209    
4210            /**
4211             * Returns the first user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and delivered = &#63;.
4212             *
4213             * @param userId the user ID
4214             * @param deliveryType the delivery type
4215             * @param delivered the delivered
4216             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4217             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
4218             */
4219            @Override
4220            public UserNotificationEvent fetchByU_DT_D_First(long userId,
4221                    int deliveryType, boolean delivered,
4222                    OrderByComparator<UserNotificationEvent> orderByComparator) {
4223                    List<UserNotificationEvent> list = findByU_DT_D(userId, deliveryType,
4224                                    delivered, 0, 1, orderByComparator);
4225    
4226                    if (!list.isEmpty()) {
4227                            return list.get(0);
4228                    }
4229    
4230                    return null;
4231            }
4232    
4233            /**
4234             * Returns the last user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and delivered = &#63;.
4235             *
4236             * @param userId the user ID
4237             * @param deliveryType the delivery type
4238             * @param delivered the delivered
4239             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4240             * @return the last matching user notification event
4241             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
4242             */
4243            @Override
4244            public UserNotificationEvent findByU_DT_D_Last(long userId,
4245                    int deliveryType, boolean delivered,
4246                    OrderByComparator<UserNotificationEvent> orderByComparator)
4247                    throws NoSuchUserNotificationEventException {
4248                    UserNotificationEvent userNotificationEvent = fetchByU_DT_D_Last(userId,
4249                                    deliveryType, delivered, orderByComparator);
4250    
4251                    if (userNotificationEvent != null) {
4252                            return userNotificationEvent;
4253                    }
4254    
4255                    StringBundler msg = new StringBundler(8);
4256    
4257                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4258    
4259                    msg.append("userId=");
4260                    msg.append(userId);
4261    
4262                    msg.append(", deliveryType=");
4263                    msg.append(deliveryType);
4264    
4265                    msg.append(", delivered=");
4266                    msg.append(delivered);
4267    
4268                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4269    
4270                    throw new NoSuchUserNotificationEventException(msg.toString());
4271            }
4272    
4273            /**
4274             * Returns the last user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and delivered = &#63;.
4275             *
4276             * @param userId the user ID
4277             * @param deliveryType the delivery type
4278             * @param delivered the delivered
4279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4280             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
4281             */
4282            @Override
4283            public UserNotificationEvent fetchByU_DT_D_Last(long userId,
4284                    int deliveryType, boolean delivered,
4285                    OrderByComparator<UserNotificationEvent> orderByComparator) {
4286                    int count = countByU_DT_D(userId, deliveryType, delivered);
4287    
4288                    if (count == 0) {
4289                            return null;
4290                    }
4291    
4292                    List<UserNotificationEvent> list = findByU_DT_D(userId, deliveryType,
4293                                    delivered, count - 1, count, orderByComparator);
4294    
4295                    if (!list.isEmpty()) {
4296                            return list.get(0);
4297                    }
4298    
4299                    return null;
4300            }
4301    
4302            /**
4303             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and delivered = &#63;.
4304             *
4305             * @param userNotificationEventId the primary key of the current user notification event
4306             * @param userId the user ID
4307             * @param deliveryType the delivery type
4308             * @param delivered the delivered
4309             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4310             * @return the previous, current, and next user notification event
4311             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
4312             */
4313            @Override
4314            public UserNotificationEvent[] findByU_DT_D_PrevAndNext(
4315                    long userNotificationEventId, long userId, int deliveryType,
4316                    boolean delivered,
4317                    OrderByComparator<UserNotificationEvent> orderByComparator)
4318                    throws NoSuchUserNotificationEventException {
4319                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
4320    
4321                    Session session = null;
4322    
4323                    try {
4324                            session = openSession();
4325    
4326                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
4327    
4328                            array[0] = getByU_DT_D_PrevAndNext(session, userNotificationEvent,
4329                                            userId, deliveryType, delivered, orderByComparator, true);
4330    
4331                            array[1] = userNotificationEvent;
4332    
4333                            array[2] = getByU_DT_D_PrevAndNext(session, userNotificationEvent,
4334                                            userId, deliveryType, delivered, orderByComparator, false);
4335    
4336                            return array;
4337                    }
4338                    catch (Exception e) {
4339                            throw processException(e);
4340                    }
4341                    finally {
4342                            closeSession(session);
4343                    }
4344            }
4345    
4346            protected UserNotificationEvent getByU_DT_D_PrevAndNext(Session session,
4347                    UserNotificationEvent userNotificationEvent, long userId,
4348                    int deliveryType, boolean delivered,
4349                    OrderByComparator<UserNotificationEvent> orderByComparator,
4350                    boolean previous) {
4351                    StringBundler query = null;
4352    
4353                    if (orderByComparator != null) {
4354                            query = new StringBundler(6 +
4355                                            (orderByComparator.getOrderByFields().length * 6));
4356                    }
4357                    else {
4358                            query = new StringBundler(3);
4359                    }
4360    
4361                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
4362    
4363                    query.append(_FINDER_COLUMN_U_DT_D_USERID_2);
4364    
4365                    query.append(_FINDER_COLUMN_U_DT_D_DELIVERYTYPE_2);
4366    
4367                    query.append(_FINDER_COLUMN_U_DT_D_DELIVERED_2);
4368    
4369                    if (orderByComparator != null) {
4370                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4371    
4372                            if (orderByConditionFields.length > 0) {
4373                                    query.append(WHERE_AND);
4374                            }
4375    
4376                            for (int i = 0; i < orderByConditionFields.length; i++) {
4377                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4378                                    query.append(orderByConditionFields[i]);
4379    
4380                                    if ((i + 1) < orderByConditionFields.length) {
4381                                            if (orderByComparator.isAscending() ^ previous) {
4382                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4383                                            }
4384                                            else {
4385                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4386                                            }
4387                                    }
4388                                    else {
4389                                            if (orderByComparator.isAscending() ^ previous) {
4390                                                    query.append(WHERE_GREATER_THAN);
4391                                            }
4392                                            else {
4393                                                    query.append(WHERE_LESSER_THAN);
4394                                            }
4395                                    }
4396                            }
4397    
4398                            query.append(ORDER_BY_CLAUSE);
4399    
4400                            String[] orderByFields = orderByComparator.getOrderByFields();
4401    
4402                            for (int i = 0; i < orderByFields.length; i++) {
4403                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4404                                    query.append(orderByFields[i]);
4405    
4406                                    if ((i + 1) < orderByFields.length) {
4407                                            if (orderByComparator.isAscending() ^ previous) {
4408                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4409                                            }
4410                                            else {
4411                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4412                                            }
4413                                    }
4414                                    else {
4415                                            if (orderByComparator.isAscending() ^ previous) {
4416                                                    query.append(ORDER_BY_ASC);
4417                                            }
4418                                            else {
4419                                                    query.append(ORDER_BY_DESC);
4420                                            }
4421                                    }
4422                            }
4423                    }
4424                    else {
4425                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
4426                    }
4427    
4428                    String sql = query.toString();
4429    
4430                    Query q = session.createQuery(sql);
4431    
4432                    q.setFirstResult(0);
4433                    q.setMaxResults(2);
4434    
4435                    QueryPos qPos = QueryPos.getInstance(q);
4436    
4437                    qPos.add(userId);
4438    
4439                    qPos.add(deliveryType);
4440    
4441                    qPos.add(delivered);
4442    
4443                    if (orderByComparator != null) {
4444                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
4445    
4446                            for (Object value : values) {
4447                                    qPos.add(value);
4448                            }
4449                    }
4450    
4451                    List<UserNotificationEvent> list = q.list();
4452    
4453                    if (list.size() == 2) {
4454                            return list.get(1);
4455                    }
4456                    else {
4457                            return null;
4458                    }
4459            }
4460    
4461            /**
4462             * Removes all the user notification events where userId = &#63; and deliveryType = &#63; and delivered = &#63; from the database.
4463             *
4464             * @param userId the user ID
4465             * @param deliveryType the delivery type
4466             * @param delivered the delivered
4467             */
4468            @Override
4469            public void removeByU_DT_D(long userId, int deliveryType, boolean delivered) {
4470                    for (UserNotificationEvent userNotificationEvent : findByU_DT_D(
4471                                    userId, deliveryType, delivered, QueryUtil.ALL_POS,
4472                                    QueryUtil.ALL_POS, null)) {
4473                            remove(userNotificationEvent);
4474                    }
4475            }
4476    
4477            /**
4478             * Returns the number of user notification events where userId = &#63; and deliveryType = &#63; and delivered = &#63;.
4479             *
4480             * @param userId the user ID
4481             * @param deliveryType the delivery type
4482             * @param delivered the delivered
4483             * @return the number of matching user notification events
4484             */
4485            @Override
4486            public int countByU_DT_D(long userId, int deliveryType, boolean delivered) {
4487                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_DT_D;
4488    
4489                    Object[] finderArgs = new Object[] { userId, deliveryType, delivered };
4490    
4491                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4492    
4493                    if (count == null) {
4494                            StringBundler query = new StringBundler(4);
4495    
4496                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
4497    
4498                            query.append(_FINDER_COLUMN_U_DT_D_USERID_2);
4499    
4500                            query.append(_FINDER_COLUMN_U_DT_D_DELIVERYTYPE_2);
4501    
4502                            query.append(_FINDER_COLUMN_U_DT_D_DELIVERED_2);
4503    
4504                            String sql = query.toString();
4505    
4506                            Session session = null;
4507    
4508                            try {
4509                                    session = openSession();
4510    
4511                                    Query q = session.createQuery(sql);
4512    
4513                                    QueryPos qPos = QueryPos.getInstance(q);
4514    
4515                                    qPos.add(userId);
4516    
4517                                    qPos.add(deliveryType);
4518    
4519                                    qPos.add(delivered);
4520    
4521                                    count = (Long)q.uniqueResult();
4522    
4523                                    finderCache.putResult(finderPath, finderArgs, count);
4524                            }
4525                            catch (Exception e) {
4526                                    finderCache.removeResult(finderPath, finderArgs);
4527    
4528                                    throw processException(e);
4529                            }
4530                            finally {
4531                                    closeSession(session);
4532                            }
4533                    }
4534    
4535                    return count.intValue();
4536            }
4537    
4538            private static final String _FINDER_COLUMN_U_DT_D_USERID_2 = "userNotificationEvent.userId = ? AND ";
4539            private static final String _FINDER_COLUMN_U_DT_D_DELIVERYTYPE_2 = "userNotificationEvent.deliveryType = ? AND ";
4540            private static final String _FINDER_COLUMN_U_DT_D_DELIVERED_2 = "userNotificationEvent.delivered = ?";
4541            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_DT_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
4542                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
4543                            UserNotificationEventImpl.class,
4544                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_DT_A",
4545                            new String[] {
4546                                    Long.class.getName(), Integer.class.getName(),
4547                                    Boolean.class.getName(),
4548                                    
4549                            Integer.class.getName(), Integer.class.getName(),
4550                                    OrderByComparator.class.getName()
4551                            });
4552            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_A =
4553                    new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
4554                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
4555                            UserNotificationEventImpl.class,
4556                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_DT_A",
4557                            new String[] {
4558                                    Long.class.getName(), Integer.class.getName(),
4559                                    Boolean.class.getName()
4560                            },
4561                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
4562                            UserNotificationEventModelImpl.DELIVERYTYPE_COLUMN_BITMASK |
4563                            UserNotificationEventModelImpl.ARCHIVED_COLUMN_BITMASK |
4564                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
4565            public static final FinderPath FINDER_PATH_COUNT_BY_U_DT_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
4566                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
4567                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_DT_A",
4568                            new String[] {
4569                                    Long.class.getName(), Integer.class.getName(),
4570                                    Boolean.class.getName()
4571                            });
4572    
4573            /**
4574             * Returns all the user notification events where userId = &#63; and deliveryType = &#63; and archived = &#63;.
4575             *
4576             * @param userId the user ID
4577             * @param deliveryType the delivery type
4578             * @param archived the archived
4579             * @return the matching user notification events
4580             */
4581            @Override
4582            public List<UserNotificationEvent> findByU_DT_A(long userId,
4583                    int deliveryType, boolean archived) {
4584                    return findByU_DT_A(userId, deliveryType, archived, QueryUtil.ALL_POS,
4585                            QueryUtil.ALL_POS, null);
4586            }
4587    
4588            /**
4589             * Returns a range of all the user notification events where userId = &#63; and deliveryType = &#63; and archived = &#63;.
4590             *
4591             * <p>
4592             * 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 UserNotificationEventModelImpl}. 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.
4593             * </p>
4594             *
4595             * @param userId the user ID
4596             * @param deliveryType the delivery type
4597             * @param archived the archived
4598             * @param start the lower bound of the range of user notification events
4599             * @param end the upper bound of the range of user notification events (not inclusive)
4600             * @return the range of matching user notification events
4601             */
4602            @Override
4603            public List<UserNotificationEvent> findByU_DT_A(long userId,
4604                    int deliveryType, boolean archived, int start, int end) {
4605                    return findByU_DT_A(userId, deliveryType, archived, start, end, null);
4606            }
4607    
4608            /**
4609             * Returns an ordered range of all the user notification events where userId = &#63; and deliveryType = &#63; and archived = &#63;.
4610             *
4611             * <p>
4612             * 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 UserNotificationEventModelImpl}. 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.
4613             * </p>
4614             *
4615             * @param userId the user ID
4616             * @param deliveryType the delivery type
4617             * @param archived the archived
4618             * @param start the lower bound of the range of user notification events
4619             * @param end the upper bound of the range of user notification events (not inclusive)
4620             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4621             * @return the ordered range of matching user notification events
4622             */
4623            @Override
4624            public List<UserNotificationEvent> findByU_DT_A(long userId,
4625                    int deliveryType, boolean archived, int start, int end,
4626                    OrderByComparator<UserNotificationEvent> orderByComparator) {
4627                    return findByU_DT_A(userId, deliveryType, archived, start, end,
4628                            orderByComparator, true);
4629            }
4630    
4631            /**
4632             * Returns an ordered range of all the user notification events where userId = &#63; and deliveryType = &#63; and archived = &#63;.
4633             *
4634             * <p>
4635             * 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 UserNotificationEventModelImpl}. 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.
4636             * </p>
4637             *
4638             * @param userId the user ID
4639             * @param deliveryType the delivery type
4640             * @param archived the archived
4641             * @param start the lower bound of the range of user notification events
4642             * @param end the upper bound of the range of user notification events (not inclusive)
4643             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4644             * @param retrieveFromCache whether to retrieve from the finder cache
4645             * @return the ordered range of matching user notification events
4646             */
4647            @Override
4648            public List<UserNotificationEvent> findByU_DT_A(long userId,
4649                    int deliveryType, boolean archived, int start, int end,
4650                    OrderByComparator<UserNotificationEvent> orderByComparator,
4651                    boolean retrieveFromCache) {
4652                    boolean pagination = true;
4653                    FinderPath finderPath = null;
4654                    Object[] finderArgs = null;
4655    
4656                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4657                                    (orderByComparator == null)) {
4658                            pagination = false;
4659                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_A;
4660                            finderArgs = new Object[] { userId, deliveryType, archived };
4661                    }
4662                    else {
4663                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_DT_A;
4664                            finderArgs = new Object[] {
4665                                            userId, deliveryType, archived,
4666                                            
4667                                            start, end, orderByComparator
4668                                    };
4669                    }
4670    
4671                    List<UserNotificationEvent> list = null;
4672    
4673                    if (retrieveFromCache) {
4674                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
4675                                            finderArgs, this);
4676    
4677                            if ((list != null) && !list.isEmpty()) {
4678                                    for (UserNotificationEvent userNotificationEvent : list) {
4679                                            if ((userId != userNotificationEvent.getUserId()) ||
4680                                                            (deliveryType != userNotificationEvent.getDeliveryType()) ||
4681                                                            (archived != userNotificationEvent.getArchived())) {
4682                                                    list = null;
4683    
4684                                                    break;
4685                                            }
4686                                    }
4687                            }
4688                    }
4689    
4690                    if (list == null) {
4691                            StringBundler query = null;
4692    
4693                            if (orderByComparator != null) {
4694                                    query = new StringBundler(5 +
4695                                                    (orderByComparator.getOrderByFields().length * 3));
4696                            }
4697                            else {
4698                                    query = new StringBundler(5);
4699                            }
4700    
4701                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
4702    
4703                            query.append(_FINDER_COLUMN_U_DT_A_USERID_2);
4704    
4705                            query.append(_FINDER_COLUMN_U_DT_A_DELIVERYTYPE_2);
4706    
4707                            query.append(_FINDER_COLUMN_U_DT_A_ARCHIVED_2);
4708    
4709                            if (orderByComparator != null) {
4710                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4711                                            orderByComparator);
4712                            }
4713                            else
4714                             if (pagination) {
4715                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
4716                            }
4717    
4718                            String sql = query.toString();
4719    
4720                            Session session = null;
4721    
4722                            try {
4723                                    session = openSession();
4724    
4725                                    Query q = session.createQuery(sql);
4726    
4727                                    QueryPos qPos = QueryPos.getInstance(q);
4728    
4729                                    qPos.add(userId);
4730    
4731                                    qPos.add(deliveryType);
4732    
4733                                    qPos.add(archived);
4734    
4735                                    if (!pagination) {
4736                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
4737                                                            getDialect(), start, end, false);
4738    
4739                                            Collections.sort(list);
4740    
4741                                            list = Collections.unmodifiableList(list);
4742                                    }
4743                                    else {
4744                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
4745                                                            getDialect(), start, end);
4746                                    }
4747    
4748                                    cacheResult(list);
4749    
4750                                    finderCache.putResult(finderPath, finderArgs, list);
4751                            }
4752                            catch (Exception e) {
4753                                    finderCache.removeResult(finderPath, finderArgs);
4754    
4755                                    throw processException(e);
4756                            }
4757                            finally {
4758                                    closeSession(session);
4759                            }
4760                    }
4761    
4762                    return list;
4763            }
4764    
4765            /**
4766             * Returns the first user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and archived = &#63;.
4767             *
4768             * @param userId the user ID
4769             * @param deliveryType the delivery type
4770             * @param archived the archived
4771             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4772             * @return the first matching user notification event
4773             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
4774             */
4775            @Override
4776            public UserNotificationEvent findByU_DT_A_First(long userId,
4777                    int deliveryType, boolean archived,
4778                    OrderByComparator<UserNotificationEvent> orderByComparator)
4779                    throws NoSuchUserNotificationEventException {
4780                    UserNotificationEvent userNotificationEvent = fetchByU_DT_A_First(userId,
4781                                    deliveryType, archived, orderByComparator);
4782    
4783                    if (userNotificationEvent != null) {
4784                            return userNotificationEvent;
4785                    }
4786    
4787                    StringBundler msg = new StringBundler(8);
4788    
4789                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4790    
4791                    msg.append("userId=");
4792                    msg.append(userId);
4793    
4794                    msg.append(", deliveryType=");
4795                    msg.append(deliveryType);
4796    
4797                    msg.append(", archived=");
4798                    msg.append(archived);
4799    
4800                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4801    
4802                    throw new NoSuchUserNotificationEventException(msg.toString());
4803            }
4804    
4805            /**
4806             * Returns the first user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and archived = &#63;.
4807             *
4808             * @param userId the user ID
4809             * @param deliveryType the delivery type
4810             * @param archived the archived
4811             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4812             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
4813             */
4814            @Override
4815            public UserNotificationEvent fetchByU_DT_A_First(long userId,
4816                    int deliveryType, boolean archived,
4817                    OrderByComparator<UserNotificationEvent> orderByComparator) {
4818                    List<UserNotificationEvent> list = findByU_DT_A(userId, deliveryType,
4819                                    archived, 0, 1, orderByComparator);
4820    
4821                    if (!list.isEmpty()) {
4822                            return list.get(0);
4823                    }
4824    
4825                    return null;
4826            }
4827    
4828            /**
4829             * Returns the last user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and archived = &#63;.
4830             *
4831             * @param userId the user ID
4832             * @param deliveryType the delivery type
4833             * @param archived the archived
4834             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4835             * @return the last matching user notification event
4836             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
4837             */
4838            @Override
4839            public UserNotificationEvent findByU_DT_A_Last(long userId,
4840                    int deliveryType, boolean archived,
4841                    OrderByComparator<UserNotificationEvent> orderByComparator)
4842                    throws NoSuchUserNotificationEventException {
4843                    UserNotificationEvent userNotificationEvent = fetchByU_DT_A_Last(userId,
4844                                    deliveryType, archived, orderByComparator);
4845    
4846                    if (userNotificationEvent != null) {
4847                            return userNotificationEvent;
4848                    }
4849    
4850                    StringBundler msg = new StringBundler(8);
4851    
4852                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4853    
4854                    msg.append("userId=");
4855                    msg.append(userId);
4856    
4857                    msg.append(", deliveryType=");
4858                    msg.append(deliveryType);
4859    
4860                    msg.append(", archived=");
4861                    msg.append(archived);
4862    
4863                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4864    
4865                    throw new NoSuchUserNotificationEventException(msg.toString());
4866            }
4867    
4868            /**
4869             * Returns the last user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and archived = &#63;.
4870             *
4871             * @param userId the user ID
4872             * @param deliveryType the delivery type
4873             * @param archived the archived
4874             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4875             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
4876             */
4877            @Override
4878            public UserNotificationEvent fetchByU_DT_A_Last(long userId,
4879                    int deliveryType, boolean archived,
4880                    OrderByComparator<UserNotificationEvent> orderByComparator) {
4881                    int count = countByU_DT_A(userId, deliveryType, archived);
4882    
4883                    if (count == 0) {
4884                            return null;
4885                    }
4886    
4887                    List<UserNotificationEvent> list = findByU_DT_A(userId, deliveryType,
4888                                    archived, count - 1, count, orderByComparator);
4889    
4890                    if (!list.isEmpty()) {
4891                            return list.get(0);
4892                    }
4893    
4894                    return null;
4895            }
4896    
4897            /**
4898             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and archived = &#63;.
4899             *
4900             * @param userNotificationEventId the primary key of the current user notification event
4901             * @param userId the user ID
4902             * @param deliveryType the delivery type
4903             * @param archived the archived
4904             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4905             * @return the previous, current, and next user notification event
4906             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
4907             */
4908            @Override
4909            public UserNotificationEvent[] findByU_DT_A_PrevAndNext(
4910                    long userNotificationEventId, long userId, int deliveryType,
4911                    boolean archived,
4912                    OrderByComparator<UserNotificationEvent> orderByComparator)
4913                    throws NoSuchUserNotificationEventException {
4914                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
4915    
4916                    Session session = null;
4917    
4918                    try {
4919                            session = openSession();
4920    
4921                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
4922    
4923                            array[0] = getByU_DT_A_PrevAndNext(session, userNotificationEvent,
4924                                            userId, deliveryType, archived, orderByComparator, true);
4925    
4926                            array[1] = userNotificationEvent;
4927    
4928                            array[2] = getByU_DT_A_PrevAndNext(session, userNotificationEvent,
4929                                            userId, deliveryType, archived, orderByComparator, false);
4930    
4931                            return array;
4932                    }
4933                    catch (Exception e) {
4934                            throw processException(e);
4935                    }
4936                    finally {
4937                            closeSession(session);
4938                    }
4939            }
4940    
4941            protected UserNotificationEvent getByU_DT_A_PrevAndNext(Session session,
4942                    UserNotificationEvent userNotificationEvent, long userId,
4943                    int deliveryType, boolean archived,
4944                    OrderByComparator<UserNotificationEvent> orderByComparator,
4945                    boolean previous) {
4946                    StringBundler query = null;
4947    
4948                    if (orderByComparator != null) {
4949                            query = new StringBundler(6 +
4950                                            (orderByComparator.getOrderByFields().length * 6));
4951                    }
4952                    else {
4953                            query = new StringBundler(3);
4954                    }
4955    
4956                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
4957    
4958                    query.append(_FINDER_COLUMN_U_DT_A_USERID_2);
4959    
4960                    query.append(_FINDER_COLUMN_U_DT_A_DELIVERYTYPE_2);
4961    
4962                    query.append(_FINDER_COLUMN_U_DT_A_ARCHIVED_2);
4963    
4964                    if (orderByComparator != null) {
4965                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4966    
4967                            if (orderByConditionFields.length > 0) {
4968                                    query.append(WHERE_AND);
4969                            }
4970    
4971                            for (int i = 0; i < orderByConditionFields.length; i++) {
4972                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4973                                    query.append(orderByConditionFields[i]);
4974    
4975                                    if ((i + 1) < orderByConditionFields.length) {
4976                                            if (orderByComparator.isAscending() ^ previous) {
4977                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4978                                            }
4979                                            else {
4980                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4981                                            }
4982                                    }
4983                                    else {
4984                                            if (orderByComparator.isAscending() ^ previous) {
4985                                                    query.append(WHERE_GREATER_THAN);
4986                                            }
4987                                            else {
4988                                                    query.append(WHERE_LESSER_THAN);
4989                                            }
4990                                    }
4991                            }
4992    
4993                            query.append(ORDER_BY_CLAUSE);
4994    
4995                            String[] orderByFields = orderByComparator.getOrderByFields();
4996    
4997                            for (int i = 0; i < orderByFields.length; i++) {
4998                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4999                                    query.append(orderByFields[i]);
5000    
5001                                    if ((i + 1) < orderByFields.length) {
5002                                            if (orderByComparator.isAscending() ^ previous) {
5003                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5004                                            }
5005                                            else {
5006                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5007                                            }
5008                                    }
5009                                    else {
5010                                            if (orderByComparator.isAscending() ^ previous) {
5011                                                    query.append(ORDER_BY_ASC);
5012                                            }
5013                                            else {
5014                                                    query.append(ORDER_BY_DESC);
5015                                            }
5016                                    }
5017                            }
5018                    }
5019                    else {
5020                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
5021                    }
5022    
5023                    String sql = query.toString();
5024    
5025                    Query q = session.createQuery(sql);
5026    
5027                    q.setFirstResult(0);
5028                    q.setMaxResults(2);
5029    
5030                    QueryPos qPos = QueryPos.getInstance(q);
5031    
5032                    qPos.add(userId);
5033    
5034                    qPos.add(deliveryType);
5035    
5036                    qPos.add(archived);
5037    
5038                    if (orderByComparator != null) {
5039                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
5040    
5041                            for (Object value : values) {
5042                                    qPos.add(value);
5043                            }
5044                    }
5045    
5046                    List<UserNotificationEvent> list = q.list();
5047    
5048                    if (list.size() == 2) {
5049                            return list.get(1);
5050                    }
5051                    else {
5052                            return null;
5053                    }
5054            }
5055    
5056            /**
5057             * Removes all the user notification events where userId = &#63; and deliveryType = &#63; and archived = &#63; from the database.
5058             *
5059             * @param userId the user ID
5060             * @param deliveryType the delivery type
5061             * @param archived the archived
5062             */
5063            @Override
5064            public void removeByU_DT_A(long userId, int deliveryType, boolean archived) {
5065                    for (UserNotificationEvent userNotificationEvent : findByU_DT_A(
5066                                    userId, deliveryType, archived, QueryUtil.ALL_POS,
5067                                    QueryUtil.ALL_POS, null)) {
5068                            remove(userNotificationEvent);
5069                    }
5070            }
5071    
5072            /**
5073             * Returns the number of user notification events where userId = &#63; and deliveryType = &#63; and archived = &#63;.
5074             *
5075             * @param userId the user ID
5076             * @param deliveryType the delivery type
5077             * @param archived the archived
5078             * @return the number of matching user notification events
5079             */
5080            @Override
5081            public int countByU_DT_A(long userId, int deliveryType, boolean archived) {
5082                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_DT_A;
5083    
5084                    Object[] finderArgs = new Object[] { userId, deliveryType, archived };
5085    
5086                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5087    
5088                    if (count == null) {
5089                            StringBundler query = new StringBundler(4);
5090    
5091                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
5092    
5093                            query.append(_FINDER_COLUMN_U_DT_A_USERID_2);
5094    
5095                            query.append(_FINDER_COLUMN_U_DT_A_DELIVERYTYPE_2);
5096    
5097                            query.append(_FINDER_COLUMN_U_DT_A_ARCHIVED_2);
5098    
5099                            String sql = query.toString();
5100    
5101                            Session session = null;
5102    
5103                            try {
5104                                    session = openSession();
5105    
5106                                    Query q = session.createQuery(sql);
5107    
5108                                    QueryPos qPos = QueryPos.getInstance(q);
5109    
5110                                    qPos.add(userId);
5111    
5112                                    qPos.add(deliveryType);
5113    
5114                                    qPos.add(archived);
5115    
5116                                    count = (Long)q.uniqueResult();
5117    
5118                                    finderCache.putResult(finderPath, finderArgs, count);
5119                            }
5120                            catch (Exception e) {
5121                                    finderCache.removeResult(finderPath, finderArgs);
5122    
5123                                    throw processException(e);
5124                            }
5125                            finally {
5126                                    closeSession(session);
5127                            }
5128                    }
5129    
5130                    return count.intValue();
5131            }
5132    
5133            private static final String _FINDER_COLUMN_U_DT_A_USERID_2 = "userNotificationEvent.userId = ? AND ";
5134            private static final String _FINDER_COLUMN_U_DT_A_DELIVERYTYPE_2 = "userNotificationEvent.deliveryType = ? AND ";
5135            private static final String _FINDER_COLUMN_U_DT_A_ARCHIVED_2 = "userNotificationEvent.archived = ?";
5136            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_D_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
5137                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
5138                            UserNotificationEventImpl.class,
5139                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_D_A",
5140                            new String[] {
5141                                    Long.class.getName(), Boolean.class.getName(),
5142                                    Boolean.class.getName(),
5143                                    
5144                            Integer.class.getName(), Integer.class.getName(),
5145                                    OrderByComparator.class.getName()
5146                            });
5147            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_D_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
5148                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
5149                            UserNotificationEventImpl.class,
5150                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_D_A",
5151                            new String[] {
5152                                    Long.class.getName(), Boolean.class.getName(),
5153                                    Boolean.class.getName()
5154                            },
5155                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
5156                            UserNotificationEventModelImpl.DELIVERED_COLUMN_BITMASK |
5157                            UserNotificationEventModelImpl.ACTIONREQUIRED_COLUMN_BITMASK |
5158                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
5159            public static final FinderPath FINDER_PATH_COUNT_BY_U_D_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
5160                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
5161                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_D_A",
5162                            new String[] {
5163                                    Long.class.getName(), Boolean.class.getName(),
5164                                    Boolean.class.getName()
5165                            });
5166    
5167            /**
5168             * Returns all the user notification events where userId = &#63; and delivered = &#63; and actionRequired = &#63;.
5169             *
5170             * @param userId the user ID
5171             * @param delivered the delivered
5172             * @param actionRequired the action required
5173             * @return the matching user notification events
5174             */
5175            @Override
5176            public List<UserNotificationEvent> findByU_D_A(long userId,
5177                    boolean delivered, boolean actionRequired) {
5178                    return findByU_D_A(userId, delivered, actionRequired,
5179                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5180            }
5181    
5182            /**
5183             * Returns a range of all the user notification events where userId = &#63; and delivered = &#63; and actionRequired = &#63;.
5184             *
5185             * <p>
5186             * 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 UserNotificationEventModelImpl}. 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.
5187             * </p>
5188             *
5189             * @param userId the user ID
5190             * @param delivered the delivered
5191             * @param actionRequired the action required
5192             * @param start the lower bound of the range of user notification events
5193             * @param end the upper bound of the range of user notification events (not inclusive)
5194             * @return the range of matching user notification events
5195             */
5196            @Override
5197            public List<UserNotificationEvent> findByU_D_A(long userId,
5198                    boolean delivered, boolean actionRequired, int start, int end) {
5199                    return findByU_D_A(userId, delivered, actionRequired, start, end, null);
5200            }
5201    
5202            /**
5203             * Returns an ordered range of all the user notification events where userId = &#63; and delivered = &#63; and actionRequired = &#63;.
5204             *
5205             * <p>
5206             * 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 UserNotificationEventModelImpl}. 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.
5207             * </p>
5208             *
5209             * @param userId the user ID
5210             * @param delivered the delivered
5211             * @param actionRequired the action required
5212             * @param start the lower bound of the range of user notification events
5213             * @param end the upper bound of the range of user notification events (not inclusive)
5214             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5215             * @return the ordered range of matching user notification events
5216             */
5217            @Override
5218            public List<UserNotificationEvent> findByU_D_A(long userId,
5219                    boolean delivered, boolean actionRequired, int start, int end,
5220                    OrderByComparator<UserNotificationEvent> orderByComparator) {
5221                    return findByU_D_A(userId, delivered, actionRequired, start, end,
5222                            orderByComparator, true);
5223            }
5224    
5225            /**
5226             * Returns an ordered range of all the user notification events where userId = &#63; and delivered = &#63; and actionRequired = &#63;.
5227             *
5228             * <p>
5229             * 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 UserNotificationEventModelImpl}. 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.
5230             * </p>
5231             *
5232             * @param userId the user ID
5233             * @param delivered the delivered
5234             * @param actionRequired the action required
5235             * @param start the lower bound of the range of user notification events
5236             * @param end the upper bound of the range of user notification events (not inclusive)
5237             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5238             * @param retrieveFromCache whether to retrieve from the finder cache
5239             * @return the ordered range of matching user notification events
5240             */
5241            @Override
5242            public List<UserNotificationEvent> findByU_D_A(long userId,
5243                    boolean delivered, boolean actionRequired, int start, int end,
5244                    OrderByComparator<UserNotificationEvent> orderByComparator,
5245                    boolean retrieveFromCache) {
5246                    boolean pagination = true;
5247                    FinderPath finderPath = null;
5248                    Object[] finderArgs = null;
5249    
5250                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5251                                    (orderByComparator == null)) {
5252                            pagination = false;
5253                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_D_A;
5254                            finderArgs = new Object[] { userId, delivered, actionRequired };
5255                    }
5256                    else {
5257                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_D_A;
5258                            finderArgs = new Object[] {
5259                                            userId, delivered, actionRequired,
5260                                            
5261                                            start, end, orderByComparator
5262                                    };
5263                    }
5264    
5265                    List<UserNotificationEvent> list = null;
5266    
5267                    if (retrieveFromCache) {
5268                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
5269                                            finderArgs, this);
5270    
5271                            if ((list != null) && !list.isEmpty()) {
5272                                    for (UserNotificationEvent userNotificationEvent : list) {
5273                                            if ((userId != userNotificationEvent.getUserId()) ||
5274                                                            (delivered != userNotificationEvent.getDelivered()) ||
5275                                                            (actionRequired != userNotificationEvent.getActionRequired())) {
5276                                                    list = null;
5277    
5278                                                    break;
5279                                            }
5280                                    }
5281                            }
5282                    }
5283    
5284                    if (list == null) {
5285                            StringBundler query = null;
5286    
5287                            if (orderByComparator != null) {
5288                                    query = new StringBundler(5 +
5289                                                    (orderByComparator.getOrderByFields().length * 3));
5290                            }
5291                            else {
5292                                    query = new StringBundler(5);
5293                            }
5294    
5295                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
5296    
5297                            query.append(_FINDER_COLUMN_U_D_A_USERID_2);
5298    
5299                            query.append(_FINDER_COLUMN_U_D_A_DELIVERED_2);
5300    
5301                            query.append(_FINDER_COLUMN_U_D_A_ACTIONREQUIRED_2);
5302    
5303                            if (orderByComparator != null) {
5304                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5305                                            orderByComparator);
5306                            }
5307                            else
5308                             if (pagination) {
5309                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
5310                            }
5311    
5312                            String sql = query.toString();
5313    
5314                            Session session = null;
5315    
5316                            try {
5317                                    session = openSession();
5318    
5319                                    Query q = session.createQuery(sql);
5320    
5321                                    QueryPos qPos = QueryPos.getInstance(q);
5322    
5323                                    qPos.add(userId);
5324    
5325                                    qPos.add(delivered);
5326    
5327                                    qPos.add(actionRequired);
5328    
5329                                    if (!pagination) {
5330                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
5331                                                            getDialect(), start, end, false);
5332    
5333                                            Collections.sort(list);
5334    
5335                                            list = Collections.unmodifiableList(list);
5336                                    }
5337                                    else {
5338                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
5339                                                            getDialect(), start, end);
5340                                    }
5341    
5342                                    cacheResult(list);
5343    
5344                                    finderCache.putResult(finderPath, finderArgs, list);
5345                            }
5346                            catch (Exception e) {
5347                                    finderCache.removeResult(finderPath, finderArgs);
5348    
5349                                    throw processException(e);
5350                            }
5351                            finally {
5352                                    closeSession(session);
5353                            }
5354                    }
5355    
5356                    return list;
5357            }
5358    
5359            /**
5360             * Returns the first user notification event in the ordered set where userId = &#63; and delivered = &#63; and actionRequired = &#63;.
5361             *
5362             * @param userId the user ID
5363             * @param delivered the delivered
5364             * @param actionRequired the action required
5365             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5366             * @return the first matching user notification event
5367             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
5368             */
5369            @Override
5370            public UserNotificationEvent findByU_D_A_First(long userId,
5371                    boolean delivered, boolean actionRequired,
5372                    OrderByComparator<UserNotificationEvent> orderByComparator)
5373                    throws NoSuchUserNotificationEventException {
5374                    UserNotificationEvent userNotificationEvent = fetchByU_D_A_First(userId,
5375                                    delivered, actionRequired, orderByComparator);
5376    
5377                    if (userNotificationEvent != null) {
5378                            return userNotificationEvent;
5379                    }
5380    
5381                    StringBundler msg = new StringBundler(8);
5382    
5383                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5384    
5385                    msg.append("userId=");
5386                    msg.append(userId);
5387    
5388                    msg.append(", delivered=");
5389                    msg.append(delivered);
5390    
5391                    msg.append(", actionRequired=");
5392                    msg.append(actionRequired);
5393    
5394                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5395    
5396                    throw new NoSuchUserNotificationEventException(msg.toString());
5397            }
5398    
5399            /**
5400             * Returns the first user notification event in the ordered set where userId = &#63; and delivered = &#63; and actionRequired = &#63;.
5401             *
5402             * @param userId the user ID
5403             * @param delivered the delivered
5404             * @param actionRequired the action required
5405             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5406             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
5407             */
5408            @Override
5409            public UserNotificationEvent fetchByU_D_A_First(long userId,
5410                    boolean delivered, boolean actionRequired,
5411                    OrderByComparator<UserNotificationEvent> orderByComparator) {
5412                    List<UserNotificationEvent> list = findByU_D_A(userId, delivered,
5413                                    actionRequired, 0, 1, orderByComparator);
5414    
5415                    if (!list.isEmpty()) {
5416                            return list.get(0);
5417                    }
5418    
5419                    return null;
5420            }
5421    
5422            /**
5423             * Returns the last user notification event in the ordered set where userId = &#63; and delivered = &#63; and actionRequired = &#63;.
5424             *
5425             * @param userId the user ID
5426             * @param delivered the delivered
5427             * @param actionRequired the action required
5428             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5429             * @return the last matching user notification event
5430             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
5431             */
5432            @Override
5433            public UserNotificationEvent findByU_D_A_Last(long userId,
5434                    boolean delivered, boolean actionRequired,
5435                    OrderByComparator<UserNotificationEvent> orderByComparator)
5436                    throws NoSuchUserNotificationEventException {
5437                    UserNotificationEvent userNotificationEvent = fetchByU_D_A_Last(userId,
5438                                    delivered, actionRequired, orderByComparator);
5439    
5440                    if (userNotificationEvent != null) {
5441                            return userNotificationEvent;
5442                    }
5443    
5444                    StringBundler msg = new StringBundler(8);
5445    
5446                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5447    
5448                    msg.append("userId=");
5449                    msg.append(userId);
5450    
5451                    msg.append(", delivered=");
5452                    msg.append(delivered);
5453    
5454                    msg.append(", actionRequired=");
5455                    msg.append(actionRequired);
5456    
5457                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5458    
5459                    throw new NoSuchUserNotificationEventException(msg.toString());
5460            }
5461    
5462            /**
5463             * Returns the last user notification event in the ordered set where userId = &#63; and delivered = &#63; and actionRequired = &#63;.
5464             *
5465             * @param userId the user ID
5466             * @param delivered the delivered
5467             * @param actionRequired the action required
5468             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5469             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
5470             */
5471            @Override
5472            public UserNotificationEvent fetchByU_D_A_Last(long userId,
5473                    boolean delivered, boolean actionRequired,
5474                    OrderByComparator<UserNotificationEvent> orderByComparator) {
5475                    int count = countByU_D_A(userId, delivered, actionRequired);
5476    
5477                    if (count == 0) {
5478                            return null;
5479                    }
5480    
5481                    List<UserNotificationEvent> list = findByU_D_A(userId, delivered,
5482                                    actionRequired, count - 1, count, orderByComparator);
5483    
5484                    if (!list.isEmpty()) {
5485                            return list.get(0);
5486                    }
5487    
5488                    return null;
5489            }
5490    
5491            /**
5492             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63; and delivered = &#63; and actionRequired = &#63;.
5493             *
5494             * @param userNotificationEventId the primary key of the current user notification event
5495             * @param userId the user ID
5496             * @param delivered the delivered
5497             * @param actionRequired the action required
5498             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5499             * @return the previous, current, and next user notification event
5500             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
5501             */
5502            @Override
5503            public UserNotificationEvent[] findByU_D_A_PrevAndNext(
5504                    long userNotificationEventId, long userId, boolean delivered,
5505                    boolean actionRequired,
5506                    OrderByComparator<UserNotificationEvent> orderByComparator)
5507                    throws NoSuchUserNotificationEventException {
5508                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
5509    
5510                    Session session = null;
5511    
5512                    try {
5513                            session = openSession();
5514    
5515                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
5516    
5517                            array[0] = getByU_D_A_PrevAndNext(session, userNotificationEvent,
5518                                            userId, delivered, actionRequired, orderByComparator, true);
5519    
5520                            array[1] = userNotificationEvent;
5521    
5522                            array[2] = getByU_D_A_PrevAndNext(session, userNotificationEvent,
5523                                            userId, delivered, actionRequired, orderByComparator, false);
5524    
5525                            return array;
5526                    }
5527                    catch (Exception e) {
5528                            throw processException(e);
5529                    }
5530                    finally {
5531                            closeSession(session);
5532                    }
5533            }
5534    
5535            protected UserNotificationEvent getByU_D_A_PrevAndNext(Session session,
5536                    UserNotificationEvent userNotificationEvent, long userId,
5537                    boolean delivered, boolean actionRequired,
5538                    OrderByComparator<UserNotificationEvent> orderByComparator,
5539                    boolean previous) {
5540                    StringBundler query = null;
5541    
5542                    if (orderByComparator != null) {
5543                            query = new StringBundler(6 +
5544                                            (orderByComparator.getOrderByFields().length * 6));
5545                    }
5546                    else {
5547                            query = new StringBundler(3);
5548                    }
5549    
5550                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
5551    
5552                    query.append(_FINDER_COLUMN_U_D_A_USERID_2);
5553    
5554                    query.append(_FINDER_COLUMN_U_D_A_DELIVERED_2);
5555    
5556                    query.append(_FINDER_COLUMN_U_D_A_ACTIONREQUIRED_2);
5557    
5558                    if (orderByComparator != null) {
5559                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5560    
5561                            if (orderByConditionFields.length > 0) {
5562                                    query.append(WHERE_AND);
5563                            }
5564    
5565                            for (int i = 0; i < orderByConditionFields.length; i++) {
5566                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5567                                    query.append(orderByConditionFields[i]);
5568    
5569                                    if ((i + 1) < orderByConditionFields.length) {
5570                                            if (orderByComparator.isAscending() ^ previous) {
5571                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5572                                            }
5573                                            else {
5574                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5575                                            }
5576                                    }
5577                                    else {
5578                                            if (orderByComparator.isAscending() ^ previous) {
5579                                                    query.append(WHERE_GREATER_THAN);
5580                                            }
5581                                            else {
5582                                                    query.append(WHERE_LESSER_THAN);
5583                                            }
5584                                    }
5585                            }
5586    
5587                            query.append(ORDER_BY_CLAUSE);
5588    
5589                            String[] orderByFields = orderByComparator.getOrderByFields();
5590    
5591                            for (int i = 0; i < orderByFields.length; i++) {
5592                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5593                                    query.append(orderByFields[i]);
5594    
5595                                    if ((i + 1) < orderByFields.length) {
5596                                            if (orderByComparator.isAscending() ^ previous) {
5597                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5598                                            }
5599                                            else {
5600                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5601                                            }
5602                                    }
5603                                    else {
5604                                            if (orderByComparator.isAscending() ^ previous) {
5605                                                    query.append(ORDER_BY_ASC);
5606                                            }
5607                                            else {
5608                                                    query.append(ORDER_BY_DESC);
5609                                            }
5610                                    }
5611                            }
5612                    }
5613                    else {
5614                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
5615                    }
5616    
5617                    String sql = query.toString();
5618    
5619                    Query q = session.createQuery(sql);
5620    
5621                    q.setFirstResult(0);
5622                    q.setMaxResults(2);
5623    
5624                    QueryPos qPos = QueryPos.getInstance(q);
5625    
5626                    qPos.add(userId);
5627    
5628                    qPos.add(delivered);
5629    
5630                    qPos.add(actionRequired);
5631    
5632                    if (orderByComparator != null) {
5633                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
5634    
5635                            for (Object value : values) {
5636                                    qPos.add(value);
5637                            }
5638                    }
5639    
5640                    List<UserNotificationEvent> list = q.list();
5641    
5642                    if (list.size() == 2) {
5643                            return list.get(1);
5644                    }
5645                    else {
5646                            return null;
5647                    }
5648            }
5649    
5650            /**
5651             * Removes all the user notification events where userId = &#63; and delivered = &#63; and actionRequired = &#63; from the database.
5652             *
5653             * @param userId the user ID
5654             * @param delivered the delivered
5655             * @param actionRequired the action required
5656             */
5657            @Override
5658            public void removeByU_D_A(long userId, boolean delivered,
5659                    boolean actionRequired) {
5660                    for (UserNotificationEvent userNotificationEvent : findByU_D_A(userId,
5661                                    delivered, actionRequired, QueryUtil.ALL_POS,
5662                                    QueryUtil.ALL_POS, null)) {
5663                            remove(userNotificationEvent);
5664                    }
5665            }
5666    
5667            /**
5668             * Returns the number of user notification events where userId = &#63; and delivered = &#63; and actionRequired = &#63;.
5669             *
5670             * @param userId the user ID
5671             * @param delivered the delivered
5672             * @param actionRequired the action required
5673             * @return the number of matching user notification events
5674             */
5675            @Override
5676            public int countByU_D_A(long userId, boolean delivered,
5677                    boolean actionRequired) {
5678                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_D_A;
5679    
5680                    Object[] finderArgs = new Object[] { userId, delivered, actionRequired };
5681    
5682                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5683    
5684                    if (count == null) {
5685                            StringBundler query = new StringBundler(4);
5686    
5687                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
5688    
5689                            query.append(_FINDER_COLUMN_U_D_A_USERID_2);
5690    
5691                            query.append(_FINDER_COLUMN_U_D_A_DELIVERED_2);
5692    
5693                            query.append(_FINDER_COLUMN_U_D_A_ACTIONREQUIRED_2);
5694    
5695                            String sql = query.toString();
5696    
5697                            Session session = null;
5698    
5699                            try {
5700                                    session = openSession();
5701    
5702                                    Query q = session.createQuery(sql);
5703    
5704                                    QueryPos qPos = QueryPos.getInstance(q);
5705    
5706                                    qPos.add(userId);
5707    
5708                                    qPos.add(delivered);
5709    
5710                                    qPos.add(actionRequired);
5711    
5712                                    count = (Long)q.uniqueResult();
5713    
5714                                    finderCache.putResult(finderPath, finderArgs, count);
5715                            }
5716                            catch (Exception e) {
5717                                    finderCache.removeResult(finderPath, finderArgs);
5718    
5719                                    throw processException(e);
5720                            }
5721                            finally {
5722                                    closeSession(session);
5723                            }
5724                    }
5725    
5726                    return count.intValue();
5727            }
5728    
5729            private static final String _FINDER_COLUMN_U_D_A_USERID_2 = "userNotificationEvent.userId = ? AND ";
5730            private static final String _FINDER_COLUMN_U_D_A_DELIVERED_2 = "userNotificationEvent.delivered = ? AND ";
5731            private static final String _FINDER_COLUMN_U_D_A_ACTIONREQUIRED_2 = "userNotificationEvent.actionRequired = ?";
5732            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_A_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
5733                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
5734                            UserNotificationEventImpl.class,
5735                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_A_A",
5736                            new String[] {
5737                                    Long.class.getName(), Boolean.class.getName(),
5738                                    Boolean.class.getName(),
5739                                    
5740                            Integer.class.getName(), Integer.class.getName(),
5741                                    OrderByComparator.class.getName()
5742                            });
5743            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
5744                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
5745                            UserNotificationEventImpl.class,
5746                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_A_A",
5747                            new String[] {
5748                                    Long.class.getName(), Boolean.class.getName(),
5749                                    Boolean.class.getName()
5750                            },
5751                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
5752                            UserNotificationEventModelImpl.ACTIONREQUIRED_COLUMN_BITMASK |
5753                            UserNotificationEventModelImpl.ARCHIVED_COLUMN_BITMASK |
5754                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
5755            public static final FinderPath FINDER_PATH_COUNT_BY_U_A_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
5756                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
5757                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_A_A",
5758                            new String[] {
5759                                    Long.class.getName(), Boolean.class.getName(),
5760                                    Boolean.class.getName()
5761                            });
5762    
5763            /**
5764             * Returns all the user notification events where userId = &#63; and actionRequired = &#63; and archived = &#63;.
5765             *
5766             * @param userId the user ID
5767             * @param actionRequired the action required
5768             * @param archived the archived
5769             * @return the matching user notification events
5770             */
5771            @Override
5772            public List<UserNotificationEvent> findByU_A_A(long userId,
5773                    boolean actionRequired, boolean archived) {
5774                    return findByU_A_A(userId, actionRequired, archived, QueryUtil.ALL_POS,
5775                            QueryUtil.ALL_POS, null);
5776            }
5777    
5778            /**
5779             * Returns a range of all the user notification events where userId = &#63; and actionRequired = &#63; and archived = &#63;.
5780             *
5781             * <p>
5782             * 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 UserNotificationEventModelImpl}. 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.
5783             * </p>
5784             *
5785             * @param userId the user ID
5786             * @param actionRequired the action required
5787             * @param archived the archived
5788             * @param start the lower bound of the range of user notification events
5789             * @param end the upper bound of the range of user notification events (not inclusive)
5790             * @return the range of matching user notification events
5791             */
5792            @Override
5793            public List<UserNotificationEvent> findByU_A_A(long userId,
5794                    boolean actionRequired, boolean archived, int start, int end) {
5795                    return findByU_A_A(userId, actionRequired, archived, start, end, null);
5796            }
5797    
5798            /**
5799             * Returns an ordered range of all the user notification events where userId = &#63; and actionRequired = &#63; and archived = &#63;.
5800             *
5801             * <p>
5802             * 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 UserNotificationEventModelImpl}. 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.
5803             * </p>
5804             *
5805             * @param userId the user ID
5806             * @param actionRequired the action required
5807             * @param archived the archived
5808             * @param start the lower bound of the range of user notification events
5809             * @param end the upper bound of the range of user notification events (not inclusive)
5810             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5811             * @return the ordered range of matching user notification events
5812             */
5813            @Override
5814            public List<UserNotificationEvent> findByU_A_A(long userId,
5815                    boolean actionRequired, boolean archived, int start, int end,
5816                    OrderByComparator<UserNotificationEvent> orderByComparator) {
5817                    return findByU_A_A(userId, actionRequired, archived, start, end,
5818                            orderByComparator, true);
5819            }
5820    
5821            /**
5822             * Returns an ordered range of all the user notification events where userId = &#63; and actionRequired = &#63; and archived = &#63;.
5823             *
5824             * <p>
5825             * 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 UserNotificationEventModelImpl}. 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.
5826             * </p>
5827             *
5828             * @param userId the user ID
5829             * @param actionRequired the action required
5830             * @param archived the archived
5831             * @param start the lower bound of the range of user notification events
5832             * @param end the upper bound of the range of user notification events (not inclusive)
5833             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5834             * @param retrieveFromCache whether to retrieve from the finder cache
5835             * @return the ordered range of matching user notification events
5836             */
5837            @Override
5838            public List<UserNotificationEvent> findByU_A_A(long userId,
5839                    boolean actionRequired, boolean archived, int start, int end,
5840                    OrderByComparator<UserNotificationEvent> orderByComparator,
5841                    boolean retrieveFromCache) {
5842                    boolean pagination = true;
5843                    FinderPath finderPath = null;
5844                    Object[] finderArgs = null;
5845    
5846                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5847                                    (orderByComparator == null)) {
5848                            pagination = false;
5849                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A_A;
5850                            finderArgs = new Object[] { userId, actionRequired, archived };
5851                    }
5852                    else {
5853                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_A_A;
5854                            finderArgs = new Object[] {
5855                                            userId, actionRequired, archived,
5856                                            
5857                                            start, end, orderByComparator
5858                                    };
5859                    }
5860    
5861                    List<UserNotificationEvent> list = null;
5862    
5863                    if (retrieveFromCache) {
5864                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
5865                                            finderArgs, this);
5866    
5867                            if ((list != null) && !list.isEmpty()) {
5868                                    for (UserNotificationEvent userNotificationEvent : list) {
5869                                            if ((userId != userNotificationEvent.getUserId()) ||
5870                                                            (actionRequired != userNotificationEvent.getActionRequired()) ||
5871                                                            (archived != userNotificationEvent.getArchived())) {
5872                                                    list = null;
5873    
5874                                                    break;
5875                                            }
5876                                    }
5877                            }
5878                    }
5879    
5880                    if (list == null) {
5881                            StringBundler query = null;
5882    
5883                            if (orderByComparator != null) {
5884                                    query = new StringBundler(5 +
5885                                                    (orderByComparator.getOrderByFields().length * 3));
5886                            }
5887                            else {
5888                                    query = new StringBundler(5);
5889                            }
5890    
5891                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
5892    
5893                            query.append(_FINDER_COLUMN_U_A_A_USERID_2);
5894    
5895                            query.append(_FINDER_COLUMN_U_A_A_ACTIONREQUIRED_2);
5896    
5897                            query.append(_FINDER_COLUMN_U_A_A_ARCHIVED_2);
5898    
5899                            if (orderByComparator != null) {
5900                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5901                                            orderByComparator);
5902                            }
5903                            else
5904                             if (pagination) {
5905                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
5906                            }
5907    
5908                            String sql = query.toString();
5909    
5910                            Session session = null;
5911    
5912                            try {
5913                                    session = openSession();
5914    
5915                                    Query q = session.createQuery(sql);
5916    
5917                                    QueryPos qPos = QueryPos.getInstance(q);
5918    
5919                                    qPos.add(userId);
5920    
5921                                    qPos.add(actionRequired);
5922    
5923                                    qPos.add(archived);
5924    
5925                                    if (!pagination) {
5926                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
5927                                                            getDialect(), start, end, false);
5928    
5929                                            Collections.sort(list);
5930    
5931                                            list = Collections.unmodifiableList(list);
5932                                    }
5933                                    else {
5934                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
5935                                                            getDialect(), start, end);
5936                                    }
5937    
5938                                    cacheResult(list);
5939    
5940                                    finderCache.putResult(finderPath, finderArgs, list);
5941                            }
5942                            catch (Exception e) {
5943                                    finderCache.removeResult(finderPath, finderArgs);
5944    
5945                                    throw processException(e);
5946                            }
5947                            finally {
5948                                    closeSession(session);
5949                            }
5950                    }
5951    
5952                    return list;
5953            }
5954    
5955            /**
5956             * Returns the first user notification event in the ordered set where userId = &#63; and actionRequired = &#63; and archived = &#63;.
5957             *
5958             * @param userId the user ID
5959             * @param actionRequired the action required
5960             * @param archived the archived
5961             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5962             * @return the first matching user notification event
5963             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
5964             */
5965            @Override
5966            public UserNotificationEvent findByU_A_A_First(long userId,
5967                    boolean actionRequired, boolean archived,
5968                    OrderByComparator<UserNotificationEvent> orderByComparator)
5969                    throws NoSuchUserNotificationEventException {
5970                    UserNotificationEvent userNotificationEvent = fetchByU_A_A_First(userId,
5971                                    actionRequired, archived, orderByComparator);
5972    
5973                    if (userNotificationEvent != null) {
5974                            return userNotificationEvent;
5975                    }
5976    
5977                    StringBundler msg = new StringBundler(8);
5978    
5979                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5980    
5981                    msg.append("userId=");
5982                    msg.append(userId);
5983    
5984                    msg.append(", actionRequired=");
5985                    msg.append(actionRequired);
5986    
5987                    msg.append(", archived=");
5988                    msg.append(archived);
5989    
5990                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5991    
5992                    throw new NoSuchUserNotificationEventException(msg.toString());
5993            }
5994    
5995            /**
5996             * Returns the first user notification event in the ordered set where userId = &#63; and actionRequired = &#63; and archived = &#63;.
5997             *
5998             * @param userId the user ID
5999             * @param actionRequired the action required
6000             * @param archived the archived
6001             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6002             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
6003             */
6004            @Override
6005            public UserNotificationEvent fetchByU_A_A_First(long userId,
6006                    boolean actionRequired, boolean archived,
6007                    OrderByComparator<UserNotificationEvent> orderByComparator) {
6008                    List<UserNotificationEvent> list = findByU_A_A(userId, actionRequired,
6009                                    archived, 0, 1, orderByComparator);
6010    
6011                    if (!list.isEmpty()) {
6012                            return list.get(0);
6013                    }
6014    
6015                    return null;
6016            }
6017    
6018            /**
6019             * Returns the last user notification event in the ordered set where userId = &#63; and actionRequired = &#63; and archived = &#63;.
6020             *
6021             * @param userId the user ID
6022             * @param actionRequired the action required
6023             * @param archived the archived
6024             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6025             * @return the last matching user notification event
6026             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
6027             */
6028            @Override
6029            public UserNotificationEvent findByU_A_A_Last(long userId,
6030                    boolean actionRequired, boolean archived,
6031                    OrderByComparator<UserNotificationEvent> orderByComparator)
6032                    throws NoSuchUserNotificationEventException {
6033                    UserNotificationEvent userNotificationEvent = fetchByU_A_A_Last(userId,
6034                                    actionRequired, archived, orderByComparator);
6035    
6036                    if (userNotificationEvent != null) {
6037                            return userNotificationEvent;
6038                    }
6039    
6040                    StringBundler msg = new StringBundler(8);
6041    
6042                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6043    
6044                    msg.append("userId=");
6045                    msg.append(userId);
6046    
6047                    msg.append(", actionRequired=");
6048                    msg.append(actionRequired);
6049    
6050                    msg.append(", archived=");
6051                    msg.append(archived);
6052    
6053                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6054    
6055                    throw new NoSuchUserNotificationEventException(msg.toString());
6056            }
6057    
6058            /**
6059             * Returns the last user notification event in the ordered set where userId = &#63; and actionRequired = &#63; and archived = &#63;.
6060             *
6061             * @param userId the user ID
6062             * @param actionRequired the action required
6063             * @param archived the archived
6064             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6065             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
6066             */
6067            @Override
6068            public UserNotificationEvent fetchByU_A_A_Last(long userId,
6069                    boolean actionRequired, boolean archived,
6070                    OrderByComparator<UserNotificationEvent> orderByComparator) {
6071                    int count = countByU_A_A(userId, actionRequired, archived);
6072    
6073                    if (count == 0) {
6074                            return null;
6075                    }
6076    
6077                    List<UserNotificationEvent> list = findByU_A_A(userId, actionRequired,
6078                                    archived, count - 1, count, orderByComparator);
6079    
6080                    if (!list.isEmpty()) {
6081                            return list.get(0);
6082                    }
6083    
6084                    return null;
6085            }
6086    
6087            /**
6088             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63; and actionRequired = &#63; and archived = &#63;.
6089             *
6090             * @param userNotificationEventId the primary key of the current user notification event
6091             * @param userId the user ID
6092             * @param actionRequired the action required
6093             * @param archived the archived
6094             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6095             * @return the previous, current, and next user notification event
6096             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
6097             */
6098            @Override
6099            public UserNotificationEvent[] findByU_A_A_PrevAndNext(
6100                    long userNotificationEventId, long userId, boolean actionRequired,
6101                    boolean archived,
6102                    OrderByComparator<UserNotificationEvent> orderByComparator)
6103                    throws NoSuchUserNotificationEventException {
6104                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
6105    
6106                    Session session = null;
6107    
6108                    try {
6109                            session = openSession();
6110    
6111                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
6112    
6113                            array[0] = getByU_A_A_PrevAndNext(session, userNotificationEvent,
6114                                            userId, actionRequired, archived, orderByComparator, true);
6115    
6116                            array[1] = userNotificationEvent;
6117    
6118                            array[2] = getByU_A_A_PrevAndNext(session, userNotificationEvent,
6119                                            userId, actionRequired, archived, orderByComparator, false);
6120    
6121                            return array;
6122                    }
6123                    catch (Exception e) {
6124                            throw processException(e);
6125                    }
6126                    finally {
6127                            closeSession(session);
6128                    }
6129            }
6130    
6131            protected UserNotificationEvent getByU_A_A_PrevAndNext(Session session,
6132                    UserNotificationEvent userNotificationEvent, long userId,
6133                    boolean actionRequired, boolean archived,
6134                    OrderByComparator<UserNotificationEvent> orderByComparator,
6135                    boolean previous) {
6136                    StringBundler query = null;
6137    
6138                    if (orderByComparator != null) {
6139                            query = new StringBundler(6 +
6140                                            (orderByComparator.getOrderByFields().length * 6));
6141                    }
6142                    else {
6143                            query = new StringBundler(3);
6144                    }
6145    
6146                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
6147    
6148                    query.append(_FINDER_COLUMN_U_A_A_USERID_2);
6149    
6150                    query.append(_FINDER_COLUMN_U_A_A_ACTIONREQUIRED_2);
6151    
6152                    query.append(_FINDER_COLUMN_U_A_A_ARCHIVED_2);
6153    
6154                    if (orderByComparator != null) {
6155                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6156    
6157                            if (orderByConditionFields.length > 0) {
6158                                    query.append(WHERE_AND);
6159                            }
6160    
6161                            for (int i = 0; i < orderByConditionFields.length; i++) {
6162                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6163                                    query.append(orderByConditionFields[i]);
6164    
6165                                    if ((i + 1) < orderByConditionFields.length) {
6166                                            if (orderByComparator.isAscending() ^ previous) {
6167                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6168                                            }
6169                                            else {
6170                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6171                                            }
6172                                    }
6173                                    else {
6174                                            if (orderByComparator.isAscending() ^ previous) {
6175                                                    query.append(WHERE_GREATER_THAN);
6176                                            }
6177                                            else {
6178                                                    query.append(WHERE_LESSER_THAN);
6179                                            }
6180                                    }
6181                            }
6182    
6183                            query.append(ORDER_BY_CLAUSE);
6184    
6185                            String[] orderByFields = orderByComparator.getOrderByFields();
6186    
6187                            for (int i = 0; i < orderByFields.length; i++) {
6188                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6189                                    query.append(orderByFields[i]);
6190    
6191                                    if ((i + 1) < orderByFields.length) {
6192                                            if (orderByComparator.isAscending() ^ previous) {
6193                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6194                                            }
6195                                            else {
6196                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6197                                            }
6198                                    }
6199                                    else {
6200                                            if (orderByComparator.isAscending() ^ previous) {
6201                                                    query.append(ORDER_BY_ASC);
6202                                            }
6203                                            else {
6204                                                    query.append(ORDER_BY_DESC);
6205                                            }
6206                                    }
6207                            }
6208                    }
6209                    else {
6210                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
6211                    }
6212    
6213                    String sql = query.toString();
6214    
6215                    Query q = session.createQuery(sql);
6216    
6217                    q.setFirstResult(0);
6218                    q.setMaxResults(2);
6219    
6220                    QueryPos qPos = QueryPos.getInstance(q);
6221    
6222                    qPos.add(userId);
6223    
6224                    qPos.add(actionRequired);
6225    
6226                    qPos.add(archived);
6227    
6228                    if (orderByComparator != null) {
6229                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
6230    
6231                            for (Object value : values) {
6232                                    qPos.add(value);
6233                            }
6234                    }
6235    
6236                    List<UserNotificationEvent> list = q.list();
6237    
6238                    if (list.size() == 2) {
6239                            return list.get(1);
6240                    }
6241                    else {
6242                            return null;
6243                    }
6244            }
6245    
6246            /**
6247             * Removes all the user notification events where userId = &#63; and actionRequired = &#63; and archived = &#63; from the database.
6248             *
6249             * @param userId the user ID
6250             * @param actionRequired the action required
6251             * @param archived the archived
6252             */
6253            @Override
6254            public void removeByU_A_A(long userId, boolean actionRequired,
6255                    boolean archived) {
6256                    for (UserNotificationEvent userNotificationEvent : findByU_A_A(userId,
6257                                    actionRequired, archived, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6258                                    null)) {
6259                            remove(userNotificationEvent);
6260                    }
6261            }
6262    
6263            /**
6264             * Returns the number of user notification events where userId = &#63; and actionRequired = &#63; and archived = &#63;.
6265             *
6266             * @param userId the user ID
6267             * @param actionRequired the action required
6268             * @param archived the archived
6269             * @return the number of matching user notification events
6270             */
6271            @Override
6272            public int countByU_A_A(long userId, boolean actionRequired,
6273                    boolean archived) {
6274                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_A_A;
6275    
6276                    Object[] finderArgs = new Object[] { userId, actionRequired, archived };
6277    
6278                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6279    
6280                    if (count == null) {
6281                            StringBundler query = new StringBundler(4);
6282    
6283                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
6284    
6285                            query.append(_FINDER_COLUMN_U_A_A_USERID_2);
6286    
6287                            query.append(_FINDER_COLUMN_U_A_A_ACTIONREQUIRED_2);
6288    
6289                            query.append(_FINDER_COLUMN_U_A_A_ARCHIVED_2);
6290    
6291                            String sql = query.toString();
6292    
6293                            Session session = null;
6294    
6295                            try {
6296                                    session = openSession();
6297    
6298                                    Query q = session.createQuery(sql);
6299    
6300                                    QueryPos qPos = QueryPos.getInstance(q);
6301    
6302                                    qPos.add(userId);
6303    
6304                                    qPos.add(actionRequired);
6305    
6306                                    qPos.add(archived);
6307    
6308                                    count = (Long)q.uniqueResult();
6309    
6310                                    finderCache.putResult(finderPath, finderArgs, count);
6311                            }
6312                            catch (Exception e) {
6313                                    finderCache.removeResult(finderPath, finderArgs);
6314    
6315                                    throw processException(e);
6316                            }
6317                            finally {
6318                                    closeSession(session);
6319                            }
6320                    }
6321    
6322                    return count.intValue();
6323            }
6324    
6325            private static final String _FINDER_COLUMN_U_A_A_USERID_2 = "userNotificationEvent.userId = ? AND ";
6326            private static final String _FINDER_COLUMN_U_A_A_ACTIONREQUIRED_2 = "userNotificationEvent.actionRequired = ? AND ";
6327            private static final String _FINDER_COLUMN_U_A_A_ARCHIVED_2 = "userNotificationEvent.archived = ?";
6328            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_T_DT_D = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
6329                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
6330                            UserNotificationEventImpl.class,
6331                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_T_DT_D",
6332                            new String[] {
6333                                    Long.class.getName(), String.class.getName(),
6334                                    Integer.class.getName(), Boolean.class.getName(),
6335                                    
6336                            Integer.class.getName(), Integer.class.getName(),
6337                                    OrderByComparator.class.getName()
6338                            });
6339            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_T_DT_D =
6340                    new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
6341                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
6342                            UserNotificationEventImpl.class,
6343                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_T_DT_D",
6344                            new String[] {
6345                                    Long.class.getName(), String.class.getName(),
6346                                    Integer.class.getName(), Boolean.class.getName()
6347                            },
6348                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
6349                            UserNotificationEventModelImpl.TYPE_COLUMN_BITMASK |
6350                            UserNotificationEventModelImpl.DELIVERYTYPE_COLUMN_BITMASK |
6351                            UserNotificationEventModelImpl.DELIVERED_COLUMN_BITMASK |
6352                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
6353            public static final FinderPath FINDER_PATH_COUNT_BY_U_T_DT_D = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
6354                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
6355                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_T_DT_D",
6356                            new String[] {
6357                                    Long.class.getName(), String.class.getName(),
6358                                    Integer.class.getName(), Boolean.class.getName()
6359                            });
6360    
6361            /**
6362             * Returns all the user notification events where userId = &#63; and type = &#63; and deliveryType = &#63; and delivered = &#63;.
6363             *
6364             * @param userId the user ID
6365             * @param type the type
6366             * @param deliveryType the delivery type
6367             * @param delivered the delivered
6368             * @return the matching user notification events
6369             */
6370            @Override
6371            public List<UserNotificationEvent> findByU_T_DT_D(long userId, String type,
6372                    int deliveryType, boolean delivered) {
6373                    return findByU_T_DT_D(userId, type, deliveryType, delivered,
6374                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6375            }
6376    
6377            /**
6378             * Returns a range of all the user notification events where userId = &#63; and type = &#63; and deliveryType = &#63; and delivered = &#63;.
6379             *
6380             * <p>
6381             * 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 UserNotificationEventModelImpl}. 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.
6382             * </p>
6383             *
6384             * @param userId the user ID
6385             * @param type the type
6386             * @param deliveryType the delivery type
6387             * @param delivered the delivered
6388             * @param start the lower bound of the range of user notification events
6389             * @param end the upper bound of the range of user notification events (not inclusive)
6390             * @return the range of matching user notification events
6391             */
6392            @Override
6393            public List<UserNotificationEvent> findByU_T_DT_D(long userId, String type,
6394                    int deliveryType, boolean delivered, int start, int end) {
6395                    return findByU_T_DT_D(userId, type, deliveryType, delivered, start,
6396                            end, null);
6397            }
6398    
6399            /**
6400             * Returns an ordered range of all the user notification events where userId = &#63; and type = &#63; and deliveryType = &#63; and delivered = &#63;.
6401             *
6402             * <p>
6403             * 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 UserNotificationEventModelImpl}. 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.
6404             * </p>
6405             *
6406             * @param userId the user ID
6407             * @param type the type
6408             * @param deliveryType the delivery type
6409             * @param delivered the delivered
6410             * @param start the lower bound of the range of user notification events
6411             * @param end the upper bound of the range of user notification events (not inclusive)
6412             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6413             * @return the ordered range of matching user notification events
6414             */
6415            @Override
6416            public List<UserNotificationEvent> findByU_T_DT_D(long userId, String type,
6417                    int deliveryType, boolean delivered, int start, int end,
6418                    OrderByComparator<UserNotificationEvent> orderByComparator) {
6419                    return findByU_T_DT_D(userId, type, deliveryType, delivered, start,
6420                            end, orderByComparator, true);
6421            }
6422    
6423            /**
6424             * Returns an ordered range of all the user notification events where userId = &#63; and type = &#63; and deliveryType = &#63; and delivered = &#63;.
6425             *
6426             * <p>
6427             * 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 UserNotificationEventModelImpl}. 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.
6428             * </p>
6429             *
6430             * @param userId the user ID
6431             * @param type the type
6432             * @param deliveryType the delivery type
6433             * @param delivered the delivered
6434             * @param start the lower bound of the range of user notification events
6435             * @param end the upper bound of the range of user notification events (not inclusive)
6436             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6437             * @param retrieveFromCache whether to retrieve from the finder cache
6438             * @return the ordered range of matching user notification events
6439             */
6440            @Override
6441            public List<UserNotificationEvent> findByU_T_DT_D(long userId, String type,
6442                    int deliveryType, boolean delivered, int start, int end,
6443                    OrderByComparator<UserNotificationEvent> orderByComparator,
6444                    boolean retrieveFromCache) {
6445                    boolean pagination = true;
6446                    FinderPath finderPath = null;
6447                    Object[] finderArgs = null;
6448    
6449                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6450                                    (orderByComparator == null)) {
6451                            pagination = false;
6452                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_T_DT_D;
6453                            finderArgs = new Object[] { userId, type, deliveryType, delivered };
6454                    }
6455                    else {
6456                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_T_DT_D;
6457                            finderArgs = new Object[] {
6458                                            userId, type, deliveryType, delivered,
6459                                            
6460                                            start, end, orderByComparator
6461                                    };
6462                    }
6463    
6464                    List<UserNotificationEvent> list = null;
6465    
6466                    if (retrieveFromCache) {
6467                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
6468                                            finderArgs, this);
6469    
6470                            if ((list != null) && !list.isEmpty()) {
6471                                    for (UserNotificationEvent userNotificationEvent : list) {
6472                                            if ((userId != userNotificationEvent.getUserId()) ||
6473                                                            !Validator.equals(type,
6474                                                                    userNotificationEvent.getType()) ||
6475                                                            (deliveryType != userNotificationEvent.getDeliveryType()) ||
6476                                                            (delivered != userNotificationEvent.getDelivered())) {
6477                                                    list = null;
6478    
6479                                                    break;
6480                                            }
6481                                    }
6482                            }
6483                    }
6484    
6485                    if (list == null) {
6486                            StringBundler query = null;
6487    
6488                            if (orderByComparator != null) {
6489                                    query = new StringBundler(6 +
6490                                                    (orderByComparator.getOrderByFields().length * 3));
6491                            }
6492                            else {
6493                                    query = new StringBundler(6);
6494                            }
6495    
6496                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
6497    
6498                            query.append(_FINDER_COLUMN_U_T_DT_D_USERID_2);
6499    
6500                            boolean bindType = false;
6501    
6502                            if (type == null) {
6503                                    query.append(_FINDER_COLUMN_U_T_DT_D_TYPE_1);
6504                            }
6505                            else if (type.equals(StringPool.BLANK)) {
6506                                    query.append(_FINDER_COLUMN_U_T_DT_D_TYPE_3);
6507                            }
6508                            else {
6509                                    bindType = true;
6510    
6511                                    query.append(_FINDER_COLUMN_U_T_DT_D_TYPE_2);
6512                            }
6513    
6514                            query.append(_FINDER_COLUMN_U_T_DT_D_DELIVERYTYPE_2);
6515    
6516                            query.append(_FINDER_COLUMN_U_T_DT_D_DELIVERED_2);
6517    
6518                            if (orderByComparator != null) {
6519                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6520                                            orderByComparator);
6521                            }
6522                            else
6523                             if (pagination) {
6524                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
6525                            }
6526    
6527                            String sql = query.toString();
6528    
6529                            Session session = null;
6530    
6531                            try {
6532                                    session = openSession();
6533    
6534                                    Query q = session.createQuery(sql);
6535    
6536                                    QueryPos qPos = QueryPos.getInstance(q);
6537    
6538                                    qPos.add(userId);
6539    
6540                                    if (bindType) {
6541                                            qPos.add(type);
6542                                    }
6543    
6544                                    qPos.add(deliveryType);
6545    
6546                                    qPos.add(delivered);
6547    
6548                                    if (!pagination) {
6549                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
6550                                                            getDialect(), start, end, false);
6551    
6552                                            Collections.sort(list);
6553    
6554                                            list = Collections.unmodifiableList(list);
6555                                    }
6556                                    else {
6557                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
6558                                                            getDialect(), start, end);
6559                                    }
6560    
6561                                    cacheResult(list);
6562    
6563                                    finderCache.putResult(finderPath, finderArgs, list);
6564                            }
6565                            catch (Exception e) {
6566                                    finderCache.removeResult(finderPath, finderArgs);
6567    
6568                                    throw processException(e);
6569                            }
6570                            finally {
6571                                    closeSession(session);
6572                            }
6573                    }
6574    
6575                    return list;
6576            }
6577    
6578            /**
6579             * Returns the first user notification event in the ordered set where userId = &#63; and type = &#63; and deliveryType = &#63; and delivered = &#63;.
6580             *
6581             * @param userId the user ID
6582             * @param type the type
6583             * @param deliveryType the delivery type
6584             * @param delivered the delivered
6585             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6586             * @return the first matching user notification event
6587             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
6588             */
6589            @Override
6590            public UserNotificationEvent findByU_T_DT_D_First(long userId, String type,
6591                    int deliveryType, boolean delivered,
6592                    OrderByComparator<UserNotificationEvent> orderByComparator)
6593                    throws NoSuchUserNotificationEventException {
6594                    UserNotificationEvent userNotificationEvent = fetchByU_T_DT_D_First(userId,
6595                                    type, deliveryType, delivered, orderByComparator);
6596    
6597                    if (userNotificationEvent != null) {
6598                            return userNotificationEvent;
6599                    }
6600    
6601                    StringBundler msg = new StringBundler(10);
6602    
6603                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6604    
6605                    msg.append("userId=");
6606                    msg.append(userId);
6607    
6608                    msg.append(", type=");
6609                    msg.append(type);
6610    
6611                    msg.append(", deliveryType=");
6612                    msg.append(deliveryType);
6613    
6614                    msg.append(", delivered=");
6615                    msg.append(delivered);
6616    
6617                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6618    
6619                    throw new NoSuchUserNotificationEventException(msg.toString());
6620            }
6621    
6622            /**
6623             * Returns the first user notification event in the ordered set where userId = &#63; and type = &#63; and deliveryType = &#63; and delivered = &#63;.
6624             *
6625             * @param userId the user ID
6626             * @param type the type
6627             * @param deliveryType the delivery type
6628             * @param delivered the delivered
6629             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6630             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
6631             */
6632            @Override
6633            public UserNotificationEvent fetchByU_T_DT_D_First(long userId,
6634                    String type, int deliveryType, boolean delivered,
6635                    OrderByComparator<UserNotificationEvent> orderByComparator) {
6636                    List<UserNotificationEvent> list = findByU_T_DT_D(userId, type,
6637                                    deliveryType, delivered, 0, 1, orderByComparator);
6638    
6639                    if (!list.isEmpty()) {
6640                            return list.get(0);
6641                    }
6642    
6643                    return null;
6644            }
6645    
6646            /**
6647             * Returns the last user notification event in the ordered set where userId = &#63; and type = &#63; and deliveryType = &#63; and delivered = &#63;.
6648             *
6649             * @param userId the user ID
6650             * @param type the type
6651             * @param deliveryType the delivery type
6652             * @param delivered the delivered
6653             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6654             * @return the last matching user notification event
6655             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
6656             */
6657            @Override
6658            public UserNotificationEvent findByU_T_DT_D_Last(long userId, String type,
6659                    int deliveryType, boolean delivered,
6660                    OrderByComparator<UserNotificationEvent> orderByComparator)
6661                    throws NoSuchUserNotificationEventException {
6662                    UserNotificationEvent userNotificationEvent = fetchByU_T_DT_D_Last(userId,
6663                                    type, deliveryType, delivered, orderByComparator);
6664    
6665                    if (userNotificationEvent != null) {
6666                            return userNotificationEvent;
6667                    }
6668    
6669                    StringBundler msg = new StringBundler(10);
6670    
6671                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6672    
6673                    msg.append("userId=");
6674                    msg.append(userId);
6675    
6676                    msg.append(", type=");
6677                    msg.append(type);
6678    
6679                    msg.append(", deliveryType=");
6680                    msg.append(deliveryType);
6681    
6682                    msg.append(", delivered=");
6683                    msg.append(delivered);
6684    
6685                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6686    
6687                    throw new NoSuchUserNotificationEventException(msg.toString());
6688            }
6689    
6690            /**
6691             * Returns the last user notification event in the ordered set where userId = &#63; and type = &#63; and deliveryType = &#63; and delivered = &#63;.
6692             *
6693             * @param userId the user ID
6694             * @param type the type
6695             * @param deliveryType the delivery type
6696             * @param delivered the delivered
6697             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6698             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
6699             */
6700            @Override
6701            public UserNotificationEvent fetchByU_T_DT_D_Last(long userId, String type,
6702                    int deliveryType, boolean delivered,
6703                    OrderByComparator<UserNotificationEvent> orderByComparator) {
6704                    int count = countByU_T_DT_D(userId, type, deliveryType, delivered);
6705    
6706                    if (count == 0) {
6707                            return null;
6708                    }
6709    
6710                    List<UserNotificationEvent> list = findByU_T_DT_D(userId, type,
6711                                    deliveryType, delivered, count - 1, count, orderByComparator);
6712    
6713                    if (!list.isEmpty()) {
6714                            return list.get(0);
6715                    }
6716    
6717                    return null;
6718            }
6719    
6720            /**
6721             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63; and type = &#63; and deliveryType = &#63; and delivered = &#63;.
6722             *
6723             * @param userNotificationEventId the primary key of the current user notification event
6724             * @param userId the user ID
6725             * @param type the type
6726             * @param deliveryType the delivery type
6727             * @param delivered the delivered
6728             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6729             * @return the previous, current, and next user notification event
6730             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
6731             */
6732            @Override
6733            public UserNotificationEvent[] findByU_T_DT_D_PrevAndNext(
6734                    long userNotificationEventId, long userId, String type,
6735                    int deliveryType, boolean delivered,
6736                    OrderByComparator<UserNotificationEvent> orderByComparator)
6737                    throws NoSuchUserNotificationEventException {
6738                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
6739    
6740                    Session session = null;
6741    
6742                    try {
6743                            session = openSession();
6744    
6745                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
6746    
6747                            array[0] = getByU_T_DT_D_PrevAndNext(session,
6748                                            userNotificationEvent, userId, type, deliveryType,
6749                                            delivered, orderByComparator, true);
6750    
6751                            array[1] = userNotificationEvent;
6752    
6753                            array[2] = getByU_T_DT_D_PrevAndNext(session,
6754                                            userNotificationEvent, userId, type, deliveryType,
6755                                            delivered, orderByComparator, false);
6756    
6757                            return array;
6758                    }
6759                    catch (Exception e) {
6760                            throw processException(e);
6761                    }
6762                    finally {
6763                            closeSession(session);
6764                    }
6765            }
6766    
6767            protected UserNotificationEvent getByU_T_DT_D_PrevAndNext(Session session,
6768                    UserNotificationEvent userNotificationEvent, long userId, String type,
6769                    int deliveryType, boolean delivered,
6770                    OrderByComparator<UserNotificationEvent> orderByComparator,
6771                    boolean previous) {
6772                    StringBundler query = null;
6773    
6774                    if (orderByComparator != null) {
6775                            query = new StringBundler(6 +
6776                                            (orderByComparator.getOrderByFields().length * 6));
6777                    }
6778                    else {
6779                            query = new StringBundler(3);
6780                    }
6781    
6782                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
6783    
6784                    query.append(_FINDER_COLUMN_U_T_DT_D_USERID_2);
6785    
6786                    boolean bindType = false;
6787    
6788                    if (type == null) {
6789                            query.append(_FINDER_COLUMN_U_T_DT_D_TYPE_1);
6790                    }
6791                    else if (type.equals(StringPool.BLANK)) {
6792                            query.append(_FINDER_COLUMN_U_T_DT_D_TYPE_3);
6793                    }
6794                    else {
6795                            bindType = true;
6796    
6797                            query.append(_FINDER_COLUMN_U_T_DT_D_TYPE_2);
6798                    }
6799    
6800                    query.append(_FINDER_COLUMN_U_T_DT_D_DELIVERYTYPE_2);
6801    
6802                    query.append(_FINDER_COLUMN_U_T_DT_D_DELIVERED_2);
6803    
6804                    if (orderByComparator != null) {
6805                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6806    
6807                            if (orderByConditionFields.length > 0) {
6808                                    query.append(WHERE_AND);
6809                            }
6810    
6811                            for (int i = 0; i < orderByConditionFields.length; i++) {
6812                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6813                                    query.append(orderByConditionFields[i]);
6814    
6815                                    if ((i + 1) < orderByConditionFields.length) {
6816                                            if (orderByComparator.isAscending() ^ previous) {
6817                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6818                                            }
6819                                            else {
6820                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6821                                            }
6822                                    }
6823                                    else {
6824                                            if (orderByComparator.isAscending() ^ previous) {
6825                                                    query.append(WHERE_GREATER_THAN);
6826                                            }
6827                                            else {
6828                                                    query.append(WHERE_LESSER_THAN);
6829                                            }
6830                                    }
6831                            }
6832    
6833                            query.append(ORDER_BY_CLAUSE);
6834    
6835                            String[] orderByFields = orderByComparator.getOrderByFields();
6836    
6837                            for (int i = 0; i < orderByFields.length; i++) {
6838                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6839                                    query.append(orderByFields[i]);
6840    
6841                                    if ((i + 1) < orderByFields.length) {
6842                                            if (orderByComparator.isAscending() ^ previous) {
6843                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6844                                            }
6845                                            else {
6846                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6847                                            }
6848                                    }
6849                                    else {
6850                                            if (orderByComparator.isAscending() ^ previous) {
6851                                                    query.append(ORDER_BY_ASC);
6852                                            }
6853                                            else {
6854                                                    query.append(ORDER_BY_DESC);
6855                                            }
6856                                    }
6857                            }
6858                    }
6859                    else {
6860                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
6861                    }
6862    
6863                    String sql = query.toString();
6864    
6865                    Query q = session.createQuery(sql);
6866    
6867                    q.setFirstResult(0);
6868                    q.setMaxResults(2);
6869    
6870                    QueryPos qPos = QueryPos.getInstance(q);
6871    
6872                    qPos.add(userId);
6873    
6874                    if (bindType) {
6875                            qPos.add(type);
6876                    }
6877    
6878                    qPos.add(deliveryType);
6879    
6880                    qPos.add(delivered);
6881    
6882                    if (orderByComparator != null) {
6883                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
6884    
6885                            for (Object value : values) {
6886                                    qPos.add(value);
6887                            }
6888                    }
6889    
6890                    List<UserNotificationEvent> list = q.list();
6891    
6892                    if (list.size() == 2) {
6893                            return list.get(1);
6894                    }
6895                    else {
6896                            return null;
6897                    }
6898            }
6899    
6900            /**
6901             * Removes all the user notification events where userId = &#63; and type = &#63; and deliveryType = &#63; and delivered = &#63; from the database.
6902             *
6903             * @param userId the user ID
6904             * @param type the type
6905             * @param deliveryType the delivery type
6906             * @param delivered the delivered
6907             */
6908            @Override
6909            public void removeByU_T_DT_D(long userId, String type, int deliveryType,
6910                    boolean delivered) {
6911                    for (UserNotificationEvent userNotificationEvent : findByU_T_DT_D(
6912                                    userId, type, deliveryType, delivered, QueryUtil.ALL_POS,
6913                                    QueryUtil.ALL_POS, null)) {
6914                            remove(userNotificationEvent);
6915                    }
6916            }
6917    
6918            /**
6919             * Returns the number of user notification events where userId = &#63; and type = &#63; and deliveryType = &#63; and delivered = &#63;.
6920             *
6921             * @param userId the user ID
6922             * @param type the type
6923             * @param deliveryType the delivery type
6924             * @param delivered the delivered
6925             * @return the number of matching user notification events
6926             */
6927            @Override
6928            public int countByU_T_DT_D(long userId, String type, int deliveryType,
6929                    boolean delivered) {
6930                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_T_DT_D;
6931    
6932                    Object[] finderArgs = new Object[] { userId, type, deliveryType, delivered };
6933    
6934                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6935    
6936                    if (count == null) {
6937                            StringBundler query = new StringBundler(5);
6938    
6939                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
6940    
6941                            query.append(_FINDER_COLUMN_U_T_DT_D_USERID_2);
6942    
6943                            boolean bindType = false;
6944    
6945                            if (type == null) {
6946                                    query.append(_FINDER_COLUMN_U_T_DT_D_TYPE_1);
6947                            }
6948                            else if (type.equals(StringPool.BLANK)) {
6949                                    query.append(_FINDER_COLUMN_U_T_DT_D_TYPE_3);
6950                            }
6951                            else {
6952                                    bindType = true;
6953    
6954                                    query.append(_FINDER_COLUMN_U_T_DT_D_TYPE_2);
6955                            }
6956    
6957                            query.append(_FINDER_COLUMN_U_T_DT_D_DELIVERYTYPE_2);
6958    
6959                            query.append(_FINDER_COLUMN_U_T_DT_D_DELIVERED_2);
6960    
6961                            String sql = query.toString();
6962    
6963                            Session session = null;
6964    
6965                            try {
6966                                    session = openSession();
6967    
6968                                    Query q = session.createQuery(sql);
6969    
6970                                    QueryPos qPos = QueryPos.getInstance(q);
6971    
6972                                    qPos.add(userId);
6973    
6974                                    if (bindType) {
6975                                            qPos.add(type);
6976                                    }
6977    
6978                                    qPos.add(deliveryType);
6979    
6980                                    qPos.add(delivered);
6981    
6982                                    count = (Long)q.uniqueResult();
6983    
6984                                    finderCache.putResult(finderPath, finderArgs, count);
6985                            }
6986                            catch (Exception e) {
6987                                    finderCache.removeResult(finderPath, finderArgs);
6988    
6989                                    throw processException(e);
6990                            }
6991                            finally {
6992                                    closeSession(session);
6993                            }
6994                    }
6995    
6996                    return count.intValue();
6997            }
6998    
6999            private static final String _FINDER_COLUMN_U_T_DT_D_USERID_2 = "userNotificationEvent.userId = ? AND ";
7000            private static final String _FINDER_COLUMN_U_T_DT_D_TYPE_1 = "userNotificationEvent.type IS NULL AND ";
7001            private static final String _FINDER_COLUMN_U_T_DT_D_TYPE_2 = "userNotificationEvent.type = ? AND ";
7002            private static final String _FINDER_COLUMN_U_T_DT_D_TYPE_3 = "(userNotificationEvent.type IS NULL OR userNotificationEvent.type = '') AND ";
7003            private static final String _FINDER_COLUMN_U_T_DT_D_DELIVERYTYPE_2 = "userNotificationEvent.deliveryType = ? AND ";
7004            private static final String _FINDER_COLUMN_U_T_DT_D_DELIVERED_2 = "userNotificationEvent.delivered = ?";
7005            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_DT_D_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
7006                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
7007                            UserNotificationEventImpl.class,
7008                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_DT_D_A",
7009                            new String[] {
7010                                    Long.class.getName(), Integer.class.getName(),
7011                                    Boolean.class.getName(), Boolean.class.getName(),
7012                                    
7013                            Integer.class.getName(), Integer.class.getName(),
7014                                    OrderByComparator.class.getName()
7015                            });
7016            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_D_A =
7017                    new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
7018                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
7019                            UserNotificationEventImpl.class,
7020                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_DT_D_A",
7021                            new String[] {
7022                                    Long.class.getName(), Integer.class.getName(),
7023                                    Boolean.class.getName(), Boolean.class.getName()
7024                            },
7025                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
7026                            UserNotificationEventModelImpl.DELIVERYTYPE_COLUMN_BITMASK |
7027                            UserNotificationEventModelImpl.DELIVERED_COLUMN_BITMASK |
7028                            UserNotificationEventModelImpl.ACTIONREQUIRED_COLUMN_BITMASK |
7029                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
7030            public static final FinderPath FINDER_PATH_COUNT_BY_U_DT_D_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
7031                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
7032                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_DT_D_A",
7033                            new String[] {
7034                                    Long.class.getName(), Integer.class.getName(),
7035                                    Boolean.class.getName(), Boolean.class.getName()
7036                            });
7037    
7038            /**
7039             * Returns all the user notification events where userId = &#63; and deliveryType = &#63; and delivered = &#63; and actionRequired = &#63;.
7040             *
7041             * @param userId the user ID
7042             * @param deliveryType the delivery type
7043             * @param delivered the delivered
7044             * @param actionRequired the action required
7045             * @return the matching user notification events
7046             */
7047            @Override
7048            public List<UserNotificationEvent> findByU_DT_D_A(long userId,
7049                    int deliveryType, boolean delivered, boolean actionRequired) {
7050                    return findByU_DT_D_A(userId, deliveryType, delivered, actionRequired,
7051                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7052            }
7053    
7054            /**
7055             * Returns a range of all the user notification events where userId = &#63; and deliveryType = &#63; and delivered = &#63; and actionRequired = &#63;.
7056             *
7057             * <p>
7058             * 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 UserNotificationEventModelImpl}. 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.
7059             * </p>
7060             *
7061             * @param userId the user ID
7062             * @param deliveryType the delivery type
7063             * @param delivered the delivered
7064             * @param actionRequired the action required
7065             * @param start the lower bound of the range of user notification events
7066             * @param end the upper bound of the range of user notification events (not inclusive)
7067             * @return the range of matching user notification events
7068             */
7069            @Override
7070            public List<UserNotificationEvent> findByU_DT_D_A(long userId,
7071                    int deliveryType, boolean delivered, boolean actionRequired, int start,
7072                    int end) {
7073                    return findByU_DT_D_A(userId, deliveryType, delivered, actionRequired,
7074                            start, end, null);
7075            }
7076    
7077            /**
7078             * Returns an ordered range of all the user notification events where userId = &#63; and deliveryType = &#63; and delivered = &#63; and actionRequired = &#63;.
7079             *
7080             * <p>
7081             * 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 UserNotificationEventModelImpl}. 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.
7082             * </p>
7083             *
7084             * @param userId the user ID
7085             * @param deliveryType the delivery type
7086             * @param delivered the delivered
7087             * @param actionRequired the action required
7088             * @param start the lower bound of the range of user notification events
7089             * @param end the upper bound of the range of user notification events (not inclusive)
7090             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7091             * @return the ordered range of matching user notification events
7092             */
7093            @Override
7094            public List<UserNotificationEvent> findByU_DT_D_A(long userId,
7095                    int deliveryType, boolean delivered, boolean actionRequired, int start,
7096                    int end, OrderByComparator<UserNotificationEvent> orderByComparator) {
7097                    return findByU_DT_D_A(userId, deliveryType, delivered, actionRequired,
7098                            start, end, orderByComparator, true);
7099            }
7100    
7101            /**
7102             * Returns an ordered range of all the user notification events where userId = &#63; and deliveryType = &#63; and delivered = &#63; and actionRequired = &#63;.
7103             *
7104             * <p>
7105             * 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 UserNotificationEventModelImpl}. 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.
7106             * </p>
7107             *
7108             * @param userId the user ID
7109             * @param deliveryType the delivery type
7110             * @param delivered the delivered
7111             * @param actionRequired the action required
7112             * @param start the lower bound of the range of user notification events
7113             * @param end the upper bound of the range of user notification events (not inclusive)
7114             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7115             * @param retrieveFromCache whether to retrieve from the finder cache
7116             * @return the ordered range of matching user notification events
7117             */
7118            @Override
7119            public List<UserNotificationEvent> findByU_DT_D_A(long userId,
7120                    int deliveryType, boolean delivered, boolean actionRequired, int start,
7121                    int end, OrderByComparator<UserNotificationEvent> orderByComparator,
7122                    boolean retrieveFromCache) {
7123                    boolean pagination = true;
7124                    FinderPath finderPath = null;
7125                    Object[] finderArgs = null;
7126    
7127                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7128                                    (orderByComparator == null)) {
7129                            pagination = false;
7130                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_D_A;
7131                            finderArgs = new Object[] {
7132                                            userId, deliveryType, delivered, actionRequired
7133                                    };
7134                    }
7135                    else {
7136                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_DT_D_A;
7137                            finderArgs = new Object[] {
7138                                            userId, deliveryType, delivered, actionRequired,
7139                                            
7140                                            start, end, orderByComparator
7141                                    };
7142                    }
7143    
7144                    List<UserNotificationEvent> list = null;
7145    
7146                    if (retrieveFromCache) {
7147                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
7148                                            finderArgs, this);
7149    
7150                            if ((list != null) && !list.isEmpty()) {
7151                                    for (UserNotificationEvent userNotificationEvent : list) {
7152                                            if ((userId != userNotificationEvent.getUserId()) ||
7153                                                            (deliveryType != userNotificationEvent.getDeliveryType()) ||
7154                                                            (delivered != userNotificationEvent.getDelivered()) ||
7155                                                            (actionRequired != userNotificationEvent.getActionRequired())) {
7156                                                    list = null;
7157    
7158                                                    break;
7159                                            }
7160                                    }
7161                            }
7162                    }
7163    
7164                    if (list == null) {
7165                            StringBundler query = null;
7166    
7167                            if (orderByComparator != null) {
7168                                    query = new StringBundler(6 +
7169                                                    (orderByComparator.getOrderByFields().length * 3));
7170                            }
7171                            else {
7172                                    query = new StringBundler(6);
7173                            }
7174    
7175                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
7176    
7177                            query.append(_FINDER_COLUMN_U_DT_D_A_USERID_2);
7178    
7179                            query.append(_FINDER_COLUMN_U_DT_D_A_DELIVERYTYPE_2);
7180    
7181                            query.append(_FINDER_COLUMN_U_DT_D_A_DELIVERED_2);
7182    
7183                            query.append(_FINDER_COLUMN_U_DT_D_A_ACTIONREQUIRED_2);
7184    
7185                            if (orderByComparator != null) {
7186                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7187                                            orderByComparator);
7188                            }
7189                            else
7190                             if (pagination) {
7191                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
7192                            }
7193    
7194                            String sql = query.toString();
7195    
7196                            Session session = null;
7197    
7198                            try {
7199                                    session = openSession();
7200    
7201                                    Query q = session.createQuery(sql);
7202    
7203                                    QueryPos qPos = QueryPos.getInstance(q);
7204    
7205                                    qPos.add(userId);
7206    
7207                                    qPos.add(deliveryType);
7208    
7209                                    qPos.add(delivered);
7210    
7211                                    qPos.add(actionRequired);
7212    
7213                                    if (!pagination) {
7214                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
7215                                                            getDialect(), start, end, false);
7216    
7217                                            Collections.sort(list);
7218    
7219                                            list = Collections.unmodifiableList(list);
7220                                    }
7221                                    else {
7222                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
7223                                                            getDialect(), start, end);
7224                                    }
7225    
7226                                    cacheResult(list);
7227    
7228                                    finderCache.putResult(finderPath, finderArgs, list);
7229                            }
7230                            catch (Exception e) {
7231                                    finderCache.removeResult(finderPath, finderArgs);
7232    
7233                                    throw processException(e);
7234                            }
7235                            finally {
7236                                    closeSession(session);
7237                            }
7238                    }
7239    
7240                    return list;
7241            }
7242    
7243            /**
7244             * Returns the first user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and delivered = &#63; and actionRequired = &#63;.
7245             *
7246             * @param userId the user ID
7247             * @param deliveryType the delivery type
7248             * @param delivered the delivered
7249             * @param actionRequired the action required
7250             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7251             * @return the first matching user notification event
7252             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
7253             */
7254            @Override
7255            public UserNotificationEvent findByU_DT_D_A_First(long userId,
7256                    int deliveryType, boolean delivered, boolean actionRequired,
7257                    OrderByComparator<UserNotificationEvent> orderByComparator)
7258                    throws NoSuchUserNotificationEventException {
7259                    UserNotificationEvent userNotificationEvent = fetchByU_DT_D_A_First(userId,
7260                                    deliveryType, delivered, actionRequired, orderByComparator);
7261    
7262                    if (userNotificationEvent != null) {
7263                            return userNotificationEvent;
7264                    }
7265    
7266                    StringBundler msg = new StringBundler(10);
7267    
7268                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7269    
7270                    msg.append("userId=");
7271                    msg.append(userId);
7272    
7273                    msg.append(", deliveryType=");
7274                    msg.append(deliveryType);
7275    
7276                    msg.append(", delivered=");
7277                    msg.append(delivered);
7278    
7279                    msg.append(", actionRequired=");
7280                    msg.append(actionRequired);
7281    
7282                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7283    
7284                    throw new NoSuchUserNotificationEventException(msg.toString());
7285            }
7286    
7287            /**
7288             * Returns the first user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and delivered = &#63; and actionRequired = &#63;.
7289             *
7290             * @param userId the user ID
7291             * @param deliveryType the delivery type
7292             * @param delivered the delivered
7293             * @param actionRequired the action required
7294             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7295             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
7296             */
7297            @Override
7298            public UserNotificationEvent fetchByU_DT_D_A_First(long userId,
7299                    int deliveryType, boolean delivered, boolean actionRequired,
7300                    OrderByComparator<UserNotificationEvent> orderByComparator) {
7301                    List<UserNotificationEvent> list = findByU_DT_D_A(userId, deliveryType,
7302                                    delivered, actionRequired, 0, 1, orderByComparator);
7303    
7304                    if (!list.isEmpty()) {
7305                            return list.get(0);
7306                    }
7307    
7308                    return null;
7309            }
7310    
7311            /**
7312             * Returns the last user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and delivered = &#63; and actionRequired = &#63;.
7313             *
7314             * @param userId the user ID
7315             * @param deliveryType the delivery type
7316             * @param delivered the delivered
7317             * @param actionRequired the action required
7318             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7319             * @return the last matching user notification event
7320             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
7321             */
7322            @Override
7323            public UserNotificationEvent findByU_DT_D_A_Last(long userId,
7324                    int deliveryType, boolean delivered, boolean actionRequired,
7325                    OrderByComparator<UserNotificationEvent> orderByComparator)
7326                    throws NoSuchUserNotificationEventException {
7327                    UserNotificationEvent userNotificationEvent = fetchByU_DT_D_A_Last(userId,
7328                                    deliveryType, delivered, actionRequired, orderByComparator);
7329    
7330                    if (userNotificationEvent != null) {
7331                            return userNotificationEvent;
7332                    }
7333    
7334                    StringBundler msg = new StringBundler(10);
7335    
7336                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7337    
7338                    msg.append("userId=");
7339                    msg.append(userId);
7340    
7341                    msg.append(", deliveryType=");
7342                    msg.append(deliveryType);
7343    
7344                    msg.append(", delivered=");
7345                    msg.append(delivered);
7346    
7347                    msg.append(", actionRequired=");
7348                    msg.append(actionRequired);
7349    
7350                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7351    
7352                    throw new NoSuchUserNotificationEventException(msg.toString());
7353            }
7354    
7355            /**
7356             * Returns the last user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and delivered = &#63; and actionRequired = &#63;.
7357             *
7358             * @param userId the user ID
7359             * @param deliveryType the delivery type
7360             * @param delivered the delivered
7361             * @param actionRequired the action required
7362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7363             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
7364             */
7365            @Override
7366            public UserNotificationEvent fetchByU_DT_D_A_Last(long userId,
7367                    int deliveryType, boolean delivered, boolean actionRequired,
7368                    OrderByComparator<UserNotificationEvent> orderByComparator) {
7369                    int count = countByU_DT_D_A(userId, deliveryType, delivered,
7370                                    actionRequired);
7371    
7372                    if (count == 0) {
7373                            return null;
7374                    }
7375    
7376                    List<UserNotificationEvent> list = findByU_DT_D_A(userId, deliveryType,
7377                                    delivered, actionRequired, count - 1, count, orderByComparator);
7378    
7379                    if (!list.isEmpty()) {
7380                            return list.get(0);
7381                    }
7382    
7383                    return null;
7384            }
7385    
7386            /**
7387             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and delivered = &#63; and actionRequired = &#63;.
7388             *
7389             * @param userNotificationEventId the primary key of the current user notification event
7390             * @param userId the user ID
7391             * @param deliveryType the delivery type
7392             * @param delivered the delivered
7393             * @param actionRequired the action required
7394             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7395             * @return the previous, current, and next user notification event
7396             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
7397             */
7398            @Override
7399            public UserNotificationEvent[] findByU_DT_D_A_PrevAndNext(
7400                    long userNotificationEventId, long userId, int deliveryType,
7401                    boolean delivered, boolean actionRequired,
7402                    OrderByComparator<UserNotificationEvent> orderByComparator)
7403                    throws NoSuchUserNotificationEventException {
7404                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
7405    
7406                    Session session = null;
7407    
7408                    try {
7409                            session = openSession();
7410    
7411                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
7412    
7413                            array[0] = getByU_DT_D_A_PrevAndNext(session,
7414                                            userNotificationEvent, userId, deliveryType, delivered,
7415                                            actionRequired, orderByComparator, true);
7416    
7417                            array[1] = userNotificationEvent;
7418    
7419                            array[2] = getByU_DT_D_A_PrevAndNext(session,
7420                                            userNotificationEvent, userId, deliveryType, delivered,
7421                                            actionRequired, orderByComparator, false);
7422    
7423                            return array;
7424                    }
7425                    catch (Exception e) {
7426                            throw processException(e);
7427                    }
7428                    finally {
7429                            closeSession(session);
7430                    }
7431            }
7432    
7433            protected UserNotificationEvent getByU_DT_D_A_PrevAndNext(Session session,
7434                    UserNotificationEvent userNotificationEvent, long userId,
7435                    int deliveryType, boolean delivered, boolean actionRequired,
7436                    OrderByComparator<UserNotificationEvent> orderByComparator,
7437                    boolean previous) {
7438                    StringBundler query = null;
7439    
7440                    if (orderByComparator != null) {
7441                            query = new StringBundler(6 +
7442                                            (orderByComparator.getOrderByFields().length * 6));
7443                    }
7444                    else {
7445                            query = new StringBundler(3);
7446                    }
7447    
7448                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
7449    
7450                    query.append(_FINDER_COLUMN_U_DT_D_A_USERID_2);
7451    
7452                    query.append(_FINDER_COLUMN_U_DT_D_A_DELIVERYTYPE_2);
7453    
7454                    query.append(_FINDER_COLUMN_U_DT_D_A_DELIVERED_2);
7455    
7456                    query.append(_FINDER_COLUMN_U_DT_D_A_ACTIONREQUIRED_2);
7457    
7458                    if (orderByComparator != null) {
7459                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7460    
7461                            if (orderByConditionFields.length > 0) {
7462                                    query.append(WHERE_AND);
7463                            }
7464    
7465                            for (int i = 0; i < orderByConditionFields.length; i++) {
7466                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7467                                    query.append(orderByConditionFields[i]);
7468    
7469                                    if ((i + 1) < orderByConditionFields.length) {
7470                                            if (orderByComparator.isAscending() ^ previous) {
7471                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7472                                            }
7473                                            else {
7474                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7475                                            }
7476                                    }
7477                                    else {
7478                                            if (orderByComparator.isAscending() ^ previous) {
7479                                                    query.append(WHERE_GREATER_THAN);
7480                                            }
7481                                            else {
7482                                                    query.append(WHERE_LESSER_THAN);
7483                                            }
7484                                    }
7485                            }
7486    
7487                            query.append(ORDER_BY_CLAUSE);
7488    
7489                            String[] orderByFields = orderByComparator.getOrderByFields();
7490    
7491                            for (int i = 0; i < orderByFields.length; i++) {
7492                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7493                                    query.append(orderByFields[i]);
7494    
7495                                    if ((i + 1) < orderByFields.length) {
7496                                            if (orderByComparator.isAscending() ^ previous) {
7497                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7498                                            }
7499                                            else {
7500                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7501                                            }
7502                                    }
7503                                    else {
7504                                            if (orderByComparator.isAscending() ^ previous) {
7505                                                    query.append(ORDER_BY_ASC);
7506                                            }
7507                                            else {
7508                                                    query.append(ORDER_BY_DESC);
7509                                            }
7510                                    }
7511                            }
7512                    }
7513                    else {
7514                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
7515                    }
7516    
7517                    String sql = query.toString();
7518    
7519                    Query q = session.createQuery(sql);
7520    
7521                    q.setFirstResult(0);
7522                    q.setMaxResults(2);
7523    
7524                    QueryPos qPos = QueryPos.getInstance(q);
7525    
7526                    qPos.add(userId);
7527    
7528                    qPos.add(deliveryType);
7529    
7530                    qPos.add(delivered);
7531    
7532                    qPos.add(actionRequired);
7533    
7534                    if (orderByComparator != null) {
7535                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
7536    
7537                            for (Object value : values) {
7538                                    qPos.add(value);
7539                            }
7540                    }
7541    
7542                    List<UserNotificationEvent> list = q.list();
7543    
7544                    if (list.size() == 2) {
7545                            return list.get(1);
7546                    }
7547                    else {
7548                            return null;
7549                    }
7550            }
7551    
7552            /**
7553             * Removes all the user notification events where userId = &#63; and deliveryType = &#63; and delivered = &#63; and actionRequired = &#63; from the database.
7554             *
7555             * @param userId the user ID
7556             * @param deliveryType the delivery type
7557             * @param delivered the delivered
7558             * @param actionRequired the action required
7559             */
7560            @Override
7561            public void removeByU_DT_D_A(long userId, int deliveryType,
7562                    boolean delivered, boolean actionRequired) {
7563                    for (UserNotificationEvent userNotificationEvent : findByU_DT_D_A(
7564                                    userId, deliveryType, delivered, actionRequired,
7565                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7566                            remove(userNotificationEvent);
7567                    }
7568            }
7569    
7570            /**
7571             * Returns the number of user notification events where userId = &#63; and deliveryType = &#63; and delivered = &#63; and actionRequired = &#63;.
7572             *
7573             * @param userId the user ID
7574             * @param deliveryType the delivery type
7575             * @param delivered the delivered
7576             * @param actionRequired the action required
7577             * @return the number of matching user notification events
7578             */
7579            @Override
7580            public int countByU_DT_D_A(long userId, int deliveryType,
7581                    boolean delivered, boolean actionRequired) {
7582                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_DT_D_A;
7583    
7584                    Object[] finderArgs = new Object[] {
7585                                    userId, deliveryType, delivered, actionRequired
7586                            };
7587    
7588                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7589    
7590                    if (count == null) {
7591                            StringBundler query = new StringBundler(5);
7592    
7593                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
7594    
7595                            query.append(_FINDER_COLUMN_U_DT_D_A_USERID_2);
7596    
7597                            query.append(_FINDER_COLUMN_U_DT_D_A_DELIVERYTYPE_2);
7598    
7599                            query.append(_FINDER_COLUMN_U_DT_D_A_DELIVERED_2);
7600    
7601                            query.append(_FINDER_COLUMN_U_DT_D_A_ACTIONREQUIRED_2);
7602    
7603                            String sql = query.toString();
7604    
7605                            Session session = null;
7606    
7607                            try {
7608                                    session = openSession();
7609    
7610                                    Query q = session.createQuery(sql);
7611    
7612                                    QueryPos qPos = QueryPos.getInstance(q);
7613    
7614                                    qPos.add(userId);
7615    
7616                                    qPos.add(deliveryType);
7617    
7618                                    qPos.add(delivered);
7619    
7620                                    qPos.add(actionRequired);
7621    
7622                                    count = (Long)q.uniqueResult();
7623    
7624                                    finderCache.putResult(finderPath, finderArgs, count);
7625                            }
7626                            catch (Exception e) {
7627                                    finderCache.removeResult(finderPath, finderArgs);
7628    
7629                                    throw processException(e);
7630                            }
7631                            finally {
7632                                    closeSession(session);
7633                            }
7634                    }
7635    
7636                    return count.intValue();
7637            }
7638    
7639            private static final String _FINDER_COLUMN_U_DT_D_A_USERID_2 = "userNotificationEvent.userId = ? AND ";
7640            private static final String _FINDER_COLUMN_U_DT_D_A_DELIVERYTYPE_2 = "userNotificationEvent.deliveryType = ? AND ";
7641            private static final String _FINDER_COLUMN_U_DT_D_A_DELIVERED_2 = "userNotificationEvent.delivered = ? AND ";
7642            private static final String _FINDER_COLUMN_U_DT_D_A_ACTIONREQUIRED_2 = "userNotificationEvent.actionRequired = ?";
7643            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_DT_A_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
7644                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
7645                            UserNotificationEventImpl.class,
7646                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_DT_A_A",
7647                            new String[] {
7648                                    Long.class.getName(), Integer.class.getName(),
7649                                    Boolean.class.getName(), Boolean.class.getName(),
7650                                    
7651                            Integer.class.getName(), Integer.class.getName(),
7652                                    OrderByComparator.class.getName()
7653                            });
7654            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_A_A =
7655                    new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
7656                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
7657                            UserNotificationEventImpl.class,
7658                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_DT_A_A",
7659                            new String[] {
7660                                    Long.class.getName(), Integer.class.getName(),
7661                                    Boolean.class.getName(), Boolean.class.getName()
7662                            },
7663                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
7664                            UserNotificationEventModelImpl.DELIVERYTYPE_COLUMN_BITMASK |
7665                            UserNotificationEventModelImpl.ACTIONREQUIRED_COLUMN_BITMASK |
7666                            UserNotificationEventModelImpl.ARCHIVED_COLUMN_BITMASK |
7667                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
7668            public static final FinderPath FINDER_PATH_COUNT_BY_U_DT_A_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
7669                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
7670                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_DT_A_A",
7671                            new String[] {
7672                                    Long.class.getName(), Integer.class.getName(),
7673                                    Boolean.class.getName(), Boolean.class.getName()
7674                            });
7675    
7676            /**
7677             * Returns all the user notification events where userId = &#63; and deliveryType = &#63; and actionRequired = &#63; and archived = &#63;.
7678             *
7679             * @param userId the user ID
7680             * @param deliveryType the delivery type
7681             * @param actionRequired the action required
7682             * @param archived the archived
7683             * @return the matching user notification events
7684             */
7685            @Override
7686            public List<UserNotificationEvent> findByU_DT_A_A(long userId,
7687                    int deliveryType, boolean actionRequired, boolean archived) {
7688                    return findByU_DT_A_A(userId, deliveryType, actionRequired, archived,
7689                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7690            }
7691    
7692            /**
7693             * Returns a range of all the user notification events where userId = &#63; and deliveryType = &#63; and actionRequired = &#63; and archived = &#63;.
7694             *
7695             * <p>
7696             * 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 UserNotificationEventModelImpl}. 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.
7697             * </p>
7698             *
7699             * @param userId the user ID
7700             * @param deliveryType the delivery type
7701             * @param actionRequired the action required
7702             * @param archived the archived
7703             * @param start the lower bound of the range of user notification events
7704             * @param end the upper bound of the range of user notification events (not inclusive)
7705             * @return the range of matching user notification events
7706             */
7707            @Override
7708            public List<UserNotificationEvent> findByU_DT_A_A(long userId,
7709                    int deliveryType, boolean actionRequired, boolean archived, int start,
7710                    int end) {
7711                    return findByU_DT_A_A(userId, deliveryType, actionRequired, archived,
7712                            start, end, null);
7713            }
7714    
7715            /**
7716             * Returns an ordered range of all the user notification events where userId = &#63; and deliveryType = &#63; and actionRequired = &#63; and archived = &#63;.
7717             *
7718             * <p>
7719             * 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 UserNotificationEventModelImpl}. 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.
7720             * </p>
7721             *
7722             * @param userId the user ID
7723             * @param deliveryType the delivery type
7724             * @param actionRequired the action required
7725             * @param archived the archived
7726             * @param start the lower bound of the range of user notification events
7727             * @param end the upper bound of the range of user notification events (not inclusive)
7728             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7729             * @return the ordered range of matching user notification events
7730             */
7731            @Override
7732            public List<UserNotificationEvent> findByU_DT_A_A(long userId,
7733                    int deliveryType, boolean actionRequired, boolean archived, int start,
7734                    int end, OrderByComparator<UserNotificationEvent> orderByComparator) {
7735                    return findByU_DT_A_A(userId, deliveryType, actionRequired, archived,
7736                            start, end, orderByComparator, true);
7737            }
7738    
7739            /**
7740             * Returns an ordered range of all the user notification events where userId = &#63; and deliveryType = &#63; and actionRequired = &#63; and archived = &#63;.
7741             *
7742             * <p>
7743             * 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 UserNotificationEventModelImpl}. 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.
7744             * </p>
7745             *
7746             * @param userId the user ID
7747             * @param deliveryType the delivery type
7748             * @param actionRequired the action required
7749             * @param archived the archived
7750             * @param start the lower bound of the range of user notification events
7751             * @param end the upper bound of the range of user notification events (not inclusive)
7752             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7753             * @param retrieveFromCache whether to retrieve from the finder cache
7754             * @return the ordered range of matching user notification events
7755             */
7756            @Override
7757            public List<UserNotificationEvent> findByU_DT_A_A(long userId,
7758                    int deliveryType, boolean actionRequired, boolean archived, int start,
7759                    int end, OrderByComparator<UserNotificationEvent> orderByComparator,
7760                    boolean retrieveFromCache) {
7761                    boolean pagination = true;
7762                    FinderPath finderPath = null;
7763                    Object[] finderArgs = null;
7764    
7765                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7766                                    (orderByComparator == null)) {
7767                            pagination = false;
7768                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_A_A;
7769                            finderArgs = new Object[] {
7770                                            userId, deliveryType, actionRequired, archived
7771                                    };
7772                    }
7773                    else {
7774                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_DT_A_A;
7775                            finderArgs = new Object[] {
7776                                            userId, deliveryType, actionRequired, archived,
7777                                            
7778                                            start, end, orderByComparator
7779                                    };
7780                    }
7781    
7782                    List<UserNotificationEvent> list = null;
7783    
7784                    if (retrieveFromCache) {
7785                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
7786                                            finderArgs, this);
7787    
7788                            if ((list != null) && !list.isEmpty()) {
7789                                    for (UserNotificationEvent userNotificationEvent : list) {
7790                                            if ((userId != userNotificationEvent.getUserId()) ||
7791                                                            (deliveryType != userNotificationEvent.getDeliveryType()) ||
7792                                                            (actionRequired != userNotificationEvent.getActionRequired()) ||
7793                                                            (archived != userNotificationEvent.getArchived())) {
7794                                                    list = null;
7795    
7796                                                    break;
7797                                            }
7798                                    }
7799                            }
7800                    }
7801    
7802                    if (list == null) {
7803                            StringBundler query = null;
7804    
7805                            if (orderByComparator != null) {
7806                                    query = new StringBundler(6 +
7807                                                    (orderByComparator.getOrderByFields().length * 3));
7808                            }
7809                            else {
7810                                    query = new StringBundler(6);
7811                            }
7812    
7813                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
7814    
7815                            query.append(_FINDER_COLUMN_U_DT_A_A_USERID_2);
7816    
7817                            query.append(_FINDER_COLUMN_U_DT_A_A_DELIVERYTYPE_2);
7818    
7819                            query.append(_FINDER_COLUMN_U_DT_A_A_ACTIONREQUIRED_2);
7820    
7821                            query.append(_FINDER_COLUMN_U_DT_A_A_ARCHIVED_2);
7822    
7823                            if (orderByComparator != null) {
7824                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7825                                            orderByComparator);
7826                            }
7827                            else
7828                             if (pagination) {
7829                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
7830                            }
7831    
7832                            String sql = query.toString();
7833    
7834                            Session session = null;
7835    
7836                            try {
7837                                    session = openSession();
7838    
7839                                    Query q = session.createQuery(sql);
7840    
7841                                    QueryPos qPos = QueryPos.getInstance(q);
7842    
7843                                    qPos.add(userId);
7844    
7845                                    qPos.add(deliveryType);
7846    
7847                                    qPos.add(actionRequired);
7848    
7849                                    qPos.add(archived);
7850    
7851                                    if (!pagination) {
7852                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
7853                                                            getDialect(), start, end, false);
7854    
7855                                            Collections.sort(list);
7856    
7857                                            list = Collections.unmodifiableList(list);
7858                                    }
7859                                    else {
7860                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
7861                                                            getDialect(), start, end);
7862                                    }
7863    
7864                                    cacheResult(list);
7865    
7866                                    finderCache.putResult(finderPath, finderArgs, list);
7867                            }
7868                            catch (Exception e) {
7869                                    finderCache.removeResult(finderPath, finderArgs);
7870    
7871                                    throw processException(e);
7872                            }
7873                            finally {
7874                                    closeSession(session);
7875                            }
7876                    }
7877    
7878                    return list;
7879            }
7880    
7881            /**
7882             * Returns the first user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and actionRequired = &#63; and archived = &#63;.
7883             *
7884             * @param userId the user ID
7885             * @param deliveryType the delivery type
7886             * @param actionRequired the action required
7887             * @param archived the archived
7888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7889             * @return the first matching user notification event
7890             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
7891             */
7892            @Override
7893            public UserNotificationEvent findByU_DT_A_A_First(long userId,
7894                    int deliveryType, boolean actionRequired, boolean archived,
7895                    OrderByComparator<UserNotificationEvent> orderByComparator)
7896                    throws NoSuchUserNotificationEventException {
7897                    UserNotificationEvent userNotificationEvent = fetchByU_DT_A_A_First(userId,
7898                                    deliveryType, actionRequired, archived, orderByComparator);
7899    
7900                    if (userNotificationEvent != null) {
7901                            return userNotificationEvent;
7902                    }
7903    
7904                    StringBundler msg = new StringBundler(10);
7905    
7906                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7907    
7908                    msg.append("userId=");
7909                    msg.append(userId);
7910    
7911                    msg.append(", deliveryType=");
7912                    msg.append(deliveryType);
7913    
7914                    msg.append(", actionRequired=");
7915                    msg.append(actionRequired);
7916    
7917                    msg.append(", archived=");
7918                    msg.append(archived);
7919    
7920                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7921    
7922                    throw new NoSuchUserNotificationEventException(msg.toString());
7923            }
7924    
7925            /**
7926             * Returns the first user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and actionRequired = &#63; and archived = &#63;.
7927             *
7928             * @param userId the user ID
7929             * @param deliveryType the delivery type
7930             * @param actionRequired the action required
7931             * @param archived the archived
7932             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7933             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
7934             */
7935            @Override
7936            public UserNotificationEvent fetchByU_DT_A_A_First(long userId,
7937                    int deliveryType, boolean actionRequired, boolean archived,
7938                    OrderByComparator<UserNotificationEvent> orderByComparator) {
7939                    List<UserNotificationEvent> list = findByU_DT_A_A(userId, deliveryType,
7940                                    actionRequired, archived, 0, 1, orderByComparator);
7941    
7942                    if (!list.isEmpty()) {
7943                            return list.get(0);
7944                    }
7945    
7946                    return null;
7947            }
7948    
7949            /**
7950             * Returns the last user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and actionRequired = &#63; and archived = &#63;.
7951             *
7952             * @param userId the user ID
7953             * @param deliveryType the delivery type
7954             * @param actionRequired the action required
7955             * @param archived the archived
7956             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7957             * @return the last matching user notification event
7958             * @throws NoSuchUserNotificationEventException if a matching user notification event could not be found
7959             */
7960            @Override
7961            public UserNotificationEvent findByU_DT_A_A_Last(long userId,
7962                    int deliveryType, boolean actionRequired, boolean archived,
7963                    OrderByComparator<UserNotificationEvent> orderByComparator)
7964                    throws NoSuchUserNotificationEventException {
7965                    UserNotificationEvent userNotificationEvent = fetchByU_DT_A_A_Last(userId,
7966                                    deliveryType, actionRequired, archived, orderByComparator);
7967    
7968                    if (userNotificationEvent != null) {
7969                            return userNotificationEvent;
7970                    }
7971    
7972                    StringBundler msg = new StringBundler(10);
7973    
7974                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7975    
7976                    msg.append("userId=");
7977                    msg.append(userId);
7978    
7979                    msg.append(", deliveryType=");
7980                    msg.append(deliveryType);
7981    
7982                    msg.append(", actionRequired=");
7983                    msg.append(actionRequired);
7984    
7985                    msg.append(", archived=");
7986                    msg.append(archived);
7987    
7988                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7989    
7990                    throw new NoSuchUserNotificationEventException(msg.toString());
7991            }
7992    
7993            /**
7994             * Returns the last user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and actionRequired = &#63; and archived = &#63;.
7995             *
7996             * @param userId the user ID
7997             * @param deliveryType the delivery type
7998             * @param actionRequired the action required
7999             * @param archived the archived
8000             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8001             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
8002             */
8003            @Override
8004            public UserNotificationEvent fetchByU_DT_A_A_Last(long userId,
8005                    int deliveryType, boolean actionRequired, boolean archived,
8006                    OrderByComparator<UserNotificationEvent> orderByComparator) {
8007                    int count = countByU_DT_A_A(userId, deliveryType, actionRequired,
8008                                    archived);
8009    
8010                    if (count == 0) {
8011                            return null;
8012                    }
8013    
8014                    List<UserNotificationEvent> list = findByU_DT_A_A(userId, deliveryType,
8015                                    actionRequired, archived, count - 1, count, orderByComparator);
8016    
8017                    if (!list.isEmpty()) {
8018                            return list.get(0);
8019                    }
8020    
8021                    return null;
8022            }
8023    
8024            /**
8025             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63; and deliveryType = &#63; and actionRequired = &#63; and archived = &#63;.
8026             *
8027             * @param userNotificationEventId the primary key of the current user notification event
8028             * @param userId the user ID
8029             * @param deliveryType the delivery type
8030             * @param actionRequired the action required
8031             * @param archived the archived
8032             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8033             * @return the previous, current, and next user notification event
8034             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
8035             */
8036            @Override
8037            public UserNotificationEvent[] findByU_DT_A_A_PrevAndNext(
8038                    long userNotificationEventId, long userId, int deliveryType,
8039                    boolean actionRequired, boolean archived,
8040                    OrderByComparator<UserNotificationEvent> orderByComparator)
8041                    throws NoSuchUserNotificationEventException {
8042                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
8043    
8044                    Session session = null;
8045    
8046                    try {
8047                            session = openSession();
8048    
8049                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
8050    
8051                            array[0] = getByU_DT_A_A_PrevAndNext(session,
8052                                            userNotificationEvent, userId, deliveryType,
8053                                            actionRequired, archived, orderByComparator, true);
8054    
8055                            array[1] = userNotificationEvent;
8056    
8057                            array[2] = getByU_DT_A_A_PrevAndNext(session,
8058                                            userNotificationEvent, userId, deliveryType,
8059                                            actionRequired, archived, orderByComparator, false);
8060    
8061                            return array;
8062                    }
8063                    catch (Exception e) {
8064                            throw processException(e);
8065                    }
8066                    finally {
8067                            closeSession(session);
8068                    }
8069            }
8070    
8071            protected UserNotificationEvent getByU_DT_A_A_PrevAndNext(Session session,
8072                    UserNotificationEvent userNotificationEvent, long userId,
8073                    int deliveryType, boolean actionRequired, boolean archived,
8074                    OrderByComparator<UserNotificationEvent> orderByComparator,
8075                    boolean previous) {
8076                    StringBundler query = null;
8077    
8078                    if (orderByComparator != null) {
8079                            query = new StringBundler(6 +
8080                                            (orderByComparator.getOrderByFields().length * 6));
8081                    }
8082                    else {
8083                            query = new StringBundler(3);
8084                    }
8085    
8086                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
8087    
8088                    query.append(_FINDER_COLUMN_U_DT_A_A_USERID_2);
8089    
8090                    query.append(_FINDER_COLUMN_U_DT_A_A_DELIVERYTYPE_2);
8091    
8092                    query.append(_FINDER_COLUMN_U_DT_A_A_ACTIONREQUIRED_2);
8093    
8094                    query.append(_FINDER_COLUMN_U_DT_A_A_ARCHIVED_2);
8095    
8096                    if (orderByComparator != null) {
8097                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8098    
8099                            if (orderByConditionFields.length > 0) {
8100                                    query.append(WHERE_AND);
8101                            }
8102    
8103                            for (int i = 0; i < orderByConditionFields.length; i++) {
8104                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8105                                    query.append(orderByConditionFields[i]);
8106    
8107                                    if ((i + 1) < orderByConditionFields.length) {
8108                                            if (orderByComparator.isAscending() ^ previous) {
8109                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8110                                            }
8111                                            else {
8112                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8113                                            }
8114                                    }
8115                                    else {
8116                                            if (orderByComparator.isAscending() ^ previous) {
8117                                                    query.append(WHERE_GREATER_THAN);
8118                                            }
8119                                            else {
8120                                                    query.append(WHERE_LESSER_THAN);
8121                                            }
8122                                    }
8123                            }
8124    
8125                            query.append(ORDER_BY_CLAUSE);
8126    
8127                            String[] orderByFields = orderByComparator.getOrderByFields();
8128    
8129                            for (int i = 0; i < orderByFields.length; i++) {
8130                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8131                                    query.append(orderByFields[i]);
8132    
8133                                    if ((i + 1) < orderByFields.length) {
8134                                            if (orderByComparator.isAscending() ^ previous) {
8135                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8136                                            }
8137                                            else {
8138                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8139                                            }
8140                                    }
8141                                    else {
8142                                            if (orderByComparator.isAscending() ^ previous) {
8143                                                    query.append(ORDER_BY_ASC);
8144                                            }
8145                                            else {
8146                                                    query.append(ORDER_BY_DESC);
8147                                            }
8148                                    }
8149                            }
8150                    }
8151                    else {
8152                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
8153                    }
8154    
8155                    String sql = query.toString();
8156    
8157                    Query q = session.createQuery(sql);
8158    
8159                    q.setFirstResult(0);
8160                    q.setMaxResults(2);
8161    
8162                    QueryPos qPos = QueryPos.getInstance(q);
8163    
8164                    qPos.add(userId);
8165    
8166                    qPos.add(deliveryType);
8167    
8168                    qPos.add(actionRequired);
8169    
8170                    qPos.add(archived);
8171    
8172                    if (orderByComparator != null) {
8173                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
8174    
8175                            for (Object value : values) {
8176                                    qPos.add(value);
8177                            }
8178                    }
8179    
8180                    List<UserNotificationEvent> list = q.list();
8181    
8182                    if (list.size() == 2) {
8183                            return list.get(1);
8184                    }
8185                    else {
8186                            return null;
8187                    }
8188            }
8189    
8190            /**
8191             * Removes all the user notification events where userId = &#63; and deliveryType = &#63; and actionRequired = &#63; and archived = &#63; from the database.
8192             *
8193             * @param userId the user ID
8194             * @param deliveryType the delivery type
8195             * @param actionRequired the action required
8196             * @param archived the archived
8197             */
8198            @Override
8199            public void removeByU_DT_A_A(long userId, int deliveryType,
8200                    boolean actionRequired, boolean archived) {
8201                    for (UserNotificationEvent userNotificationEvent : findByU_DT_A_A(
8202                                    userId, deliveryType, actionRequired, archived,
8203                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8204                            remove(userNotificationEvent);
8205                    }
8206            }
8207    
8208            /**
8209             * Returns the number of user notification events where userId = &#63; and deliveryType = &#63; and actionRequired = &#63; and archived = &#63;.
8210             *
8211             * @param userId the user ID
8212             * @param deliveryType the delivery type
8213             * @param actionRequired the action required
8214             * @param archived the archived
8215             * @return the number of matching user notification events
8216             */
8217            @Override
8218            public int countByU_DT_A_A(long userId, int deliveryType,
8219                    boolean actionRequired, boolean archived) {
8220                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_DT_A_A;
8221    
8222                    Object[] finderArgs = new Object[] {
8223                                    userId, deliveryType, actionRequired, archived
8224                            };
8225    
8226                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8227    
8228                    if (count == null) {
8229                            StringBundler query = new StringBundler(5);
8230    
8231                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
8232    
8233                            query.append(_FINDER_COLUMN_U_DT_A_A_USERID_2);
8234    
8235                            query.append(_FINDER_COLUMN_U_DT_A_A_DELIVERYTYPE_2);
8236    
8237                            query.append(_FINDER_COLUMN_U_DT_A_A_ACTIONREQUIRED_2);
8238    
8239                            query.append(_FINDER_COLUMN_U_DT_A_A_ARCHIVED_2);
8240    
8241                            String sql = query.toString();
8242    
8243                            Session session = null;
8244    
8245                            try {
8246                                    session = openSession();
8247    
8248                                    Query q = session.createQuery(sql);
8249    
8250                                    QueryPos qPos = QueryPos.getInstance(q);
8251    
8252                                    qPos.add(userId);
8253    
8254                                    qPos.add(deliveryType);
8255    
8256                                    qPos.add(actionRequired);
8257    
8258                                    qPos.add(archived);
8259    
8260                                    count = (Long)q.uniqueResult();
8261    
8262                                    finderCache.putResult(finderPath, finderArgs, count);
8263                            }
8264                            catch (Exception e) {
8265                                    finderCache.removeResult(finderPath, finderArgs);
8266    
8267                                    throw processException(e);
8268                            }
8269                            finally {
8270                                    closeSession(session);
8271                            }
8272                    }
8273    
8274                    return count.intValue();
8275            }
8276    
8277            private static final String _FINDER_COLUMN_U_DT_A_A_USERID_2 = "userNotificationEvent.userId = ? AND ";
8278            private static final String _FINDER_COLUMN_U_DT_A_A_DELIVERYTYPE_2 = "userNotificationEvent.deliveryType = ? AND ";
8279            private static final String _FINDER_COLUMN_U_DT_A_A_ACTIONREQUIRED_2 = "userNotificationEvent.actionRequired = ? AND ";
8280            private static final String _FINDER_COLUMN_U_DT_A_A_ARCHIVED_2 = "userNotificationEvent.archived = ?";
8281    
8282            public UserNotificationEventPersistenceImpl() {
8283                    setModelClass(UserNotificationEvent.class);
8284            }
8285    
8286            /**
8287             * Caches the user notification event in the entity cache if it is enabled.
8288             *
8289             * @param userNotificationEvent the user notification event
8290             */
8291            @Override
8292            public void cacheResult(UserNotificationEvent userNotificationEvent) {
8293                    entityCache.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
8294                            UserNotificationEventImpl.class,
8295                            userNotificationEvent.getPrimaryKey(), userNotificationEvent);
8296    
8297                    userNotificationEvent.resetOriginalValues();
8298            }
8299    
8300            /**
8301             * Caches the user notification events in the entity cache if it is enabled.
8302             *
8303             * @param userNotificationEvents the user notification events
8304             */
8305            @Override
8306            public void cacheResult(List<UserNotificationEvent> userNotificationEvents) {
8307                    for (UserNotificationEvent userNotificationEvent : userNotificationEvents) {
8308                            if (entityCache.getResult(
8309                                                    UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
8310                                                    UserNotificationEventImpl.class,
8311                                                    userNotificationEvent.getPrimaryKey()) == null) {
8312                                    cacheResult(userNotificationEvent);
8313                            }
8314                            else {
8315                                    userNotificationEvent.resetOriginalValues();
8316                            }
8317                    }
8318            }
8319    
8320            /**
8321             * Clears the cache for all user notification events.
8322             *
8323             * <p>
8324             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
8325             * </p>
8326             */
8327            @Override
8328            public void clearCache() {
8329                    entityCache.clearCache(UserNotificationEventImpl.class);
8330    
8331                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
8332                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8333                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8334            }
8335    
8336            /**
8337             * Clears the cache for the user notification event.
8338             *
8339             * <p>
8340             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
8341             * </p>
8342             */
8343            @Override
8344            public void clearCache(UserNotificationEvent userNotificationEvent) {
8345                    entityCache.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
8346                            UserNotificationEventImpl.class,
8347                            userNotificationEvent.getPrimaryKey());
8348    
8349                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8350                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8351            }
8352    
8353            @Override
8354            public void clearCache(List<UserNotificationEvent> userNotificationEvents) {
8355                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8356                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8357    
8358                    for (UserNotificationEvent userNotificationEvent : userNotificationEvents) {
8359                            entityCache.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
8360                                    UserNotificationEventImpl.class,
8361                                    userNotificationEvent.getPrimaryKey());
8362                    }
8363            }
8364    
8365            /**
8366             * Creates a new user notification event with the primary key. Does not add the user notification event to the database.
8367             *
8368             * @param userNotificationEventId the primary key for the new user notification event
8369             * @return the new user notification event
8370             */
8371            @Override
8372            public UserNotificationEvent create(long userNotificationEventId) {
8373                    UserNotificationEvent userNotificationEvent = new UserNotificationEventImpl();
8374    
8375                    userNotificationEvent.setNew(true);
8376                    userNotificationEvent.setPrimaryKey(userNotificationEventId);
8377    
8378                    String uuid = PortalUUIDUtil.generate();
8379    
8380                    userNotificationEvent.setUuid(uuid);
8381    
8382                    return userNotificationEvent;
8383            }
8384    
8385            /**
8386             * Removes the user notification event with the primary key from the database. Also notifies the appropriate model listeners.
8387             *
8388             * @param userNotificationEventId the primary key of the user notification event
8389             * @return the user notification event that was removed
8390             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
8391             */
8392            @Override
8393            public UserNotificationEvent remove(long userNotificationEventId)
8394                    throws NoSuchUserNotificationEventException {
8395                    return remove((Serializable)userNotificationEventId);
8396            }
8397    
8398            /**
8399             * Removes the user notification event with the primary key from the database. Also notifies the appropriate model listeners.
8400             *
8401             * @param primaryKey the primary key of the user notification event
8402             * @return the user notification event that was removed
8403             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
8404             */
8405            @Override
8406            public UserNotificationEvent remove(Serializable primaryKey)
8407                    throws NoSuchUserNotificationEventException {
8408                    Session session = null;
8409    
8410                    try {
8411                            session = openSession();
8412    
8413                            UserNotificationEvent userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
8414                                            primaryKey);
8415    
8416                            if (userNotificationEvent == null) {
8417                                    if (_log.isWarnEnabled()) {
8418                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8419                                    }
8420    
8421                                    throw new NoSuchUserNotificationEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8422                                            primaryKey);
8423                            }
8424    
8425                            return remove(userNotificationEvent);
8426                    }
8427                    catch (NoSuchUserNotificationEventException nsee) {
8428                            throw nsee;
8429                    }
8430                    catch (Exception e) {
8431                            throw processException(e);
8432                    }
8433                    finally {
8434                            closeSession(session);
8435                    }
8436            }
8437    
8438            @Override
8439            protected UserNotificationEvent removeImpl(
8440                    UserNotificationEvent userNotificationEvent) {
8441                    userNotificationEvent = toUnwrappedModel(userNotificationEvent);
8442    
8443                    Session session = null;
8444    
8445                    try {
8446                            session = openSession();
8447    
8448                            if (!session.contains(userNotificationEvent)) {
8449                                    userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
8450                                                    userNotificationEvent.getPrimaryKeyObj());
8451                            }
8452    
8453                            if (userNotificationEvent != null) {
8454                                    session.delete(userNotificationEvent);
8455                            }
8456                    }
8457                    catch (Exception e) {
8458                            throw processException(e);
8459                    }
8460                    finally {
8461                            closeSession(session);
8462                    }
8463    
8464                    if (userNotificationEvent != null) {
8465                            clearCache(userNotificationEvent);
8466                    }
8467    
8468                    return userNotificationEvent;
8469            }
8470    
8471            @Override
8472            public UserNotificationEvent updateImpl(
8473                    UserNotificationEvent userNotificationEvent) {
8474                    userNotificationEvent = toUnwrappedModel(userNotificationEvent);
8475    
8476                    boolean isNew = userNotificationEvent.isNew();
8477    
8478                    UserNotificationEventModelImpl userNotificationEventModelImpl = (UserNotificationEventModelImpl)userNotificationEvent;
8479    
8480                    if (Validator.isNull(userNotificationEvent.getUuid())) {
8481                            String uuid = PortalUUIDUtil.generate();
8482    
8483                            userNotificationEvent.setUuid(uuid);
8484                    }
8485    
8486                    Session session = null;
8487    
8488                    try {
8489                            session = openSession();
8490    
8491                            if (userNotificationEvent.isNew()) {
8492                                    session.save(userNotificationEvent);
8493    
8494                                    userNotificationEvent.setNew(false);
8495                            }
8496                            else {
8497                                    userNotificationEvent = (UserNotificationEvent)session.merge(userNotificationEvent);
8498                            }
8499                    }
8500                    catch (Exception e) {
8501                            throw processException(e);
8502                    }
8503                    finally {
8504                            closeSession(session);
8505                    }
8506    
8507                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8508    
8509                    if (isNew || !UserNotificationEventModelImpl.COLUMN_BITMASK_ENABLED) {
8510                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8511                    }
8512    
8513                    else {
8514                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8515                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
8516                                    Object[] args = new Object[] {
8517                                                    userNotificationEventModelImpl.getOriginalUuid()
8518                                            };
8519    
8520                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8521                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8522                                            args);
8523    
8524                                    args = new Object[] { userNotificationEventModelImpl.getUuid() };
8525    
8526                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8527                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8528                                            args);
8529                            }
8530    
8531                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8532                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
8533                                    Object[] args = new Object[] {
8534                                                    userNotificationEventModelImpl.getOriginalUuid(),
8535                                                    userNotificationEventModelImpl.getOriginalCompanyId()
8536                                            };
8537    
8538                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8539                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8540                                            args);
8541    
8542                                    args = new Object[] {
8543                                                    userNotificationEventModelImpl.getUuid(),
8544                                                    userNotificationEventModelImpl.getCompanyId()
8545                                            };
8546    
8547                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8548                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8549                                            args);
8550                            }
8551    
8552                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8553                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
8554                                    Object[] args = new Object[] {
8555                                                    userNotificationEventModelImpl.getOriginalUserId()
8556                                            };
8557    
8558                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
8559                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
8560                                            args);
8561    
8562                                    args = new Object[] { userNotificationEventModelImpl.getUserId() };
8563    
8564                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
8565                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
8566                                            args);
8567                            }
8568    
8569                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8570                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
8571                                    Object[] args = new Object[] {
8572                                                    userNotificationEventModelImpl.getOriginalType()
8573                                            };
8574    
8575                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
8576                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
8577                                            args);
8578    
8579                                    args = new Object[] { userNotificationEventModelImpl.getType() };
8580    
8581                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
8582                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
8583                                            args);
8584                            }
8585    
8586                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8587                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT.getColumnBitmask()) != 0) {
8588                                    Object[] args = new Object[] {
8589                                                    userNotificationEventModelImpl.getOriginalUserId(),
8590                                                    userNotificationEventModelImpl.getOriginalDeliveryType()
8591                                            };
8592    
8593                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_DT, args);
8594                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT,
8595                                            args);
8596    
8597                                    args = new Object[] {
8598                                                    userNotificationEventModelImpl.getUserId(),
8599                                                    userNotificationEventModelImpl.getDeliveryType()
8600                                            };
8601    
8602                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_DT, args);
8603                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT,
8604                                            args);
8605                            }
8606    
8607                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8608                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_D.getColumnBitmask()) != 0) {
8609                                    Object[] args = new Object[] {
8610                                                    userNotificationEventModelImpl.getOriginalUserId(),
8611                                                    userNotificationEventModelImpl.getOriginalDelivered()
8612                                            };
8613    
8614                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_D, args);
8615                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_D,
8616                                            args);
8617    
8618                                    args = new Object[] {
8619                                                    userNotificationEventModelImpl.getUserId(),
8620                                                    userNotificationEventModelImpl.getDelivered()
8621                                            };
8622    
8623                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_D, args);
8624                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_D,
8625                                            args);
8626                            }
8627    
8628                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8629                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A.getColumnBitmask()) != 0) {
8630                                    Object[] args = new Object[] {
8631                                                    userNotificationEventModelImpl.getOriginalUserId(),
8632                                                    userNotificationEventModelImpl.getOriginalArchived()
8633                                            };
8634    
8635                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_A, args);
8636                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A,
8637                                            args);
8638    
8639                                    args = new Object[] {
8640                                                    userNotificationEventModelImpl.getUserId(),
8641                                                    userNotificationEventModelImpl.getArchived()
8642                                            };
8643    
8644                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_A, args);
8645                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A,
8646                                            args);
8647                            }
8648    
8649                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8650                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_D.getColumnBitmask()) != 0) {
8651                                    Object[] args = new Object[] {
8652                                                    userNotificationEventModelImpl.getOriginalUserId(),
8653                                                    userNotificationEventModelImpl.getOriginalDeliveryType(),
8654                                                    userNotificationEventModelImpl.getOriginalDelivered()
8655                                            };
8656    
8657                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_DT_D, args);
8658                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_D,
8659                                            args);
8660    
8661                                    args = new Object[] {
8662                                                    userNotificationEventModelImpl.getUserId(),
8663                                                    userNotificationEventModelImpl.getDeliveryType(),
8664                                                    userNotificationEventModelImpl.getDelivered()
8665                                            };
8666    
8667                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_DT_D, args);
8668                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_D,
8669                                            args);
8670                            }
8671    
8672                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8673                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_A.getColumnBitmask()) != 0) {
8674                                    Object[] args = new Object[] {
8675                                                    userNotificationEventModelImpl.getOriginalUserId(),
8676                                                    userNotificationEventModelImpl.getOriginalDeliveryType(),
8677                                                    userNotificationEventModelImpl.getOriginalArchived()
8678                                            };
8679    
8680                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_DT_A, args);
8681                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_A,
8682                                            args);
8683    
8684                                    args = new Object[] {
8685                                                    userNotificationEventModelImpl.getUserId(),
8686                                                    userNotificationEventModelImpl.getDeliveryType(),
8687                                                    userNotificationEventModelImpl.getArchived()
8688                                            };
8689    
8690                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_DT_A, args);
8691                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_A,
8692                                            args);
8693                            }
8694    
8695                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8696                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_D_A.getColumnBitmask()) != 0) {
8697                                    Object[] args = new Object[] {
8698                                                    userNotificationEventModelImpl.getOriginalUserId(),
8699                                                    userNotificationEventModelImpl.getOriginalDelivered(),
8700                                                    userNotificationEventModelImpl.getOriginalActionRequired()
8701                                            };
8702    
8703                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_D_A, args);
8704                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_D_A,
8705                                            args);
8706    
8707                                    args = new Object[] {
8708                                                    userNotificationEventModelImpl.getUserId(),
8709                                                    userNotificationEventModelImpl.getDelivered(),
8710                                                    userNotificationEventModelImpl.getActionRequired()
8711                                            };
8712    
8713                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_D_A, args);
8714                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_D_A,
8715                                            args);
8716                            }
8717    
8718                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8719                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A_A.getColumnBitmask()) != 0) {
8720                                    Object[] args = new Object[] {
8721                                                    userNotificationEventModelImpl.getOriginalUserId(),
8722                                                    userNotificationEventModelImpl.getOriginalActionRequired(),
8723                                                    userNotificationEventModelImpl.getOriginalArchived()
8724                                            };
8725    
8726                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_A_A, args);
8727                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A_A,
8728                                            args);
8729    
8730                                    args = new Object[] {
8731                                                    userNotificationEventModelImpl.getUserId(),
8732                                                    userNotificationEventModelImpl.getActionRequired(),
8733                                                    userNotificationEventModelImpl.getArchived()
8734                                            };
8735    
8736                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_A_A, args);
8737                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A_A,
8738                                            args);
8739                            }
8740    
8741                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8742                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_T_DT_D.getColumnBitmask()) != 0) {
8743                                    Object[] args = new Object[] {
8744                                                    userNotificationEventModelImpl.getOriginalUserId(),
8745                                                    userNotificationEventModelImpl.getOriginalType(),
8746                                                    userNotificationEventModelImpl.getOriginalDeliveryType(),
8747                                                    userNotificationEventModelImpl.getOriginalDelivered()
8748                                            };
8749    
8750                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_T_DT_D, args);
8751                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_T_DT_D,
8752                                            args);
8753    
8754                                    args = new Object[] {
8755                                                    userNotificationEventModelImpl.getUserId(),
8756                                                    userNotificationEventModelImpl.getType(),
8757                                                    userNotificationEventModelImpl.getDeliveryType(),
8758                                                    userNotificationEventModelImpl.getDelivered()
8759                                            };
8760    
8761                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_T_DT_D, args);
8762                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_T_DT_D,
8763                                            args);
8764                            }
8765    
8766                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8767                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_D_A.getColumnBitmask()) != 0) {
8768                                    Object[] args = new Object[] {
8769                                                    userNotificationEventModelImpl.getOriginalUserId(),
8770                                                    userNotificationEventModelImpl.getOriginalDeliveryType(),
8771                                                    userNotificationEventModelImpl.getOriginalDelivered(),
8772                                                    userNotificationEventModelImpl.getOriginalActionRequired()
8773                                            };
8774    
8775                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_DT_D_A, args);
8776                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_D_A,
8777                                            args);
8778    
8779                                    args = new Object[] {
8780                                                    userNotificationEventModelImpl.getUserId(),
8781                                                    userNotificationEventModelImpl.getDeliveryType(),
8782                                                    userNotificationEventModelImpl.getDelivered(),
8783                                                    userNotificationEventModelImpl.getActionRequired()
8784                                            };
8785    
8786                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_DT_D_A, args);
8787                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_D_A,
8788                                            args);
8789                            }
8790    
8791                            if ((userNotificationEventModelImpl.getColumnBitmask() &
8792                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_A_A.getColumnBitmask()) != 0) {
8793                                    Object[] args = new Object[] {
8794                                                    userNotificationEventModelImpl.getOriginalUserId(),
8795                                                    userNotificationEventModelImpl.getOriginalDeliveryType(),
8796                                                    userNotificationEventModelImpl.getOriginalActionRequired(),
8797                                                    userNotificationEventModelImpl.getOriginalArchived()
8798                                            };
8799    
8800                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_DT_A_A, args);
8801                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_A_A,
8802                                            args);
8803    
8804                                    args = new Object[] {
8805                                                    userNotificationEventModelImpl.getUserId(),
8806                                                    userNotificationEventModelImpl.getDeliveryType(),
8807                                                    userNotificationEventModelImpl.getActionRequired(),
8808                                                    userNotificationEventModelImpl.getArchived()
8809                                            };
8810    
8811                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_DT_A_A, args);
8812                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_DT_A_A,
8813                                            args);
8814                            }
8815                    }
8816    
8817                    entityCache.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
8818                            UserNotificationEventImpl.class,
8819                            userNotificationEvent.getPrimaryKey(), userNotificationEvent, false);
8820    
8821                    userNotificationEvent.resetOriginalValues();
8822    
8823                    return userNotificationEvent;
8824            }
8825    
8826            protected UserNotificationEvent toUnwrappedModel(
8827                    UserNotificationEvent userNotificationEvent) {
8828                    if (userNotificationEvent instanceof UserNotificationEventImpl) {
8829                            return userNotificationEvent;
8830                    }
8831    
8832                    UserNotificationEventImpl userNotificationEventImpl = new UserNotificationEventImpl();
8833    
8834                    userNotificationEventImpl.setNew(userNotificationEvent.isNew());
8835                    userNotificationEventImpl.setPrimaryKey(userNotificationEvent.getPrimaryKey());
8836    
8837                    userNotificationEventImpl.setMvccVersion(userNotificationEvent.getMvccVersion());
8838                    userNotificationEventImpl.setUuid(userNotificationEvent.getUuid());
8839                    userNotificationEventImpl.setUserNotificationEventId(userNotificationEvent.getUserNotificationEventId());
8840                    userNotificationEventImpl.setCompanyId(userNotificationEvent.getCompanyId());
8841                    userNotificationEventImpl.setUserId(userNotificationEvent.getUserId());
8842                    userNotificationEventImpl.setType(userNotificationEvent.getType());
8843                    userNotificationEventImpl.setTimestamp(userNotificationEvent.getTimestamp());
8844                    userNotificationEventImpl.setDeliveryType(userNotificationEvent.getDeliveryType());
8845                    userNotificationEventImpl.setDeliverBy(userNotificationEvent.getDeliverBy());
8846                    userNotificationEventImpl.setDelivered(userNotificationEvent.isDelivered());
8847                    userNotificationEventImpl.setPayload(userNotificationEvent.getPayload());
8848                    userNotificationEventImpl.setActionRequired(userNotificationEvent.isActionRequired());
8849                    userNotificationEventImpl.setArchived(userNotificationEvent.isArchived());
8850    
8851                    return userNotificationEventImpl;
8852            }
8853    
8854            /**
8855             * Returns the user notification event with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
8856             *
8857             * @param primaryKey the primary key of the user notification event
8858             * @return the user notification event
8859             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
8860             */
8861            @Override
8862            public UserNotificationEvent findByPrimaryKey(Serializable primaryKey)
8863                    throws NoSuchUserNotificationEventException {
8864                    UserNotificationEvent userNotificationEvent = fetchByPrimaryKey(primaryKey);
8865    
8866                    if (userNotificationEvent == null) {
8867                            if (_log.isWarnEnabled()) {
8868                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8869                            }
8870    
8871                            throw new NoSuchUserNotificationEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8872                                    primaryKey);
8873                    }
8874    
8875                    return userNotificationEvent;
8876            }
8877    
8878            /**
8879             * Returns the user notification event with the primary key or throws a {@link NoSuchUserNotificationEventException} if it could not be found.
8880             *
8881             * @param userNotificationEventId the primary key of the user notification event
8882             * @return the user notification event
8883             * @throws NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
8884             */
8885            @Override
8886            public UserNotificationEvent findByPrimaryKey(long userNotificationEventId)
8887                    throws NoSuchUserNotificationEventException {
8888                    return findByPrimaryKey((Serializable)userNotificationEventId);
8889            }
8890    
8891            /**
8892             * Returns the user notification event with the primary key or returns <code>null</code> if it could not be found.
8893             *
8894             * @param primaryKey the primary key of the user notification event
8895             * @return the user notification event, or <code>null</code> if a user notification event with the primary key could not be found
8896             */
8897            @Override
8898            public UserNotificationEvent fetchByPrimaryKey(Serializable primaryKey) {
8899                    UserNotificationEvent userNotificationEvent = (UserNotificationEvent)entityCache.getResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
8900                                    UserNotificationEventImpl.class, primaryKey);
8901    
8902                    if (userNotificationEvent == _nullUserNotificationEvent) {
8903                            return null;
8904                    }
8905    
8906                    if (userNotificationEvent == null) {
8907                            Session session = null;
8908    
8909                            try {
8910                                    session = openSession();
8911    
8912                                    userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
8913                                                    primaryKey);
8914    
8915                                    if (userNotificationEvent != null) {
8916                                            cacheResult(userNotificationEvent);
8917                                    }
8918                                    else {
8919                                            entityCache.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
8920                                                    UserNotificationEventImpl.class, primaryKey,
8921                                                    _nullUserNotificationEvent);
8922                                    }
8923                            }
8924                            catch (Exception e) {
8925                                    entityCache.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
8926                                            UserNotificationEventImpl.class, primaryKey);
8927    
8928                                    throw processException(e);
8929                            }
8930                            finally {
8931                                    closeSession(session);
8932                            }
8933                    }
8934    
8935                    return userNotificationEvent;
8936            }
8937    
8938            /**
8939             * Returns the user notification event with the primary key or returns <code>null</code> if it could not be found.
8940             *
8941             * @param userNotificationEventId the primary key of the user notification event
8942             * @return the user notification event, or <code>null</code> if a user notification event with the primary key could not be found
8943             */
8944            @Override
8945            public UserNotificationEvent fetchByPrimaryKey(long userNotificationEventId) {
8946                    return fetchByPrimaryKey((Serializable)userNotificationEventId);
8947            }
8948    
8949            @Override
8950            public Map<Serializable, UserNotificationEvent> fetchByPrimaryKeys(
8951                    Set<Serializable> primaryKeys) {
8952                    if (primaryKeys.isEmpty()) {
8953                            return Collections.emptyMap();
8954                    }
8955    
8956                    Map<Serializable, UserNotificationEvent> map = new HashMap<Serializable, UserNotificationEvent>();
8957    
8958                    if (primaryKeys.size() == 1) {
8959                            Iterator<Serializable> iterator = primaryKeys.iterator();
8960    
8961                            Serializable primaryKey = iterator.next();
8962    
8963                            UserNotificationEvent userNotificationEvent = fetchByPrimaryKey(primaryKey);
8964    
8965                            if (userNotificationEvent != null) {
8966                                    map.put(primaryKey, userNotificationEvent);
8967                            }
8968    
8969                            return map;
8970                    }
8971    
8972                    Set<Serializable> uncachedPrimaryKeys = null;
8973    
8974                    for (Serializable primaryKey : primaryKeys) {
8975                            UserNotificationEvent userNotificationEvent = (UserNotificationEvent)entityCache.getResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
8976                                            UserNotificationEventImpl.class, primaryKey);
8977    
8978                            if (userNotificationEvent == null) {
8979                                    if (uncachedPrimaryKeys == null) {
8980                                            uncachedPrimaryKeys = new HashSet<Serializable>();
8981                                    }
8982    
8983                                    uncachedPrimaryKeys.add(primaryKey);
8984                            }
8985                            else {
8986                                    map.put(primaryKey, userNotificationEvent);
8987                            }
8988                    }
8989    
8990                    if (uncachedPrimaryKeys == null) {
8991                            return map;
8992                    }
8993    
8994                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
8995                                    1);
8996    
8997                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE_PKS_IN);
8998    
8999                    for (Serializable primaryKey : uncachedPrimaryKeys) {
9000                            query.append(String.valueOf(primaryKey));
9001    
9002                            query.append(StringPool.COMMA);
9003                    }
9004    
9005                    query.setIndex(query.index() - 1);
9006    
9007                    query.append(StringPool.CLOSE_PARENTHESIS);
9008    
9009                    String sql = query.toString();
9010    
9011                    Session session = null;
9012    
9013                    try {
9014                            session = openSession();
9015    
9016                            Query q = session.createQuery(sql);
9017    
9018                            for (UserNotificationEvent userNotificationEvent : (List<UserNotificationEvent>)q.list()) {
9019                                    map.put(userNotificationEvent.getPrimaryKeyObj(),
9020                                            userNotificationEvent);
9021    
9022                                    cacheResult(userNotificationEvent);
9023    
9024                                    uncachedPrimaryKeys.remove(userNotificationEvent.getPrimaryKeyObj());
9025                            }
9026    
9027                            for (Serializable primaryKey : uncachedPrimaryKeys) {
9028                                    entityCache.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
9029                                            UserNotificationEventImpl.class, primaryKey,
9030                                            _nullUserNotificationEvent);
9031                            }
9032                    }
9033                    catch (Exception e) {
9034                            throw processException(e);
9035                    }
9036                    finally {
9037                            closeSession(session);
9038                    }
9039    
9040                    return map;
9041            }
9042    
9043            /**
9044             * Returns all the user notification events.
9045             *
9046             * @return the user notification events
9047             */
9048            @Override
9049            public List<UserNotificationEvent> findAll() {
9050                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9051            }
9052    
9053            /**
9054             * Returns a range of all the user notification events.
9055             *
9056             * <p>
9057             * 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 UserNotificationEventModelImpl}. 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.
9058             * </p>
9059             *
9060             * @param start the lower bound of the range of user notification events
9061             * @param end the upper bound of the range of user notification events (not inclusive)
9062             * @return the range of user notification events
9063             */
9064            @Override
9065            public List<UserNotificationEvent> findAll(int start, int end) {
9066                    return findAll(start, end, null);
9067            }
9068    
9069            /**
9070             * Returns an ordered range of all the user notification events.
9071             *
9072             * <p>
9073             * 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 UserNotificationEventModelImpl}. 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.
9074             * </p>
9075             *
9076             * @param start the lower bound of the range of user notification events
9077             * @param end the upper bound of the range of user notification events (not inclusive)
9078             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9079             * @return the ordered range of user notification events
9080             */
9081            @Override
9082            public List<UserNotificationEvent> findAll(int start, int end,
9083                    OrderByComparator<UserNotificationEvent> orderByComparator) {
9084                    return findAll(start, end, orderByComparator, true);
9085            }
9086    
9087            /**
9088             * Returns an ordered range of all the user notification events.
9089             *
9090             * <p>
9091             * 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 UserNotificationEventModelImpl}. 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.
9092             * </p>
9093             *
9094             * @param start the lower bound of the range of user notification events
9095             * @param end the upper bound of the range of user notification events (not inclusive)
9096             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9097             * @param retrieveFromCache whether to retrieve from the finder cache
9098             * @return the ordered range of user notification events
9099             */
9100            @Override
9101            public List<UserNotificationEvent> findAll(int start, int end,
9102                    OrderByComparator<UserNotificationEvent> orderByComparator,
9103                    boolean retrieveFromCache) {
9104                    boolean pagination = true;
9105                    FinderPath finderPath = null;
9106                    Object[] finderArgs = null;
9107    
9108                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9109                                    (orderByComparator == null)) {
9110                            pagination = false;
9111                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
9112                            finderArgs = FINDER_ARGS_EMPTY;
9113                    }
9114                    else {
9115                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
9116                            finderArgs = new Object[] { start, end, orderByComparator };
9117                    }
9118    
9119                    List<UserNotificationEvent> list = null;
9120    
9121                    if (retrieveFromCache) {
9122                            list = (List<UserNotificationEvent>)finderCache.getResult(finderPath,
9123                                            finderArgs, this);
9124                    }
9125    
9126                    if (list == null) {
9127                            StringBundler query = null;
9128                            String sql = null;
9129    
9130                            if (orderByComparator != null) {
9131                                    query = new StringBundler(2 +
9132                                                    (orderByComparator.getOrderByFields().length * 3));
9133    
9134                                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT);
9135    
9136                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9137                                            orderByComparator);
9138    
9139                                    sql = query.toString();
9140                            }
9141                            else {
9142                                    sql = _SQL_SELECT_USERNOTIFICATIONEVENT;
9143    
9144                                    if (pagination) {
9145                                            sql = sql.concat(UserNotificationEventModelImpl.ORDER_BY_JPQL);
9146                                    }
9147                            }
9148    
9149                            Session session = null;
9150    
9151                            try {
9152                                    session = openSession();
9153    
9154                                    Query q = session.createQuery(sql);
9155    
9156                                    if (!pagination) {
9157                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
9158                                                            getDialect(), start, end, false);
9159    
9160                                            Collections.sort(list);
9161    
9162                                            list = Collections.unmodifiableList(list);
9163                                    }
9164                                    else {
9165                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
9166                                                            getDialect(), start, end);
9167                                    }
9168    
9169                                    cacheResult(list);
9170    
9171                                    finderCache.putResult(finderPath, finderArgs, list);
9172                            }
9173                            catch (Exception e) {
9174                                    finderCache.removeResult(finderPath, finderArgs);
9175    
9176                                    throw processException(e);
9177                            }
9178                            finally {
9179                                    closeSession(session);
9180                            }
9181                    }
9182    
9183                    return list;
9184            }
9185    
9186            /**
9187             * Removes all the user notification events from the database.
9188             *
9189             */
9190            @Override
9191            public void removeAll() {
9192                    for (UserNotificationEvent userNotificationEvent : findAll()) {
9193                            remove(userNotificationEvent);
9194                    }
9195            }
9196    
9197            /**
9198             * Returns the number of user notification events.
9199             *
9200             * @return the number of user notification events
9201             */
9202            @Override
9203            public int countAll() {
9204                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
9205                                    FINDER_ARGS_EMPTY, this);
9206    
9207                    if (count == null) {
9208                            Session session = null;
9209    
9210                            try {
9211                                    session = openSession();
9212    
9213                                    Query q = session.createQuery(_SQL_COUNT_USERNOTIFICATIONEVENT);
9214    
9215                                    count = (Long)q.uniqueResult();
9216    
9217                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
9218                                            count);
9219                            }
9220                            catch (Exception e) {
9221                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
9222                                            FINDER_ARGS_EMPTY);
9223    
9224                                    throw processException(e);
9225                            }
9226                            finally {
9227                                    closeSession(session);
9228                            }
9229                    }
9230    
9231                    return count.intValue();
9232            }
9233    
9234            @Override
9235            public Set<String> getBadColumnNames() {
9236                    return _badColumnNames;
9237            }
9238    
9239            @Override
9240            protected Map<String, Integer> getTableColumnsMap() {
9241                    return UserNotificationEventModelImpl.TABLE_COLUMNS_MAP;
9242            }
9243    
9244            /**
9245             * Initializes the user notification event persistence.
9246             */
9247            public void afterPropertiesSet() {
9248            }
9249    
9250            public void destroy() {
9251                    entityCache.removeCache(UserNotificationEventImpl.class.getName());
9252                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
9253                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9254                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9255            }
9256    
9257            @BeanReference(type = CompanyProvider.class)
9258            protected CompanyProvider companyProvider;
9259            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
9260            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
9261            private static final String _SQL_SELECT_USERNOTIFICATIONEVENT = "SELECT userNotificationEvent FROM UserNotificationEvent userNotificationEvent";
9262            private static final String _SQL_SELECT_USERNOTIFICATIONEVENT_WHERE_PKS_IN = "SELECT userNotificationEvent FROM UserNotificationEvent userNotificationEvent WHERE userNotificationEventId IN (";
9263            private static final String _SQL_SELECT_USERNOTIFICATIONEVENT_WHERE = "SELECT userNotificationEvent FROM UserNotificationEvent userNotificationEvent WHERE ";
9264            private static final String _SQL_COUNT_USERNOTIFICATIONEVENT = "SELECT COUNT(userNotificationEvent) FROM UserNotificationEvent userNotificationEvent";
9265            private static final String _SQL_COUNT_USERNOTIFICATIONEVENT_WHERE = "SELECT COUNT(userNotificationEvent) FROM UserNotificationEvent userNotificationEvent WHERE ";
9266            private static final String _ORDER_BY_ENTITY_ALIAS = "userNotificationEvent.";
9267            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserNotificationEvent exists with the primary key ";
9268            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserNotificationEvent exists with the key {";
9269            private static final Log _log = LogFactoryUtil.getLog(UserNotificationEventPersistenceImpl.class);
9270            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
9271                                    "uuid", "type"
9272                            });
9273            private static final UserNotificationEvent _nullUserNotificationEvent = new UserNotificationEventImpl() {
9274                            @Override
9275                            public Object clone() {
9276                                    return this;
9277                            }
9278    
9279                            @Override
9280                            public CacheModel<UserNotificationEvent> toCacheModel() {
9281                                    return _nullUserNotificationEventCacheModel;
9282                            }
9283                    };
9284    
9285            private static final CacheModel<UserNotificationEvent> _nullUserNotificationEventCacheModel =
9286                    new NullCacheModel();
9287    
9288            private static class NullCacheModel implements CacheModel<UserNotificationEvent>,
9289                    MVCCModel {
9290                    @Override
9291                    public long getMvccVersion() {
9292                            return -1;
9293                    }
9294    
9295                    @Override
9296                    public void setMvccVersion(long mvccVersion) {
9297                    }
9298    
9299                    @Override
9300                    public UserNotificationEvent toEntityModel() {
9301                            return _nullUserNotificationEvent;
9302                    }
9303            }
9304    }