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