001    /**
002     * Copyright (c) 2000-2012 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;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
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.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040    
041    import com.liferay.portlet.social.NoSuchActivityLimitException;
042    import com.liferay.portlet.social.model.SocialActivityLimit;
043    import com.liferay.portlet.social.model.impl.SocialActivityLimitImpl;
044    import com.liferay.portlet.social.model.impl.SocialActivityLimitModelImpl;
045    
046    import java.io.Serializable;
047    
048    import java.util.ArrayList;
049    import java.util.Collections;
050    import java.util.List;
051    
052    /**
053     * The persistence implementation for the social activity limit service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see SocialActivityLimitPersistence
061     * @see SocialActivityLimitUtil
062     * @generated
063     */
064    public class SocialActivityLimitPersistenceImpl extends BasePersistenceImpl<SocialActivityLimit>
065            implements SocialActivityLimitPersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * Never modify or reference this class directly. Always use {@link SocialActivityLimitUtil} to access the social activity limit persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = SocialActivityLimitImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
077                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED,
078                            SocialActivityLimitImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
081                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED,
082                            SocialActivityLimitImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
085                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
088                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED,
089                            SocialActivityLimitImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
091                            new String[] {
092                                    Long.class.getName(),
093                                    
094                            Integer.class.getName(), Integer.class.getName(),
095                                    OrderByComparator.class.getName()
096                            });
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
098                    new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
099                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED,
100                            SocialActivityLimitImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
102                            new String[] { Long.class.getName() },
103                            SocialActivityLimitModelImpl.USERID_COLUMN_BITMASK);
104            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
105                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED, Long.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
107                            new String[] { Long.class.getName() });
108    
109            /**
110             * Returns all the social activity limits where userId = &#63;.
111             *
112             * @param userId the user ID
113             * @return the matching social activity limits
114             * @throws SystemException if a system exception occurred
115             */
116            public List<SocialActivityLimit> findByUserId(long userId)
117                    throws SystemException {
118                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
119            }
120    
121            /**
122             * Returns a range of all the social activity limits where userId = &#63;.
123             *
124             * <p>
125             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
126             * </p>
127             *
128             * @param userId the user ID
129             * @param start the lower bound of the range of social activity limits
130             * @param end the upper bound of the range of social activity limits (not inclusive)
131             * @return the range of matching social activity limits
132             * @throws SystemException if a system exception occurred
133             */
134            public List<SocialActivityLimit> findByUserId(long userId, int start,
135                    int end) throws SystemException {
136                    return findByUserId(userId, start, end, null);
137            }
138    
139            /**
140             * Returns an ordered range of all the social activity limits where userId = &#63;.
141             *
142             * <p>
143             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
144             * </p>
145             *
146             * @param userId the user ID
147             * @param start the lower bound of the range of social activity limits
148             * @param end the upper bound of the range of social activity limits (not inclusive)
149             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
150             * @return the ordered range of matching social activity limits
151             * @throws SystemException if a system exception occurred
152             */
153            public List<SocialActivityLimit> findByUserId(long userId, int start,
154                    int end, OrderByComparator orderByComparator) throws SystemException {
155                    boolean pagination = true;
156                    FinderPath finderPath = null;
157                    Object[] finderArgs = null;
158    
159                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160                                    (orderByComparator == null)) {
161                            pagination = false;
162                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
163                            finderArgs = new Object[] { userId };
164                    }
165                    else {
166                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
167                            finderArgs = new Object[] { userId, start, end, orderByComparator };
168                    }
169    
170                    List<SocialActivityLimit> list = (List<SocialActivityLimit>)FinderCacheUtil.getResult(finderPath,
171                                    finderArgs, this);
172    
173                    if ((list != null) && !list.isEmpty()) {
174                            for (SocialActivityLimit socialActivityLimit : list) {
175                                    if ((userId != socialActivityLimit.getUserId())) {
176                                            list = null;
177    
178                                            break;
179                                    }
180                            }
181                    }
182    
183                    if (list == null) {
184                            StringBundler query = null;
185    
186                            if (orderByComparator != null) {
187                                    query = new StringBundler(3 +
188                                                    (orderByComparator.getOrderByFields().length * 3));
189                            }
190                            else {
191                                    query = new StringBundler(3);
192                            }
193    
194                            query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
195    
196                            query.append(_FINDER_COLUMN_USERID_USERID_2);
197    
198                            if (orderByComparator != null) {
199                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
200                                            orderByComparator);
201                            }
202                            else
203                             if (pagination) {
204                                    query.append(SocialActivityLimitModelImpl.ORDER_BY_JPQL);
205                            }
206    
207                            String sql = query.toString();
208    
209                            Session session = null;
210    
211                            try {
212                                    session = openSession();
213    
214                                    Query q = session.createQuery(sql);
215    
216                                    QueryPos qPos = QueryPos.getInstance(q);
217    
218                                    qPos.add(userId);
219    
220                                    if (!pagination) {
221                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
222                                                            getDialect(), start, end, false);
223    
224                                            Collections.sort(list);
225    
226                                            list = new UnmodifiableList<SocialActivityLimit>(list);
227                                    }
228                                    else {
229                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
230                                                            getDialect(), start, end);
231                                    }
232    
233                                    cacheResult(list);
234    
235                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
236                            }
237                            catch (Exception e) {
238                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
239    
240                                    throw processException(e);
241                            }
242                            finally {
243                                    closeSession(session);
244                            }
245                    }
246    
247                    return list;
248            }
249    
250            /**
251             * Returns the first social activity limit in the ordered set where userId = &#63;.
252             *
253             * @param userId the user ID
254             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
255             * @return the first matching social activity limit
256             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
257             * @throws SystemException if a system exception occurred
258             */
259            public SocialActivityLimit findByUserId_First(long userId,
260                    OrderByComparator orderByComparator)
261                    throws NoSuchActivityLimitException, SystemException {
262                    SocialActivityLimit socialActivityLimit = fetchByUserId_First(userId,
263                                    orderByComparator);
264    
265                    if (socialActivityLimit != null) {
266                            return socialActivityLimit;
267                    }
268    
269                    StringBundler msg = new StringBundler(4);
270    
271                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
272    
273                    msg.append("userId=");
274                    msg.append(userId);
275    
276                    msg.append(StringPool.CLOSE_CURLY_BRACE);
277    
278                    throw new NoSuchActivityLimitException(msg.toString());
279            }
280    
281            /**
282             * Returns the first social activity limit in the ordered set where userId = &#63;.
283             *
284             * @param userId the user ID
285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
286             * @return the first matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
287             * @throws SystemException if a system exception occurred
288             */
289            public SocialActivityLimit fetchByUserId_First(long userId,
290                    OrderByComparator orderByComparator) throws SystemException {
291                    List<SocialActivityLimit> list = findByUserId(userId, 0, 1,
292                                    orderByComparator);
293    
294                    if (!list.isEmpty()) {
295                            return list.get(0);
296                    }
297    
298                    return null;
299            }
300    
301            /**
302             * Returns the last social activity limit in the ordered set where userId = &#63;.
303             *
304             * @param userId the user ID
305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
306             * @return the last matching social activity limit
307             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
308             * @throws SystemException if a system exception occurred
309             */
310            public SocialActivityLimit findByUserId_Last(long userId,
311                    OrderByComparator orderByComparator)
312                    throws NoSuchActivityLimitException, SystemException {
313                    SocialActivityLimit socialActivityLimit = fetchByUserId_Last(userId,
314                                    orderByComparator);
315    
316                    if (socialActivityLimit != null) {
317                            return socialActivityLimit;
318                    }
319    
320                    StringBundler msg = new StringBundler(4);
321    
322                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
323    
324                    msg.append("userId=");
325                    msg.append(userId);
326    
327                    msg.append(StringPool.CLOSE_CURLY_BRACE);
328    
329                    throw new NoSuchActivityLimitException(msg.toString());
330            }
331    
332            /**
333             * Returns the last social activity limit in the ordered set where userId = &#63;.
334             *
335             * @param userId the user ID
336             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
337             * @return the last matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
338             * @throws SystemException if a system exception occurred
339             */
340            public SocialActivityLimit fetchByUserId_Last(long userId,
341                    OrderByComparator orderByComparator) throws SystemException {
342                    int count = countByUserId(userId);
343    
344                    List<SocialActivityLimit> list = findByUserId(userId, count - 1, count,
345                                    orderByComparator);
346    
347                    if (!list.isEmpty()) {
348                            return list.get(0);
349                    }
350    
351                    return null;
352            }
353    
354            /**
355             * Returns the social activity limits before and after the current social activity limit in the ordered set where userId = &#63;.
356             *
357             * @param activityLimitId the primary key of the current social activity limit
358             * @param userId the user ID
359             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
360             * @return the previous, current, and next social activity limit
361             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
362             * @throws SystemException if a system exception occurred
363             */
364            public SocialActivityLimit[] findByUserId_PrevAndNext(
365                    long activityLimitId, long userId, OrderByComparator orderByComparator)
366                    throws NoSuchActivityLimitException, SystemException {
367                    SocialActivityLimit socialActivityLimit = findByPrimaryKey(activityLimitId);
368    
369                    Session session = null;
370    
371                    try {
372                            session = openSession();
373    
374                            SocialActivityLimit[] array = new SocialActivityLimitImpl[3];
375    
376                            array[0] = getByUserId_PrevAndNext(session, socialActivityLimit,
377                                            userId, orderByComparator, true);
378    
379                            array[1] = socialActivityLimit;
380    
381                            array[2] = getByUserId_PrevAndNext(session, socialActivityLimit,
382                                            userId, orderByComparator, false);
383    
384                            return array;
385                    }
386                    catch (Exception e) {
387                            throw processException(e);
388                    }
389                    finally {
390                            closeSession(session);
391                    }
392            }
393    
394            protected SocialActivityLimit getByUserId_PrevAndNext(Session session,
395                    SocialActivityLimit socialActivityLimit, long userId,
396                    OrderByComparator orderByComparator, boolean previous) {
397                    StringBundler query = null;
398    
399                    if (orderByComparator != null) {
400                            query = new StringBundler(6 +
401                                            (orderByComparator.getOrderByFields().length * 6));
402                    }
403                    else {
404                            query = new StringBundler(3);
405                    }
406    
407                    query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
408    
409                    query.append(_FINDER_COLUMN_USERID_USERID_2);
410    
411                    if (orderByComparator != null) {
412                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
413    
414                            if (orderByConditionFields.length > 0) {
415                                    query.append(WHERE_AND);
416                            }
417    
418                            for (int i = 0; i < orderByConditionFields.length; i++) {
419                                    query.append(_ORDER_BY_ENTITY_ALIAS);
420                                    query.append(orderByConditionFields[i]);
421    
422                                    if ((i + 1) < orderByConditionFields.length) {
423                                            if (orderByComparator.isAscending() ^ previous) {
424                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
425                                            }
426                                            else {
427                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
428                                            }
429                                    }
430                                    else {
431                                            if (orderByComparator.isAscending() ^ previous) {
432                                                    query.append(WHERE_GREATER_THAN);
433                                            }
434                                            else {
435                                                    query.append(WHERE_LESSER_THAN);
436                                            }
437                                    }
438                            }
439    
440                            query.append(ORDER_BY_CLAUSE);
441    
442                            String[] orderByFields = orderByComparator.getOrderByFields();
443    
444                            for (int i = 0; i < orderByFields.length; i++) {
445                                    query.append(_ORDER_BY_ENTITY_ALIAS);
446                                    query.append(orderByFields[i]);
447    
448                                    if ((i + 1) < orderByFields.length) {
449                                            if (orderByComparator.isAscending() ^ previous) {
450                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
451                                            }
452                                            else {
453                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
454                                            }
455                                    }
456                                    else {
457                                            if (orderByComparator.isAscending() ^ previous) {
458                                                    query.append(ORDER_BY_ASC);
459                                            }
460                                            else {
461                                                    query.append(ORDER_BY_DESC);
462                                            }
463                                    }
464                            }
465                    }
466                    else {
467                            query.append(SocialActivityLimitModelImpl.ORDER_BY_JPQL);
468                    }
469    
470                    String sql = query.toString();
471    
472                    Query q = session.createQuery(sql);
473    
474                    q.setFirstResult(0);
475                    q.setMaxResults(2);
476    
477                    QueryPos qPos = QueryPos.getInstance(q);
478    
479                    qPos.add(userId);
480    
481                    if (orderByComparator != null) {
482                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivityLimit);
483    
484                            for (Object value : values) {
485                                    qPos.add(value);
486                            }
487                    }
488    
489                    List<SocialActivityLimit> list = q.list();
490    
491                    if (list.size() == 2) {
492                            return list.get(1);
493                    }
494                    else {
495                            return null;
496                    }
497            }
498    
499            /**
500             * Removes all the social activity limits where userId = &#63; from the database.
501             *
502             * @param userId the user ID
503             * @throws SystemException if a system exception occurred
504             */
505            public void removeByUserId(long userId) throws SystemException {
506                    for (SocialActivityLimit socialActivityLimit : findByUserId(userId,
507                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
508                            remove(socialActivityLimit);
509                    }
510            }
511    
512            /**
513             * Returns the number of social activity limits where userId = &#63;.
514             *
515             * @param userId the user ID
516             * @return the number of matching social activity limits
517             * @throws SystemException if a system exception occurred
518             */
519            public int countByUserId(long userId) throws SystemException {
520                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
521    
522                    Object[] finderArgs = new Object[] { userId };
523    
524                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
525                                    this);
526    
527                    if (count == null) {
528                            StringBundler query = new StringBundler(2);
529    
530                            query.append(_SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE);
531    
532                            query.append(_FINDER_COLUMN_USERID_USERID_2);
533    
534                            String sql = query.toString();
535    
536                            Session session = null;
537    
538                            try {
539                                    session = openSession();
540    
541                                    Query q = session.createQuery(sql);
542    
543                                    QueryPos qPos = QueryPos.getInstance(q);
544    
545                                    qPos.add(userId);
546    
547                                    count = (Long)q.uniqueResult();
548    
549                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
550                            }
551                            catch (Exception e) {
552                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
553    
554                                    throw processException(e);
555                            }
556                            finally {
557                                    closeSession(session);
558                            }
559                    }
560    
561                    return count.intValue();
562            }
563    
564            private static final String _FINDER_COLUMN_USERID_USERID_2 = "socialActivityLimit.userId = ?";
565            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
566                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED,
567                            SocialActivityLimitImpl.class,
568                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
569                            new String[] {
570                                    Long.class.getName(), Long.class.getName(),
571                                    
572                            Integer.class.getName(), Integer.class.getName(),
573                                    OrderByComparator.class.getName()
574                            });
575            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
576                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED,
577                            SocialActivityLimitImpl.class,
578                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
579                            new String[] { Long.class.getName(), Long.class.getName() },
580                            SocialActivityLimitModelImpl.CLASSNAMEID_COLUMN_BITMASK |
581                            SocialActivityLimitModelImpl.CLASSPK_COLUMN_BITMASK);
582            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
583                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED, Long.class,
584                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
585                            new String[] { Long.class.getName(), Long.class.getName() });
586    
587            /**
588             * Returns all the social activity limits where classNameId = &#63; and classPK = &#63;.
589             *
590             * @param classNameId the class name ID
591             * @param classPK the class p k
592             * @return the matching social activity limits
593             * @throws SystemException if a system exception occurred
594             */
595            public List<SocialActivityLimit> findByC_C(long classNameId, long classPK)
596                    throws SystemException {
597                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
598                            QueryUtil.ALL_POS, null);
599            }
600    
601            /**
602             * Returns a range of all the social activity limits where classNameId = &#63; and classPK = &#63;.
603             *
604             * <p>
605             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
606             * </p>
607             *
608             * @param classNameId the class name ID
609             * @param classPK the class p k
610             * @param start the lower bound of the range of social activity limits
611             * @param end the upper bound of the range of social activity limits (not inclusive)
612             * @return the range of matching social activity limits
613             * @throws SystemException if a system exception occurred
614             */
615            public List<SocialActivityLimit> findByC_C(long classNameId, long classPK,
616                    int start, int end) throws SystemException {
617                    return findByC_C(classNameId, classPK, start, end, null);
618            }
619    
620            /**
621             * Returns an ordered range of all the social activity limits where classNameId = &#63; and classPK = &#63;.
622             *
623             * <p>
624             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
625             * </p>
626             *
627             * @param classNameId the class name ID
628             * @param classPK the class p k
629             * @param start the lower bound of the range of social activity limits
630             * @param end the upper bound of the range of social activity limits (not inclusive)
631             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
632             * @return the ordered range of matching social activity limits
633             * @throws SystemException if a system exception occurred
634             */
635            public List<SocialActivityLimit> findByC_C(long classNameId, long classPK,
636                    int start, int end, OrderByComparator orderByComparator)
637                    throws SystemException {
638                    boolean pagination = true;
639                    FinderPath finderPath = null;
640                    Object[] finderArgs = null;
641    
642                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
643                                    (orderByComparator == null)) {
644                            pagination = false;
645                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
646                            finderArgs = new Object[] { classNameId, classPK };
647                    }
648                    else {
649                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
650                            finderArgs = new Object[] {
651                                            classNameId, classPK,
652                                            
653                                            start, end, orderByComparator
654                                    };
655                    }
656    
657                    List<SocialActivityLimit> list = (List<SocialActivityLimit>)FinderCacheUtil.getResult(finderPath,
658                                    finderArgs, this);
659    
660                    if ((list != null) && !list.isEmpty()) {
661                            for (SocialActivityLimit socialActivityLimit : list) {
662                                    if ((classNameId != socialActivityLimit.getClassNameId()) ||
663                                                    (classPK != socialActivityLimit.getClassPK())) {
664                                            list = null;
665    
666                                            break;
667                                    }
668                            }
669                    }
670    
671                    if (list == null) {
672                            StringBundler query = null;
673    
674                            if (orderByComparator != null) {
675                                    query = new StringBundler(4 +
676                                                    (orderByComparator.getOrderByFields().length * 3));
677                            }
678                            else {
679                                    query = new StringBundler(4);
680                            }
681    
682                            query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
683    
684                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
685    
686                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
687    
688                            if (orderByComparator != null) {
689                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
690                                            orderByComparator);
691                            }
692                            else
693                             if (pagination) {
694                                    query.append(SocialActivityLimitModelImpl.ORDER_BY_JPQL);
695                            }
696    
697                            String sql = query.toString();
698    
699                            Session session = null;
700    
701                            try {
702                                    session = openSession();
703    
704                                    Query q = session.createQuery(sql);
705    
706                                    QueryPos qPos = QueryPos.getInstance(q);
707    
708                                    qPos.add(classNameId);
709    
710                                    qPos.add(classPK);
711    
712                                    if (!pagination) {
713                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
714                                                            getDialect(), start, end, false);
715    
716                                            Collections.sort(list);
717    
718                                            list = new UnmodifiableList<SocialActivityLimit>(list);
719                                    }
720                                    else {
721                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
722                                                            getDialect(), start, end);
723                                    }
724    
725                                    cacheResult(list);
726    
727                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
728                            }
729                            catch (Exception e) {
730                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
731    
732                                    throw processException(e);
733                            }
734                            finally {
735                                    closeSession(session);
736                            }
737                    }
738    
739                    return list;
740            }
741    
742            /**
743             * Returns the first social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
744             *
745             * @param classNameId the class name ID
746             * @param classPK the class p k
747             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
748             * @return the first matching social activity limit
749             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
750             * @throws SystemException if a system exception occurred
751             */
752            public SocialActivityLimit findByC_C_First(long classNameId, long classPK,
753                    OrderByComparator orderByComparator)
754                    throws NoSuchActivityLimitException, SystemException {
755                    SocialActivityLimit socialActivityLimit = fetchByC_C_First(classNameId,
756                                    classPK, orderByComparator);
757    
758                    if (socialActivityLimit != null) {
759                            return socialActivityLimit;
760                    }
761    
762                    StringBundler msg = new StringBundler(6);
763    
764                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
765    
766                    msg.append("classNameId=");
767                    msg.append(classNameId);
768    
769                    msg.append(", classPK=");
770                    msg.append(classPK);
771    
772                    msg.append(StringPool.CLOSE_CURLY_BRACE);
773    
774                    throw new NoSuchActivityLimitException(msg.toString());
775            }
776    
777            /**
778             * Returns the first social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
779             *
780             * @param classNameId the class name ID
781             * @param classPK the class p k
782             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
783             * @return the first matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
784             * @throws SystemException if a system exception occurred
785             */
786            public SocialActivityLimit fetchByC_C_First(long classNameId, long classPK,
787                    OrderByComparator orderByComparator) throws SystemException {
788                    List<SocialActivityLimit> list = findByC_C(classNameId, classPK, 0, 1,
789                                    orderByComparator);
790    
791                    if (!list.isEmpty()) {
792                            return list.get(0);
793                    }
794    
795                    return null;
796            }
797    
798            /**
799             * Returns the last social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
800             *
801             * @param classNameId the class name ID
802             * @param classPK the class p k
803             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
804             * @return the last matching social activity limit
805             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
806             * @throws SystemException if a system exception occurred
807             */
808            public SocialActivityLimit findByC_C_Last(long classNameId, long classPK,
809                    OrderByComparator orderByComparator)
810                    throws NoSuchActivityLimitException, SystemException {
811                    SocialActivityLimit socialActivityLimit = fetchByC_C_Last(classNameId,
812                                    classPK, orderByComparator);
813    
814                    if (socialActivityLimit != null) {
815                            return socialActivityLimit;
816                    }
817    
818                    StringBundler msg = new StringBundler(6);
819    
820                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
821    
822                    msg.append("classNameId=");
823                    msg.append(classNameId);
824    
825                    msg.append(", classPK=");
826                    msg.append(classPK);
827    
828                    msg.append(StringPool.CLOSE_CURLY_BRACE);
829    
830                    throw new NoSuchActivityLimitException(msg.toString());
831            }
832    
833            /**
834             * Returns the last social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
835             *
836             * @param classNameId the class name ID
837             * @param classPK the class p k
838             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
839             * @return the last matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
840             * @throws SystemException if a system exception occurred
841             */
842            public SocialActivityLimit fetchByC_C_Last(long classNameId, long classPK,
843                    OrderByComparator orderByComparator) throws SystemException {
844                    int count = countByC_C(classNameId, classPK);
845    
846                    List<SocialActivityLimit> list = findByC_C(classNameId, classPK,
847                                    count - 1, count, orderByComparator);
848    
849                    if (!list.isEmpty()) {
850                            return list.get(0);
851                    }
852    
853                    return null;
854            }
855    
856            /**
857             * Returns the social activity limits before and after the current social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
858             *
859             * @param activityLimitId the primary key of the current social activity limit
860             * @param classNameId the class name ID
861             * @param classPK the class p k
862             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
863             * @return the previous, current, and next social activity limit
864             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
865             * @throws SystemException if a system exception occurred
866             */
867            public SocialActivityLimit[] findByC_C_PrevAndNext(long activityLimitId,
868                    long classNameId, long classPK, OrderByComparator orderByComparator)
869                    throws NoSuchActivityLimitException, SystemException {
870                    SocialActivityLimit socialActivityLimit = findByPrimaryKey(activityLimitId);
871    
872                    Session session = null;
873    
874                    try {
875                            session = openSession();
876    
877                            SocialActivityLimit[] array = new SocialActivityLimitImpl[3];
878    
879                            array[0] = getByC_C_PrevAndNext(session, socialActivityLimit,
880                                            classNameId, classPK, orderByComparator, true);
881    
882                            array[1] = socialActivityLimit;
883    
884                            array[2] = getByC_C_PrevAndNext(session, socialActivityLimit,
885                                            classNameId, classPK, orderByComparator, false);
886    
887                            return array;
888                    }
889                    catch (Exception e) {
890                            throw processException(e);
891                    }
892                    finally {
893                            closeSession(session);
894                    }
895            }
896    
897            protected SocialActivityLimit getByC_C_PrevAndNext(Session session,
898                    SocialActivityLimit socialActivityLimit, long classNameId,
899                    long classPK, OrderByComparator orderByComparator, boolean previous) {
900                    StringBundler query = null;
901    
902                    if (orderByComparator != null) {
903                            query = new StringBundler(6 +
904                                            (orderByComparator.getOrderByFields().length * 6));
905                    }
906                    else {
907                            query = new StringBundler(3);
908                    }
909    
910                    query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
911    
912                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
913    
914                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
915    
916                    if (orderByComparator != null) {
917                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
918    
919                            if (orderByConditionFields.length > 0) {
920                                    query.append(WHERE_AND);
921                            }
922    
923                            for (int i = 0; i < orderByConditionFields.length; i++) {
924                                    query.append(_ORDER_BY_ENTITY_ALIAS);
925                                    query.append(orderByConditionFields[i]);
926    
927                                    if ((i + 1) < orderByConditionFields.length) {
928                                            if (orderByComparator.isAscending() ^ previous) {
929                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
930                                            }
931                                            else {
932                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
933                                            }
934                                    }
935                                    else {
936                                            if (orderByComparator.isAscending() ^ previous) {
937                                                    query.append(WHERE_GREATER_THAN);
938                                            }
939                                            else {
940                                                    query.append(WHERE_LESSER_THAN);
941                                            }
942                                    }
943                            }
944    
945                            query.append(ORDER_BY_CLAUSE);
946    
947                            String[] orderByFields = orderByComparator.getOrderByFields();
948    
949                            for (int i = 0; i < orderByFields.length; i++) {
950                                    query.append(_ORDER_BY_ENTITY_ALIAS);
951                                    query.append(orderByFields[i]);
952    
953                                    if ((i + 1) < orderByFields.length) {
954                                            if (orderByComparator.isAscending() ^ previous) {
955                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
956                                            }
957                                            else {
958                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
959                                            }
960                                    }
961                                    else {
962                                            if (orderByComparator.isAscending() ^ previous) {
963                                                    query.append(ORDER_BY_ASC);
964                                            }
965                                            else {
966                                                    query.append(ORDER_BY_DESC);
967                                            }
968                                    }
969                            }
970                    }
971                    else {
972                            query.append(SocialActivityLimitModelImpl.ORDER_BY_JPQL);
973                    }
974    
975                    String sql = query.toString();
976    
977                    Query q = session.createQuery(sql);
978    
979                    q.setFirstResult(0);
980                    q.setMaxResults(2);
981    
982                    QueryPos qPos = QueryPos.getInstance(q);
983    
984                    qPos.add(classNameId);
985    
986                    qPos.add(classPK);
987    
988                    if (orderByComparator != null) {
989                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivityLimit);
990    
991                            for (Object value : values) {
992                                    qPos.add(value);
993                            }
994                    }
995    
996                    List<SocialActivityLimit> list = q.list();
997    
998                    if (list.size() == 2) {
999                            return list.get(1);
1000                    }
1001                    else {
1002                            return null;
1003                    }
1004            }
1005    
1006            /**
1007             * Removes all the social activity limits where classNameId = &#63; and classPK = &#63; from the database.
1008             *
1009             * @param classNameId the class name ID
1010             * @param classPK the class p k
1011             * @throws SystemException if a system exception occurred
1012             */
1013            public void removeByC_C(long classNameId, long classPK)
1014                    throws SystemException {
1015                    for (SocialActivityLimit socialActivityLimit : findByC_C(classNameId,
1016                                    classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1017                            remove(socialActivityLimit);
1018                    }
1019            }
1020    
1021            /**
1022             * Returns the number of social activity limits where classNameId = &#63; and classPK = &#63;.
1023             *
1024             * @param classNameId the class name ID
1025             * @param classPK the class p k
1026             * @return the number of matching social activity limits
1027             * @throws SystemException if a system exception occurred
1028             */
1029            public int countByC_C(long classNameId, long classPK)
1030                    throws SystemException {
1031                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
1032    
1033                    Object[] finderArgs = new Object[] { classNameId, classPK };
1034    
1035                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1036                                    this);
1037    
1038                    if (count == null) {
1039                            StringBundler query = new StringBundler(3);
1040    
1041                            query.append(_SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE);
1042    
1043                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1044    
1045                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1046    
1047                            String sql = query.toString();
1048    
1049                            Session session = null;
1050    
1051                            try {
1052                                    session = openSession();
1053    
1054                                    Query q = session.createQuery(sql);
1055    
1056                                    QueryPos qPos = QueryPos.getInstance(q);
1057    
1058                                    qPos.add(classNameId);
1059    
1060                                    qPos.add(classPK);
1061    
1062                                    count = (Long)q.uniqueResult();
1063    
1064                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1065                            }
1066                            catch (Exception e) {
1067                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1068    
1069                                    throw processException(e);
1070                            }
1071                            finally {
1072                                    closeSession(session);
1073                            }
1074                    }
1075    
1076                    return count.intValue();
1077            }
1078    
1079            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "socialActivityLimit.classNameId = ? AND ";
1080            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "socialActivityLimit.classPK = ?";
1081            public static final FinderPath FINDER_PATH_FETCH_BY_G_U_C_C_A_A = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
1082                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED,
1083                            SocialActivityLimitImpl.class, FINDER_CLASS_NAME_ENTITY,
1084                            "fetchByG_U_C_C_A_A",
1085                            new String[] {
1086                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1087                                    Long.class.getName(), Integer.class.getName(),
1088                                    String.class.getName()
1089                            },
1090                            SocialActivityLimitModelImpl.GROUPID_COLUMN_BITMASK |
1091                            SocialActivityLimitModelImpl.USERID_COLUMN_BITMASK |
1092                            SocialActivityLimitModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1093                            SocialActivityLimitModelImpl.CLASSPK_COLUMN_BITMASK |
1094                            SocialActivityLimitModelImpl.ACTIVITYTYPE_COLUMN_BITMASK |
1095                            SocialActivityLimitModelImpl.ACTIVITYCOUNTERNAME_COLUMN_BITMASK);
1096            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_C_C_A_A = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
1097                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED, Long.class,
1098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_C_C_A_A",
1099                            new String[] {
1100                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1101                                    Long.class.getName(), Integer.class.getName(),
1102                                    String.class.getName()
1103                            });
1104    
1105            /**
1106             * 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 com.liferay.portlet.social.NoSuchActivityLimitException} if it could not be found.
1107             *
1108             * @param groupId the group ID
1109             * @param userId the user ID
1110             * @param classNameId the class name ID
1111             * @param classPK the class p k
1112             * @param activityType the activity type
1113             * @param activityCounterName the activity counter name
1114             * @return the matching social activity limit
1115             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
1116             * @throws SystemException if a system exception occurred
1117             */
1118            public SocialActivityLimit findByG_U_C_C_A_A(long groupId, long userId,
1119                    long classNameId, long classPK, int activityType,
1120                    String activityCounterName)
1121                    throws NoSuchActivityLimitException, SystemException {
1122                    SocialActivityLimit socialActivityLimit = fetchByG_U_C_C_A_A(groupId,
1123                                    userId, classNameId, classPK, activityType, activityCounterName);
1124    
1125                    if (socialActivityLimit == null) {
1126                            StringBundler msg = new StringBundler(14);
1127    
1128                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1129    
1130                            msg.append("groupId=");
1131                            msg.append(groupId);
1132    
1133                            msg.append(", userId=");
1134                            msg.append(userId);
1135    
1136                            msg.append(", classNameId=");
1137                            msg.append(classNameId);
1138    
1139                            msg.append(", classPK=");
1140                            msg.append(classPK);
1141    
1142                            msg.append(", activityType=");
1143                            msg.append(activityType);
1144    
1145                            msg.append(", activityCounterName=");
1146                            msg.append(activityCounterName);
1147    
1148                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1149    
1150                            if (_log.isWarnEnabled()) {
1151                                    _log.warn(msg.toString());
1152                            }
1153    
1154                            throw new NoSuchActivityLimitException(msg.toString());
1155                    }
1156    
1157                    return socialActivityLimit;
1158            }
1159    
1160            /**
1161             * 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.
1162             *
1163             * @param groupId the group ID
1164             * @param userId the user ID
1165             * @param classNameId the class name ID
1166             * @param classPK the class p k
1167             * @param activityType the activity type
1168             * @param activityCounterName the activity counter name
1169             * @return the matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
1170             * @throws SystemException if a system exception occurred
1171             */
1172            public SocialActivityLimit fetchByG_U_C_C_A_A(long groupId, long userId,
1173                    long classNameId, long classPK, int activityType,
1174                    String activityCounterName) throws SystemException {
1175                    return fetchByG_U_C_C_A_A(groupId, userId, classNameId, classPK,
1176                            activityType, activityCounterName, true);
1177            }
1178    
1179            /**
1180             * 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.
1181             *
1182             * @param groupId the group ID
1183             * @param userId the user ID
1184             * @param classNameId the class name ID
1185             * @param classPK the class p k
1186             * @param activityType the activity type
1187             * @param activityCounterName the activity counter name
1188             * @param retrieveFromCache whether to use the finder cache
1189             * @return the matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
1190             * @throws SystemException if a system exception occurred
1191             */
1192            public SocialActivityLimit fetchByG_U_C_C_A_A(long groupId, long userId,
1193                    long classNameId, long classPK, int activityType,
1194                    String activityCounterName, boolean retrieveFromCache)
1195                    throws SystemException {
1196                    Object[] finderArgs = new Object[] {
1197                                    groupId, userId, classNameId, classPK, activityType,
1198                                    activityCounterName
1199                            };
1200    
1201                    Object result = null;
1202    
1203                    if (retrieveFromCache) {
1204                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1205                                            finderArgs, this);
1206                    }
1207    
1208                    if (result instanceof SocialActivityLimit) {
1209                            SocialActivityLimit socialActivityLimit = (SocialActivityLimit)result;
1210    
1211                            if ((groupId != socialActivityLimit.getGroupId()) ||
1212                                            (userId != socialActivityLimit.getUserId()) ||
1213                                            (classNameId != socialActivityLimit.getClassNameId()) ||
1214                                            (classPK != socialActivityLimit.getClassPK()) ||
1215                                            (activityType != socialActivityLimit.getActivityType()) ||
1216                                            !Validator.equals(activityCounterName,
1217                                                    socialActivityLimit.getActivityCounterName())) {
1218                                    result = null;
1219                            }
1220                    }
1221    
1222                    if (result == null) {
1223                            StringBundler query = new StringBundler(8);
1224    
1225                            query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
1226    
1227                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_GROUPID_2);
1228    
1229                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_USERID_2);
1230    
1231                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSNAMEID_2);
1232    
1233                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSPK_2);
1234    
1235                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYTYPE_2);
1236    
1237                            if (activityCounterName == null) {
1238                                    query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_1);
1239                            }
1240                            else {
1241                                    if (activityCounterName.equals(StringPool.BLANK)) {
1242                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_3);
1243                                    }
1244                                    else {
1245                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_2);
1246                                    }
1247                            }
1248    
1249                            String sql = query.toString();
1250    
1251                            Session session = null;
1252    
1253                            try {
1254                                    session = openSession();
1255    
1256                                    Query q = session.createQuery(sql);
1257    
1258                                    QueryPos qPos = QueryPos.getInstance(q);
1259    
1260                                    qPos.add(groupId);
1261    
1262                                    qPos.add(userId);
1263    
1264                                    qPos.add(classNameId);
1265    
1266                                    qPos.add(classPK);
1267    
1268                                    qPos.add(activityType);
1269    
1270                                    if (activityCounterName != null) {
1271                                            qPos.add(activityCounterName);
1272                                    }
1273    
1274                                    List<SocialActivityLimit> list = q.list();
1275    
1276                                    if (list.isEmpty()) {
1277                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1278                                                    finderArgs, list);
1279                                    }
1280                                    else {
1281                                            SocialActivityLimit socialActivityLimit = list.get(0);
1282    
1283                                            result = socialActivityLimit;
1284    
1285                                            cacheResult(socialActivityLimit);
1286    
1287                                            if ((socialActivityLimit.getGroupId() != groupId) ||
1288                                                            (socialActivityLimit.getUserId() != userId) ||
1289                                                            (socialActivityLimit.getClassNameId() != classNameId) ||
1290                                                            (socialActivityLimit.getClassPK() != classPK) ||
1291                                                            (socialActivityLimit.getActivityType() != activityType) ||
1292                                                            (socialActivityLimit.getActivityCounterName() == null) ||
1293                                                            !socialActivityLimit.getActivityCounterName()
1294                                                                                                            .equals(activityCounterName)) {
1295                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1296                                                            finderArgs, socialActivityLimit);
1297                                            }
1298                                    }
1299                            }
1300                            catch (Exception e) {
1301                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1302                                            finderArgs);
1303    
1304                                    throw processException(e);
1305                            }
1306                            finally {
1307                                    closeSession(session);
1308                            }
1309                    }
1310    
1311                    if (result instanceof List<?>) {
1312                            return null;
1313                    }
1314                    else {
1315                            return (SocialActivityLimit)result;
1316                    }
1317            }
1318    
1319            /**
1320             * 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.
1321             *
1322             * @param groupId the group ID
1323             * @param userId the user ID
1324             * @param classNameId the class name ID
1325             * @param classPK the class p k
1326             * @param activityType the activity type
1327             * @param activityCounterName the activity counter name
1328             * @return the social activity limit that was removed
1329             * @throws SystemException if a system exception occurred
1330             */
1331            public SocialActivityLimit removeByG_U_C_C_A_A(long groupId, long userId,
1332                    long classNameId, long classPK, int activityType,
1333                    String activityCounterName)
1334                    throws NoSuchActivityLimitException, SystemException {
1335                    SocialActivityLimit socialActivityLimit = findByG_U_C_C_A_A(groupId,
1336                                    userId, classNameId, classPK, activityType, activityCounterName);
1337    
1338                    return remove(socialActivityLimit);
1339            }
1340    
1341            /**
1342             * 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;.
1343             *
1344             * @param groupId the group ID
1345             * @param userId the user ID
1346             * @param classNameId the class name ID
1347             * @param classPK the class p k
1348             * @param activityType the activity type
1349             * @param activityCounterName the activity counter name
1350             * @return the number of matching social activity limits
1351             * @throws SystemException if a system exception occurred
1352             */
1353            public int countByG_U_C_C_A_A(long groupId, long userId, long classNameId,
1354                    long classPK, int activityType, String activityCounterName)
1355                    throws SystemException {
1356                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_C_C_A_A;
1357    
1358                    Object[] finderArgs = new Object[] {
1359                                    groupId, userId, classNameId, classPK, activityType,
1360                                    activityCounterName
1361                            };
1362    
1363                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1364                                    this);
1365    
1366                    if (count == null) {
1367                            StringBundler query = new StringBundler(7);
1368    
1369                            query.append(_SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE);
1370    
1371                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_GROUPID_2);
1372    
1373                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_USERID_2);
1374    
1375                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSNAMEID_2);
1376    
1377                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSPK_2);
1378    
1379                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYTYPE_2);
1380    
1381                            if (activityCounterName == null) {
1382                                    query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_1);
1383                            }
1384                            else {
1385                                    if (activityCounterName.equals(StringPool.BLANK)) {
1386                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_3);
1387                                    }
1388                                    else {
1389                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_2);
1390                                    }
1391                            }
1392    
1393                            String sql = query.toString();
1394    
1395                            Session session = null;
1396    
1397                            try {
1398                                    session = openSession();
1399    
1400                                    Query q = session.createQuery(sql);
1401    
1402                                    QueryPos qPos = QueryPos.getInstance(q);
1403    
1404                                    qPos.add(groupId);
1405    
1406                                    qPos.add(userId);
1407    
1408                                    qPos.add(classNameId);
1409    
1410                                    qPos.add(classPK);
1411    
1412                                    qPos.add(activityType);
1413    
1414                                    if (activityCounterName != null) {
1415                                            qPos.add(activityCounterName);
1416                                    }
1417    
1418                                    count = (Long)q.uniqueResult();
1419    
1420                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1421                            }
1422                            catch (Exception e) {
1423                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1424    
1425                                    throw processException(e);
1426                            }
1427                            finally {
1428                                    closeSession(session);
1429                            }
1430                    }
1431    
1432                    return count.intValue();
1433            }
1434    
1435            private static final String _FINDER_COLUMN_G_U_C_C_A_A_GROUPID_2 = "socialActivityLimit.groupId = ? AND ";
1436            private static final String _FINDER_COLUMN_G_U_C_C_A_A_USERID_2 = "socialActivityLimit.userId = ? AND ";
1437            private static final String _FINDER_COLUMN_G_U_C_C_A_A_CLASSNAMEID_2 = "socialActivityLimit.classNameId = ? AND ";
1438            private static final String _FINDER_COLUMN_G_U_C_C_A_A_CLASSPK_2 = "socialActivityLimit.classPK = ? AND ";
1439            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYTYPE_2 = "socialActivityLimit.activityType = ? AND ";
1440            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_1 =
1441                    "socialActivityLimit.activityCounterName IS NULL";
1442            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_2 =
1443                    "socialActivityLimit.activityCounterName = ?";
1444            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_3 =
1445                    "(socialActivityLimit.activityCounterName IS NULL OR socialActivityLimit.activityCounterName = ?)";
1446    
1447            /**
1448             * Caches the social activity limit in the entity cache if it is enabled.
1449             *
1450             * @param socialActivityLimit the social activity limit
1451             */
1452            public void cacheResult(SocialActivityLimit socialActivityLimit) {
1453                    EntityCacheUtil.putResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
1454                            SocialActivityLimitImpl.class, socialActivityLimit.getPrimaryKey(),
1455                            socialActivityLimit);
1456    
1457                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1458                            new Object[] {
1459                                    Long.valueOf(socialActivityLimit.getGroupId()),
1460                                    Long.valueOf(socialActivityLimit.getUserId()),
1461                                    Long.valueOf(socialActivityLimit.getClassNameId()),
1462                                    Long.valueOf(socialActivityLimit.getClassPK()),
1463                                    Integer.valueOf(socialActivityLimit.getActivityType()),
1464                                    
1465                            socialActivityLimit.getActivityCounterName()
1466                            }, socialActivityLimit);
1467    
1468                    socialActivityLimit.resetOriginalValues();
1469            }
1470    
1471            /**
1472             * Caches the social activity limits in the entity cache if it is enabled.
1473             *
1474             * @param socialActivityLimits the social activity limits
1475             */
1476            public void cacheResult(List<SocialActivityLimit> socialActivityLimits) {
1477                    for (SocialActivityLimit socialActivityLimit : socialActivityLimits) {
1478                            if (EntityCacheUtil.getResult(
1479                                                    SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
1480                                                    SocialActivityLimitImpl.class,
1481                                                    socialActivityLimit.getPrimaryKey()) == null) {
1482                                    cacheResult(socialActivityLimit);
1483                            }
1484                            else {
1485                                    socialActivityLimit.resetOriginalValues();
1486                            }
1487                    }
1488            }
1489    
1490            /**
1491             * Clears the cache for all social activity limits.
1492             *
1493             * <p>
1494             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1495             * </p>
1496             */
1497            @Override
1498            public void clearCache() {
1499                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1500                            CacheRegistryUtil.clear(SocialActivityLimitImpl.class.getName());
1501                    }
1502    
1503                    EntityCacheUtil.clearCache(SocialActivityLimitImpl.class.getName());
1504    
1505                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1506                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1507                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1508            }
1509    
1510            /**
1511             * Clears the cache for the social activity limit.
1512             *
1513             * <p>
1514             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1515             * </p>
1516             */
1517            @Override
1518            public void clearCache(SocialActivityLimit socialActivityLimit) {
1519                    EntityCacheUtil.removeResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
1520                            SocialActivityLimitImpl.class, socialActivityLimit.getPrimaryKey());
1521    
1522                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1523                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1524    
1525                    clearUniqueFindersCache(socialActivityLimit);
1526            }
1527    
1528            @Override
1529            public void clearCache(List<SocialActivityLimit> socialActivityLimits) {
1530                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1531                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1532    
1533                    for (SocialActivityLimit socialActivityLimit : socialActivityLimits) {
1534                            EntityCacheUtil.removeResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
1535                                    SocialActivityLimitImpl.class,
1536                                    socialActivityLimit.getPrimaryKey());
1537    
1538                            clearUniqueFindersCache(socialActivityLimit);
1539                    }
1540            }
1541    
1542            protected void cacheUniqueFindersCache(
1543                    SocialActivityLimit socialActivityLimit) {
1544                    if (socialActivityLimit.isNew()) {
1545                            Object[] args = new Object[] {
1546                                            Long.valueOf(socialActivityLimit.getGroupId()),
1547                                            Long.valueOf(socialActivityLimit.getUserId()),
1548                                            Long.valueOf(socialActivityLimit.getClassNameId()),
1549                                            Long.valueOf(socialActivityLimit.getClassPK()),
1550                                            Integer.valueOf(socialActivityLimit.getActivityType()),
1551                                            
1552                                            socialActivityLimit.getActivityCounterName()
1553                                    };
1554    
1555                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A, args,
1556                                    Long.valueOf(1));
1557                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A, args,
1558                                    socialActivityLimit);
1559                    }
1560                    else {
1561                            SocialActivityLimitModelImpl socialActivityLimitModelImpl = (SocialActivityLimitModelImpl)socialActivityLimit;
1562    
1563                            if ((socialActivityLimitModelImpl.getColumnBitmask() &
1564                                            FINDER_PATH_FETCH_BY_G_U_C_C_A_A.getColumnBitmask()) != 0) {
1565                                    Object[] args = new Object[] {
1566                                                    Long.valueOf(socialActivityLimit.getGroupId()),
1567                                                    Long.valueOf(socialActivityLimit.getUserId()),
1568                                                    Long.valueOf(socialActivityLimit.getClassNameId()),
1569                                                    Long.valueOf(socialActivityLimit.getClassPK()),
1570                                                    Integer.valueOf(socialActivityLimit.getActivityType()),
1571                                                    
1572                                                    socialActivityLimit.getActivityCounterName()
1573                                            };
1574    
1575                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A,
1576                                            args, Long.valueOf(1));
1577                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1578                                            args, socialActivityLimit);
1579                            }
1580                    }
1581            }
1582    
1583            protected void clearUniqueFindersCache(
1584                    SocialActivityLimit socialActivityLimit) {
1585                    SocialActivityLimitModelImpl socialActivityLimitModelImpl = (SocialActivityLimitModelImpl)socialActivityLimit;
1586    
1587                    Object[] args = new Object[] {
1588                                    Long.valueOf(socialActivityLimit.getGroupId()),
1589                                    Long.valueOf(socialActivityLimit.getUserId()),
1590                                    Long.valueOf(socialActivityLimit.getClassNameId()),
1591                                    Long.valueOf(socialActivityLimit.getClassPK()),
1592                                    Integer.valueOf(socialActivityLimit.getActivityType()),
1593                                    
1594                                    socialActivityLimit.getActivityCounterName()
1595                            };
1596    
1597                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A, args);
1598                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A, args);
1599    
1600                    if ((socialActivityLimitModelImpl.getColumnBitmask() &
1601                                    FINDER_PATH_FETCH_BY_G_U_C_C_A_A.getColumnBitmask()) != 0) {
1602                            args = new Object[] {
1603                                            Long.valueOf(socialActivityLimitModelImpl.getOriginalGroupId()),
1604                                            Long.valueOf(socialActivityLimitModelImpl.getOriginalUserId()),
1605                                            Long.valueOf(socialActivityLimitModelImpl.getOriginalClassNameId()),
1606                                            Long.valueOf(socialActivityLimitModelImpl.getOriginalClassPK()),
1607                                            Integer.valueOf(socialActivityLimitModelImpl.getOriginalActivityType()),
1608                                            
1609                                            socialActivityLimitModelImpl.getOriginalActivityCounterName()
1610                                    };
1611    
1612                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A, args);
1613                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A, args);
1614                    }
1615            }
1616    
1617            /**
1618             * Creates a new social activity limit with the primary key. Does not add the social activity limit to the database.
1619             *
1620             * @param activityLimitId the primary key for the new social activity limit
1621             * @return the new social activity limit
1622             */
1623            public SocialActivityLimit create(long activityLimitId) {
1624                    SocialActivityLimit socialActivityLimit = new SocialActivityLimitImpl();
1625    
1626                    socialActivityLimit.setNew(true);
1627                    socialActivityLimit.setPrimaryKey(activityLimitId);
1628    
1629                    return socialActivityLimit;
1630            }
1631    
1632            /**
1633             * Removes the social activity limit with the primary key from the database. Also notifies the appropriate model listeners.
1634             *
1635             * @param activityLimitId the primary key of the social activity limit
1636             * @return the social activity limit that was removed
1637             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
1638             * @throws SystemException if a system exception occurred
1639             */
1640            public SocialActivityLimit remove(long activityLimitId)
1641                    throws NoSuchActivityLimitException, SystemException {
1642                    return remove(Long.valueOf(activityLimitId));
1643            }
1644    
1645            /**
1646             * Removes the social activity limit with the primary key from the database. Also notifies the appropriate model listeners.
1647             *
1648             * @param primaryKey the primary key of the social activity limit
1649             * @return the social activity limit that was removed
1650             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
1651             * @throws SystemException if a system exception occurred
1652             */
1653            @Override
1654            public SocialActivityLimit remove(Serializable primaryKey)
1655                    throws NoSuchActivityLimitException, SystemException {
1656                    Session session = null;
1657    
1658                    try {
1659                            session = openSession();
1660    
1661                            SocialActivityLimit socialActivityLimit = (SocialActivityLimit)session.get(SocialActivityLimitImpl.class,
1662                                            primaryKey);
1663    
1664                            if (socialActivityLimit == null) {
1665                                    if (_log.isWarnEnabled()) {
1666                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1667                                    }
1668    
1669                                    throw new NoSuchActivityLimitException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1670                                            primaryKey);
1671                            }
1672    
1673                            return remove(socialActivityLimit);
1674                    }
1675                    catch (NoSuchActivityLimitException nsee) {
1676                            throw nsee;
1677                    }
1678                    catch (Exception e) {
1679                            throw processException(e);
1680                    }
1681                    finally {
1682                            closeSession(session);
1683                    }
1684            }
1685    
1686            @Override
1687            protected SocialActivityLimit removeImpl(
1688                    SocialActivityLimit socialActivityLimit) throws SystemException {
1689                    socialActivityLimit = toUnwrappedModel(socialActivityLimit);
1690    
1691                    Session session = null;
1692    
1693                    try {
1694                            session = openSession();
1695    
1696                            if (!session.contains(socialActivityLimit)) {
1697                                    socialActivityLimit = (SocialActivityLimit)session.get(SocialActivityLimitImpl.class,
1698                                                    socialActivityLimit.getPrimaryKeyObj());
1699                            }
1700    
1701                            if (socialActivityLimit != null) {
1702                                    session.delete(socialActivityLimit);
1703                            }
1704                    }
1705                    catch (Exception e) {
1706                            throw processException(e);
1707                    }
1708                    finally {
1709                            closeSession(session);
1710                    }
1711    
1712                    if (socialActivityLimit != null) {
1713                            clearCache(socialActivityLimit);
1714                    }
1715    
1716                    return socialActivityLimit;
1717            }
1718    
1719            @Override
1720            public SocialActivityLimit updateImpl(
1721                    com.liferay.portlet.social.model.SocialActivityLimit socialActivityLimit)
1722                    throws SystemException {
1723                    socialActivityLimit = toUnwrappedModel(socialActivityLimit);
1724    
1725                    boolean isNew = socialActivityLimit.isNew();
1726    
1727                    SocialActivityLimitModelImpl socialActivityLimitModelImpl = (SocialActivityLimitModelImpl)socialActivityLimit;
1728    
1729                    Session session = null;
1730    
1731                    try {
1732                            session = openSession();
1733    
1734                            if (socialActivityLimit.isNew()) {
1735                                    session.save(socialActivityLimit);
1736    
1737                                    socialActivityLimit.setNew(false);
1738                            }
1739                            else {
1740                                    session.merge(socialActivityLimit);
1741                            }
1742                    }
1743                    catch (Exception e) {
1744                            throw processException(e);
1745                    }
1746                    finally {
1747                            closeSession(session);
1748                    }
1749    
1750                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1751    
1752                    if (isNew || !SocialActivityLimitModelImpl.COLUMN_BITMASK_ENABLED) {
1753                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1754                    }
1755    
1756                    else {
1757                            if ((socialActivityLimitModelImpl.getColumnBitmask() &
1758                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1759                                    Object[] args = new Object[] {
1760                                                    Long.valueOf(socialActivityLimitModelImpl.getOriginalUserId())
1761                                            };
1762    
1763                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1764                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1765                                            args);
1766    
1767                                    args = new Object[] {
1768                                                    Long.valueOf(socialActivityLimitModelImpl.getUserId())
1769                                            };
1770    
1771                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1772                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1773                                            args);
1774                            }
1775    
1776                            if ((socialActivityLimitModelImpl.getColumnBitmask() &
1777                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
1778                                    Object[] args = new Object[] {
1779                                                    Long.valueOf(socialActivityLimitModelImpl.getOriginalClassNameId()),
1780                                                    Long.valueOf(socialActivityLimitModelImpl.getOriginalClassPK())
1781                                            };
1782    
1783                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1784                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1785                                            args);
1786    
1787                                    args = new Object[] {
1788                                                    Long.valueOf(socialActivityLimitModelImpl.getClassNameId()),
1789                                                    Long.valueOf(socialActivityLimitModelImpl.getClassPK())
1790                                            };
1791    
1792                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1793                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1794                                            args);
1795                            }
1796                    }
1797    
1798                    EntityCacheUtil.putResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
1799                            SocialActivityLimitImpl.class, socialActivityLimit.getPrimaryKey(),
1800                            socialActivityLimit);
1801    
1802                    clearUniqueFindersCache(socialActivityLimit);
1803                    cacheUniqueFindersCache(socialActivityLimit);
1804    
1805                    return socialActivityLimit;
1806            }
1807    
1808            protected SocialActivityLimit toUnwrappedModel(
1809                    SocialActivityLimit socialActivityLimit) {
1810                    if (socialActivityLimit instanceof SocialActivityLimitImpl) {
1811                            return socialActivityLimit;
1812                    }
1813    
1814                    SocialActivityLimitImpl socialActivityLimitImpl = new SocialActivityLimitImpl();
1815    
1816                    socialActivityLimitImpl.setNew(socialActivityLimit.isNew());
1817                    socialActivityLimitImpl.setPrimaryKey(socialActivityLimit.getPrimaryKey());
1818    
1819                    socialActivityLimitImpl.setActivityLimitId(socialActivityLimit.getActivityLimitId());
1820                    socialActivityLimitImpl.setGroupId(socialActivityLimit.getGroupId());
1821                    socialActivityLimitImpl.setCompanyId(socialActivityLimit.getCompanyId());
1822                    socialActivityLimitImpl.setUserId(socialActivityLimit.getUserId());
1823                    socialActivityLimitImpl.setClassNameId(socialActivityLimit.getClassNameId());
1824                    socialActivityLimitImpl.setClassPK(socialActivityLimit.getClassPK());
1825                    socialActivityLimitImpl.setActivityType(socialActivityLimit.getActivityType());
1826                    socialActivityLimitImpl.setActivityCounterName(socialActivityLimit.getActivityCounterName());
1827                    socialActivityLimitImpl.setValue(socialActivityLimit.getValue());
1828    
1829                    return socialActivityLimitImpl;
1830            }
1831    
1832            /**
1833             * Returns the social activity limit with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1834             *
1835             * @param primaryKey the primary key of the social activity limit
1836             * @return the social activity limit
1837             * @throws com.liferay.portal.NoSuchModelException if a social activity limit with the primary key could not be found
1838             * @throws SystemException if a system exception occurred
1839             */
1840            @Override
1841            public SocialActivityLimit findByPrimaryKey(Serializable primaryKey)
1842                    throws NoSuchModelException, SystemException {
1843                    return findByPrimaryKey(((Long)primaryKey).longValue());
1844            }
1845    
1846            /**
1847             * Returns the social activity limit with the primary key or throws a {@link com.liferay.portlet.social.NoSuchActivityLimitException} if it could not be found.
1848             *
1849             * @param activityLimitId the primary key of the social activity limit
1850             * @return the social activity limit
1851             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
1852             * @throws SystemException if a system exception occurred
1853             */
1854            public SocialActivityLimit findByPrimaryKey(long activityLimitId)
1855                    throws NoSuchActivityLimitException, SystemException {
1856                    SocialActivityLimit socialActivityLimit = fetchByPrimaryKey(activityLimitId);
1857    
1858                    if (socialActivityLimit == null) {
1859                            if (_log.isWarnEnabled()) {
1860                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + activityLimitId);
1861                            }
1862    
1863                            throw new NoSuchActivityLimitException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1864                                    activityLimitId);
1865                    }
1866    
1867                    return socialActivityLimit;
1868            }
1869    
1870            /**
1871             * Returns the social activity limit with the primary key or returns <code>null</code> if it could not be found.
1872             *
1873             * @param primaryKey the primary key of the social activity limit
1874             * @return the social activity limit, or <code>null</code> if a social activity limit with the primary key could not be found
1875             * @throws SystemException if a system exception occurred
1876             */
1877            @Override
1878            public SocialActivityLimit fetchByPrimaryKey(Serializable primaryKey)
1879                    throws SystemException {
1880                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
1881            }
1882    
1883            /**
1884             * Returns the social activity limit with the primary key or returns <code>null</code> if it could not be found.
1885             *
1886             * @param activityLimitId the primary key of the social activity limit
1887             * @return the social activity limit, or <code>null</code> if a social activity limit with the primary key could not be found
1888             * @throws SystemException if a system exception occurred
1889             */
1890            public SocialActivityLimit fetchByPrimaryKey(long activityLimitId)
1891                    throws SystemException {
1892                    SocialActivityLimit socialActivityLimit = (SocialActivityLimit)EntityCacheUtil.getResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
1893                                    SocialActivityLimitImpl.class, activityLimitId);
1894    
1895                    if (socialActivityLimit == _nullSocialActivityLimit) {
1896                            return null;
1897                    }
1898    
1899                    if (socialActivityLimit == null) {
1900                            Session session = null;
1901    
1902                            try {
1903                                    session = openSession();
1904    
1905                                    socialActivityLimit = (SocialActivityLimit)session.get(SocialActivityLimitImpl.class,
1906                                                    Long.valueOf(activityLimitId));
1907    
1908                                    if (socialActivityLimit != null) {
1909                                            cacheResult(socialActivityLimit);
1910                                    }
1911                                    else {
1912                                            EntityCacheUtil.putResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
1913                                                    SocialActivityLimitImpl.class, activityLimitId,
1914                                                    _nullSocialActivityLimit);
1915                                    }
1916                            }
1917                            catch (Exception e) {
1918                                    EntityCacheUtil.removeResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
1919                                            SocialActivityLimitImpl.class, activityLimitId);
1920    
1921                                    throw processException(e);
1922                            }
1923                            finally {
1924                                    closeSession(session);
1925                            }
1926                    }
1927    
1928                    return socialActivityLimit;
1929            }
1930    
1931            /**
1932             * Returns all the social activity limits.
1933             *
1934             * @return the social activity limits
1935             * @throws SystemException if a system exception occurred
1936             */
1937            public List<SocialActivityLimit> findAll() throws SystemException {
1938                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1939            }
1940    
1941            /**
1942             * Returns a range of all the social activity limits.
1943             *
1944             * <p>
1945             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
1946             * </p>
1947             *
1948             * @param start the lower bound of the range of social activity limits
1949             * @param end the upper bound of the range of social activity limits (not inclusive)
1950             * @return the range of social activity limits
1951             * @throws SystemException if a system exception occurred
1952             */
1953            public List<SocialActivityLimit> findAll(int start, int end)
1954                    throws SystemException {
1955                    return findAll(start, end, null);
1956            }
1957    
1958            /**
1959             * Returns an ordered range of all the social activity limits.
1960             *
1961             * <p>
1962             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
1963             * </p>
1964             *
1965             * @param start the lower bound of the range of social activity limits
1966             * @param end the upper bound of the range of social activity limits (not inclusive)
1967             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1968             * @return the ordered range of social activity limits
1969             * @throws SystemException if a system exception occurred
1970             */
1971            public List<SocialActivityLimit> findAll(int start, int end,
1972                    OrderByComparator orderByComparator) throws SystemException {
1973                    boolean pagination = true;
1974                    FinderPath finderPath = null;
1975                    Object[] finderArgs = null;
1976    
1977                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1978                                    (orderByComparator == null)) {
1979                            pagination = false;
1980                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1981                            finderArgs = FINDER_ARGS_EMPTY;
1982                    }
1983                    else {
1984                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1985                            finderArgs = new Object[] { start, end, orderByComparator };
1986                    }
1987    
1988                    List<SocialActivityLimit> list = (List<SocialActivityLimit>)FinderCacheUtil.getResult(finderPath,
1989                                    finderArgs, this);
1990    
1991                    if (list == null) {
1992                            StringBundler query = null;
1993                            String sql = null;
1994    
1995                            if (orderByComparator != null) {
1996                                    query = new StringBundler(2 +
1997                                                    (orderByComparator.getOrderByFields().length * 3));
1998    
1999                                    query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT);
2000    
2001                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2002                                            orderByComparator);
2003    
2004                                    sql = query.toString();
2005                            }
2006                            else {
2007                                    sql = _SQL_SELECT_SOCIALACTIVITYLIMIT;
2008    
2009                                    if (pagination) {
2010                                            sql = sql.concat(SocialActivityLimitModelImpl.ORDER_BY_JPQL);
2011                                    }
2012                            }
2013    
2014                            Session session = null;
2015    
2016                            try {
2017                                    session = openSession();
2018    
2019                                    Query q = session.createQuery(sql);
2020    
2021                                    if (!pagination) {
2022                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
2023                                                            getDialect(), start, end, false);
2024    
2025                                            Collections.sort(list);
2026    
2027                                            list = new UnmodifiableList<SocialActivityLimit>(list);
2028                                    }
2029                                    else {
2030                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
2031                                                            getDialect(), start, end);
2032                                    }
2033    
2034                                    cacheResult(list);
2035    
2036                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2037                            }
2038                            catch (Exception e) {
2039                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2040    
2041                                    throw processException(e);
2042                            }
2043                            finally {
2044                                    closeSession(session);
2045                            }
2046                    }
2047    
2048                    return list;
2049            }
2050    
2051            /**
2052             * Removes all the social activity limits from the database.
2053             *
2054             * @throws SystemException if a system exception occurred
2055             */
2056            public void removeAll() throws SystemException {
2057                    for (SocialActivityLimit socialActivityLimit : findAll()) {
2058                            remove(socialActivityLimit);
2059                    }
2060            }
2061    
2062            /**
2063             * Returns the number of social activity limits.
2064             *
2065             * @return the number of social activity limits
2066             * @throws SystemException if a system exception occurred
2067             */
2068            public int countAll() throws SystemException {
2069                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2070                                    FINDER_ARGS_EMPTY, this);
2071    
2072                    if (count == null) {
2073                            Session session = null;
2074    
2075                            try {
2076                                    session = openSession();
2077    
2078                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITYLIMIT);
2079    
2080                                    count = (Long)q.uniqueResult();
2081    
2082                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2083                                            FINDER_ARGS_EMPTY, count);
2084                            }
2085                            catch (Exception e) {
2086                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2087                                            FINDER_ARGS_EMPTY);
2088    
2089                                    throw processException(e);
2090                            }
2091                            finally {
2092                                    closeSession(session);
2093                            }
2094                    }
2095    
2096                    return count.intValue();
2097            }
2098    
2099            /**
2100             * Initializes the social activity limit persistence.
2101             */
2102            public void afterPropertiesSet() {
2103                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2104                                            com.liferay.portal.util.PropsUtil.get(
2105                                                    "value.object.listener.com.liferay.portlet.social.model.SocialActivityLimit")));
2106    
2107                    if (listenerClassNames.length > 0) {
2108                            try {
2109                                    List<ModelListener<SocialActivityLimit>> listenersList = new ArrayList<ModelListener<SocialActivityLimit>>();
2110    
2111                                    for (String listenerClassName : listenerClassNames) {
2112                                            listenersList.add((ModelListener<SocialActivityLimit>)InstanceFactory.newInstance(
2113                                                            listenerClassName));
2114                                    }
2115    
2116                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2117                            }
2118                            catch (Exception e) {
2119                                    _log.error(e);
2120                            }
2121                    }
2122            }
2123    
2124            public void destroy() {
2125                    EntityCacheUtil.removeCache(SocialActivityLimitImpl.class.getName());
2126                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2127                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2128                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2129            }
2130    
2131            private static final String _SQL_SELECT_SOCIALACTIVITYLIMIT = "SELECT socialActivityLimit FROM SocialActivityLimit socialActivityLimit";
2132            private static final String _SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE = "SELECT socialActivityLimit FROM SocialActivityLimit socialActivityLimit WHERE ";
2133            private static final String _SQL_COUNT_SOCIALACTIVITYLIMIT = "SELECT COUNT(socialActivityLimit) FROM SocialActivityLimit socialActivityLimit";
2134            private static final String _SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE = "SELECT COUNT(socialActivityLimit) FROM SocialActivityLimit socialActivityLimit WHERE ";
2135            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivityLimit.";
2136            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivityLimit exists with the primary key ";
2137            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialActivityLimit exists with the key {";
2138            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2139            private static Log _log = LogFactoryUtil.getLog(SocialActivityLimitPersistenceImpl.class);
2140            private static SocialActivityLimit _nullSocialActivityLimit = new SocialActivityLimitImpl() {
2141                            @Override
2142                            public Object clone() {
2143                                    return this;
2144                            }
2145    
2146                            @Override
2147                            public CacheModel<SocialActivityLimit> toCacheModel() {
2148                                    return _nullSocialActivityLimitCacheModel;
2149                            }
2150                    };
2151    
2152            private static CacheModel<SocialActivityLimit> _nullSocialActivityLimitCacheModel =
2153                    new CacheModel<SocialActivityLimit>() {
2154                            public SocialActivityLimit toEntityModel() {
2155                                    return _nullSocialActivityLimit;
2156                            }
2157                    };
2158    }