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