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