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