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