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