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