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