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