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