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            /**
1976             * Caches the social activity limit in the entity cache if it is enabled.
1977             *
1978             * @param socialActivityLimit the social activity limit
1979             */
1980            @Override
1981            public void cacheResult(SocialActivityLimit socialActivityLimit) {
1982                    EntityCacheUtil.putResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
1983                            SocialActivityLimitImpl.class, socialActivityLimit.getPrimaryKey(),
1984                            socialActivityLimit);
1985    
1986                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1987                            new Object[] {
1988                                    socialActivityLimit.getGroupId(),
1989                                    socialActivityLimit.getUserId(),
1990                                    socialActivityLimit.getClassNameId(),
1991                                    socialActivityLimit.getClassPK(),
1992                                    socialActivityLimit.getActivityType(),
1993                                    socialActivityLimit.getActivityCounterName()
1994                            }, socialActivityLimit);
1995    
1996                    socialActivityLimit.resetOriginalValues();
1997            }
1998    
1999            /**
2000             * Caches the social activity limits in the entity cache if it is enabled.
2001             *
2002             * @param socialActivityLimits the social activity limits
2003             */
2004            @Override
2005            public void cacheResult(List<SocialActivityLimit> socialActivityLimits) {
2006                    for (SocialActivityLimit socialActivityLimit : socialActivityLimits) {
2007                            if (EntityCacheUtil.getResult(
2008                                                    SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
2009                                                    SocialActivityLimitImpl.class,
2010                                                    socialActivityLimit.getPrimaryKey()) == null) {
2011                                    cacheResult(socialActivityLimit);
2012                            }
2013                            else {
2014                                    socialActivityLimit.resetOriginalValues();
2015                            }
2016                    }
2017            }
2018    
2019            /**
2020             * Clears the cache for all social activity limits.
2021             *
2022             * <p>
2023             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2024             * </p>
2025             */
2026            @Override
2027            public void clearCache() {
2028                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2029                            CacheRegistryUtil.clear(SocialActivityLimitImpl.class.getName());
2030                    }
2031    
2032                    EntityCacheUtil.clearCache(SocialActivityLimitImpl.class.getName());
2033    
2034                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2035                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2036                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2037            }
2038    
2039            /**
2040             * Clears the cache for the social activity limit.
2041             *
2042             * <p>
2043             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2044             * </p>
2045             */
2046            @Override
2047            public void clearCache(SocialActivityLimit socialActivityLimit) {
2048                    EntityCacheUtil.removeResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
2049                            SocialActivityLimitImpl.class, socialActivityLimit.getPrimaryKey());
2050    
2051                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2052                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2053    
2054                    clearUniqueFindersCache(socialActivityLimit);
2055            }
2056    
2057            @Override
2058            public void clearCache(List<SocialActivityLimit> socialActivityLimits) {
2059                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2060                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2061    
2062                    for (SocialActivityLimit socialActivityLimit : socialActivityLimits) {
2063                            EntityCacheUtil.removeResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
2064                                    SocialActivityLimitImpl.class,
2065                                    socialActivityLimit.getPrimaryKey());
2066    
2067                            clearUniqueFindersCache(socialActivityLimit);
2068                    }
2069            }
2070    
2071            protected void cacheUniqueFindersCache(
2072                    SocialActivityLimit socialActivityLimit) {
2073                    if (socialActivityLimit.isNew()) {
2074                            Object[] args = new Object[] {
2075                                            socialActivityLimit.getGroupId(),
2076                                            socialActivityLimit.getUserId(),
2077                                            socialActivityLimit.getClassNameId(),
2078                                            socialActivityLimit.getClassPK(),
2079                                            socialActivityLimit.getActivityType(),
2080                                            socialActivityLimit.getActivityCounterName()
2081                                    };
2082    
2083                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A, args,
2084                                    Long.valueOf(1));
2085                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A, args,
2086                                    socialActivityLimit);
2087                    }
2088                    else {
2089                            SocialActivityLimitModelImpl socialActivityLimitModelImpl = (SocialActivityLimitModelImpl)socialActivityLimit;
2090    
2091                            if ((socialActivityLimitModelImpl.getColumnBitmask() &
2092                                            FINDER_PATH_FETCH_BY_G_U_C_C_A_A.getColumnBitmask()) != 0) {
2093                                    Object[] args = new Object[] {
2094                                                    socialActivityLimit.getGroupId(),
2095                                                    socialActivityLimit.getUserId(),
2096                                                    socialActivityLimit.getClassNameId(),
2097                                                    socialActivityLimit.getClassPK(),
2098                                                    socialActivityLimit.getActivityType(),
2099                                                    socialActivityLimit.getActivityCounterName()
2100                                            };
2101    
2102                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A,
2103                                            args, Long.valueOf(1));
2104                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
2105                                            args, socialActivityLimit);
2106                            }
2107                    }
2108            }
2109    
2110            protected void clearUniqueFindersCache(
2111                    SocialActivityLimit socialActivityLimit) {
2112                    SocialActivityLimitModelImpl socialActivityLimitModelImpl = (SocialActivityLimitModelImpl)socialActivityLimit;
2113    
2114                    Object[] args = new Object[] {
2115                                    socialActivityLimit.getGroupId(),
2116                                    socialActivityLimit.getUserId(),
2117                                    socialActivityLimit.getClassNameId(),
2118                                    socialActivityLimit.getClassPK(),
2119                                    socialActivityLimit.getActivityType(),
2120                                    socialActivityLimit.getActivityCounterName()
2121                            };
2122    
2123                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A, args);
2124                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A, args);
2125    
2126                    if ((socialActivityLimitModelImpl.getColumnBitmask() &
2127                                    FINDER_PATH_FETCH_BY_G_U_C_C_A_A.getColumnBitmask()) != 0) {
2128                            args = new Object[] {
2129                                            socialActivityLimitModelImpl.getOriginalGroupId(),
2130                                            socialActivityLimitModelImpl.getOriginalUserId(),
2131                                            socialActivityLimitModelImpl.getOriginalClassNameId(),
2132                                            socialActivityLimitModelImpl.getOriginalClassPK(),
2133                                            socialActivityLimitModelImpl.getOriginalActivityType(),
2134                                            socialActivityLimitModelImpl.getOriginalActivityCounterName()
2135                                    };
2136    
2137                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A, args);
2138                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A, args);
2139                    }
2140            }
2141    
2142            /**
2143             * Creates a new social activity limit with the primary key. Does not add the social activity limit to the database.
2144             *
2145             * @param activityLimitId the primary key for the new social activity limit
2146             * @return the new social activity limit
2147             */
2148            @Override
2149            public SocialActivityLimit create(long activityLimitId) {
2150                    SocialActivityLimit socialActivityLimit = new SocialActivityLimitImpl();
2151    
2152                    socialActivityLimit.setNew(true);
2153                    socialActivityLimit.setPrimaryKey(activityLimitId);
2154    
2155                    return socialActivityLimit;
2156            }
2157    
2158            /**
2159             * Removes the social activity limit with the primary key from the database. Also notifies the appropriate model listeners.
2160             *
2161             * @param activityLimitId the primary key of the social activity limit
2162             * @return the social activity limit that was removed
2163             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
2164             * @throws SystemException if a system exception occurred
2165             */
2166            @Override
2167            public SocialActivityLimit remove(long activityLimitId)
2168                    throws NoSuchActivityLimitException, SystemException {
2169                    return remove((Serializable)activityLimitId);
2170            }
2171    
2172            /**
2173             * Removes the social activity limit with the primary key from the database. Also notifies the appropriate model listeners.
2174             *
2175             * @param primaryKey the primary key of the social activity limit
2176             * @return the social activity limit that was removed
2177             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
2178             * @throws SystemException if a system exception occurred
2179             */
2180            @Override
2181            public SocialActivityLimit remove(Serializable primaryKey)
2182                    throws NoSuchActivityLimitException, SystemException {
2183                    Session session = null;
2184    
2185                    try {
2186                            session = openSession();
2187    
2188                            SocialActivityLimit socialActivityLimit = (SocialActivityLimit)session.get(SocialActivityLimitImpl.class,
2189                                            primaryKey);
2190    
2191                            if (socialActivityLimit == null) {
2192                                    if (_log.isWarnEnabled()) {
2193                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2194                                    }
2195    
2196                                    throw new NoSuchActivityLimitException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2197                                            primaryKey);
2198                            }
2199    
2200                            return remove(socialActivityLimit);
2201                    }
2202                    catch (NoSuchActivityLimitException nsee) {
2203                            throw nsee;
2204                    }
2205                    catch (Exception e) {
2206                            throw processException(e);
2207                    }
2208                    finally {
2209                            closeSession(session);
2210                    }
2211            }
2212    
2213            @Override
2214            protected SocialActivityLimit removeImpl(
2215                    SocialActivityLimit socialActivityLimit) throws SystemException {
2216                    socialActivityLimit = toUnwrappedModel(socialActivityLimit);
2217    
2218                    Session session = null;
2219    
2220                    try {
2221                            session = openSession();
2222    
2223                            if (!session.contains(socialActivityLimit)) {
2224                                    socialActivityLimit = (SocialActivityLimit)session.get(SocialActivityLimitImpl.class,
2225                                                    socialActivityLimit.getPrimaryKeyObj());
2226                            }
2227    
2228                            if (socialActivityLimit != null) {
2229                                    session.delete(socialActivityLimit);
2230                            }
2231                    }
2232                    catch (Exception e) {
2233                            throw processException(e);
2234                    }
2235                    finally {
2236                            closeSession(session);
2237                    }
2238    
2239                    if (socialActivityLimit != null) {
2240                            clearCache(socialActivityLimit);
2241                    }
2242    
2243                    return socialActivityLimit;
2244            }
2245    
2246            @Override
2247            public SocialActivityLimit updateImpl(
2248                    com.liferay.portlet.social.model.SocialActivityLimit socialActivityLimit)
2249                    throws SystemException {
2250                    socialActivityLimit = toUnwrappedModel(socialActivityLimit);
2251    
2252                    boolean isNew = socialActivityLimit.isNew();
2253    
2254                    SocialActivityLimitModelImpl socialActivityLimitModelImpl = (SocialActivityLimitModelImpl)socialActivityLimit;
2255    
2256                    Session session = null;
2257    
2258                    try {
2259                            session = openSession();
2260    
2261                            if (socialActivityLimit.isNew()) {
2262                                    session.save(socialActivityLimit);
2263    
2264                                    socialActivityLimit.setNew(false);
2265                            }
2266                            else {
2267                                    session.merge(socialActivityLimit);
2268                            }
2269                    }
2270                    catch (Exception e) {
2271                            throw processException(e);
2272                    }
2273                    finally {
2274                            closeSession(session);
2275                    }
2276    
2277                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2278    
2279                    if (isNew || !SocialActivityLimitModelImpl.COLUMN_BITMASK_ENABLED) {
2280                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2281                    }
2282    
2283                    else {
2284                            if ((socialActivityLimitModelImpl.getColumnBitmask() &
2285                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2286                                    Object[] args = new Object[] {
2287                                                    socialActivityLimitModelImpl.getOriginalGroupId()
2288                                            };
2289    
2290                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2291                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2292                                            args);
2293    
2294                                    args = new Object[] { socialActivityLimitModelImpl.getGroupId() };
2295    
2296                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2297                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2298                                            args);
2299                            }
2300    
2301                            if ((socialActivityLimitModelImpl.getColumnBitmask() &
2302                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2303                                    Object[] args = new Object[] {
2304                                                    socialActivityLimitModelImpl.getOriginalUserId()
2305                                            };
2306    
2307                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2308                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2309                                            args);
2310    
2311                                    args = new Object[] { socialActivityLimitModelImpl.getUserId() };
2312    
2313                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2314                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2315                                            args);
2316                            }
2317    
2318                            if ((socialActivityLimitModelImpl.getColumnBitmask() &
2319                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
2320                                    Object[] args = new Object[] {
2321                                                    socialActivityLimitModelImpl.getOriginalClassNameId(),
2322                                                    socialActivityLimitModelImpl.getOriginalClassPK()
2323                                            };
2324    
2325                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2326                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
2327                                            args);
2328    
2329                                    args = new Object[] {
2330                                                    socialActivityLimitModelImpl.getClassNameId(),
2331                                                    socialActivityLimitModelImpl.getClassPK()
2332                                            };
2333    
2334                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2335                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
2336                                            args);
2337                            }
2338                    }
2339    
2340                    EntityCacheUtil.putResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
2341                            SocialActivityLimitImpl.class, socialActivityLimit.getPrimaryKey(),
2342                            socialActivityLimit);
2343    
2344                    clearUniqueFindersCache(socialActivityLimit);
2345                    cacheUniqueFindersCache(socialActivityLimit);
2346    
2347                    return socialActivityLimit;
2348            }
2349    
2350            protected SocialActivityLimit toUnwrappedModel(
2351                    SocialActivityLimit socialActivityLimit) {
2352                    if (socialActivityLimit instanceof SocialActivityLimitImpl) {
2353                            return socialActivityLimit;
2354                    }
2355    
2356                    SocialActivityLimitImpl socialActivityLimitImpl = new SocialActivityLimitImpl();
2357    
2358                    socialActivityLimitImpl.setNew(socialActivityLimit.isNew());
2359                    socialActivityLimitImpl.setPrimaryKey(socialActivityLimit.getPrimaryKey());
2360    
2361                    socialActivityLimitImpl.setActivityLimitId(socialActivityLimit.getActivityLimitId());
2362                    socialActivityLimitImpl.setGroupId(socialActivityLimit.getGroupId());
2363                    socialActivityLimitImpl.setCompanyId(socialActivityLimit.getCompanyId());
2364                    socialActivityLimitImpl.setUserId(socialActivityLimit.getUserId());
2365                    socialActivityLimitImpl.setClassNameId(socialActivityLimit.getClassNameId());
2366                    socialActivityLimitImpl.setClassPK(socialActivityLimit.getClassPK());
2367                    socialActivityLimitImpl.setActivityType(socialActivityLimit.getActivityType());
2368                    socialActivityLimitImpl.setActivityCounterName(socialActivityLimit.getActivityCounterName());
2369                    socialActivityLimitImpl.setValue(socialActivityLimit.getValue());
2370    
2371                    return socialActivityLimitImpl;
2372            }
2373    
2374            /**
2375             * Returns the social activity limit with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2376             *
2377             * @param primaryKey the primary key of the social activity limit
2378             * @return the social activity limit
2379             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
2380             * @throws SystemException if a system exception occurred
2381             */
2382            @Override
2383            public SocialActivityLimit findByPrimaryKey(Serializable primaryKey)
2384                    throws NoSuchActivityLimitException, SystemException {
2385                    SocialActivityLimit socialActivityLimit = fetchByPrimaryKey(primaryKey);
2386    
2387                    if (socialActivityLimit == null) {
2388                            if (_log.isWarnEnabled()) {
2389                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2390                            }
2391    
2392                            throw new NoSuchActivityLimitException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2393                                    primaryKey);
2394                    }
2395    
2396                    return socialActivityLimit;
2397            }
2398    
2399            /**
2400             * Returns the social activity limit with the primary key or throws a {@link com.liferay.portlet.social.NoSuchActivityLimitException} if it could not be found.
2401             *
2402             * @param activityLimitId the primary key of the social activity limit
2403             * @return the social activity limit
2404             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
2405             * @throws SystemException if a system exception occurred
2406             */
2407            @Override
2408            public SocialActivityLimit findByPrimaryKey(long activityLimitId)
2409                    throws NoSuchActivityLimitException, SystemException {
2410                    return findByPrimaryKey((Serializable)activityLimitId);
2411            }
2412    
2413            /**
2414             * Returns the social activity limit with the primary key or returns <code>null</code> if it could not be found.
2415             *
2416             * @param primaryKey the primary key of the social activity limit
2417             * @return the social activity limit, or <code>null</code> if a social activity limit with the primary key could not be found
2418             * @throws SystemException if a system exception occurred
2419             */
2420            @Override
2421            public SocialActivityLimit fetchByPrimaryKey(Serializable primaryKey)
2422                    throws SystemException {
2423                    SocialActivityLimit socialActivityLimit = (SocialActivityLimit)EntityCacheUtil.getResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
2424                                    SocialActivityLimitImpl.class, primaryKey);
2425    
2426                    if (socialActivityLimit == _nullSocialActivityLimit) {
2427                            return null;
2428                    }
2429    
2430                    if (socialActivityLimit == null) {
2431                            Session session = null;
2432    
2433                            try {
2434                                    session = openSession();
2435    
2436                                    socialActivityLimit = (SocialActivityLimit)session.get(SocialActivityLimitImpl.class,
2437                                                    primaryKey);
2438    
2439                                    if (socialActivityLimit != null) {
2440                                            cacheResult(socialActivityLimit);
2441                                    }
2442                                    else {
2443                                            EntityCacheUtil.putResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
2444                                                    SocialActivityLimitImpl.class, primaryKey,
2445                                                    _nullSocialActivityLimit);
2446                                    }
2447                            }
2448                            catch (Exception e) {
2449                                    EntityCacheUtil.removeResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
2450                                            SocialActivityLimitImpl.class, primaryKey);
2451    
2452                                    throw processException(e);
2453                            }
2454                            finally {
2455                                    closeSession(session);
2456                            }
2457                    }
2458    
2459                    return socialActivityLimit;
2460            }
2461    
2462            /**
2463             * Returns the social activity limit with the primary key or returns <code>null</code> if it could not be found.
2464             *
2465             * @param activityLimitId the primary key of the social activity limit
2466             * @return the social activity limit, or <code>null</code> if a social activity limit with the primary key could not be found
2467             * @throws SystemException if a system exception occurred
2468             */
2469            @Override
2470            public SocialActivityLimit fetchByPrimaryKey(long activityLimitId)
2471                    throws SystemException {
2472                    return fetchByPrimaryKey((Serializable)activityLimitId);
2473            }
2474    
2475            /**
2476             * Returns all the social activity limits.
2477             *
2478             * @return the social activity limits
2479             * @throws SystemException if a system exception occurred
2480             */
2481            @Override
2482            public List<SocialActivityLimit> findAll() throws SystemException {
2483                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2484            }
2485    
2486            /**
2487             * Returns a range of all the social activity limits.
2488             *
2489             * <p>
2490             * 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.
2491             * </p>
2492             *
2493             * @param start the lower bound of the range of social activity limits
2494             * @param end the upper bound of the range of social activity limits (not inclusive)
2495             * @return the range of social activity limits
2496             * @throws SystemException if a system exception occurred
2497             */
2498            @Override
2499            public List<SocialActivityLimit> findAll(int start, int end)
2500                    throws SystemException {
2501                    return findAll(start, end, null);
2502            }
2503    
2504            /**
2505             * Returns an ordered range of all the social activity limits.
2506             *
2507             * <p>
2508             * 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.
2509             * </p>
2510             *
2511             * @param start the lower bound of the range of social activity limits
2512             * @param end the upper bound of the range of social activity limits (not inclusive)
2513             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2514             * @return the ordered range of social activity limits
2515             * @throws SystemException if a system exception occurred
2516             */
2517            @Override
2518            public List<SocialActivityLimit> findAll(int start, int end,
2519                    OrderByComparator orderByComparator) throws SystemException {
2520                    boolean pagination = true;
2521                    FinderPath finderPath = null;
2522                    Object[] finderArgs = null;
2523    
2524                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2525                                    (orderByComparator == null)) {
2526                            pagination = false;
2527                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2528                            finderArgs = FINDER_ARGS_EMPTY;
2529                    }
2530                    else {
2531                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2532                            finderArgs = new Object[] { start, end, orderByComparator };
2533                    }
2534    
2535                    List<SocialActivityLimit> list = (List<SocialActivityLimit>)FinderCacheUtil.getResult(finderPath,
2536                                    finderArgs, this);
2537    
2538                    if (list == null) {
2539                            StringBundler query = null;
2540                            String sql = null;
2541    
2542                            if (orderByComparator != null) {
2543                                    query = new StringBundler(2 +
2544                                                    (orderByComparator.getOrderByFields().length * 3));
2545    
2546                                    query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT);
2547    
2548                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2549                                            orderByComparator);
2550    
2551                                    sql = query.toString();
2552                            }
2553                            else {
2554                                    sql = _SQL_SELECT_SOCIALACTIVITYLIMIT;
2555    
2556                                    if (pagination) {
2557                                            sql = sql.concat(SocialActivityLimitModelImpl.ORDER_BY_JPQL);
2558                                    }
2559                            }
2560    
2561                            Session session = null;
2562    
2563                            try {
2564                                    session = openSession();
2565    
2566                                    Query q = session.createQuery(sql);
2567    
2568                                    if (!pagination) {
2569                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
2570                                                            getDialect(), start, end, false);
2571    
2572                                            Collections.sort(list);
2573    
2574                                            list = new UnmodifiableList<SocialActivityLimit>(list);
2575                                    }
2576                                    else {
2577                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
2578                                                            getDialect(), start, end);
2579                                    }
2580    
2581                                    cacheResult(list);
2582    
2583                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2584                            }
2585                            catch (Exception e) {
2586                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2587    
2588                                    throw processException(e);
2589                            }
2590                            finally {
2591                                    closeSession(session);
2592                            }
2593                    }
2594    
2595                    return list;
2596            }
2597    
2598            /**
2599             * Removes all the social activity limits from the database.
2600             *
2601             * @throws SystemException if a system exception occurred
2602             */
2603            @Override
2604            public void removeAll() throws SystemException {
2605                    for (SocialActivityLimit socialActivityLimit : findAll()) {
2606                            remove(socialActivityLimit);
2607                    }
2608            }
2609    
2610            /**
2611             * Returns the number of social activity limits.
2612             *
2613             * @return the number of social activity limits
2614             * @throws SystemException if a system exception occurred
2615             */
2616            @Override
2617            public int countAll() throws SystemException {
2618                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2619                                    FINDER_ARGS_EMPTY, this);
2620    
2621                    if (count == null) {
2622                            Session session = null;
2623    
2624                            try {
2625                                    session = openSession();
2626    
2627                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITYLIMIT);
2628    
2629                                    count = (Long)q.uniqueResult();
2630    
2631                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2632                                            FINDER_ARGS_EMPTY, count);
2633                            }
2634                            catch (Exception e) {
2635                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2636                                            FINDER_ARGS_EMPTY);
2637    
2638                                    throw processException(e);
2639                            }
2640                            finally {
2641                                    closeSession(session);
2642                            }
2643                    }
2644    
2645                    return count.intValue();
2646            }
2647    
2648            /**
2649             * Initializes the social activity limit persistence.
2650             */
2651            public void afterPropertiesSet() {
2652                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2653                                            com.liferay.portal.util.PropsUtil.get(
2654                                                    "value.object.listener.com.liferay.portlet.social.model.SocialActivityLimit")));
2655    
2656                    if (listenerClassNames.length > 0) {
2657                            try {
2658                                    List<ModelListener<SocialActivityLimit>> listenersList = new ArrayList<ModelListener<SocialActivityLimit>>();
2659    
2660                                    for (String listenerClassName : listenerClassNames) {
2661                                            listenersList.add((ModelListener<SocialActivityLimit>)InstanceFactory.newInstance(
2662                                                            getClassLoader(), listenerClassName));
2663                                    }
2664    
2665                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2666                            }
2667                            catch (Exception e) {
2668                                    _log.error(e);
2669                            }
2670                    }
2671            }
2672    
2673            public void destroy() {
2674                    EntityCacheUtil.removeCache(SocialActivityLimitImpl.class.getName());
2675                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2676                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2677                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2678            }
2679    
2680            private static final String _SQL_SELECT_SOCIALACTIVITYLIMIT = "SELECT socialActivityLimit FROM SocialActivityLimit socialActivityLimit";
2681            private static final String _SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE = "SELECT socialActivityLimit FROM SocialActivityLimit socialActivityLimit WHERE ";
2682            private static final String _SQL_COUNT_SOCIALACTIVITYLIMIT = "SELECT COUNT(socialActivityLimit) FROM SocialActivityLimit socialActivityLimit";
2683            private static final String _SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE = "SELECT COUNT(socialActivityLimit) FROM SocialActivityLimit socialActivityLimit WHERE ";
2684            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivityLimit.";
2685            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivityLimit exists with the primary key ";
2686            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialActivityLimit exists with the key {";
2687            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2688            private static Log _log = LogFactoryUtil.getLog(SocialActivityLimitPersistenceImpl.class);
2689            private static SocialActivityLimit _nullSocialActivityLimit = new SocialActivityLimitImpl() {
2690                            @Override
2691                            public Object clone() {
2692                                    return this;
2693                            }
2694    
2695                            @Override
2696                            public CacheModel<SocialActivityLimit> toCacheModel() {
2697                                    return _nullSocialActivityLimitCacheModel;
2698                            }
2699                    };
2700    
2701            private static CacheModel<SocialActivityLimit> _nullSocialActivityLimitCacheModel =
2702                    new CacheModel<SocialActivityLimit>() {
2703                            @Override
2704                            public SocialActivityLimit toEntityModel() {
2705                                    return _nullSocialActivityLimit;
2706                            }
2707                    };
2708    }