001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    
042    import com.liferay.portlet.messageboards.NoSuchMailingListException;
043    import com.liferay.portlet.messageboards.model.MBMailingList;
044    import com.liferay.portlet.messageboards.model.impl.MBMailingListImpl;
045    import com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl;
046    
047    import java.io.Serializable;
048    
049    import java.util.ArrayList;
050    import java.util.Collections;
051    import java.util.List;
052    
053    /**
054     * The persistence implementation for the message boards mailing list service.
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see MBMailingListPersistence
062     * @see MBMailingListUtil
063     * @generated
064     */
065    public class MBMailingListPersistenceImpl extends BasePersistenceImpl<MBMailingList>
066            implements MBMailingListPersistence {
067            /*
068             * NOTE FOR DEVELOPERS:
069             *
070             * 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.
071             */
072            public static final String FINDER_CLASS_NAME_ENTITY = MBMailingListImpl.class.getName();
073            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List1";
075            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List2";
077            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
078                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
079                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
080                            "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
082                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
083                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
084                            "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
086                            MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
089                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
090                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
091                            "findByUuid",
092                            new String[] {
093                                    String.class.getName(),
094                                    
095                            Integer.class.getName(), Integer.class.getName(),
096                                    OrderByComparator.class.getName()
097                            });
098            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
099                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
100                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
101                            "findByUuid", new String[] { String.class.getName() },
102                            MBMailingListModelImpl.UUID_COLUMN_BITMASK);
103            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
104                            MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
106                            new String[] { String.class.getName() });
107    
108            /**
109             * Returns all the message boards mailing lists where uuid = &#63;.
110             *
111             * @param uuid the uuid
112             * @return the matching message boards mailing lists
113             * @throws SystemException if a system exception occurred
114             */
115            public List<MBMailingList> findByUuid(String uuid)
116                    throws SystemException {
117                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118            }
119    
120            /**
121             * Returns a range of all the message boards mailing lists where uuid = &#63;.
122             *
123             * <p>
124             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
125             * </p>
126             *
127             * @param uuid the uuid
128             * @param start the lower bound of the range of message boards mailing lists
129             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
130             * @return the range of matching message boards mailing lists
131             * @throws SystemException if a system exception occurred
132             */
133            public List<MBMailingList> findByUuid(String uuid, int start, int end)
134                    throws SystemException {
135                    return findByUuid(uuid, start, end, null);
136            }
137    
138            /**
139             * Returns an ordered range of all the message boards mailing lists where uuid = &#63;.
140             *
141             * <p>
142             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
143             * </p>
144             *
145             * @param uuid the uuid
146             * @param start the lower bound of the range of message boards mailing lists
147             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
148             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
149             * @return the ordered range of matching message boards mailing lists
150             * @throws SystemException if a system exception occurred
151             */
152            public List<MBMailingList> findByUuid(String uuid, int start, int end,
153                    OrderByComparator orderByComparator) throws SystemException {
154                    boolean pagination = true;
155                    FinderPath finderPath = null;
156                    Object[] finderArgs = null;
157    
158                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159                                    (orderByComparator == null)) {
160                            pagination = false;
161                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
162                            finderArgs = new Object[] { uuid };
163                    }
164                    else {
165                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
166                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
167                    }
168    
169                    List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(finderPath,
170                                    finderArgs, this);
171    
172                    if ((list != null) && !list.isEmpty()) {
173                            for (MBMailingList mbMailingList : list) {
174                                    if (!Validator.equals(uuid, mbMailingList.getUuid())) {
175                                            list = null;
176    
177                                            break;
178                                    }
179                            }
180                    }
181    
182                    if (list == null) {
183                            StringBundler query = null;
184    
185                            if (orderByComparator != null) {
186                                    query = new StringBundler(3 +
187                                                    (orderByComparator.getOrderByFields().length * 3));
188                            }
189                            else {
190                                    query = new StringBundler(3);
191                            }
192    
193                            query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
194    
195                            if (uuid == null) {
196                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
197                            }
198                            else {
199                                    if (uuid.equals(StringPool.BLANK)) {
200                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
201                                    }
202                                    else {
203                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
204                                    }
205                            }
206    
207                            if (orderByComparator != null) {
208                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
209                                            orderByComparator);
210                            }
211                            else
212                             if (pagination) {
213                                    query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
214                            }
215    
216                            String sql = query.toString();
217    
218                            Session session = null;
219    
220                            try {
221                                    session = openSession();
222    
223                                    Query q = session.createQuery(sql);
224    
225                                    QueryPos qPos = QueryPos.getInstance(q);
226    
227                                    if (uuid != null) {
228                                            qPos.add(uuid);
229                                    }
230    
231                                    if (!pagination) {
232                                            list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
233                                                            start, end, false);
234    
235                                            Collections.sort(list);
236    
237                                            list = new UnmodifiableList<MBMailingList>(list);
238                                    }
239                                    else {
240                                            list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
241                                                            start, end);
242                                    }
243    
244                                    cacheResult(list);
245    
246                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
247                            }
248                            catch (Exception e) {
249                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
250    
251                                    throw processException(e);
252                            }
253                            finally {
254                                    closeSession(session);
255                            }
256                    }
257    
258                    return list;
259            }
260    
261            /**
262             * Returns the first message boards mailing list in the ordered set where uuid = &#63;.
263             *
264             * @param uuid the uuid
265             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
266             * @return the first matching message boards mailing list
267             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
268             * @throws SystemException if a system exception occurred
269             */
270            public MBMailingList findByUuid_First(String uuid,
271                    OrderByComparator orderByComparator)
272                    throws NoSuchMailingListException, SystemException {
273                    MBMailingList mbMailingList = fetchByUuid_First(uuid, orderByComparator);
274    
275                    if (mbMailingList != null) {
276                            return mbMailingList;
277                    }
278    
279                    StringBundler msg = new StringBundler(4);
280    
281                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
282    
283                    msg.append("uuid=");
284                    msg.append(uuid);
285    
286                    msg.append(StringPool.CLOSE_CURLY_BRACE);
287    
288                    throw new NoSuchMailingListException(msg.toString());
289            }
290    
291            /**
292             * Returns the first message boards mailing list in the ordered set where uuid = &#63;.
293             *
294             * @param uuid the uuid
295             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
296             * @return the first matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
297             * @throws SystemException if a system exception occurred
298             */
299            public MBMailingList fetchByUuid_First(String uuid,
300                    OrderByComparator orderByComparator) throws SystemException {
301                    List<MBMailingList> list = findByUuid(uuid, 0, 1, orderByComparator);
302    
303                    if (!list.isEmpty()) {
304                            return list.get(0);
305                    }
306    
307                    return null;
308            }
309    
310            /**
311             * Returns the last message boards mailing list in the ordered set where uuid = &#63;.
312             *
313             * @param uuid the uuid
314             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
315             * @return the last matching message boards mailing list
316             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
317             * @throws SystemException if a system exception occurred
318             */
319            public MBMailingList findByUuid_Last(String uuid,
320                    OrderByComparator orderByComparator)
321                    throws NoSuchMailingListException, SystemException {
322                    MBMailingList mbMailingList = fetchByUuid_Last(uuid, orderByComparator);
323    
324                    if (mbMailingList != null) {
325                            return mbMailingList;
326                    }
327    
328                    StringBundler msg = new StringBundler(4);
329    
330                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
331    
332                    msg.append("uuid=");
333                    msg.append(uuid);
334    
335                    msg.append(StringPool.CLOSE_CURLY_BRACE);
336    
337                    throw new NoSuchMailingListException(msg.toString());
338            }
339    
340            /**
341             * Returns the last message boards mailing list in the ordered set where uuid = &#63;.
342             *
343             * @param uuid the uuid
344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
345             * @return the last matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
346             * @throws SystemException if a system exception occurred
347             */
348            public MBMailingList fetchByUuid_Last(String uuid,
349                    OrderByComparator orderByComparator) throws SystemException {
350                    int count = countByUuid(uuid);
351    
352                    List<MBMailingList> list = findByUuid(uuid, count - 1, count,
353                                    orderByComparator);
354    
355                    if (!list.isEmpty()) {
356                            return list.get(0);
357                    }
358    
359                    return null;
360            }
361    
362            /**
363             * Returns the message boards mailing lists before and after the current message boards mailing list in the ordered set where uuid = &#63;.
364             *
365             * @param mailingListId the primary key of the current message boards mailing list
366             * @param uuid the uuid
367             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
368             * @return the previous, current, and next message boards mailing list
369             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a message boards mailing list with the primary key could not be found
370             * @throws SystemException if a system exception occurred
371             */
372            public MBMailingList[] findByUuid_PrevAndNext(long mailingListId,
373                    String uuid, OrderByComparator orderByComparator)
374                    throws NoSuchMailingListException, SystemException {
375                    MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
376    
377                    Session session = null;
378    
379                    try {
380                            session = openSession();
381    
382                            MBMailingList[] array = new MBMailingListImpl[3];
383    
384                            array[0] = getByUuid_PrevAndNext(session, mbMailingList, uuid,
385                                            orderByComparator, true);
386    
387                            array[1] = mbMailingList;
388    
389                            array[2] = getByUuid_PrevAndNext(session, mbMailingList, uuid,
390                                            orderByComparator, false);
391    
392                            return array;
393                    }
394                    catch (Exception e) {
395                            throw processException(e);
396                    }
397                    finally {
398                            closeSession(session);
399                    }
400            }
401    
402            protected MBMailingList getByUuid_PrevAndNext(Session session,
403                    MBMailingList mbMailingList, String uuid,
404                    OrderByComparator orderByComparator, boolean previous) {
405                    StringBundler query = null;
406    
407                    if (orderByComparator != null) {
408                            query = new StringBundler(6 +
409                                            (orderByComparator.getOrderByFields().length * 6));
410                    }
411                    else {
412                            query = new StringBundler(3);
413                    }
414    
415                    query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
416    
417                    if (uuid == null) {
418                            query.append(_FINDER_COLUMN_UUID_UUID_1);
419                    }
420                    else {
421                            if (uuid.equals(StringPool.BLANK)) {
422                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
423                            }
424                            else {
425                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
426                            }
427                    }
428    
429                    if (orderByComparator != null) {
430                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
431    
432                            if (orderByConditionFields.length > 0) {
433                                    query.append(WHERE_AND);
434                            }
435    
436                            for (int i = 0; i < orderByConditionFields.length; i++) {
437                                    query.append(_ORDER_BY_ENTITY_ALIAS);
438                                    query.append(orderByConditionFields[i]);
439    
440                                    if ((i + 1) < orderByConditionFields.length) {
441                                            if (orderByComparator.isAscending() ^ previous) {
442                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
443                                            }
444                                            else {
445                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
446                                            }
447                                    }
448                                    else {
449                                            if (orderByComparator.isAscending() ^ previous) {
450                                                    query.append(WHERE_GREATER_THAN);
451                                            }
452                                            else {
453                                                    query.append(WHERE_LESSER_THAN);
454                                            }
455                                    }
456                            }
457    
458                            query.append(ORDER_BY_CLAUSE);
459    
460                            String[] orderByFields = orderByComparator.getOrderByFields();
461    
462                            for (int i = 0; i < orderByFields.length; i++) {
463                                    query.append(_ORDER_BY_ENTITY_ALIAS);
464                                    query.append(orderByFields[i]);
465    
466                                    if ((i + 1) < orderByFields.length) {
467                                            if (orderByComparator.isAscending() ^ previous) {
468                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
469                                            }
470                                            else {
471                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
472                                            }
473                                    }
474                                    else {
475                                            if (orderByComparator.isAscending() ^ previous) {
476                                                    query.append(ORDER_BY_ASC);
477                                            }
478                                            else {
479                                                    query.append(ORDER_BY_DESC);
480                                            }
481                                    }
482                            }
483                    }
484                    else {
485                            query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
486                    }
487    
488                    String sql = query.toString();
489    
490                    Query q = session.createQuery(sql);
491    
492                    q.setFirstResult(0);
493                    q.setMaxResults(2);
494    
495                    QueryPos qPos = QueryPos.getInstance(q);
496    
497                    if (uuid != null) {
498                            qPos.add(uuid);
499                    }
500    
501                    if (orderByComparator != null) {
502                            Object[] values = orderByComparator.getOrderByConditionValues(mbMailingList);
503    
504                            for (Object value : values) {
505                                    qPos.add(value);
506                            }
507                    }
508    
509                    List<MBMailingList> list = q.list();
510    
511                    if (list.size() == 2) {
512                            return list.get(1);
513                    }
514                    else {
515                            return null;
516                    }
517            }
518    
519            /**
520             * Removes all the message boards mailing lists where uuid = &#63; from the database.
521             *
522             * @param uuid the uuid
523             * @throws SystemException if a system exception occurred
524             */
525            public void removeByUuid(String uuid) throws SystemException {
526                    for (MBMailingList mbMailingList : findByUuid(uuid, QueryUtil.ALL_POS,
527                                    QueryUtil.ALL_POS, null)) {
528                            remove(mbMailingList);
529                    }
530            }
531    
532            /**
533             * Returns the number of message boards mailing lists where uuid = &#63;.
534             *
535             * @param uuid the uuid
536             * @return the number of matching message boards mailing lists
537             * @throws SystemException if a system exception occurred
538             */
539            public int countByUuid(String uuid) throws SystemException {
540                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
541    
542                    Object[] finderArgs = new Object[] { uuid };
543    
544                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
545                                    this);
546    
547                    if (count == null) {
548                            StringBundler query = new StringBundler(2);
549    
550                            query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
551    
552                            if (uuid == null) {
553                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
554                            }
555                            else {
556                                    if (uuid.equals(StringPool.BLANK)) {
557                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
558                                    }
559                                    else {
560                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
561                                    }
562                            }
563    
564                            String sql = query.toString();
565    
566                            Session session = null;
567    
568                            try {
569                                    session = openSession();
570    
571                                    Query q = session.createQuery(sql);
572    
573                                    QueryPos qPos = QueryPos.getInstance(q);
574    
575                                    if (uuid != null) {
576                                            qPos.add(uuid);
577                                    }
578    
579                                    count = (Long)q.uniqueResult();
580    
581                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
582                            }
583                            catch (Exception e) {
584                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
585    
586                                    throw processException(e);
587                            }
588                            finally {
589                                    closeSession(session);
590                            }
591                    }
592    
593                    return count.intValue();
594            }
595    
596            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMailingList.uuid IS NULL";
597            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMailingList.uuid = ?";
598            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = ?)";
599            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
600                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
601                            MBMailingListImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
602                            new String[] { String.class.getName(), Long.class.getName() },
603                            MBMailingListModelImpl.UUID_COLUMN_BITMASK |
604                            MBMailingListModelImpl.GROUPID_COLUMN_BITMASK);
605            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
606                            MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
607                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
608                            new String[] { String.class.getName(), Long.class.getName() });
609    
610            /**
611             * Returns 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.
612             *
613             * @param uuid the uuid
614             * @param groupId the group ID
615             * @return the matching message boards mailing list
616             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
617             * @throws SystemException if a system exception occurred
618             */
619            public MBMailingList findByUUID_G(String uuid, long groupId)
620                    throws NoSuchMailingListException, SystemException {
621                    MBMailingList mbMailingList = fetchByUUID_G(uuid, groupId);
622    
623                    if (mbMailingList == null) {
624                            StringBundler msg = new StringBundler(6);
625    
626                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
627    
628                            msg.append("uuid=");
629                            msg.append(uuid);
630    
631                            msg.append(", groupId=");
632                            msg.append(groupId);
633    
634                            msg.append(StringPool.CLOSE_CURLY_BRACE);
635    
636                            if (_log.isWarnEnabled()) {
637                                    _log.warn(msg.toString());
638                            }
639    
640                            throw new NoSuchMailingListException(msg.toString());
641                    }
642    
643                    return mbMailingList;
644            }
645    
646            /**
647             * Returns 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.
648             *
649             * @param uuid the uuid
650             * @param groupId the group ID
651             * @return the matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
652             * @throws SystemException if a system exception occurred
653             */
654            public MBMailingList fetchByUUID_G(String uuid, long groupId)
655                    throws SystemException {
656                    return fetchByUUID_G(uuid, groupId, true);
657            }
658    
659            /**
660             * Returns 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.
661             *
662             * @param uuid the uuid
663             * @param groupId the group ID
664             * @param retrieveFromCache whether to use the finder cache
665             * @return the matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
666             * @throws SystemException if a system exception occurred
667             */
668            public MBMailingList fetchByUUID_G(String uuid, long groupId,
669                    boolean retrieveFromCache) throws SystemException {
670                    Object[] finderArgs = new Object[] { uuid, groupId };
671    
672                    Object result = null;
673    
674                    if (retrieveFromCache) {
675                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
676                                            finderArgs, this);
677                    }
678    
679                    if (result instanceof MBMailingList) {
680                            MBMailingList mbMailingList = (MBMailingList)result;
681    
682                            if (!Validator.equals(uuid, mbMailingList.getUuid()) ||
683                                            (groupId != mbMailingList.getGroupId())) {
684                                    result = null;
685                            }
686                    }
687    
688                    if (result == null) {
689                            StringBundler query = new StringBundler(4);
690    
691                            query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
692    
693                            if (uuid == null) {
694                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
695                            }
696                            else {
697                                    if (uuid.equals(StringPool.BLANK)) {
698                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
699                                    }
700                                    else {
701                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
702                                    }
703                            }
704    
705                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
706    
707                            String sql = query.toString();
708    
709                            Session session = null;
710    
711                            try {
712                                    session = openSession();
713    
714                                    Query q = session.createQuery(sql);
715    
716                                    QueryPos qPos = QueryPos.getInstance(q);
717    
718                                    if (uuid != null) {
719                                            qPos.add(uuid);
720                                    }
721    
722                                    qPos.add(groupId);
723    
724                                    List<MBMailingList> list = q.list();
725    
726                                    if (list.isEmpty()) {
727                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
728                                                    finderArgs, list);
729                                    }
730                                    else {
731                                            MBMailingList mbMailingList = list.get(0);
732    
733                                            result = mbMailingList;
734    
735                                            cacheResult(mbMailingList);
736    
737                                            if ((mbMailingList.getUuid() == null) ||
738                                                            !mbMailingList.getUuid().equals(uuid) ||
739                                                            (mbMailingList.getGroupId() != groupId)) {
740                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
741                                                            finderArgs, mbMailingList);
742                                            }
743                                    }
744                            }
745                            catch (Exception e) {
746                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
747                                            finderArgs);
748    
749                                    throw processException(e);
750                            }
751                            finally {
752                                    closeSession(session);
753                            }
754                    }
755    
756                    if (result instanceof List<?>) {
757                            return null;
758                    }
759                    else {
760                            return (MBMailingList)result;
761                    }
762            }
763    
764            /**
765             * Removes the message boards mailing list where uuid = &#63; and groupId = &#63; from the database.
766             *
767             * @param uuid the uuid
768             * @param groupId the group ID
769             * @return the message boards mailing list that was removed
770             * @throws SystemException if a system exception occurred
771             */
772            public MBMailingList removeByUUID_G(String uuid, long groupId)
773                    throws NoSuchMailingListException, SystemException {
774                    MBMailingList mbMailingList = findByUUID_G(uuid, groupId);
775    
776                    return remove(mbMailingList);
777            }
778    
779            /**
780             * Returns the number of message boards mailing lists where uuid = &#63; and groupId = &#63;.
781             *
782             * @param uuid the uuid
783             * @param groupId the group ID
784             * @return the number of matching message boards mailing lists
785             * @throws SystemException if a system exception occurred
786             */
787            public int countByUUID_G(String uuid, long groupId)
788                    throws SystemException {
789                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
790    
791                    Object[] finderArgs = new Object[] { uuid, groupId };
792    
793                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
794                                    this);
795    
796                    if (count == null) {
797                            StringBundler query = new StringBundler(3);
798    
799                            query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
800    
801                            if (uuid == null) {
802                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
803                            }
804                            else {
805                                    if (uuid.equals(StringPool.BLANK)) {
806                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
807                                    }
808                                    else {
809                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
810                                    }
811                            }
812    
813                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
814    
815                            String sql = query.toString();
816    
817                            Session session = null;
818    
819                            try {
820                                    session = openSession();
821    
822                                    Query q = session.createQuery(sql);
823    
824                                    QueryPos qPos = QueryPos.getInstance(q);
825    
826                                    if (uuid != null) {
827                                            qPos.add(uuid);
828                                    }
829    
830                                    qPos.add(groupId);
831    
832                                    count = (Long)q.uniqueResult();
833    
834                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
835                            }
836                            catch (Exception e) {
837                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
838    
839                                    throw processException(e);
840                            }
841                            finally {
842                                    closeSession(session);
843                            }
844                    }
845    
846                    return count.intValue();
847            }
848    
849            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMailingList.uuid IS NULL AND ";
850            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMailingList.uuid = ? AND ";
851            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = ?) AND ";
852            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMailingList.groupId = ?";
853            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
854                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
855                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
856                            "findByUuid_C",
857                            new String[] {
858                                    String.class.getName(), Long.class.getName(),
859                                    
860                            Integer.class.getName(), Integer.class.getName(),
861                                    OrderByComparator.class.getName()
862                            });
863            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
864                    new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
865                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
866                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
867                            "findByUuid_C",
868                            new String[] { String.class.getName(), Long.class.getName() },
869                            MBMailingListModelImpl.UUID_COLUMN_BITMASK |
870                            MBMailingListModelImpl.COMPANYID_COLUMN_BITMASK);
871            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
872                            MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
873                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
874                            new String[] { String.class.getName(), Long.class.getName() });
875    
876            /**
877             * Returns all the message boards mailing lists where uuid = &#63; and companyId = &#63;.
878             *
879             * @param uuid the uuid
880             * @param companyId the company ID
881             * @return the matching message boards mailing lists
882             * @throws SystemException if a system exception occurred
883             */
884            public List<MBMailingList> findByUuid_C(String uuid, long companyId)
885                    throws SystemException {
886                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
887                            QueryUtil.ALL_POS, null);
888            }
889    
890            /**
891             * Returns a range of all the message boards mailing lists where uuid = &#63; and companyId = &#63;.
892             *
893             * <p>
894             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
895             * </p>
896             *
897             * @param uuid the uuid
898             * @param companyId the company ID
899             * @param start the lower bound of the range of message boards mailing lists
900             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
901             * @return the range of matching message boards mailing lists
902             * @throws SystemException if a system exception occurred
903             */
904            public List<MBMailingList> findByUuid_C(String uuid, long companyId,
905                    int start, int end) throws SystemException {
906                    return findByUuid_C(uuid, companyId, start, end, null);
907            }
908    
909            /**
910             * Returns an ordered range of all the message boards mailing lists where uuid = &#63; and companyId = &#63;.
911             *
912             * <p>
913             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
914             * </p>
915             *
916             * @param uuid the uuid
917             * @param companyId the company ID
918             * @param start the lower bound of the range of message boards mailing lists
919             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
920             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
921             * @return the ordered range of matching message boards mailing lists
922             * @throws SystemException if a system exception occurred
923             */
924            public List<MBMailingList> findByUuid_C(String uuid, long companyId,
925                    int start, int end, OrderByComparator orderByComparator)
926                    throws SystemException {
927                    boolean pagination = true;
928                    FinderPath finderPath = null;
929                    Object[] finderArgs = null;
930    
931                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
932                                    (orderByComparator == null)) {
933                            pagination = false;
934                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
935                            finderArgs = new Object[] { uuid, companyId };
936                    }
937                    else {
938                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
939                            finderArgs = new Object[] {
940                                            uuid, companyId,
941                                            
942                                            start, end, orderByComparator
943                                    };
944                    }
945    
946                    List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(finderPath,
947                                    finderArgs, this);
948    
949                    if ((list != null) && !list.isEmpty()) {
950                            for (MBMailingList mbMailingList : list) {
951                                    if (!Validator.equals(uuid, mbMailingList.getUuid()) ||
952                                                    (companyId != mbMailingList.getCompanyId())) {
953                                            list = null;
954    
955                                            break;
956                                    }
957                            }
958                    }
959    
960                    if (list == null) {
961                            StringBundler query = null;
962    
963                            if (orderByComparator != null) {
964                                    query = new StringBundler(4 +
965                                                    (orderByComparator.getOrderByFields().length * 3));
966                            }
967                            else {
968                                    query = new StringBundler(4);
969                            }
970    
971                            query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
972    
973                            if (uuid == null) {
974                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
975                            }
976                            else {
977                                    if (uuid.equals(StringPool.BLANK)) {
978                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
979                                    }
980                                    else {
981                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
982                                    }
983                            }
984    
985                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
986    
987                            if (orderByComparator != null) {
988                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
989                                            orderByComparator);
990                            }
991                            else
992                             if (pagination) {
993                                    query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
994                            }
995    
996                            String sql = query.toString();
997    
998                            Session session = null;
999    
1000                            try {
1001                                    session = openSession();
1002    
1003                                    Query q = session.createQuery(sql);
1004    
1005                                    QueryPos qPos = QueryPos.getInstance(q);
1006    
1007                                    if (uuid != null) {
1008                                            qPos.add(uuid);
1009                                    }
1010    
1011                                    qPos.add(companyId);
1012    
1013                                    if (!pagination) {
1014                                            list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1015                                                            start, end, false);
1016    
1017                                            Collections.sort(list);
1018    
1019                                            list = new UnmodifiableList<MBMailingList>(list);
1020                                    }
1021                                    else {
1022                                            list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1023                                                            start, end);
1024                                    }
1025    
1026                                    cacheResult(list);
1027    
1028                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1029                            }
1030                            catch (Exception e) {
1031                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1032    
1033                                    throw processException(e);
1034                            }
1035                            finally {
1036                                    closeSession(session);
1037                            }
1038                    }
1039    
1040                    return list;
1041            }
1042    
1043            /**
1044             * Returns the first message boards mailing list in the ordered set where uuid = &#63; and companyId = &#63;.
1045             *
1046             * @param uuid the uuid
1047             * @param companyId the company ID
1048             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1049             * @return the first matching message boards mailing list
1050             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
1051             * @throws SystemException if a system exception occurred
1052             */
1053            public MBMailingList findByUuid_C_First(String uuid, long companyId,
1054                    OrderByComparator orderByComparator)
1055                    throws NoSuchMailingListException, SystemException {
1056                    MBMailingList mbMailingList = fetchByUuid_C_First(uuid, companyId,
1057                                    orderByComparator);
1058    
1059                    if (mbMailingList != null) {
1060                            return mbMailingList;
1061                    }
1062    
1063                    StringBundler msg = new StringBundler(6);
1064    
1065                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1066    
1067                    msg.append("uuid=");
1068                    msg.append(uuid);
1069    
1070                    msg.append(", companyId=");
1071                    msg.append(companyId);
1072    
1073                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1074    
1075                    throw new NoSuchMailingListException(msg.toString());
1076            }
1077    
1078            /**
1079             * Returns the first message boards mailing list in the ordered set where uuid = &#63; and companyId = &#63;.
1080             *
1081             * @param uuid the uuid
1082             * @param companyId the company ID
1083             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1084             * @return the first matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1085             * @throws SystemException if a system exception occurred
1086             */
1087            public MBMailingList fetchByUuid_C_First(String uuid, long companyId,
1088                    OrderByComparator orderByComparator) throws SystemException {
1089                    List<MBMailingList> list = findByUuid_C(uuid, companyId, 0, 1,
1090                                    orderByComparator);
1091    
1092                    if (!list.isEmpty()) {
1093                            return list.get(0);
1094                    }
1095    
1096                    return null;
1097            }
1098    
1099            /**
1100             * Returns the last message boards mailing list in the ordered set where uuid = &#63; and companyId = &#63;.
1101             *
1102             * @param uuid the uuid
1103             * @param companyId the company ID
1104             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1105             * @return the last matching message boards mailing list
1106             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
1107             * @throws SystemException if a system exception occurred
1108             */
1109            public MBMailingList findByUuid_C_Last(String uuid, long companyId,
1110                    OrderByComparator orderByComparator)
1111                    throws NoSuchMailingListException, SystemException {
1112                    MBMailingList mbMailingList = fetchByUuid_C_Last(uuid, companyId,
1113                                    orderByComparator);
1114    
1115                    if (mbMailingList != null) {
1116                            return mbMailingList;
1117                    }
1118    
1119                    StringBundler msg = new StringBundler(6);
1120    
1121                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1122    
1123                    msg.append("uuid=");
1124                    msg.append(uuid);
1125    
1126                    msg.append(", companyId=");
1127                    msg.append(companyId);
1128    
1129                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1130    
1131                    throw new NoSuchMailingListException(msg.toString());
1132            }
1133    
1134            /**
1135             * Returns the last message boards mailing list in the ordered set where uuid = &#63; and companyId = &#63;.
1136             *
1137             * @param uuid the uuid
1138             * @param companyId the company ID
1139             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1140             * @return the last matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1141             * @throws SystemException if a system exception occurred
1142             */
1143            public MBMailingList fetchByUuid_C_Last(String uuid, long companyId,
1144                    OrderByComparator orderByComparator) throws SystemException {
1145                    int count = countByUuid_C(uuid, companyId);
1146    
1147                    List<MBMailingList> list = findByUuid_C(uuid, companyId, count - 1,
1148                                    count, orderByComparator);
1149    
1150                    if (!list.isEmpty()) {
1151                            return list.get(0);
1152                    }
1153    
1154                    return null;
1155            }
1156    
1157            /**
1158             * Returns the message boards mailing lists before and after the current message boards mailing list in the ordered set where uuid = &#63; and companyId = &#63;.
1159             *
1160             * @param mailingListId the primary key of the current message boards mailing list
1161             * @param uuid the uuid
1162             * @param companyId the company ID
1163             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1164             * @return the previous, current, and next message boards mailing list
1165             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a message boards mailing list with the primary key could not be found
1166             * @throws SystemException if a system exception occurred
1167             */
1168            public MBMailingList[] findByUuid_C_PrevAndNext(long mailingListId,
1169                    String uuid, long companyId, OrderByComparator orderByComparator)
1170                    throws NoSuchMailingListException, SystemException {
1171                    MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
1172    
1173                    Session session = null;
1174    
1175                    try {
1176                            session = openSession();
1177    
1178                            MBMailingList[] array = new MBMailingListImpl[3];
1179    
1180                            array[0] = getByUuid_C_PrevAndNext(session, mbMailingList, uuid,
1181                                            companyId, orderByComparator, true);
1182    
1183                            array[1] = mbMailingList;
1184    
1185                            array[2] = getByUuid_C_PrevAndNext(session, mbMailingList, uuid,
1186                                            companyId, orderByComparator, false);
1187    
1188                            return array;
1189                    }
1190                    catch (Exception e) {
1191                            throw processException(e);
1192                    }
1193                    finally {
1194                            closeSession(session);
1195                    }
1196            }
1197    
1198            protected MBMailingList getByUuid_C_PrevAndNext(Session session,
1199                    MBMailingList mbMailingList, String uuid, long companyId,
1200                    OrderByComparator orderByComparator, boolean previous) {
1201                    StringBundler query = null;
1202    
1203                    if (orderByComparator != null) {
1204                            query = new StringBundler(6 +
1205                                            (orderByComparator.getOrderByFields().length * 6));
1206                    }
1207                    else {
1208                            query = new StringBundler(3);
1209                    }
1210    
1211                    query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1212    
1213                    if (uuid == null) {
1214                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1215                    }
1216                    else {
1217                            if (uuid.equals(StringPool.BLANK)) {
1218                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1219                            }
1220                            else {
1221                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1222                            }
1223                    }
1224    
1225                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1226    
1227                    if (orderByComparator != null) {
1228                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1229    
1230                            if (orderByConditionFields.length > 0) {
1231                                    query.append(WHERE_AND);
1232                            }
1233    
1234                            for (int i = 0; i < orderByConditionFields.length; i++) {
1235                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1236                                    query.append(orderByConditionFields[i]);
1237    
1238                                    if ((i + 1) < orderByConditionFields.length) {
1239                                            if (orderByComparator.isAscending() ^ previous) {
1240                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1241                                            }
1242                                            else {
1243                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1244                                            }
1245                                    }
1246                                    else {
1247                                            if (orderByComparator.isAscending() ^ previous) {
1248                                                    query.append(WHERE_GREATER_THAN);
1249                                            }
1250                                            else {
1251                                                    query.append(WHERE_LESSER_THAN);
1252                                            }
1253                                    }
1254                            }
1255    
1256                            query.append(ORDER_BY_CLAUSE);
1257    
1258                            String[] orderByFields = orderByComparator.getOrderByFields();
1259    
1260                            for (int i = 0; i < orderByFields.length; i++) {
1261                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1262                                    query.append(orderByFields[i]);
1263    
1264                                    if ((i + 1) < orderByFields.length) {
1265                                            if (orderByComparator.isAscending() ^ previous) {
1266                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1267                                            }
1268                                            else {
1269                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1270                                            }
1271                                    }
1272                                    else {
1273                                            if (orderByComparator.isAscending() ^ previous) {
1274                                                    query.append(ORDER_BY_ASC);
1275                                            }
1276                                            else {
1277                                                    query.append(ORDER_BY_DESC);
1278                                            }
1279                                    }
1280                            }
1281                    }
1282                    else {
1283                            query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
1284                    }
1285    
1286                    String sql = query.toString();
1287    
1288                    Query q = session.createQuery(sql);
1289    
1290                    q.setFirstResult(0);
1291                    q.setMaxResults(2);
1292    
1293                    QueryPos qPos = QueryPos.getInstance(q);
1294    
1295                    if (uuid != null) {
1296                            qPos.add(uuid);
1297                    }
1298    
1299                    qPos.add(companyId);
1300    
1301                    if (orderByComparator != null) {
1302                            Object[] values = orderByComparator.getOrderByConditionValues(mbMailingList);
1303    
1304                            for (Object value : values) {
1305                                    qPos.add(value);
1306                            }
1307                    }
1308    
1309                    List<MBMailingList> list = q.list();
1310    
1311                    if (list.size() == 2) {
1312                            return list.get(1);
1313                    }
1314                    else {
1315                            return null;
1316                    }
1317            }
1318    
1319            /**
1320             * Removes all the message boards mailing lists where uuid = &#63; and companyId = &#63; from the database.
1321             *
1322             * @param uuid the uuid
1323             * @param companyId the company ID
1324             * @throws SystemException if a system exception occurred
1325             */
1326            public void removeByUuid_C(String uuid, long companyId)
1327                    throws SystemException {
1328                    for (MBMailingList mbMailingList : findByUuid_C(uuid, companyId,
1329                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1330                            remove(mbMailingList);
1331                    }
1332            }
1333    
1334            /**
1335             * Returns the number of message boards mailing lists where uuid = &#63; and companyId = &#63;.
1336             *
1337             * @param uuid the uuid
1338             * @param companyId the company ID
1339             * @return the number of matching message boards mailing lists
1340             * @throws SystemException if a system exception occurred
1341             */
1342            public int countByUuid_C(String uuid, long companyId)
1343                    throws SystemException {
1344                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1345    
1346                    Object[] finderArgs = new Object[] { uuid, companyId };
1347    
1348                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1349                                    this);
1350    
1351                    if (count == null) {
1352                            StringBundler query = new StringBundler(3);
1353    
1354                            query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1355    
1356                            if (uuid == null) {
1357                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1358                            }
1359                            else {
1360                                    if (uuid.equals(StringPool.BLANK)) {
1361                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1362                                    }
1363                                    else {
1364                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1365                                    }
1366                            }
1367    
1368                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1369    
1370                            String sql = query.toString();
1371    
1372                            Session session = null;
1373    
1374                            try {
1375                                    session = openSession();
1376    
1377                                    Query q = session.createQuery(sql);
1378    
1379                                    QueryPos qPos = QueryPos.getInstance(q);
1380    
1381                                    if (uuid != null) {
1382                                            qPos.add(uuid);
1383                                    }
1384    
1385                                    qPos.add(companyId);
1386    
1387                                    count = (Long)q.uniqueResult();
1388    
1389                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1390                            }
1391                            catch (Exception e) {
1392                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1393    
1394                                    throw processException(e);
1395                            }
1396                            finally {
1397                                    closeSession(session);
1398                            }
1399                    }
1400    
1401                    return count.intValue();
1402            }
1403    
1404            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMailingList.uuid IS NULL AND ";
1405            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMailingList.uuid = ? AND ";
1406            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = ?) AND ";
1407            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMailingList.companyId = ?";
1408            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1409                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
1410                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1411                            "findByActive",
1412                            new String[] {
1413                                    Boolean.class.getName(),
1414                                    
1415                            Integer.class.getName(), Integer.class.getName(),
1416                                    OrderByComparator.class.getName()
1417                            });
1418            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE =
1419                    new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1420                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
1421                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1422                            "findByActive", new String[] { Boolean.class.getName() },
1423                            MBMailingListModelImpl.ACTIVE_COLUMN_BITMASK);
1424            public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1425                            MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
1426                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByActive",
1427                            new String[] { Boolean.class.getName() });
1428    
1429            /**
1430             * Returns all the message boards mailing lists where active = &#63;.
1431             *
1432             * @param active the active
1433             * @return the matching message boards mailing lists
1434             * @throws SystemException if a system exception occurred
1435             */
1436            public List<MBMailingList> findByActive(boolean active)
1437                    throws SystemException {
1438                    return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1439            }
1440    
1441            /**
1442             * Returns a range of all the message boards mailing lists where active = &#63;.
1443             *
1444             * <p>
1445             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1446             * </p>
1447             *
1448             * @param active the active
1449             * @param start the lower bound of the range of message boards mailing lists
1450             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
1451             * @return the range of matching message boards mailing lists
1452             * @throws SystemException if a system exception occurred
1453             */
1454            public List<MBMailingList> findByActive(boolean active, int start, int end)
1455                    throws SystemException {
1456                    return findByActive(active, start, end, null);
1457            }
1458    
1459            /**
1460             * Returns an ordered range of all the message boards mailing lists where active = &#63;.
1461             *
1462             * <p>
1463             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1464             * </p>
1465             *
1466             * @param active the active
1467             * @param start the lower bound of the range of message boards mailing lists
1468             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
1469             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1470             * @return the ordered range of matching message boards mailing lists
1471             * @throws SystemException if a system exception occurred
1472             */
1473            public List<MBMailingList> findByActive(boolean active, int start, int end,
1474                    OrderByComparator orderByComparator) throws SystemException {
1475                    boolean pagination = true;
1476                    FinderPath finderPath = null;
1477                    Object[] finderArgs = null;
1478    
1479                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1480                                    (orderByComparator == null)) {
1481                            pagination = false;
1482                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE;
1483                            finderArgs = new Object[] { active };
1484                    }
1485                    else {
1486                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE;
1487                            finderArgs = new Object[] { active, start, end, orderByComparator };
1488                    }
1489    
1490                    List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(finderPath,
1491                                    finderArgs, this);
1492    
1493                    if ((list != null) && !list.isEmpty()) {
1494                            for (MBMailingList mbMailingList : list) {
1495                                    if ((active != mbMailingList.getActive())) {
1496                                            list = null;
1497    
1498                                            break;
1499                                    }
1500                            }
1501                    }
1502    
1503                    if (list == null) {
1504                            StringBundler query = null;
1505    
1506                            if (orderByComparator != null) {
1507                                    query = new StringBundler(3 +
1508                                                    (orderByComparator.getOrderByFields().length * 3));
1509                            }
1510                            else {
1511                                    query = new StringBundler(3);
1512                            }
1513    
1514                            query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1515    
1516                            query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1517    
1518                            if (orderByComparator != null) {
1519                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1520                                            orderByComparator);
1521                            }
1522                            else
1523                             if (pagination) {
1524                                    query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
1525                            }
1526    
1527                            String sql = query.toString();
1528    
1529                            Session session = null;
1530    
1531                            try {
1532                                    session = openSession();
1533    
1534                                    Query q = session.createQuery(sql);
1535    
1536                                    QueryPos qPos = QueryPos.getInstance(q);
1537    
1538                                    qPos.add(active);
1539    
1540                                    if (!pagination) {
1541                                            list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1542                                                            start, end, false);
1543    
1544                                            Collections.sort(list);
1545    
1546                                            list = new UnmodifiableList<MBMailingList>(list);
1547                                    }
1548                                    else {
1549                                            list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1550                                                            start, end);
1551                                    }
1552    
1553                                    cacheResult(list);
1554    
1555                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1556                            }
1557                            catch (Exception e) {
1558                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1559    
1560                                    throw processException(e);
1561                            }
1562                            finally {
1563                                    closeSession(session);
1564                            }
1565                    }
1566    
1567                    return list;
1568            }
1569    
1570            /**
1571             * Returns the first message boards mailing list in the ordered set where active = &#63;.
1572             *
1573             * @param active the active
1574             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1575             * @return the first matching message boards mailing list
1576             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
1577             * @throws SystemException if a system exception occurred
1578             */
1579            public MBMailingList findByActive_First(boolean active,
1580                    OrderByComparator orderByComparator)
1581                    throws NoSuchMailingListException, SystemException {
1582                    MBMailingList mbMailingList = fetchByActive_First(active,
1583                                    orderByComparator);
1584    
1585                    if (mbMailingList != null) {
1586                            return mbMailingList;
1587                    }
1588    
1589                    StringBundler msg = new StringBundler(4);
1590    
1591                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1592    
1593                    msg.append("active=");
1594                    msg.append(active);
1595    
1596                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1597    
1598                    throw new NoSuchMailingListException(msg.toString());
1599            }
1600    
1601            /**
1602             * Returns the first message boards mailing list in the ordered set where active = &#63;.
1603             *
1604             * @param active the active
1605             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1606             * @return the first matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1607             * @throws SystemException if a system exception occurred
1608             */
1609            public MBMailingList fetchByActive_First(boolean active,
1610                    OrderByComparator orderByComparator) throws SystemException {
1611                    List<MBMailingList> list = findByActive(active, 0, 1, orderByComparator);
1612    
1613                    if (!list.isEmpty()) {
1614                            return list.get(0);
1615                    }
1616    
1617                    return null;
1618            }
1619    
1620            /**
1621             * Returns the last message boards mailing list in the ordered set where active = &#63;.
1622             *
1623             * @param active the active
1624             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1625             * @return the last matching message boards mailing list
1626             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
1627             * @throws SystemException if a system exception occurred
1628             */
1629            public MBMailingList findByActive_Last(boolean active,
1630                    OrderByComparator orderByComparator)
1631                    throws NoSuchMailingListException, SystemException {
1632                    MBMailingList mbMailingList = fetchByActive_Last(active,
1633                                    orderByComparator);
1634    
1635                    if (mbMailingList != null) {
1636                            return mbMailingList;
1637                    }
1638    
1639                    StringBundler msg = new StringBundler(4);
1640    
1641                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1642    
1643                    msg.append("active=");
1644                    msg.append(active);
1645    
1646                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1647    
1648                    throw new NoSuchMailingListException(msg.toString());
1649            }
1650    
1651            /**
1652             * Returns the last message boards mailing list in the ordered set where active = &#63;.
1653             *
1654             * @param active the active
1655             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1656             * @return the last matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1657             * @throws SystemException if a system exception occurred
1658             */
1659            public MBMailingList fetchByActive_Last(boolean active,
1660                    OrderByComparator orderByComparator) throws SystemException {
1661                    int count = countByActive(active);
1662    
1663                    List<MBMailingList> list = findByActive(active, count - 1, count,
1664                                    orderByComparator);
1665    
1666                    if (!list.isEmpty()) {
1667                            return list.get(0);
1668                    }
1669    
1670                    return null;
1671            }
1672    
1673            /**
1674             * Returns the message boards mailing lists before and after the current message boards mailing list in the ordered set where active = &#63;.
1675             *
1676             * @param mailingListId the primary key of the current message boards mailing list
1677             * @param active the active
1678             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1679             * @return the previous, current, and next message boards mailing list
1680             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a message boards mailing list with the primary key could not be found
1681             * @throws SystemException if a system exception occurred
1682             */
1683            public MBMailingList[] findByActive_PrevAndNext(long mailingListId,
1684                    boolean active, OrderByComparator orderByComparator)
1685                    throws NoSuchMailingListException, SystemException {
1686                    MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
1687    
1688                    Session session = null;
1689    
1690                    try {
1691                            session = openSession();
1692    
1693                            MBMailingList[] array = new MBMailingListImpl[3];
1694    
1695                            array[0] = getByActive_PrevAndNext(session, mbMailingList, active,
1696                                            orderByComparator, true);
1697    
1698                            array[1] = mbMailingList;
1699    
1700                            array[2] = getByActive_PrevAndNext(session, mbMailingList, active,
1701                                            orderByComparator, false);
1702    
1703                            return array;
1704                    }
1705                    catch (Exception e) {
1706                            throw processException(e);
1707                    }
1708                    finally {
1709                            closeSession(session);
1710                    }
1711            }
1712    
1713            protected MBMailingList getByActive_PrevAndNext(Session session,
1714                    MBMailingList mbMailingList, boolean active,
1715                    OrderByComparator orderByComparator, boolean previous) {
1716                    StringBundler query = null;
1717    
1718                    if (orderByComparator != null) {
1719                            query = new StringBundler(6 +
1720                                            (orderByComparator.getOrderByFields().length * 6));
1721                    }
1722                    else {
1723                            query = new StringBundler(3);
1724                    }
1725    
1726                    query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1727    
1728                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1729    
1730                    if (orderByComparator != null) {
1731                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1732    
1733                            if (orderByConditionFields.length > 0) {
1734                                    query.append(WHERE_AND);
1735                            }
1736    
1737                            for (int i = 0; i < orderByConditionFields.length; i++) {
1738                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1739                                    query.append(orderByConditionFields[i]);
1740    
1741                                    if ((i + 1) < orderByConditionFields.length) {
1742                                            if (orderByComparator.isAscending() ^ previous) {
1743                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1744                                            }
1745                                            else {
1746                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1747                                            }
1748                                    }
1749                                    else {
1750                                            if (orderByComparator.isAscending() ^ previous) {
1751                                                    query.append(WHERE_GREATER_THAN);
1752                                            }
1753                                            else {
1754                                                    query.append(WHERE_LESSER_THAN);
1755                                            }
1756                                    }
1757                            }
1758    
1759                            query.append(ORDER_BY_CLAUSE);
1760    
1761                            String[] orderByFields = orderByComparator.getOrderByFields();
1762    
1763                            for (int i = 0; i < orderByFields.length; i++) {
1764                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1765                                    query.append(orderByFields[i]);
1766    
1767                                    if ((i + 1) < orderByFields.length) {
1768                                            if (orderByComparator.isAscending() ^ previous) {
1769                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1770                                            }
1771                                            else {
1772                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1773                                            }
1774                                    }
1775                                    else {
1776                                            if (orderByComparator.isAscending() ^ previous) {
1777                                                    query.append(ORDER_BY_ASC);
1778                                            }
1779                                            else {
1780                                                    query.append(ORDER_BY_DESC);
1781                                            }
1782                                    }
1783                            }
1784                    }
1785                    else {
1786                            query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
1787                    }
1788    
1789                    String sql = query.toString();
1790    
1791                    Query q = session.createQuery(sql);
1792    
1793                    q.setFirstResult(0);
1794                    q.setMaxResults(2);
1795    
1796                    QueryPos qPos = QueryPos.getInstance(q);
1797    
1798                    qPos.add(active);
1799    
1800                    if (orderByComparator != null) {
1801                            Object[] values = orderByComparator.getOrderByConditionValues(mbMailingList);
1802    
1803                            for (Object value : values) {
1804                                    qPos.add(value);
1805                            }
1806                    }
1807    
1808                    List<MBMailingList> list = q.list();
1809    
1810                    if (list.size() == 2) {
1811                            return list.get(1);
1812                    }
1813                    else {
1814                            return null;
1815                    }
1816            }
1817    
1818            /**
1819             * Removes all the message boards mailing lists where active = &#63; from the database.
1820             *
1821             * @param active the active
1822             * @throws SystemException if a system exception occurred
1823             */
1824            public void removeByActive(boolean active) throws SystemException {
1825                    for (MBMailingList mbMailingList : findByActive(active,
1826                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1827                            remove(mbMailingList);
1828                    }
1829            }
1830    
1831            /**
1832             * Returns the number of message boards mailing lists where active = &#63;.
1833             *
1834             * @param active the active
1835             * @return the number of matching message boards mailing lists
1836             * @throws SystemException if a system exception occurred
1837             */
1838            public int countByActive(boolean active) throws SystemException {
1839                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ACTIVE;
1840    
1841                    Object[] finderArgs = new Object[] { active };
1842    
1843                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1844                                    this);
1845    
1846                    if (count == null) {
1847                            StringBundler query = new StringBundler(2);
1848    
1849                            query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1850    
1851                            query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1852    
1853                            String sql = query.toString();
1854    
1855                            Session session = null;
1856    
1857                            try {
1858                                    session = openSession();
1859    
1860                                    Query q = session.createQuery(sql);
1861    
1862                                    QueryPos qPos = QueryPos.getInstance(q);
1863    
1864                                    qPos.add(active);
1865    
1866                                    count = (Long)q.uniqueResult();
1867    
1868                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1869                            }
1870                            catch (Exception e) {
1871                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1872    
1873                                    throw processException(e);
1874                            }
1875                            finally {
1876                                    closeSession(session);
1877                            }
1878                    }
1879    
1880                    return count.intValue();
1881            }
1882    
1883            private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "mbMailingList.active = ?";
1884            public static final FinderPath FINDER_PATH_FETCH_BY_G_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1885                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
1886                            MBMailingListImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_C",
1887                            new String[] { Long.class.getName(), Long.class.getName() },
1888                            MBMailingListModelImpl.GROUPID_COLUMN_BITMASK |
1889                            MBMailingListModelImpl.CATEGORYID_COLUMN_BITMASK);
1890            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1891                            MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
1892                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
1893                            new String[] { Long.class.getName(), Long.class.getName() });
1894    
1895            /**
1896             * Returns 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.
1897             *
1898             * @param groupId the group ID
1899             * @param categoryId the category ID
1900             * @return the matching message boards mailing list
1901             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
1902             * @throws SystemException if a system exception occurred
1903             */
1904            public MBMailingList findByG_C(long groupId, long categoryId)
1905                    throws NoSuchMailingListException, SystemException {
1906                    MBMailingList mbMailingList = fetchByG_C(groupId, categoryId);
1907    
1908                    if (mbMailingList == null) {
1909                            StringBundler msg = new StringBundler(6);
1910    
1911                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1912    
1913                            msg.append("groupId=");
1914                            msg.append(groupId);
1915    
1916                            msg.append(", categoryId=");
1917                            msg.append(categoryId);
1918    
1919                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1920    
1921                            if (_log.isWarnEnabled()) {
1922                                    _log.warn(msg.toString());
1923                            }
1924    
1925                            throw new NoSuchMailingListException(msg.toString());
1926                    }
1927    
1928                    return mbMailingList;
1929            }
1930    
1931            /**
1932             * Returns 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.
1933             *
1934             * @param groupId the group ID
1935             * @param categoryId the category ID
1936             * @return the matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1937             * @throws SystemException if a system exception occurred
1938             */
1939            public MBMailingList fetchByG_C(long groupId, long categoryId)
1940                    throws SystemException {
1941                    return fetchByG_C(groupId, categoryId, true);
1942            }
1943    
1944            /**
1945             * Returns 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.
1946             *
1947             * @param groupId the group ID
1948             * @param categoryId the category ID
1949             * @param retrieveFromCache whether to use the finder cache
1950             * @return the matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1951             * @throws SystemException if a system exception occurred
1952             */
1953            public MBMailingList fetchByG_C(long groupId, long categoryId,
1954                    boolean retrieveFromCache) throws SystemException {
1955                    Object[] finderArgs = new Object[] { groupId, categoryId };
1956    
1957                    Object result = null;
1958    
1959                    if (retrieveFromCache) {
1960                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C,
1961                                            finderArgs, this);
1962                    }
1963    
1964                    if (result instanceof MBMailingList) {
1965                            MBMailingList mbMailingList = (MBMailingList)result;
1966    
1967                            if ((groupId != mbMailingList.getGroupId()) ||
1968                                            (categoryId != mbMailingList.getCategoryId())) {
1969                                    result = null;
1970                            }
1971                    }
1972    
1973                    if (result == null) {
1974                            StringBundler query = new StringBundler(4);
1975    
1976                            query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1977    
1978                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1979    
1980                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1981    
1982                            String sql = query.toString();
1983    
1984                            Session session = null;
1985    
1986                            try {
1987                                    session = openSession();
1988    
1989                                    Query q = session.createQuery(sql);
1990    
1991                                    QueryPos qPos = QueryPos.getInstance(q);
1992    
1993                                    qPos.add(groupId);
1994    
1995                                    qPos.add(categoryId);
1996    
1997                                    List<MBMailingList> list = q.list();
1998    
1999                                    if (list.isEmpty()) {
2000                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
2001                                                    finderArgs, list);
2002                                    }
2003                                    else {
2004                                            MBMailingList mbMailingList = list.get(0);
2005    
2006                                            result = mbMailingList;
2007    
2008                                            cacheResult(mbMailingList);
2009    
2010                                            if ((mbMailingList.getGroupId() != groupId) ||
2011                                                            (mbMailingList.getCategoryId() != categoryId)) {
2012                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
2013                                                            finderArgs, mbMailingList);
2014                                            }
2015                                    }
2016                            }
2017                            catch (Exception e) {
2018                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C,
2019                                            finderArgs);
2020    
2021                                    throw processException(e);
2022                            }
2023                            finally {
2024                                    closeSession(session);
2025                            }
2026                    }
2027    
2028                    if (result instanceof List<?>) {
2029                            return null;
2030                    }
2031                    else {
2032                            return (MBMailingList)result;
2033                    }
2034            }
2035    
2036            /**
2037             * Removes the message boards mailing list where groupId = &#63; and categoryId = &#63; from the database.
2038             *
2039             * @param groupId the group ID
2040             * @param categoryId the category ID
2041             * @return the message boards mailing list that was removed
2042             * @throws SystemException if a system exception occurred
2043             */
2044            public MBMailingList removeByG_C(long groupId, long categoryId)
2045                    throws NoSuchMailingListException, SystemException {
2046                    MBMailingList mbMailingList = findByG_C(groupId, categoryId);
2047    
2048                    return remove(mbMailingList);
2049            }
2050    
2051            /**
2052             * Returns the number of message boards mailing lists where groupId = &#63; and categoryId = &#63;.
2053             *
2054             * @param groupId the group ID
2055             * @param categoryId the category ID
2056             * @return the number of matching message boards mailing lists
2057             * @throws SystemException if a system exception occurred
2058             */
2059            public int countByG_C(long groupId, long categoryId)
2060                    throws SystemException {
2061                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
2062    
2063                    Object[] finderArgs = new Object[] { groupId, categoryId };
2064    
2065                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2066                                    this);
2067    
2068                    if (count == null) {
2069                            StringBundler query = new StringBundler(3);
2070    
2071                            query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
2072    
2073                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2074    
2075                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2076    
2077                            String sql = query.toString();
2078    
2079                            Session session = null;
2080    
2081                            try {
2082                                    session = openSession();
2083    
2084                                    Query q = session.createQuery(sql);
2085    
2086                                    QueryPos qPos = QueryPos.getInstance(q);
2087    
2088                                    qPos.add(groupId);
2089    
2090                                    qPos.add(categoryId);
2091    
2092                                    count = (Long)q.uniqueResult();
2093    
2094                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2095                            }
2096                            catch (Exception e) {
2097                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2098    
2099                                    throw processException(e);
2100                            }
2101                            finally {
2102                                    closeSession(session);
2103                            }
2104                    }
2105    
2106                    return count.intValue();
2107            }
2108    
2109            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMailingList.groupId = ? AND ";
2110            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMailingList.categoryId = ?";
2111    
2112            /**
2113             * Caches the message boards mailing list in the entity cache if it is enabled.
2114             *
2115             * @param mbMailingList the message boards mailing list
2116             */
2117            public void cacheResult(MBMailingList mbMailingList) {
2118                    EntityCacheUtil.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2119                            MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
2120                            mbMailingList);
2121    
2122                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2123                            new Object[] {
2124                                    mbMailingList.getUuid(),
2125                                    Long.valueOf(mbMailingList.getGroupId())
2126                            }, mbMailingList);
2127    
2128                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
2129                            new Object[] {
2130                                    Long.valueOf(mbMailingList.getGroupId()),
2131                                    Long.valueOf(mbMailingList.getCategoryId())
2132                            }, mbMailingList);
2133    
2134                    mbMailingList.resetOriginalValues();
2135            }
2136    
2137            /**
2138             * Caches the message boards mailing lists in the entity cache if it is enabled.
2139             *
2140             * @param mbMailingLists the message boards mailing lists
2141             */
2142            public void cacheResult(List<MBMailingList> mbMailingLists) {
2143                    for (MBMailingList mbMailingList : mbMailingLists) {
2144                            if (EntityCacheUtil.getResult(
2145                                                    MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2146                                                    MBMailingListImpl.class, mbMailingList.getPrimaryKey()) == null) {
2147                                    cacheResult(mbMailingList);
2148                            }
2149                            else {
2150                                    mbMailingList.resetOriginalValues();
2151                            }
2152                    }
2153            }
2154    
2155            /**
2156             * Clears the cache for all message boards mailing lists.
2157             *
2158             * <p>
2159             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2160             * </p>
2161             */
2162            @Override
2163            public void clearCache() {
2164                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2165                            CacheRegistryUtil.clear(MBMailingListImpl.class.getName());
2166                    }
2167    
2168                    EntityCacheUtil.clearCache(MBMailingListImpl.class.getName());
2169    
2170                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2171                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2172                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2173            }
2174    
2175            /**
2176             * Clears the cache for the message boards mailing list.
2177             *
2178             * <p>
2179             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2180             * </p>
2181             */
2182            @Override
2183            public void clearCache(MBMailingList mbMailingList) {
2184                    EntityCacheUtil.removeResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2185                            MBMailingListImpl.class, mbMailingList.getPrimaryKey());
2186    
2187                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2188                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2189    
2190                    clearUniqueFindersCache(mbMailingList);
2191            }
2192    
2193            @Override
2194            public void clearCache(List<MBMailingList> mbMailingLists) {
2195                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2196                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2197    
2198                    for (MBMailingList mbMailingList : mbMailingLists) {
2199                            EntityCacheUtil.removeResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2200                                    MBMailingListImpl.class, mbMailingList.getPrimaryKey());
2201    
2202                            clearUniqueFindersCache(mbMailingList);
2203                    }
2204            }
2205    
2206            protected void cacheUniqueFindersCache(MBMailingList mbMailingList) {
2207                    if (mbMailingList.isNew()) {
2208                            Object[] args = new Object[] {
2209                                            mbMailingList.getUuid(),
2210                                            Long.valueOf(mbMailingList.getGroupId())
2211                                    };
2212    
2213                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2214                                    Long.valueOf(1));
2215                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2216                                    mbMailingList);
2217    
2218                            args = new Object[] {
2219                                            Long.valueOf(mbMailingList.getGroupId()),
2220                                            Long.valueOf(mbMailingList.getCategoryId())
2221                                    };
2222    
2223                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, args,
2224                                    Long.valueOf(1));
2225                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C, args,
2226                                    mbMailingList);
2227                    }
2228                    else {
2229                            MBMailingListModelImpl mbMailingListModelImpl = (MBMailingListModelImpl)mbMailingList;
2230    
2231                            if ((mbMailingListModelImpl.getColumnBitmask() &
2232                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2233                                    Object[] args = new Object[] {
2234                                                    mbMailingList.getUuid(),
2235                                                    Long.valueOf(mbMailingList.getGroupId())
2236                                            };
2237    
2238                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2239                                            Long.valueOf(1));
2240                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2241                                            mbMailingList);
2242                            }
2243    
2244                            if ((mbMailingListModelImpl.getColumnBitmask() &
2245                                            FINDER_PATH_FETCH_BY_G_C.getColumnBitmask()) != 0) {
2246                                    Object[] args = new Object[] {
2247                                                    Long.valueOf(mbMailingList.getGroupId()),
2248                                                    Long.valueOf(mbMailingList.getCategoryId())
2249                                            };
2250    
2251                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, args,
2252                                            Long.valueOf(1));
2253                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C, args,
2254                                            mbMailingList);
2255                            }
2256                    }
2257            }
2258    
2259            protected void clearUniqueFindersCache(MBMailingList mbMailingList) {
2260                    MBMailingListModelImpl mbMailingListModelImpl = (MBMailingListModelImpl)mbMailingList;
2261    
2262                    Object[] args = new Object[] {
2263                                    mbMailingList.getUuid(),
2264                                    Long.valueOf(mbMailingList.getGroupId())
2265                            };
2266    
2267                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2268                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2269    
2270                    if ((mbMailingListModelImpl.getColumnBitmask() &
2271                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2272                            args = new Object[] {
2273                                            mbMailingListModelImpl.getOriginalUuid(),
2274                                            Long.valueOf(mbMailingListModelImpl.getOriginalGroupId())
2275                                    };
2276    
2277                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2278                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2279                    }
2280    
2281                    args = new Object[] {
2282                                    Long.valueOf(mbMailingList.getGroupId()),
2283                                    Long.valueOf(mbMailingList.getCategoryId())
2284                            };
2285    
2286                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2287                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C, args);
2288    
2289                    if ((mbMailingListModelImpl.getColumnBitmask() &
2290                                    FINDER_PATH_FETCH_BY_G_C.getColumnBitmask()) != 0) {
2291                            args = new Object[] {
2292                                            Long.valueOf(mbMailingListModelImpl.getOriginalGroupId()),
2293                                            Long.valueOf(mbMailingListModelImpl.getOriginalCategoryId())
2294                                    };
2295    
2296                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2297                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C, args);
2298                    }
2299            }
2300    
2301            /**
2302             * Creates a new message boards mailing list with the primary key. Does not add the message boards mailing list to the database.
2303             *
2304             * @param mailingListId the primary key for the new message boards mailing list
2305             * @return the new message boards mailing list
2306             */
2307            public MBMailingList create(long mailingListId) {
2308                    MBMailingList mbMailingList = new MBMailingListImpl();
2309    
2310                    mbMailingList.setNew(true);
2311                    mbMailingList.setPrimaryKey(mailingListId);
2312    
2313                    String uuid = PortalUUIDUtil.generate();
2314    
2315                    mbMailingList.setUuid(uuid);
2316    
2317                    return mbMailingList;
2318            }
2319    
2320            /**
2321             * Removes the message boards mailing list with the primary key from the database. Also notifies the appropriate model listeners.
2322             *
2323             * @param mailingListId the primary key of the message boards mailing list
2324             * @return the message boards mailing list that was removed
2325             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a message boards mailing list with the primary key could not be found
2326             * @throws SystemException if a system exception occurred
2327             */
2328            public MBMailingList remove(long mailingListId)
2329                    throws NoSuchMailingListException, SystemException {
2330                    return remove(Long.valueOf(mailingListId));
2331            }
2332    
2333            /**
2334             * Removes the message boards mailing list with the primary key from the database. Also notifies the appropriate model listeners.
2335             *
2336             * @param primaryKey the primary key of the message boards mailing list
2337             * @return the message boards mailing list that was removed
2338             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a message boards mailing list with the primary key could not be found
2339             * @throws SystemException if a system exception occurred
2340             */
2341            @Override
2342            public MBMailingList remove(Serializable primaryKey)
2343                    throws NoSuchMailingListException, SystemException {
2344                    Session session = null;
2345    
2346                    try {
2347                            session = openSession();
2348    
2349                            MBMailingList mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
2350                                            primaryKey);
2351    
2352                            if (mbMailingList == null) {
2353                                    if (_log.isWarnEnabled()) {
2354                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2355                                    }
2356    
2357                                    throw new NoSuchMailingListException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2358                                            primaryKey);
2359                            }
2360    
2361                            return remove(mbMailingList);
2362                    }
2363                    catch (NoSuchMailingListException nsee) {
2364                            throw nsee;
2365                    }
2366                    catch (Exception e) {
2367                            throw processException(e);
2368                    }
2369                    finally {
2370                            closeSession(session);
2371                    }
2372            }
2373    
2374            @Override
2375            protected MBMailingList removeImpl(MBMailingList mbMailingList)
2376                    throws SystemException {
2377                    mbMailingList = toUnwrappedModel(mbMailingList);
2378    
2379                    Session session = null;
2380    
2381                    try {
2382                            session = openSession();
2383    
2384                            if (!session.contains(mbMailingList)) {
2385                                    mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
2386                                                    mbMailingList.getPrimaryKeyObj());
2387                            }
2388    
2389                            if (mbMailingList != null) {
2390                                    session.delete(mbMailingList);
2391                            }
2392                    }
2393                    catch (Exception e) {
2394                            throw processException(e);
2395                    }
2396                    finally {
2397                            closeSession(session);
2398                    }
2399    
2400                    if (mbMailingList != null) {
2401                            clearCache(mbMailingList);
2402                    }
2403    
2404                    return mbMailingList;
2405            }
2406    
2407            @Override
2408            public MBMailingList updateImpl(
2409                    com.liferay.portlet.messageboards.model.MBMailingList mbMailingList)
2410                    throws SystemException {
2411                    mbMailingList = toUnwrappedModel(mbMailingList);
2412    
2413                    boolean isNew = mbMailingList.isNew();
2414    
2415                    MBMailingListModelImpl mbMailingListModelImpl = (MBMailingListModelImpl)mbMailingList;
2416    
2417                    if (Validator.isNull(mbMailingList.getUuid())) {
2418                            String uuid = PortalUUIDUtil.generate();
2419    
2420                            mbMailingList.setUuid(uuid);
2421                    }
2422    
2423                    Session session = null;
2424    
2425                    try {
2426                            session = openSession();
2427    
2428                            if (mbMailingList.isNew()) {
2429                                    session.save(mbMailingList);
2430    
2431                                    mbMailingList.setNew(false);
2432                            }
2433                            else {
2434                                    session.merge(mbMailingList);
2435                            }
2436                    }
2437                    catch (Exception e) {
2438                            throw processException(e);
2439                    }
2440                    finally {
2441                            closeSession(session);
2442                    }
2443    
2444                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2445    
2446                    if (isNew || !MBMailingListModelImpl.COLUMN_BITMASK_ENABLED) {
2447                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2448                    }
2449    
2450                    else {
2451                            if ((mbMailingListModelImpl.getColumnBitmask() &
2452                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2453                                    Object[] args = new Object[] {
2454                                                    mbMailingListModelImpl.getOriginalUuid()
2455                                            };
2456    
2457                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2458                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2459                                            args);
2460    
2461                                    args = new Object[] { mbMailingListModelImpl.getUuid() };
2462    
2463                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2464                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2465                                            args);
2466                            }
2467    
2468                            if ((mbMailingListModelImpl.getColumnBitmask() &
2469                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2470                                    Object[] args = new Object[] {
2471                                                    mbMailingListModelImpl.getOriginalUuid(),
2472                                                    Long.valueOf(mbMailingListModelImpl.getOriginalCompanyId())
2473                                            };
2474    
2475                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2476                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2477                                            args);
2478    
2479                                    args = new Object[] {
2480                                                    mbMailingListModelImpl.getUuid(),
2481                                                    Long.valueOf(mbMailingListModelImpl.getCompanyId())
2482                                            };
2483    
2484                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2485                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2486                                            args);
2487                            }
2488    
2489                            if ((mbMailingListModelImpl.getColumnBitmask() &
2490                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE.getColumnBitmask()) != 0) {
2491                                    Object[] args = new Object[] {
2492                                                    Boolean.valueOf(mbMailingListModelImpl.getOriginalActive())
2493                                            };
2494    
2495                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
2496                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
2497                                            args);
2498    
2499                                    args = new Object[] {
2500                                                    Boolean.valueOf(mbMailingListModelImpl.getActive())
2501                                            };
2502    
2503                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
2504                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
2505                                            args);
2506                            }
2507                    }
2508    
2509                    EntityCacheUtil.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2510                            MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
2511                            mbMailingList);
2512    
2513                    clearUniqueFindersCache(mbMailingList);
2514                    cacheUniqueFindersCache(mbMailingList);
2515    
2516                    return mbMailingList;
2517            }
2518    
2519            protected MBMailingList toUnwrappedModel(MBMailingList mbMailingList) {
2520                    if (mbMailingList instanceof MBMailingListImpl) {
2521                            return mbMailingList;
2522                    }
2523    
2524                    MBMailingListImpl mbMailingListImpl = new MBMailingListImpl();
2525    
2526                    mbMailingListImpl.setNew(mbMailingList.isNew());
2527                    mbMailingListImpl.setPrimaryKey(mbMailingList.getPrimaryKey());
2528    
2529                    mbMailingListImpl.setUuid(mbMailingList.getUuid());
2530                    mbMailingListImpl.setMailingListId(mbMailingList.getMailingListId());
2531                    mbMailingListImpl.setGroupId(mbMailingList.getGroupId());
2532                    mbMailingListImpl.setCompanyId(mbMailingList.getCompanyId());
2533                    mbMailingListImpl.setUserId(mbMailingList.getUserId());
2534                    mbMailingListImpl.setUserName(mbMailingList.getUserName());
2535                    mbMailingListImpl.setCreateDate(mbMailingList.getCreateDate());
2536                    mbMailingListImpl.setModifiedDate(mbMailingList.getModifiedDate());
2537                    mbMailingListImpl.setCategoryId(mbMailingList.getCategoryId());
2538                    mbMailingListImpl.setEmailAddress(mbMailingList.getEmailAddress());
2539                    mbMailingListImpl.setInProtocol(mbMailingList.getInProtocol());
2540                    mbMailingListImpl.setInServerName(mbMailingList.getInServerName());
2541                    mbMailingListImpl.setInServerPort(mbMailingList.getInServerPort());
2542                    mbMailingListImpl.setInUseSSL(mbMailingList.isInUseSSL());
2543                    mbMailingListImpl.setInUserName(mbMailingList.getInUserName());
2544                    mbMailingListImpl.setInPassword(mbMailingList.getInPassword());
2545                    mbMailingListImpl.setInReadInterval(mbMailingList.getInReadInterval());
2546                    mbMailingListImpl.setOutEmailAddress(mbMailingList.getOutEmailAddress());
2547                    mbMailingListImpl.setOutCustom(mbMailingList.isOutCustom());
2548                    mbMailingListImpl.setOutServerName(mbMailingList.getOutServerName());
2549                    mbMailingListImpl.setOutServerPort(mbMailingList.getOutServerPort());
2550                    mbMailingListImpl.setOutUseSSL(mbMailingList.isOutUseSSL());
2551                    mbMailingListImpl.setOutUserName(mbMailingList.getOutUserName());
2552                    mbMailingListImpl.setOutPassword(mbMailingList.getOutPassword());
2553                    mbMailingListImpl.setAllowAnonymous(mbMailingList.isAllowAnonymous());
2554                    mbMailingListImpl.setActive(mbMailingList.isActive());
2555    
2556                    return mbMailingListImpl;
2557            }
2558    
2559            /**
2560             * Returns the message boards mailing list with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2561             *
2562             * @param primaryKey the primary key of the message boards mailing list
2563             * @return the message boards mailing list
2564             * @throws com.liferay.portal.NoSuchModelException if a message boards mailing list with the primary key could not be found
2565             * @throws SystemException if a system exception occurred
2566             */
2567            @Override
2568            public MBMailingList findByPrimaryKey(Serializable primaryKey)
2569                    throws NoSuchModelException, SystemException {
2570                    return findByPrimaryKey(((Long)primaryKey).longValue());
2571            }
2572    
2573            /**
2574             * Returns the message boards mailing list with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMailingListException} if it could not be found.
2575             *
2576             * @param mailingListId the primary key of the message boards mailing list
2577             * @return the message boards mailing list
2578             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a message boards mailing list with the primary key could not be found
2579             * @throws SystemException if a system exception occurred
2580             */
2581            public MBMailingList findByPrimaryKey(long mailingListId)
2582                    throws NoSuchMailingListException, SystemException {
2583                    MBMailingList mbMailingList = fetchByPrimaryKey(mailingListId);
2584    
2585                    if (mbMailingList == null) {
2586                            if (_log.isWarnEnabled()) {
2587                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + mailingListId);
2588                            }
2589    
2590                            throw new NoSuchMailingListException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2591                                    mailingListId);
2592                    }
2593    
2594                    return mbMailingList;
2595            }
2596    
2597            /**
2598             * Returns the message boards mailing list with the primary key or returns <code>null</code> if it could not be found.
2599             *
2600             * @param primaryKey the primary key of the message boards mailing list
2601             * @return the message boards mailing list, or <code>null</code> if a message boards mailing list with the primary key could not be found
2602             * @throws SystemException if a system exception occurred
2603             */
2604            @Override
2605            public MBMailingList fetchByPrimaryKey(Serializable primaryKey)
2606                    throws SystemException {
2607                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
2608            }
2609    
2610            /**
2611             * Returns the message boards mailing list with the primary key or returns <code>null</code> if it could not be found.
2612             *
2613             * @param mailingListId the primary key of the message boards mailing list
2614             * @return the message boards mailing list, or <code>null</code> if a message boards mailing list with the primary key could not be found
2615             * @throws SystemException if a system exception occurred
2616             */
2617            public MBMailingList fetchByPrimaryKey(long mailingListId)
2618                    throws SystemException {
2619                    MBMailingList mbMailingList = (MBMailingList)EntityCacheUtil.getResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2620                                    MBMailingListImpl.class, mailingListId);
2621    
2622                    if (mbMailingList == _nullMBMailingList) {
2623                            return null;
2624                    }
2625    
2626                    if (mbMailingList == null) {
2627                            Session session = null;
2628    
2629                            try {
2630                                    session = openSession();
2631    
2632                                    mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
2633                                                    Long.valueOf(mailingListId));
2634    
2635                                    if (mbMailingList != null) {
2636                                            cacheResult(mbMailingList);
2637                                    }
2638                                    else {
2639                                            EntityCacheUtil.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2640                                                    MBMailingListImpl.class, mailingListId,
2641                                                    _nullMBMailingList);
2642                                    }
2643                            }
2644                            catch (Exception e) {
2645                                    EntityCacheUtil.removeResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2646                                            MBMailingListImpl.class, mailingListId);
2647    
2648                                    throw processException(e);
2649                            }
2650                            finally {
2651                                    closeSession(session);
2652                            }
2653                    }
2654    
2655                    return mbMailingList;
2656            }
2657    
2658            /**
2659             * Returns all the message boards mailing lists.
2660             *
2661             * @return the message boards mailing lists
2662             * @throws SystemException if a system exception occurred
2663             */
2664            public List<MBMailingList> findAll() throws SystemException {
2665                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2666            }
2667    
2668            /**
2669             * Returns a range of all the message boards mailing lists.
2670             *
2671             * <p>
2672             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2673             * </p>
2674             *
2675             * @param start the lower bound of the range of message boards mailing lists
2676             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
2677             * @return the range of message boards mailing lists
2678             * @throws SystemException if a system exception occurred
2679             */
2680            public List<MBMailingList> findAll(int start, int end)
2681                    throws SystemException {
2682                    return findAll(start, end, null);
2683            }
2684    
2685            /**
2686             * Returns an ordered range of all the message boards mailing lists.
2687             *
2688             * <p>
2689             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2690             * </p>
2691             *
2692             * @param start the lower bound of the range of message boards mailing lists
2693             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
2694             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2695             * @return the ordered range of message boards mailing lists
2696             * @throws SystemException if a system exception occurred
2697             */
2698            public List<MBMailingList> findAll(int start, int end,
2699                    OrderByComparator orderByComparator) throws SystemException {
2700                    boolean pagination = true;
2701                    FinderPath finderPath = null;
2702                    Object[] finderArgs = null;
2703    
2704                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2705                                    (orderByComparator == null)) {
2706                            pagination = false;
2707                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2708                            finderArgs = FINDER_ARGS_EMPTY;
2709                    }
2710                    else {
2711                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2712                            finderArgs = new Object[] { start, end, orderByComparator };
2713                    }
2714    
2715                    List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(finderPath,
2716                                    finderArgs, this);
2717    
2718                    if (list == null) {
2719                            StringBundler query = null;
2720                            String sql = null;
2721    
2722                            if (orderByComparator != null) {
2723                                    query = new StringBundler(2 +
2724                                                    (orderByComparator.getOrderByFields().length * 3));
2725    
2726                                    query.append(_SQL_SELECT_MBMAILINGLIST);
2727    
2728                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2729                                            orderByComparator);
2730    
2731                                    sql = query.toString();
2732                            }
2733                            else {
2734                                    sql = _SQL_SELECT_MBMAILINGLIST;
2735    
2736                                    if (pagination) {
2737                                            sql = sql.concat(MBMailingListModelImpl.ORDER_BY_JPQL);
2738                                    }
2739                            }
2740    
2741                            Session session = null;
2742    
2743                            try {
2744                                    session = openSession();
2745    
2746                                    Query q = session.createQuery(sql);
2747    
2748                                    if (!pagination) {
2749                                            list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
2750                                                            start, end, false);
2751    
2752                                            Collections.sort(list);
2753    
2754                                            list = new UnmodifiableList<MBMailingList>(list);
2755                                    }
2756                                    else {
2757                                            list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
2758                                                            start, end);
2759                                    }
2760    
2761                                    cacheResult(list);
2762    
2763                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2764                            }
2765                            catch (Exception e) {
2766                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2767    
2768                                    throw processException(e);
2769                            }
2770                            finally {
2771                                    closeSession(session);
2772                            }
2773                    }
2774    
2775                    return list;
2776            }
2777    
2778            /**
2779             * Removes all the message boards mailing lists from the database.
2780             *
2781             * @throws SystemException if a system exception occurred
2782             */
2783            public void removeAll() throws SystemException {
2784                    for (MBMailingList mbMailingList : findAll()) {
2785                            remove(mbMailingList);
2786                    }
2787            }
2788    
2789            /**
2790             * Returns the number of message boards mailing lists.
2791             *
2792             * @return the number of message boards mailing lists
2793             * @throws SystemException if a system exception occurred
2794             */
2795            public int countAll() throws SystemException {
2796                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2797                                    FINDER_ARGS_EMPTY, this);
2798    
2799                    if (count == null) {
2800                            Session session = null;
2801    
2802                            try {
2803                                    session = openSession();
2804    
2805                                    Query q = session.createQuery(_SQL_COUNT_MBMAILINGLIST);
2806    
2807                                    count = (Long)q.uniqueResult();
2808    
2809                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2810                                            FINDER_ARGS_EMPTY, count);
2811                            }
2812                            catch (Exception e) {
2813                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2814                                            FINDER_ARGS_EMPTY);
2815    
2816                                    throw processException(e);
2817                            }
2818                            finally {
2819                                    closeSession(session);
2820                            }
2821                    }
2822    
2823                    return count.intValue();
2824            }
2825    
2826            /**
2827             * Initializes the message boards mailing list persistence.
2828             */
2829            public void afterPropertiesSet() {
2830                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2831                                            com.liferay.portal.util.PropsUtil.get(
2832                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMailingList")));
2833    
2834                    if (listenerClassNames.length > 0) {
2835                            try {
2836                                    List<ModelListener<MBMailingList>> listenersList = new ArrayList<ModelListener<MBMailingList>>();
2837    
2838                                    for (String listenerClassName : listenerClassNames) {
2839                                            listenersList.add((ModelListener<MBMailingList>)InstanceFactory.newInstance(
2840                                                            listenerClassName));
2841                                    }
2842    
2843                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2844                            }
2845                            catch (Exception e) {
2846                                    _log.error(e);
2847                            }
2848                    }
2849            }
2850    
2851            public void destroy() {
2852                    EntityCacheUtil.removeCache(MBMailingListImpl.class.getName());
2853                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2854                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2855                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2856            }
2857    
2858            private static final String _SQL_SELECT_MBMAILINGLIST = "SELECT mbMailingList FROM MBMailingList mbMailingList";
2859            private static final String _SQL_SELECT_MBMAILINGLIST_WHERE = "SELECT mbMailingList FROM MBMailingList mbMailingList WHERE ";
2860            private static final String _SQL_COUNT_MBMAILINGLIST = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList";
2861            private static final String _SQL_COUNT_MBMAILINGLIST_WHERE = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList WHERE ";
2862            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMailingList.";
2863            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMailingList exists with the primary key ";
2864            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMailingList exists with the key {";
2865            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2866            private static Log _log = LogFactoryUtil.getLog(MBMailingListPersistenceImpl.class);
2867            private static MBMailingList _nullMBMailingList = new MBMailingListImpl() {
2868                            @Override
2869                            public Object clone() {
2870                                    return this;
2871                            }
2872    
2873                            @Override
2874                            public CacheModel<MBMailingList> toCacheModel() {
2875                                    return _nullMBMailingListCacheModel;
2876                            }
2877                    };
2878    
2879            private static CacheModel<MBMailingList> _nullMBMailingListCacheModel = new CacheModel<MBMailingList>() {
2880                            public MBMailingList toEntityModel() {
2881                                    return _nullMBMailingList;
2882                            }
2883                    };
2884    }