001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.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.getOriginalUuid(),
297                                    new Long(mbMailingListModelImpl.getOriginalGroupId())
298                            });
299    
300                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C,
301                            new Object[] {
302                                    new Long(mbMailingListModelImpl.getOriginalGroupId()),
303                                    new Long(mbMailingListModelImpl.getOriginalCategoryId())
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                            Session session = null;
576    
577                            try {
578                                    session = openSession();
579    
580                                    StringBundler query = null;
581    
582                                    if (orderByComparator != null) {
583                                            query = new StringBundler(3 +
584                                                            (orderByComparator.getOrderByFields().length * 3));
585                                    }
586                                    else {
587                                            query = new StringBundler(2);
588                                    }
589    
590                                    query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
591    
592                                    if (uuid == null) {
593                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
594                                    }
595                                    else {
596                                            if (uuid.equals(StringPool.BLANK)) {
597                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
598                                            }
599                                            else {
600                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
601                                            }
602                                    }
603    
604                                    if (orderByComparator != null) {
605                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
606                                                    orderByComparator);
607                                    }
608    
609                                    String sql = query.toString();
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                                            list = new ArrayList<MBMailingList>();
628                                    }
629    
630                                    cacheResult(list);
631    
632                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
633                                            list);
634    
635                                    closeSession(session);
636                            }
637                    }
638    
639                    return list;
640            }
641    
642            /**
643             * Finds the first message boards mailing list in the ordered set where uuid = &#63;.
644             *
645             * <p>
646             * 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.
647             * </p>
648             *
649             * @param uuid the uuid to search with
650             * @param orderByComparator the comparator to order the set by
651             * @return the first matching message boards mailing list
652             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
653             * @throws SystemException if a system exception occurred
654             */
655            public MBMailingList findByUuid_First(String uuid,
656                    OrderByComparator orderByComparator)
657                    throws NoSuchMailingListException, SystemException {
658                    List<MBMailingList> list = findByUuid(uuid, 0, 1, orderByComparator);
659    
660                    if (list.isEmpty()) {
661                            StringBundler msg = new StringBundler(4);
662    
663                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
664    
665                            msg.append("uuid=");
666                            msg.append(uuid);
667    
668                            msg.append(StringPool.CLOSE_CURLY_BRACE);
669    
670                            throw new NoSuchMailingListException(msg.toString());
671                    }
672                    else {
673                            return list.get(0);
674                    }
675            }
676    
677            /**
678             * Finds the last message boards mailing list in the ordered set where uuid = &#63;.
679             *
680             * <p>
681             * 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.
682             * </p>
683             *
684             * @param uuid the uuid to search with
685             * @param orderByComparator the comparator to order the set by
686             * @return the last matching message boards mailing list
687             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
688             * @throws SystemException if a system exception occurred
689             */
690            public MBMailingList findByUuid_Last(String uuid,
691                    OrderByComparator orderByComparator)
692                    throws NoSuchMailingListException, SystemException {
693                    int count = countByUuid(uuid);
694    
695                    List<MBMailingList> list = findByUuid(uuid, count - 1, count,
696                                    orderByComparator);
697    
698                    if (list.isEmpty()) {
699                            StringBundler msg = new StringBundler(4);
700    
701                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
702    
703                            msg.append("uuid=");
704                            msg.append(uuid);
705    
706                            msg.append(StringPool.CLOSE_CURLY_BRACE);
707    
708                            throw new NoSuchMailingListException(msg.toString());
709                    }
710                    else {
711                            return list.get(0);
712                    }
713            }
714    
715            /**
716             * Finds the message boards mailing lists before and after the current message boards mailing list in the ordered set where uuid = &#63;.
717             *
718             * <p>
719             * 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.
720             * </p>
721             *
722             * @param mailingListId the primary key of the current message boards mailing list
723             * @param uuid the uuid to search with
724             * @param orderByComparator the comparator to order the set by
725             * @return the previous, current, and next message boards mailing list
726             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a message boards mailing list with the primary key could not be found
727             * @throws SystemException if a system exception occurred
728             */
729            public MBMailingList[] findByUuid_PrevAndNext(long mailingListId,
730                    String uuid, OrderByComparator orderByComparator)
731                    throws NoSuchMailingListException, SystemException {
732                    MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
733    
734                    Session session = null;
735    
736                    try {
737                            session = openSession();
738    
739                            MBMailingList[] array = new MBMailingListImpl[3];
740    
741                            array[0] = getByUuid_PrevAndNext(session, mbMailingList, uuid,
742                                            orderByComparator, true);
743    
744                            array[1] = mbMailingList;
745    
746                            array[2] = getByUuid_PrevAndNext(session, mbMailingList, uuid,
747                                            orderByComparator, false);
748    
749                            return array;
750                    }
751                    catch (Exception e) {
752                            throw processException(e);
753                    }
754                    finally {
755                            closeSession(session);
756                    }
757            }
758    
759            protected MBMailingList getByUuid_PrevAndNext(Session session,
760                    MBMailingList mbMailingList, String uuid,
761                    OrderByComparator orderByComparator, boolean previous) {
762                    StringBundler query = null;
763    
764                    if (orderByComparator != null) {
765                            query = new StringBundler(6 +
766                                            (orderByComparator.getOrderByFields().length * 6));
767                    }
768                    else {
769                            query = new StringBundler(3);
770                    }
771    
772                    query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
773    
774                    if (uuid == null) {
775                            query.append(_FINDER_COLUMN_UUID_UUID_1);
776                    }
777                    else {
778                            if (uuid.equals(StringPool.BLANK)) {
779                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
780                            }
781                            else {
782                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
783                            }
784                    }
785    
786                    if (orderByComparator != null) {
787                            String[] orderByFields = orderByComparator.getOrderByFields();
788    
789                            if (orderByFields.length > 0) {
790                                    query.append(WHERE_AND);
791                            }
792    
793                            for (int i = 0; i < orderByFields.length; i++) {
794                                    query.append(_ORDER_BY_ENTITY_ALIAS);
795                                    query.append(orderByFields[i]);
796    
797                                    if ((i + 1) < orderByFields.length) {
798                                            if (orderByComparator.isAscending() ^ previous) {
799                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
800                                            }
801                                            else {
802                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
803                                            }
804                                    }
805                                    else {
806                                            if (orderByComparator.isAscending() ^ previous) {
807                                                    query.append(WHERE_GREATER_THAN);
808                                            }
809                                            else {
810                                                    query.append(WHERE_LESSER_THAN);
811                                            }
812                                    }
813                            }
814    
815                            query.append(ORDER_BY_CLAUSE);
816    
817                            for (int i = 0; i < orderByFields.length; i++) {
818                                    query.append(_ORDER_BY_ENTITY_ALIAS);
819                                    query.append(orderByFields[i]);
820    
821                                    if ((i + 1) < orderByFields.length) {
822                                            if (orderByComparator.isAscending() ^ previous) {
823                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
824                                            }
825                                            else {
826                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
827                                            }
828                                    }
829                                    else {
830                                            if (orderByComparator.isAscending() ^ previous) {
831                                                    query.append(ORDER_BY_ASC);
832                                            }
833                                            else {
834                                                    query.append(ORDER_BY_DESC);
835                                            }
836                                    }
837                            }
838                    }
839    
840                    String sql = query.toString();
841    
842                    Query q = session.createQuery(sql);
843    
844                    q.setFirstResult(0);
845                    q.setMaxResults(2);
846    
847                    QueryPos qPos = QueryPos.getInstance(q);
848    
849                    if (uuid != null) {
850                            qPos.add(uuid);
851                    }
852    
853                    if (orderByComparator != null) {
854                            Object[] values = orderByComparator.getOrderByValues(mbMailingList);
855    
856                            for (Object value : values) {
857                                    qPos.add(value);
858                            }
859                    }
860    
861                    List<MBMailingList> list = q.list();
862    
863                    if (list.size() == 2) {
864                            return list.get(1);
865                    }
866                    else {
867                            return null;
868                    }
869            }
870    
871            /**
872             * 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.
873             *
874             * @param uuid the uuid to search with
875             * @param groupId the group id to search with
876             * @return the matching message boards mailing list
877             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
878             * @throws SystemException if a system exception occurred
879             */
880            public MBMailingList findByUUID_G(String uuid, long groupId)
881                    throws NoSuchMailingListException, SystemException {
882                    MBMailingList mbMailingList = fetchByUUID_G(uuid, groupId);
883    
884                    if (mbMailingList == null) {
885                            StringBundler msg = new StringBundler(6);
886    
887                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
888    
889                            msg.append("uuid=");
890                            msg.append(uuid);
891    
892                            msg.append(", groupId=");
893                            msg.append(groupId);
894    
895                            msg.append(StringPool.CLOSE_CURLY_BRACE);
896    
897                            if (_log.isWarnEnabled()) {
898                                    _log.warn(msg.toString());
899                            }
900    
901                            throw new NoSuchMailingListException(msg.toString());
902                    }
903    
904                    return mbMailingList;
905            }
906    
907            /**
908             * 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.
909             *
910             * @param uuid the uuid to search with
911             * @param groupId the group id to search with
912             * @return the matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
913             * @throws SystemException if a system exception occurred
914             */
915            public MBMailingList fetchByUUID_G(String uuid, long groupId)
916                    throws SystemException {
917                    return fetchByUUID_G(uuid, groupId, true);
918            }
919    
920            /**
921             * 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.
922             *
923             * @param uuid the uuid to search with
924             * @param groupId the group id to search with
925             * @return the matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
926             * @throws SystemException if a system exception occurred
927             */
928            public MBMailingList fetchByUUID_G(String uuid, long groupId,
929                    boolean retrieveFromCache) throws SystemException {
930                    Object[] finderArgs = new Object[] { uuid, groupId };
931    
932                    Object result = null;
933    
934                    if (retrieveFromCache) {
935                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
936                                            finderArgs, this);
937                    }
938    
939                    if (result == null) {
940                            Session session = null;
941    
942                            try {
943                                    session = openSession();
944    
945                                    StringBundler query = new StringBundler(3);
946    
947                                    query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
948    
949                                    if (uuid == null) {
950                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
951                                    }
952                                    else {
953                                            if (uuid.equals(StringPool.BLANK)) {
954                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
955                                            }
956                                            else {
957                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
958                                            }
959                                    }
960    
961                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
962    
963                                    String sql = query.toString();
964    
965                                    Query q = session.createQuery(sql);
966    
967                                    QueryPos qPos = QueryPos.getInstance(q);
968    
969                                    if (uuid != null) {
970                                            qPos.add(uuid);
971                                    }
972    
973                                    qPos.add(groupId);
974    
975                                    List<MBMailingList> list = q.list();
976    
977                                    result = list;
978    
979                                    MBMailingList mbMailingList = null;
980    
981                                    if (list.isEmpty()) {
982                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
983                                                    finderArgs, list);
984                                    }
985                                    else {
986                                            mbMailingList = list.get(0);
987    
988                                            cacheResult(mbMailingList);
989    
990                                            if ((mbMailingList.getUuid() == null) ||
991                                                            !mbMailingList.getUuid().equals(uuid) ||
992                                                            (mbMailingList.getGroupId() != groupId)) {
993                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
994                                                            finderArgs, mbMailingList);
995                                            }
996                                    }
997    
998                                    return mbMailingList;
999                            }
1000                            catch (Exception e) {
1001                                    throw processException(e);
1002                            }
1003                            finally {
1004                                    if (result == null) {
1005                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1006                                                    finderArgs, new ArrayList<MBMailingList>());
1007                                    }
1008    
1009                                    closeSession(session);
1010                            }
1011                    }
1012                    else {
1013                            if (result instanceof List<?>) {
1014                                    return null;
1015                            }
1016                            else {
1017                                    return (MBMailingList)result;
1018                            }
1019                    }
1020            }
1021    
1022            /**
1023             * Finds all the message boards mailing lists where active = &#63;.
1024             *
1025             * @param active the active to search with
1026             * @return the matching message boards mailing lists
1027             * @throws SystemException if a system exception occurred
1028             */
1029            public List<MBMailingList> findByActive(boolean active)
1030                    throws SystemException {
1031                    return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1032            }
1033    
1034            /**
1035             * Finds a range of all the message boards mailing lists where active = &#63;.
1036             *
1037             * <p>
1038             * 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.
1039             * </p>
1040             *
1041             * @param active the active to search with
1042             * @param start the lower bound of the range of message boards mailing lists to return
1043             * @param end the upper bound of the range of message boards mailing lists to return (not inclusive)
1044             * @return the range of matching message boards mailing lists
1045             * @throws SystemException if a system exception occurred
1046             */
1047            public List<MBMailingList> findByActive(boolean active, int start, int end)
1048                    throws SystemException {
1049                    return findByActive(active, start, end, null);
1050            }
1051    
1052            /**
1053             * Finds an ordered range of all the message boards mailing lists where active = &#63;.
1054             *
1055             * <p>
1056             * 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.
1057             * </p>
1058             *
1059             * @param active the active to search with
1060             * @param start the lower bound of the range of message boards mailing lists to return
1061             * @param end the upper bound of the range of message boards mailing lists to return (not inclusive)
1062             * @param orderByComparator the comparator to order the results by
1063             * @return the ordered range of matching message boards mailing lists
1064             * @throws SystemException if a system exception occurred
1065             */
1066            public List<MBMailingList> findByActive(boolean active, int start, int end,
1067                    OrderByComparator orderByComparator) throws SystemException {
1068                    Object[] finderArgs = new Object[] {
1069                                    active,
1070                                    
1071                                    String.valueOf(start), String.valueOf(end),
1072                                    String.valueOf(orderByComparator)
1073                            };
1074    
1075                    List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ACTIVE,
1076                                    finderArgs, this);
1077    
1078                    if (list == null) {
1079                            Session session = null;
1080    
1081                            try {
1082                                    session = openSession();
1083    
1084                                    StringBundler query = null;
1085    
1086                                    if (orderByComparator != null) {
1087                                            query = new StringBundler(3 +
1088                                                            (orderByComparator.getOrderByFields().length * 3));
1089                                    }
1090                                    else {
1091                                            query = new StringBundler(2);
1092                                    }
1093    
1094                                    query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1095    
1096                                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1097    
1098                                    if (orderByComparator != null) {
1099                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1100                                                    orderByComparator);
1101                                    }
1102    
1103                                    String sql = query.toString();
1104    
1105                                    Query q = session.createQuery(sql);
1106    
1107                                    QueryPos qPos = QueryPos.getInstance(q);
1108    
1109                                    qPos.add(active);
1110    
1111                                    list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1112                                                    start, end);
1113                            }
1114                            catch (Exception e) {
1115                                    throw processException(e);
1116                            }
1117                            finally {
1118                                    if (list == null) {
1119                                            list = new ArrayList<MBMailingList>();
1120                                    }
1121    
1122                                    cacheResult(list);
1123    
1124                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ACTIVE,
1125                                            finderArgs, list);
1126    
1127                                    closeSession(session);
1128                            }
1129                    }
1130    
1131                    return list;
1132            }
1133    
1134            /**
1135             * Finds the first message boards mailing list in the ordered set where active = &#63;.
1136             *
1137             * <p>
1138             * 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.
1139             * </p>
1140             *
1141             * @param active the active to search with
1142             * @param orderByComparator the comparator to order the set by
1143             * @return the first matching message boards mailing list
1144             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
1145             * @throws SystemException if a system exception occurred
1146             */
1147            public MBMailingList findByActive_First(boolean active,
1148                    OrderByComparator orderByComparator)
1149                    throws NoSuchMailingListException, SystemException {
1150                    List<MBMailingList> list = findByActive(active, 0, 1, orderByComparator);
1151    
1152                    if (list.isEmpty()) {
1153                            StringBundler msg = new StringBundler(4);
1154    
1155                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1156    
1157                            msg.append("active=");
1158                            msg.append(active);
1159    
1160                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1161    
1162                            throw new NoSuchMailingListException(msg.toString());
1163                    }
1164                    else {
1165                            return list.get(0);
1166                    }
1167            }
1168    
1169            /**
1170             * Finds the last message boards mailing list in the ordered set where active = &#63;.
1171             *
1172             * <p>
1173             * 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.
1174             * </p>
1175             *
1176             * @param active the active to search with
1177             * @param orderByComparator the comparator to order the set by
1178             * @return the last matching message boards mailing list
1179             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
1180             * @throws SystemException if a system exception occurred
1181             */
1182            public MBMailingList findByActive_Last(boolean active,
1183                    OrderByComparator orderByComparator)
1184                    throws NoSuchMailingListException, SystemException {
1185                    int count = countByActive(active);
1186    
1187                    List<MBMailingList> list = findByActive(active, count - 1, count,
1188                                    orderByComparator);
1189    
1190                    if (list.isEmpty()) {
1191                            StringBundler msg = new StringBundler(4);
1192    
1193                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1194    
1195                            msg.append("active=");
1196                            msg.append(active);
1197    
1198                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1199    
1200                            throw new NoSuchMailingListException(msg.toString());
1201                    }
1202                    else {
1203                            return list.get(0);
1204                    }
1205            }
1206    
1207            /**
1208             * Finds the message boards mailing lists before and after the current message boards mailing list in the ordered set where active = &#63;.
1209             *
1210             * <p>
1211             * 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.
1212             * </p>
1213             *
1214             * @param mailingListId the primary key of the current message boards mailing list
1215             * @param active the active to search with
1216             * @param orderByComparator the comparator to order the set by
1217             * @return the previous, current, and next message boards mailing list
1218             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a message boards mailing list with the primary key could not be found
1219             * @throws SystemException if a system exception occurred
1220             */
1221            public MBMailingList[] findByActive_PrevAndNext(long mailingListId,
1222                    boolean active, OrderByComparator orderByComparator)
1223                    throws NoSuchMailingListException, SystemException {
1224                    MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
1225    
1226                    Session session = null;
1227    
1228                    try {
1229                            session = openSession();
1230    
1231                            MBMailingList[] array = new MBMailingListImpl[3];
1232    
1233                            array[0] = getByActive_PrevAndNext(session, mbMailingList, active,
1234                                            orderByComparator, true);
1235    
1236                            array[1] = mbMailingList;
1237    
1238                            array[2] = getByActive_PrevAndNext(session, mbMailingList, active,
1239                                            orderByComparator, false);
1240    
1241                            return array;
1242                    }
1243                    catch (Exception e) {
1244                            throw processException(e);
1245                    }
1246                    finally {
1247                            closeSession(session);
1248                    }
1249            }
1250    
1251            protected MBMailingList getByActive_PrevAndNext(Session session,
1252                    MBMailingList mbMailingList, boolean active,
1253                    OrderByComparator orderByComparator, boolean previous) {
1254                    StringBundler query = null;
1255    
1256                    if (orderByComparator != null) {
1257                            query = new StringBundler(6 +
1258                                            (orderByComparator.getOrderByFields().length * 6));
1259                    }
1260                    else {
1261                            query = new StringBundler(3);
1262                    }
1263    
1264                    query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1265    
1266                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1267    
1268                    if (orderByComparator != null) {
1269                            String[] orderByFields = orderByComparator.getOrderByFields();
1270    
1271                            if (orderByFields.length > 0) {
1272                                    query.append(WHERE_AND);
1273                            }
1274    
1275                            for (int i = 0; i < orderByFields.length; i++) {
1276                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1277                                    query.append(orderByFields[i]);
1278    
1279                                    if ((i + 1) < orderByFields.length) {
1280                                            if (orderByComparator.isAscending() ^ previous) {
1281                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1282                                            }
1283                                            else {
1284                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1285                                            }
1286                                    }
1287                                    else {
1288                                            if (orderByComparator.isAscending() ^ previous) {
1289                                                    query.append(WHERE_GREATER_THAN);
1290                                            }
1291                                            else {
1292                                                    query.append(WHERE_LESSER_THAN);
1293                                            }
1294                                    }
1295                            }
1296    
1297                            query.append(ORDER_BY_CLAUSE);
1298    
1299                            for (int i = 0; i < orderByFields.length; i++) {
1300                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1301                                    query.append(orderByFields[i]);
1302    
1303                                    if ((i + 1) < orderByFields.length) {
1304                                            if (orderByComparator.isAscending() ^ previous) {
1305                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1306                                            }
1307                                            else {
1308                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1309                                            }
1310                                    }
1311                                    else {
1312                                            if (orderByComparator.isAscending() ^ previous) {
1313                                                    query.append(ORDER_BY_ASC);
1314                                            }
1315                                            else {
1316                                                    query.append(ORDER_BY_DESC);
1317                                            }
1318                                    }
1319                            }
1320                    }
1321    
1322                    String sql = query.toString();
1323    
1324                    Query q = session.createQuery(sql);
1325    
1326                    q.setFirstResult(0);
1327                    q.setMaxResults(2);
1328    
1329                    QueryPos qPos = QueryPos.getInstance(q);
1330    
1331                    qPos.add(active);
1332    
1333                    if (orderByComparator != null) {
1334                            Object[] values = orderByComparator.getOrderByValues(mbMailingList);
1335    
1336                            for (Object value : values) {
1337                                    qPos.add(value);
1338                            }
1339                    }
1340    
1341                    List<MBMailingList> list = q.list();
1342    
1343                    if (list.size() == 2) {
1344                            return list.get(1);
1345                    }
1346                    else {
1347                            return null;
1348                    }
1349            }
1350    
1351            /**
1352             * 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.
1353             *
1354             * @param groupId the group id to search with
1355             * @param categoryId the category id to search with
1356             * @return the matching message boards mailing list
1357             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
1358             * @throws SystemException if a system exception occurred
1359             */
1360            public MBMailingList findByG_C(long groupId, long categoryId)
1361                    throws NoSuchMailingListException, SystemException {
1362                    MBMailingList mbMailingList = fetchByG_C(groupId, categoryId);
1363    
1364                    if (mbMailingList == null) {
1365                            StringBundler msg = new StringBundler(6);
1366    
1367                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1368    
1369                            msg.append("groupId=");
1370                            msg.append(groupId);
1371    
1372                            msg.append(", categoryId=");
1373                            msg.append(categoryId);
1374    
1375                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1376    
1377                            if (_log.isWarnEnabled()) {
1378                                    _log.warn(msg.toString());
1379                            }
1380    
1381                            throw new NoSuchMailingListException(msg.toString());
1382                    }
1383    
1384                    return mbMailingList;
1385            }
1386    
1387            /**
1388             * 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.
1389             *
1390             * @param groupId the group id to search with
1391             * @param categoryId the category id to search with
1392             * @return the matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1393             * @throws SystemException if a system exception occurred
1394             */
1395            public MBMailingList fetchByG_C(long groupId, long categoryId)
1396                    throws SystemException {
1397                    return fetchByG_C(groupId, categoryId, true);
1398            }
1399    
1400            /**
1401             * 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.
1402             *
1403             * @param groupId the group id to search with
1404             * @param categoryId the category id to search with
1405             * @return the matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1406             * @throws SystemException if a system exception occurred
1407             */
1408            public MBMailingList fetchByG_C(long groupId, long categoryId,
1409                    boolean retrieveFromCache) throws SystemException {
1410                    Object[] finderArgs = new Object[] { groupId, categoryId };
1411    
1412                    Object result = null;
1413    
1414                    if (retrieveFromCache) {
1415                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C,
1416                                            finderArgs, this);
1417                    }
1418    
1419                    if (result == null) {
1420                            Session session = null;
1421    
1422                            try {
1423                                    session = openSession();
1424    
1425                                    StringBundler query = new StringBundler(3);
1426    
1427                                    query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1428    
1429                                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1430    
1431                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1432    
1433                                    String sql = query.toString();
1434    
1435                                    Query q = session.createQuery(sql);
1436    
1437                                    QueryPos qPos = QueryPos.getInstance(q);
1438    
1439                                    qPos.add(groupId);
1440    
1441                                    qPos.add(categoryId);
1442    
1443                                    List<MBMailingList> list = q.list();
1444    
1445                                    result = list;
1446    
1447                                    MBMailingList mbMailingList = null;
1448    
1449                                    if (list.isEmpty()) {
1450                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
1451                                                    finderArgs, list);
1452                                    }
1453                                    else {
1454                                            mbMailingList = list.get(0);
1455    
1456                                            cacheResult(mbMailingList);
1457    
1458                                            if ((mbMailingList.getGroupId() != groupId) ||
1459                                                            (mbMailingList.getCategoryId() != categoryId)) {
1460                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
1461                                                            finderArgs, mbMailingList);
1462                                            }
1463                                    }
1464    
1465                                    return mbMailingList;
1466                            }
1467                            catch (Exception e) {
1468                                    throw processException(e);
1469                            }
1470                            finally {
1471                                    if (result == null) {
1472                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
1473                                                    finderArgs, new ArrayList<MBMailingList>());
1474                                    }
1475    
1476                                    closeSession(session);
1477                            }
1478                    }
1479                    else {
1480                            if (result instanceof List<?>) {
1481                                    return null;
1482                            }
1483                            else {
1484                                    return (MBMailingList)result;
1485                            }
1486                    }
1487            }
1488    
1489            /**
1490             * Finds all the message boards mailing lists.
1491             *
1492             * @return the message boards mailing lists
1493             * @throws SystemException if a system exception occurred
1494             */
1495            public List<MBMailingList> findAll() throws SystemException {
1496                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1497            }
1498    
1499            /**
1500             * Finds a range of all the message boards mailing lists.
1501             *
1502             * <p>
1503             * 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.
1504             * </p>
1505             *
1506             * @param start the lower bound of the range of message boards mailing lists to return
1507             * @param end the upper bound of the range of message boards mailing lists to return (not inclusive)
1508             * @return the range of message boards mailing lists
1509             * @throws SystemException if a system exception occurred
1510             */
1511            public List<MBMailingList> findAll(int start, int end)
1512                    throws SystemException {
1513                    return findAll(start, end, null);
1514            }
1515    
1516            /**
1517             * Finds an ordered range of all the message boards mailing lists.
1518             *
1519             * <p>
1520             * 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.
1521             * </p>
1522             *
1523             * @param start the lower bound of the range of message boards mailing lists to return
1524             * @param end the upper bound of the range of message boards mailing lists to return (not inclusive)
1525             * @param orderByComparator the comparator to order the results by
1526             * @return the ordered range of message boards mailing lists
1527             * @throws SystemException if a system exception occurred
1528             */
1529            public List<MBMailingList> findAll(int start, int end,
1530                    OrderByComparator orderByComparator) throws SystemException {
1531                    Object[] finderArgs = new Object[] {
1532                                    String.valueOf(start), String.valueOf(end),
1533                                    String.valueOf(orderByComparator)
1534                            };
1535    
1536                    List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1537                                    finderArgs, this);
1538    
1539                    if (list == null) {
1540                            Session session = null;
1541    
1542                            try {
1543                                    session = openSession();
1544    
1545                                    StringBundler query = null;
1546                                    String sql = null;
1547    
1548                                    if (orderByComparator != null) {
1549                                            query = new StringBundler(2 +
1550                                                            (orderByComparator.getOrderByFields().length * 3));
1551    
1552                                            query.append(_SQL_SELECT_MBMAILINGLIST);
1553    
1554                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1555                                                    orderByComparator);
1556    
1557                                            sql = query.toString();
1558                                    }
1559                                    else {
1560                                            sql = _SQL_SELECT_MBMAILINGLIST;
1561                                    }
1562    
1563                                    Query q = session.createQuery(sql);
1564    
1565                                    if (orderByComparator == null) {
1566                                            list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1567                                                            start, end, false);
1568    
1569                                            Collections.sort(list);
1570                                    }
1571                                    else {
1572                                            list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1573                                                            start, end);
1574                                    }
1575                            }
1576                            catch (Exception e) {
1577                                    throw processException(e);
1578                            }
1579                            finally {
1580                                    if (list == null) {
1581                                            list = new ArrayList<MBMailingList>();
1582                                    }
1583    
1584                                    cacheResult(list);
1585    
1586                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1587    
1588                                    closeSession(session);
1589                            }
1590                    }
1591    
1592                    return list;
1593            }
1594    
1595            /**
1596             * Removes all the message boards mailing lists where uuid = &#63; from the database.
1597             *
1598             * @param uuid the uuid to search with
1599             * @throws SystemException if a system exception occurred
1600             */
1601            public void removeByUuid(String uuid) throws SystemException {
1602                    for (MBMailingList mbMailingList : findByUuid(uuid)) {
1603                            remove(mbMailingList);
1604                    }
1605            }
1606    
1607            /**
1608             * Removes the message boards mailing list where uuid = &#63; and groupId = &#63; from the database.
1609             *
1610             * @param uuid the uuid to search with
1611             * @param groupId the group id to search with
1612             * @throws SystemException if a system exception occurred
1613             */
1614            public void removeByUUID_G(String uuid, long groupId)
1615                    throws NoSuchMailingListException, SystemException {
1616                    MBMailingList mbMailingList = findByUUID_G(uuid, groupId);
1617    
1618                    remove(mbMailingList);
1619            }
1620    
1621            /**
1622             * Removes all the message boards mailing lists where active = &#63; from the database.
1623             *
1624             * @param active the active to search with
1625             * @throws SystemException if a system exception occurred
1626             */
1627            public void removeByActive(boolean active) throws SystemException {
1628                    for (MBMailingList mbMailingList : findByActive(active)) {
1629                            remove(mbMailingList);
1630                    }
1631            }
1632    
1633            /**
1634             * Removes the message boards mailing list where groupId = &#63; and categoryId = &#63; from the database.
1635             *
1636             * @param groupId the group id to search with
1637             * @param categoryId the category id to search with
1638             * @throws SystemException if a system exception occurred
1639             */
1640            public void removeByG_C(long groupId, long categoryId)
1641                    throws NoSuchMailingListException, SystemException {
1642                    MBMailingList mbMailingList = findByG_C(groupId, categoryId);
1643    
1644                    remove(mbMailingList);
1645            }
1646    
1647            /**
1648             * Removes all the message boards mailing lists from the database.
1649             *
1650             * @throws SystemException if a system exception occurred
1651             */
1652            public void removeAll() throws SystemException {
1653                    for (MBMailingList mbMailingList : findAll()) {
1654                            remove(mbMailingList);
1655                    }
1656            }
1657    
1658            /**
1659             * Counts all the message boards mailing lists where uuid = &#63;.
1660             *
1661             * @param uuid the uuid to search with
1662             * @return the number of matching message boards mailing lists
1663             * @throws SystemException if a system exception occurred
1664             */
1665            public int countByUuid(String uuid) throws SystemException {
1666                    Object[] finderArgs = new Object[] { uuid };
1667    
1668                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1669                                    finderArgs, this);
1670    
1671                    if (count == null) {
1672                            Session session = null;
1673    
1674                            try {
1675                                    session = openSession();
1676    
1677                                    StringBundler query = new StringBundler(2);
1678    
1679                                    query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1680    
1681                                    if (uuid == null) {
1682                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1683                                    }
1684                                    else {
1685                                            if (uuid.equals(StringPool.BLANK)) {
1686                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1687                                            }
1688                                            else {
1689                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1690                                            }
1691                                    }
1692    
1693                                    String sql = query.toString();
1694    
1695                                    Query q = session.createQuery(sql);
1696    
1697                                    QueryPos qPos = QueryPos.getInstance(q);
1698    
1699                                    if (uuid != null) {
1700                                            qPos.add(uuid);
1701                                    }
1702    
1703                                    count = (Long)q.uniqueResult();
1704                            }
1705                            catch (Exception e) {
1706                                    throw processException(e);
1707                            }
1708                            finally {
1709                                    if (count == null) {
1710                                            count = Long.valueOf(0);
1711                                    }
1712    
1713                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1714                                            finderArgs, count);
1715    
1716                                    closeSession(session);
1717                            }
1718                    }
1719    
1720                    return count.intValue();
1721            }
1722    
1723            /**
1724             * Counts all the message boards mailing lists where uuid = &#63; and groupId = &#63;.
1725             *
1726             * @param uuid the uuid to search with
1727             * @param groupId the group id to search with
1728             * @return the number of matching message boards mailing lists
1729             * @throws SystemException if a system exception occurred
1730             */
1731            public int countByUUID_G(String uuid, long groupId)
1732                    throws SystemException {
1733                    Object[] finderArgs = new Object[] { uuid, groupId };
1734    
1735                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1736                                    finderArgs, this);
1737    
1738                    if (count == null) {
1739                            Session session = null;
1740    
1741                            try {
1742                                    session = openSession();
1743    
1744                                    StringBundler query = new StringBundler(3);
1745    
1746                                    query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1747    
1748                                    if (uuid == null) {
1749                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1750                                    }
1751                                    else {
1752                                            if (uuid.equals(StringPool.BLANK)) {
1753                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1754                                            }
1755                                            else {
1756                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1757                                            }
1758                                    }
1759    
1760                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1761    
1762                                    String sql = query.toString();
1763    
1764                                    Query q = session.createQuery(sql);
1765    
1766                                    QueryPos qPos = QueryPos.getInstance(q);
1767    
1768                                    if (uuid != null) {
1769                                            qPos.add(uuid);
1770                                    }
1771    
1772                                    qPos.add(groupId);
1773    
1774                                    count = (Long)q.uniqueResult();
1775                            }
1776                            catch (Exception e) {
1777                                    throw processException(e);
1778                            }
1779                            finally {
1780                                    if (count == null) {
1781                                            count = Long.valueOf(0);
1782                                    }
1783    
1784                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1785                                            finderArgs, count);
1786    
1787                                    closeSession(session);
1788                            }
1789                    }
1790    
1791                    return count.intValue();
1792            }
1793    
1794            /**
1795             * Counts all the message boards mailing lists where active = &#63;.
1796             *
1797             * @param active the active to search with
1798             * @return the number of matching message boards mailing lists
1799             * @throws SystemException if a system exception occurred
1800             */
1801            public int countByActive(boolean active) throws SystemException {
1802                    Object[] finderArgs = new Object[] { active };
1803    
1804                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ACTIVE,
1805                                    finderArgs, this);
1806    
1807                    if (count == null) {
1808                            Session session = null;
1809    
1810                            try {
1811                                    session = openSession();
1812    
1813                                    StringBundler query = new StringBundler(2);
1814    
1815                                    query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1816    
1817                                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1818    
1819                                    String sql = query.toString();
1820    
1821                                    Query q = session.createQuery(sql);
1822    
1823                                    QueryPos qPos = QueryPos.getInstance(q);
1824    
1825                                    qPos.add(active);
1826    
1827                                    count = (Long)q.uniqueResult();
1828                            }
1829                            catch (Exception e) {
1830                                    throw processException(e);
1831                            }
1832                            finally {
1833                                    if (count == null) {
1834                                            count = Long.valueOf(0);
1835                                    }
1836    
1837                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ACTIVE,
1838                                            finderArgs, count);
1839    
1840                                    closeSession(session);
1841                            }
1842                    }
1843    
1844                    return count.intValue();
1845            }
1846    
1847            /**
1848             * Counts all the message boards mailing lists where groupId = &#63; and categoryId = &#63;.
1849             *
1850             * @param groupId the group id to search with
1851             * @param categoryId the category id to search with
1852             * @return the number of matching message boards mailing lists
1853             * @throws SystemException if a system exception occurred
1854             */
1855            public int countByG_C(long groupId, long categoryId)
1856                    throws SystemException {
1857                    Object[] finderArgs = new Object[] { groupId, categoryId };
1858    
1859                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
1860                                    finderArgs, this);
1861    
1862                    if (count == null) {
1863                            Session session = null;
1864    
1865                            try {
1866                                    session = openSession();
1867    
1868                                    StringBundler query = new StringBundler(3);
1869    
1870                                    query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1871    
1872                                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1873    
1874                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1875    
1876                                    String sql = query.toString();
1877    
1878                                    Query q = session.createQuery(sql);
1879    
1880                                    QueryPos qPos = QueryPos.getInstance(q);
1881    
1882                                    qPos.add(groupId);
1883    
1884                                    qPos.add(categoryId);
1885    
1886                                    count = (Long)q.uniqueResult();
1887                            }
1888                            catch (Exception e) {
1889                                    throw processException(e);
1890                            }
1891                            finally {
1892                                    if (count == null) {
1893                                            count = Long.valueOf(0);
1894                                    }
1895    
1896                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
1897                                            count);
1898    
1899                                    closeSession(session);
1900                            }
1901                    }
1902    
1903                    return count.intValue();
1904            }
1905    
1906            /**
1907             * Counts all the message boards mailing lists.
1908             *
1909             * @return the number of message boards mailing lists
1910             * @throws SystemException if a system exception occurred
1911             */
1912            public int countAll() throws SystemException {
1913                    Object[] finderArgs = new Object[0];
1914    
1915                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1916                                    finderArgs, this);
1917    
1918                    if (count == null) {
1919                            Session session = null;
1920    
1921                            try {
1922                                    session = openSession();
1923    
1924                                    Query q = session.createQuery(_SQL_COUNT_MBMAILINGLIST);
1925    
1926                                    count = (Long)q.uniqueResult();
1927                            }
1928                            catch (Exception e) {
1929                                    throw processException(e);
1930                            }
1931                            finally {
1932                                    if (count == null) {
1933                                            count = Long.valueOf(0);
1934                                    }
1935    
1936                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1937                                            count);
1938    
1939                                    closeSession(session);
1940                            }
1941                    }
1942    
1943                    return count.intValue();
1944            }
1945    
1946            /**
1947             * Initializes the message boards mailing list persistence.
1948             */
1949            public void afterPropertiesSet() {
1950                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1951                                            com.liferay.portal.util.PropsUtil.get(
1952                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMailingList")));
1953    
1954                    if (listenerClassNames.length > 0) {
1955                            try {
1956                                    List<ModelListener<MBMailingList>> listenersList = new ArrayList<ModelListener<MBMailingList>>();
1957    
1958                                    for (String listenerClassName : listenerClassNames) {
1959                                            listenersList.add((ModelListener<MBMailingList>)InstanceFactory.newInstance(
1960                                                            listenerClassName));
1961                                    }
1962    
1963                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1964                            }
1965                            catch (Exception e) {
1966                                    _log.error(e);
1967                            }
1968                    }
1969            }
1970    
1971            public void destroy() {
1972                    EntityCacheUtil.removeCache(MBMailingListImpl.class.getName());
1973                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1974                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1975            }
1976    
1977            @BeanReference(type = MBBanPersistence.class)
1978            protected MBBanPersistence mbBanPersistence;
1979            @BeanReference(type = MBCategoryPersistence.class)
1980            protected MBCategoryPersistence mbCategoryPersistence;
1981            @BeanReference(type = MBDiscussionPersistence.class)
1982            protected MBDiscussionPersistence mbDiscussionPersistence;
1983            @BeanReference(type = MBMailingListPersistence.class)
1984            protected MBMailingListPersistence mbMailingListPersistence;
1985            @BeanReference(type = MBMessagePersistence.class)
1986            protected MBMessagePersistence mbMessagePersistence;
1987            @BeanReference(type = MBMessageFlagPersistence.class)
1988            protected MBMessageFlagPersistence mbMessageFlagPersistence;
1989            @BeanReference(type = MBStatsUserPersistence.class)
1990            protected MBStatsUserPersistence mbStatsUserPersistence;
1991            @BeanReference(type = MBThreadPersistence.class)
1992            protected MBThreadPersistence mbThreadPersistence;
1993            @BeanReference(type = ResourcePersistence.class)
1994            protected ResourcePersistence resourcePersistence;
1995            @BeanReference(type = UserPersistence.class)
1996            protected UserPersistence userPersistence;
1997            private static final String _SQL_SELECT_MBMAILINGLIST = "SELECT mbMailingList FROM MBMailingList mbMailingList";
1998            private static final String _SQL_SELECT_MBMAILINGLIST_WHERE = "SELECT mbMailingList FROM MBMailingList mbMailingList WHERE ";
1999            private static final String _SQL_COUNT_MBMAILINGLIST = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList";
2000            private static final String _SQL_COUNT_MBMAILINGLIST_WHERE = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList WHERE ";
2001            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMailingList.uuid IS NULL";
2002            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMailingList.uuid = ?";
2003            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = ?)";
2004            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMailingList.uuid IS NULL AND ";
2005            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMailingList.uuid = ? AND ";
2006            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = ?) AND ";
2007            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMailingList.groupId = ?";
2008            private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "mbMailingList.active = ?";
2009            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMailingList.groupId = ? AND ";
2010            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMailingList.categoryId = ?";
2011            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMailingList.";
2012            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMailingList exists with the primary key ";
2013            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMailingList exists with the key {";
2014            private static Log _log = LogFactoryUtil.getLog(MBMailingListPersistenceImpl.class);
2015    }