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