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