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