1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.messageboards.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.kernel.annotation.BeanReference;
19  import com.liferay.portal.kernel.cache.CacheRegistry;
20  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
21  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderPath;
24  import com.liferay.portal.kernel.dao.orm.Query;
25  import com.liferay.portal.kernel.dao.orm.QueryPos;
26  import com.liferay.portal.kernel.dao.orm.QueryUtil;
27  import com.liferay.portal.kernel.dao.orm.Session;
28  import com.liferay.portal.kernel.exception.SystemException;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringBundler;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.kernel.util.Validator;
37  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
38  import com.liferay.portal.model.ModelListener;
39  import com.liferay.portal.service.persistence.BatchSessionUtil;
40  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41  
42  import com.liferay.portlet.messageboards.NoSuchMailingListException;
43  import com.liferay.portlet.messageboards.model.MBMailingList;
44  import com.liferay.portlet.messageboards.model.impl.MBMailingListImpl;
45  import com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl;
46  
47  import java.io.Serializable;
48  
49  import java.util.ArrayList;
50  import java.util.Collections;
51  import java.util.List;
52  
53  /**
54   * <a href="MBMailingListPersistenceImpl.java.html"><b><i>View Source</i></b></a>
55   *
56   * <p>
57   * ServiceBuilder generated this class. Modifications in this class will be
58   * overwritten the next time is generated.
59   * </p>
60   *
61   * @author    Brian Wing Shun Chan
62   * @see       MBMailingListPersistence
63   * @see       MBMailingListUtil
64   * @generated
65   */
66  public class MBMailingListPersistenceImpl extends BasePersistenceImpl<MBMailingList>
67      implements MBMailingListPersistence {
68      public static final String FINDER_CLASS_NAME_ENTITY = MBMailingListImpl.class.getName();
69      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
70          ".List";
71      public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
72              MBMailingListModelImpl.FINDER_CACHE_ENABLED,
73              FINDER_CLASS_NAME_LIST, "findByUuid",
74              new String[] { String.class.getName() });
75      public static final FinderPath FINDER_PATH_FIND_BY_OBC_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
76              MBMailingListModelImpl.FINDER_CACHE_ENABLED,
77              FINDER_CLASS_NAME_LIST, "findByUuid",
78              new String[] {
79                  String.class.getName(),
80                  
81              "java.lang.Integer", "java.lang.Integer",
82                  "com.liferay.portal.kernel.util.OrderByComparator"
83              });
84      public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
85              MBMailingListModelImpl.FINDER_CACHE_ENABLED,
86              FINDER_CLASS_NAME_LIST, "countByUuid",
87              new String[] { String.class.getName() });
88      public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
89              MBMailingListModelImpl.FINDER_CACHE_ENABLED,
90              FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
91              new String[] { String.class.getName(), Long.class.getName() });
92      public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
93              MBMailingListModelImpl.FINDER_CACHE_ENABLED,
94              FINDER_CLASS_NAME_LIST, "countByUUID_G",
95              new String[] { String.class.getName(), Long.class.getName() });
96      public static final FinderPath FINDER_PATH_FIND_BY_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
97              MBMailingListModelImpl.FINDER_CACHE_ENABLED,
98              FINDER_CLASS_NAME_LIST, "findByActive",
99              new String[] { Boolean.class.getName() });
100     public static final FinderPath FINDER_PATH_FIND_BY_OBC_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
101             MBMailingListModelImpl.FINDER_CACHE_ENABLED,
102             FINDER_CLASS_NAME_LIST, "findByActive",
103             new String[] {
104                 Boolean.class.getName(),
105                 
106             "java.lang.Integer", "java.lang.Integer",
107                 "com.liferay.portal.kernel.util.OrderByComparator"
108             });
109     public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
110             MBMailingListModelImpl.FINDER_CACHE_ENABLED,
111             FINDER_CLASS_NAME_LIST, "countByActive",
112             new String[] { Boolean.class.getName() });
113     public static final FinderPath FINDER_PATH_FETCH_BY_G_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
114             MBMailingListModelImpl.FINDER_CACHE_ENABLED,
115             FINDER_CLASS_NAME_ENTITY, "fetchByG_C",
116             new String[] { Long.class.getName(), Long.class.getName() });
117     public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
118             MBMailingListModelImpl.FINDER_CACHE_ENABLED,
119             FINDER_CLASS_NAME_LIST, "countByG_C",
120             new String[] { Long.class.getName(), Long.class.getName() });
121     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
122             MBMailingListModelImpl.FINDER_CACHE_ENABLED,
123             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
124     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
125             MBMailingListModelImpl.FINDER_CACHE_ENABLED,
126             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
127 
128     public void cacheResult(MBMailingList mbMailingList) {
129         EntityCacheUtil.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
130             MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
131             mbMailingList);
132 
133         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
134             new Object[] {
135                 mbMailingList.getUuid(), new Long(mbMailingList.getGroupId())
136             }, mbMailingList);
137 
138         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
139             new Object[] {
140                 new Long(mbMailingList.getGroupId()),
141                 new Long(mbMailingList.getCategoryId())
142             }, mbMailingList);
143     }
144 
145     public void cacheResult(List<MBMailingList> mbMailingLists) {
146         for (MBMailingList mbMailingList : mbMailingLists) {
147             if (EntityCacheUtil.getResult(
148                         MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
149                         MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
150                         this) == null) {
151                 cacheResult(mbMailingList);
152             }
153         }
154     }
155 
156     public void clearCache() {
157         CacheRegistry.clear(MBMailingListImpl.class.getName());
158         EntityCacheUtil.clearCache(MBMailingListImpl.class.getName());
159         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
160         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
161     }
162 
163     public MBMailingList create(long mailingListId) {
164         MBMailingList mbMailingList = new MBMailingListImpl();
165 
166         mbMailingList.setNew(true);
167         mbMailingList.setPrimaryKey(mailingListId);
168 
169         String uuid = PortalUUIDUtil.generate();
170 
171         mbMailingList.setUuid(uuid);
172 
173         return mbMailingList;
174     }
175 
176     public MBMailingList remove(Serializable primaryKey)
177         throws NoSuchModelException, SystemException {
178         return remove(((Long)primaryKey).longValue());
179     }
180 
181     public MBMailingList remove(long mailingListId)
182         throws NoSuchMailingListException, SystemException {
183         Session session = null;
184 
185         try {
186             session = openSession();
187 
188             MBMailingList mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
189                     new Long(mailingListId));
190 
191             if (mbMailingList == null) {
192                 if (_log.isWarnEnabled()) {
193                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + mailingListId);
194                 }
195 
196                 throw new NoSuchMailingListException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
197                     mailingListId);
198             }
199 
200             return remove(mbMailingList);
201         }
202         catch (NoSuchMailingListException nsee) {
203             throw nsee;
204         }
205         catch (Exception e) {
206             throw processException(e);
207         }
208         finally {
209             closeSession(session);
210         }
211     }
212 
213     public MBMailingList remove(MBMailingList mbMailingList)
214         throws SystemException {
215         for (ModelListener<MBMailingList> listener : listeners) {
216             listener.onBeforeRemove(mbMailingList);
217         }
218 
219         mbMailingList = removeImpl(mbMailingList);
220 
221         for (ModelListener<MBMailingList> listener : listeners) {
222             listener.onAfterRemove(mbMailingList);
223         }
224 
225         return mbMailingList;
226     }
227 
228     protected MBMailingList removeImpl(MBMailingList mbMailingList)
229         throws SystemException {
230         mbMailingList = toUnwrappedModel(mbMailingList);
231 
232         Session session = null;
233 
234         try {
235             session = openSession();
236 
237             if (mbMailingList.isCachedModel() || BatchSessionUtil.isEnabled()) {
238                 Object staleObject = session.get(MBMailingListImpl.class,
239                         mbMailingList.getPrimaryKeyObj());
240 
241                 if (staleObject != null) {
242                     session.evict(staleObject);
243                 }
244             }
245 
246             session.delete(mbMailingList);
247 
248             session.flush();
249         }
250         catch (Exception e) {
251             throw processException(e);
252         }
253         finally {
254             closeSession(session);
255         }
256 
257         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
258 
259         MBMailingListModelImpl mbMailingListModelImpl = (MBMailingListModelImpl)mbMailingList;
260 
261         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
262             new Object[] {
263                 mbMailingListModelImpl.getOriginalUuid(),
264                 new Long(mbMailingListModelImpl.getOriginalGroupId())
265             });
266 
267         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C,
268             new Object[] {
269                 new Long(mbMailingListModelImpl.getOriginalGroupId()),
270                 new Long(mbMailingListModelImpl.getOriginalCategoryId())
271             });
272 
273         EntityCacheUtil.removeResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
274             MBMailingListImpl.class, mbMailingList.getPrimaryKey());
275 
276         return mbMailingList;
277     }
278 
279     public MBMailingList updateImpl(
280         com.liferay.portlet.messageboards.model.MBMailingList mbMailingList,
281         boolean merge) throws SystemException {
282         mbMailingList = toUnwrappedModel(mbMailingList);
283 
284         boolean isNew = mbMailingList.isNew();
285 
286         MBMailingListModelImpl mbMailingListModelImpl = (MBMailingListModelImpl)mbMailingList;
287 
288         if (Validator.isNull(mbMailingList.getUuid())) {
289             String uuid = PortalUUIDUtil.generate();
290 
291             mbMailingList.setUuid(uuid);
292         }
293 
294         Session session = null;
295 
296         try {
297             session = openSession();
298 
299             BatchSessionUtil.update(session, mbMailingList, merge);
300 
301             mbMailingList.setNew(false);
302         }
303         catch (Exception e) {
304             throw processException(e);
305         }
306         finally {
307             closeSession(session);
308         }
309 
310         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
311 
312         EntityCacheUtil.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
313             MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
314             mbMailingList);
315 
316         if (!isNew &&
317                 (!Validator.equals(mbMailingList.getUuid(),
318                     mbMailingListModelImpl.getOriginalUuid()) ||
319                 (mbMailingList.getGroupId() != mbMailingListModelImpl.getOriginalGroupId()))) {
320             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
321                 new Object[] {
322                     mbMailingListModelImpl.getOriginalUuid(),
323                     new Long(mbMailingListModelImpl.getOriginalGroupId())
324                 });
325         }
326 
327         if (isNew ||
328                 (!Validator.equals(mbMailingList.getUuid(),
329                     mbMailingListModelImpl.getOriginalUuid()) ||
330                 (mbMailingList.getGroupId() != mbMailingListModelImpl.getOriginalGroupId()))) {
331             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
332                 new Object[] {
333                     mbMailingList.getUuid(),
334                     new Long(mbMailingList.getGroupId())
335                 }, mbMailingList);
336         }
337 
338         if (!isNew &&
339                 ((mbMailingList.getGroupId() != mbMailingListModelImpl.getOriginalGroupId()) ||
340                 (mbMailingList.getCategoryId() != mbMailingListModelImpl.getOriginalCategoryId()))) {
341             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C,
342                 new Object[] {
343                     new Long(mbMailingListModelImpl.getOriginalGroupId()),
344                     new Long(mbMailingListModelImpl.getOriginalCategoryId())
345                 });
346         }
347 
348         if (isNew ||
349                 ((mbMailingList.getGroupId() != mbMailingListModelImpl.getOriginalGroupId()) ||
350                 (mbMailingList.getCategoryId() != mbMailingListModelImpl.getOriginalCategoryId()))) {
351             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
352                 new Object[] {
353                     new Long(mbMailingList.getGroupId()),
354                     new Long(mbMailingList.getCategoryId())
355                 }, mbMailingList);
356         }
357 
358         return mbMailingList;
359     }
360 
361     protected MBMailingList toUnwrappedModel(MBMailingList mbMailingList) {
362         if (mbMailingList instanceof MBMailingListImpl) {
363             return mbMailingList;
364         }
365 
366         MBMailingListImpl mbMailingListImpl = new MBMailingListImpl();
367 
368         mbMailingListImpl.setNew(mbMailingList.isNew());
369         mbMailingListImpl.setPrimaryKey(mbMailingList.getPrimaryKey());
370 
371         mbMailingListImpl.setUuid(mbMailingList.getUuid());
372         mbMailingListImpl.setMailingListId(mbMailingList.getMailingListId());
373         mbMailingListImpl.setGroupId(mbMailingList.getGroupId());
374         mbMailingListImpl.setCompanyId(mbMailingList.getCompanyId());
375         mbMailingListImpl.setUserId(mbMailingList.getUserId());
376         mbMailingListImpl.setUserName(mbMailingList.getUserName());
377         mbMailingListImpl.setCreateDate(mbMailingList.getCreateDate());
378         mbMailingListImpl.setModifiedDate(mbMailingList.getModifiedDate());
379         mbMailingListImpl.setCategoryId(mbMailingList.getCategoryId());
380         mbMailingListImpl.setEmailAddress(mbMailingList.getEmailAddress());
381         mbMailingListImpl.setInProtocol(mbMailingList.getInProtocol());
382         mbMailingListImpl.setInServerName(mbMailingList.getInServerName());
383         mbMailingListImpl.setInServerPort(mbMailingList.getInServerPort());
384         mbMailingListImpl.setInUseSSL(mbMailingList.isInUseSSL());
385         mbMailingListImpl.setInUserName(mbMailingList.getInUserName());
386         mbMailingListImpl.setInPassword(mbMailingList.getInPassword());
387         mbMailingListImpl.setInReadInterval(mbMailingList.getInReadInterval());
388         mbMailingListImpl.setOutEmailAddress(mbMailingList.getOutEmailAddress());
389         mbMailingListImpl.setOutCustom(mbMailingList.isOutCustom());
390         mbMailingListImpl.setOutServerName(mbMailingList.getOutServerName());
391         mbMailingListImpl.setOutServerPort(mbMailingList.getOutServerPort());
392         mbMailingListImpl.setOutUseSSL(mbMailingList.isOutUseSSL());
393         mbMailingListImpl.setOutUserName(mbMailingList.getOutUserName());
394         mbMailingListImpl.setOutPassword(mbMailingList.getOutPassword());
395         mbMailingListImpl.setActive(mbMailingList.isActive());
396 
397         return mbMailingListImpl;
398     }
399 
400     public MBMailingList findByPrimaryKey(Serializable primaryKey)
401         throws NoSuchModelException, SystemException {
402         return findByPrimaryKey(((Long)primaryKey).longValue());
403     }
404 
405     public MBMailingList findByPrimaryKey(long mailingListId)
406         throws NoSuchMailingListException, SystemException {
407         MBMailingList mbMailingList = fetchByPrimaryKey(mailingListId);
408 
409         if (mbMailingList == null) {
410             if (_log.isWarnEnabled()) {
411                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + mailingListId);
412             }
413 
414             throw new NoSuchMailingListException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
415                 mailingListId);
416         }
417 
418         return mbMailingList;
419     }
420 
421     public MBMailingList fetchByPrimaryKey(Serializable primaryKey)
422         throws SystemException {
423         return fetchByPrimaryKey(((Long)primaryKey).longValue());
424     }
425 
426     public MBMailingList fetchByPrimaryKey(long mailingListId)
427         throws SystemException {
428         MBMailingList mbMailingList = (MBMailingList)EntityCacheUtil.getResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
429                 MBMailingListImpl.class, mailingListId, this);
430 
431         if (mbMailingList == null) {
432             Session session = null;
433 
434             try {
435                 session = openSession();
436 
437                 mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
438                         new Long(mailingListId));
439             }
440             catch (Exception e) {
441                 throw processException(e);
442             }
443             finally {
444                 if (mbMailingList != null) {
445                     cacheResult(mbMailingList);
446                 }
447 
448                 closeSession(session);
449             }
450         }
451 
452         return mbMailingList;
453     }
454 
455     public List<MBMailingList> findByUuid(String uuid)
456         throws SystemException {
457         Object[] finderArgs = new Object[] { uuid };
458 
459         List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
460                 finderArgs, this);
461 
462         if (list == null) {
463             Session session = null;
464 
465             try {
466                 session = openSession();
467 
468                 StringBundler query = new StringBundler(2);
469 
470                 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
471 
472                 if (uuid == null) {
473                     query.append(_FINDER_COLUMN_UUID_UUID_1);
474                 }
475                 else {
476                     if (uuid.equals(StringPool.BLANK)) {
477                         query.append(_FINDER_COLUMN_UUID_UUID_3);
478                     }
479                     else {
480                         query.append(_FINDER_COLUMN_UUID_UUID_2);
481                     }
482                 }
483 
484                 String sql = query.toString();
485 
486                 Query q = session.createQuery(sql);
487 
488                 QueryPos qPos = QueryPos.getInstance(q);
489 
490                 if (uuid != null) {
491                     qPos.add(uuid);
492                 }
493 
494                 list = q.list();
495             }
496             catch (Exception e) {
497                 throw processException(e);
498             }
499             finally {
500                 if (list == null) {
501                     list = new ArrayList<MBMailingList>();
502                 }
503 
504                 cacheResult(list);
505 
506                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
507                     list);
508 
509                 closeSession(session);
510             }
511         }
512 
513         return list;
514     }
515 
516     public List<MBMailingList> findByUuid(String uuid, int start, int end)
517         throws SystemException {
518         return findByUuid(uuid, start, end, null);
519     }
520 
521     public List<MBMailingList> findByUuid(String uuid, int start, int end,
522         OrderByComparator obc) throws SystemException {
523         Object[] finderArgs = new Object[] {
524                 uuid,
525                 
526                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
527             };
528 
529         List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
530                 finderArgs, this);
531 
532         if (list == null) {
533             Session session = null;
534 
535             try {
536                 session = openSession();
537 
538                 StringBundler query = null;
539 
540                 if (obc != null) {
541                     query = new StringBundler(3 +
542                             (obc.getOrderByFields().length * 3));
543                 }
544                 else {
545                     query = new StringBundler(2);
546                 }
547 
548                 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
549 
550                 if (uuid == null) {
551                     query.append(_FINDER_COLUMN_UUID_UUID_1);
552                 }
553                 else {
554                     if (uuid.equals(StringPool.BLANK)) {
555                         query.append(_FINDER_COLUMN_UUID_UUID_3);
556                     }
557                     else {
558                         query.append(_FINDER_COLUMN_UUID_UUID_2);
559                     }
560                 }
561 
562                 if (obc != null) {
563                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
564                 }
565 
566                 String sql = query.toString();
567 
568                 Query q = session.createQuery(sql);
569 
570                 QueryPos qPos = QueryPos.getInstance(q);
571 
572                 if (uuid != null) {
573                     qPos.add(uuid);
574                 }
575 
576                 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
577                         start, end);
578             }
579             catch (Exception e) {
580                 throw processException(e);
581             }
582             finally {
583                 if (list == null) {
584                     list = new ArrayList<MBMailingList>();
585                 }
586 
587                 cacheResult(list);
588 
589                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
590                     finderArgs, list);
591 
592                 closeSession(session);
593             }
594         }
595 
596         return list;
597     }
598 
599     public MBMailingList findByUuid_First(String uuid, OrderByComparator obc)
600         throws NoSuchMailingListException, SystemException {
601         List<MBMailingList> list = findByUuid(uuid, 0, 1, obc);
602 
603         if (list.isEmpty()) {
604             StringBundler msg = new StringBundler(4);
605 
606             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
607 
608             msg.append("uuid=");
609             msg.append(uuid);
610 
611             msg.append(StringPool.CLOSE_CURLY_BRACE);
612 
613             throw new NoSuchMailingListException(msg.toString());
614         }
615         else {
616             return list.get(0);
617         }
618     }
619 
620     public MBMailingList findByUuid_Last(String uuid, OrderByComparator obc)
621         throws NoSuchMailingListException, SystemException {
622         int count = countByUuid(uuid);
623 
624         List<MBMailingList> list = findByUuid(uuid, count - 1, count, obc);
625 
626         if (list.isEmpty()) {
627             StringBundler msg = new StringBundler(4);
628 
629             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
630 
631             msg.append("uuid=");
632             msg.append(uuid);
633 
634             msg.append(StringPool.CLOSE_CURLY_BRACE);
635 
636             throw new NoSuchMailingListException(msg.toString());
637         }
638         else {
639             return list.get(0);
640         }
641     }
642 
643     public MBMailingList[] findByUuid_PrevAndNext(long mailingListId,
644         String uuid, OrderByComparator obc)
645         throws NoSuchMailingListException, SystemException {
646         MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
647 
648         int count = countByUuid(uuid);
649 
650         Session session = null;
651 
652         try {
653             session = openSession();
654 
655             StringBundler query = null;
656 
657             if (obc != null) {
658                 query = new StringBundler(3 +
659                         (obc.getOrderByFields().length * 3));
660             }
661             else {
662                 query = new StringBundler(2);
663             }
664 
665             query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
666 
667             if (uuid == null) {
668                 query.append(_FINDER_COLUMN_UUID_UUID_1);
669             }
670             else {
671                 if (uuid.equals(StringPool.BLANK)) {
672                     query.append(_FINDER_COLUMN_UUID_UUID_3);
673                 }
674                 else {
675                     query.append(_FINDER_COLUMN_UUID_UUID_2);
676                 }
677             }
678 
679             if (obc != null) {
680                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
681             }
682 
683             String sql = query.toString();
684 
685             Query q = session.createQuery(sql);
686 
687             QueryPos qPos = QueryPos.getInstance(q);
688 
689             if (uuid != null) {
690                 qPos.add(uuid);
691             }
692 
693             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
694                     mbMailingList);
695 
696             MBMailingList[] array = new MBMailingListImpl[3];
697 
698             array[0] = (MBMailingList)objArray[0];
699             array[1] = (MBMailingList)objArray[1];
700             array[2] = (MBMailingList)objArray[2];
701 
702             return array;
703         }
704         catch (Exception e) {
705             throw processException(e);
706         }
707         finally {
708             closeSession(session);
709         }
710     }
711 
712     public MBMailingList findByUUID_G(String uuid, long groupId)
713         throws NoSuchMailingListException, SystemException {
714         MBMailingList mbMailingList = fetchByUUID_G(uuid, groupId);
715 
716         if (mbMailingList == null) {
717             StringBundler msg = new StringBundler(6);
718 
719             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
720 
721             msg.append("uuid=");
722             msg.append(uuid);
723 
724             msg.append(", groupId=");
725             msg.append(groupId);
726 
727             msg.append(StringPool.CLOSE_CURLY_BRACE);
728 
729             if (_log.isWarnEnabled()) {
730                 _log.warn(msg.toString());
731             }
732 
733             throw new NoSuchMailingListException(msg.toString());
734         }
735 
736         return mbMailingList;
737     }
738 
739     public MBMailingList fetchByUUID_G(String uuid, long groupId)
740         throws SystemException {
741         return fetchByUUID_G(uuid, groupId, true);
742     }
743 
744     public MBMailingList fetchByUUID_G(String uuid, long groupId,
745         boolean retrieveFromCache) throws SystemException {
746         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
747 
748         Object result = null;
749 
750         if (retrieveFromCache) {
751             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
752                     finderArgs, this);
753         }
754 
755         if (result == null) {
756             Session session = null;
757 
758             try {
759                 session = openSession();
760 
761                 StringBundler query = new StringBundler(3);
762 
763                 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
764 
765                 if (uuid == null) {
766                     query.append(_FINDER_COLUMN_UUID_G_UUID_1);
767                 }
768                 else {
769                     if (uuid.equals(StringPool.BLANK)) {
770                         query.append(_FINDER_COLUMN_UUID_G_UUID_3);
771                     }
772                     else {
773                         query.append(_FINDER_COLUMN_UUID_G_UUID_2);
774                     }
775                 }
776 
777                 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
778 
779                 String sql = query.toString();
780 
781                 Query q = session.createQuery(sql);
782 
783                 QueryPos qPos = QueryPos.getInstance(q);
784 
785                 if (uuid != null) {
786                     qPos.add(uuid);
787                 }
788 
789                 qPos.add(groupId);
790 
791                 List<MBMailingList> list = q.list();
792 
793                 result = list;
794 
795                 MBMailingList mbMailingList = null;
796 
797                 if (list.isEmpty()) {
798                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
799                         finderArgs, list);
800                 }
801                 else {
802                     mbMailingList = list.get(0);
803 
804                     cacheResult(mbMailingList);
805 
806                     if ((mbMailingList.getUuid() == null) ||
807                             !mbMailingList.getUuid().equals(uuid) ||
808                             (mbMailingList.getGroupId() != groupId)) {
809                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
810                             finderArgs, mbMailingList);
811                     }
812                 }
813 
814                 return mbMailingList;
815             }
816             catch (Exception e) {
817                 throw processException(e);
818             }
819             finally {
820                 if (result == null) {
821                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
822                         finderArgs, new ArrayList<MBMailingList>());
823                 }
824 
825                 closeSession(session);
826             }
827         }
828         else {
829             if (result instanceof List<?>) {
830                 return null;
831             }
832             else {
833                 return (MBMailingList)result;
834             }
835         }
836     }
837 
838     public List<MBMailingList> findByActive(boolean active)
839         throws SystemException {
840         Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
841 
842         List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ACTIVE,
843                 finderArgs, this);
844 
845         if (list == null) {
846             Session session = null;
847 
848             try {
849                 session = openSession();
850 
851                 StringBundler query = new StringBundler(2);
852 
853                 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
854 
855                 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
856 
857                 String sql = query.toString();
858 
859                 Query q = session.createQuery(sql);
860 
861                 QueryPos qPos = QueryPos.getInstance(q);
862 
863                 qPos.add(active);
864 
865                 list = q.list();
866             }
867             catch (Exception e) {
868                 throw processException(e);
869             }
870             finally {
871                 if (list == null) {
872                     list = new ArrayList<MBMailingList>();
873                 }
874 
875                 cacheResult(list);
876 
877                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ACTIVE,
878                     finderArgs, list);
879 
880                 closeSession(session);
881             }
882         }
883 
884         return list;
885     }
886 
887     public List<MBMailingList> findByActive(boolean active, int start, int end)
888         throws SystemException {
889         return findByActive(active, start, end, null);
890     }
891 
892     public List<MBMailingList> findByActive(boolean active, int start, int end,
893         OrderByComparator obc) throws SystemException {
894         Object[] finderArgs = new Object[] {
895                 Boolean.valueOf(active),
896                 
897                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
898             };
899 
900         List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ACTIVE,
901                 finderArgs, this);
902 
903         if (list == null) {
904             Session session = null;
905 
906             try {
907                 session = openSession();
908 
909                 StringBundler query = null;
910 
911                 if (obc != null) {
912                     query = new StringBundler(3 +
913                             (obc.getOrderByFields().length * 3));
914                 }
915                 else {
916                     query = new StringBundler(2);
917                 }
918 
919                 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
920 
921                 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
922 
923                 if (obc != null) {
924                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
925                 }
926 
927                 String sql = query.toString();
928 
929                 Query q = session.createQuery(sql);
930 
931                 QueryPos qPos = QueryPos.getInstance(q);
932 
933                 qPos.add(active);
934 
935                 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
936                         start, end);
937             }
938             catch (Exception e) {
939                 throw processException(e);
940             }
941             finally {
942                 if (list == null) {
943                     list = new ArrayList<MBMailingList>();
944                 }
945 
946                 cacheResult(list);
947 
948                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ACTIVE,
949                     finderArgs, list);
950 
951                 closeSession(session);
952             }
953         }
954 
955         return list;
956     }
957 
958     public MBMailingList findByActive_First(boolean active,
959         OrderByComparator obc)
960         throws NoSuchMailingListException, SystemException {
961         List<MBMailingList> list = findByActive(active, 0, 1, obc);
962 
963         if (list.isEmpty()) {
964             StringBundler msg = new StringBundler(4);
965 
966             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
967 
968             msg.append("active=");
969             msg.append(active);
970 
971             msg.append(StringPool.CLOSE_CURLY_BRACE);
972 
973             throw new NoSuchMailingListException(msg.toString());
974         }
975         else {
976             return list.get(0);
977         }
978     }
979 
980     public MBMailingList findByActive_Last(boolean active, OrderByComparator obc)
981         throws NoSuchMailingListException, SystemException {
982         int count = countByActive(active);
983 
984         List<MBMailingList> list = findByActive(active, count - 1, count, obc);
985 
986         if (list.isEmpty()) {
987             StringBundler msg = new StringBundler(4);
988 
989             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
990 
991             msg.append("active=");
992             msg.append(active);
993 
994             msg.append(StringPool.CLOSE_CURLY_BRACE);
995 
996             throw new NoSuchMailingListException(msg.toString());
997         }
998         else {
999             return list.get(0);
1000        }
1001    }
1002
1003    public MBMailingList[] findByActive_PrevAndNext(long mailingListId,
1004        boolean active, OrderByComparator obc)
1005        throws NoSuchMailingListException, SystemException {
1006        MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
1007
1008        int count = countByActive(active);
1009
1010        Session session = null;
1011
1012        try {
1013            session = openSession();
1014
1015            StringBundler query = null;
1016
1017            if (obc != null) {
1018                query = new StringBundler(3 +
1019                        (obc.getOrderByFields().length * 3));
1020            }
1021            else {
1022                query = new StringBundler(2);
1023            }
1024
1025            query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1026
1027            query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1028
1029            if (obc != null) {
1030                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1031            }
1032
1033            String sql = query.toString();
1034
1035            Query q = session.createQuery(sql);
1036
1037            QueryPos qPos = QueryPos.getInstance(q);
1038
1039            qPos.add(active);
1040
1041            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1042                    mbMailingList);
1043
1044            MBMailingList[] array = new MBMailingListImpl[3];
1045
1046            array[0] = (MBMailingList)objArray[0];
1047            array[1] = (MBMailingList)objArray[1];
1048            array[2] = (MBMailingList)objArray[2];
1049
1050            return array;
1051        }
1052        catch (Exception e) {
1053            throw processException(e);
1054        }
1055        finally {
1056            closeSession(session);
1057        }
1058    }
1059
1060    public MBMailingList findByG_C(long groupId, long categoryId)
1061        throws NoSuchMailingListException, SystemException {
1062        MBMailingList mbMailingList = fetchByG_C(groupId, categoryId);
1063
1064        if (mbMailingList == null) {
1065            StringBundler msg = new StringBundler(6);
1066
1067            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1068
1069            msg.append("groupId=");
1070            msg.append(groupId);
1071
1072            msg.append(", categoryId=");
1073            msg.append(categoryId);
1074
1075            msg.append(StringPool.CLOSE_CURLY_BRACE);
1076
1077            if (_log.isWarnEnabled()) {
1078                _log.warn(msg.toString());
1079            }
1080
1081            throw new NoSuchMailingListException(msg.toString());
1082        }
1083
1084        return mbMailingList;
1085    }
1086
1087    public MBMailingList fetchByG_C(long groupId, long categoryId)
1088        throws SystemException {
1089        return fetchByG_C(groupId, categoryId, true);
1090    }
1091
1092    public MBMailingList fetchByG_C(long groupId, long categoryId,
1093        boolean retrieveFromCache) throws SystemException {
1094        Object[] finderArgs = new Object[] {
1095                new Long(groupId), new Long(categoryId)
1096            };
1097
1098        Object result = null;
1099
1100        if (retrieveFromCache) {
1101            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C,
1102                    finderArgs, this);
1103        }
1104
1105        if (result == null) {
1106            Session session = null;
1107
1108            try {
1109                session = openSession();
1110
1111                StringBundler query = new StringBundler(3);
1112
1113                query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1114
1115                query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1116
1117                query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1118
1119                String sql = query.toString();
1120
1121                Query q = session.createQuery(sql);
1122
1123                QueryPos qPos = QueryPos.getInstance(q);
1124
1125                qPos.add(groupId);
1126
1127                qPos.add(categoryId);
1128
1129                List<MBMailingList> list = q.list();
1130
1131                result = list;
1132
1133                MBMailingList mbMailingList = null;
1134
1135                if (list.isEmpty()) {
1136                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
1137                        finderArgs, list);
1138                }
1139                else {
1140                    mbMailingList = list.get(0);
1141
1142                    cacheResult(mbMailingList);
1143
1144                    if ((mbMailingList.getGroupId() != groupId) ||
1145                            (mbMailingList.getCategoryId() != categoryId)) {
1146                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
1147                            finderArgs, mbMailingList);
1148                    }
1149                }
1150
1151                return mbMailingList;
1152            }
1153            catch (Exception e) {
1154                throw processException(e);
1155            }
1156            finally {
1157                if (result == null) {
1158                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C,
1159                        finderArgs, new ArrayList<MBMailingList>());
1160                }
1161
1162                closeSession(session);
1163            }
1164        }
1165        else {
1166            if (result instanceof List<?>) {
1167                return null;
1168            }
1169            else {
1170                return (MBMailingList)result;
1171            }
1172        }
1173    }
1174
1175    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1176        throws SystemException {
1177        Session session = null;
1178
1179        try {
1180            session = openSession();
1181
1182            dynamicQuery.compile(session);
1183
1184            return dynamicQuery.list();
1185        }
1186        catch (Exception e) {
1187            throw processException(e);
1188        }
1189        finally {
1190            closeSession(session);
1191        }
1192    }
1193
1194    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1195        int start, int end) throws SystemException {
1196        Session session = null;
1197
1198        try {
1199            session = openSession();
1200
1201            dynamicQuery.setLimit(start, end);
1202
1203            dynamicQuery.compile(session);
1204
1205            return dynamicQuery.list();
1206        }
1207        catch (Exception e) {
1208            throw processException(e);
1209        }
1210        finally {
1211            closeSession(session);
1212        }
1213    }
1214
1215    public List<MBMailingList> findAll() throws SystemException {
1216        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1217    }
1218
1219    public List<MBMailingList> findAll(int start, int end)
1220        throws SystemException {
1221        return findAll(start, end, null);
1222    }
1223
1224    public List<MBMailingList> findAll(int start, int end, OrderByComparator obc)
1225        throws SystemException {
1226        Object[] finderArgs = new Object[] {
1227                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1228            };
1229
1230        List<MBMailingList> list = (List<MBMailingList>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1231                finderArgs, this);
1232
1233        if (list == null) {
1234            Session session = null;
1235
1236            try {
1237                session = openSession();
1238
1239                StringBundler query = null;
1240                String sql = null;
1241
1242                if (obc != null) {
1243                    query = new StringBundler(2 +
1244                            (obc.getOrderByFields().length * 3));
1245
1246                    query.append(_SQL_SELECT_MBMAILINGLIST);
1247
1248                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1249
1250                    sql = query.toString();
1251                }
1252
1253                sql = _SQL_SELECT_MBMAILINGLIST;
1254
1255                Query q = session.createQuery(sql);
1256
1257                if (obc == null) {
1258                    list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1259                            start, end, false);
1260
1261                    Collections.sort(list);
1262                }
1263                else {
1264                    list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1265                            start, end);
1266                }
1267            }
1268            catch (Exception e) {
1269                throw processException(e);
1270            }
1271            finally {
1272                if (list == null) {
1273                    list = new ArrayList<MBMailingList>();
1274                }
1275
1276                cacheResult(list);
1277
1278                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1279
1280                closeSession(session);
1281            }
1282        }
1283
1284        return list;
1285    }
1286
1287    public void removeByUuid(String uuid) throws SystemException {
1288        for (MBMailingList mbMailingList : findByUuid(uuid)) {
1289            remove(mbMailingList);
1290        }
1291    }
1292
1293    public void removeByUUID_G(String uuid, long groupId)
1294        throws NoSuchMailingListException, SystemException {
1295        MBMailingList mbMailingList = findByUUID_G(uuid, groupId);
1296
1297        remove(mbMailingList);
1298    }
1299
1300    public void removeByActive(boolean active) throws SystemException {
1301        for (MBMailingList mbMailingList : findByActive(active)) {
1302            remove(mbMailingList);
1303        }
1304    }
1305
1306    public void removeByG_C(long groupId, long categoryId)
1307        throws NoSuchMailingListException, SystemException {
1308        MBMailingList mbMailingList = findByG_C(groupId, categoryId);
1309
1310        remove(mbMailingList);
1311    }
1312
1313    public void removeAll() throws SystemException {
1314        for (MBMailingList mbMailingList : findAll()) {
1315            remove(mbMailingList);
1316        }
1317    }
1318
1319    public int countByUuid(String uuid) throws SystemException {
1320        Object[] finderArgs = new Object[] { uuid };
1321
1322        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1323                finderArgs, this);
1324
1325        if (count == null) {
1326            Session session = null;
1327
1328            try {
1329                session = openSession();
1330
1331                StringBundler query = new StringBundler(2);
1332
1333                query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1334
1335                if (uuid == null) {
1336                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1337                }
1338                else {
1339                    if (uuid.equals(StringPool.BLANK)) {
1340                        query.append(_FINDER_COLUMN_UUID_UUID_3);
1341                    }
1342                    else {
1343                        query.append(_FINDER_COLUMN_UUID_UUID_2);
1344                    }
1345                }
1346
1347                String sql = query.toString();
1348
1349                Query q = session.createQuery(sql);
1350
1351                QueryPos qPos = QueryPos.getInstance(q);
1352
1353                if (uuid != null) {
1354                    qPos.add(uuid);
1355                }
1356
1357                count = (Long)q.uniqueResult();
1358            }
1359            catch (Exception e) {
1360                throw processException(e);
1361            }
1362            finally {
1363                if (count == null) {
1364                    count = Long.valueOf(0);
1365                }
1366
1367                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1368                    finderArgs, count);
1369
1370                closeSession(session);
1371            }
1372        }
1373
1374        return count.intValue();
1375    }
1376
1377    public int countByUUID_G(String uuid, long groupId)
1378        throws SystemException {
1379        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1380
1381        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1382                finderArgs, this);
1383
1384        if (count == null) {
1385            Session session = null;
1386
1387            try {
1388                session = openSession();
1389
1390                StringBundler query = new StringBundler(3);
1391
1392                query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1393
1394                if (uuid == null) {
1395                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1396                }
1397                else {
1398                    if (uuid.equals(StringPool.BLANK)) {
1399                        query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1400                    }
1401                    else {
1402                        query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1403                    }
1404                }
1405
1406                query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1407
1408                String sql = query.toString();
1409
1410                Query q = session.createQuery(sql);
1411
1412                QueryPos qPos = QueryPos.getInstance(q);
1413
1414                if (uuid != null) {
1415                    qPos.add(uuid);
1416                }
1417
1418                qPos.add(groupId);
1419
1420                count = (Long)q.uniqueResult();
1421            }
1422            catch (Exception e) {
1423                throw processException(e);
1424            }
1425            finally {
1426                if (count == null) {
1427                    count = Long.valueOf(0);
1428                }
1429
1430                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1431                    finderArgs, count);
1432
1433                closeSession(session);
1434            }
1435        }
1436
1437        return count.intValue();
1438    }
1439
1440    public int countByActive(boolean active) throws SystemException {
1441        Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
1442
1443        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ACTIVE,
1444                finderArgs, this);
1445
1446        if (count == null) {
1447            Session session = null;
1448
1449            try {
1450                session = openSession();
1451
1452                StringBundler query = new StringBundler(2);
1453
1454                query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1455
1456                query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1457
1458                String sql = query.toString();
1459
1460                Query q = session.createQuery(sql);
1461
1462                QueryPos qPos = QueryPos.getInstance(q);
1463
1464                qPos.add(active);
1465
1466                count = (Long)q.uniqueResult();
1467            }
1468            catch (Exception e) {
1469                throw processException(e);
1470            }
1471            finally {
1472                if (count == null) {
1473                    count = Long.valueOf(0);
1474                }
1475
1476                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ACTIVE,
1477                    finderArgs, count);
1478
1479                closeSession(session);
1480            }
1481        }
1482
1483        return count.intValue();
1484    }
1485
1486    public int countByG_C(long groupId, long categoryId)
1487        throws SystemException {
1488        Object[] finderArgs = new Object[] {
1489                new Long(groupId), new Long(categoryId)
1490            };
1491
1492        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
1493                finderArgs, this);
1494
1495        if (count == null) {
1496            Session session = null;
1497
1498            try {
1499                session = openSession();
1500
1501                StringBundler query = new StringBundler(3);
1502
1503                query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1504
1505                query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1506
1507                query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1508
1509                String sql = query.toString();
1510
1511                Query q = session.createQuery(sql);
1512
1513                QueryPos qPos = QueryPos.getInstance(q);
1514
1515                qPos.add(groupId);
1516
1517                qPos.add(categoryId);
1518
1519                count = (Long)q.uniqueResult();
1520            }
1521            catch (Exception e) {
1522                throw processException(e);
1523            }
1524            finally {
1525                if (count == null) {
1526                    count = Long.valueOf(0);
1527                }
1528
1529                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
1530                    count);
1531
1532                closeSession(session);
1533            }
1534        }
1535
1536        return count.intValue();
1537    }
1538
1539    public int countAll() throws SystemException {
1540        Object[] finderArgs = new Object[0];
1541
1542        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1543                finderArgs, this);
1544
1545        if (count == null) {
1546            Session session = null;
1547
1548            try {
1549                session = openSession();
1550
1551                Query q = session.createQuery(_SQL_COUNT_MBMAILINGLIST);
1552
1553                count = (Long)q.uniqueResult();
1554            }
1555            catch (Exception e) {
1556                throw processException(e);
1557            }
1558            finally {
1559                if (count == null) {
1560                    count = Long.valueOf(0);
1561                }
1562
1563                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1564                    count);
1565
1566                closeSession(session);
1567            }
1568        }
1569
1570        return count.intValue();
1571    }
1572
1573    public void afterPropertiesSet() {
1574        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1575                    com.liferay.portal.util.PropsUtil.get(
1576                        "value.object.listener.com.liferay.portlet.messageboards.model.MBMailingList")));
1577
1578        if (listenerClassNames.length > 0) {
1579            try {
1580                List<ModelListener<MBMailingList>> listenersList = new ArrayList<ModelListener<MBMailingList>>();
1581
1582                for (String listenerClassName : listenerClassNames) {
1583                    listenersList.add((ModelListener<MBMailingList>)Class.forName(
1584                            listenerClassName).newInstance());
1585                }
1586
1587                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1588            }
1589            catch (Exception e) {
1590                _log.error(e);
1591            }
1592        }
1593    }
1594
1595    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBBanPersistence")
1596    protected com.liferay.portlet.messageboards.service.persistence.MBBanPersistence mbBanPersistence;
1597    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence")
1598    protected com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence mbCategoryPersistence;
1599    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence")
1600    protected com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence mbDiscussionPersistence;
1601    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMailingListPersistence")
1602    protected com.liferay.portlet.messageboards.service.persistence.MBMailingListPersistence mbMailingListPersistence;
1603    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence")
1604    protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
1605    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessageFlagPersistence")
1606    protected com.liferay.portlet.messageboards.service.persistence.MBMessageFlagPersistence mbMessageFlagPersistence;
1607    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence")
1608    protected com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence mbStatsUserPersistence;
1609    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBThreadPersistence")
1610    protected com.liferay.portlet.messageboards.service.persistence.MBThreadPersistence mbThreadPersistence;
1611    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1612    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1613    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1614    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1615    private static final String _SQL_SELECT_MBMAILINGLIST = "SELECT mbMailingList FROM MBMailingList mbMailingList";
1616    private static final String _SQL_SELECT_MBMAILINGLIST_WHERE = "SELECT mbMailingList FROM MBMailingList mbMailingList WHERE ";
1617    private static final String _SQL_COUNT_MBMAILINGLIST = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList";
1618    private static final String _SQL_COUNT_MBMAILINGLIST_WHERE = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList WHERE ";
1619    private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMailingList.uuid IS NULL";
1620    private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMailingList.uuid = ?";
1621    private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = ?)";
1622    private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMailingList.uuid IS NULL AND ";
1623    private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMailingList.uuid = ? AND ";
1624    private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = ?) AND ";
1625    private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMailingList.groupId = ?";
1626    private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "mbMailingList.active = ?";
1627    private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMailingList.groupId = ? AND ";
1628    private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMailingList.categoryId = ?";
1629    private static final String _ORDER_BY_ENTITY_ALIAS = "mbMailingList.";
1630    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMailingList exists with the primary key ";
1631    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMailingList exists with the key {";
1632    private static Log _log = LogFactoryUtil.getLog(MBMailingListPersistenceImpl.class);
1633}