001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.service.persistence.BatchSessionUtil;
041    import com.liferay.portal.service.persistence.ResourcePersistence;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.messageboards.NoSuchMailingListException;
046    import com.liferay.portlet.messageboards.model.MBMailingList;
047    import com.liferay.portlet.messageboards.model.impl.MBMailingListImpl;
048    import com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the message boards mailing list service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see MBMailingListPersistence
065     * @see MBMailingListUtil
066     * @generated
067     */
068    public class MBMailingListPersistenceImpl extends BasePersistenceImpl<MBMailingList>
069            implements MBMailingListPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * Never modify or reference this class directly. Always use {@link MBMailingListUtil} to access the message boards mailing list persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = MBMailingListImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
081                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
082                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083                            "findByUuid",
084                            new String[] {
085                                    String.class.getName(),
086                                    
087                            "java.lang.Integer", "java.lang.Integer",
088                                    "com.liferay.portal.kernel.util.OrderByComparator"
089                            });
090            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
091                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
092                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
093                            "findByUuid", new String[] { String.class.getName() },
094                            MBMailingListModelImpl.UUID_COLUMN_BITMASK);
095            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
096                            MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
098                            new String[] { String.class.getName() });
099            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
100                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
101                            MBMailingListImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
102                            new String[] { String.class.getName(), Long.class.getName() },
103                            MBMailingListModelImpl.UUID_COLUMN_BITMASK |
104                            MBMailingListModelImpl.GROUPID_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
106                            MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
108                            new String[] { String.class.getName(), Long.class.getName() });
109            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
110                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
111                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
112                            "findByActive",
113                            new String[] {
114                                    Boolean.class.getName(),
115                                    
116                            "java.lang.Integer", "java.lang.Integer",
117                                    "com.liferay.portal.kernel.util.OrderByComparator"
118                            });
119            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE =
120                    new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
121                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
122                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
123                            "findByActive", new String[] { Boolean.class.getName() },
124                            MBMailingListModelImpl.ACTIVE_COLUMN_BITMASK);
125            public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
126                            MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
127                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByActive",
128                            new String[] { Boolean.class.getName() });
129            public static final FinderPath FINDER_PATH_FETCH_BY_G_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
130                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
131                            MBMailingListImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_C",
132                            new String[] { Long.class.getName(), Long.class.getName() },
133                            MBMailingListModelImpl.GROUPID_COLUMN_BITMASK |
134                            MBMailingListModelImpl.CATEGORYID_COLUMN_BITMASK);
135            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
136                            MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
137                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
138                            new String[] { Long.class.getName(), Long.class.getName() });
139            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
140                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
141                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
142                            "findAll", new String[0]);
143            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
144                            MBMailingListModelImpl.FINDER_CACHE_ENABLED,
145                            MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
146                            "findAll", new String[0]);
147            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
148                            MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
149                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
150    
151            /**
152             * Caches the message boards mailing list in the entity cache if it is enabled.
153             *
154             * @param mbMailingList the message boards mailing list
155             */
156            public void cacheResult(MBMailingList mbMailingList) {
157                    EntityCacheUtil.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
158                            MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
159                            mbMailingList);
160    
161                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
162                            new Object[] {
163                                    mbMailingList.getUuid(),
164                                    Long.valueOf(mbMailingList.getGroupId())
165                            }, mbMailingList);
166    
167                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
168                            new Object[] {
169                                    Long.valueOf(mbMailingList.getGroupId()),
170                                    Long.valueOf(mbMailingList.getCategoryId())
171                            }, mbMailingList);
172    
173                    mbMailingList.resetOriginalValues();
174            }
175    
176            /**
177             * Caches the message boards mailing lists in the entity cache if it is enabled.
178             *
179             * @param mbMailingLists the message boards mailing lists
180             */
181            public void cacheResult(List<MBMailingList> mbMailingLists) {
182                    for (MBMailingList mbMailingList : mbMailingLists) {
183                            if (EntityCacheUtil.getResult(
184                                                    MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
185                                                    MBMailingListImpl.class, mbMailingList.getPrimaryKey()) == null) {
186                                    cacheResult(mbMailingList);
187                            }
188                            else {
189                                    mbMailingList.resetOriginalValues();
190                            }
191                    }
192            }
193    
194            /**
195             * Clears the cache for all message boards mailing lists.
196             *
197             * <p>
198             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
199             * </p>
200             */
201            @Override
202            public void clearCache() {
203                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
204                            CacheRegistryUtil.clear(MBMailingListImpl.class.getName());
205                    }
206    
207                    EntityCacheUtil.clearCache(MBMailingListImpl.class.getName());
208    
209                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
210                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
211                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
212            }
213    
214            /**
215             * Clears the cache for the message boards mailing list.
216             *
217             * <p>
218             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
219             * </p>
220             */
221            @Override
222            public void clearCache(MBMailingList mbMailingList) {
223                    EntityCacheUtil.removeResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
224                            MBMailingListImpl.class, mbMailingList.getPrimaryKey());
225    
226                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
227                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
228    
229                    clearUniqueFindersCache(mbMailingList);
230            }
231    
232            @Override
233            public void clearCache(List<MBMailingList> mbMailingLists) {
234                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
235                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
236    
237                    for (MBMailingList mbMailingList : mbMailingLists) {
238                            EntityCacheUtil.removeResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
239                                    MBMailingListImpl.class, mbMailingList.getPrimaryKey());
240    
241                            clearUniqueFindersCache(mbMailingList);
242                    }
243            }
244    
245            protected void cacheUniqueFindersCache(MBMailingList mbMailingList) {
246                    if (mbMailingList.isNew()) {
247                            Object[] args = new Object[] {
248                                            mbMailingList.getUuid(),
249                                            Long.valueOf(mbMailingList.getGroupId())
250                                    };
251    
252                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
253                                    Long.valueOf(1));
254                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
255                                    mbMailingList);
256    
257                            args = new Object[] {
258                                            Long.valueOf(mbMailingList.getGroupId()),
259                                            Long.valueOf(mbMailingList.getCategoryId())
260                                    };
261    
262                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, args,
263                                    Long.valueOf(1));
264                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C, args,
265                                    mbMailingList);
266                    }
267                    else {
268                            MBMailingListModelImpl mbMailingListModelImpl = (MBMailingListModelImpl)mbMailingList;
269    
270                            if ((mbMailingListModelImpl.getColumnBitmask() &
271                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
272                                    Object[] args = new Object[] {
273                                                    mbMailingList.getUuid(),
274                                                    Long.valueOf(mbMailingList.getGroupId())
275                                            };
276    
277                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
278                                            Long.valueOf(1));
279                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
280                                            mbMailingList);
281                            }
282    
283                            if ((mbMailingListModelImpl.getColumnBitmask() &
284                                            FINDER_PATH_FETCH_BY_G_C.getColumnBitmask()) != 0) {
285                                    Object[] args = new Object[] {
286                                                    Long.valueOf(mbMailingList.getGroupId()),
287                                                    Long.valueOf(mbMailingList.getCategoryId())
288                                            };
289    
290                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, args,
291                                            Long.valueOf(1));
292                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C, args,
293                                            mbMailingList);
294                            }
295                    }
296            }
297    
298            protected void clearUniqueFindersCache(MBMailingList mbMailingList) {
299                    MBMailingListModelImpl mbMailingListModelImpl = (MBMailingListModelImpl)mbMailingList;
300    
301                    Object[] args = new Object[] {
302                                    mbMailingList.getUuid(),
303                                    Long.valueOf(mbMailingList.getGroupId())
304                            };
305    
306                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
307                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
308    
309                    if ((mbMailingListModelImpl.getColumnBitmask() &
310                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
311                            args = new Object[] {
312                                            mbMailingListModelImpl.getOriginalUuid(),
313                                            Long.valueOf(mbMailingListModelImpl.getOriginalGroupId())
314                                    };
315    
316                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
317                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
318                    }
319    
320                    args = new Object[] {
321                                    Long.valueOf(mbMailingList.getGroupId()),
322                                    Long.valueOf(mbMailingList.getCategoryId())
323                            };
324    
325                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
326                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C, args);
327    
328                    if ((mbMailingListModelImpl.getColumnBitmask() &
329                                    FINDER_PATH_FETCH_BY_G_C.getColumnBitmask()) != 0) {
330                            args = new Object[] {
331                                            Long.valueOf(mbMailingListModelImpl.getOriginalGroupId()),
332                                            Long.valueOf(mbMailingListModelImpl.getOriginalCategoryId())
333                                    };
334    
335                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
336                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C, args);
337                    }
338            }
339    
340            /**
341             * Creates a new message boards mailing list with the primary key. Does not add the message boards mailing list to the database.
342             *
343             * @param mailingListId the primary key for the new message boards mailing list
344             * @return the new message boards mailing list
345             */
346            public MBMailingList create(long mailingListId) {
347                    MBMailingList mbMailingList = new MBMailingListImpl();
348    
349                    mbMailingList.setNew(true);
350                    mbMailingList.setPrimaryKey(mailingListId);
351    
352                    String uuid = PortalUUIDUtil.generate();
353    
354                    mbMailingList.setUuid(uuid);
355    
356                    return mbMailingList;
357            }
358    
359            /**
360             * Removes the message boards mailing list with the primary key from the database. Also notifies the appropriate model listeners.
361             *
362             * @param mailingListId the primary key of the message boards mailing list
363             * @return the message boards mailing list that was removed
364             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a message boards mailing list with the primary key could not be found
365             * @throws SystemException if a system exception occurred
366             */
367            public MBMailingList remove(long mailingListId)
368                    throws NoSuchMailingListException, SystemException {
369                    return remove(Long.valueOf(mailingListId));
370            }
371    
372            /**
373             * Removes the message boards mailing list with the primary key from the database. Also notifies the appropriate model listeners.
374             *
375             * @param primaryKey the primary key of the message boards mailing list
376             * @return the message boards mailing list that was removed
377             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a message boards mailing list with the primary key could not be found
378             * @throws SystemException if a system exception occurred
379             */
380            @Override
381            public MBMailingList remove(Serializable primaryKey)
382                    throws NoSuchMailingListException, SystemException {
383                    Session session = null;
384    
385                    try {
386                            session = openSession();
387    
388                            MBMailingList mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
389                                            primaryKey);
390    
391                            if (mbMailingList == null) {
392                                    if (_log.isWarnEnabled()) {
393                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
394                                    }
395    
396                                    throw new NoSuchMailingListException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
397                                            primaryKey);
398                            }
399    
400                            return remove(mbMailingList);
401                    }
402                    catch (NoSuchMailingListException nsee) {
403                            throw nsee;
404                    }
405                    catch (Exception e) {
406                            throw processException(e);
407                    }
408                    finally {
409                            closeSession(session);
410                    }
411            }
412    
413            @Override
414            protected MBMailingList removeImpl(MBMailingList mbMailingList)
415                    throws SystemException {
416                    mbMailingList = toUnwrappedModel(mbMailingList);
417    
418                    Session session = null;
419    
420                    try {
421                            session = openSession();
422    
423                            BatchSessionUtil.delete(session, mbMailingList);
424                    }
425                    catch (Exception e) {
426                            throw processException(e);
427                    }
428                    finally {
429                            closeSession(session);
430                    }
431    
432                    clearCache(mbMailingList);
433    
434                    return mbMailingList;
435            }
436    
437            @Override
438            public MBMailingList updateImpl(
439                    com.liferay.portlet.messageboards.model.MBMailingList mbMailingList,
440                    boolean merge) throws SystemException {
441                    mbMailingList = toUnwrappedModel(mbMailingList);
442    
443                    boolean isNew = mbMailingList.isNew();
444    
445                    MBMailingListModelImpl mbMailingListModelImpl = (MBMailingListModelImpl)mbMailingList;
446    
447                    if (Validator.isNull(mbMailingList.getUuid())) {
448                            String uuid = PortalUUIDUtil.generate();
449    
450                            mbMailingList.setUuid(uuid);
451                    }
452    
453                    Session session = null;
454    
455                    try {
456                            session = openSession();
457    
458                            BatchSessionUtil.update(session, mbMailingList, merge);
459    
460                            mbMailingList.setNew(false);
461                    }
462                    catch (Exception e) {
463                            throw processException(e);
464                    }
465                    finally {
466                            closeSession(session);
467                    }
468    
469                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
470    
471                    if (isNew || !MBMailingListModelImpl.COLUMN_BITMASK_ENABLED) {
472                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
473                    }
474    
475                    else {
476                            if ((mbMailingListModelImpl.getColumnBitmask() &
477                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
478                                    Object[] args = new Object[] {
479                                                    mbMailingListModelImpl.getOriginalUuid()
480                                            };
481    
482                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
483                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
484                                            args);
485    
486                                    args = new Object[] { mbMailingListModelImpl.getUuid() };
487    
488                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
489                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
490                                            args);
491                            }
492    
493                            if ((mbMailingListModelImpl.getColumnBitmask() &
494                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE.getColumnBitmask()) != 0) {
495                                    Object[] args = new Object[] {
496                                                    Boolean.valueOf(mbMailingListModelImpl.getOriginalActive())
497                                            };
498    
499                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
500                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
501                                            args);
502    
503                                    args = new Object[] {
504                                                    Boolean.valueOf(mbMailingListModelImpl.getActive())
505                                            };
506    
507                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
508                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
509                                            args);
510                            }
511                    }
512    
513                    EntityCacheUtil.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
514                            MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
515                            mbMailingList);
516    
517                    clearUniqueFindersCache(mbMailingList);
518                    cacheUniqueFindersCache(mbMailingList);
519    
520                    return mbMailingList;
521            }
522    
523            protected MBMailingList toUnwrappedModel(MBMailingList mbMailingList) {
524                    if (mbMailingList instanceof MBMailingListImpl) {
525                            return mbMailingList;
526                    }
527    
528                    MBMailingListImpl mbMailingListImpl = new MBMailingListImpl();
529    
530                    mbMailingListImpl.setNew(mbMailingList.isNew());
531                    mbMailingListImpl.setPrimaryKey(mbMailingList.getPrimaryKey());
532    
533                    mbMailingListImpl.setUuid(mbMailingList.getUuid());
534                    mbMailingListImpl.setMailingListId(mbMailingList.getMailingListId());
535                    mbMailingListImpl.setGroupId(mbMailingList.getGroupId());
536                    mbMailingListImpl.setCompanyId(mbMailingList.getCompanyId());
537                    mbMailingListImpl.setUserId(mbMailingList.getUserId());
538                    mbMailingListImpl.setUserName(mbMailingList.getUserName());
539                    mbMailingListImpl.setCreateDate(mbMailingList.getCreateDate());
540                    mbMailingListImpl.setModifiedDate(mbMailingList.getModifiedDate());
541                    mbMailingListImpl.setCategoryId(mbMailingList.getCategoryId());
542                    mbMailingListImpl.setEmailAddress(mbMailingList.getEmailAddress());
543                    mbMailingListImpl.setInProtocol(mbMailingList.getInProtocol());
544                    mbMailingListImpl.setInServerName(mbMailingList.getInServerName());
545                    mbMailingListImpl.setInServerPort(mbMailingList.getInServerPort());
546                    mbMailingListImpl.setInUseSSL(mbMailingList.isInUseSSL());
547                    mbMailingListImpl.setInUserName(mbMailingList.getInUserName());
548                    mbMailingListImpl.setInPassword(mbMailingList.getInPassword());
549                    mbMailingListImpl.setInReadInterval(mbMailingList.getInReadInterval());
550                    mbMailingListImpl.setOutEmailAddress(mbMailingList.getOutEmailAddress());
551                    mbMailingListImpl.setOutCustom(mbMailingList.isOutCustom());
552                    mbMailingListImpl.setOutServerName(mbMailingList.getOutServerName());
553                    mbMailingListImpl.setOutServerPort(mbMailingList.getOutServerPort());
554                    mbMailingListImpl.setOutUseSSL(mbMailingList.isOutUseSSL());
555                    mbMailingListImpl.setOutUserName(mbMailingList.getOutUserName());
556                    mbMailingListImpl.setOutPassword(mbMailingList.getOutPassword());
557                    mbMailingListImpl.setAllowAnonymous(mbMailingList.isAllowAnonymous());
558                    mbMailingListImpl.setActive(mbMailingList.isActive());
559    
560                    return mbMailingListImpl;
561            }
562    
563            /**
564             * Returns the message boards mailing list with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
565             *
566             * @param primaryKey the primary key of the message boards mailing list
567             * @return the message boards mailing list
568             * @throws com.liferay.portal.NoSuchModelException if a message boards mailing list with the primary key could not be found
569             * @throws SystemException if a system exception occurred
570             */
571            @Override
572            public MBMailingList findByPrimaryKey(Serializable primaryKey)
573                    throws NoSuchModelException, SystemException {
574                    return findByPrimaryKey(((Long)primaryKey).longValue());
575            }
576    
577            /**
578             * Returns the message boards mailing list with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMailingListException} if it could not be found.
579             *
580             * @param mailingListId the primary key of the message boards mailing list
581             * @return the message boards mailing list
582             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a message boards mailing list with the primary key could not be found
583             * @throws SystemException if a system exception occurred
584             */
585            public MBMailingList findByPrimaryKey(long mailingListId)
586                    throws NoSuchMailingListException, SystemException {
587                    MBMailingList mbMailingList = fetchByPrimaryKey(mailingListId);
588    
589                    if (mbMailingList == null) {
590                            if (_log.isWarnEnabled()) {
591                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + mailingListId);
592                            }
593    
594                            throw new NoSuchMailingListException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
595                                    mailingListId);
596                    }
597    
598                    return mbMailingList;
599            }
600    
601            /**
602             * Returns the message boards mailing list with the primary key or returns <code>null</code> if it could not be found.
603             *
604             * @param primaryKey the primary key of the message boards mailing list
605             * @return the message boards mailing list, or <code>null</code> if a message boards mailing list with the primary key could not be found
606             * @throws SystemException if a system exception occurred
607             */
608            @Override
609            public MBMailingList fetchByPrimaryKey(Serializable primaryKey)
610                    throws SystemException {
611                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
612            }
613    
614            /**
615             * Returns the message boards mailing list with the primary key or returns <code>null</code> if it could not be found.
616             *
617             * @param mailingListId the primary key of the message boards mailing list
618             * @return the message boards mailing list, or <code>null</code> if a message boards mailing list with the primary key could not be found
619             * @throws SystemException if a system exception occurred
620             */
621            public MBMailingList fetchByPrimaryKey(long mailingListId)
622                    throws SystemException {
623                    MBMailingList mbMailingList = (MBMailingList)EntityCacheUtil.getResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
624                                    MBMailingListImpl.class, mailingListId);
625    
626                    if (mbMailingList == _nullMBMailingList) {
627                            return null;
628                    }
629    
630                    if (mbMailingList == null) {
631                            Session session = null;
632    
633                            boolean hasException = false;
634    
635                            try {
636                                    session = openSession();
637    
638                                    mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
639                                                    Long.valueOf(mailingListId));
640                            }
641                            catch (Exception e) {
642                                    hasException = true;
643    
644                                    throw processException(e);
645                            }
646                            finally {
647                                    if (mbMailingList != null) {
648                                            cacheResult(mbMailingList);
649                                    }
650                                    else if (!hasException) {
651                                            EntityCacheUtil.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
652                                                    MBMailingListImpl.class, mailingListId,
653                                                    _nullMBMailingList);
654                                    }
655    
656                                    closeSession(session);
657                            }
658                    }
659    
660                    return mbMailingList;
661            }
662    
663            /**
664             * Returns all the message boards mailing lists where uuid = &#63;.
665             *
666             * @param uuid the uuid
667             * @return the matching message boards mailing lists
668             * @throws SystemException if a system exception occurred
669             */
670            public List<MBMailingList> findByUuid(String uuid)
671                    throws SystemException {
672                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
673            }
674    
675            /**
676             * Returns a range of all the message boards mailing lists where uuid = &#63;.
677             *
678             * <p>
679             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
680             * </p>
681             *
682             * @param uuid the uuid
683             * @param start the lower bound of the range of message boards mailing lists
684             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
685             * @return the range of matching message boards mailing lists
686             * @throws SystemException if a system exception occurred
687             */
688            public List<MBMailingList> findByUuid(String uuid, int start, int end)
689                    throws SystemException {
690                    return findByUuid(uuid, start, end, null);
691            }
692    
693            /**
694             * Returns an ordered range of all the message boards mailing lists where uuid = &#63;.
695             *
696             * <p>
697             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
698             * </p>
699             *
700             * @param uuid the uuid
701             * @param start the lower bound of the range of message boards mailing lists
702             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
703             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
704             * @return the ordered range of matching message boards mailing lists
705             * @throws SystemException if a system exception occurred
706             */
707            public List<MBMailingList> findByUuid(String uuid, int start, int end,
708                    OrderByComparator orderByComparator) throws SystemException {
709                    FinderPath finderPath = null;
710                    Object[] finderArgs = null;
711    
712                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
713                                    (orderByComparator == null)) {
714                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
715                            finderArgs = new Object[] { uuid };
716                    }
717                    else {
718                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
719                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
720                    }
721    
722                    List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(finderPath,
723                                    finderArgs, this);
724    
725                    if ((list != null) && !list.isEmpty()) {
726                            for (MBMailingList mbMailingList : list) {
727                                    if (!Validator.equals(uuid, mbMailingList.getUuid())) {
728                                            list = null;
729    
730                                            break;
731                                    }
732                            }
733                    }
734    
735                    if (list == null) {
736                            StringBundler query = null;
737    
738                            if (orderByComparator != null) {
739                                    query = new StringBundler(3 +
740                                                    (orderByComparator.getOrderByFields().length * 3));
741                            }
742                            else {
743                                    query = new StringBundler(2);
744                            }
745    
746                            query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
747    
748                            if (uuid == null) {
749                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
750                            }
751                            else {
752                                    if (uuid.equals(StringPool.BLANK)) {
753                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
754                                    }
755                                    else {
756                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
757                                    }
758                            }
759    
760                            if (orderByComparator != null) {
761                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
762                                            orderByComparator);
763                            }
764    
765                            String sql = query.toString();
766    
767                            Session session = null;
768    
769                            try {
770                                    session = openSession();
771    
772                                    Query q = session.createQuery(sql);
773    
774                                    QueryPos qPos = QueryPos.getInstance(q);
775    
776                                    if (uuid != null) {
777                                            qPos.add(uuid);
778                                    }
779    
780                                    list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
781                                                    start, end);
782                            }
783                            catch (Exception e) {
784                                    throw processException(e);
785                            }
786                            finally {
787                                    if (list == null) {
788                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
789                                    }
790                                    else {
791                                            cacheResult(list);
792    
793                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
794                                    }
795    
796                                    closeSession(session);
797                            }
798                    }
799    
800                    return list;
801            }
802    
803            /**
804             * Returns the first message boards mailing list in the ordered set where uuid = &#63;.
805             *
806             * @param uuid the uuid
807             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
808             * @return the first matching message boards mailing list
809             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
810             * @throws SystemException if a system exception occurred
811             */
812            public MBMailingList findByUuid_First(String uuid,
813                    OrderByComparator orderByComparator)
814                    throws NoSuchMailingListException, SystemException {
815                    MBMailingList mbMailingList = fetchByUuid_First(uuid, orderByComparator);
816    
817                    if (mbMailingList != null) {
818                            return mbMailingList;
819                    }
820    
821                    StringBundler msg = new StringBundler(4);
822    
823                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
824    
825                    msg.append("uuid=");
826                    msg.append(uuid);
827    
828                    msg.append(StringPool.CLOSE_CURLY_BRACE);
829    
830                    throw new NoSuchMailingListException(msg.toString());
831            }
832    
833            /**
834             * Returns the first message boards mailing list in the ordered set where uuid = &#63;.
835             *
836             * @param uuid the uuid
837             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
838             * @return the first matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
839             * @throws SystemException if a system exception occurred
840             */
841            public MBMailingList fetchByUuid_First(String uuid,
842                    OrderByComparator orderByComparator) throws SystemException {
843                    List<MBMailingList> list = findByUuid(uuid, 0, 1, orderByComparator);
844    
845                    if (!list.isEmpty()) {
846                            return list.get(0);
847                    }
848    
849                    return null;
850            }
851    
852            /**
853             * Returns the last message boards mailing list in the ordered set where uuid = &#63;.
854             *
855             * @param uuid the uuid
856             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
857             * @return the last matching message boards mailing list
858             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
859             * @throws SystemException if a system exception occurred
860             */
861            public MBMailingList findByUuid_Last(String uuid,
862                    OrderByComparator orderByComparator)
863                    throws NoSuchMailingListException, SystemException {
864                    MBMailingList mbMailingList = fetchByUuid_Last(uuid, orderByComparator);
865    
866                    if (mbMailingList != null) {
867                            return mbMailingList;
868                    }
869    
870                    StringBundler msg = new StringBundler(4);
871    
872                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
873    
874                    msg.append("uuid=");
875                    msg.append(uuid);
876    
877                    msg.append(StringPool.CLOSE_CURLY_BRACE);
878    
879                    throw new NoSuchMailingListException(msg.toString());
880            }
881    
882            /**
883             * Returns the last message boards mailing list in the ordered set where uuid = &#63;.
884             *
885             * @param uuid the uuid
886             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
887             * @return the last matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
888             * @throws SystemException if a system exception occurred
889             */
890            public MBMailingList fetchByUuid_Last(String uuid,
891                    OrderByComparator orderByComparator) throws SystemException {
892                    int count = countByUuid(uuid);
893    
894                    List<MBMailingList> list = findByUuid(uuid, count - 1, count,
895                                    orderByComparator);
896    
897                    if (!list.isEmpty()) {
898                            return list.get(0);
899                    }
900    
901                    return null;
902            }
903    
904            /**
905             * Returns the message boards mailing lists before and after the current message boards mailing list in the ordered set where uuid = &#63;.
906             *
907             * @param mailingListId the primary key of the current message boards mailing list
908             * @param uuid the uuid
909             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
910             * @return the previous, current, and next message boards mailing list
911             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a message boards mailing list with the primary key could not be found
912             * @throws SystemException if a system exception occurred
913             */
914            public MBMailingList[] findByUuid_PrevAndNext(long mailingListId,
915                    String uuid, OrderByComparator orderByComparator)
916                    throws NoSuchMailingListException, SystemException {
917                    MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
918    
919                    Session session = null;
920    
921                    try {
922                            session = openSession();
923    
924                            MBMailingList[] array = new MBMailingListImpl[3];
925    
926                            array[0] = getByUuid_PrevAndNext(session, mbMailingList, uuid,
927                                            orderByComparator, true);
928    
929                            array[1] = mbMailingList;
930    
931                            array[2] = getByUuid_PrevAndNext(session, mbMailingList, uuid,
932                                            orderByComparator, false);
933    
934                            return array;
935                    }
936                    catch (Exception e) {
937                            throw processException(e);
938                    }
939                    finally {
940                            closeSession(session);
941                    }
942            }
943    
944            protected MBMailingList getByUuid_PrevAndNext(Session session,
945                    MBMailingList mbMailingList, String uuid,
946                    OrderByComparator orderByComparator, boolean previous) {
947                    StringBundler query = null;
948    
949                    if (orderByComparator != null) {
950                            query = new StringBundler(6 +
951                                            (orderByComparator.getOrderByFields().length * 6));
952                    }
953                    else {
954                            query = new StringBundler(3);
955                    }
956    
957                    query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
958    
959                    if (uuid == null) {
960                            query.append(_FINDER_COLUMN_UUID_UUID_1);
961                    }
962                    else {
963                            if (uuid.equals(StringPool.BLANK)) {
964                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
965                            }
966                            else {
967                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
968                            }
969                    }
970    
971                    if (orderByComparator != null) {
972                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
973    
974                            if (orderByConditionFields.length > 0) {
975                                    query.append(WHERE_AND);
976                            }
977    
978                            for (int i = 0; i < orderByConditionFields.length; i++) {
979                                    query.append(_ORDER_BY_ENTITY_ALIAS);
980                                    query.append(orderByConditionFields[i]);
981    
982                                    if ((i + 1) < orderByConditionFields.length) {
983                                            if (orderByComparator.isAscending() ^ previous) {
984                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
985                                            }
986                                            else {
987                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
988                                            }
989                                    }
990                                    else {
991                                            if (orderByComparator.isAscending() ^ previous) {
992                                                    query.append(WHERE_GREATER_THAN);
993                                            }
994                                            else {
995                                                    query.append(WHERE_LESSER_THAN);
996                                            }
997                                    }
998                            }
999    
1000                            query.append(ORDER_BY_CLAUSE);
1001    
1002                            String[] orderByFields = orderByComparator.getOrderByFields();
1003    
1004                            for (int i = 0; i < orderByFields.length; i++) {
1005                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1006                                    query.append(orderByFields[i]);
1007    
1008                                    if ((i + 1) < orderByFields.length) {
1009                                            if (orderByComparator.isAscending() ^ previous) {
1010                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1011                                            }
1012                                            else {
1013                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1014                                            }
1015                                    }
1016                                    else {
1017                                            if (orderByComparator.isAscending() ^ previous) {
1018                                                    query.append(ORDER_BY_ASC);
1019                                            }
1020                                            else {
1021                                                    query.append(ORDER_BY_DESC);
1022                                            }
1023                                    }
1024                            }
1025                    }
1026    
1027                    String sql = query.toString();
1028    
1029                    Query q = session.createQuery(sql);
1030    
1031                    q.setFirstResult(0);
1032                    q.setMaxResults(2);
1033    
1034                    QueryPos qPos = QueryPos.getInstance(q);
1035    
1036                    if (uuid != null) {
1037                            qPos.add(uuid);
1038                    }
1039    
1040                    if (orderByComparator != null) {
1041                            Object[] values = orderByComparator.getOrderByConditionValues(mbMailingList);
1042    
1043                            for (Object value : values) {
1044                                    qPos.add(value);
1045                            }
1046                    }
1047    
1048                    List<MBMailingList> list = q.list();
1049    
1050                    if (list.size() == 2) {
1051                            return list.get(1);
1052                    }
1053                    else {
1054                            return null;
1055                    }
1056            }
1057    
1058            /**
1059             * Returns the message boards mailing list where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchMailingListException} if it could not be found.
1060             *
1061             * @param uuid the uuid
1062             * @param groupId the group ID
1063             * @return the matching message boards mailing list
1064             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
1065             * @throws SystemException if a system exception occurred
1066             */
1067            public MBMailingList findByUUID_G(String uuid, long groupId)
1068                    throws NoSuchMailingListException, SystemException {
1069                    MBMailingList mbMailingList = fetchByUUID_G(uuid, groupId);
1070    
1071                    if (mbMailingList == null) {
1072                            StringBundler msg = new StringBundler(6);
1073    
1074                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1075    
1076                            msg.append("uuid=");
1077                            msg.append(uuid);
1078    
1079                            msg.append(", groupId=");
1080                            msg.append(groupId);
1081    
1082                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1083    
1084                            if (_log.isWarnEnabled()) {
1085                                    _log.warn(msg.toString());
1086                            }
1087    
1088                            throw new NoSuchMailingListException(msg.toString());
1089                    }
1090    
1091                    return mbMailingList;
1092            }
1093    
1094            /**
1095             * Returns the message boards mailing list where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1096             *
1097             * @param uuid the uuid
1098             * @param groupId the group ID
1099             * @return the matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1100             * @throws SystemException if a system exception occurred
1101             */
1102            public MBMailingList fetchByUUID_G(String uuid, long groupId)
1103                    throws SystemException {
1104                    return fetchByUUID_G(uuid, groupId, true);
1105            }
1106    
1107            /**
1108             * Returns the message boards mailing list where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1109             *
1110             * @param uuid the uuid
1111             * @param groupId the group ID
1112             * @param retrieveFromCache whether to use the finder cache
1113             * @return the matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1114             * @throws SystemException if a system exception occurred
1115             */
1116            public MBMailingList fetchByUUID_G(String uuid, long groupId,
1117                    boolean retrieveFromCache) throws SystemException {
1118                    Object[] finderArgs = new Object[] { uuid, groupId };
1119    
1120                    Object result = null;
1121    
1122                    if (retrieveFromCache) {
1123                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1124                                            finderArgs, this);
1125                    }
1126    
1127                    if (result instanceof MBMailingList) {
1128                            MBMailingList mbMailingList = (MBMailingList)result;
1129    
1130                            if (!Validator.equals(uuid, mbMailingList.getUuid()) ||
1131                                            (groupId != mbMailingList.getGroupId())) {
1132                                    result = null;
1133                            }
1134                    }
1135    
1136                    if (result == null) {
1137                            StringBundler query = new StringBundler(3);
1138    
1139                            query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1140    
1141                            if (uuid == null) {
1142                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1143                            }
1144                            else {
1145                                    if (uuid.equals(StringPool.BLANK)) {
1146                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1147                                    }
1148                                    else {
1149                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1150                                    }
1151                            }
1152    
1153                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1154    
1155                            String sql = query.toString();
1156    
1157                            Session session = null;
1158    
1159                            try {
1160                                    session = openSession();
1161    
1162                                    Query q = session.createQuery(sql);
1163    
1164                                    QueryPos qPos = QueryPos.getInstance(q);
1165    
1166                                    if (uuid != null) {
1167                                            qPos.add(uuid);
1168                                    }
1169    
1170                                    qPos.add(groupId);
1171    
1172                                    List<MBMailingList> list = q.list();
1173    
1174                                    result = list;
1175    
1176                                    MBMailingList mbMailingList = null;
1177    
1178                                    if (list.isEmpty()) {
1179                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1180                                                    finderArgs, list);
1181                                    }
1182                                    else {
1183                                            mbMailingList = list.get(0);
1184    
1185                                            cacheResult(mbMailingList);
1186    
1187                                            if ((mbMailingList.getUuid() == null) ||
1188                                                            !mbMailingList.getUuid().equals(uuid) ||
1189                                                            (mbMailingList.getGroupId() != groupId)) {
1190                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1191                                                            finderArgs, mbMailingList);
1192                                            }
1193                                    }
1194    
1195                                    return mbMailingList;
1196                            }
1197                            catch (Exception e) {
1198                                    throw processException(e);
1199                            }
1200                            finally {
1201                                    if (result == null) {
1202                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1203                                                    finderArgs);
1204                                    }
1205    
1206                                    closeSession(session);
1207                            }
1208                    }
1209                    else {
1210                            if (result instanceof List<?>) {
1211                                    return null;
1212                            }
1213                            else {
1214                                    return (MBMailingList)result;
1215                            }
1216                    }
1217            }
1218    
1219            /**
1220             * Returns all the message boards mailing lists where active = &#63;.
1221             *
1222             * @param active the active
1223             * @return the matching message boards mailing lists
1224             * @throws SystemException if a system exception occurred
1225             */
1226            public List<MBMailingList> findByActive(boolean active)
1227                    throws SystemException {
1228                    return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1229            }
1230    
1231            /**
1232             * Returns a range of all the message boards mailing lists where active = &#63;.
1233             *
1234             * <p>
1235             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1236             * </p>
1237             *
1238             * @param active the active
1239             * @param start the lower bound of the range of message boards mailing lists
1240             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
1241             * @return the range of matching message boards mailing lists
1242             * @throws SystemException if a system exception occurred
1243             */
1244            public List<MBMailingList> findByActive(boolean active, int start, int end)
1245                    throws SystemException {
1246                    return findByActive(active, start, end, null);
1247            }
1248    
1249            /**
1250             * Returns an ordered range of all the message boards mailing lists where active = &#63;.
1251             *
1252             * <p>
1253             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1254             * </p>
1255             *
1256             * @param active the active
1257             * @param start the lower bound of the range of message boards mailing lists
1258             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
1259             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1260             * @return the ordered range of matching message boards mailing lists
1261             * @throws SystemException if a system exception occurred
1262             */
1263            public List<MBMailingList> findByActive(boolean active, int start, int end,
1264                    OrderByComparator orderByComparator) throws SystemException {
1265                    FinderPath finderPath = null;
1266                    Object[] finderArgs = null;
1267    
1268                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1269                                    (orderByComparator == null)) {
1270                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE;
1271                            finderArgs = new Object[] { active };
1272                    }
1273                    else {
1274                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE;
1275                            finderArgs = new Object[] { active, start, end, orderByComparator };
1276                    }
1277    
1278                    List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(finderPath,
1279                                    finderArgs, this);
1280    
1281                    if ((list != null) && !list.isEmpty()) {
1282                            for (MBMailingList mbMailingList : list) {
1283                                    if ((active != mbMailingList.getActive())) {
1284                                            list = null;
1285    
1286                                            break;
1287                                    }
1288                            }
1289                    }
1290    
1291                    if (list == null) {
1292                            StringBundler query = null;
1293    
1294                            if (orderByComparator != null) {
1295                                    query = new StringBundler(3 +
1296                                                    (orderByComparator.getOrderByFields().length * 3));
1297                            }
1298                            else {
1299                                    query = new StringBundler(2);
1300                            }
1301    
1302                            query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1303    
1304                            query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1305    
1306                            if (orderByComparator != null) {
1307                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1308                                            orderByComparator);
1309                            }
1310    
1311                            String sql = query.toString();
1312    
1313                            Session session = null;
1314    
1315                            try {
1316                                    session = openSession();
1317    
1318                                    Query q = session.createQuery(sql);
1319    
1320                                    QueryPos qPos = QueryPos.getInstance(q);
1321    
1322                                    qPos.add(active);
1323    
1324                                    list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1325                                                    start, end);
1326                            }
1327                            catch (Exception e) {
1328                                    throw processException(e);
1329                            }
1330                            finally {
1331                                    if (list == null) {
1332                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1333                                    }
1334                                    else {
1335                                            cacheResult(list);
1336    
1337                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1338                                    }
1339    
1340                                    closeSession(session);
1341                            }
1342                    }
1343    
1344                    return list;
1345            }
1346    
1347            /**
1348             * Returns the first message boards mailing list in the ordered set where active = &#63;.
1349             *
1350             * @param active the active
1351             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1352             * @return the first matching message boards mailing list
1353             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
1354             * @throws SystemException if a system exception occurred
1355             */
1356            public MBMailingList findByActive_First(boolean active,
1357                    OrderByComparator orderByComparator)
1358                    throws NoSuchMailingListException, SystemException {
1359                    MBMailingList mbMailingList = fetchByActive_First(active,
1360                                    orderByComparator);
1361    
1362                    if (mbMailingList != null) {
1363                            return mbMailingList;
1364                    }
1365    
1366                    StringBundler msg = new StringBundler(4);
1367    
1368                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1369    
1370                    msg.append("active=");
1371                    msg.append(active);
1372    
1373                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1374    
1375                    throw new NoSuchMailingListException(msg.toString());
1376            }
1377    
1378            /**
1379             * Returns the first message boards mailing list in the ordered set where active = &#63;.
1380             *
1381             * @param active the active
1382             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1383             * @return the first matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1384             * @throws SystemException if a system exception occurred
1385             */
1386            public MBMailingList fetchByActive_First(boolean active,
1387                    OrderByComparator orderByComparator) throws SystemException {
1388                    List<MBMailingList> list = findByActive(active, 0, 1, orderByComparator);
1389    
1390                    if (!list.isEmpty()) {
1391                            return list.get(0);
1392                    }
1393    
1394                    return null;
1395            }
1396    
1397            /**
1398             * Returns the last message boards mailing list in the ordered set where active = &#63;.
1399             *
1400             * @param active the active
1401             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1402             * @return the last matching message boards mailing list
1403             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
1404             * @throws SystemException if a system exception occurred
1405             */
1406            public MBMailingList findByActive_Last(boolean active,
1407                    OrderByComparator orderByComparator)
1408                    throws NoSuchMailingListException, SystemException {
1409                    MBMailingList mbMailingList = fetchByActive_Last(active,
1410                                    orderByComparator);
1411    
1412                    if (mbMailingList != null) {
1413                            return mbMailingList;
1414                    }
1415    
1416                    StringBundler msg = new StringBundler(4);
1417    
1418                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1419    
1420                    msg.append("active=");
1421                    msg.append(active);
1422    
1423                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1424    
1425                    throw new NoSuchMailingListException(msg.toString());
1426            }
1427    
1428            /**
1429             * Returns the last message boards mailing list in the ordered set where active = &#63;.
1430             *
1431             * @param active the active
1432             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1433             * @return the last matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1434             * @throws SystemException if a system exception occurred
1435             */
1436            public MBMailingList fetchByActive_Last(boolean active,
1437                    OrderByComparator orderByComparator) throws SystemException {
1438                    int count = countByActive(active);
1439    
1440                    List<MBMailingList> list = findByActive(active, count - 1, count,
1441                                    orderByComparator);
1442    
1443                    if (!list.isEmpty()) {
1444                            return list.get(0);
1445                    }
1446    
1447                    return null;
1448            }
1449    
1450            /**
1451             * Returns the message boards mailing lists before and after the current message boards mailing list in the ordered set where active = &#63;.
1452             *
1453             * @param mailingListId the primary key of the current message boards mailing list
1454             * @param active the active
1455             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1456             * @return the previous, current, and next message boards mailing list
1457             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a message boards mailing list with the primary key could not be found
1458             * @throws SystemException if a system exception occurred
1459             */
1460            public MBMailingList[] findByActive_PrevAndNext(long mailingListId,
1461                    boolean active, OrderByComparator orderByComparator)
1462                    throws NoSuchMailingListException, SystemException {
1463                    MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
1464    
1465                    Session session = null;
1466    
1467                    try {
1468                            session = openSession();
1469    
1470                            MBMailingList[] array = new MBMailingListImpl[3];
1471    
1472                            array[0] = getByActive_PrevAndNext(session, mbMailingList, active,
1473                                            orderByComparator, true);
1474    
1475                            array[1] = mbMailingList;
1476    
1477                            array[2] = getByActive_PrevAndNext(session, mbMailingList, active,
1478                                            orderByComparator, false);
1479    
1480                            return array;
1481                    }
1482                    catch (Exception e) {
1483                            throw processException(e);
1484                    }
1485                    finally {
1486                            closeSession(session);
1487                    }
1488            }
1489    
1490            protected MBMailingList getByActive_PrevAndNext(Session session,
1491                    MBMailingList mbMailingList, boolean active,
1492                    OrderByComparator orderByComparator, boolean previous) {
1493                    StringBundler query = null;
1494    
1495                    if (orderByComparator != null) {
1496                            query = new StringBundler(6 +
1497                                            (orderByComparator.getOrderByFields().length * 6));
1498                    }
1499                    else {
1500                            query = new StringBundler(3);
1501                    }
1502    
1503                    query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1504    
1505                    query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1506    
1507                    if (orderByComparator != null) {
1508                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1509    
1510                            if (orderByConditionFields.length > 0) {
1511                                    query.append(WHERE_AND);
1512                            }
1513    
1514                            for (int i = 0; i < orderByConditionFields.length; i++) {
1515                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1516                                    query.append(orderByConditionFields[i]);
1517    
1518                                    if ((i + 1) < orderByConditionFields.length) {
1519                                            if (orderByComparator.isAscending() ^ previous) {
1520                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1521                                            }
1522                                            else {
1523                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1524                                            }
1525                                    }
1526                                    else {
1527                                            if (orderByComparator.isAscending() ^ previous) {
1528                                                    query.append(WHERE_GREATER_THAN);
1529                                            }
1530                                            else {
1531                                                    query.append(WHERE_LESSER_THAN);
1532                                            }
1533                                    }
1534                            }
1535    
1536                            query.append(ORDER_BY_CLAUSE);
1537    
1538                            String[] orderByFields = orderByComparator.getOrderByFields();
1539    
1540                            for (int i = 0; i < orderByFields.length; i++) {
1541                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1542                                    query.append(orderByFields[i]);
1543    
1544                                    if ((i + 1) < orderByFields.length) {
1545                                            if (orderByComparator.isAscending() ^ previous) {
1546                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1547                                            }
1548                                            else {
1549                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1550                                            }
1551                                    }
1552                                    else {
1553                                            if (orderByComparator.isAscending() ^ previous) {
1554                                                    query.append(ORDER_BY_ASC);
1555                                            }
1556                                            else {
1557                                                    query.append(ORDER_BY_DESC);
1558                                            }
1559                                    }
1560                            }
1561                    }
1562    
1563                    String sql = query.toString();
1564    
1565                    Query q = session.createQuery(sql);
1566    
1567                    q.setFirstResult(0);
1568                    q.setMaxResults(2);
1569    
1570                    QueryPos qPos = QueryPos.getInstance(q);
1571    
1572                    qPos.add(active);
1573    
1574                    if (orderByComparator != null) {
1575                            Object[] values = orderByComparator.getOrderByConditionValues(mbMailingList);
1576    
1577                            for (Object value : values) {
1578                                    qPos.add(value);
1579                            }
1580                    }
1581    
1582                    List<MBMailingList> list = q.list();
1583    
1584                    if (list.size() == 2) {
1585                            return list.get(1);
1586                    }
1587                    else {
1588                            return null;
1589                    }
1590            }
1591    
1592            /**
1593             * Returns the message boards mailing list where groupId = &#63; and categoryId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchMailingListException} if it could not be found.
1594             *
1595             * @param groupId the group ID
1596             * @param categoryId the category ID
1597             * @return the matching message boards mailing list
1598             * @throws com.liferay.portlet.messageboards.NoSuchMailingListException if a matching message boards mailing list could not be found
1599             * @throws SystemException if a system exception occurred
1600             */
1601            public MBMailingList findByG_C(long groupId, long categoryId)
1602                    throws NoSuchMailingListException, SystemException {
1603                    MBMailingList mbMailingList = fetchByG_C(groupId, categoryId);
1604    
1605                    if (mbMailingList == null) {
1606                            StringBundler msg = new StringBundler(6);
1607    
1608                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1609    
1610                            msg.append("groupId=");
1611                            msg.append(groupId);
1612    
1613                            msg.append(", categoryId=");
1614                            msg.append(categoryId);
1615    
1616                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1617    
1618                            if (_log.isWarnEnabled()) {
1619                                    _log.warn(msg.toString());
1620                            }
1621    
1622                            throw new NoSuchMailingListException(msg.toString());
1623                    }
1624    
1625                    return mbMailingList;
1626            }
1627    
1628            /**
1629             * Returns the message boards mailing list where groupId = &#63; and categoryId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1630             *
1631             * @param groupId the group ID
1632             * @param categoryId the category ID
1633             * @return the matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1634             * @throws SystemException if a system exception occurred
1635             */
1636            public MBMailingList fetchByG_C(long groupId, long categoryId)
1637                    throws SystemException {
1638                    return fetchByG_C(groupId, categoryId, true);
1639            }
1640    
1641            /**
1642             * Returns the message boards mailing list where groupId = &#63; and categoryId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1643             *
1644             * @param groupId the group ID
1645             * @param categoryId the category ID
1646             * @param retrieveFromCache whether to use the finder cache
1647             * @return the matching message boards mailing list, or <code>null</code> if a matching message boards mailing list could not be found
1648             * @throws SystemException if a system exception occurred
1649             */
1650            public MBMailingList fetchByG_C(long groupId, long categoryId,
1651                    boolean retrieveFromCache) throws SystemException {
1652                    Object[] finderArgs = new Object[] { groupId, categoryId };
1653    
1654                    Object result = null;
1655    
1656                    if (retrieveFromCache) {
1657                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C,
1658                                            finderArgs, this);
1659                    }
1660    
1661                    if (result instanceof MBMailingList) {
1662                            MBMailingList mbMailingList = (MBMailingList)result;
1663    
1664                            if ((groupId != mbMailingList.getGroupId()) ||
1665                                            (categoryId != mbMailingList.getCategoryId())) {
1666                                    result = null;
1667                            }
1668                    }
1669    
1670                    if (result == null) {
1671                            StringBundler query = new StringBundler(3);
1672    
1673                            query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1674    
1675                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1676    
1677                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1678    
1679                            String sql = query.toString();
1680    
1681                            Session session = null;
1682    
1683                            try {
1684                                    session = openSession();
1685    
1686                                    Query q = session.createQuery(sql);
1687    
1688                                    QueryPos qPos = QueryPos.getInstance(q);
1689    
1690                                    qPos.add(groupId);
1691    
1692                                    qPos.add(categoryId);
1693    
1694                                    List<MBMailingList> list = q.list();
1695    
1696                                    result = list;
1697    
1698                                    MBMailingList mbMailingList = null;
1699    
1700                                    if (list.isEmpty()) {
1701                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
1702                                                    finderArgs, list);
1703                                    }
1704                                    else {
1705                                            mbMailingList = list.get(0);
1706    
1707                                            cacheResult(mbMailingList);
1708    
1709                                            if ((mbMailingList.getGroupId() != groupId) ||
1710                                                            (mbMailingList.getCategoryId() != categoryId)) {
1711                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
1712                                                            finderArgs, mbMailingList);
1713                                            }
1714                                    }
1715    
1716                                    return mbMailingList;
1717                            }
1718                            catch (Exception e) {
1719                                    throw processException(e);
1720                            }
1721                            finally {
1722                                    if (result == null) {
1723                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C,
1724                                                    finderArgs);
1725                                    }
1726    
1727                                    closeSession(session);
1728                            }
1729                    }
1730                    else {
1731                            if (result instanceof List<?>) {
1732                                    return null;
1733                            }
1734                            else {
1735                                    return (MBMailingList)result;
1736                            }
1737                    }
1738            }
1739    
1740            /**
1741             * Returns all the message boards mailing lists.
1742             *
1743             * @return the message boards mailing lists
1744             * @throws SystemException if a system exception occurred
1745             */
1746            public List<MBMailingList> findAll() throws SystemException {
1747                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1748            }
1749    
1750            /**
1751             * Returns a range of all the message boards mailing lists.
1752             *
1753             * <p>
1754             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1755             * </p>
1756             *
1757             * @param start the lower bound of the range of message boards mailing lists
1758             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
1759             * @return the range of message boards mailing lists
1760             * @throws SystemException if a system exception occurred
1761             */
1762            public List<MBMailingList> findAll(int start, int end)
1763                    throws SystemException {
1764                    return findAll(start, end, null);
1765            }
1766    
1767            /**
1768             * Returns an ordered range of all the message boards mailing lists.
1769             *
1770             * <p>
1771             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1772             * </p>
1773             *
1774             * @param start the lower bound of the range of message boards mailing lists
1775             * @param end the upper bound of the range of message boards mailing lists (not inclusive)
1776             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1777             * @return the ordered range of message boards mailing lists
1778             * @throws SystemException if a system exception occurred
1779             */
1780            public List<MBMailingList> findAll(int start, int end,
1781                    OrderByComparator orderByComparator) throws SystemException {
1782                    FinderPath finderPath = null;
1783                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1784    
1785                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1786                                    (orderByComparator == null)) {
1787                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1788                            finderArgs = FINDER_ARGS_EMPTY;
1789                    }
1790                    else {
1791                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1792                            finderArgs = new Object[] { start, end, orderByComparator };
1793                    }
1794    
1795                    List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(finderPath,
1796                                    finderArgs, this);
1797    
1798                    if (list == null) {
1799                            StringBundler query = null;
1800                            String sql = null;
1801    
1802                            if (orderByComparator != null) {
1803                                    query = new StringBundler(2 +
1804                                                    (orderByComparator.getOrderByFields().length * 3));
1805    
1806                                    query.append(_SQL_SELECT_MBMAILINGLIST);
1807    
1808                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1809                                            orderByComparator);
1810    
1811                                    sql = query.toString();
1812                            }
1813                            else {
1814                                    sql = _SQL_SELECT_MBMAILINGLIST;
1815                            }
1816    
1817                            Session session = null;
1818    
1819                            try {
1820                                    session = openSession();
1821    
1822                                    Query q = session.createQuery(sql);
1823    
1824                                    if (orderByComparator == null) {
1825                                            list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1826                                                            start, end, false);
1827    
1828                                            Collections.sort(list);
1829                                    }
1830                                    else {
1831                                            list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1832                                                            start, end);
1833                                    }
1834                            }
1835                            catch (Exception e) {
1836                                    throw processException(e);
1837                            }
1838                            finally {
1839                                    if (list == null) {
1840                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1841                                    }
1842                                    else {
1843                                            cacheResult(list);
1844    
1845                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1846                                    }
1847    
1848                                    closeSession(session);
1849                            }
1850                    }
1851    
1852                    return list;
1853            }
1854    
1855            /**
1856             * Removes all the message boards mailing lists where uuid = &#63; from the database.
1857             *
1858             * @param uuid the uuid
1859             * @throws SystemException if a system exception occurred
1860             */
1861            public void removeByUuid(String uuid) throws SystemException {
1862                    for (MBMailingList mbMailingList : findByUuid(uuid)) {
1863                            remove(mbMailingList);
1864                    }
1865            }
1866    
1867            /**
1868             * Removes the message boards mailing list where uuid = &#63; and groupId = &#63; from the database.
1869             *
1870             * @param uuid the uuid
1871             * @param groupId the group ID
1872             * @return the message boards mailing list that was removed
1873             * @throws SystemException if a system exception occurred
1874             */
1875            public MBMailingList removeByUUID_G(String uuid, long groupId)
1876                    throws NoSuchMailingListException, SystemException {
1877                    MBMailingList mbMailingList = findByUUID_G(uuid, groupId);
1878    
1879                    return remove(mbMailingList);
1880            }
1881    
1882            /**
1883             * Removes all the message boards mailing lists where active = &#63; from the database.
1884             *
1885             * @param active the active
1886             * @throws SystemException if a system exception occurred
1887             */
1888            public void removeByActive(boolean active) throws SystemException {
1889                    for (MBMailingList mbMailingList : findByActive(active)) {
1890                            remove(mbMailingList);
1891                    }
1892            }
1893    
1894            /**
1895             * Removes the message boards mailing list where groupId = &#63; and categoryId = &#63; from the database.
1896             *
1897             * @param groupId the group ID
1898             * @param categoryId the category ID
1899             * @return the message boards mailing list that was removed
1900             * @throws SystemException if a system exception occurred
1901             */
1902            public MBMailingList removeByG_C(long groupId, long categoryId)
1903                    throws NoSuchMailingListException, SystemException {
1904                    MBMailingList mbMailingList = findByG_C(groupId, categoryId);
1905    
1906                    return remove(mbMailingList);
1907            }
1908    
1909            /**
1910             * Removes all the message boards mailing lists from the database.
1911             *
1912             * @throws SystemException if a system exception occurred
1913             */
1914            public void removeAll() throws SystemException {
1915                    for (MBMailingList mbMailingList : findAll()) {
1916                            remove(mbMailingList);
1917                    }
1918            }
1919    
1920            /**
1921             * Returns the number of message boards mailing lists where uuid = &#63;.
1922             *
1923             * @param uuid the uuid
1924             * @return the number of matching message boards mailing lists
1925             * @throws SystemException if a system exception occurred
1926             */
1927            public int countByUuid(String uuid) throws SystemException {
1928                    Object[] finderArgs = new Object[] { uuid };
1929    
1930                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1931                                    finderArgs, this);
1932    
1933                    if (count == null) {
1934                            StringBundler query = new StringBundler(2);
1935    
1936                            query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1937    
1938                            if (uuid == null) {
1939                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1940                            }
1941                            else {
1942                                    if (uuid.equals(StringPool.BLANK)) {
1943                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1944                                    }
1945                                    else {
1946                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1947                                    }
1948                            }
1949    
1950                            String sql = query.toString();
1951    
1952                            Session session = null;
1953    
1954                            try {
1955                                    session = openSession();
1956    
1957                                    Query q = session.createQuery(sql);
1958    
1959                                    QueryPos qPos = QueryPos.getInstance(q);
1960    
1961                                    if (uuid != null) {
1962                                            qPos.add(uuid);
1963                                    }
1964    
1965                                    count = (Long)q.uniqueResult();
1966                            }
1967                            catch (Exception e) {
1968                                    throw processException(e);
1969                            }
1970                            finally {
1971                                    if (count == null) {
1972                                            count = Long.valueOf(0);
1973                                    }
1974    
1975                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1976                                            finderArgs, count);
1977    
1978                                    closeSession(session);
1979                            }
1980                    }
1981    
1982                    return count.intValue();
1983            }
1984    
1985            /**
1986             * Returns the number of message boards mailing lists where uuid = &#63; and groupId = &#63;.
1987             *
1988             * @param uuid the uuid
1989             * @param groupId the group ID
1990             * @return the number of matching message boards mailing lists
1991             * @throws SystemException if a system exception occurred
1992             */
1993            public int countByUUID_G(String uuid, long groupId)
1994                    throws SystemException {
1995                    Object[] finderArgs = new Object[] { uuid, groupId };
1996    
1997                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1998                                    finderArgs, this);
1999    
2000                    if (count == null) {
2001                            StringBundler query = new StringBundler(3);
2002    
2003                            query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
2004    
2005                            if (uuid == null) {
2006                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2007                            }
2008                            else {
2009                                    if (uuid.equals(StringPool.BLANK)) {
2010                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2011                                    }
2012                                    else {
2013                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2014                                    }
2015                            }
2016    
2017                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2018    
2019                            String sql = query.toString();
2020    
2021                            Session session = null;
2022    
2023                            try {
2024                                    session = openSession();
2025    
2026                                    Query q = session.createQuery(sql);
2027    
2028                                    QueryPos qPos = QueryPos.getInstance(q);
2029    
2030                                    if (uuid != null) {
2031                                            qPos.add(uuid);
2032                                    }
2033    
2034                                    qPos.add(groupId);
2035    
2036                                    count = (Long)q.uniqueResult();
2037                            }
2038                            catch (Exception e) {
2039                                    throw processException(e);
2040                            }
2041                            finally {
2042                                    if (count == null) {
2043                                            count = Long.valueOf(0);
2044                                    }
2045    
2046                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2047                                            finderArgs, count);
2048    
2049                                    closeSession(session);
2050                            }
2051                    }
2052    
2053                    return count.intValue();
2054            }
2055    
2056            /**
2057             * Returns the number of message boards mailing lists where active = &#63;.
2058             *
2059             * @param active the active
2060             * @return the number of matching message boards mailing lists
2061             * @throws SystemException if a system exception occurred
2062             */
2063            public int countByActive(boolean active) throws SystemException {
2064                    Object[] finderArgs = new Object[] { active };
2065    
2066                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ACTIVE,
2067                                    finderArgs, this);
2068    
2069                    if (count == null) {
2070                            StringBundler query = new StringBundler(2);
2071    
2072                            query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
2073    
2074                            query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
2075    
2076                            String sql = query.toString();
2077    
2078                            Session session = null;
2079    
2080                            try {
2081                                    session = openSession();
2082    
2083                                    Query q = session.createQuery(sql);
2084    
2085                                    QueryPos qPos = QueryPos.getInstance(q);
2086    
2087                                    qPos.add(active);
2088    
2089                                    count = (Long)q.uniqueResult();
2090                            }
2091                            catch (Exception e) {
2092                                    throw processException(e);
2093                            }
2094                            finally {
2095                                    if (count == null) {
2096                                            count = Long.valueOf(0);
2097                                    }
2098    
2099                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ACTIVE,
2100                                            finderArgs, count);
2101    
2102                                    closeSession(session);
2103                            }
2104                    }
2105    
2106                    return count.intValue();
2107            }
2108    
2109            /**
2110             * Returns the number of message boards mailing lists where groupId = &#63; and categoryId = &#63;.
2111             *
2112             * @param groupId the group ID
2113             * @param categoryId the category ID
2114             * @return the number of matching message boards mailing lists
2115             * @throws SystemException if a system exception occurred
2116             */
2117            public int countByG_C(long groupId, long categoryId)
2118                    throws SystemException {
2119                    Object[] finderArgs = new Object[] { groupId, categoryId };
2120    
2121                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
2122                                    finderArgs, this);
2123    
2124                    if (count == null) {
2125                            StringBundler query = new StringBundler(3);
2126    
2127                            query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
2128    
2129                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2130    
2131                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2132    
2133                            String sql = query.toString();
2134    
2135                            Session session = null;
2136    
2137                            try {
2138                                    session = openSession();
2139    
2140                                    Query q = session.createQuery(sql);
2141    
2142                                    QueryPos qPos = QueryPos.getInstance(q);
2143    
2144                                    qPos.add(groupId);
2145    
2146                                    qPos.add(categoryId);
2147    
2148                                    count = (Long)q.uniqueResult();
2149                            }
2150                            catch (Exception e) {
2151                                    throw processException(e);
2152                            }
2153                            finally {
2154                                    if (count == null) {
2155                                            count = Long.valueOf(0);
2156                                    }
2157    
2158                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
2159                                            count);
2160    
2161                                    closeSession(session);
2162                            }
2163                    }
2164    
2165                    return count.intValue();
2166            }
2167    
2168            /**
2169             * Returns the number of message boards mailing lists.
2170             *
2171             * @return the number of message boards mailing lists
2172             * @throws SystemException if a system exception occurred
2173             */
2174            public int countAll() throws SystemException {
2175                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2176                                    FINDER_ARGS_EMPTY, this);
2177    
2178                    if (count == null) {
2179                            Session session = null;
2180    
2181                            try {
2182                                    session = openSession();
2183    
2184                                    Query q = session.createQuery(_SQL_COUNT_MBMAILINGLIST);
2185    
2186                                    count = (Long)q.uniqueResult();
2187                            }
2188                            catch (Exception e) {
2189                                    throw processException(e);
2190                            }
2191                            finally {
2192                                    if (count == null) {
2193                                            count = Long.valueOf(0);
2194                                    }
2195    
2196                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2197                                            FINDER_ARGS_EMPTY, count);
2198    
2199                                    closeSession(session);
2200                            }
2201                    }
2202    
2203                    return count.intValue();
2204            }
2205    
2206            /**
2207             * Initializes the message boards mailing list persistence.
2208             */
2209            public void afterPropertiesSet() {
2210                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2211                                            com.liferay.portal.util.PropsUtil.get(
2212                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMailingList")));
2213    
2214                    if (listenerClassNames.length > 0) {
2215                            try {
2216                                    List<ModelListener<MBMailingList>> listenersList = new ArrayList<ModelListener<MBMailingList>>();
2217    
2218                                    for (String listenerClassName : listenerClassNames) {
2219                                            Class<?> clazz = getClass();
2220    
2221                                            listenersList.add((ModelListener<MBMailingList>)InstanceFactory.newInstance(
2222                                                            clazz.getClassLoader(), listenerClassName));
2223                                    }
2224    
2225                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2226                            }
2227                            catch (Exception e) {
2228                                    _log.error(e);
2229                            }
2230                    }
2231            }
2232    
2233            public void destroy() {
2234                    EntityCacheUtil.removeCache(MBMailingListImpl.class.getName());
2235                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2236                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2237            }
2238    
2239            @BeanReference(type = MBBanPersistence.class)
2240            protected MBBanPersistence mbBanPersistence;
2241            @BeanReference(type = MBCategoryPersistence.class)
2242            protected MBCategoryPersistence mbCategoryPersistence;
2243            @BeanReference(type = MBDiscussionPersistence.class)
2244            protected MBDiscussionPersistence mbDiscussionPersistence;
2245            @BeanReference(type = MBMailingListPersistence.class)
2246            protected MBMailingListPersistence mbMailingListPersistence;
2247            @BeanReference(type = MBMessagePersistence.class)
2248            protected MBMessagePersistence mbMessagePersistence;
2249            @BeanReference(type = MBStatsUserPersistence.class)
2250            protected MBStatsUserPersistence mbStatsUserPersistence;
2251            @BeanReference(type = MBThreadPersistence.class)
2252            protected MBThreadPersistence mbThreadPersistence;
2253            @BeanReference(type = MBThreadFlagPersistence.class)
2254            protected MBThreadFlagPersistence mbThreadFlagPersistence;
2255            @BeanReference(type = ResourcePersistence.class)
2256            protected ResourcePersistence resourcePersistence;
2257            @BeanReference(type = UserPersistence.class)
2258            protected UserPersistence userPersistence;
2259            private static final String _SQL_SELECT_MBMAILINGLIST = "SELECT mbMailingList FROM MBMailingList mbMailingList";
2260            private static final String _SQL_SELECT_MBMAILINGLIST_WHERE = "SELECT mbMailingList FROM MBMailingList mbMailingList WHERE ";
2261            private static final String _SQL_COUNT_MBMAILINGLIST = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList";
2262            private static final String _SQL_COUNT_MBMAILINGLIST_WHERE = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList WHERE ";
2263            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMailingList.uuid IS NULL";
2264            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMailingList.uuid = ?";
2265            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = ?)";
2266            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMailingList.uuid IS NULL AND ";
2267            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMailingList.uuid = ? AND ";
2268            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = ?) AND ";
2269            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMailingList.groupId = ?";
2270            private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "mbMailingList.active = ?";
2271            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMailingList.groupId = ? AND ";
2272            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMailingList.categoryId = ?";
2273            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMailingList.";
2274            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMailingList exists with the primary key ";
2275            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMailingList exists with the key {";
2276            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2277            private static Log _log = LogFactoryUtil.getLog(MBMailingListPersistenceImpl.class);
2278            private static MBMailingList _nullMBMailingList = new MBMailingListImpl() {
2279                            @Override
2280                            public Object clone() {
2281                                    return this;
2282                            }
2283    
2284                            @Override
2285                            public CacheModel<MBMailingList> toCacheModel() {
2286                                    return _nullMBMailingListCacheModel;
2287                            }
2288                    };
2289    
2290            private static CacheModel<MBMailingList> _nullMBMailingListCacheModel = new CacheModel<MBMailingList>() {
2291                            public MBMailingList toEntityModel() {
2292                                    return _nullMBMailingList;
2293                            }
2294                    };
2295    }