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