001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.exception.NoSuchUserNotificationDeliveryException;
020    import com.liferay.portal.kernel.bean.BeanReference;
021    import com.liferay.portal.kernel.dao.orm.EntityCache;
022    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderCache;
024    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025    import com.liferay.portal.kernel.dao.orm.FinderPath;
026    import com.liferay.portal.kernel.dao.orm.Query;
027    import com.liferay.portal.kernel.dao.orm.QueryPos;
028    import com.liferay.portal.kernel.dao.orm.QueryUtil;
029    import com.liferay.portal.kernel.dao.orm.Session;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.Validator;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.MVCCModel;
038    import com.liferay.portal.model.UserNotificationDelivery;
039    import com.liferay.portal.model.impl.UserNotificationDeliveryImpl;
040    import com.liferay.portal.model.impl.UserNotificationDeliveryModelImpl;
041    import com.liferay.portal.service.persistence.CompanyProvider;
042    import com.liferay.portal.service.persistence.CompanyProviderWrapper;
043    import com.liferay.portal.service.persistence.UserNotificationDeliveryPersistence;
044    
045    import java.io.Serializable;
046    
047    import java.util.Collections;
048    import java.util.HashMap;
049    import java.util.HashSet;
050    import java.util.Iterator;
051    import java.util.List;
052    import java.util.Map;
053    import java.util.Set;
054    
055    /**
056     * The persistence implementation for the user notification delivery service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see UserNotificationDeliveryPersistence
064     * @see com.liferay.portal.service.persistence.UserNotificationDeliveryUtil
065     * @generated
066     */
067    @ProviderType
068    public class UserNotificationDeliveryPersistenceImpl extends BasePersistenceImpl<UserNotificationDelivery>
069            implements UserNotificationDeliveryPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * Never modify or reference this class directly. Always use {@link UserNotificationDeliveryUtil} to access the user notification delivery persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = UserNotificationDeliveryImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
081                            UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED,
082                            UserNotificationDeliveryImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
085                            UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED,
086                            UserNotificationDeliveryImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
089                            UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
092                            UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED,
093                            UserNotificationDeliveryImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
095                            new String[] {
096                                    Long.class.getName(),
097                                    
098                            Integer.class.getName(), Integer.class.getName(),
099                                    OrderByComparator.class.getName()
100                            });
101            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
102                    new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
103                            UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED,
104                            UserNotificationDeliveryImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
106                            new String[] { Long.class.getName() },
107                            UserNotificationDeliveryModelImpl.USERID_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
109                            UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
111                            new String[] { Long.class.getName() });
112    
113            /**
114             * Returns all the user notification deliveries where userId = &#63;.
115             *
116             * @param userId the user ID
117             * @return the matching user notification deliveries
118             */
119            @Override
120            public List<UserNotificationDelivery> findByUserId(long userId) {
121                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122            }
123    
124            /**
125             * Returns a range of all the user notification deliveries where userId = &#63;.
126             *
127             * <p>
128             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserNotificationDeliveryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
129             * </p>
130             *
131             * @param userId the user ID
132             * @param start the lower bound of the range of user notification deliveries
133             * @param end the upper bound of the range of user notification deliveries (not inclusive)
134             * @return the range of matching user notification deliveries
135             */
136            @Override
137            public List<UserNotificationDelivery> findByUserId(long userId, int start,
138                    int end) {
139                    return findByUserId(userId, start, end, null);
140            }
141    
142            /**
143             * Returns an ordered range of all the user notification deliveries where userId = &#63;.
144             *
145             * <p>
146             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserNotificationDeliveryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
147             * </p>
148             *
149             * @param userId the user ID
150             * @param start the lower bound of the range of user notification deliveries
151             * @param end the upper bound of the range of user notification deliveries (not inclusive)
152             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
153             * @return the ordered range of matching user notification deliveries
154             */
155            @Override
156            public List<UserNotificationDelivery> findByUserId(long userId, int start,
157                    int end, OrderByComparator<UserNotificationDelivery> orderByComparator) {
158                    return findByUserId(userId, start, end, orderByComparator, true);
159            }
160    
161            /**
162             * Returns an ordered range of all the user notification deliveries where userId = &#63;.
163             *
164             * <p>
165             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserNotificationDeliveryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
166             * </p>
167             *
168             * @param userId the user ID
169             * @param start the lower bound of the range of user notification deliveries
170             * @param end the upper bound of the range of user notification deliveries (not inclusive)
171             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
172             * @param retrieveFromCache whether to retrieve from the finder cache
173             * @return the ordered range of matching user notification deliveries
174             */
175            @Override
176            public List<UserNotificationDelivery> findByUserId(long userId, int start,
177                    int end, OrderByComparator<UserNotificationDelivery> orderByComparator,
178                    boolean retrieveFromCache) {
179                    boolean pagination = true;
180                    FinderPath finderPath = null;
181                    Object[] finderArgs = null;
182    
183                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
184                                    (orderByComparator == null)) {
185                            pagination = false;
186                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
187                            finderArgs = new Object[] { userId };
188                    }
189                    else {
190                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
191                            finderArgs = new Object[] { userId, start, end, orderByComparator };
192                    }
193    
194                    List<UserNotificationDelivery> list = null;
195    
196                    if (retrieveFromCache) {
197                            list = (List<UserNotificationDelivery>)finderCache.getResult(finderPath,
198                                            finderArgs, this);
199    
200                            if ((list != null) && !list.isEmpty()) {
201                                    for (UserNotificationDelivery userNotificationDelivery : list) {
202                                            if ((userId != userNotificationDelivery.getUserId())) {
203                                                    list = null;
204    
205                                                    break;
206                                            }
207                                    }
208                            }
209                    }
210    
211                    if (list == null) {
212                            StringBundler query = null;
213    
214                            if (orderByComparator != null) {
215                                    query = new StringBundler(3 +
216                                                    (orderByComparator.getOrderByFields().length * 3));
217                            }
218                            else {
219                                    query = new StringBundler(3);
220                            }
221    
222                            query.append(_SQL_SELECT_USERNOTIFICATIONDELIVERY_WHERE);
223    
224                            query.append(_FINDER_COLUMN_USERID_USERID_2);
225    
226                            if (orderByComparator != null) {
227                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
228                                            orderByComparator);
229                            }
230                            else
231                             if (pagination) {
232                                    query.append(UserNotificationDeliveryModelImpl.ORDER_BY_JPQL);
233                            }
234    
235                            String sql = query.toString();
236    
237                            Session session = null;
238    
239                            try {
240                                    session = openSession();
241    
242                                    Query q = session.createQuery(sql);
243    
244                                    QueryPos qPos = QueryPos.getInstance(q);
245    
246                                    qPos.add(userId);
247    
248                                    if (!pagination) {
249                                            list = (List<UserNotificationDelivery>)QueryUtil.list(q,
250                                                            getDialect(), start, end, false);
251    
252                                            Collections.sort(list);
253    
254                                            list = Collections.unmodifiableList(list);
255                                    }
256                                    else {
257                                            list = (List<UserNotificationDelivery>)QueryUtil.list(q,
258                                                            getDialect(), start, end);
259                                    }
260    
261                                    cacheResult(list);
262    
263                                    finderCache.putResult(finderPath, finderArgs, list);
264                            }
265                            catch (Exception e) {
266                                    finderCache.removeResult(finderPath, finderArgs);
267    
268                                    throw processException(e);
269                            }
270                            finally {
271                                    closeSession(session);
272                            }
273                    }
274    
275                    return list;
276            }
277    
278            /**
279             * Returns the first user notification delivery in the ordered set where userId = &#63;.
280             *
281             * @param userId the user ID
282             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
283             * @return the first matching user notification delivery
284             * @throws NoSuchUserNotificationDeliveryException if a matching user notification delivery could not be found
285             */
286            @Override
287            public UserNotificationDelivery findByUserId_First(long userId,
288                    OrderByComparator<UserNotificationDelivery> orderByComparator)
289                    throws NoSuchUserNotificationDeliveryException {
290                    UserNotificationDelivery userNotificationDelivery = fetchByUserId_First(userId,
291                                    orderByComparator);
292    
293                    if (userNotificationDelivery != null) {
294                            return userNotificationDelivery;
295                    }
296    
297                    StringBundler msg = new StringBundler(4);
298    
299                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
300    
301                    msg.append("userId=");
302                    msg.append(userId);
303    
304                    msg.append(StringPool.CLOSE_CURLY_BRACE);
305    
306                    throw new NoSuchUserNotificationDeliveryException(msg.toString());
307            }
308    
309            /**
310             * Returns the first user notification delivery in the ordered set where userId = &#63;.
311             *
312             * @param userId the user ID
313             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
314             * @return the first matching user notification delivery, or <code>null</code> if a matching user notification delivery could not be found
315             */
316            @Override
317            public UserNotificationDelivery fetchByUserId_First(long userId,
318                    OrderByComparator<UserNotificationDelivery> orderByComparator) {
319                    List<UserNotificationDelivery> list = findByUserId(userId, 0, 1,
320                                    orderByComparator);
321    
322                    if (!list.isEmpty()) {
323                            return list.get(0);
324                    }
325    
326                    return null;
327            }
328    
329            /**
330             * Returns the last user notification delivery in the ordered set where userId = &#63;.
331             *
332             * @param userId the user ID
333             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
334             * @return the last matching user notification delivery
335             * @throws NoSuchUserNotificationDeliveryException if a matching user notification delivery could not be found
336             */
337            @Override
338            public UserNotificationDelivery findByUserId_Last(long userId,
339                    OrderByComparator<UserNotificationDelivery> orderByComparator)
340                    throws NoSuchUserNotificationDeliveryException {
341                    UserNotificationDelivery userNotificationDelivery = fetchByUserId_Last(userId,
342                                    orderByComparator);
343    
344                    if (userNotificationDelivery != null) {
345                            return userNotificationDelivery;
346                    }
347    
348                    StringBundler msg = new StringBundler(4);
349    
350                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
351    
352                    msg.append("userId=");
353                    msg.append(userId);
354    
355                    msg.append(StringPool.CLOSE_CURLY_BRACE);
356    
357                    throw new NoSuchUserNotificationDeliveryException(msg.toString());
358            }
359    
360            /**
361             * Returns the last user notification delivery in the ordered set where userId = &#63;.
362             *
363             * @param userId the user ID
364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
365             * @return the last matching user notification delivery, or <code>null</code> if a matching user notification delivery could not be found
366             */
367            @Override
368            public UserNotificationDelivery fetchByUserId_Last(long userId,
369                    OrderByComparator<UserNotificationDelivery> orderByComparator) {
370                    int count = countByUserId(userId);
371    
372                    if (count == 0) {
373                            return null;
374                    }
375    
376                    List<UserNotificationDelivery> list = findByUserId(userId, count - 1,
377                                    count, orderByComparator);
378    
379                    if (!list.isEmpty()) {
380                            return list.get(0);
381                    }
382    
383                    return null;
384            }
385    
386            /**
387             * Returns the user notification deliveries before and after the current user notification delivery in the ordered set where userId = &#63;.
388             *
389             * @param userNotificationDeliveryId the primary key of the current user notification delivery
390             * @param userId the user ID
391             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
392             * @return the previous, current, and next user notification delivery
393             * @throws NoSuchUserNotificationDeliveryException if a user notification delivery with the primary key could not be found
394             */
395            @Override
396            public UserNotificationDelivery[] findByUserId_PrevAndNext(
397                    long userNotificationDeliveryId, long userId,
398                    OrderByComparator<UserNotificationDelivery> orderByComparator)
399                    throws NoSuchUserNotificationDeliveryException {
400                    UserNotificationDelivery userNotificationDelivery = findByPrimaryKey(userNotificationDeliveryId);
401    
402                    Session session = null;
403    
404                    try {
405                            session = openSession();
406    
407                            UserNotificationDelivery[] array = new UserNotificationDeliveryImpl[3];
408    
409                            array[0] = getByUserId_PrevAndNext(session,
410                                            userNotificationDelivery, userId, orderByComparator, true);
411    
412                            array[1] = userNotificationDelivery;
413    
414                            array[2] = getByUserId_PrevAndNext(session,
415                                            userNotificationDelivery, userId, orderByComparator, false);
416    
417                            return array;
418                    }
419                    catch (Exception e) {
420                            throw processException(e);
421                    }
422                    finally {
423                            closeSession(session);
424                    }
425            }
426    
427            protected UserNotificationDelivery getByUserId_PrevAndNext(
428                    Session session, UserNotificationDelivery userNotificationDelivery,
429                    long userId,
430                    OrderByComparator<UserNotificationDelivery> orderByComparator,
431                    boolean previous) {
432                    StringBundler query = null;
433    
434                    if (orderByComparator != null) {
435                            query = new StringBundler(6 +
436                                            (orderByComparator.getOrderByFields().length * 6));
437                    }
438                    else {
439                            query = new StringBundler(3);
440                    }
441    
442                    query.append(_SQL_SELECT_USERNOTIFICATIONDELIVERY_WHERE);
443    
444                    query.append(_FINDER_COLUMN_USERID_USERID_2);
445    
446                    if (orderByComparator != null) {
447                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
448    
449                            if (orderByConditionFields.length > 0) {
450                                    query.append(WHERE_AND);
451                            }
452    
453                            for (int i = 0; i < orderByConditionFields.length; i++) {
454                                    query.append(_ORDER_BY_ENTITY_ALIAS);
455                                    query.append(orderByConditionFields[i]);
456    
457                                    if ((i + 1) < orderByConditionFields.length) {
458                                            if (orderByComparator.isAscending() ^ previous) {
459                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
460                                            }
461                                            else {
462                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
463                                            }
464                                    }
465                                    else {
466                                            if (orderByComparator.isAscending() ^ previous) {
467                                                    query.append(WHERE_GREATER_THAN);
468                                            }
469                                            else {
470                                                    query.append(WHERE_LESSER_THAN);
471                                            }
472                                    }
473                            }
474    
475                            query.append(ORDER_BY_CLAUSE);
476    
477                            String[] orderByFields = orderByComparator.getOrderByFields();
478    
479                            for (int i = 0; i < orderByFields.length; i++) {
480                                    query.append(_ORDER_BY_ENTITY_ALIAS);
481                                    query.append(orderByFields[i]);
482    
483                                    if ((i + 1) < orderByFields.length) {
484                                            if (orderByComparator.isAscending() ^ previous) {
485                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
486                                            }
487                                            else {
488                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
489                                            }
490                                    }
491                                    else {
492                                            if (orderByComparator.isAscending() ^ previous) {
493                                                    query.append(ORDER_BY_ASC);
494                                            }
495                                            else {
496                                                    query.append(ORDER_BY_DESC);
497                                            }
498                                    }
499                            }
500                    }
501                    else {
502                            query.append(UserNotificationDeliveryModelImpl.ORDER_BY_JPQL);
503                    }
504    
505                    String sql = query.toString();
506    
507                    Query q = session.createQuery(sql);
508    
509                    q.setFirstResult(0);
510                    q.setMaxResults(2);
511    
512                    QueryPos qPos = QueryPos.getInstance(q);
513    
514                    qPos.add(userId);
515    
516                    if (orderByComparator != null) {
517                            Object[] values = orderByComparator.getOrderByConditionValues(userNotificationDelivery);
518    
519                            for (Object value : values) {
520                                    qPos.add(value);
521                            }
522                    }
523    
524                    List<UserNotificationDelivery> list = q.list();
525    
526                    if (list.size() == 2) {
527                            return list.get(1);
528                    }
529                    else {
530                            return null;
531                    }
532            }
533    
534            /**
535             * Removes all the user notification deliveries where userId = &#63; from the database.
536             *
537             * @param userId the user ID
538             */
539            @Override
540            public void removeByUserId(long userId) {
541                    for (UserNotificationDelivery userNotificationDelivery : findByUserId(
542                                    userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
543                            remove(userNotificationDelivery);
544                    }
545            }
546    
547            /**
548             * Returns the number of user notification deliveries where userId = &#63;.
549             *
550             * @param userId the user ID
551             * @return the number of matching user notification deliveries
552             */
553            @Override
554            public int countByUserId(long userId) {
555                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
556    
557                    Object[] finderArgs = new Object[] { userId };
558    
559                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
560    
561                    if (count == null) {
562                            StringBundler query = new StringBundler(2);
563    
564                            query.append(_SQL_COUNT_USERNOTIFICATIONDELIVERY_WHERE);
565    
566                            query.append(_FINDER_COLUMN_USERID_USERID_2);
567    
568                            String sql = query.toString();
569    
570                            Session session = null;
571    
572                            try {
573                                    session = openSession();
574    
575                                    Query q = session.createQuery(sql);
576    
577                                    QueryPos qPos = QueryPos.getInstance(q);
578    
579                                    qPos.add(userId);
580    
581                                    count = (Long)q.uniqueResult();
582    
583                                    finderCache.putResult(finderPath, finderArgs, count);
584                            }
585                            catch (Exception e) {
586                                    finderCache.removeResult(finderPath, finderArgs);
587    
588                                    throw processException(e);
589                            }
590                            finally {
591                                    closeSession(session);
592                            }
593                    }
594    
595                    return count.intValue();
596            }
597    
598            private static final String _FINDER_COLUMN_USERID_USERID_2 = "userNotificationDelivery.userId = ?";
599            public static final FinderPath FINDER_PATH_FETCH_BY_U_P_C_N_D = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
600                            UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED,
601                            UserNotificationDeliveryImpl.class, FINDER_CLASS_NAME_ENTITY,
602                            "fetchByU_P_C_N_D",
603                            new String[] {
604                                    Long.class.getName(), String.class.getName(),
605                                    Long.class.getName(), Integer.class.getName(),
606                                    Integer.class.getName()
607                            },
608                            UserNotificationDeliveryModelImpl.USERID_COLUMN_BITMASK |
609                            UserNotificationDeliveryModelImpl.PORTLETID_COLUMN_BITMASK |
610                            UserNotificationDeliveryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
611                            UserNotificationDeliveryModelImpl.NOTIFICATIONTYPE_COLUMN_BITMASK |
612                            UserNotificationDeliveryModelImpl.DELIVERYTYPE_COLUMN_BITMASK);
613            public static final FinderPath FINDER_PATH_COUNT_BY_U_P_C_N_D = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
614                            UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
615                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_P_C_N_D",
616                            new String[] {
617                                    Long.class.getName(), String.class.getName(),
618                                    Long.class.getName(), Integer.class.getName(),
619                                    Integer.class.getName()
620                            });
621    
622            /**
623             * Returns the user notification delivery where userId = &#63; and portletId = &#63; and classNameId = &#63; and notificationType = &#63; and deliveryType = &#63; or throws a {@link NoSuchUserNotificationDeliveryException} if it could not be found.
624             *
625             * @param userId the user ID
626             * @param portletId the portlet ID
627             * @param classNameId the class name ID
628             * @param notificationType the notification type
629             * @param deliveryType the delivery type
630             * @return the matching user notification delivery
631             * @throws NoSuchUserNotificationDeliveryException if a matching user notification delivery could not be found
632             */
633            @Override
634            public UserNotificationDelivery findByU_P_C_N_D(long userId,
635                    String portletId, long classNameId, int notificationType,
636                    int deliveryType) throws NoSuchUserNotificationDeliveryException {
637                    UserNotificationDelivery userNotificationDelivery = fetchByU_P_C_N_D(userId,
638                                    portletId, classNameId, notificationType, deliveryType);
639    
640                    if (userNotificationDelivery == null) {
641                            StringBundler msg = new StringBundler(12);
642    
643                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
644    
645                            msg.append("userId=");
646                            msg.append(userId);
647    
648                            msg.append(", portletId=");
649                            msg.append(portletId);
650    
651                            msg.append(", classNameId=");
652                            msg.append(classNameId);
653    
654                            msg.append(", notificationType=");
655                            msg.append(notificationType);
656    
657                            msg.append(", deliveryType=");
658                            msg.append(deliveryType);
659    
660                            msg.append(StringPool.CLOSE_CURLY_BRACE);
661    
662                            if (_log.isWarnEnabled()) {
663                                    _log.warn(msg.toString());
664                            }
665    
666                            throw new NoSuchUserNotificationDeliveryException(msg.toString());
667                    }
668    
669                    return userNotificationDelivery;
670            }
671    
672            /**
673             * Returns the user notification delivery where userId = &#63; and portletId = &#63; and classNameId = &#63; and notificationType = &#63; and deliveryType = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
674             *
675             * @param userId the user ID
676             * @param portletId the portlet ID
677             * @param classNameId the class name ID
678             * @param notificationType the notification type
679             * @param deliveryType the delivery type
680             * @return the matching user notification delivery, or <code>null</code> if a matching user notification delivery could not be found
681             */
682            @Override
683            public UserNotificationDelivery fetchByU_P_C_N_D(long userId,
684                    String portletId, long classNameId, int notificationType,
685                    int deliveryType) {
686                    return fetchByU_P_C_N_D(userId, portletId, classNameId,
687                            notificationType, deliveryType, true);
688            }
689    
690            /**
691             * Returns the user notification delivery where userId = &#63; and portletId = &#63; and classNameId = &#63; and notificationType = &#63; and deliveryType = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
692             *
693             * @param userId the user ID
694             * @param portletId the portlet ID
695             * @param classNameId the class name ID
696             * @param notificationType the notification type
697             * @param deliveryType the delivery type
698             * @param retrieveFromCache whether to retrieve from the finder cache
699             * @return the matching user notification delivery, or <code>null</code> if a matching user notification delivery could not be found
700             */
701            @Override
702            public UserNotificationDelivery fetchByU_P_C_N_D(long userId,
703                    String portletId, long classNameId, int notificationType,
704                    int deliveryType, boolean retrieveFromCache) {
705                    Object[] finderArgs = new Object[] {
706                                    userId, portletId, classNameId, notificationType, deliveryType
707                            };
708    
709                    Object result = null;
710    
711                    if (retrieveFromCache) {
712                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_U_P_C_N_D,
713                                            finderArgs, this);
714                    }
715    
716                    if (result instanceof UserNotificationDelivery) {
717                            UserNotificationDelivery userNotificationDelivery = (UserNotificationDelivery)result;
718    
719                            if ((userId != userNotificationDelivery.getUserId()) ||
720                                            !Validator.equals(portletId,
721                                                    userNotificationDelivery.getPortletId()) ||
722                                            (classNameId != userNotificationDelivery.getClassNameId()) ||
723                                            (notificationType != userNotificationDelivery.getNotificationType()) ||
724                                            (deliveryType != userNotificationDelivery.getDeliveryType())) {
725                                    result = null;
726                            }
727                    }
728    
729                    if (result == null) {
730                            StringBundler query = new StringBundler(7);
731    
732                            query.append(_SQL_SELECT_USERNOTIFICATIONDELIVERY_WHERE);
733    
734                            query.append(_FINDER_COLUMN_U_P_C_N_D_USERID_2);
735    
736                            boolean bindPortletId = false;
737    
738                            if (portletId == null) {
739                                    query.append(_FINDER_COLUMN_U_P_C_N_D_PORTLETID_1);
740                            }
741                            else if (portletId.equals(StringPool.BLANK)) {
742                                    query.append(_FINDER_COLUMN_U_P_C_N_D_PORTLETID_3);
743                            }
744                            else {
745                                    bindPortletId = true;
746    
747                                    query.append(_FINDER_COLUMN_U_P_C_N_D_PORTLETID_2);
748                            }
749    
750                            query.append(_FINDER_COLUMN_U_P_C_N_D_CLASSNAMEID_2);
751    
752                            query.append(_FINDER_COLUMN_U_P_C_N_D_NOTIFICATIONTYPE_2);
753    
754                            query.append(_FINDER_COLUMN_U_P_C_N_D_DELIVERYTYPE_2);
755    
756                            String sql = query.toString();
757    
758                            Session session = null;
759    
760                            try {
761                                    session = openSession();
762    
763                                    Query q = session.createQuery(sql);
764    
765                                    QueryPos qPos = QueryPos.getInstance(q);
766    
767                                    qPos.add(userId);
768    
769                                    if (bindPortletId) {
770                                            qPos.add(portletId);
771                                    }
772    
773                                    qPos.add(classNameId);
774    
775                                    qPos.add(notificationType);
776    
777                                    qPos.add(deliveryType);
778    
779                                    List<UserNotificationDelivery> list = q.list();
780    
781                                    if (list.isEmpty()) {
782                                            finderCache.putResult(FINDER_PATH_FETCH_BY_U_P_C_N_D,
783                                                    finderArgs, list);
784                                    }
785                                    else {
786                                            UserNotificationDelivery userNotificationDelivery = list.get(0);
787    
788                                            result = userNotificationDelivery;
789    
790                                            cacheResult(userNotificationDelivery);
791    
792                                            if ((userNotificationDelivery.getUserId() != userId) ||
793                                                            (userNotificationDelivery.getPortletId() == null) ||
794                                                            !userNotificationDelivery.getPortletId()
795                                                                                                                     .equals(portletId) ||
796                                                            (userNotificationDelivery.getClassNameId() != classNameId) ||
797                                                            (userNotificationDelivery.getNotificationType() != notificationType) ||
798                                                            (userNotificationDelivery.getDeliveryType() != deliveryType)) {
799                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_P_C_N_D,
800                                                            finderArgs, userNotificationDelivery);
801                                            }
802                                    }
803                            }
804                            catch (Exception e) {
805                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_U_P_C_N_D,
806                                            finderArgs);
807    
808                                    throw processException(e);
809                            }
810                            finally {
811                                    closeSession(session);
812                            }
813                    }
814    
815                    if (result instanceof List<?>) {
816                            return null;
817                    }
818                    else {
819                            return (UserNotificationDelivery)result;
820                    }
821            }
822    
823            /**
824             * Removes the user notification delivery where userId = &#63; and portletId = &#63; and classNameId = &#63; and notificationType = &#63; and deliveryType = &#63; from the database.
825             *
826             * @param userId the user ID
827             * @param portletId the portlet ID
828             * @param classNameId the class name ID
829             * @param notificationType the notification type
830             * @param deliveryType the delivery type
831             * @return the user notification delivery that was removed
832             */
833            @Override
834            public UserNotificationDelivery removeByU_P_C_N_D(long userId,
835                    String portletId, long classNameId, int notificationType,
836                    int deliveryType) throws NoSuchUserNotificationDeliveryException {
837                    UserNotificationDelivery userNotificationDelivery = findByU_P_C_N_D(userId,
838                                    portletId, classNameId, notificationType, deliveryType);
839    
840                    return remove(userNotificationDelivery);
841            }
842    
843            /**
844             * Returns the number of user notification deliveries where userId = &#63; and portletId = &#63; and classNameId = &#63; and notificationType = &#63; and deliveryType = &#63;.
845             *
846             * @param userId the user ID
847             * @param portletId the portlet ID
848             * @param classNameId the class name ID
849             * @param notificationType the notification type
850             * @param deliveryType the delivery type
851             * @return the number of matching user notification deliveries
852             */
853            @Override
854            public int countByU_P_C_N_D(long userId, String portletId,
855                    long classNameId, int notificationType, int deliveryType) {
856                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_P_C_N_D;
857    
858                    Object[] finderArgs = new Object[] {
859                                    userId, portletId, classNameId, notificationType, deliveryType
860                            };
861    
862                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
863    
864                    if (count == null) {
865                            StringBundler query = new StringBundler(6);
866    
867                            query.append(_SQL_COUNT_USERNOTIFICATIONDELIVERY_WHERE);
868    
869                            query.append(_FINDER_COLUMN_U_P_C_N_D_USERID_2);
870    
871                            boolean bindPortletId = false;
872    
873                            if (portletId == null) {
874                                    query.append(_FINDER_COLUMN_U_P_C_N_D_PORTLETID_1);
875                            }
876                            else if (portletId.equals(StringPool.BLANK)) {
877                                    query.append(_FINDER_COLUMN_U_P_C_N_D_PORTLETID_3);
878                            }
879                            else {
880                                    bindPortletId = true;
881    
882                                    query.append(_FINDER_COLUMN_U_P_C_N_D_PORTLETID_2);
883                            }
884    
885                            query.append(_FINDER_COLUMN_U_P_C_N_D_CLASSNAMEID_2);
886    
887                            query.append(_FINDER_COLUMN_U_P_C_N_D_NOTIFICATIONTYPE_2);
888    
889                            query.append(_FINDER_COLUMN_U_P_C_N_D_DELIVERYTYPE_2);
890    
891                            String sql = query.toString();
892    
893                            Session session = null;
894    
895                            try {
896                                    session = openSession();
897    
898                                    Query q = session.createQuery(sql);
899    
900                                    QueryPos qPos = QueryPos.getInstance(q);
901    
902                                    qPos.add(userId);
903    
904                                    if (bindPortletId) {
905                                            qPos.add(portletId);
906                                    }
907    
908                                    qPos.add(classNameId);
909    
910                                    qPos.add(notificationType);
911    
912                                    qPos.add(deliveryType);
913    
914                                    count = (Long)q.uniqueResult();
915    
916                                    finderCache.putResult(finderPath, finderArgs, count);
917                            }
918                            catch (Exception e) {
919                                    finderCache.removeResult(finderPath, finderArgs);
920    
921                                    throw processException(e);
922                            }
923                            finally {
924                                    closeSession(session);
925                            }
926                    }
927    
928                    return count.intValue();
929            }
930    
931            private static final String _FINDER_COLUMN_U_P_C_N_D_USERID_2 = "userNotificationDelivery.userId = ? AND ";
932            private static final String _FINDER_COLUMN_U_P_C_N_D_PORTLETID_1 = "userNotificationDelivery.portletId IS NULL AND ";
933            private static final String _FINDER_COLUMN_U_P_C_N_D_PORTLETID_2 = "userNotificationDelivery.portletId = ? AND ";
934            private static final String _FINDER_COLUMN_U_P_C_N_D_PORTLETID_3 = "(userNotificationDelivery.portletId IS NULL OR userNotificationDelivery.portletId = '') AND ";
935            private static final String _FINDER_COLUMN_U_P_C_N_D_CLASSNAMEID_2 = "userNotificationDelivery.classNameId = ? AND ";
936            private static final String _FINDER_COLUMN_U_P_C_N_D_NOTIFICATIONTYPE_2 = "userNotificationDelivery.notificationType = ? AND ";
937            private static final String _FINDER_COLUMN_U_P_C_N_D_DELIVERYTYPE_2 = "userNotificationDelivery.deliveryType = ?";
938    
939            public UserNotificationDeliveryPersistenceImpl() {
940                    setModelClass(UserNotificationDelivery.class);
941            }
942    
943            /**
944             * Caches the user notification delivery in the entity cache if it is enabled.
945             *
946             * @param userNotificationDelivery the user notification delivery
947             */
948            @Override
949            public void cacheResult(UserNotificationDelivery userNotificationDelivery) {
950                    entityCache.putResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
951                            UserNotificationDeliveryImpl.class,
952                            userNotificationDelivery.getPrimaryKey(), userNotificationDelivery);
953    
954                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_P_C_N_D,
955                            new Object[] {
956                                    userNotificationDelivery.getUserId(),
957                                    userNotificationDelivery.getPortletId(),
958                                    userNotificationDelivery.getClassNameId(),
959                                    userNotificationDelivery.getNotificationType(),
960                                    userNotificationDelivery.getDeliveryType()
961                            }, userNotificationDelivery);
962    
963                    userNotificationDelivery.resetOriginalValues();
964            }
965    
966            /**
967             * Caches the user notification deliveries in the entity cache if it is enabled.
968             *
969             * @param userNotificationDeliveries the user notification deliveries
970             */
971            @Override
972            public void cacheResult(
973                    List<UserNotificationDelivery> userNotificationDeliveries) {
974                    for (UserNotificationDelivery userNotificationDelivery : userNotificationDeliveries) {
975                            if (entityCache.getResult(
976                                                    UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
977                                                    UserNotificationDeliveryImpl.class,
978                                                    userNotificationDelivery.getPrimaryKey()) == null) {
979                                    cacheResult(userNotificationDelivery);
980                            }
981                            else {
982                                    userNotificationDelivery.resetOriginalValues();
983                            }
984                    }
985            }
986    
987            /**
988             * Clears the cache for all user notification deliveries.
989             *
990             * <p>
991             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
992             * </p>
993             */
994            @Override
995            public void clearCache() {
996                    entityCache.clearCache(UserNotificationDeliveryImpl.class);
997    
998                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
999                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1000                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1001            }
1002    
1003            /**
1004             * Clears the cache for the user notification delivery.
1005             *
1006             * <p>
1007             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1008             * </p>
1009             */
1010            @Override
1011            public void clearCache(UserNotificationDelivery userNotificationDelivery) {
1012                    entityCache.removeResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1013                            UserNotificationDeliveryImpl.class,
1014                            userNotificationDelivery.getPrimaryKey());
1015    
1016                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1017                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1018    
1019                    clearUniqueFindersCache((UserNotificationDeliveryModelImpl)userNotificationDelivery);
1020            }
1021    
1022            @Override
1023            public void clearCache(
1024                    List<UserNotificationDelivery> userNotificationDeliveries) {
1025                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1026                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1027    
1028                    for (UserNotificationDelivery userNotificationDelivery : userNotificationDeliveries) {
1029                            entityCache.removeResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1030                                    UserNotificationDeliveryImpl.class,
1031                                    userNotificationDelivery.getPrimaryKey());
1032    
1033                            clearUniqueFindersCache((UserNotificationDeliveryModelImpl)userNotificationDelivery);
1034                    }
1035            }
1036    
1037            protected void cacheUniqueFindersCache(
1038                    UserNotificationDeliveryModelImpl userNotificationDeliveryModelImpl,
1039                    boolean isNew) {
1040                    if (isNew) {
1041                            Object[] args = new Object[] {
1042                                            userNotificationDeliveryModelImpl.getUserId(),
1043                                            userNotificationDeliveryModelImpl.getPortletId(),
1044                                            userNotificationDeliveryModelImpl.getClassNameId(),
1045                                            userNotificationDeliveryModelImpl.getNotificationType(),
1046                                            userNotificationDeliveryModelImpl.getDeliveryType()
1047                                    };
1048    
1049                            finderCache.putResult(FINDER_PATH_COUNT_BY_U_P_C_N_D, args,
1050                                    Long.valueOf(1));
1051                            finderCache.putResult(FINDER_PATH_FETCH_BY_U_P_C_N_D, args,
1052                                    userNotificationDeliveryModelImpl);
1053                    }
1054                    else {
1055                            if ((userNotificationDeliveryModelImpl.getColumnBitmask() &
1056                                            FINDER_PATH_FETCH_BY_U_P_C_N_D.getColumnBitmask()) != 0) {
1057                                    Object[] args = new Object[] {
1058                                                    userNotificationDeliveryModelImpl.getUserId(),
1059                                                    userNotificationDeliveryModelImpl.getPortletId(),
1060                                                    userNotificationDeliveryModelImpl.getClassNameId(),
1061                                                    userNotificationDeliveryModelImpl.getNotificationType(),
1062                                                    userNotificationDeliveryModelImpl.getDeliveryType()
1063                                            };
1064    
1065                                    finderCache.putResult(FINDER_PATH_COUNT_BY_U_P_C_N_D, args,
1066                                            Long.valueOf(1));
1067                                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_P_C_N_D, args,
1068                                            userNotificationDeliveryModelImpl);
1069                            }
1070                    }
1071            }
1072    
1073            protected void clearUniqueFindersCache(
1074                    UserNotificationDeliveryModelImpl userNotificationDeliveryModelImpl) {
1075                    Object[] args = new Object[] {
1076                                    userNotificationDeliveryModelImpl.getUserId(),
1077                                    userNotificationDeliveryModelImpl.getPortletId(),
1078                                    userNotificationDeliveryModelImpl.getClassNameId(),
1079                                    userNotificationDeliveryModelImpl.getNotificationType(),
1080                                    userNotificationDeliveryModelImpl.getDeliveryType()
1081                            };
1082    
1083                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_P_C_N_D, args);
1084                    finderCache.removeResult(FINDER_PATH_FETCH_BY_U_P_C_N_D, args);
1085    
1086                    if ((userNotificationDeliveryModelImpl.getColumnBitmask() &
1087                                    FINDER_PATH_FETCH_BY_U_P_C_N_D.getColumnBitmask()) != 0) {
1088                            args = new Object[] {
1089                                            userNotificationDeliveryModelImpl.getOriginalUserId(),
1090                                            userNotificationDeliveryModelImpl.getOriginalPortletId(),
1091                                            userNotificationDeliveryModelImpl.getOriginalClassNameId(),
1092                                            userNotificationDeliveryModelImpl.getOriginalNotificationType(),
1093                                            userNotificationDeliveryModelImpl.getOriginalDeliveryType()
1094                                    };
1095    
1096                            finderCache.removeResult(FINDER_PATH_COUNT_BY_U_P_C_N_D, args);
1097                            finderCache.removeResult(FINDER_PATH_FETCH_BY_U_P_C_N_D, args);
1098                    }
1099            }
1100    
1101            /**
1102             * Creates a new user notification delivery with the primary key. Does not add the user notification delivery to the database.
1103             *
1104             * @param userNotificationDeliveryId the primary key for the new user notification delivery
1105             * @return the new user notification delivery
1106             */
1107            @Override
1108            public UserNotificationDelivery create(long userNotificationDeliveryId) {
1109                    UserNotificationDelivery userNotificationDelivery = new UserNotificationDeliveryImpl();
1110    
1111                    userNotificationDelivery.setNew(true);
1112                    userNotificationDelivery.setPrimaryKey(userNotificationDeliveryId);
1113    
1114                    userNotificationDelivery.setCompanyId(companyProvider.getCompanyId());
1115    
1116                    return userNotificationDelivery;
1117            }
1118    
1119            /**
1120             * Removes the user notification delivery with the primary key from the database. Also notifies the appropriate model listeners.
1121             *
1122             * @param userNotificationDeliveryId the primary key of the user notification delivery
1123             * @return the user notification delivery that was removed
1124             * @throws NoSuchUserNotificationDeliveryException if a user notification delivery with the primary key could not be found
1125             */
1126            @Override
1127            public UserNotificationDelivery remove(long userNotificationDeliveryId)
1128                    throws NoSuchUserNotificationDeliveryException {
1129                    return remove((Serializable)userNotificationDeliveryId);
1130            }
1131    
1132            /**
1133             * Removes the user notification delivery with the primary key from the database. Also notifies the appropriate model listeners.
1134             *
1135             * @param primaryKey the primary key of the user notification delivery
1136             * @return the user notification delivery that was removed
1137             * @throws NoSuchUserNotificationDeliveryException if a user notification delivery with the primary key could not be found
1138             */
1139            @Override
1140            public UserNotificationDelivery remove(Serializable primaryKey)
1141                    throws NoSuchUserNotificationDeliveryException {
1142                    Session session = null;
1143    
1144                    try {
1145                            session = openSession();
1146    
1147                            UserNotificationDelivery userNotificationDelivery = (UserNotificationDelivery)session.get(UserNotificationDeliveryImpl.class,
1148                                            primaryKey);
1149    
1150                            if (userNotificationDelivery == null) {
1151                                    if (_log.isWarnEnabled()) {
1152                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1153                                    }
1154    
1155                                    throw new NoSuchUserNotificationDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1156                                            primaryKey);
1157                            }
1158    
1159                            return remove(userNotificationDelivery);
1160                    }
1161                    catch (NoSuchUserNotificationDeliveryException nsee) {
1162                            throw nsee;
1163                    }
1164                    catch (Exception e) {
1165                            throw processException(e);
1166                    }
1167                    finally {
1168                            closeSession(session);
1169                    }
1170            }
1171    
1172            @Override
1173            protected UserNotificationDelivery removeImpl(
1174                    UserNotificationDelivery userNotificationDelivery) {
1175                    userNotificationDelivery = toUnwrappedModel(userNotificationDelivery);
1176    
1177                    Session session = null;
1178    
1179                    try {
1180                            session = openSession();
1181    
1182                            if (!session.contains(userNotificationDelivery)) {
1183                                    userNotificationDelivery = (UserNotificationDelivery)session.get(UserNotificationDeliveryImpl.class,
1184                                                    userNotificationDelivery.getPrimaryKeyObj());
1185                            }
1186    
1187                            if (userNotificationDelivery != null) {
1188                                    session.delete(userNotificationDelivery);
1189                            }
1190                    }
1191                    catch (Exception e) {
1192                            throw processException(e);
1193                    }
1194                    finally {
1195                            closeSession(session);
1196                    }
1197    
1198                    if (userNotificationDelivery != null) {
1199                            clearCache(userNotificationDelivery);
1200                    }
1201    
1202                    return userNotificationDelivery;
1203            }
1204    
1205            @Override
1206            public UserNotificationDelivery updateImpl(
1207                    UserNotificationDelivery userNotificationDelivery) {
1208                    userNotificationDelivery = toUnwrappedModel(userNotificationDelivery);
1209    
1210                    boolean isNew = userNotificationDelivery.isNew();
1211    
1212                    UserNotificationDeliveryModelImpl userNotificationDeliveryModelImpl = (UserNotificationDeliveryModelImpl)userNotificationDelivery;
1213    
1214                    Session session = null;
1215    
1216                    try {
1217                            session = openSession();
1218    
1219                            if (userNotificationDelivery.isNew()) {
1220                                    session.save(userNotificationDelivery);
1221    
1222                                    userNotificationDelivery.setNew(false);
1223                            }
1224                            else {
1225                                    userNotificationDelivery = (UserNotificationDelivery)session.merge(userNotificationDelivery);
1226                            }
1227                    }
1228                    catch (Exception e) {
1229                            throw processException(e);
1230                    }
1231                    finally {
1232                            closeSession(session);
1233                    }
1234    
1235                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1236    
1237                    if (isNew || !UserNotificationDeliveryModelImpl.COLUMN_BITMASK_ENABLED) {
1238                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1239                    }
1240    
1241                    else {
1242                            if ((userNotificationDeliveryModelImpl.getColumnBitmask() &
1243                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1244                                    Object[] args = new Object[] {
1245                                                    userNotificationDeliveryModelImpl.getOriginalUserId()
1246                                            };
1247    
1248                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1249                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1250                                            args);
1251    
1252                                    args = new Object[] {
1253                                                    userNotificationDeliveryModelImpl.getUserId()
1254                                            };
1255    
1256                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1257                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1258                                            args);
1259                            }
1260                    }
1261    
1262                    entityCache.putResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1263                            UserNotificationDeliveryImpl.class,
1264                            userNotificationDelivery.getPrimaryKey(), userNotificationDelivery,
1265                            false);
1266    
1267                    clearUniqueFindersCache(userNotificationDeliveryModelImpl);
1268                    cacheUniqueFindersCache(userNotificationDeliveryModelImpl, isNew);
1269    
1270                    userNotificationDelivery.resetOriginalValues();
1271    
1272                    return userNotificationDelivery;
1273            }
1274    
1275            protected UserNotificationDelivery toUnwrappedModel(
1276                    UserNotificationDelivery userNotificationDelivery) {
1277                    if (userNotificationDelivery instanceof UserNotificationDeliveryImpl) {
1278                            return userNotificationDelivery;
1279                    }
1280    
1281                    UserNotificationDeliveryImpl userNotificationDeliveryImpl = new UserNotificationDeliveryImpl();
1282    
1283                    userNotificationDeliveryImpl.setNew(userNotificationDelivery.isNew());
1284                    userNotificationDeliveryImpl.setPrimaryKey(userNotificationDelivery.getPrimaryKey());
1285    
1286                    userNotificationDeliveryImpl.setMvccVersion(userNotificationDelivery.getMvccVersion());
1287                    userNotificationDeliveryImpl.setUserNotificationDeliveryId(userNotificationDelivery.getUserNotificationDeliveryId());
1288                    userNotificationDeliveryImpl.setCompanyId(userNotificationDelivery.getCompanyId());
1289                    userNotificationDeliveryImpl.setUserId(userNotificationDelivery.getUserId());
1290                    userNotificationDeliveryImpl.setPortletId(userNotificationDelivery.getPortletId());
1291                    userNotificationDeliveryImpl.setClassNameId(userNotificationDelivery.getClassNameId());
1292                    userNotificationDeliveryImpl.setNotificationType(userNotificationDelivery.getNotificationType());
1293                    userNotificationDeliveryImpl.setDeliveryType(userNotificationDelivery.getDeliveryType());
1294                    userNotificationDeliveryImpl.setDeliver(userNotificationDelivery.isDeliver());
1295    
1296                    return userNotificationDeliveryImpl;
1297            }
1298    
1299            /**
1300             * Returns the user notification delivery with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
1301             *
1302             * @param primaryKey the primary key of the user notification delivery
1303             * @return the user notification delivery
1304             * @throws NoSuchUserNotificationDeliveryException if a user notification delivery with the primary key could not be found
1305             */
1306            @Override
1307            public UserNotificationDelivery findByPrimaryKey(Serializable primaryKey)
1308                    throws NoSuchUserNotificationDeliveryException {
1309                    UserNotificationDelivery userNotificationDelivery = fetchByPrimaryKey(primaryKey);
1310    
1311                    if (userNotificationDelivery == null) {
1312                            if (_log.isWarnEnabled()) {
1313                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1314                            }
1315    
1316                            throw new NoSuchUserNotificationDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1317                                    primaryKey);
1318                    }
1319    
1320                    return userNotificationDelivery;
1321            }
1322    
1323            /**
1324             * Returns the user notification delivery with the primary key or throws a {@link NoSuchUserNotificationDeliveryException} if it could not be found.
1325             *
1326             * @param userNotificationDeliveryId the primary key of the user notification delivery
1327             * @return the user notification delivery
1328             * @throws NoSuchUserNotificationDeliveryException if a user notification delivery with the primary key could not be found
1329             */
1330            @Override
1331            public UserNotificationDelivery findByPrimaryKey(
1332                    long userNotificationDeliveryId)
1333                    throws NoSuchUserNotificationDeliveryException {
1334                    return findByPrimaryKey((Serializable)userNotificationDeliveryId);
1335            }
1336    
1337            /**
1338             * Returns the user notification delivery with the primary key or returns <code>null</code> if it could not be found.
1339             *
1340             * @param primaryKey the primary key of the user notification delivery
1341             * @return the user notification delivery, or <code>null</code> if a user notification delivery with the primary key could not be found
1342             */
1343            @Override
1344            public UserNotificationDelivery fetchByPrimaryKey(Serializable primaryKey) {
1345                    UserNotificationDelivery userNotificationDelivery = (UserNotificationDelivery)entityCache.getResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1346                                    UserNotificationDeliveryImpl.class, primaryKey);
1347    
1348                    if (userNotificationDelivery == _nullUserNotificationDelivery) {
1349                            return null;
1350                    }
1351    
1352                    if (userNotificationDelivery == null) {
1353                            Session session = null;
1354    
1355                            try {
1356                                    session = openSession();
1357    
1358                                    userNotificationDelivery = (UserNotificationDelivery)session.get(UserNotificationDeliveryImpl.class,
1359                                                    primaryKey);
1360    
1361                                    if (userNotificationDelivery != null) {
1362                                            cacheResult(userNotificationDelivery);
1363                                    }
1364                                    else {
1365                                            entityCache.putResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1366                                                    UserNotificationDeliveryImpl.class, primaryKey,
1367                                                    _nullUserNotificationDelivery);
1368                                    }
1369                            }
1370                            catch (Exception e) {
1371                                    entityCache.removeResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1372                                            UserNotificationDeliveryImpl.class, primaryKey);
1373    
1374                                    throw processException(e);
1375                            }
1376                            finally {
1377                                    closeSession(session);
1378                            }
1379                    }
1380    
1381                    return userNotificationDelivery;
1382            }
1383    
1384            /**
1385             * Returns the user notification delivery with the primary key or returns <code>null</code> if it could not be found.
1386             *
1387             * @param userNotificationDeliveryId the primary key of the user notification delivery
1388             * @return the user notification delivery, or <code>null</code> if a user notification delivery with the primary key could not be found
1389             */
1390            @Override
1391            public UserNotificationDelivery fetchByPrimaryKey(
1392                    long userNotificationDeliveryId) {
1393                    return fetchByPrimaryKey((Serializable)userNotificationDeliveryId);
1394            }
1395    
1396            @Override
1397            public Map<Serializable, UserNotificationDelivery> fetchByPrimaryKeys(
1398                    Set<Serializable> primaryKeys) {
1399                    if (primaryKeys.isEmpty()) {
1400                            return Collections.emptyMap();
1401                    }
1402    
1403                    Map<Serializable, UserNotificationDelivery> map = new HashMap<Serializable, UserNotificationDelivery>();
1404    
1405                    if (primaryKeys.size() == 1) {
1406                            Iterator<Serializable> iterator = primaryKeys.iterator();
1407    
1408                            Serializable primaryKey = iterator.next();
1409    
1410                            UserNotificationDelivery userNotificationDelivery = fetchByPrimaryKey(primaryKey);
1411    
1412                            if (userNotificationDelivery != null) {
1413                                    map.put(primaryKey, userNotificationDelivery);
1414                            }
1415    
1416                            return map;
1417                    }
1418    
1419                    Set<Serializable> uncachedPrimaryKeys = null;
1420    
1421                    for (Serializable primaryKey : primaryKeys) {
1422                            UserNotificationDelivery userNotificationDelivery = (UserNotificationDelivery)entityCache.getResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1423                                            UserNotificationDeliveryImpl.class, primaryKey);
1424    
1425                            if (userNotificationDelivery == null) {
1426                                    if (uncachedPrimaryKeys == null) {
1427                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1428                                    }
1429    
1430                                    uncachedPrimaryKeys.add(primaryKey);
1431                            }
1432                            else {
1433                                    map.put(primaryKey, userNotificationDelivery);
1434                            }
1435                    }
1436    
1437                    if (uncachedPrimaryKeys == null) {
1438                            return map;
1439                    }
1440    
1441                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1442                                    1);
1443    
1444                    query.append(_SQL_SELECT_USERNOTIFICATIONDELIVERY_WHERE_PKS_IN);
1445    
1446                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1447                            query.append(String.valueOf(primaryKey));
1448    
1449                            query.append(StringPool.COMMA);
1450                    }
1451    
1452                    query.setIndex(query.index() - 1);
1453    
1454                    query.append(StringPool.CLOSE_PARENTHESIS);
1455    
1456                    String sql = query.toString();
1457    
1458                    Session session = null;
1459    
1460                    try {
1461                            session = openSession();
1462    
1463                            Query q = session.createQuery(sql);
1464    
1465                            for (UserNotificationDelivery userNotificationDelivery : (List<UserNotificationDelivery>)q.list()) {
1466                                    map.put(userNotificationDelivery.getPrimaryKeyObj(),
1467                                            userNotificationDelivery);
1468    
1469                                    cacheResult(userNotificationDelivery);
1470    
1471                                    uncachedPrimaryKeys.remove(userNotificationDelivery.getPrimaryKeyObj());
1472                            }
1473    
1474                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1475                                    entityCache.putResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1476                                            UserNotificationDeliveryImpl.class, primaryKey,
1477                                            _nullUserNotificationDelivery);
1478                            }
1479                    }
1480                    catch (Exception e) {
1481                            throw processException(e);
1482                    }
1483                    finally {
1484                            closeSession(session);
1485                    }
1486    
1487                    return map;
1488            }
1489    
1490            /**
1491             * Returns all the user notification deliveries.
1492             *
1493             * @return the user notification deliveries
1494             */
1495            @Override
1496            public List<UserNotificationDelivery> findAll() {
1497                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1498            }
1499    
1500            /**
1501             * Returns a range of all the user notification deliveries.
1502             *
1503             * <p>
1504             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserNotificationDeliveryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1505             * </p>
1506             *
1507             * @param start the lower bound of the range of user notification deliveries
1508             * @param end the upper bound of the range of user notification deliveries (not inclusive)
1509             * @return the range of user notification deliveries
1510             */
1511            @Override
1512            public List<UserNotificationDelivery> findAll(int start, int end) {
1513                    return findAll(start, end, null);
1514            }
1515    
1516            /**
1517             * Returns an ordered range of all the user notification deliveries.
1518             *
1519             * <p>
1520             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserNotificationDeliveryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1521             * </p>
1522             *
1523             * @param start the lower bound of the range of user notification deliveries
1524             * @param end the upper bound of the range of user notification deliveries (not inclusive)
1525             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1526             * @return the ordered range of user notification deliveries
1527             */
1528            @Override
1529            public List<UserNotificationDelivery> findAll(int start, int end,
1530                    OrderByComparator<UserNotificationDelivery> orderByComparator) {
1531                    return findAll(start, end, orderByComparator, true);
1532            }
1533    
1534            /**
1535             * Returns an ordered range of all the user notification deliveries.
1536             *
1537             * <p>
1538             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserNotificationDeliveryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1539             * </p>
1540             *
1541             * @param start the lower bound of the range of user notification deliveries
1542             * @param end the upper bound of the range of user notification deliveries (not inclusive)
1543             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1544             * @param retrieveFromCache whether to retrieve from the finder cache
1545             * @return the ordered range of user notification deliveries
1546             */
1547            @Override
1548            public List<UserNotificationDelivery> findAll(int start, int end,
1549                    OrderByComparator<UserNotificationDelivery> orderByComparator,
1550                    boolean retrieveFromCache) {
1551                    boolean pagination = true;
1552                    FinderPath finderPath = null;
1553                    Object[] finderArgs = null;
1554    
1555                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1556                                    (orderByComparator == null)) {
1557                            pagination = false;
1558                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1559                            finderArgs = FINDER_ARGS_EMPTY;
1560                    }
1561                    else {
1562                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1563                            finderArgs = new Object[] { start, end, orderByComparator };
1564                    }
1565    
1566                    List<UserNotificationDelivery> list = null;
1567    
1568                    if (retrieveFromCache) {
1569                            list = (List<UserNotificationDelivery>)finderCache.getResult(finderPath,
1570                                            finderArgs, this);
1571                    }
1572    
1573                    if (list == null) {
1574                            StringBundler query = null;
1575                            String sql = null;
1576    
1577                            if (orderByComparator != null) {
1578                                    query = new StringBundler(2 +
1579                                                    (orderByComparator.getOrderByFields().length * 3));
1580    
1581                                    query.append(_SQL_SELECT_USERNOTIFICATIONDELIVERY);
1582    
1583                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1584                                            orderByComparator);
1585    
1586                                    sql = query.toString();
1587                            }
1588                            else {
1589                                    sql = _SQL_SELECT_USERNOTIFICATIONDELIVERY;
1590    
1591                                    if (pagination) {
1592                                            sql = sql.concat(UserNotificationDeliveryModelImpl.ORDER_BY_JPQL);
1593                                    }
1594                            }
1595    
1596                            Session session = null;
1597    
1598                            try {
1599                                    session = openSession();
1600    
1601                                    Query q = session.createQuery(sql);
1602    
1603                                    if (!pagination) {
1604                                            list = (List<UserNotificationDelivery>)QueryUtil.list(q,
1605                                                            getDialect(), start, end, false);
1606    
1607                                            Collections.sort(list);
1608    
1609                                            list = Collections.unmodifiableList(list);
1610                                    }
1611                                    else {
1612                                            list = (List<UserNotificationDelivery>)QueryUtil.list(q,
1613                                                            getDialect(), start, end);
1614                                    }
1615    
1616                                    cacheResult(list);
1617    
1618                                    finderCache.putResult(finderPath, finderArgs, list);
1619                            }
1620                            catch (Exception e) {
1621                                    finderCache.removeResult(finderPath, finderArgs);
1622    
1623                                    throw processException(e);
1624                            }
1625                            finally {
1626                                    closeSession(session);
1627                            }
1628                    }
1629    
1630                    return list;
1631            }
1632    
1633            /**
1634             * Removes all the user notification deliveries from the database.
1635             *
1636             */
1637            @Override
1638            public void removeAll() {
1639                    for (UserNotificationDelivery userNotificationDelivery : findAll()) {
1640                            remove(userNotificationDelivery);
1641                    }
1642            }
1643    
1644            /**
1645             * Returns the number of user notification deliveries.
1646             *
1647             * @return the number of user notification deliveries
1648             */
1649            @Override
1650            public int countAll() {
1651                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1652                                    FINDER_ARGS_EMPTY, this);
1653    
1654                    if (count == null) {
1655                            Session session = null;
1656    
1657                            try {
1658                                    session = openSession();
1659    
1660                                    Query q = session.createQuery(_SQL_COUNT_USERNOTIFICATIONDELIVERY);
1661    
1662                                    count = (Long)q.uniqueResult();
1663    
1664                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1665                                            count);
1666                            }
1667                            catch (Exception e) {
1668                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1669                                            FINDER_ARGS_EMPTY);
1670    
1671                                    throw processException(e);
1672                            }
1673                            finally {
1674                                    closeSession(session);
1675                            }
1676                    }
1677    
1678                    return count.intValue();
1679            }
1680    
1681            @Override
1682            protected Map<String, Integer> getTableColumnsMap() {
1683                    return UserNotificationDeliveryModelImpl.TABLE_COLUMNS_MAP;
1684            }
1685    
1686            /**
1687             * Initializes the user notification delivery persistence.
1688             */
1689            public void afterPropertiesSet() {
1690            }
1691    
1692            public void destroy() {
1693                    entityCache.removeCache(UserNotificationDeliveryImpl.class.getName());
1694                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1695                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1696                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1697            }
1698    
1699            @BeanReference(type = CompanyProviderWrapper.class)
1700            protected CompanyProvider companyProvider;
1701            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1702            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1703            private static final String _SQL_SELECT_USERNOTIFICATIONDELIVERY = "SELECT userNotificationDelivery FROM UserNotificationDelivery userNotificationDelivery";
1704            private static final String _SQL_SELECT_USERNOTIFICATIONDELIVERY_WHERE_PKS_IN =
1705                    "SELECT userNotificationDelivery FROM UserNotificationDelivery userNotificationDelivery WHERE userNotificationDeliveryId IN (";
1706            private static final String _SQL_SELECT_USERNOTIFICATIONDELIVERY_WHERE = "SELECT userNotificationDelivery FROM UserNotificationDelivery userNotificationDelivery WHERE ";
1707            private static final String _SQL_COUNT_USERNOTIFICATIONDELIVERY = "SELECT COUNT(userNotificationDelivery) FROM UserNotificationDelivery userNotificationDelivery";
1708            private static final String _SQL_COUNT_USERNOTIFICATIONDELIVERY_WHERE = "SELECT COUNT(userNotificationDelivery) FROM UserNotificationDelivery userNotificationDelivery WHERE ";
1709            private static final String _ORDER_BY_ENTITY_ALIAS = "userNotificationDelivery.";
1710            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserNotificationDelivery exists with the primary key ";
1711            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserNotificationDelivery exists with the key {";
1712            private static final Log _log = LogFactoryUtil.getLog(UserNotificationDeliveryPersistenceImpl.class);
1713            private static final UserNotificationDelivery _nullUserNotificationDelivery = new UserNotificationDeliveryImpl() {
1714                            @Override
1715                            public Object clone() {
1716                                    return this;
1717                            }
1718    
1719                            @Override
1720                            public CacheModel<UserNotificationDelivery> toCacheModel() {
1721                                    return _nullUserNotificationDeliveryCacheModel;
1722                            }
1723                    };
1724    
1725            private static final CacheModel<UserNotificationDelivery> _nullUserNotificationDeliveryCacheModel =
1726                    new NullCacheModel();
1727    
1728            private static class NullCacheModel implements CacheModel<UserNotificationDelivery>,
1729                    MVCCModel {
1730                    @Override
1731                    public long getMvccVersion() {
1732                            return -1;
1733                    }
1734    
1735                    @Override
1736                    public void setMvccVersion(long mvccVersion) {
1737                    }
1738    
1739                    @Override
1740                    public UserNotificationDelivery toEntityModel() {
1741                            return _nullUserNotificationDelivery;
1742                    }
1743            }
1744    }