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