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