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