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