001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchUserNotificationEventException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.SetUtil;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.UnmodifiableList;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.model.UserNotificationEvent;
042    import com.liferay.portal.model.impl.UserNotificationEventImpl;
043    import com.liferay.portal.model.impl.UserNotificationEventModelImpl;
044    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045    
046    import java.io.Serializable;
047    
048    import java.util.ArrayList;
049    import java.util.Collections;
050    import java.util.List;
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    public class UserNotificationEventPersistenceImpl extends BasePersistenceImpl<UserNotificationEvent>
066            implements UserNotificationEventPersistence {
067            /*
068             * NOTE FOR DEVELOPERS:
069             *
070             * 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.
071             */
072            public static final String FINDER_CLASS_NAME_ENTITY = UserNotificationEventImpl.class.getName();
073            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List1";
075            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List2";
077            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
078                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
079                            UserNotificationEventImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
082                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
083                            UserNotificationEventImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
086                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
089                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
090                            UserNotificationEventImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
092                            new String[] {
093                                    String.class.getName(),
094                                    
095                            Integer.class.getName(), Integer.class.getName(),
096                                    OrderByComparator.class.getName()
097                            });
098            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
099                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
100                            UserNotificationEventImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
102                            new String[] { String.class.getName() },
103                            UserNotificationEventModelImpl.UUID_COLUMN_BITMASK |
104                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
106                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
108                            new String[] { String.class.getName() });
109    
110            /**
111             * Returns all the user notification events where uuid = &#63;.
112             *
113             * @param uuid the uuid
114             * @return the matching user notification events
115             * @throws SystemException if a system exception occurred
116             */
117            public List<UserNotificationEvent> findByUuid(String uuid)
118                    throws SystemException {
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             * @throws SystemException if a system exception occurred
134             */
135            public List<UserNotificationEvent> findByUuid(String uuid, int start,
136                    int end) throws SystemException {
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             * @throws SystemException if a system exception occurred
153             */
154            public List<UserNotificationEvent> findByUuid(String uuid, int start,
155                    int end, OrderByComparator orderByComparator) throws SystemException {
156                    boolean pagination = true;
157                    FinderPath finderPath = null;
158                    Object[] finderArgs = null;
159    
160                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161                                    (orderByComparator == null)) {
162                            pagination = false;
163                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_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 = new UnmodifiableList<UserNotificationEvent>(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             * @throws SystemException if a system exception occurred
273             */
274            public UserNotificationEvent findByUuid_First(String uuid,
275                    OrderByComparator orderByComparator)
276                    throws NoSuchUserNotificationEventException, SystemException {
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             * @throws SystemException if a system exception occurred
303             */
304            public UserNotificationEvent fetchByUuid_First(String uuid,
305                    OrderByComparator orderByComparator) throws SystemException {
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             * @throws SystemException if a system exception occurred
324             */
325            public UserNotificationEvent findByUuid_Last(String uuid,
326                    OrderByComparator orderByComparator)
327                    throws NoSuchUserNotificationEventException, SystemException {
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             * @throws SystemException if a system exception occurred
354             */
355            public UserNotificationEvent fetchByUuid_Last(String uuid,
356                    OrderByComparator orderByComparator) throws SystemException {
357                    int count = countByUuid(uuid);
358    
359                    List<UserNotificationEvent> list = findByUuid(uuid, count - 1, count,
360                                    orderByComparator);
361    
362                    if (!list.isEmpty()) {
363                            return list.get(0);
364                    }
365    
366                    return null;
367            }
368    
369            /**
370             * Returns the user notification events before and after the current user notification event in the ordered set where uuid = &#63;.
371             *
372             * @param userNotificationEventId the primary key of the current user notification event
373             * @param uuid the uuid
374             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
375             * @return the previous, current, and next user notification event
376             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
377             * @throws SystemException if a system exception occurred
378             */
379            public UserNotificationEvent[] findByUuid_PrevAndNext(
380                    long userNotificationEventId, String uuid,
381                    OrderByComparator orderByComparator)
382                    throws NoSuchUserNotificationEventException, SystemException {
383                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
384    
385                    Session session = null;
386    
387                    try {
388                            session = openSession();
389    
390                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
391    
392                            array[0] = getByUuid_PrevAndNext(session, userNotificationEvent,
393                                            uuid, orderByComparator, true);
394    
395                            array[1] = userNotificationEvent;
396    
397                            array[2] = getByUuid_PrevAndNext(session, userNotificationEvent,
398                                            uuid, orderByComparator, false);
399    
400                            return array;
401                    }
402                    catch (Exception e) {
403                            throw processException(e);
404                    }
405                    finally {
406                            closeSession(session);
407                    }
408            }
409    
410            protected UserNotificationEvent getByUuid_PrevAndNext(Session session,
411                    UserNotificationEvent userNotificationEvent, String uuid,
412                    OrderByComparator orderByComparator, boolean previous) {
413                    StringBundler query = null;
414    
415                    if (orderByComparator != null) {
416                            query = new StringBundler(6 +
417                                            (orderByComparator.getOrderByFields().length * 6));
418                    }
419                    else {
420                            query = new StringBundler(3);
421                    }
422    
423                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
424    
425                    boolean bindUuid = false;
426    
427                    if (uuid == null) {
428                            query.append(_FINDER_COLUMN_UUID_UUID_1);
429                    }
430                    else if (uuid.equals(StringPool.BLANK)) {
431                            query.append(_FINDER_COLUMN_UUID_UUID_3);
432                    }
433                    else {
434                            bindUuid = true;
435    
436                            query.append(_FINDER_COLUMN_UUID_UUID_2);
437                    }
438    
439                    if (orderByComparator != null) {
440                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
441    
442                            if (orderByConditionFields.length > 0) {
443                                    query.append(WHERE_AND);
444                            }
445    
446                            for (int i = 0; i < orderByConditionFields.length; i++) {
447                                    query.append(_ORDER_BY_ENTITY_ALIAS);
448                                    query.append(orderByConditionFields[i]);
449    
450                                    if ((i + 1) < orderByConditionFields.length) {
451                                            if (orderByComparator.isAscending() ^ previous) {
452                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
453                                            }
454                                            else {
455                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
456                                            }
457                                    }
458                                    else {
459                                            if (orderByComparator.isAscending() ^ previous) {
460                                                    query.append(WHERE_GREATER_THAN);
461                                            }
462                                            else {
463                                                    query.append(WHERE_LESSER_THAN);
464                                            }
465                                    }
466                            }
467    
468                            query.append(ORDER_BY_CLAUSE);
469    
470                            String[] orderByFields = orderByComparator.getOrderByFields();
471    
472                            for (int i = 0; i < orderByFields.length; i++) {
473                                    query.append(_ORDER_BY_ENTITY_ALIAS);
474                                    query.append(orderByFields[i]);
475    
476                                    if ((i + 1) < orderByFields.length) {
477                                            if (orderByComparator.isAscending() ^ previous) {
478                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
479                                            }
480                                            else {
481                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
482                                            }
483                                    }
484                                    else {
485                                            if (orderByComparator.isAscending() ^ previous) {
486                                                    query.append(ORDER_BY_ASC);
487                                            }
488                                            else {
489                                                    query.append(ORDER_BY_DESC);
490                                            }
491                                    }
492                            }
493                    }
494                    else {
495                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
496                    }
497    
498                    String sql = query.toString();
499    
500                    Query q = session.createQuery(sql);
501    
502                    q.setFirstResult(0);
503                    q.setMaxResults(2);
504    
505                    QueryPos qPos = QueryPos.getInstance(q);
506    
507                    if (bindUuid) {
508                            qPos.add(uuid);
509                    }
510    
511                    if (orderByComparator != null) {
512                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
513    
514                            for (Object value : values) {
515                                    qPos.add(value);
516                            }
517                    }
518    
519                    List<UserNotificationEvent> list = q.list();
520    
521                    if (list.size() == 2) {
522                            return list.get(1);
523                    }
524                    else {
525                            return null;
526                    }
527            }
528    
529            /**
530             * Removes all the user notification events where uuid = &#63; from the database.
531             *
532             * @param uuid the uuid
533             * @throws SystemException if a system exception occurred
534             */
535            public void removeByUuid(String uuid) throws SystemException {
536                    for (UserNotificationEvent userNotificationEvent : findByUuid(uuid,
537                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
538                            remove(userNotificationEvent);
539                    }
540            }
541    
542            /**
543             * Returns the number of user notification events where uuid = &#63;.
544             *
545             * @param uuid the uuid
546             * @return the number of matching user notification events
547             * @throws SystemException if a system exception occurred
548             */
549            public int countByUuid(String uuid) throws SystemException {
550                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
551    
552                    Object[] finderArgs = new Object[] { uuid };
553    
554                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
555                                    this);
556    
557                    if (count == null) {
558                            StringBundler query = new StringBundler(2);
559    
560                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
561    
562                            boolean bindUuid = false;
563    
564                            if (uuid == null) {
565                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
566                            }
567                            else if (uuid.equals(StringPool.BLANK)) {
568                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
569                            }
570                            else {
571                                    bindUuid = true;
572    
573                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
574                            }
575    
576                            String sql = query.toString();
577    
578                            Session session = null;
579    
580                            try {
581                                    session = openSession();
582    
583                                    Query q = session.createQuery(sql);
584    
585                                    QueryPos qPos = QueryPos.getInstance(q);
586    
587                                    if (bindUuid) {
588                                            qPos.add(uuid);
589                                    }
590    
591                                    count = (Long)q.uniqueResult();
592    
593                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
594                            }
595                            catch (Exception e) {
596                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
597    
598                                    throw processException(e);
599                            }
600                            finally {
601                                    closeSession(session);
602                            }
603                    }
604    
605                    return count.intValue();
606            }
607    
608            private static final String _FINDER_COLUMN_UUID_UUID_1 = "userNotificationEvent.uuid IS NULL";
609            private static final String _FINDER_COLUMN_UUID_UUID_2 = "userNotificationEvent.uuid = ?";
610            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(userNotificationEvent.uuid IS NULL OR userNotificationEvent.uuid = '')";
611            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
612                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
613                            UserNotificationEventImpl.class,
614                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
615                            new String[] {
616                                    String.class.getName(), Long.class.getName(),
617                                    
618                            Integer.class.getName(), Integer.class.getName(),
619                                    OrderByComparator.class.getName()
620                            });
621            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
622                    new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
623                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
624                            UserNotificationEventImpl.class,
625                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
626                            new String[] { String.class.getName(), Long.class.getName() },
627                            UserNotificationEventModelImpl.UUID_COLUMN_BITMASK |
628                            UserNotificationEventModelImpl.COMPANYID_COLUMN_BITMASK |
629                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
630            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
631                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
632                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
633                            new String[] { String.class.getName(), Long.class.getName() });
634    
635            /**
636             * Returns all the user notification events where uuid = &#63; and companyId = &#63;.
637             *
638             * @param uuid the uuid
639             * @param companyId the company ID
640             * @return the matching user notification events
641             * @throws SystemException if a system exception occurred
642             */
643            public List<UserNotificationEvent> findByUuid_C(String uuid, long companyId)
644                    throws SystemException {
645                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
646                            QueryUtil.ALL_POS, null);
647            }
648    
649            /**
650             * Returns a range of all the user notification events where uuid = &#63; and companyId = &#63;.
651             *
652             * <p>
653             * 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.
654             * </p>
655             *
656             * @param uuid the uuid
657             * @param companyId the company ID
658             * @param start the lower bound of the range of user notification events
659             * @param end the upper bound of the range of user notification events (not inclusive)
660             * @return the range of matching user notification events
661             * @throws SystemException if a system exception occurred
662             */
663            public List<UserNotificationEvent> findByUuid_C(String uuid,
664                    long companyId, int start, int end) throws SystemException {
665                    return findByUuid_C(uuid, companyId, start, end, null);
666            }
667    
668            /**
669             * Returns an ordered range of all the user notification events where uuid = &#63; and companyId = &#63;.
670             *
671             * <p>
672             * 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.
673             * </p>
674             *
675             * @param uuid the uuid
676             * @param companyId the company ID
677             * @param start the lower bound of the range of user notification events
678             * @param end the upper bound of the range of user notification events (not inclusive)
679             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
680             * @return the ordered range of matching user notification events
681             * @throws SystemException if a system exception occurred
682             */
683            public List<UserNotificationEvent> findByUuid_C(String uuid,
684                    long companyId, int start, int end, OrderByComparator orderByComparator)
685                    throws SystemException {
686                    boolean pagination = true;
687                    FinderPath finderPath = null;
688                    Object[] finderArgs = null;
689    
690                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
691                                    (orderByComparator == null)) {
692                            pagination = false;
693                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
694                            finderArgs = new Object[] { uuid, companyId };
695                    }
696                    else {
697                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
698                            finderArgs = new Object[] {
699                                            uuid, companyId,
700                                            
701                                            start, end, orderByComparator
702                                    };
703                    }
704    
705                    List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
706                                    finderArgs, this);
707    
708                    if ((list != null) && !list.isEmpty()) {
709                            for (UserNotificationEvent userNotificationEvent : list) {
710                                    if (!Validator.equals(uuid, userNotificationEvent.getUuid()) ||
711                                                    (companyId != userNotificationEvent.getCompanyId())) {
712                                            list = null;
713    
714                                            break;
715                                    }
716                            }
717                    }
718    
719                    if (list == null) {
720                            StringBundler query = null;
721    
722                            if (orderByComparator != null) {
723                                    query = new StringBundler(4 +
724                                                    (orderByComparator.getOrderByFields().length * 3));
725                            }
726                            else {
727                                    query = new StringBundler(4);
728                            }
729    
730                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
731    
732                            boolean bindUuid = false;
733    
734                            if (uuid == null) {
735                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
736                            }
737                            else if (uuid.equals(StringPool.BLANK)) {
738                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
739                            }
740                            else {
741                                    bindUuid = true;
742    
743                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
744                            }
745    
746                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
747    
748                            if (orderByComparator != null) {
749                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
750                                            orderByComparator);
751                            }
752                            else
753                             if (pagination) {
754                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
755                            }
756    
757                            String sql = query.toString();
758    
759                            Session session = null;
760    
761                            try {
762                                    session = openSession();
763    
764                                    Query q = session.createQuery(sql);
765    
766                                    QueryPos qPos = QueryPos.getInstance(q);
767    
768                                    if (bindUuid) {
769                                            qPos.add(uuid);
770                                    }
771    
772                                    qPos.add(companyId);
773    
774                                    if (!pagination) {
775                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
776                                                            getDialect(), start, end, false);
777    
778                                            Collections.sort(list);
779    
780                                            list = new UnmodifiableList<UserNotificationEvent>(list);
781                                    }
782                                    else {
783                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
784                                                            getDialect(), start, end);
785                                    }
786    
787                                    cacheResult(list);
788    
789                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
790                            }
791                            catch (Exception e) {
792                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
793    
794                                    throw processException(e);
795                            }
796                            finally {
797                                    closeSession(session);
798                            }
799                    }
800    
801                    return list;
802            }
803    
804            /**
805             * Returns the first user notification event in the ordered set where uuid = &#63; and companyId = &#63;.
806             *
807             * @param uuid the uuid
808             * @param companyId the company ID
809             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
810             * @return the first matching user notification event
811             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a matching user notification event could not be found
812             * @throws SystemException if a system exception occurred
813             */
814            public UserNotificationEvent findByUuid_C_First(String uuid,
815                    long companyId, OrderByComparator orderByComparator)
816                    throws NoSuchUserNotificationEventException, SystemException {
817                    UserNotificationEvent userNotificationEvent = fetchByUuid_C_First(uuid,
818                                    companyId, orderByComparator);
819    
820                    if (userNotificationEvent != null) {
821                            return userNotificationEvent;
822                    }
823    
824                    StringBundler msg = new StringBundler(6);
825    
826                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
827    
828                    msg.append("uuid=");
829                    msg.append(uuid);
830    
831                    msg.append(", companyId=");
832                    msg.append(companyId);
833    
834                    msg.append(StringPool.CLOSE_CURLY_BRACE);
835    
836                    throw new NoSuchUserNotificationEventException(msg.toString());
837            }
838    
839            /**
840             * Returns the first user notification event in the ordered set where uuid = &#63; and companyId = &#63;.
841             *
842             * @param uuid the uuid
843             * @param companyId the company ID
844             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
845             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
846             * @throws SystemException if a system exception occurred
847             */
848            public UserNotificationEvent fetchByUuid_C_First(String uuid,
849                    long companyId, OrderByComparator orderByComparator)
850                    throws SystemException {
851                    List<UserNotificationEvent> list = findByUuid_C(uuid, companyId, 0, 1,
852                                    orderByComparator);
853    
854                    if (!list.isEmpty()) {
855                            return list.get(0);
856                    }
857    
858                    return null;
859            }
860    
861            /**
862             * Returns the last user notification event in the ordered set where uuid = &#63; and companyId = &#63;.
863             *
864             * @param uuid the uuid
865             * @param companyId the company ID
866             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
867             * @return the last matching user notification event
868             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a matching user notification event could not be found
869             * @throws SystemException if a system exception occurred
870             */
871            public UserNotificationEvent findByUuid_C_Last(String uuid, long companyId,
872                    OrderByComparator orderByComparator)
873                    throws NoSuchUserNotificationEventException, SystemException {
874                    UserNotificationEvent userNotificationEvent = fetchByUuid_C_Last(uuid,
875                                    companyId, orderByComparator);
876    
877                    if (userNotificationEvent != null) {
878                            return userNotificationEvent;
879                    }
880    
881                    StringBundler msg = new StringBundler(6);
882    
883                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
884    
885                    msg.append("uuid=");
886                    msg.append(uuid);
887    
888                    msg.append(", companyId=");
889                    msg.append(companyId);
890    
891                    msg.append(StringPool.CLOSE_CURLY_BRACE);
892    
893                    throw new NoSuchUserNotificationEventException(msg.toString());
894            }
895    
896            /**
897             * Returns the last user notification event in the ordered set where uuid = &#63; and companyId = &#63;.
898             *
899             * @param uuid the uuid
900             * @param companyId the company ID
901             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
902             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
903             * @throws SystemException if a system exception occurred
904             */
905            public UserNotificationEvent fetchByUuid_C_Last(String uuid,
906                    long companyId, OrderByComparator orderByComparator)
907                    throws SystemException {
908                    int count = countByUuid_C(uuid, companyId);
909    
910                    List<UserNotificationEvent> list = findByUuid_C(uuid, companyId,
911                                    count - 1, count, orderByComparator);
912    
913                    if (!list.isEmpty()) {
914                            return list.get(0);
915                    }
916    
917                    return null;
918            }
919    
920            /**
921             * Returns the user notification events before and after the current user notification event in the ordered set where uuid = &#63; and companyId = &#63;.
922             *
923             * @param userNotificationEventId the primary key of the current user notification event
924             * @param uuid the uuid
925             * @param companyId the company ID
926             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
927             * @return the previous, current, and next user notification event
928             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
929             * @throws SystemException if a system exception occurred
930             */
931            public UserNotificationEvent[] findByUuid_C_PrevAndNext(
932                    long userNotificationEventId, String uuid, long companyId,
933                    OrderByComparator orderByComparator)
934                    throws NoSuchUserNotificationEventException, SystemException {
935                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
936    
937                    Session session = null;
938    
939                    try {
940                            session = openSession();
941    
942                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
943    
944                            array[0] = getByUuid_C_PrevAndNext(session, userNotificationEvent,
945                                            uuid, companyId, orderByComparator, true);
946    
947                            array[1] = userNotificationEvent;
948    
949                            array[2] = getByUuid_C_PrevAndNext(session, userNotificationEvent,
950                                            uuid, companyId, orderByComparator, false);
951    
952                            return array;
953                    }
954                    catch (Exception e) {
955                            throw processException(e);
956                    }
957                    finally {
958                            closeSession(session);
959                    }
960            }
961    
962            protected UserNotificationEvent getByUuid_C_PrevAndNext(Session session,
963                    UserNotificationEvent userNotificationEvent, String uuid,
964                    long companyId, OrderByComparator orderByComparator, boolean previous) {
965                    StringBundler query = null;
966    
967                    if (orderByComparator != null) {
968                            query = new StringBundler(6 +
969                                            (orderByComparator.getOrderByFields().length * 6));
970                    }
971                    else {
972                            query = new StringBundler(3);
973                    }
974    
975                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
976    
977                    boolean bindUuid = false;
978    
979                    if (uuid == null) {
980                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
981                    }
982                    else if (uuid.equals(StringPool.BLANK)) {
983                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
984                    }
985                    else {
986                            bindUuid = true;
987    
988                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
989                    }
990    
991                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
992    
993                    if (orderByComparator != null) {
994                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
995    
996                            if (orderByConditionFields.length > 0) {
997                                    query.append(WHERE_AND);
998                            }
999    
1000                            for (int i = 0; i < orderByConditionFields.length; i++) {
1001                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1002                                    query.append(orderByConditionFields[i]);
1003    
1004                                    if ((i + 1) < orderByConditionFields.length) {
1005                                            if (orderByComparator.isAscending() ^ previous) {
1006                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1007                                            }
1008                                            else {
1009                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1010                                            }
1011                                    }
1012                                    else {
1013                                            if (orderByComparator.isAscending() ^ previous) {
1014                                                    query.append(WHERE_GREATER_THAN);
1015                                            }
1016                                            else {
1017                                                    query.append(WHERE_LESSER_THAN);
1018                                            }
1019                                    }
1020                            }
1021    
1022                            query.append(ORDER_BY_CLAUSE);
1023    
1024                            String[] orderByFields = orderByComparator.getOrderByFields();
1025    
1026                            for (int i = 0; i < orderByFields.length; i++) {
1027                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1028                                    query.append(orderByFields[i]);
1029    
1030                                    if ((i + 1) < orderByFields.length) {
1031                                            if (orderByComparator.isAscending() ^ previous) {
1032                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1033                                            }
1034                                            else {
1035                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1036                                            }
1037                                    }
1038                                    else {
1039                                            if (orderByComparator.isAscending() ^ previous) {
1040                                                    query.append(ORDER_BY_ASC);
1041                                            }
1042                                            else {
1043                                                    query.append(ORDER_BY_DESC);
1044                                            }
1045                                    }
1046                            }
1047                    }
1048                    else {
1049                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1050                    }
1051    
1052                    String sql = query.toString();
1053    
1054                    Query q = session.createQuery(sql);
1055    
1056                    q.setFirstResult(0);
1057                    q.setMaxResults(2);
1058    
1059                    QueryPos qPos = QueryPos.getInstance(q);
1060    
1061                    if (bindUuid) {
1062                            qPos.add(uuid);
1063                    }
1064    
1065                    qPos.add(companyId);
1066    
1067                    if (orderByComparator != null) {
1068                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
1069    
1070                            for (Object value : values) {
1071                                    qPos.add(value);
1072                            }
1073                    }
1074    
1075                    List<UserNotificationEvent> list = q.list();
1076    
1077                    if (list.size() == 2) {
1078                            return list.get(1);
1079                    }
1080                    else {
1081                            return null;
1082                    }
1083            }
1084    
1085            /**
1086             * Removes all the user notification events where uuid = &#63; and companyId = &#63; from the database.
1087             *
1088             * @param uuid the uuid
1089             * @param companyId the company ID
1090             * @throws SystemException if a system exception occurred
1091             */
1092            public void removeByUuid_C(String uuid, long companyId)
1093                    throws SystemException {
1094                    for (UserNotificationEvent userNotificationEvent : findByUuid_C(uuid,
1095                                    companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1096                            remove(userNotificationEvent);
1097                    }
1098            }
1099    
1100            /**
1101             * Returns the number of user notification events where uuid = &#63; and companyId = &#63;.
1102             *
1103             * @param uuid the uuid
1104             * @param companyId the company ID
1105             * @return the number of matching user notification events
1106             * @throws SystemException if a system exception occurred
1107             */
1108            public int countByUuid_C(String uuid, long companyId)
1109                    throws SystemException {
1110                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1111    
1112                    Object[] finderArgs = new Object[] { uuid, companyId };
1113    
1114                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1115                                    this);
1116    
1117                    if (count == null) {
1118                            StringBundler query = new StringBundler(3);
1119    
1120                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
1121    
1122                            boolean bindUuid = false;
1123    
1124                            if (uuid == null) {
1125                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1126                            }
1127                            else if (uuid.equals(StringPool.BLANK)) {
1128                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1129                            }
1130                            else {
1131                                    bindUuid = true;
1132    
1133                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1134                            }
1135    
1136                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1137    
1138                            String sql = query.toString();
1139    
1140                            Session session = null;
1141    
1142                            try {
1143                                    session = openSession();
1144    
1145                                    Query q = session.createQuery(sql);
1146    
1147                                    QueryPos qPos = QueryPos.getInstance(q);
1148    
1149                                    if (bindUuid) {
1150                                            qPos.add(uuid);
1151                                    }
1152    
1153                                    qPos.add(companyId);
1154    
1155                                    count = (Long)q.uniqueResult();
1156    
1157                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1158                            }
1159                            catch (Exception e) {
1160                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1161    
1162                                    throw processException(e);
1163                            }
1164                            finally {
1165                                    closeSession(session);
1166                            }
1167                    }
1168    
1169                    return count.intValue();
1170            }
1171    
1172            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "userNotificationEvent.uuid IS NULL AND ";
1173            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "userNotificationEvent.uuid = ? AND ";
1174            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(userNotificationEvent.uuid IS NULL OR userNotificationEvent.uuid = '') AND ";
1175            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "userNotificationEvent.companyId = ?";
1176            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1177                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1178                            UserNotificationEventImpl.class,
1179                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
1180                            new String[] {
1181                                    Long.class.getName(),
1182                                    
1183                            Integer.class.getName(), Integer.class.getName(),
1184                                    OrderByComparator.class.getName()
1185                            });
1186            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1187                    new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1188                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1189                            UserNotificationEventImpl.class,
1190                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
1191                            new String[] { Long.class.getName() },
1192                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
1193                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
1194            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1195                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
1196                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1197                            new String[] { Long.class.getName() });
1198    
1199            /**
1200             * Returns all the user notification events where userId = &#63;.
1201             *
1202             * @param userId the user ID
1203             * @return the matching user notification events
1204             * @throws SystemException if a system exception occurred
1205             */
1206            public List<UserNotificationEvent> findByUserId(long userId)
1207                    throws SystemException {
1208                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1209            }
1210    
1211            /**
1212             * Returns a range of all the user notification events where userId = &#63;.
1213             *
1214             * <p>
1215             * 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.
1216             * </p>
1217             *
1218             * @param userId the user ID
1219             * @param start the lower bound of the range of user notification events
1220             * @param end the upper bound of the range of user notification events (not inclusive)
1221             * @return the range of matching user notification events
1222             * @throws SystemException if a system exception occurred
1223             */
1224            public List<UserNotificationEvent> findByUserId(long userId, int start,
1225                    int end) throws SystemException {
1226                    return findByUserId(userId, start, end, null);
1227            }
1228    
1229            /**
1230             * Returns an ordered range of all the user notification events where userId = &#63;.
1231             *
1232             * <p>
1233             * 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.
1234             * </p>
1235             *
1236             * @param userId the user ID
1237             * @param start the lower bound of the range of user notification events
1238             * @param end the upper bound of the range of user notification events (not inclusive)
1239             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1240             * @return the ordered range of matching user notification events
1241             * @throws SystemException if a system exception occurred
1242             */
1243            public List<UserNotificationEvent> findByUserId(long userId, int start,
1244                    int end, OrderByComparator orderByComparator) throws SystemException {
1245                    boolean pagination = true;
1246                    FinderPath finderPath = null;
1247                    Object[] finderArgs = null;
1248    
1249                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1250                                    (orderByComparator == null)) {
1251                            pagination = false;
1252                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1253                            finderArgs = new Object[] { userId };
1254                    }
1255                    else {
1256                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1257                            finderArgs = new Object[] { userId, start, end, orderByComparator };
1258                    }
1259    
1260                    List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
1261                                    finderArgs, this);
1262    
1263                    if ((list != null) && !list.isEmpty()) {
1264                            for (UserNotificationEvent userNotificationEvent : list) {
1265                                    if ((userId != userNotificationEvent.getUserId())) {
1266                                            list = null;
1267    
1268                                            break;
1269                                    }
1270                            }
1271                    }
1272    
1273                    if (list == null) {
1274                            StringBundler query = null;
1275    
1276                            if (orderByComparator != null) {
1277                                    query = new StringBundler(3 +
1278                                                    (orderByComparator.getOrderByFields().length * 3));
1279                            }
1280                            else {
1281                                    query = new StringBundler(3);
1282                            }
1283    
1284                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1285    
1286                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1287    
1288                            if (orderByComparator != null) {
1289                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1290                                            orderByComparator);
1291                            }
1292                            else
1293                             if (pagination) {
1294                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1295                            }
1296    
1297                            String sql = query.toString();
1298    
1299                            Session session = null;
1300    
1301                            try {
1302                                    session = openSession();
1303    
1304                                    Query q = session.createQuery(sql);
1305    
1306                                    QueryPos qPos = QueryPos.getInstance(q);
1307    
1308                                    qPos.add(userId);
1309    
1310                                    if (!pagination) {
1311                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
1312                                                            getDialect(), start, end, false);
1313    
1314                                            Collections.sort(list);
1315    
1316                                            list = new UnmodifiableList<UserNotificationEvent>(list);
1317                                    }
1318                                    else {
1319                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
1320                                                            getDialect(), start, end);
1321                                    }
1322    
1323                                    cacheResult(list);
1324    
1325                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1326                            }
1327                            catch (Exception e) {
1328                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1329    
1330                                    throw processException(e);
1331                            }
1332                            finally {
1333                                    closeSession(session);
1334                            }
1335                    }
1336    
1337                    return list;
1338            }
1339    
1340            /**
1341             * Returns the first user notification event in the ordered set where userId = &#63;.
1342             *
1343             * @param userId the user ID
1344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1345             * @return the first matching user notification event
1346             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a matching user notification event could not be found
1347             * @throws SystemException if a system exception occurred
1348             */
1349            public UserNotificationEvent findByUserId_First(long userId,
1350                    OrderByComparator orderByComparator)
1351                    throws NoSuchUserNotificationEventException, SystemException {
1352                    UserNotificationEvent userNotificationEvent = fetchByUserId_First(userId,
1353                                    orderByComparator);
1354    
1355                    if (userNotificationEvent != null) {
1356                            return userNotificationEvent;
1357                    }
1358    
1359                    StringBundler msg = new StringBundler(4);
1360    
1361                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1362    
1363                    msg.append("userId=");
1364                    msg.append(userId);
1365    
1366                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1367    
1368                    throw new NoSuchUserNotificationEventException(msg.toString());
1369            }
1370    
1371            /**
1372             * Returns the first user notification event in the ordered set where userId = &#63;.
1373             *
1374             * @param userId the user ID
1375             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1376             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
1377             * @throws SystemException if a system exception occurred
1378             */
1379            public UserNotificationEvent fetchByUserId_First(long userId,
1380                    OrderByComparator orderByComparator) throws SystemException {
1381                    List<UserNotificationEvent> list = findByUserId(userId, 0, 1,
1382                                    orderByComparator);
1383    
1384                    if (!list.isEmpty()) {
1385                            return list.get(0);
1386                    }
1387    
1388                    return null;
1389            }
1390    
1391            /**
1392             * Returns the last user notification event in the ordered set where userId = &#63;.
1393             *
1394             * @param userId the user ID
1395             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1396             * @return the last matching user notification event
1397             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a matching user notification event could not be found
1398             * @throws SystemException if a system exception occurred
1399             */
1400            public UserNotificationEvent findByUserId_Last(long userId,
1401                    OrderByComparator orderByComparator)
1402                    throws NoSuchUserNotificationEventException, SystemException {
1403                    UserNotificationEvent userNotificationEvent = fetchByUserId_Last(userId,
1404                                    orderByComparator);
1405    
1406                    if (userNotificationEvent != null) {
1407                            return userNotificationEvent;
1408                    }
1409    
1410                    StringBundler msg = new StringBundler(4);
1411    
1412                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1413    
1414                    msg.append("userId=");
1415                    msg.append(userId);
1416    
1417                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1418    
1419                    throw new NoSuchUserNotificationEventException(msg.toString());
1420            }
1421    
1422            /**
1423             * Returns the last user notification event in the ordered set where userId = &#63;.
1424             *
1425             * @param userId the user ID
1426             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1427             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
1428             * @throws SystemException if a system exception occurred
1429             */
1430            public UserNotificationEvent fetchByUserId_Last(long userId,
1431                    OrderByComparator orderByComparator) throws SystemException {
1432                    int count = countByUserId(userId);
1433    
1434                    List<UserNotificationEvent> list = findByUserId(userId, count - 1,
1435                                    count, orderByComparator);
1436    
1437                    if (!list.isEmpty()) {
1438                            return list.get(0);
1439                    }
1440    
1441                    return null;
1442            }
1443    
1444            /**
1445             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63;.
1446             *
1447             * @param userNotificationEventId the primary key of the current user notification event
1448             * @param userId the user ID
1449             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1450             * @return the previous, current, and next user notification event
1451             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
1452             * @throws SystemException if a system exception occurred
1453             */
1454            public UserNotificationEvent[] findByUserId_PrevAndNext(
1455                    long userNotificationEventId, long userId,
1456                    OrderByComparator orderByComparator)
1457                    throws NoSuchUserNotificationEventException, SystemException {
1458                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
1459    
1460                    Session session = null;
1461    
1462                    try {
1463                            session = openSession();
1464    
1465                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
1466    
1467                            array[0] = getByUserId_PrevAndNext(session, userNotificationEvent,
1468                                            userId, orderByComparator, true);
1469    
1470                            array[1] = userNotificationEvent;
1471    
1472                            array[2] = getByUserId_PrevAndNext(session, userNotificationEvent,
1473                                            userId, orderByComparator, false);
1474    
1475                            return array;
1476                    }
1477                    catch (Exception e) {
1478                            throw processException(e);
1479                    }
1480                    finally {
1481                            closeSession(session);
1482                    }
1483            }
1484    
1485            protected UserNotificationEvent getByUserId_PrevAndNext(Session session,
1486                    UserNotificationEvent userNotificationEvent, long userId,
1487                    OrderByComparator orderByComparator, boolean previous) {
1488                    StringBundler query = null;
1489    
1490                    if (orderByComparator != null) {
1491                            query = new StringBundler(6 +
1492                                            (orderByComparator.getOrderByFields().length * 6));
1493                    }
1494                    else {
1495                            query = new StringBundler(3);
1496                    }
1497    
1498                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1499    
1500                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1501    
1502                    if (orderByComparator != null) {
1503                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1504    
1505                            if (orderByConditionFields.length > 0) {
1506                                    query.append(WHERE_AND);
1507                            }
1508    
1509                            for (int i = 0; i < orderByConditionFields.length; i++) {
1510                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1511                                    query.append(orderByConditionFields[i]);
1512    
1513                                    if ((i + 1) < orderByConditionFields.length) {
1514                                            if (orderByComparator.isAscending() ^ previous) {
1515                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1516                                            }
1517                                            else {
1518                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1519                                            }
1520                                    }
1521                                    else {
1522                                            if (orderByComparator.isAscending() ^ previous) {
1523                                                    query.append(WHERE_GREATER_THAN);
1524                                            }
1525                                            else {
1526                                                    query.append(WHERE_LESSER_THAN);
1527                                            }
1528                                    }
1529                            }
1530    
1531                            query.append(ORDER_BY_CLAUSE);
1532    
1533                            String[] orderByFields = orderByComparator.getOrderByFields();
1534    
1535                            for (int i = 0; i < orderByFields.length; i++) {
1536                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1537                                    query.append(orderByFields[i]);
1538    
1539                                    if ((i + 1) < orderByFields.length) {
1540                                            if (orderByComparator.isAscending() ^ previous) {
1541                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1542                                            }
1543                                            else {
1544                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1545                                            }
1546                                    }
1547                                    else {
1548                                            if (orderByComparator.isAscending() ^ previous) {
1549                                                    query.append(ORDER_BY_ASC);
1550                                            }
1551                                            else {
1552                                                    query.append(ORDER_BY_DESC);
1553                                            }
1554                                    }
1555                            }
1556                    }
1557                    else {
1558                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1559                    }
1560    
1561                    String sql = query.toString();
1562    
1563                    Query q = session.createQuery(sql);
1564    
1565                    q.setFirstResult(0);
1566                    q.setMaxResults(2);
1567    
1568                    QueryPos qPos = QueryPos.getInstance(q);
1569    
1570                    qPos.add(userId);
1571    
1572                    if (orderByComparator != null) {
1573                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
1574    
1575                            for (Object value : values) {
1576                                    qPos.add(value);
1577                            }
1578                    }
1579    
1580                    List<UserNotificationEvent> list = q.list();
1581    
1582                    if (list.size() == 2) {
1583                            return list.get(1);
1584                    }
1585                    else {
1586                            return null;
1587                    }
1588            }
1589    
1590            /**
1591             * Removes all the user notification events where userId = &#63; from the database.
1592             *
1593             * @param userId the user ID
1594             * @throws SystemException if a system exception occurred
1595             */
1596            public void removeByUserId(long userId) throws SystemException {
1597                    for (UserNotificationEvent userNotificationEvent : findByUserId(
1598                                    userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1599                            remove(userNotificationEvent);
1600                    }
1601            }
1602    
1603            /**
1604             * Returns the number of user notification events where userId = &#63;.
1605             *
1606             * @param userId the user ID
1607             * @return the number of matching user notification events
1608             * @throws SystemException if a system exception occurred
1609             */
1610            public int countByUserId(long userId) throws SystemException {
1611                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
1612    
1613                    Object[] finderArgs = new Object[] { userId };
1614    
1615                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1616                                    this);
1617    
1618                    if (count == null) {
1619                            StringBundler query = new StringBundler(2);
1620    
1621                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
1622    
1623                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1624    
1625                            String sql = query.toString();
1626    
1627                            Session session = null;
1628    
1629                            try {
1630                                    session = openSession();
1631    
1632                                    Query q = session.createQuery(sql);
1633    
1634                                    QueryPos qPos = QueryPos.getInstance(q);
1635    
1636                                    qPos.add(userId);
1637    
1638                                    count = (Long)q.uniqueResult();
1639    
1640                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1641                            }
1642                            catch (Exception e) {
1643                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1644    
1645                                    throw processException(e);
1646                            }
1647                            finally {
1648                                    closeSession(session);
1649                            }
1650                    }
1651    
1652                    return count.intValue();
1653            }
1654    
1655            private static final String _FINDER_COLUMN_USERID_USERID_2 = "userNotificationEvent.userId = ?";
1656            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1657                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1658                            UserNotificationEventImpl.class,
1659                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_A",
1660                            new String[] {
1661                                    Long.class.getName(), Boolean.class.getName(),
1662                                    
1663                            Integer.class.getName(), Integer.class.getName(),
1664                                    OrderByComparator.class.getName()
1665                            });
1666            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1667                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1668                            UserNotificationEventImpl.class,
1669                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_A",
1670                            new String[] { Long.class.getName(), Boolean.class.getName() },
1671                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
1672                            UserNotificationEventModelImpl.ARCHIVED_COLUMN_BITMASK |
1673                            UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
1674            public static final FinderPath FINDER_PATH_COUNT_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1675                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
1676                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_A",
1677                            new String[] { Long.class.getName(), Boolean.class.getName() });
1678    
1679            /**
1680             * Returns all the user notification events where userId = &#63; and archived = &#63;.
1681             *
1682             * @param userId the user ID
1683             * @param archived the archived
1684             * @return the matching user notification events
1685             * @throws SystemException if a system exception occurred
1686             */
1687            public List<UserNotificationEvent> findByU_A(long userId, boolean archived)
1688                    throws SystemException {
1689                    return findByU_A(userId, archived, QueryUtil.ALL_POS,
1690                            QueryUtil.ALL_POS, null);
1691            }
1692    
1693            /**
1694             * Returns a range of all the user notification events where userId = &#63; and archived = &#63;.
1695             *
1696             * <p>
1697             * 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.
1698             * </p>
1699             *
1700             * @param userId the user ID
1701             * @param archived the archived
1702             * @param start the lower bound of the range of user notification events
1703             * @param end the upper bound of the range of user notification events (not inclusive)
1704             * @return the range of matching user notification events
1705             * @throws SystemException if a system exception occurred
1706             */
1707            public List<UserNotificationEvent> findByU_A(long userId, boolean archived,
1708                    int start, int end) throws SystemException {
1709                    return findByU_A(userId, archived, start, end, null);
1710            }
1711    
1712            /**
1713             * Returns an ordered range of all the user notification events where userId = &#63; and archived = &#63;.
1714             *
1715             * <p>
1716             * 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.
1717             * </p>
1718             *
1719             * @param userId the user ID
1720             * @param archived the archived
1721             * @param start the lower bound of the range of user notification events
1722             * @param end the upper bound of the range of user notification events (not inclusive)
1723             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1724             * @return the ordered range of matching user notification events
1725             * @throws SystemException if a system exception occurred
1726             */
1727            public List<UserNotificationEvent> findByU_A(long userId, boolean archived,
1728                    int start, int end, OrderByComparator orderByComparator)
1729                    throws SystemException {
1730                    boolean pagination = true;
1731                    FinderPath finderPath = null;
1732                    Object[] finderArgs = null;
1733    
1734                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1735                                    (orderByComparator == null)) {
1736                            pagination = false;
1737                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A;
1738                            finderArgs = new Object[] { userId, archived };
1739                    }
1740                    else {
1741                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_A;
1742                            finderArgs = new Object[] {
1743                                            userId, archived,
1744                                            
1745                                            start, end, orderByComparator
1746                                    };
1747                    }
1748    
1749                    List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
1750                                    finderArgs, this);
1751    
1752                    if ((list != null) && !list.isEmpty()) {
1753                            for (UserNotificationEvent userNotificationEvent : list) {
1754                                    if ((userId != userNotificationEvent.getUserId()) ||
1755                                                    (archived != userNotificationEvent.getArchived())) {
1756                                            list = null;
1757    
1758                                            break;
1759                                    }
1760                            }
1761                    }
1762    
1763                    if (list == null) {
1764                            StringBundler query = null;
1765    
1766                            if (orderByComparator != null) {
1767                                    query = new StringBundler(4 +
1768                                                    (orderByComparator.getOrderByFields().length * 3));
1769                            }
1770                            else {
1771                                    query = new StringBundler(4);
1772                            }
1773    
1774                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1775    
1776                            query.append(_FINDER_COLUMN_U_A_USERID_2);
1777    
1778                            query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
1779    
1780                            if (orderByComparator != null) {
1781                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1782                                            orderByComparator);
1783                            }
1784                            else
1785                             if (pagination) {
1786                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1787                            }
1788    
1789                            String sql = query.toString();
1790    
1791                            Session session = null;
1792    
1793                            try {
1794                                    session = openSession();
1795    
1796                                    Query q = session.createQuery(sql);
1797    
1798                                    QueryPos qPos = QueryPos.getInstance(q);
1799    
1800                                    qPos.add(userId);
1801    
1802                                    qPos.add(archived);
1803    
1804                                    if (!pagination) {
1805                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
1806                                                            getDialect(), start, end, false);
1807    
1808                                            Collections.sort(list);
1809    
1810                                            list = new UnmodifiableList<UserNotificationEvent>(list);
1811                                    }
1812                                    else {
1813                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
1814                                                            getDialect(), start, end);
1815                                    }
1816    
1817                                    cacheResult(list);
1818    
1819                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1820                            }
1821                            catch (Exception e) {
1822                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1823    
1824                                    throw processException(e);
1825                            }
1826                            finally {
1827                                    closeSession(session);
1828                            }
1829                    }
1830    
1831                    return list;
1832            }
1833    
1834            /**
1835             * Returns the first user notification event in the ordered set where userId = &#63; and archived = &#63;.
1836             *
1837             * @param userId the user ID
1838             * @param archived the archived
1839             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1840             * @return the first matching user notification event
1841             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a matching user notification event could not be found
1842             * @throws SystemException if a system exception occurred
1843             */
1844            public UserNotificationEvent findByU_A_First(long userId, boolean archived,
1845                    OrderByComparator orderByComparator)
1846                    throws NoSuchUserNotificationEventException, SystemException {
1847                    UserNotificationEvent userNotificationEvent = fetchByU_A_First(userId,
1848                                    archived, orderByComparator);
1849    
1850                    if (userNotificationEvent != null) {
1851                            return userNotificationEvent;
1852                    }
1853    
1854                    StringBundler msg = new StringBundler(6);
1855    
1856                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1857    
1858                    msg.append("userId=");
1859                    msg.append(userId);
1860    
1861                    msg.append(", archived=");
1862                    msg.append(archived);
1863    
1864                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1865    
1866                    throw new NoSuchUserNotificationEventException(msg.toString());
1867            }
1868    
1869            /**
1870             * Returns the first user notification event in the ordered set where userId = &#63; and archived = &#63;.
1871             *
1872             * @param userId the user ID
1873             * @param archived the archived
1874             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1875             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
1876             * @throws SystemException if a system exception occurred
1877             */
1878            public UserNotificationEvent fetchByU_A_First(long userId,
1879                    boolean archived, OrderByComparator orderByComparator)
1880                    throws SystemException {
1881                    List<UserNotificationEvent> list = findByU_A(userId, archived, 0, 1,
1882                                    orderByComparator);
1883    
1884                    if (!list.isEmpty()) {
1885                            return list.get(0);
1886                    }
1887    
1888                    return null;
1889            }
1890    
1891            /**
1892             * Returns the last user notification event in the ordered set where userId = &#63; and archived = &#63;.
1893             *
1894             * @param userId the user ID
1895             * @param archived the archived
1896             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1897             * @return the last matching user notification event
1898             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a matching user notification event could not be found
1899             * @throws SystemException if a system exception occurred
1900             */
1901            public UserNotificationEvent findByU_A_Last(long userId, boolean archived,
1902                    OrderByComparator orderByComparator)
1903                    throws NoSuchUserNotificationEventException, SystemException {
1904                    UserNotificationEvent userNotificationEvent = fetchByU_A_Last(userId,
1905                                    archived, orderByComparator);
1906    
1907                    if (userNotificationEvent != null) {
1908                            return userNotificationEvent;
1909                    }
1910    
1911                    StringBundler msg = new StringBundler(6);
1912    
1913                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1914    
1915                    msg.append("userId=");
1916                    msg.append(userId);
1917    
1918                    msg.append(", archived=");
1919                    msg.append(archived);
1920    
1921                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1922    
1923                    throw new NoSuchUserNotificationEventException(msg.toString());
1924            }
1925    
1926            /**
1927             * Returns the last user notification event in the ordered set where userId = &#63; and archived = &#63;.
1928             *
1929             * @param userId the user ID
1930             * @param archived the archived
1931             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1932             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
1933             * @throws SystemException if a system exception occurred
1934             */
1935            public UserNotificationEvent fetchByU_A_Last(long userId, boolean archived,
1936                    OrderByComparator orderByComparator) throws SystemException {
1937                    int count = countByU_A(userId, archived);
1938    
1939                    List<UserNotificationEvent> list = findByU_A(userId, archived,
1940                                    count - 1, count, orderByComparator);
1941    
1942                    if (!list.isEmpty()) {
1943                            return list.get(0);
1944                    }
1945    
1946                    return null;
1947            }
1948    
1949            /**
1950             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63; and archived = &#63;.
1951             *
1952             * @param userNotificationEventId the primary key of the current user notification event
1953             * @param userId the user ID
1954             * @param archived the archived
1955             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1956             * @return the previous, current, and next user notification event
1957             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
1958             * @throws SystemException if a system exception occurred
1959             */
1960            public UserNotificationEvent[] findByU_A_PrevAndNext(
1961                    long userNotificationEventId, long userId, boolean archived,
1962                    OrderByComparator orderByComparator)
1963                    throws NoSuchUserNotificationEventException, SystemException {
1964                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
1965    
1966                    Session session = null;
1967    
1968                    try {
1969                            session = openSession();
1970    
1971                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
1972    
1973                            array[0] = getByU_A_PrevAndNext(session, userNotificationEvent,
1974                                            userId, archived, orderByComparator, true);
1975    
1976                            array[1] = userNotificationEvent;
1977    
1978                            array[2] = getByU_A_PrevAndNext(session, userNotificationEvent,
1979                                            userId, archived, orderByComparator, false);
1980    
1981                            return array;
1982                    }
1983                    catch (Exception e) {
1984                            throw processException(e);
1985                    }
1986                    finally {
1987                            closeSession(session);
1988                    }
1989            }
1990    
1991            protected UserNotificationEvent getByU_A_PrevAndNext(Session session,
1992                    UserNotificationEvent userNotificationEvent, long userId,
1993                    boolean archived, OrderByComparator orderByComparator, boolean previous) {
1994                    StringBundler query = null;
1995    
1996                    if (orderByComparator != null) {
1997                            query = new StringBundler(6 +
1998                                            (orderByComparator.getOrderByFields().length * 6));
1999                    }
2000                    else {
2001                            query = new StringBundler(3);
2002                    }
2003    
2004                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
2005    
2006                    query.append(_FINDER_COLUMN_U_A_USERID_2);
2007    
2008                    query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
2009    
2010                    if (orderByComparator != null) {
2011                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2012    
2013                            if (orderByConditionFields.length > 0) {
2014                                    query.append(WHERE_AND);
2015                            }
2016    
2017                            for (int i = 0; i < orderByConditionFields.length; i++) {
2018                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2019                                    query.append(orderByConditionFields[i]);
2020    
2021                                    if ((i + 1) < orderByConditionFields.length) {
2022                                            if (orderByComparator.isAscending() ^ previous) {
2023                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2024                                            }
2025                                            else {
2026                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2027                                            }
2028                                    }
2029                                    else {
2030                                            if (orderByComparator.isAscending() ^ previous) {
2031                                                    query.append(WHERE_GREATER_THAN);
2032                                            }
2033                                            else {
2034                                                    query.append(WHERE_LESSER_THAN);
2035                                            }
2036                                    }
2037                            }
2038    
2039                            query.append(ORDER_BY_CLAUSE);
2040    
2041                            String[] orderByFields = orderByComparator.getOrderByFields();
2042    
2043                            for (int i = 0; i < orderByFields.length; i++) {
2044                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2045                                    query.append(orderByFields[i]);
2046    
2047                                    if ((i + 1) < orderByFields.length) {
2048                                            if (orderByComparator.isAscending() ^ previous) {
2049                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2050                                            }
2051                                            else {
2052                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2053                                            }
2054                                    }
2055                                    else {
2056                                            if (orderByComparator.isAscending() ^ previous) {
2057                                                    query.append(ORDER_BY_ASC);
2058                                            }
2059                                            else {
2060                                                    query.append(ORDER_BY_DESC);
2061                                            }
2062                                    }
2063                            }
2064                    }
2065                    else {
2066                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
2067                    }
2068    
2069                    String sql = query.toString();
2070    
2071                    Query q = session.createQuery(sql);
2072    
2073                    q.setFirstResult(0);
2074                    q.setMaxResults(2);
2075    
2076                    QueryPos qPos = QueryPos.getInstance(q);
2077    
2078                    qPos.add(userId);
2079    
2080                    qPos.add(archived);
2081    
2082                    if (orderByComparator != null) {
2083                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
2084    
2085                            for (Object value : values) {
2086                                    qPos.add(value);
2087                            }
2088                    }
2089    
2090                    List<UserNotificationEvent> list = q.list();
2091    
2092                    if (list.size() == 2) {
2093                            return list.get(1);
2094                    }
2095                    else {
2096                            return null;
2097                    }
2098            }
2099    
2100            /**
2101             * Removes all the user notification events where userId = &#63; and archived = &#63; from the database.
2102             *
2103             * @param userId the user ID
2104             * @param archived the archived
2105             * @throws SystemException if a system exception occurred
2106             */
2107            public void removeByU_A(long userId, boolean archived)
2108                    throws SystemException {
2109                    for (UserNotificationEvent userNotificationEvent : findByU_A(userId,
2110                                    archived, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2111                            remove(userNotificationEvent);
2112                    }
2113            }
2114    
2115            /**
2116             * Returns the number of user notification events where userId = &#63; and archived = &#63;.
2117             *
2118             * @param userId the user ID
2119             * @param archived the archived
2120             * @return the number of matching user notification events
2121             * @throws SystemException if a system exception occurred
2122             */
2123            public int countByU_A(long userId, boolean archived)
2124                    throws SystemException {
2125                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_A;
2126    
2127                    Object[] finderArgs = new Object[] { userId, archived };
2128    
2129                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2130                                    this);
2131    
2132                    if (count == null) {
2133                            StringBundler query = new StringBundler(3);
2134    
2135                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
2136    
2137                            query.append(_FINDER_COLUMN_U_A_USERID_2);
2138    
2139                            query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
2140    
2141                            String sql = query.toString();
2142    
2143                            Session session = null;
2144    
2145                            try {
2146                                    session = openSession();
2147    
2148                                    Query q = session.createQuery(sql);
2149    
2150                                    QueryPos qPos = QueryPos.getInstance(q);
2151    
2152                                    qPos.add(userId);
2153    
2154                                    qPos.add(archived);
2155    
2156                                    count = (Long)q.uniqueResult();
2157    
2158                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2159                            }
2160                            catch (Exception e) {
2161                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2162    
2163                                    throw processException(e);
2164                            }
2165                            finally {
2166                                    closeSession(session);
2167                            }
2168                    }
2169    
2170                    return count.intValue();
2171            }
2172    
2173            private static final String _FINDER_COLUMN_U_A_USERID_2 = "userNotificationEvent.userId = ? AND ";
2174            private static final String _FINDER_COLUMN_U_A_ARCHIVED_2 = "userNotificationEvent.archived = ?";
2175    
2176            /**
2177             * Caches the user notification event in the entity cache if it is enabled.
2178             *
2179             * @param userNotificationEvent the user notification event
2180             */
2181            public void cacheResult(UserNotificationEvent userNotificationEvent) {
2182                    EntityCacheUtil.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2183                            UserNotificationEventImpl.class,
2184                            userNotificationEvent.getPrimaryKey(), userNotificationEvent);
2185    
2186                    userNotificationEvent.resetOriginalValues();
2187            }
2188    
2189            /**
2190             * Caches the user notification events in the entity cache if it is enabled.
2191             *
2192             * @param userNotificationEvents the user notification events
2193             */
2194            public void cacheResult(List<UserNotificationEvent> userNotificationEvents) {
2195                    for (UserNotificationEvent userNotificationEvent : userNotificationEvents) {
2196                            if (EntityCacheUtil.getResult(
2197                                                    UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2198                                                    UserNotificationEventImpl.class,
2199                                                    userNotificationEvent.getPrimaryKey()) == null) {
2200                                    cacheResult(userNotificationEvent);
2201                            }
2202                            else {
2203                                    userNotificationEvent.resetOriginalValues();
2204                            }
2205                    }
2206            }
2207    
2208            /**
2209             * Clears the cache for all user notification events.
2210             *
2211             * <p>
2212             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2213             * </p>
2214             */
2215            @Override
2216            public void clearCache() {
2217                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2218                            CacheRegistryUtil.clear(UserNotificationEventImpl.class.getName());
2219                    }
2220    
2221                    EntityCacheUtil.clearCache(UserNotificationEventImpl.class.getName());
2222    
2223                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2224                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2225                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2226            }
2227    
2228            /**
2229             * Clears the cache for the user notification event.
2230             *
2231             * <p>
2232             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2233             * </p>
2234             */
2235            @Override
2236            public void clearCache(UserNotificationEvent userNotificationEvent) {
2237                    EntityCacheUtil.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2238                            UserNotificationEventImpl.class,
2239                            userNotificationEvent.getPrimaryKey());
2240    
2241                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2242                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2243            }
2244    
2245            @Override
2246            public void clearCache(List<UserNotificationEvent> userNotificationEvents) {
2247                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2248                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2249    
2250                    for (UserNotificationEvent userNotificationEvent : userNotificationEvents) {
2251                            EntityCacheUtil.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2252                                    UserNotificationEventImpl.class,
2253                                    userNotificationEvent.getPrimaryKey());
2254                    }
2255            }
2256    
2257            /**
2258             * Creates a new user notification event with the primary key. Does not add the user notification event to the database.
2259             *
2260             * @param userNotificationEventId the primary key for the new user notification event
2261             * @return the new user notification event
2262             */
2263            public UserNotificationEvent create(long userNotificationEventId) {
2264                    UserNotificationEvent userNotificationEvent = new UserNotificationEventImpl();
2265    
2266                    userNotificationEvent.setNew(true);
2267                    userNotificationEvent.setPrimaryKey(userNotificationEventId);
2268    
2269                    String uuid = PortalUUIDUtil.generate();
2270    
2271                    userNotificationEvent.setUuid(uuid);
2272    
2273                    return userNotificationEvent;
2274            }
2275    
2276            /**
2277             * Removes the user notification event with the primary key from the database. Also notifies the appropriate model listeners.
2278             *
2279             * @param userNotificationEventId the primary key of the user notification event
2280             * @return the user notification event that was removed
2281             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
2282             * @throws SystemException if a system exception occurred
2283             */
2284            public UserNotificationEvent remove(long userNotificationEventId)
2285                    throws NoSuchUserNotificationEventException, SystemException {
2286                    return remove((Serializable)userNotificationEventId);
2287            }
2288    
2289            /**
2290             * Removes the user notification event with the primary key from the database. Also notifies the appropriate model listeners.
2291             *
2292             * @param primaryKey the primary key of the user notification event
2293             * @return the user notification event that was removed
2294             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
2295             * @throws SystemException if a system exception occurred
2296             */
2297            @Override
2298            public UserNotificationEvent remove(Serializable primaryKey)
2299                    throws NoSuchUserNotificationEventException, SystemException {
2300                    Session session = null;
2301    
2302                    try {
2303                            session = openSession();
2304    
2305                            UserNotificationEvent userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
2306                                            primaryKey);
2307    
2308                            if (userNotificationEvent == null) {
2309                                    if (_log.isWarnEnabled()) {
2310                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2311                                    }
2312    
2313                                    throw new NoSuchUserNotificationEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2314                                            primaryKey);
2315                            }
2316    
2317                            return remove(userNotificationEvent);
2318                    }
2319                    catch (NoSuchUserNotificationEventException nsee) {
2320                            throw nsee;
2321                    }
2322                    catch (Exception e) {
2323                            throw processException(e);
2324                    }
2325                    finally {
2326                            closeSession(session);
2327                    }
2328            }
2329    
2330            @Override
2331            protected UserNotificationEvent removeImpl(
2332                    UserNotificationEvent userNotificationEvent) throws SystemException {
2333                    userNotificationEvent = toUnwrappedModel(userNotificationEvent);
2334    
2335                    Session session = null;
2336    
2337                    try {
2338                            session = openSession();
2339    
2340                            if (!session.contains(userNotificationEvent)) {
2341                                    userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
2342                                                    userNotificationEvent.getPrimaryKeyObj());
2343                            }
2344    
2345                            if (userNotificationEvent != null) {
2346                                    session.delete(userNotificationEvent);
2347                            }
2348                    }
2349                    catch (Exception e) {
2350                            throw processException(e);
2351                    }
2352                    finally {
2353                            closeSession(session);
2354                    }
2355    
2356                    if (userNotificationEvent != null) {
2357                            clearCache(userNotificationEvent);
2358                    }
2359    
2360                    return userNotificationEvent;
2361            }
2362    
2363            @Override
2364            public UserNotificationEvent updateImpl(
2365                    com.liferay.portal.model.UserNotificationEvent userNotificationEvent)
2366                    throws SystemException {
2367                    userNotificationEvent = toUnwrappedModel(userNotificationEvent);
2368    
2369                    boolean isNew = userNotificationEvent.isNew();
2370    
2371                    UserNotificationEventModelImpl userNotificationEventModelImpl = (UserNotificationEventModelImpl)userNotificationEvent;
2372    
2373                    if (Validator.isNull(userNotificationEvent.getUuid())) {
2374                            String uuid = PortalUUIDUtil.generate();
2375    
2376                            userNotificationEvent.setUuid(uuid);
2377                    }
2378    
2379                    Session session = null;
2380    
2381                    try {
2382                            session = openSession();
2383    
2384                            if (userNotificationEvent.isNew()) {
2385                                    session.save(userNotificationEvent);
2386    
2387                                    userNotificationEvent.setNew(false);
2388                            }
2389                            else {
2390                                    session.merge(userNotificationEvent);
2391                            }
2392                    }
2393                    catch (Exception e) {
2394                            throw processException(e);
2395                    }
2396                    finally {
2397                            closeSession(session);
2398                    }
2399    
2400                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2401    
2402                    if (isNew || !UserNotificationEventModelImpl.COLUMN_BITMASK_ENABLED) {
2403                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2404                    }
2405    
2406                    else {
2407                            if ((userNotificationEventModelImpl.getColumnBitmask() &
2408                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2409                                    Object[] args = new Object[] {
2410                                                    userNotificationEventModelImpl.getOriginalUuid()
2411                                            };
2412    
2413                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2414                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2415                                            args);
2416    
2417                                    args = new Object[] { userNotificationEventModelImpl.getUuid() };
2418    
2419                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2420                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2421                                            args);
2422                            }
2423    
2424                            if ((userNotificationEventModelImpl.getColumnBitmask() &
2425                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2426                                    Object[] args = new Object[] {
2427                                                    userNotificationEventModelImpl.getOriginalUuid(),
2428                                                    userNotificationEventModelImpl.getOriginalCompanyId()
2429                                            };
2430    
2431                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2432                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2433                                            args);
2434    
2435                                    args = new Object[] {
2436                                                    userNotificationEventModelImpl.getUuid(),
2437                                                    userNotificationEventModelImpl.getCompanyId()
2438                                            };
2439    
2440                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2441                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2442                                            args);
2443                            }
2444    
2445                            if ((userNotificationEventModelImpl.getColumnBitmask() &
2446                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2447                                    Object[] args = new Object[] {
2448                                                    userNotificationEventModelImpl.getOriginalUserId()
2449                                            };
2450    
2451                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2452                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2453                                            args);
2454    
2455                                    args = new Object[] { userNotificationEventModelImpl.getUserId() };
2456    
2457                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2458                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2459                                            args);
2460                            }
2461    
2462                            if ((userNotificationEventModelImpl.getColumnBitmask() &
2463                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A.getColumnBitmask()) != 0) {
2464                                    Object[] args = new Object[] {
2465                                                    userNotificationEventModelImpl.getOriginalUserId(),
2466                                                    userNotificationEventModelImpl.getOriginalArchived()
2467                                            };
2468    
2469                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_A, args);
2470                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A,
2471                                            args);
2472    
2473                                    args = new Object[] {
2474                                                    userNotificationEventModelImpl.getUserId(),
2475                                                    userNotificationEventModelImpl.getArchived()
2476                                            };
2477    
2478                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_A, args);
2479                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A,
2480                                            args);
2481                            }
2482                    }
2483    
2484                    EntityCacheUtil.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2485                            UserNotificationEventImpl.class,
2486                            userNotificationEvent.getPrimaryKey(), userNotificationEvent);
2487    
2488                    return userNotificationEvent;
2489            }
2490    
2491            protected UserNotificationEvent toUnwrappedModel(
2492                    UserNotificationEvent userNotificationEvent) {
2493                    if (userNotificationEvent instanceof UserNotificationEventImpl) {
2494                            return userNotificationEvent;
2495                    }
2496    
2497                    UserNotificationEventImpl userNotificationEventImpl = new UserNotificationEventImpl();
2498    
2499                    userNotificationEventImpl.setNew(userNotificationEvent.isNew());
2500                    userNotificationEventImpl.setPrimaryKey(userNotificationEvent.getPrimaryKey());
2501    
2502                    userNotificationEventImpl.setUuid(userNotificationEvent.getUuid());
2503                    userNotificationEventImpl.setUserNotificationEventId(userNotificationEvent.getUserNotificationEventId());
2504                    userNotificationEventImpl.setCompanyId(userNotificationEvent.getCompanyId());
2505                    userNotificationEventImpl.setUserId(userNotificationEvent.getUserId());
2506                    userNotificationEventImpl.setType(userNotificationEvent.getType());
2507                    userNotificationEventImpl.setTimestamp(userNotificationEvent.getTimestamp());
2508                    userNotificationEventImpl.setDeliverBy(userNotificationEvent.getDeliverBy());
2509                    userNotificationEventImpl.setPayload(userNotificationEvent.getPayload());
2510                    userNotificationEventImpl.setArchived(userNotificationEvent.isArchived());
2511    
2512                    return userNotificationEventImpl;
2513            }
2514    
2515            /**
2516             * Returns the user notification event with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2517             *
2518             * @param primaryKey the primary key of the user notification event
2519             * @return the user notification event
2520             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
2521             * @throws SystemException if a system exception occurred
2522             */
2523            @Override
2524            public UserNotificationEvent findByPrimaryKey(Serializable primaryKey)
2525                    throws NoSuchUserNotificationEventException, SystemException {
2526                    UserNotificationEvent userNotificationEvent = fetchByPrimaryKey(primaryKey);
2527    
2528                    if (userNotificationEvent == null) {
2529                            if (_log.isWarnEnabled()) {
2530                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2531                            }
2532    
2533                            throw new NoSuchUserNotificationEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2534                                    primaryKey);
2535                    }
2536    
2537                    return userNotificationEvent;
2538            }
2539    
2540            /**
2541             * Returns the user notification event with the primary key or throws a {@link com.liferay.portal.NoSuchUserNotificationEventException} if it could not be found.
2542             *
2543             * @param userNotificationEventId the primary key of the user notification event
2544             * @return the user notification event
2545             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
2546             * @throws SystemException if a system exception occurred
2547             */
2548            public UserNotificationEvent findByPrimaryKey(long userNotificationEventId)
2549                    throws NoSuchUserNotificationEventException, SystemException {
2550                    return findByPrimaryKey((Serializable)userNotificationEventId);
2551            }
2552    
2553            /**
2554             * Returns the user notification event with the primary key or returns <code>null</code> if it could not be found.
2555             *
2556             * @param primaryKey the primary key of the user notification event
2557             * @return the user notification event, or <code>null</code> if a user notification event with the primary key could not be found
2558             * @throws SystemException if a system exception occurred
2559             */
2560            @Override
2561            public UserNotificationEvent fetchByPrimaryKey(Serializable primaryKey)
2562                    throws SystemException {
2563                    UserNotificationEvent userNotificationEvent = (UserNotificationEvent)EntityCacheUtil.getResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2564                                    UserNotificationEventImpl.class, primaryKey);
2565    
2566                    if (userNotificationEvent == _nullUserNotificationEvent) {
2567                            return null;
2568                    }
2569    
2570                    if (userNotificationEvent == null) {
2571                            Session session = null;
2572    
2573                            try {
2574                                    session = openSession();
2575    
2576                                    userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
2577                                                    primaryKey);
2578    
2579                                    if (userNotificationEvent != null) {
2580                                            cacheResult(userNotificationEvent);
2581                                    }
2582                                    else {
2583                                            EntityCacheUtil.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2584                                                    UserNotificationEventImpl.class, primaryKey,
2585                                                    _nullUserNotificationEvent);
2586                                    }
2587                            }
2588                            catch (Exception e) {
2589                                    EntityCacheUtil.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2590                                            UserNotificationEventImpl.class, primaryKey);
2591    
2592                                    throw processException(e);
2593                            }
2594                            finally {
2595                                    closeSession(session);
2596                            }
2597                    }
2598    
2599                    return userNotificationEvent;
2600            }
2601    
2602            /**
2603             * Returns the user notification event with the primary key or returns <code>null</code> if it could not be found.
2604             *
2605             * @param userNotificationEventId the primary key of the user notification event
2606             * @return the user notification event, or <code>null</code> if a user notification event with the primary key could not be found
2607             * @throws SystemException if a system exception occurred
2608             */
2609            public UserNotificationEvent fetchByPrimaryKey(long userNotificationEventId)
2610                    throws SystemException {
2611                    return fetchByPrimaryKey((Serializable)userNotificationEventId);
2612            }
2613    
2614            /**
2615             * Returns all the user notification events.
2616             *
2617             * @return the user notification events
2618             * @throws SystemException if a system exception occurred
2619             */
2620            public List<UserNotificationEvent> findAll() throws SystemException {
2621                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2622            }
2623    
2624            /**
2625             * Returns a range of all the user notification events.
2626             *
2627             * <p>
2628             * 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.
2629             * </p>
2630             *
2631             * @param start the lower bound of the range of user notification events
2632             * @param end the upper bound of the range of user notification events (not inclusive)
2633             * @return the range of user notification events
2634             * @throws SystemException if a system exception occurred
2635             */
2636            public List<UserNotificationEvent> findAll(int start, int end)
2637                    throws SystemException {
2638                    return findAll(start, end, null);
2639            }
2640    
2641            /**
2642             * Returns an ordered range of all the user notification events.
2643             *
2644             * <p>
2645             * 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.
2646             * </p>
2647             *
2648             * @param start the lower bound of the range of user notification events
2649             * @param end the upper bound of the range of user notification events (not inclusive)
2650             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2651             * @return the ordered range of user notification events
2652             * @throws SystemException if a system exception occurred
2653             */
2654            public List<UserNotificationEvent> findAll(int start, int end,
2655                    OrderByComparator orderByComparator) throws SystemException {
2656                    boolean pagination = true;
2657                    FinderPath finderPath = null;
2658                    Object[] finderArgs = null;
2659    
2660                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2661                                    (orderByComparator == null)) {
2662                            pagination = false;
2663                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2664                            finderArgs = FINDER_ARGS_EMPTY;
2665                    }
2666                    else {
2667                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2668                            finderArgs = new Object[] { start, end, orderByComparator };
2669                    }
2670    
2671                    List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
2672                                    finderArgs, this);
2673    
2674                    if (list == null) {
2675                            StringBundler query = null;
2676                            String sql = null;
2677    
2678                            if (orderByComparator != null) {
2679                                    query = new StringBundler(2 +
2680                                                    (orderByComparator.getOrderByFields().length * 3));
2681    
2682                                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT);
2683    
2684                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2685                                            orderByComparator);
2686    
2687                                    sql = query.toString();
2688                            }
2689                            else {
2690                                    sql = _SQL_SELECT_USERNOTIFICATIONEVENT;
2691    
2692                                    if (pagination) {
2693                                            sql = sql.concat(UserNotificationEventModelImpl.ORDER_BY_JPQL);
2694                                    }
2695                            }
2696    
2697                            Session session = null;
2698    
2699                            try {
2700                                    session = openSession();
2701    
2702                                    Query q = session.createQuery(sql);
2703    
2704                                    if (!pagination) {
2705                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
2706                                                            getDialect(), start, end, false);
2707    
2708                                            Collections.sort(list);
2709    
2710                                            list = new UnmodifiableList<UserNotificationEvent>(list);
2711                                    }
2712                                    else {
2713                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
2714                                                            getDialect(), start, end);
2715                                    }
2716    
2717                                    cacheResult(list);
2718    
2719                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2720                            }
2721                            catch (Exception e) {
2722                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2723    
2724                                    throw processException(e);
2725                            }
2726                            finally {
2727                                    closeSession(session);
2728                            }
2729                    }
2730    
2731                    return list;
2732            }
2733    
2734            /**
2735             * Removes all the user notification events from the database.
2736             *
2737             * @throws SystemException if a system exception occurred
2738             */
2739            public void removeAll() throws SystemException {
2740                    for (UserNotificationEvent userNotificationEvent : findAll()) {
2741                            remove(userNotificationEvent);
2742                    }
2743            }
2744    
2745            /**
2746             * Returns the number of user notification events.
2747             *
2748             * @return the number of user notification events
2749             * @throws SystemException if a system exception occurred
2750             */
2751            public int countAll() throws SystemException {
2752                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2753                                    FINDER_ARGS_EMPTY, this);
2754    
2755                    if (count == null) {
2756                            Session session = null;
2757    
2758                            try {
2759                                    session = openSession();
2760    
2761                                    Query q = session.createQuery(_SQL_COUNT_USERNOTIFICATIONEVENT);
2762    
2763                                    count = (Long)q.uniqueResult();
2764    
2765                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2766                                            FINDER_ARGS_EMPTY, count);
2767                            }
2768                            catch (Exception e) {
2769                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2770                                            FINDER_ARGS_EMPTY);
2771    
2772                                    throw processException(e);
2773                            }
2774                            finally {
2775                                    closeSession(session);
2776                            }
2777                    }
2778    
2779                    return count.intValue();
2780            }
2781    
2782            @Override
2783            protected Set<String> getBadColumnNames() {
2784                    return _badColumnNames;
2785            }
2786    
2787            /**
2788             * Initializes the user notification event persistence.
2789             */
2790            public void afterPropertiesSet() {
2791                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2792                                            com.liferay.portal.util.PropsUtil.get(
2793                                                    "value.object.listener.com.liferay.portal.model.UserNotificationEvent")));
2794    
2795                    if (listenerClassNames.length > 0) {
2796                            try {
2797                                    List<ModelListener<UserNotificationEvent>> listenersList = new ArrayList<ModelListener<UserNotificationEvent>>();
2798    
2799                                    for (String listenerClassName : listenerClassNames) {
2800                                            listenersList.add((ModelListener<UserNotificationEvent>)InstanceFactory.newInstance(
2801                                                            getClassLoader(), listenerClassName));
2802                                    }
2803    
2804                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2805                            }
2806                            catch (Exception e) {
2807                                    _log.error(e);
2808                            }
2809                    }
2810            }
2811    
2812            public void destroy() {
2813                    EntityCacheUtil.removeCache(UserNotificationEventImpl.class.getName());
2814                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2815                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2816                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2817            }
2818    
2819            private static final String _SQL_SELECT_USERNOTIFICATIONEVENT = "SELECT userNotificationEvent FROM UserNotificationEvent userNotificationEvent";
2820            private static final String _SQL_SELECT_USERNOTIFICATIONEVENT_WHERE = "SELECT userNotificationEvent FROM UserNotificationEvent userNotificationEvent WHERE ";
2821            private static final String _SQL_COUNT_USERNOTIFICATIONEVENT = "SELECT COUNT(userNotificationEvent) FROM UserNotificationEvent userNotificationEvent";
2822            private static final String _SQL_COUNT_USERNOTIFICATIONEVENT_WHERE = "SELECT COUNT(userNotificationEvent) FROM UserNotificationEvent userNotificationEvent WHERE ";
2823            private static final String _ORDER_BY_ENTITY_ALIAS = "userNotificationEvent.";
2824            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserNotificationEvent exists with the primary key ";
2825            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserNotificationEvent exists with the key {";
2826            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2827            private static Log _log = LogFactoryUtil.getLog(UserNotificationEventPersistenceImpl.class);
2828            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2829                                    "uuid", "type"
2830                            });
2831            private static UserNotificationEvent _nullUserNotificationEvent = new UserNotificationEventImpl() {
2832                            @Override
2833                            public Object clone() {
2834                                    return this;
2835                            }
2836    
2837                            @Override
2838                            public CacheModel<UserNotificationEvent> toCacheModel() {
2839                                    return _nullUserNotificationEventCacheModel;
2840                            }
2841                    };
2842    
2843            private static CacheModel<UserNotificationEvent> _nullUserNotificationEventCacheModel =
2844                    new CacheModel<UserNotificationEvent>() {
2845                            public UserNotificationEvent toEntityModel() {
2846                                    return _nullUserNotificationEvent;
2847                            }
2848                    };
2849    }