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