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