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