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