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