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