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