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