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