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