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.NoSuchModelException;
018    import com.liferay.portal.NoSuchUserNotificationEventException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
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    
052    /**
053     * The persistence implementation for the user notification event service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see UserNotificationEventPersistence
061     * @see UserNotificationEventUtil
062     * @generated
063     */
064    public class UserNotificationEventPersistenceImpl extends BasePersistenceImpl<UserNotificationEvent>
065            implements UserNotificationEventPersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * 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.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = UserNotificationEventImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
077                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
078                            UserNotificationEventImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
080                            new String[] {
081                                    String.class.getName(),
082                                    
083                            "java.lang.Integer", "java.lang.Integer",
084                                    "com.liferay.portal.kernel.util.OrderByComparator"
085                            });
086            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
087                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
088                            UserNotificationEventImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
090                            new String[] { String.class.getName() },
091                            UserNotificationEventModelImpl.UUID_COLUMN_BITMASK);
092            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
093                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
095                            new String[] { String.class.getName() });
096            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
097                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
098                            UserNotificationEventImpl.class,
099                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
100                            new String[] {
101                                    Long.class.getName(),
102                                    
103                            "java.lang.Integer", "java.lang.Integer",
104                                    "com.liferay.portal.kernel.util.OrderByComparator"
105                            });
106            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
107                    new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
108                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
109                            UserNotificationEventImpl.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
111                            new String[] { Long.class.getName() },
112                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK);
113            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
114                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
115                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
116                            new String[] { Long.class.getName() });
117            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
118                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
119                            UserNotificationEventImpl.class,
120                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_A",
121                            new String[] {
122                                    Long.class.getName(), Boolean.class.getName(),
123                                    
124                            "java.lang.Integer", "java.lang.Integer",
125                                    "com.liferay.portal.kernel.util.OrderByComparator"
126                            });
127            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
128                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
129                            UserNotificationEventImpl.class,
130                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_A",
131                            new String[] { Long.class.getName(), Boolean.class.getName() },
132                            UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
133                            UserNotificationEventModelImpl.ARCHIVED_COLUMN_BITMASK);
134            public static final FinderPath FINDER_PATH_COUNT_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
135                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
136                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_A",
137                            new String[] { Long.class.getName(), Boolean.class.getName() });
138            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
139                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
140                            UserNotificationEventImpl.class,
141                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
142            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
143                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
144                            UserNotificationEventImpl.class,
145                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
146            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
147                            UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
148                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
149    
150            /**
151             * Caches the user notification event in the entity cache if it is enabled.
152             *
153             * @param userNotificationEvent the user notification event
154             */
155            public void cacheResult(UserNotificationEvent userNotificationEvent) {
156                    EntityCacheUtil.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
157                            UserNotificationEventImpl.class,
158                            userNotificationEvent.getPrimaryKey(), userNotificationEvent);
159    
160                    userNotificationEvent.resetOriginalValues();
161            }
162    
163            /**
164             * Caches the user notification events in the entity cache if it is enabled.
165             *
166             * @param userNotificationEvents the user notification events
167             */
168            public void cacheResult(List<UserNotificationEvent> userNotificationEvents) {
169                    for (UserNotificationEvent userNotificationEvent : userNotificationEvents) {
170                            if (EntityCacheUtil.getResult(
171                                                    UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
172                                                    UserNotificationEventImpl.class,
173                                                    userNotificationEvent.getPrimaryKey()) == null) {
174                                    cacheResult(userNotificationEvent);
175                            }
176                            else {
177                                    userNotificationEvent.resetOriginalValues();
178                            }
179                    }
180            }
181    
182            /**
183             * Clears the cache for all user notification events.
184             *
185             * <p>
186             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
187             * </p>
188             */
189            @Override
190            public void clearCache() {
191                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
192                            CacheRegistryUtil.clear(UserNotificationEventImpl.class.getName());
193                    }
194    
195                    EntityCacheUtil.clearCache(UserNotificationEventImpl.class.getName());
196    
197                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
198                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
199                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
200            }
201    
202            /**
203             * Clears the cache for the user notification event.
204             *
205             * <p>
206             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
207             * </p>
208             */
209            @Override
210            public void clearCache(UserNotificationEvent userNotificationEvent) {
211                    EntityCacheUtil.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
212                            UserNotificationEventImpl.class,
213                            userNotificationEvent.getPrimaryKey());
214    
215                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
216                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
217            }
218    
219            @Override
220            public void clearCache(List<UserNotificationEvent> userNotificationEvents) {
221                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
222                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
223    
224                    for (UserNotificationEvent userNotificationEvent : userNotificationEvents) {
225                            EntityCacheUtil.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
226                                    UserNotificationEventImpl.class,
227                                    userNotificationEvent.getPrimaryKey());
228                    }
229            }
230    
231            /**
232             * Creates a new user notification event with the primary key. Does not add the user notification event to the database.
233             *
234             * @param userNotificationEventId the primary key for the new user notification event
235             * @return the new user notification event
236             */
237            public UserNotificationEvent create(long userNotificationEventId) {
238                    UserNotificationEvent userNotificationEvent = new UserNotificationEventImpl();
239    
240                    userNotificationEvent.setNew(true);
241                    userNotificationEvent.setPrimaryKey(userNotificationEventId);
242    
243                    String uuid = PortalUUIDUtil.generate();
244    
245                    userNotificationEvent.setUuid(uuid);
246    
247                    return userNotificationEvent;
248            }
249    
250            /**
251             * Removes the user notification event with the primary key from the database. Also notifies the appropriate model listeners.
252             *
253             * @param userNotificationEventId the primary key of the user notification event
254             * @return the user notification event that was removed
255             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
256             * @throws SystemException if a system exception occurred
257             */
258            public UserNotificationEvent remove(long userNotificationEventId)
259                    throws NoSuchUserNotificationEventException, SystemException {
260                    return remove(Long.valueOf(userNotificationEventId));
261            }
262    
263            /**
264             * Removes the user notification event with the primary key from the database. Also notifies the appropriate model listeners.
265             *
266             * @param primaryKey the primary key of the user notification event
267             * @return the user notification event that was removed
268             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
269             * @throws SystemException if a system exception occurred
270             */
271            @Override
272            public UserNotificationEvent remove(Serializable primaryKey)
273                    throws NoSuchUserNotificationEventException, SystemException {
274                    Session session = null;
275    
276                    try {
277                            session = openSession();
278    
279                            UserNotificationEvent userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
280                                            primaryKey);
281    
282                            if (userNotificationEvent == null) {
283                                    if (_log.isWarnEnabled()) {
284                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
285                                    }
286    
287                                    throw new NoSuchUserNotificationEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
288                                            primaryKey);
289                            }
290    
291                            return remove(userNotificationEvent);
292                    }
293                    catch (NoSuchUserNotificationEventException nsee) {
294                            throw nsee;
295                    }
296                    catch (Exception e) {
297                            throw processException(e);
298                    }
299                    finally {
300                            closeSession(session);
301                    }
302            }
303    
304            @Override
305            protected UserNotificationEvent removeImpl(
306                    UserNotificationEvent userNotificationEvent) throws SystemException {
307                    userNotificationEvent = toUnwrappedModel(userNotificationEvent);
308    
309                    Session session = null;
310    
311                    try {
312                            session = openSession();
313    
314                            BatchSessionUtil.delete(session, userNotificationEvent);
315                    }
316                    catch (Exception e) {
317                            throw processException(e);
318                    }
319                    finally {
320                            closeSession(session);
321                    }
322    
323                    clearCache(userNotificationEvent);
324    
325                    return userNotificationEvent;
326            }
327    
328            @Override
329            public UserNotificationEvent updateImpl(
330                    com.liferay.portal.model.UserNotificationEvent userNotificationEvent,
331                    boolean merge) throws SystemException {
332                    userNotificationEvent = toUnwrappedModel(userNotificationEvent);
333    
334                    boolean isNew = userNotificationEvent.isNew();
335    
336                    UserNotificationEventModelImpl userNotificationEventModelImpl = (UserNotificationEventModelImpl)userNotificationEvent;
337    
338                    if (Validator.isNull(userNotificationEvent.getUuid())) {
339                            String uuid = PortalUUIDUtil.generate();
340    
341                            userNotificationEvent.setUuid(uuid);
342                    }
343    
344                    Session session = null;
345    
346                    try {
347                            session = openSession();
348    
349                            BatchSessionUtil.update(session, userNotificationEvent, merge);
350    
351                            userNotificationEvent.setNew(false);
352                    }
353                    catch (Exception e) {
354                            throw processException(e);
355                    }
356                    finally {
357                            closeSession(session);
358                    }
359    
360                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
361    
362                    if (isNew || !UserNotificationEventModelImpl.COLUMN_BITMASK_ENABLED) {
363                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
364                    }
365    
366                    else {
367                            if ((userNotificationEventModelImpl.getColumnBitmask() &
368                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
369                                    Object[] args = new Object[] {
370                                                    userNotificationEventModelImpl.getOriginalUuid()
371                                            };
372    
373                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
374                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
375                                            args);
376    
377                                    args = new Object[] { userNotificationEventModelImpl.getUuid() };
378    
379                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
380                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
381                                            args);
382                            }
383    
384                            if ((userNotificationEventModelImpl.getColumnBitmask() &
385                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
386                                    Object[] args = new Object[] {
387                                                    Long.valueOf(userNotificationEventModelImpl.getOriginalUserId())
388                                            };
389    
390                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
391                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
392                                            args);
393    
394                                    args = new Object[] {
395                                                    Long.valueOf(userNotificationEventModelImpl.getUserId())
396                                            };
397    
398                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
399                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
400                                            args);
401                            }
402    
403                            if ((userNotificationEventModelImpl.getColumnBitmask() &
404                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A.getColumnBitmask()) != 0) {
405                                    Object[] args = new Object[] {
406                                                    Long.valueOf(userNotificationEventModelImpl.getOriginalUserId()),
407                                                    Boolean.valueOf(userNotificationEventModelImpl.getOriginalArchived())
408                                            };
409    
410                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_A, args);
411                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A,
412                                            args);
413    
414                                    args = new Object[] {
415                                                    Long.valueOf(userNotificationEventModelImpl.getUserId()),
416                                                    Boolean.valueOf(userNotificationEventModelImpl.getArchived())
417                                            };
418    
419                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_A, args);
420                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A,
421                                            args);
422                            }
423                    }
424    
425                    EntityCacheUtil.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
426                            UserNotificationEventImpl.class,
427                            userNotificationEvent.getPrimaryKey(), userNotificationEvent);
428    
429                    return userNotificationEvent;
430            }
431    
432            protected UserNotificationEvent toUnwrappedModel(
433                    UserNotificationEvent userNotificationEvent) {
434                    if (userNotificationEvent instanceof UserNotificationEventImpl) {
435                            return userNotificationEvent;
436                    }
437    
438                    UserNotificationEventImpl userNotificationEventImpl = new UserNotificationEventImpl();
439    
440                    userNotificationEventImpl.setNew(userNotificationEvent.isNew());
441                    userNotificationEventImpl.setPrimaryKey(userNotificationEvent.getPrimaryKey());
442    
443                    userNotificationEventImpl.setUuid(userNotificationEvent.getUuid());
444                    userNotificationEventImpl.setUserNotificationEventId(userNotificationEvent.getUserNotificationEventId());
445                    userNotificationEventImpl.setCompanyId(userNotificationEvent.getCompanyId());
446                    userNotificationEventImpl.setUserId(userNotificationEvent.getUserId());
447                    userNotificationEventImpl.setType(userNotificationEvent.getType());
448                    userNotificationEventImpl.setTimestamp(userNotificationEvent.getTimestamp());
449                    userNotificationEventImpl.setDeliverBy(userNotificationEvent.getDeliverBy());
450                    userNotificationEventImpl.setPayload(userNotificationEvent.getPayload());
451                    userNotificationEventImpl.setArchived(userNotificationEvent.isArchived());
452    
453                    return userNotificationEventImpl;
454            }
455    
456            /**
457             * Returns the user notification event with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
458             *
459             * @param primaryKey the primary key of the user notification event
460             * @return the user notification event
461             * @throws com.liferay.portal.NoSuchModelException if a user notification event with the primary key could not be found
462             * @throws SystemException if a system exception occurred
463             */
464            @Override
465            public UserNotificationEvent findByPrimaryKey(Serializable primaryKey)
466                    throws NoSuchModelException, SystemException {
467                    return findByPrimaryKey(((Long)primaryKey).longValue());
468            }
469    
470            /**
471             * Returns the user notification event with the primary key or throws a {@link com.liferay.portal.NoSuchUserNotificationEventException} if it could not be found.
472             *
473             * @param userNotificationEventId the primary key of the user notification event
474             * @return the user notification event
475             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
476             * @throws SystemException if a system exception occurred
477             */
478            public UserNotificationEvent findByPrimaryKey(long userNotificationEventId)
479                    throws NoSuchUserNotificationEventException, SystemException {
480                    UserNotificationEvent userNotificationEvent = fetchByPrimaryKey(userNotificationEventId);
481    
482                    if (userNotificationEvent == null) {
483                            if (_log.isWarnEnabled()) {
484                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
485                                            userNotificationEventId);
486                            }
487    
488                            throw new NoSuchUserNotificationEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
489                                    userNotificationEventId);
490                    }
491    
492                    return userNotificationEvent;
493            }
494    
495            /**
496             * Returns the user notification event with the primary key or returns <code>null</code> if it could not be found.
497             *
498             * @param primaryKey the primary key of the user notification event
499             * @return the user notification event, or <code>null</code> if a user notification event with the primary key could not be found
500             * @throws SystemException if a system exception occurred
501             */
502            @Override
503            public UserNotificationEvent fetchByPrimaryKey(Serializable primaryKey)
504                    throws SystemException {
505                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
506            }
507    
508            /**
509             * Returns the user notification event with the primary key or returns <code>null</code> if it could not be found.
510             *
511             * @param userNotificationEventId the primary key of the user notification event
512             * @return the user notification event, or <code>null</code> if a user notification event with the primary key could not be found
513             * @throws SystemException if a system exception occurred
514             */
515            public UserNotificationEvent fetchByPrimaryKey(long userNotificationEventId)
516                    throws SystemException {
517                    UserNotificationEvent userNotificationEvent = (UserNotificationEvent)EntityCacheUtil.getResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
518                                    UserNotificationEventImpl.class, userNotificationEventId);
519    
520                    if (userNotificationEvent == _nullUserNotificationEvent) {
521                            return null;
522                    }
523    
524                    if (userNotificationEvent == null) {
525                            Session session = null;
526    
527                            boolean hasException = false;
528    
529                            try {
530                                    session = openSession();
531    
532                                    userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
533                                                    Long.valueOf(userNotificationEventId));
534                            }
535                            catch (Exception e) {
536                                    hasException = true;
537    
538                                    throw processException(e);
539                            }
540                            finally {
541                                    if (userNotificationEvent != null) {
542                                            cacheResult(userNotificationEvent);
543                                    }
544                                    else if (!hasException) {
545                                            EntityCacheUtil.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
546                                                    UserNotificationEventImpl.class,
547                                                    userNotificationEventId, _nullUserNotificationEvent);
548                                    }
549    
550                                    closeSession(session);
551                            }
552                    }
553    
554                    return userNotificationEvent;
555            }
556    
557            /**
558             * Returns all the user notification events where uuid = &#63;.
559             *
560             * @param uuid the uuid
561             * @return the matching user notification events
562             * @throws SystemException if a system exception occurred
563             */
564            public List<UserNotificationEvent> findByUuid(String uuid)
565                    throws SystemException {
566                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
567            }
568    
569            /**
570             * Returns a range of all the user notification events where uuid = &#63;.
571             *
572             * <p>
573             * 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.
574             * </p>
575             *
576             * @param uuid the uuid
577             * @param start the lower bound of the range of user notification events
578             * @param end the upper bound of the range of user notification events (not inclusive)
579             * @return the range of matching user notification events
580             * @throws SystemException if a system exception occurred
581             */
582            public List<UserNotificationEvent> findByUuid(String uuid, int start,
583                    int end) throws SystemException {
584                    return findByUuid(uuid, start, end, null);
585            }
586    
587            /**
588             * Returns an ordered range of all the user notification events where uuid = &#63;.
589             *
590             * <p>
591             * 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.
592             * </p>
593             *
594             * @param uuid the uuid
595             * @param start the lower bound of the range of user notification events
596             * @param end the upper bound of the range of user notification events (not inclusive)
597             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
598             * @return the ordered range of matching user notification events
599             * @throws SystemException if a system exception occurred
600             */
601            public List<UserNotificationEvent> findByUuid(String uuid, int start,
602                    int end, OrderByComparator orderByComparator) throws SystemException {
603                    FinderPath finderPath = null;
604                    Object[] finderArgs = null;
605    
606                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
607                                    (orderByComparator == null)) {
608                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
609                            finderArgs = new Object[] { uuid };
610                    }
611                    else {
612                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
613                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
614                    }
615    
616                    List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
617                                    finderArgs, this);
618    
619                    if ((list != null) && !list.isEmpty()) {
620                            for (UserNotificationEvent userNotificationEvent : list) {
621                                    if (!Validator.equals(uuid, userNotificationEvent.getUuid())) {
622                                            list = null;
623    
624                                            break;
625                                    }
626                            }
627                    }
628    
629                    if (list == null) {
630                            StringBundler query = null;
631    
632                            if (orderByComparator != null) {
633                                    query = new StringBundler(3 +
634                                                    (orderByComparator.getOrderByFields().length * 3));
635                            }
636                            else {
637                                    query = new StringBundler(3);
638                            }
639    
640                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
641    
642                            if (uuid == null) {
643                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
644                            }
645                            else {
646                                    if (uuid.equals(StringPool.BLANK)) {
647                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
648                                    }
649                                    else {
650                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
651                                    }
652                            }
653    
654                            if (orderByComparator != null) {
655                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
656                                            orderByComparator);
657                            }
658    
659                            else {
660                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
661                            }
662    
663                            String sql = query.toString();
664    
665                            Session session = null;
666    
667                            try {
668                                    session = openSession();
669    
670                                    Query q = session.createQuery(sql);
671    
672                                    QueryPos qPos = QueryPos.getInstance(q);
673    
674                                    if (uuid != null) {
675                                            qPos.add(uuid);
676                                    }
677    
678                                    list = (List<UserNotificationEvent>)QueryUtil.list(q,
679                                                    getDialect(), start, end);
680                            }
681                            catch (Exception e) {
682                                    throw processException(e);
683                            }
684                            finally {
685                                    if (list == null) {
686                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
687                                    }
688                                    else {
689                                            cacheResult(list);
690    
691                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
692                                    }
693    
694                                    closeSession(session);
695                            }
696                    }
697    
698                    return list;
699            }
700    
701            /**
702             * Returns the first user notification event in the ordered set where uuid = &#63;.
703             *
704             * @param uuid the uuid
705             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
706             * @return the first matching user notification event
707             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a matching user notification event could not be found
708             * @throws SystemException if a system exception occurred
709             */
710            public UserNotificationEvent findByUuid_First(String uuid,
711                    OrderByComparator orderByComparator)
712                    throws NoSuchUserNotificationEventException, SystemException {
713                    UserNotificationEvent userNotificationEvent = fetchByUuid_First(uuid,
714                                    orderByComparator);
715    
716                    if (userNotificationEvent != null) {
717                            return userNotificationEvent;
718                    }
719    
720                    StringBundler msg = new StringBundler(4);
721    
722                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
723    
724                    msg.append("uuid=");
725                    msg.append(uuid);
726    
727                    msg.append(StringPool.CLOSE_CURLY_BRACE);
728    
729                    throw new NoSuchUserNotificationEventException(msg.toString());
730            }
731    
732            /**
733             * Returns the first user notification event in the ordered set where uuid = &#63;.
734             *
735             * @param uuid the uuid
736             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
737             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
738             * @throws SystemException if a system exception occurred
739             */
740            public UserNotificationEvent fetchByUuid_First(String uuid,
741                    OrderByComparator orderByComparator) throws SystemException {
742                    List<UserNotificationEvent> list = findByUuid(uuid, 0, 1,
743                                    orderByComparator);
744    
745                    if (!list.isEmpty()) {
746                            return list.get(0);
747                    }
748    
749                    return null;
750            }
751    
752            /**
753             * Returns the last user notification event in the ordered set where uuid = &#63;.
754             *
755             * @param uuid the uuid
756             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
757             * @return the last matching user notification event
758             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a matching user notification event could not be found
759             * @throws SystemException if a system exception occurred
760             */
761            public UserNotificationEvent findByUuid_Last(String uuid,
762                    OrderByComparator orderByComparator)
763                    throws NoSuchUserNotificationEventException, SystemException {
764                    UserNotificationEvent userNotificationEvent = fetchByUuid_Last(uuid,
765                                    orderByComparator);
766    
767                    if (userNotificationEvent != null) {
768                            return userNotificationEvent;
769                    }
770    
771                    StringBundler msg = new StringBundler(4);
772    
773                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
774    
775                    msg.append("uuid=");
776                    msg.append(uuid);
777    
778                    msg.append(StringPool.CLOSE_CURLY_BRACE);
779    
780                    throw new NoSuchUserNotificationEventException(msg.toString());
781            }
782    
783            /**
784             * Returns the last user notification event in the ordered set where uuid = &#63;.
785             *
786             * @param uuid the uuid
787             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
788             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
789             * @throws SystemException if a system exception occurred
790             */
791            public UserNotificationEvent fetchByUuid_Last(String uuid,
792                    OrderByComparator orderByComparator) throws SystemException {
793                    int count = countByUuid(uuid);
794    
795                    List<UserNotificationEvent> list = findByUuid(uuid, count - 1, count,
796                                    orderByComparator);
797    
798                    if (!list.isEmpty()) {
799                            return list.get(0);
800                    }
801    
802                    return null;
803            }
804    
805            /**
806             * Returns the user notification events before and after the current user notification event in the ordered set where uuid = &#63;.
807             *
808             * @param userNotificationEventId the primary key of the current user notification event
809             * @param uuid the uuid
810             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
811             * @return the previous, current, and next user notification event
812             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
813             * @throws SystemException if a system exception occurred
814             */
815            public UserNotificationEvent[] findByUuid_PrevAndNext(
816                    long userNotificationEventId, String uuid,
817                    OrderByComparator orderByComparator)
818                    throws NoSuchUserNotificationEventException, SystemException {
819                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
820    
821                    Session session = null;
822    
823                    try {
824                            session = openSession();
825    
826                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
827    
828                            array[0] = getByUuid_PrevAndNext(session, userNotificationEvent,
829                                            uuid, orderByComparator, true);
830    
831                            array[1] = userNotificationEvent;
832    
833                            array[2] = getByUuid_PrevAndNext(session, userNotificationEvent,
834                                            uuid, orderByComparator, false);
835    
836                            return array;
837                    }
838                    catch (Exception e) {
839                            throw processException(e);
840                    }
841                    finally {
842                            closeSession(session);
843                    }
844            }
845    
846            protected UserNotificationEvent getByUuid_PrevAndNext(Session session,
847                    UserNotificationEvent userNotificationEvent, String uuid,
848                    OrderByComparator orderByComparator, boolean previous) {
849                    StringBundler query = null;
850    
851                    if (orderByComparator != null) {
852                            query = new StringBundler(6 +
853                                            (orderByComparator.getOrderByFields().length * 6));
854                    }
855                    else {
856                            query = new StringBundler(3);
857                    }
858    
859                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
860    
861                    if (uuid == null) {
862                            query.append(_FINDER_COLUMN_UUID_UUID_1);
863                    }
864                    else {
865                            if (uuid.equals(StringPool.BLANK)) {
866                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
867                            }
868                            else {
869                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
870                            }
871                    }
872    
873                    if (orderByComparator != null) {
874                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
875    
876                            if (orderByConditionFields.length > 0) {
877                                    query.append(WHERE_AND);
878                            }
879    
880                            for (int i = 0; i < orderByConditionFields.length; i++) {
881                                    query.append(_ORDER_BY_ENTITY_ALIAS);
882                                    query.append(orderByConditionFields[i]);
883    
884                                    if ((i + 1) < orderByConditionFields.length) {
885                                            if (orderByComparator.isAscending() ^ previous) {
886                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
887                                            }
888                                            else {
889                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
890                                            }
891                                    }
892                                    else {
893                                            if (orderByComparator.isAscending() ^ previous) {
894                                                    query.append(WHERE_GREATER_THAN);
895                                            }
896                                            else {
897                                                    query.append(WHERE_LESSER_THAN);
898                                            }
899                                    }
900                            }
901    
902                            query.append(ORDER_BY_CLAUSE);
903    
904                            String[] orderByFields = orderByComparator.getOrderByFields();
905    
906                            for (int i = 0; i < orderByFields.length; i++) {
907                                    query.append(_ORDER_BY_ENTITY_ALIAS);
908                                    query.append(orderByFields[i]);
909    
910                                    if ((i + 1) < orderByFields.length) {
911                                            if (orderByComparator.isAscending() ^ previous) {
912                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
913                                            }
914                                            else {
915                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
916                                            }
917                                    }
918                                    else {
919                                            if (orderByComparator.isAscending() ^ previous) {
920                                                    query.append(ORDER_BY_ASC);
921                                            }
922                                            else {
923                                                    query.append(ORDER_BY_DESC);
924                                            }
925                                    }
926                            }
927                    }
928    
929                    else {
930                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
931                    }
932    
933                    String sql = query.toString();
934    
935                    Query q = session.createQuery(sql);
936    
937                    q.setFirstResult(0);
938                    q.setMaxResults(2);
939    
940                    QueryPos qPos = QueryPos.getInstance(q);
941    
942                    if (uuid != null) {
943                            qPos.add(uuid);
944                    }
945    
946                    if (orderByComparator != null) {
947                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
948    
949                            for (Object value : values) {
950                                    qPos.add(value);
951                            }
952                    }
953    
954                    List<UserNotificationEvent> list = q.list();
955    
956                    if (list.size() == 2) {
957                            return list.get(1);
958                    }
959                    else {
960                            return null;
961                    }
962            }
963    
964            /**
965             * Returns all the user notification events where userId = &#63;.
966             *
967             * @param userId the user ID
968             * @return the matching user notification events
969             * @throws SystemException if a system exception occurred
970             */
971            public List<UserNotificationEvent> findByUserId(long userId)
972                    throws SystemException {
973                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
974            }
975    
976            /**
977             * Returns a range of all the user notification events where userId = &#63;.
978             *
979             * <p>
980             * 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.
981             * </p>
982             *
983             * @param userId the user ID
984             * @param start the lower bound of the range of user notification events
985             * @param end the upper bound of the range of user notification events (not inclusive)
986             * @return the range of matching user notification events
987             * @throws SystemException if a system exception occurred
988             */
989            public List<UserNotificationEvent> findByUserId(long userId, int start,
990                    int end) throws SystemException {
991                    return findByUserId(userId, start, end, null);
992            }
993    
994            /**
995             * Returns an ordered range of all the user notification events where userId = &#63;.
996             *
997             * <p>
998             * 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.
999             * </p>
1000             *
1001             * @param userId the user ID
1002             * @param start the lower bound of the range of user notification events
1003             * @param end the upper bound of the range of user notification events (not inclusive)
1004             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1005             * @return the ordered range of matching user notification events
1006             * @throws SystemException if a system exception occurred
1007             */
1008            public List<UserNotificationEvent> findByUserId(long userId, int start,
1009                    int end, OrderByComparator orderByComparator) throws SystemException {
1010                    FinderPath finderPath = null;
1011                    Object[] finderArgs = null;
1012    
1013                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1014                                    (orderByComparator == null)) {
1015                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1016                            finderArgs = new Object[] { userId };
1017                    }
1018                    else {
1019                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1020                            finderArgs = new Object[] { userId, start, end, orderByComparator };
1021                    }
1022    
1023                    List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
1024                                    finderArgs, this);
1025    
1026                    if ((list != null) && !list.isEmpty()) {
1027                            for (UserNotificationEvent userNotificationEvent : list) {
1028                                    if ((userId != userNotificationEvent.getUserId())) {
1029                                            list = null;
1030    
1031                                            break;
1032                                    }
1033                            }
1034                    }
1035    
1036                    if (list == null) {
1037                            StringBundler query = null;
1038    
1039                            if (orderByComparator != null) {
1040                                    query = new StringBundler(3 +
1041                                                    (orderByComparator.getOrderByFields().length * 3));
1042                            }
1043                            else {
1044                                    query = new StringBundler(3);
1045                            }
1046    
1047                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1048    
1049                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1050    
1051                            if (orderByComparator != null) {
1052                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1053                                            orderByComparator);
1054                            }
1055    
1056                            else {
1057                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1058                            }
1059    
1060                            String sql = query.toString();
1061    
1062                            Session session = null;
1063    
1064                            try {
1065                                    session = openSession();
1066    
1067                                    Query q = session.createQuery(sql);
1068    
1069                                    QueryPos qPos = QueryPos.getInstance(q);
1070    
1071                                    qPos.add(userId);
1072    
1073                                    list = (List<UserNotificationEvent>)QueryUtil.list(q,
1074                                                    getDialect(), start, end);
1075                            }
1076                            catch (Exception e) {
1077                                    throw processException(e);
1078                            }
1079                            finally {
1080                                    if (list == null) {
1081                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1082                                    }
1083                                    else {
1084                                            cacheResult(list);
1085    
1086                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1087                                    }
1088    
1089                                    closeSession(session);
1090                            }
1091                    }
1092    
1093                    return list;
1094            }
1095    
1096            /**
1097             * Returns the first user notification event in the ordered set where userId = &#63;.
1098             *
1099             * @param userId the user ID
1100             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1101             * @return the first matching user notification event
1102             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a matching user notification event could not be found
1103             * @throws SystemException if a system exception occurred
1104             */
1105            public UserNotificationEvent findByUserId_First(long userId,
1106                    OrderByComparator orderByComparator)
1107                    throws NoSuchUserNotificationEventException, SystemException {
1108                    UserNotificationEvent userNotificationEvent = fetchByUserId_First(userId,
1109                                    orderByComparator);
1110    
1111                    if (userNotificationEvent != null) {
1112                            return userNotificationEvent;
1113                    }
1114    
1115                    StringBundler msg = new StringBundler(4);
1116    
1117                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1118    
1119                    msg.append("userId=");
1120                    msg.append(userId);
1121    
1122                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1123    
1124                    throw new NoSuchUserNotificationEventException(msg.toString());
1125            }
1126    
1127            /**
1128             * Returns the first user notification event in the ordered set where userId = &#63;.
1129             *
1130             * @param userId the user ID
1131             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1132             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
1133             * @throws SystemException if a system exception occurred
1134             */
1135            public UserNotificationEvent fetchByUserId_First(long userId,
1136                    OrderByComparator orderByComparator) throws SystemException {
1137                    List<UserNotificationEvent> list = findByUserId(userId, 0, 1,
1138                                    orderByComparator);
1139    
1140                    if (!list.isEmpty()) {
1141                            return list.get(0);
1142                    }
1143    
1144                    return null;
1145            }
1146    
1147            /**
1148             * Returns the last user notification event in the ordered set where userId = &#63;.
1149             *
1150             * @param userId the user ID
1151             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1152             * @return the last matching user notification event
1153             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a matching user notification event could not be found
1154             * @throws SystemException if a system exception occurred
1155             */
1156            public UserNotificationEvent findByUserId_Last(long userId,
1157                    OrderByComparator orderByComparator)
1158                    throws NoSuchUserNotificationEventException, SystemException {
1159                    UserNotificationEvent userNotificationEvent = fetchByUserId_Last(userId,
1160                                    orderByComparator);
1161    
1162                    if (userNotificationEvent != null) {
1163                            return userNotificationEvent;
1164                    }
1165    
1166                    StringBundler msg = new StringBundler(4);
1167    
1168                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1169    
1170                    msg.append("userId=");
1171                    msg.append(userId);
1172    
1173                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1174    
1175                    throw new NoSuchUserNotificationEventException(msg.toString());
1176            }
1177    
1178            /**
1179             * Returns the last user notification event in the ordered set where userId = &#63;.
1180             *
1181             * @param userId the user ID
1182             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1183             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
1184             * @throws SystemException if a system exception occurred
1185             */
1186            public UserNotificationEvent fetchByUserId_Last(long userId,
1187                    OrderByComparator orderByComparator) throws SystemException {
1188                    int count = countByUserId(userId);
1189    
1190                    List<UserNotificationEvent> list = findByUserId(userId, count - 1,
1191                                    count, orderByComparator);
1192    
1193                    if (!list.isEmpty()) {
1194                            return list.get(0);
1195                    }
1196    
1197                    return null;
1198            }
1199    
1200            /**
1201             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63;.
1202             *
1203             * @param userNotificationEventId the primary key of the current user notification event
1204             * @param userId the user ID
1205             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1206             * @return the previous, current, and next user notification event
1207             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
1208             * @throws SystemException if a system exception occurred
1209             */
1210            public UserNotificationEvent[] findByUserId_PrevAndNext(
1211                    long userNotificationEventId, long userId,
1212                    OrderByComparator orderByComparator)
1213                    throws NoSuchUserNotificationEventException, SystemException {
1214                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
1215    
1216                    Session session = null;
1217    
1218                    try {
1219                            session = openSession();
1220    
1221                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
1222    
1223                            array[0] = getByUserId_PrevAndNext(session, userNotificationEvent,
1224                                            userId, orderByComparator, true);
1225    
1226                            array[1] = userNotificationEvent;
1227    
1228                            array[2] = getByUserId_PrevAndNext(session, userNotificationEvent,
1229                                            userId, orderByComparator, false);
1230    
1231                            return array;
1232                    }
1233                    catch (Exception e) {
1234                            throw processException(e);
1235                    }
1236                    finally {
1237                            closeSession(session);
1238                    }
1239            }
1240    
1241            protected UserNotificationEvent getByUserId_PrevAndNext(Session session,
1242                    UserNotificationEvent userNotificationEvent, long userId,
1243                    OrderByComparator orderByComparator, boolean previous) {
1244                    StringBundler query = null;
1245    
1246                    if (orderByComparator != null) {
1247                            query = new StringBundler(6 +
1248                                            (orderByComparator.getOrderByFields().length * 6));
1249                    }
1250                    else {
1251                            query = new StringBundler(3);
1252                    }
1253    
1254                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1255    
1256                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1257    
1258                    if (orderByComparator != null) {
1259                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1260    
1261                            if (orderByConditionFields.length > 0) {
1262                                    query.append(WHERE_AND);
1263                            }
1264    
1265                            for (int i = 0; i < orderByConditionFields.length; i++) {
1266                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1267                                    query.append(orderByConditionFields[i]);
1268    
1269                                    if ((i + 1) < orderByConditionFields.length) {
1270                                            if (orderByComparator.isAscending() ^ previous) {
1271                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1272                                            }
1273                                            else {
1274                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1275                                            }
1276                                    }
1277                                    else {
1278                                            if (orderByComparator.isAscending() ^ previous) {
1279                                                    query.append(WHERE_GREATER_THAN);
1280                                            }
1281                                            else {
1282                                                    query.append(WHERE_LESSER_THAN);
1283                                            }
1284                                    }
1285                            }
1286    
1287                            query.append(ORDER_BY_CLAUSE);
1288    
1289                            String[] orderByFields = orderByComparator.getOrderByFields();
1290    
1291                            for (int i = 0; i < orderByFields.length; i++) {
1292                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1293                                    query.append(orderByFields[i]);
1294    
1295                                    if ((i + 1) < orderByFields.length) {
1296                                            if (orderByComparator.isAscending() ^ previous) {
1297                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1298                                            }
1299                                            else {
1300                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1301                                            }
1302                                    }
1303                                    else {
1304                                            if (orderByComparator.isAscending() ^ previous) {
1305                                                    query.append(ORDER_BY_ASC);
1306                                            }
1307                                            else {
1308                                                    query.append(ORDER_BY_DESC);
1309                                            }
1310                                    }
1311                            }
1312                    }
1313    
1314                    else {
1315                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1316                    }
1317    
1318                    String sql = query.toString();
1319    
1320                    Query q = session.createQuery(sql);
1321    
1322                    q.setFirstResult(0);
1323                    q.setMaxResults(2);
1324    
1325                    QueryPos qPos = QueryPos.getInstance(q);
1326    
1327                    qPos.add(userId);
1328    
1329                    if (orderByComparator != null) {
1330                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
1331    
1332                            for (Object value : values) {
1333                                    qPos.add(value);
1334                            }
1335                    }
1336    
1337                    List<UserNotificationEvent> list = q.list();
1338    
1339                    if (list.size() == 2) {
1340                            return list.get(1);
1341                    }
1342                    else {
1343                            return null;
1344                    }
1345            }
1346    
1347            /**
1348             * Returns all the user notification events where userId = &#63; and archived = &#63;.
1349             *
1350             * @param userId the user ID
1351             * @param archived the archived
1352             * @return the matching user notification events
1353             * @throws SystemException if a system exception occurred
1354             */
1355            public List<UserNotificationEvent> findByU_A(long userId, boolean archived)
1356                    throws SystemException {
1357                    return findByU_A(userId, archived, QueryUtil.ALL_POS,
1358                            QueryUtil.ALL_POS, null);
1359            }
1360    
1361            /**
1362             * Returns a range of all the user notification events where userId = &#63; and archived = &#63;.
1363             *
1364             * <p>
1365             * 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.
1366             * </p>
1367             *
1368             * @param userId the user ID
1369             * @param archived the archived
1370             * @param start the lower bound of the range of user notification events
1371             * @param end the upper bound of the range of user notification events (not inclusive)
1372             * @return the range of matching user notification events
1373             * @throws SystemException if a system exception occurred
1374             */
1375            public List<UserNotificationEvent> findByU_A(long userId, boolean archived,
1376                    int start, int end) throws SystemException {
1377                    return findByU_A(userId, archived, start, end, null);
1378            }
1379    
1380            /**
1381             * Returns an ordered range of all the user notification events where userId = &#63; and archived = &#63;.
1382             *
1383             * <p>
1384             * 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.
1385             * </p>
1386             *
1387             * @param userId the user ID
1388             * @param archived the archived
1389             * @param start the lower bound of the range of user notification events
1390             * @param end the upper bound of the range of user notification events (not inclusive)
1391             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1392             * @return the ordered range of matching user notification events
1393             * @throws SystemException if a system exception occurred
1394             */
1395            public List<UserNotificationEvent> findByU_A(long userId, boolean archived,
1396                    int start, int end, OrderByComparator orderByComparator)
1397                    throws SystemException {
1398                    FinderPath finderPath = null;
1399                    Object[] finderArgs = null;
1400    
1401                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1402                                    (orderByComparator == null)) {
1403                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A;
1404                            finderArgs = new Object[] { userId, archived };
1405                    }
1406                    else {
1407                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_A;
1408                            finderArgs = new Object[] {
1409                                            userId, archived,
1410                                            
1411                                            start, end, orderByComparator
1412                                    };
1413                    }
1414    
1415                    List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
1416                                    finderArgs, this);
1417    
1418                    if ((list != null) && !list.isEmpty()) {
1419                            for (UserNotificationEvent userNotificationEvent : list) {
1420                                    if ((userId != userNotificationEvent.getUserId()) ||
1421                                                    (archived != userNotificationEvent.getArchived())) {
1422                                            list = null;
1423    
1424                                            break;
1425                                    }
1426                            }
1427                    }
1428    
1429                    if (list == null) {
1430                            StringBundler query = null;
1431    
1432                            if (orderByComparator != null) {
1433                                    query = new StringBundler(4 +
1434                                                    (orderByComparator.getOrderByFields().length * 3));
1435                            }
1436                            else {
1437                                    query = new StringBundler(4);
1438                            }
1439    
1440                            query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1441    
1442                            query.append(_FINDER_COLUMN_U_A_USERID_2);
1443    
1444                            query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
1445    
1446                            if (orderByComparator != null) {
1447                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1448                                            orderByComparator);
1449                            }
1450    
1451                            else {
1452                                    query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1453                            }
1454    
1455                            String sql = query.toString();
1456    
1457                            Session session = null;
1458    
1459                            try {
1460                                    session = openSession();
1461    
1462                                    Query q = session.createQuery(sql);
1463    
1464                                    QueryPos qPos = QueryPos.getInstance(q);
1465    
1466                                    qPos.add(userId);
1467    
1468                                    qPos.add(archived);
1469    
1470                                    list = (List<UserNotificationEvent>)QueryUtil.list(q,
1471                                                    getDialect(), start, end);
1472                            }
1473                            catch (Exception e) {
1474                                    throw processException(e);
1475                            }
1476                            finally {
1477                                    if (list == null) {
1478                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1479                                    }
1480                                    else {
1481                                            cacheResult(list);
1482    
1483                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1484                                    }
1485    
1486                                    closeSession(session);
1487                            }
1488                    }
1489    
1490                    return list;
1491            }
1492    
1493            /**
1494             * Returns the first user notification event in the ordered set where userId = &#63; and archived = &#63;.
1495             *
1496             * @param userId the user ID
1497             * @param archived the archived
1498             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1499             * @return the first matching user notification event
1500             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a matching user notification event could not be found
1501             * @throws SystemException if a system exception occurred
1502             */
1503            public UserNotificationEvent findByU_A_First(long userId, boolean archived,
1504                    OrderByComparator orderByComparator)
1505                    throws NoSuchUserNotificationEventException, SystemException {
1506                    UserNotificationEvent userNotificationEvent = fetchByU_A_First(userId,
1507                                    archived, orderByComparator);
1508    
1509                    if (userNotificationEvent != null) {
1510                            return userNotificationEvent;
1511                    }
1512    
1513                    StringBundler msg = new StringBundler(6);
1514    
1515                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1516    
1517                    msg.append("userId=");
1518                    msg.append(userId);
1519    
1520                    msg.append(", archived=");
1521                    msg.append(archived);
1522    
1523                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1524    
1525                    throw new NoSuchUserNotificationEventException(msg.toString());
1526            }
1527    
1528            /**
1529             * Returns the first user notification event in the ordered set where userId = &#63; and archived = &#63;.
1530             *
1531             * @param userId the user ID
1532             * @param archived the archived
1533             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1534             * @return the first matching user notification event, or <code>null</code> if a matching user notification event could not be found
1535             * @throws SystemException if a system exception occurred
1536             */
1537            public UserNotificationEvent fetchByU_A_First(long userId,
1538                    boolean archived, OrderByComparator orderByComparator)
1539                    throws SystemException {
1540                    List<UserNotificationEvent> list = findByU_A(userId, archived, 0, 1,
1541                                    orderByComparator);
1542    
1543                    if (!list.isEmpty()) {
1544                            return list.get(0);
1545                    }
1546    
1547                    return null;
1548            }
1549    
1550            /**
1551             * Returns the last user notification event in the ordered set where userId = &#63; and archived = &#63;.
1552             *
1553             * @param userId the user ID
1554             * @param archived the archived
1555             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1556             * @return the last matching user notification event
1557             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a matching user notification event could not be found
1558             * @throws SystemException if a system exception occurred
1559             */
1560            public UserNotificationEvent findByU_A_Last(long userId, boolean archived,
1561                    OrderByComparator orderByComparator)
1562                    throws NoSuchUserNotificationEventException, SystemException {
1563                    UserNotificationEvent userNotificationEvent = fetchByU_A_Last(userId,
1564                                    archived, orderByComparator);
1565    
1566                    if (userNotificationEvent != null) {
1567                            return userNotificationEvent;
1568                    }
1569    
1570                    StringBundler msg = new StringBundler(6);
1571    
1572                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1573    
1574                    msg.append("userId=");
1575                    msg.append(userId);
1576    
1577                    msg.append(", archived=");
1578                    msg.append(archived);
1579    
1580                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1581    
1582                    throw new NoSuchUserNotificationEventException(msg.toString());
1583            }
1584    
1585            /**
1586             * Returns the last user notification event in the ordered set where userId = &#63; and archived = &#63;.
1587             *
1588             * @param userId the user ID
1589             * @param archived the archived
1590             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1591             * @return the last matching user notification event, or <code>null</code> if a matching user notification event could not be found
1592             * @throws SystemException if a system exception occurred
1593             */
1594            public UserNotificationEvent fetchByU_A_Last(long userId, boolean archived,
1595                    OrderByComparator orderByComparator) throws SystemException {
1596                    int count = countByU_A(userId, archived);
1597    
1598                    List<UserNotificationEvent> list = findByU_A(userId, archived,
1599                                    count - 1, count, orderByComparator);
1600    
1601                    if (!list.isEmpty()) {
1602                            return list.get(0);
1603                    }
1604    
1605                    return null;
1606            }
1607    
1608            /**
1609             * Returns the user notification events before and after the current user notification event in the ordered set where userId = &#63; and archived = &#63;.
1610             *
1611             * @param userNotificationEventId the primary key of the current user notification event
1612             * @param userId the user ID
1613             * @param archived the archived
1614             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1615             * @return the previous, current, and next user notification event
1616             * @throws com.liferay.portal.NoSuchUserNotificationEventException if a user notification event with the primary key could not be found
1617             * @throws SystemException if a system exception occurred
1618             */
1619            public UserNotificationEvent[] findByU_A_PrevAndNext(
1620                    long userNotificationEventId, long userId, boolean archived,
1621                    OrderByComparator orderByComparator)
1622                    throws NoSuchUserNotificationEventException, SystemException {
1623                    UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
1624    
1625                    Session session = null;
1626    
1627                    try {
1628                            session = openSession();
1629    
1630                            UserNotificationEvent[] array = new UserNotificationEventImpl[3];
1631    
1632                            array[0] = getByU_A_PrevAndNext(session, userNotificationEvent,
1633                                            userId, archived, orderByComparator, true);
1634    
1635                            array[1] = userNotificationEvent;
1636    
1637                            array[2] = getByU_A_PrevAndNext(session, userNotificationEvent,
1638                                            userId, archived, orderByComparator, false);
1639    
1640                            return array;
1641                    }
1642                    catch (Exception e) {
1643                            throw processException(e);
1644                    }
1645                    finally {
1646                            closeSession(session);
1647                    }
1648            }
1649    
1650            protected UserNotificationEvent getByU_A_PrevAndNext(Session session,
1651                    UserNotificationEvent userNotificationEvent, long userId,
1652                    boolean archived, OrderByComparator orderByComparator, boolean previous) {
1653                    StringBundler query = null;
1654    
1655                    if (orderByComparator != null) {
1656                            query = new StringBundler(6 +
1657                                            (orderByComparator.getOrderByFields().length * 6));
1658                    }
1659                    else {
1660                            query = new StringBundler(3);
1661                    }
1662    
1663                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1664    
1665                    query.append(_FINDER_COLUMN_U_A_USERID_2);
1666    
1667                    query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
1668    
1669                    if (orderByComparator != null) {
1670                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1671    
1672                            if (orderByConditionFields.length > 0) {
1673                                    query.append(WHERE_AND);
1674                            }
1675    
1676                            for (int i = 0; i < orderByConditionFields.length; i++) {
1677                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1678                                    query.append(orderByConditionFields[i]);
1679    
1680                                    if ((i + 1) < orderByConditionFields.length) {
1681                                            if (orderByComparator.isAscending() ^ previous) {
1682                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1683                                            }
1684                                            else {
1685                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1686                                            }
1687                                    }
1688                                    else {
1689                                            if (orderByComparator.isAscending() ^ previous) {
1690                                                    query.append(WHERE_GREATER_THAN);
1691                                            }
1692                                            else {
1693                                                    query.append(WHERE_LESSER_THAN);
1694                                            }
1695                                    }
1696                            }
1697    
1698                            query.append(ORDER_BY_CLAUSE);
1699    
1700                            String[] orderByFields = orderByComparator.getOrderByFields();
1701    
1702                            for (int i = 0; i < orderByFields.length; i++) {
1703                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1704                                    query.append(orderByFields[i]);
1705    
1706                                    if ((i + 1) < orderByFields.length) {
1707                                            if (orderByComparator.isAscending() ^ previous) {
1708                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1709                                            }
1710                                            else {
1711                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1712                                            }
1713                                    }
1714                                    else {
1715                                            if (orderByComparator.isAscending() ^ previous) {
1716                                                    query.append(ORDER_BY_ASC);
1717                                            }
1718                                            else {
1719                                                    query.append(ORDER_BY_DESC);
1720                                            }
1721                                    }
1722                            }
1723                    }
1724    
1725                    else {
1726                            query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1727                    }
1728    
1729                    String sql = query.toString();
1730    
1731                    Query q = session.createQuery(sql);
1732    
1733                    q.setFirstResult(0);
1734                    q.setMaxResults(2);
1735    
1736                    QueryPos qPos = QueryPos.getInstance(q);
1737    
1738                    qPos.add(userId);
1739    
1740                    qPos.add(archived);
1741    
1742                    if (orderByComparator != null) {
1743                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
1744    
1745                            for (Object value : values) {
1746                                    qPos.add(value);
1747                            }
1748                    }
1749    
1750                    List<UserNotificationEvent> list = q.list();
1751    
1752                    if (list.size() == 2) {
1753                            return list.get(1);
1754                    }
1755                    else {
1756                            return null;
1757                    }
1758            }
1759    
1760            /**
1761             * Returns all the user notification events.
1762             *
1763             * @return the user notification events
1764             * @throws SystemException if a system exception occurred
1765             */
1766            public List<UserNotificationEvent> findAll() throws SystemException {
1767                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1768            }
1769    
1770            /**
1771             * Returns a range of all the user notification events.
1772             *
1773             * <p>
1774             * 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.
1775             * </p>
1776             *
1777             * @param start the lower bound of the range of user notification events
1778             * @param end the upper bound of the range of user notification events (not inclusive)
1779             * @return the range of user notification events
1780             * @throws SystemException if a system exception occurred
1781             */
1782            public List<UserNotificationEvent> findAll(int start, int end)
1783                    throws SystemException {
1784                    return findAll(start, end, null);
1785            }
1786    
1787            /**
1788             * Returns an ordered range of all the user notification events.
1789             *
1790             * <p>
1791             * 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.
1792             * </p>
1793             *
1794             * @param start the lower bound of the range of user notification events
1795             * @param end the upper bound of the range of user notification events (not inclusive)
1796             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1797             * @return the ordered range of user notification events
1798             * @throws SystemException if a system exception occurred
1799             */
1800            public List<UserNotificationEvent> findAll(int start, int end,
1801                    OrderByComparator orderByComparator) throws SystemException {
1802                    FinderPath finderPath = null;
1803                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1804    
1805                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1806                                    (orderByComparator == null)) {
1807                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1808                            finderArgs = FINDER_ARGS_EMPTY;
1809                    }
1810                    else {
1811                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1812                            finderArgs = new Object[] { start, end, orderByComparator };
1813                    }
1814    
1815                    List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
1816                                    finderArgs, this);
1817    
1818                    if (list == null) {
1819                            StringBundler query = null;
1820                            String sql = null;
1821    
1822                            if (orderByComparator != null) {
1823                                    query = new StringBundler(2 +
1824                                                    (orderByComparator.getOrderByFields().length * 3));
1825    
1826                                    query.append(_SQL_SELECT_USERNOTIFICATIONEVENT);
1827    
1828                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1829                                            orderByComparator);
1830    
1831                                    sql = query.toString();
1832                            }
1833                            else {
1834                                    sql = _SQL_SELECT_USERNOTIFICATIONEVENT.concat(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1835                            }
1836    
1837                            Session session = null;
1838    
1839                            try {
1840                                    session = openSession();
1841    
1842                                    Query q = session.createQuery(sql);
1843    
1844                                    if (orderByComparator == null) {
1845                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
1846                                                            getDialect(), start, end, false);
1847    
1848                                            Collections.sort(list);
1849                                    }
1850                                    else {
1851                                            list = (List<UserNotificationEvent>)QueryUtil.list(q,
1852                                                            getDialect(), start, end);
1853                                    }
1854                            }
1855                            catch (Exception e) {
1856                                    throw processException(e);
1857                            }
1858                            finally {
1859                                    if (list == null) {
1860                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1861                                    }
1862                                    else {
1863                                            cacheResult(list);
1864    
1865                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1866                                    }
1867    
1868                                    closeSession(session);
1869                            }
1870                    }
1871    
1872                    return list;
1873            }
1874    
1875            /**
1876             * Removes all the user notification events where uuid = &#63; from the database.
1877             *
1878             * @param uuid the uuid
1879             * @throws SystemException if a system exception occurred
1880             */
1881            public void removeByUuid(String uuid) throws SystemException {
1882                    for (UserNotificationEvent userNotificationEvent : findByUuid(uuid)) {
1883                            remove(userNotificationEvent);
1884                    }
1885            }
1886    
1887            /**
1888             * Removes all the user notification events where userId = &#63; from the database.
1889             *
1890             * @param userId the user ID
1891             * @throws SystemException if a system exception occurred
1892             */
1893            public void removeByUserId(long userId) throws SystemException {
1894                    for (UserNotificationEvent userNotificationEvent : findByUserId(userId)) {
1895                            remove(userNotificationEvent);
1896                    }
1897            }
1898    
1899            /**
1900             * Removes all the user notification events where userId = &#63; and archived = &#63; from the database.
1901             *
1902             * @param userId the user ID
1903             * @param archived the archived
1904             * @throws SystemException if a system exception occurred
1905             */
1906            public void removeByU_A(long userId, boolean archived)
1907                    throws SystemException {
1908                    for (UserNotificationEvent userNotificationEvent : findByU_A(userId,
1909                                    archived)) {
1910                            remove(userNotificationEvent);
1911                    }
1912            }
1913    
1914            /**
1915             * Removes all the user notification events from the database.
1916             *
1917             * @throws SystemException if a system exception occurred
1918             */
1919            public void removeAll() throws SystemException {
1920                    for (UserNotificationEvent userNotificationEvent : findAll()) {
1921                            remove(userNotificationEvent);
1922                    }
1923            }
1924    
1925            /**
1926             * Returns the number of user notification events where uuid = &#63;.
1927             *
1928             * @param uuid the uuid
1929             * @return the number of matching user notification events
1930             * @throws SystemException if a system exception occurred
1931             */
1932            public int countByUuid(String uuid) throws SystemException {
1933                    Object[] finderArgs = new Object[] { uuid };
1934    
1935                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1936                                    finderArgs, this);
1937    
1938                    if (count == null) {
1939                            StringBundler query = new StringBundler(2);
1940    
1941                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
1942    
1943                            if (uuid == null) {
1944                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1945                            }
1946                            else {
1947                                    if (uuid.equals(StringPool.BLANK)) {
1948                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1949                                    }
1950                                    else {
1951                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1952                                    }
1953                            }
1954    
1955                            String sql = query.toString();
1956    
1957                            Session session = null;
1958    
1959                            try {
1960                                    session = openSession();
1961    
1962                                    Query q = session.createQuery(sql);
1963    
1964                                    QueryPos qPos = QueryPos.getInstance(q);
1965    
1966                                    if (uuid != null) {
1967                                            qPos.add(uuid);
1968                                    }
1969    
1970                                    count = (Long)q.uniqueResult();
1971                            }
1972                            catch (Exception e) {
1973                                    throw processException(e);
1974                            }
1975                            finally {
1976                                    if (count == null) {
1977                                            count = Long.valueOf(0);
1978                                    }
1979    
1980                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1981                                            finderArgs, count);
1982    
1983                                    closeSession(session);
1984                            }
1985                    }
1986    
1987                    return count.intValue();
1988            }
1989    
1990            /**
1991             * Returns the number of user notification events where userId = &#63;.
1992             *
1993             * @param userId the user ID
1994             * @return the number of matching user notification events
1995             * @throws SystemException if a system exception occurred
1996             */
1997            public int countByUserId(long userId) throws SystemException {
1998                    Object[] finderArgs = new Object[] { userId };
1999    
2000                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2001                                    finderArgs, this);
2002    
2003                    if (count == null) {
2004                            StringBundler query = new StringBundler(2);
2005    
2006                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
2007    
2008                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2009    
2010                            String sql = query.toString();
2011    
2012                            Session session = null;
2013    
2014                            try {
2015                                    session = openSession();
2016    
2017                                    Query q = session.createQuery(sql);
2018    
2019                                    QueryPos qPos = QueryPos.getInstance(q);
2020    
2021                                    qPos.add(userId);
2022    
2023                                    count = (Long)q.uniqueResult();
2024                            }
2025                            catch (Exception e) {
2026                                    throw processException(e);
2027                            }
2028                            finally {
2029                                    if (count == null) {
2030                                            count = Long.valueOf(0);
2031                                    }
2032    
2033                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2034                                            finderArgs, count);
2035    
2036                                    closeSession(session);
2037                            }
2038                    }
2039    
2040                    return count.intValue();
2041            }
2042    
2043            /**
2044             * Returns the number of user notification events where userId = &#63; and archived = &#63;.
2045             *
2046             * @param userId the user ID
2047             * @param archived the archived
2048             * @return the number of matching user notification events
2049             * @throws SystemException if a system exception occurred
2050             */
2051            public int countByU_A(long userId, boolean archived)
2052                    throws SystemException {
2053                    Object[] finderArgs = new Object[] { userId, archived };
2054    
2055                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_A,
2056                                    finderArgs, this);
2057    
2058                    if (count == null) {
2059                            StringBundler query = new StringBundler(3);
2060    
2061                            query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
2062    
2063                            query.append(_FINDER_COLUMN_U_A_USERID_2);
2064    
2065                            query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
2066    
2067                            String sql = query.toString();
2068    
2069                            Session session = null;
2070    
2071                            try {
2072                                    session = openSession();
2073    
2074                                    Query q = session.createQuery(sql);
2075    
2076                                    QueryPos qPos = QueryPos.getInstance(q);
2077    
2078                                    qPos.add(userId);
2079    
2080                                    qPos.add(archived);
2081    
2082                                    count = (Long)q.uniqueResult();
2083                            }
2084                            catch (Exception e) {
2085                                    throw processException(e);
2086                            }
2087                            finally {
2088                                    if (count == null) {
2089                                            count = Long.valueOf(0);
2090                                    }
2091    
2092                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_A, finderArgs,
2093                                            count);
2094    
2095                                    closeSession(session);
2096                            }
2097                    }
2098    
2099                    return count.intValue();
2100            }
2101    
2102            /**
2103             * Returns the number of user notification events.
2104             *
2105             * @return the number of user notification events
2106             * @throws SystemException if a system exception occurred
2107             */
2108            public int countAll() throws SystemException {
2109                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2110                                    FINDER_ARGS_EMPTY, this);
2111    
2112                    if (count == null) {
2113                            Session session = null;
2114    
2115                            try {
2116                                    session = openSession();
2117    
2118                                    Query q = session.createQuery(_SQL_COUNT_USERNOTIFICATIONEVENT);
2119    
2120                                    count = (Long)q.uniqueResult();
2121                            }
2122                            catch (Exception e) {
2123                                    throw processException(e);
2124                            }
2125                            finally {
2126                                    if (count == null) {
2127                                            count = Long.valueOf(0);
2128                                    }
2129    
2130                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2131                                            FINDER_ARGS_EMPTY, count);
2132    
2133                                    closeSession(session);
2134                            }
2135                    }
2136    
2137                    return count.intValue();
2138            }
2139    
2140            /**
2141             * Initializes the user notification event persistence.
2142             */
2143            public void afterPropertiesSet() {
2144                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2145                                            com.liferay.portal.util.PropsUtil.get(
2146                                                    "value.object.listener.com.liferay.portal.model.UserNotificationEvent")));
2147    
2148                    if (listenerClassNames.length > 0) {
2149                            try {
2150                                    List<ModelListener<UserNotificationEvent>> listenersList = new ArrayList<ModelListener<UserNotificationEvent>>();
2151    
2152                                    for (String listenerClassName : listenerClassNames) {
2153                                            Class<?> clazz = getClass();
2154    
2155                                            listenersList.add((ModelListener<UserNotificationEvent>)InstanceFactory.newInstance(
2156                                                            clazz.getClassLoader(), listenerClassName));
2157                                    }
2158    
2159                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2160                            }
2161                            catch (Exception e) {
2162                                    _log.error(e);
2163                            }
2164                    }
2165            }
2166    
2167            public void destroy() {
2168                    EntityCacheUtil.removeCache(UserNotificationEventImpl.class.getName());
2169                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2170                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2171            }
2172    
2173            @BeanReference(type = AccountPersistence.class)
2174            protected AccountPersistence accountPersistence;
2175            @BeanReference(type = AddressPersistence.class)
2176            protected AddressPersistence addressPersistence;
2177            @BeanReference(type = BrowserTrackerPersistence.class)
2178            protected BrowserTrackerPersistence browserTrackerPersistence;
2179            @BeanReference(type = ClassNamePersistence.class)
2180            protected ClassNamePersistence classNamePersistence;
2181            @BeanReference(type = ClusterGroupPersistence.class)
2182            protected ClusterGroupPersistence clusterGroupPersistence;
2183            @BeanReference(type = CompanyPersistence.class)
2184            protected CompanyPersistence companyPersistence;
2185            @BeanReference(type = ContactPersistence.class)
2186            protected ContactPersistence contactPersistence;
2187            @BeanReference(type = CountryPersistence.class)
2188            protected CountryPersistence countryPersistence;
2189            @BeanReference(type = EmailAddressPersistence.class)
2190            protected EmailAddressPersistence emailAddressPersistence;
2191            @BeanReference(type = GroupPersistence.class)
2192            protected GroupPersistence groupPersistence;
2193            @BeanReference(type = ImagePersistence.class)
2194            protected ImagePersistence imagePersistence;
2195            @BeanReference(type = LayoutPersistence.class)
2196            protected LayoutPersistence layoutPersistence;
2197            @BeanReference(type = LayoutBranchPersistence.class)
2198            protected LayoutBranchPersistence layoutBranchPersistence;
2199            @BeanReference(type = LayoutPrototypePersistence.class)
2200            protected LayoutPrototypePersistence layoutPrototypePersistence;
2201            @BeanReference(type = LayoutRevisionPersistence.class)
2202            protected LayoutRevisionPersistence layoutRevisionPersistence;
2203            @BeanReference(type = LayoutSetPersistence.class)
2204            protected LayoutSetPersistence layoutSetPersistence;
2205            @BeanReference(type = LayoutSetBranchPersistence.class)
2206            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2207            @BeanReference(type = LayoutSetPrototypePersistence.class)
2208            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2209            @BeanReference(type = ListTypePersistence.class)
2210            protected ListTypePersistence listTypePersistence;
2211            @BeanReference(type = LockPersistence.class)
2212            protected LockPersistence lockPersistence;
2213            @BeanReference(type = MembershipRequestPersistence.class)
2214            protected MembershipRequestPersistence membershipRequestPersistence;
2215            @BeanReference(type = OrganizationPersistence.class)
2216            protected OrganizationPersistence organizationPersistence;
2217            @BeanReference(type = OrgGroupPermissionPersistence.class)
2218            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2219            @BeanReference(type = OrgGroupRolePersistence.class)
2220            protected OrgGroupRolePersistence orgGroupRolePersistence;
2221            @BeanReference(type = OrgLaborPersistence.class)
2222            protected OrgLaborPersistence orgLaborPersistence;
2223            @BeanReference(type = PasswordPolicyPersistence.class)
2224            protected PasswordPolicyPersistence passwordPolicyPersistence;
2225            @BeanReference(type = PasswordPolicyRelPersistence.class)
2226            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2227            @BeanReference(type = PasswordTrackerPersistence.class)
2228            protected PasswordTrackerPersistence passwordTrackerPersistence;
2229            @BeanReference(type = PermissionPersistence.class)
2230            protected PermissionPersistence permissionPersistence;
2231            @BeanReference(type = PhonePersistence.class)
2232            protected PhonePersistence phonePersistence;
2233            @BeanReference(type = PluginSettingPersistence.class)
2234            protected PluginSettingPersistence pluginSettingPersistence;
2235            @BeanReference(type = PortalPreferencesPersistence.class)
2236            protected PortalPreferencesPersistence portalPreferencesPersistence;
2237            @BeanReference(type = PortletPersistence.class)
2238            protected PortletPersistence portletPersistence;
2239            @BeanReference(type = PortletItemPersistence.class)
2240            protected PortletItemPersistence portletItemPersistence;
2241            @BeanReference(type = PortletPreferencesPersistence.class)
2242            protected PortletPreferencesPersistence portletPreferencesPersistence;
2243            @BeanReference(type = RegionPersistence.class)
2244            protected RegionPersistence regionPersistence;
2245            @BeanReference(type = ReleasePersistence.class)
2246            protected ReleasePersistence releasePersistence;
2247            @BeanReference(type = RepositoryPersistence.class)
2248            protected RepositoryPersistence repositoryPersistence;
2249            @BeanReference(type = RepositoryEntryPersistence.class)
2250            protected RepositoryEntryPersistence repositoryEntryPersistence;
2251            @BeanReference(type = ResourcePersistence.class)
2252            protected ResourcePersistence resourcePersistence;
2253            @BeanReference(type = ResourceActionPersistence.class)
2254            protected ResourceActionPersistence resourceActionPersistence;
2255            @BeanReference(type = ResourceBlockPersistence.class)
2256            protected ResourceBlockPersistence resourceBlockPersistence;
2257            @BeanReference(type = ResourceBlockPermissionPersistence.class)
2258            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2259            @BeanReference(type = ResourceCodePersistence.class)
2260            protected ResourceCodePersistence resourceCodePersistence;
2261            @BeanReference(type = ResourcePermissionPersistence.class)
2262            protected ResourcePermissionPersistence resourcePermissionPersistence;
2263            @BeanReference(type = ResourceTypePermissionPersistence.class)
2264            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2265            @BeanReference(type = RolePersistence.class)
2266            protected RolePersistence rolePersistence;
2267            @BeanReference(type = ServiceComponentPersistence.class)
2268            protected ServiceComponentPersistence serviceComponentPersistence;
2269            @BeanReference(type = ShardPersistence.class)
2270            protected ShardPersistence shardPersistence;
2271            @BeanReference(type = SubscriptionPersistence.class)
2272            protected SubscriptionPersistence subscriptionPersistence;
2273            @BeanReference(type = TeamPersistence.class)
2274            protected TeamPersistence teamPersistence;
2275            @BeanReference(type = TicketPersistence.class)
2276            protected TicketPersistence ticketPersistence;
2277            @BeanReference(type = UserPersistence.class)
2278            protected UserPersistence userPersistence;
2279            @BeanReference(type = UserGroupPersistence.class)
2280            protected UserGroupPersistence userGroupPersistence;
2281            @BeanReference(type = UserGroupGroupRolePersistence.class)
2282            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2283            @BeanReference(type = UserGroupRolePersistence.class)
2284            protected UserGroupRolePersistence userGroupRolePersistence;
2285            @BeanReference(type = UserIdMapperPersistence.class)
2286            protected UserIdMapperPersistence userIdMapperPersistence;
2287            @BeanReference(type = UserNotificationEventPersistence.class)
2288            protected UserNotificationEventPersistence userNotificationEventPersistence;
2289            @BeanReference(type = UserTrackerPersistence.class)
2290            protected UserTrackerPersistence userTrackerPersistence;
2291            @BeanReference(type = UserTrackerPathPersistence.class)
2292            protected UserTrackerPathPersistence userTrackerPathPersistence;
2293            @BeanReference(type = VirtualHostPersistence.class)
2294            protected VirtualHostPersistence virtualHostPersistence;
2295            @BeanReference(type = WebDAVPropsPersistence.class)
2296            protected WebDAVPropsPersistence webDAVPropsPersistence;
2297            @BeanReference(type = WebsitePersistence.class)
2298            protected WebsitePersistence websitePersistence;
2299            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2300            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2301            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2302            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2303            private static final String _SQL_SELECT_USERNOTIFICATIONEVENT = "SELECT userNotificationEvent FROM UserNotificationEvent userNotificationEvent";
2304            private static final String _SQL_SELECT_USERNOTIFICATIONEVENT_WHERE = "SELECT userNotificationEvent FROM UserNotificationEvent userNotificationEvent WHERE ";
2305            private static final String _SQL_COUNT_USERNOTIFICATIONEVENT = "SELECT COUNT(userNotificationEvent) FROM UserNotificationEvent userNotificationEvent";
2306            private static final String _SQL_COUNT_USERNOTIFICATIONEVENT_WHERE = "SELECT COUNT(userNotificationEvent) FROM UserNotificationEvent userNotificationEvent WHERE ";
2307            private static final String _FINDER_COLUMN_UUID_UUID_1 = "userNotificationEvent.uuid IS NULL";
2308            private static final String _FINDER_COLUMN_UUID_UUID_2 = "userNotificationEvent.uuid = ?";
2309            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(userNotificationEvent.uuid IS NULL OR userNotificationEvent.uuid = ?)";
2310            private static final String _FINDER_COLUMN_USERID_USERID_2 = "userNotificationEvent.userId = ?";
2311            private static final String _FINDER_COLUMN_U_A_USERID_2 = "userNotificationEvent.userId = ? AND ";
2312            private static final String _FINDER_COLUMN_U_A_ARCHIVED_2 = "userNotificationEvent.archived = ?";
2313            private static final String _ORDER_BY_ENTITY_ALIAS = "userNotificationEvent.";
2314            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserNotificationEvent exists with the primary key ";
2315            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserNotificationEvent exists with the key {";
2316            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2317            private static Log _log = LogFactoryUtil.getLog(UserNotificationEventPersistenceImpl.class);
2318            private static UserNotificationEvent _nullUserNotificationEvent = new UserNotificationEventImpl() {
2319                            @Override
2320                            public Object clone() {
2321                                    return this;
2322                            }
2323    
2324                            @Override
2325                            public CacheModel<UserNotificationEvent> toCacheModel() {
2326                                    return _nullUserNotificationEventCacheModel;
2327                            }
2328                    };
2329    
2330            private static CacheModel<UserNotificationEvent> _nullUserNotificationEventCacheModel =
2331                    new CacheModel<UserNotificationEvent>() {
2332                            public UserNotificationEvent toEntityModel() {
2333                                    return _nullUserNotificationEvent;
2334                            }
2335                    };
2336    }