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