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