1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.blogs.service.persistence;
21  
22  import com.liferay.portal.SystemException;
23  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
24  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
25  import com.liferay.portal.kernel.dao.orm.Query;
26  import com.liferay.portal.kernel.dao.orm.QueryPos;
27  import com.liferay.portal.kernel.dao.orm.QueryUtil;
28  import com.liferay.portal.kernel.dao.orm.Session;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.CalendarUtil;
32  import com.liferay.portal.kernel.util.GetterUtil;
33  import com.liferay.portal.kernel.util.OrderByComparator;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.kernel.util.Validator;
37  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
38  import com.liferay.portal.model.ModelListener;
39  import com.liferay.portal.service.persistence.BatchSessionUtil;
40  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41  
42  import com.liferay.portlet.blogs.NoSuchEntryException;
43  import com.liferay.portlet.blogs.model.BlogsEntry;
44  import com.liferay.portlet.blogs.model.impl.BlogsEntryImpl;
45  import com.liferay.portlet.blogs.model.impl.BlogsEntryModelImpl;
46  
47  import java.util.ArrayList;
48  import java.util.Collections;
49  import java.util.Date;
50  import java.util.Iterator;
51  import java.util.List;
52  
53  /**
54   * <a href="BlogsEntryPersistenceImpl.java.html"><b><i>View Source</i></b></a>
55   *
56   * @author Brian Wing Shun Chan
57   *
58   */
59  public class BlogsEntryPersistenceImpl extends BasePersistenceImpl
60      implements BlogsEntryPersistence {
61      public BlogsEntry create(long entryId) {
62          BlogsEntry blogsEntry = new BlogsEntryImpl();
63  
64          blogsEntry.setNew(true);
65          blogsEntry.setPrimaryKey(entryId);
66  
67          String uuid = PortalUUIDUtil.generate();
68  
69          blogsEntry.setUuid(uuid);
70  
71          return blogsEntry;
72      }
73  
74      public BlogsEntry remove(long entryId)
75          throws NoSuchEntryException, SystemException {
76          Session session = null;
77  
78          try {
79              session = openSession();
80  
81              BlogsEntry blogsEntry = (BlogsEntry)session.get(BlogsEntryImpl.class,
82                      new Long(entryId));
83  
84              if (blogsEntry == null) {
85                  if (_log.isWarnEnabled()) {
86                      _log.warn("No BlogsEntry exists with the primary key " +
87                          entryId);
88                  }
89  
90                  throw new NoSuchEntryException(
91                      "No BlogsEntry exists with the primary key " + entryId);
92              }
93  
94              return remove(blogsEntry);
95          }
96          catch (NoSuchEntryException nsee) {
97              throw nsee;
98          }
99          catch (Exception e) {
100             throw processException(e);
101         }
102         finally {
103             closeSession(session);
104         }
105     }
106 
107     public BlogsEntry remove(BlogsEntry blogsEntry) throws SystemException {
108         for (ModelListener listener : listeners) {
109             listener.onBeforeRemove(blogsEntry);
110         }
111 
112         blogsEntry = removeImpl(blogsEntry);
113 
114         for (ModelListener listener : listeners) {
115             listener.onAfterRemove(blogsEntry);
116         }
117 
118         return blogsEntry;
119     }
120 
121     protected BlogsEntry removeImpl(BlogsEntry blogsEntry)
122         throws SystemException {
123         Session session = null;
124 
125         try {
126             session = openSession();
127 
128             if (BatchSessionUtil.isEnabled()) {
129                 Object staleObject = session.get(BlogsEntryImpl.class,
130                         blogsEntry.getPrimaryKeyObj());
131 
132                 if (staleObject != null) {
133                     session.evict(staleObject);
134                 }
135             }
136 
137             session.delete(blogsEntry);
138 
139             session.flush();
140 
141             return blogsEntry;
142         }
143         catch (Exception e) {
144             throw processException(e);
145         }
146         finally {
147             closeSession(session);
148 
149             FinderCacheUtil.clearCache(BlogsEntry.class.getName());
150         }
151     }
152 
153     /**
154      * @deprecated Use <code>update(BlogsEntry blogsEntry, boolean merge)</code>.
155      */
156     public BlogsEntry update(BlogsEntry blogsEntry) throws SystemException {
157         if (_log.isWarnEnabled()) {
158             _log.warn(
159                 "Using the deprecated update(BlogsEntry blogsEntry) method. Use update(BlogsEntry blogsEntry, boolean merge) instead.");
160         }
161 
162         return update(blogsEntry, false);
163     }
164 
165     /**
166      * Add, update, or merge, the entity. This method also calls the model
167      * listeners to trigger the proper events associated with adding, deleting,
168      * or updating an entity.
169      *
170      * @param        blogsEntry the entity to add, update, or merge
171      * @param        merge boolean value for whether to merge the entity. The
172      *                default value is false. Setting merge to true is more
173      *                expensive and should only be true when blogsEntry is
174      *                transient. See LEP-5473 for a detailed discussion of this
175      *                method.
176      * @return        true if the portlet can be displayed via Ajax
177      */
178     public BlogsEntry update(BlogsEntry blogsEntry, boolean merge)
179         throws SystemException {
180         boolean isNew = blogsEntry.isNew();
181 
182         for (ModelListener listener : listeners) {
183             if (isNew) {
184                 listener.onBeforeCreate(blogsEntry);
185             }
186             else {
187                 listener.onBeforeUpdate(blogsEntry);
188             }
189         }
190 
191         blogsEntry = updateImpl(blogsEntry, merge);
192 
193         for (ModelListener listener : listeners) {
194             if (isNew) {
195                 listener.onAfterCreate(blogsEntry);
196             }
197             else {
198                 listener.onAfterUpdate(blogsEntry);
199             }
200         }
201 
202         return blogsEntry;
203     }
204 
205     public BlogsEntry updateImpl(
206         com.liferay.portlet.blogs.model.BlogsEntry blogsEntry, boolean merge)
207         throws SystemException {
208         if (Validator.isNull(blogsEntry.getUuid())) {
209             String uuid = PortalUUIDUtil.generate();
210 
211             blogsEntry.setUuid(uuid);
212         }
213 
214         Session session = null;
215 
216         try {
217             session = openSession();
218 
219             BatchSessionUtil.update(session, blogsEntry, merge);
220 
221             blogsEntry.setNew(false);
222 
223             return blogsEntry;
224         }
225         catch (Exception e) {
226             throw processException(e);
227         }
228         finally {
229             closeSession(session);
230 
231             FinderCacheUtil.clearCache(BlogsEntry.class.getName());
232         }
233     }
234 
235     public BlogsEntry findByPrimaryKey(long entryId)
236         throws NoSuchEntryException, SystemException {
237         BlogsEntry blogsEntry = fetchByPrimaryKey(entryId);
238 
239         if (blogsEntry == null) {
240             if (_log.isWarnEnabled()) {
241                 _log.warn("No BlogsEntry exists with the primary key " +
242                     entryId);
243             }
244 
245             throw new NoSuchEntryException(
246                 "No BlogsEntry exists with the primary key " + entryId);
247         }
248 
249         return blogsEntry;
250     }
251 
252     public BlogsEntry fetchByPrimaryKey(long entryId) throws SystemException {
253         Session session = null;
254 
255         try {
256             session = openSession();
257 
258             return (BlogsEntry)session.get(BlogsEntryImpl.class,
259                 new Long(entryId));
260         }
261         catch (Exception e) {
262             throw processException(e);
263         }
264         finally {
265             closeSession(session);
266         }
267     }
268 
269     public List<BlogsEntry> findByUuid(String uuid) throws SystemException {
270         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
271         String finderClassName = BlogsEntry.class.getName();
272         String finderMethodName = "findByUuid";
273         String[] finderParams = new String[] { String.class.getName() };
274         Object[] finderArgs = new Object[] { uuid };
275 
276         Object result = null;
277 
278         if (finderClassNameCacheEnabled) {
279             result = FinderCacheUtil.getResult(finderClassName,
280                     finderMethodName, finderParams, finderArgs, this);
281         }
282 
283         if (result == null) {
284             Session session = null;
285 
286             try {
287                 session = openSession();
288 
289                 StringBuilder query = new StringBuilder();
290 
291                 query.append(
292                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
293 
294                 if (uuid == null) {
295                     query.append("uuid_ IS NULL");
296                 }
297                 else {
298                     query.append("uuid_ = ?");
299                 }
300 
301                 query.append(" ");
302 
303                 query.append("ORDER BY ");
304 
305                 query.append("displayDate DESC");
306 
307                 Query q = session.createQuery(query.toString());
308 
309                 QueryPos qPos = QueryPos.getInstance(q);
310 
311                 if (uuid != null) {
312                     qPos.add(uuid);
313                 }
314 
315                 List<BlogsEntry> list = q.list();
316 
317                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
318                     finderClassName, finderMethodName, finderParams,
319                     finderArgs, list);
320 
321                 return list;
322             }
323             catch (Exception e) {
324                 throw processException(e);
325             }
326             finally {
327                 closeSession(session);
328             }
329         }
330         else {
331             return (List<BlogsEntry>)result;
332         }
333     }
334 
335     public List<BlogsEntry> findByUuid(String uuid, int start, int end)
336         throws SystemException {
337         return findByUuid(uuid, start, end, null);
338     }
339 
340     public List<BlogsEntry> findByUuid(String uuid, int start, int end,
341         OrderByComparator obc) throws SystemException {
342         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
343         String finderClassName = BlogsEntry.class.getName();
344         String finderMethodName = "findByUuid";
345         String[] finderParams = new String[] {
346                 String.class.getName(),
347                 
348                 "java.lang.Integer", "java.lang.Integer",
349                 "com.liferay.portal.kernel.util.OrderByComparator"
350             };
351         Object[] finderArgs = new Object[] {
352                 uuid,
353                 
354                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
355             };
356 
357         Object result = null;
358 
359         if (finderClassNameCacheEnabled) {
360             result = FinderCacheUtil.getResult(finderClassName,
361                     finderMethodName, finderParams, finderArgs, this);
362         }
363 
364         if (result == null) {
365             Session session = null;
366 
367             try {
368                 session = openSession();
369 
370                 StringBuilder query = new StringBuilder();
371 
372                 query.append(
373                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
374 
375                 if (uuid == null) {
376                     query.append("uuid_ IS NULL");
377                 }
378                 else {
379                     query.append("uuid_ = ?");
380                 }
381 
382                 query.append(" ");
383 
384                 if (obc != null) {
385                     query.append("ORDER BY ");
386                     query.append(obc.getOrderBy());
387                 }
388 
389                 else {
390                     query.append("ORDER BY ");
391 
392                     query.append("displayDate DESC");
393                 }
394 
395                 Query q = session.createQuery(query.toString());
396 
397                 QueryPos qPos = QueryPos.getInstance(q);
398 
399                 if (uuid != null) {
400                     qPos.add(uuid);
401                 }
402 
403                 List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
404                         getDialect(), start, end);
405 
406                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
407                     finderClassName, finderMethodName, finderParams,
408                     finderArgs, list);
409 
410                 return list;
411             }
412             catch (Exception e) {
413                 throw processException(e);
414             }
415             finally {
416                 closeSession(session);
417             }
418         }
419         else {
420             return (List<BlogsEntry>)result;
421         }
422     }
423 
424     public BlogsEntry findByUuid_First(String uuid, OrderByComparator obc)
425         throws NoSuchEntryException, SystemException {
426         List<BlogsEntry> list = findByUuid(uuid, 0, 1, obc);
427 
428         if (list.size() == 0) {
429             StringBuilder msg = new StringBuilder();
430 
431             msg.append("No BlogsEntry exists with the key {");
432 
433             msg.append("uuid=" + uuid);
434 
435             msg.append(StringPool.CLOSE_CURLY_BRACE);
436 
437             throw new NoSuchEntryException(msg.toString());
438         }
439         else {
440             return list.get(0);
441         }
442     }
443 
444     public BlogsEntry findByUuid_Last(String uuid, OrderByComparator obc)
445         throws NoSuchEntryException, SystemException {
446         int count = countByUuid(uuid);
447 
448         List<BlogsEntry> list = findByUuid(uuid, count - 1, count, obc);
449 
450         if (list.size() == 0) {
451             StringBuilder msg = new StringBuilder();
452 
453             msg.append("No BlogsEntry exists with the key {");
454 
455             msg.append("uuid=" + uuid);
456 
457             msg.append(StringPool.CLOSE_CURLY_BRACE);
458 
459             throw new NoSuchEntryException(msg.toString());
460         }
461         else {
462             return list.get(0);
463         }
464     }
465 
466     public BlogsEntry[] findByUuid_PrevAndNext(long entryId, String uuid,
467         OrderByComparator obc) throws NoSuchEntryException, SystemException {
468         BlogsEntry blogsEntry = findByPrimaryKey(entryId);
469 
470         int count = countByUuid(uuid);
471 
472         Session session = null;
473 
474         try {
475             session = openSession();
476 
477             StringBuilder query = new StringBuilder();
478 
479             query.append(
480                 "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
481 
482             if (uuid == null) {
483                 query.append("uuid_ IS NULL");
484             }
485             else {
486                 query.append("uuid_ = ?");
487             }
488 
489             query.append(" ");
490 
491             if (obc != null) {
492                 query.append("ORDER BY ");
493                 query.append(obc.getOrderBy());
494             }
495 
496             else {
497                 query.append("ORDER BY ");
498 
499                 query.append("displayDate DESC");
500             }
501 
502             Query q = session.createQuery(query.toString());
503 
504             QueryPos qPos = QueryPos.getInstance(q);
505 
506             if (uuid != null) {
507                 qPos.add(uuid);
508             }
509 
510             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
511                     blogsEntry);
512 
513             BlogsEntry[] array = new BlogsEntryImpl[3];
514 
515             array[0] = (BlogsEntry)objArray[0];
516             array[1] = (BlogsEntry)objArray[1];
517             array[2] = (BlogsEntry)objArray[2];
518 
519             return array;
520         }
521         catch (Exception e) {
522             throw processException(e);
523         }
524         finally {
525             closeSession(session);
526         }
527     }
528 
529     public BlogsEntry findByUUID_G(String uuid, long groupId)
530         throws NoSuchEntryException, SystemException {
531         BlogsEntry blogsEntry = fetchByUUID_G(uuid, groupId);
532 
533         if (blogsEntry == null) {
534             StringBuilder msg = new StringBuilder();
535 
536             msg.append("No BlogsEntry exists with the key {");
537 
538             msg.append("uuid=" + uuid);
539 
540             msg.append(", ");
541             msg.append("groupId=" + groupId);
542 
543             msg.append(StringPool.CLOSE_CURLY_BRACE);
544 
545             if (_log.isWarnEnabled()) {
546                 _log.warn(msg.toString());
547             }
548 
549             throw new NoSuchEntryException(msg.toString());
550         }
551 
552         return blogsEntry;
553     }
554 
555     public BlogsEntry fetchByUUID_G(String uuid, long groupId)
556         throws SystemException {
557         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
558         String finderClassName = BlogsEntry.class.getName();
559         String finderMethodName = "fetchByUUID_G";
560         String[] finderParams = new String[] {
561                 String.class.getName(), Long.class.getName()
562             };
563         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
564 
565         Object result = null;
566 
567         if (finderClassNameCacheEnabled) {
568             result = FinderCacheUtil.getResult(finderClassName,
569                     finderMethodName, finderParams, finderArgs, this);
570         }
571 
572         if (result == null) {
573             Session session = null;
574 
575             try {
576                 session = openSession();
577 
578                 StringBuilder query = new StringBuilder();
579 
580                 query.append(
581                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
582 
583                 if (uuid == null) {
584                     query.append("uuid_ IS NULL");
585                 }
586                 else {
587                     query.append("uuid_ = ?");
588                 }
589 
590                 query.append(" AND ");
591 
592                 query.append("groupId = ?");
593 
594                 query.append(" ");
595 
596                 query.append("ORDER BY ");
597 
598                 query.append("displayDate DESC");
599 
600                 Query q = session.createQuery(query.toString());
601 
602                 QueryPos qPos = QueryPos.getInstance(q);
603 
604                 if (uuid != null) {
605                     qPos.add(uuid);
606                 }
607 
608                 qPos.add(groupId);
609 
610                 List<BlogsEntry> list = q.list();
611 
612                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
613                     finderClassName, finderMethodName, finderParams,
614                     finderArgs, list);
615 
616                 if (list.size() == 0) {
617                     return null;
618                 }
619                 else {
620                     return list.get(0);
621                 }
622             }
623             catch (Exception e) {
624                 throw processException(e);
625             }
626             finally {
627                 closeSession(session);
628             }
629         }
630         else {
631             List<BlogsEntry> list = (List<BlogsEntry>)result;
632 
633             if (list.size() == 0) {
634                 return null;
635             }
636             else {
637                 return list.get(0);
638             }
639         }
640     }
641 
642     public List<BlogsEntry> findByGroupId(long groupId)
643         throws SystemException {
644         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
645         String finderClassName = BlogsEntry.class.getName();
646         String finderMethodName = "findByGroupId";
647         String[] finderParams = new String[] { Long.class.getName() };
648         Object[] finderArgs = new Object[] { new Long(groupId) };
649 
650         Object result = null;
651 
652         if (finderClassNameCacheEnabled) {
653             result = FinderCacheUtil.getResult(finderClassName,
654                     finderMethodName, finderParams, finderArgs, this);
655         }
656 
657         if (result == null) {
658             Session session = null;
659 
660             try {
661                 session = openSession();
662 
663                 StringBuilder query = new StringBuilder();
664 
665                 query.append(
666                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
667 
668                 query.append("groupId = ?");
669 
670                 query.append(" ");
671 
672                 query.append("ORDER BY ");
673 
674                 query.append("displayDate DESC");
675 
676                 Query q = session.createQuery(query.toString());
677 
678                 QueryPos qPos = QueryPos.getInstance(q);
679 
680                 qPos.add(groupId);
681 
682                 List<BlogsEntry> list = q.list();
683 
684                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
685                     finderClassName, finderMethodName, finderParams,
686                     finderArgs, list);
687 
688                 return list;
689             }
690             catch (Exception e) {
691                 throw processException(e);
692             }
693             finally {
694                 closeSession(session);
695             }
696         }
697         else {
698             return (List<BlogsEntry>)result;
699         }
700     }
701 
702     public List<BlogsEntry> findByGroupId(long groupId, int start, int end)
703         throws SystemException {
704         return findByGroupId(groupId, start, end, null);
705     }
706 
707     public List<BlogsEntry> findByGroupId(long groupId, int start, int end,
708         OrderByComparator obc) throws SystemException {
709         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
710         String finderClassName = BlogsEntry.class.getName();
711         String finderMethodName = "findByGroupId";
712         String[] finderParams = new String[] {
713                 Long.class.getName(),
714                 
715                 "java.lang.Integer", "java.lang.Integer",
716                 "com.liferay.portal.kernel.util.OrderByComparator"
717             };
718         Object[] finderArgs = new Object[] {
719                 new Long(groupId),
720                 
721                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
722             };
723 
724         Object result = null;
725 
726         if (finderClassNameCacheEnabled) {
727             result = FinderCacheUtil.getResult(finderClassName,
728                     finderMethodName, finderParams, finderArgs, this);
729         }
730 
731         if (result == null) {
732             Session session = null;
733 
734             try {
735                 session = openSession();
736 
737                 StringBuilder query = new StringBuilder();
738 
739                 query.append(
740                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
741 
742                 query.append("groupId = ?");
743 
744                 query.append(" ");
745 
746                 if (obc != null) {
747                     query.append("ORDER BY ");
748                     query.append(obc.getOrderBy());
749                 }
750 
751                 else {
752                     query.append("ORDER BY ");
753 
754                     query.append("displayDate DESC");
755                 }
756 
757                 Query q = session.createQuery(query.toString());
758 
759                 QueryPos qPos = QueryPos.getInstance(q);
760 
761                 qPos.add(groupId);
762 
763                 List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
764                         getDialect(), start, end);
765 
766                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
767                     finderClassName, finderMethodName, finderParams,
768                     finderArgs, list);
769 
770                 return list;
771             }
772             catch (Exception e) {
773                 throw processException(e);
774             }
775             finally {
776                 closeSession(session);
777             }
778         }
779         else {
780             return (List<BlogsEntry>)result;
781         }
782     }
783 
784     public BlogsEntry findByGroupId_First(long groupId, OrderByComparator obc)
785         throws NoSuchEntryException, SystemException {
786         List<BlogsEntry> list = findByGroupId(groupId, 0, 1, obc);
787 
788         if (list.size() == 0) {
789             StringBuilder msg = new StringBuilder();
790 
791             msg.append("No BlogsEntry exists with the key {");
792 
793             msg.append("groupId=" + groupId);
794 
795             msg.append(StringPool.CLOSE_CURLY_BRACE);
796 
797             throw new NoSuchEntryException(msg.toString());
798         }
799         else {
800             return list.get(0);
801         }
802     }
803 
804     public BlogsEntry findByGroupId_Last(long groupId, OrderByComparator obc)
805         throws NoSuchEntryException, SystemException {
806         int count = countByGroupId(groupId);
807 
808         List<BlogsEntry> list = findByGroupId(groupId, count - 1, count, obc);
809 
810         if (list.size() == 0) {
811             StringBuilder msg = new StringBuilder();
812 
813             msg.append("No BlogsEntry exists with the key {");
814 
815             msg.append("groupId=" + groupId);
816 
817             msg.append(StringPool.CLOSE_CURLY_BRACE);
818 
819             throw new NoSuchEntryException(msg.toString());
820         }
821         else {
822             return list.get(0);
823         }
824     }
825 
826     public BlogsEntry[] findByGroupId_PrevAndNext(long entryId, long groupId,
827         OrderByComparator obc) throws NoSuchEntryException, SystemException {
828         BlogsEntry blogsEntry = findByPrimaryKey(entryId);
829 
830         int count = countByGroupId(groupId);
831 
832         Session session = null;
833 
834         try {
835             session = openSession();
836 
837             StringBuilder query = new StringBuilder();
838 
839             query.append(
840                 "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
841 
842             query.append("groupId = ?");
843 
844             query.append(" ");
845 
846             if (obc != null) {
847                 query.append("ORDER BY ");
848                 query.append(obc.getOrderBy());
849             }
850 
851             else {
852                 query.append("ORDER BY ");
853 
854                 query.append("displayDate DESC");
855             }
856 
857             Query q = session.createQuery(query.toString());
858 
859             QueryPos qPos = QueryPos.getInstance(q);
860 
861             qPos.add(groupId);
862 
863             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
864                     blogsEntry);
865 
866             BlogsEntry[] array = new BlogsEntryImpl[3];
867 
868             array[0] = (BlogsEntry)objArray[0];
869             array[1] = (BlogsEntry)objArray[1];
870             array[2] = (BlogsEntry)objArray[2];
871 
872             return array;
873         }
874         catch (Exception e) {
875             throw processException(e);
876         }
877         finally {
878             closeSession(session);
879         }
880     }
881 
882     public List<BlogsEntry> findByCompanyId(long companyId)
883         throws SystemException {
884         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
885         String finderClassName = BlogsEntry.class.getName();
886         String finderMethodName = "findByCompanyId";
887         String[] finderParams = new String[] { Long.class.getName() };
888         Object[] finderArgs = new Object[] { new Long(companyId) };
889 
890         Object result = null;
891 
892         if (finderClassNameCacheEnabled) {
893             result = FinderCacheUtil.getResult(finderClassName,
894                     finderMethodName, finderParams, finderArgs, this);
895         }
896 
897         if (result == null) {
898             Session session = null;
899 
900             try {
901                 session = openSession();
902 
903                 StringBuilder query = new StringBuilder();
904 
905                 query.append(
906                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
907 
908                 query.append("companyId = ?");
909 
910                 query.append(" ");
911 
912                 query.append("ORDER BY ");
913 
914                 query.append("displayDate DESC");
915 
916                 Query q = session.createQuery(query.toString());
917 
918                 QueryPos qPos = QueryPos.getInstance(q);
919 
920                 qPos.add(companyId);
921 
922                 List<BlogsEntry> list = q.list();
923 
924                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
925                     finderClassName, finderMethodName, finderParams,
926                     finderArgs, list);
927 
928                 return list;
929             }
930             catch (Exception e) {
931                 throw processException(e);
932             }
933             finally {
934                 closeSession(session);
935             }
936         }
937         else {
938             return (List<BlogsEntry>)result;
939         }
940     }
941 
942     public List<BlogsEntry> findByCompanyId(long companyId, int start, int end)
943         throws SystemException {
944         return findByCompanyId(companyId, start, end, null);
945     }
946 
947     public List<BlogsEntry> findByCompanyId(long companyId, int start, int end,
948         OrderByComparator obc) throws SystemException {
949         boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
950         String finderClassName = BlogsEntry.class.getName();
951         String finderMethodName = "findByCompanyId";
952         String[] finderParams = new String[] {
953                 Long.class.getName(),
954                 
955                 "java.lang.Integer", "java.lang.Integer",
956                 "com.liferay.portal.kernel.util.OrderByComparator"
957             };
958         Object[] finderArgs = new Object[] {
959                 new Long(companyId),
960                 
961                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
962             };
963 
964         Object result = null;
965 
966         if (finderClassNameCacheEnabled) {
967             result = FinderCacheUtil.getResult(finderClassName,
968                     finderMethodName, finderParams, finderArgs, this);
969         }
970 
971         if (result == null) {
972             Session session = null;
973 
974             try {
975                 session = openSession();
976 
977                 StringBuilder query = new StringBuilder();
978 
979                 query.append(
980                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
981 
982                 query.append("companyId = ?");
983 
984                 query.append(" ");
985 
986                 if (obc != null) {
987                     query.append("ORDER BY ");
988                     query.append(obc.getOrderBy());
989                 }
990 
991                 else {
992                     query.append("ORDER BY ");
993 
994                     query.append("displayDate DESC");
995                 }
996 
997                 Query q = session.createQuery(query.toString());
998 
999                 QueryPos qPos = QueryPos.getInstance(q);
1000
1001                qPos.add(companyId);
1002
1003                List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
1004                        getDialect(), start, end);
1005
1006                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1007                    finderClassName, finderMethodName, finderParams,
1008                    finderArgs, list);
1009
1010                return list;
1011            }
1012            catch (Exception e) {
1013                throw processException(e);
1014            }
1015            finally {
1016                closeSession(session);
1017            }
1018        }
1019        else {
1020            return (List<BlogsEntry>)result;
1021        }
1022    }
1023
1024    public BlogsEntry findByCompanyId_First(long companyId,
1025        OrderByComparator obc) throws NoSuchEntryException, SystemException {
1026        List<BlogsEntry> list = findByCompanyId(companyId, 0, 1, obc);
1027
1028        if (list.size() == 0) {
1029            StringBuilder msg = new StringBuilder();
1030
1031            msg.append("No BlogsEntry exists with the key {");
1032
1033            msg.append("companyId=" + companyId);
1034
1035            msg.append(StringPool.CLOSE_CURLY_BRACE);
1036
1037            throw new NoSuchEntryException(msg.toString());
1038        }
1039        else {
1040            return list.get(0);
1041        }
1042    }
1043
1044    public BlogsEntry findByCompanyId_Last(long companyId, OrderByComparator obc)
1045        throws NoSuchEntryException, SystemException {
1046        int count = countByCompanyId(companyId);
1047
1048        List<BlogsEntry> list = findByCompanyId(companyId, count - 1, count, obc);
1049
1050        if (list.size() == 0) {
1051            StringBuilder msg = new StringBuilder();
1052
1053            msg.append("No BlogsEntry exists with the key {");
1054
1055            msg.append("companyId=" + companyId);
1056
1057            msg.append(StringPool.CLOSE_CURLY_BRACE);
1058
1059            throw new NoSuchEntryException(msg.toString());
1060        }
1061        else {
1062            return list.get(0);
1063        }
1064    }
1065
1066    public BlogsEntry[] findByCompanyId_PrevAndNext(long entryId,
1067        long companyId, OrderByComparator obc)
1068        throws NoSuchEntryException, SystemException {
1069        BlogsEntry blogsEntry = findByPrimaryKey(entryId);
1070
1071        int count = countByCompanyId(companyId);
1072
1073        Session session = null;
1074
1075        try {
1076            session = openSession();
1077
1078            StringBuilder query = new StringBuilder();
1079
1080            query.append(
1081                "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1082
1083            query.append("companyId = ?");
1084
1085            query.append(" ");
1086
1087            if (obc != null) {
1088                query.append("ORDER BY ");
1089                query.append(obc.getOrderBy());
1090            }
1091
1092            else {
1093                query.append("ORDER BY ");
1094
1095                query.append("displayDate DESC");
1096            }
1097
1098            Query q = session.createQuery(query.toString());
1099
1100            QueryPos qPos = QueryPos.getInstance(q);
1101
1102            qPos.add(companyId);
1103
1104            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1105                    blogsEntry);
1106
1107            BlogsEntry[] array = new BlogsEntryImpl[3];
1108
1109            array[0] = (BlogsEntry)objArray[0];
1110            array[1] = (BlogsEntry)objArray[1];
1111            array[2] = (BlogsEntry)objArray[2];
1112
1113            return array;
1114        }
1115        catch (Exception e) {
1116            throw processException(e);
1117        }
1118        finally {
1119            closeSession(session);
1120        }
1121    }
1122
1123    public List<BlogsEntry> findByG_U(long groupId, long userId)
1124        throws SystemException {
1125        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1126        String finderClassName = BlogsEntry.class.getName();
1127        String finderMethodName = "findByG_U";
1128        String[] finderParams = new String[] {
1129                Long.class.getName(), Long.class.getName()
1130            };
1131        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1132
1133        Object result = null;
1134
1135        if (finderClassNameCacheEnabled) {
1136            result = FinderCacheUtil.getResult(finderClassName,
1137                    finderMethodName, finderParams, finderArgs, this);
1138        }
1139
1140        if (result == null) {
1141            Session session = null;
1142
1143            try {
1144                session = openSession();
1145
1146                StringBuilder query = new StringBuilder();
1147
1148                query.append(
1149                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1150
1151                query.append("groupId = ?");
1152
1153                query.append(" AND ");
1154
1155                query.append("userId = ?");
1156
1157                query.append(" ");
1158
1159                query.append("ORDER BY ");
1160
1161                query.append("displayDate DESC");
1162
1163                Query q = session.createQuery(query.toString());
1164
1165                QueryPos qPos = QueryPos.getInstance(q);
1166
1167                qPos.add(groupId);
1168
1169                qPos.add(userId);
1170
1171                List<BlogsEntry> list = q.list();
1172
1173                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1174                    finderClassName, finderMethodName, finderParams,
1175                    finderArgs, list);
1176
1177                return list;
1178            }
1179            catch (Exception e) {
1180                throw processException(e);
1181            }
1182            finally {
1183                closeSession(session);
1184            }
1185        }
1186        else {
1187            return (List<BlogsEntry>)result;
1188        }
1189    }
1190
1191    public List<BlogsEntry> findByG_U(long groupId, long userId, int start,
1192        int end) throws SystemException {
1193        return findByG_U(groupId, userId, start, end, null);
1194    }
1195
1196    public List<BlogsEntry> findByG_U(long groupId, long userId, int start,
1197        int end, OrderByComparator obc) throws SystemException {
1198        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1199        String finderClassName = BlogsEntry.class.getName();
1200        String finderMethodName = "findByG_U";
1201        String[] finderParams = new String[] {
1202                Long.class.getName(), Long.class.getName(),
1203                
1204                "java.lang.Integer", "java.lang.Integer",
1205                "com.liferay.portal.kernel.util.OrderByComparator"
1206            };
1207        Object[] finderArgs = new Object[] {
1208                new Long(groupId), new Long(userId),
1209                
1210                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1211            };
1212
1213        Object result = null;
1214
1215        if (finderClassNameCacheEnabled) {
1216            result = FinderCacheUtil.getResult(finderClassName,
1217                    finderMethodName, finderParams, finderArgs, this);
1218        }
1219
1220        if (result == null) {
1221            Session session = null;
1222
1223            try {
1224                session = openSession();
1225
1226                StringBuilder query = new StringBuilder();
1227
1228                query.append(
1229                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1230
1231                query.append("groupId = ?");
1232
1233                query.append(" AND ");
1234
1235                query.append("userId = ?");
1236
1237                query.append(" ");
1238
1239                if (obc != null) {
1240                    query.append("ORDER BY ");
1241                    query.append(obc.getOrderBy());
1242                }
1243
1244                else {
1245                    query.append("ORDER BY ");
1246
1247                    query.append("displayDate DESC");
1248                }
1249
1250                Query q = session.createQuery(query.toString());
1251
1252                QueryPos qPos = QueryPos.getInstance(q);
1253
1254                qPos.add(groupId);
1255
1256                qPos.add(userId);
1257
1258                List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
1259                        getDialect(), start, end);
1260
1261                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1262                    finderClassName, finderMethodName, finderParams,
1263                    finderArgs, list);
1264
1265                return list;
1266            }
1267            catch (Exception e) {
1268                throw processException(e);
1269            }
1270            finally {
1271                closeSession(session);
1272            }
1273        }
1274        else {
1275            return (List<BlogsEntry>)result;
1276        }
1277    }
1278
1279    public BlogsEntry findByG_U_First(long groupId, long userId,
1280        OrderByComparator obc) throws NoSuchEntryException, SystemException {
1281        List<BlogsEntry> list = findByG_U(groupId, userId, 0, 1, obc);
1282
1283        if (list.size() == 0) {
1284            StringBuilder msg = new StringBuilder();
1285
1286            msg.append("No BlogsEntry exists with the key {");
1287
1288            msg.append("groupId=" + groupId);
1289
1290            msg.append(", ");
1291            msg.append("userId=" + userId);
1292
1293            msg.append(StringPool.CLOSE_CURLY_BRACE);
1294
1295            throw new NoSuchEntryException(msg.toString());
1296        }
1297        else {
1298            return list.get(0);
1299        }
1300    }
1301
1302    public BlogsEntry findByG_U_Last(long groupId, long userId,
1303        OrderByComparator obc) throws NoSuchEntryException, SystemException {
1304        int count = countByG_U(groupId, userId);
1305
1306        List<BlogsEntry> list = findByG_U(groupId, userId, count - 1, count, obc);
1307
1308        if (list.size() == 0) {
1309            StringBuilder msg = new StringBuilder();
1310
1311            msg.append("No BlogsEntry exists with the key {");
1312
1313            msg.append("groupId=" + groupId);
1314
1315            msg.append(", ");
1316            msg.append("userId=" + userId);
1317
1318            msg.append(StringPool.CLOSE_CURLY_BRACE);
1319
1320            throw new NoSuchEntryException(msg.toString());
1321        }
1322        else {
1323            return list.get(0);
1324        }
1325    }
1326
1327    public BlogsEntry[] findByG_U_PrevAndNext(long entryId, long groupId,
1328        long userId, OrderByComparator obc)
1329        throws NoSuchEntryException, SystemException {
1330        BlogsEntry blogsEntry = findByPrimaryKey(entryId);
1331
1332        int count = countByG_U(groupId, userId);
1333
1334        Session session = null;
1335
1336        try {
1337            session = openSession();
1338
1339            StringBuilder query = new StringBuilder();
1340
1341            query.append(
1342                "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1343
1344            query.append("groupId = ?");
1345
1346            query.append(" AND ");
1347
1348            query.append("userId = ?");
1349
1350            query.append(" ");
1351
1352            if (obc != null) {
1353                query.append("ORDER BY ");
1354                query.append(obc.getOrderBy());
1355            }
1356
1357            else {
1358                query.append("ORDER BY ");
1359
1360                query.append("displayDate DESC");
1361            }
1362
1363            Query q = session.createQuery(query.toString());
1364
1365            QueryPos qPos = QueryPos.getInstance(q);
1366
1367            qPos.add(groupId);
1368
1369            qPos.add(userId);
1370
1371            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1372                    blogsEntry);
1373
1374            BlogsEntry[] array = new BlogsEntryImpl[3];
1375
1376            array[0] = (BlogsEntry)objArray[0];
1377            array[1] = (BlogsEntry)objArray[1];
1378            array[2] = (BlogsEntry)objArray[2];
1379
1380            return array;
1381        }
1382        catch (Exception e) {
1383            throw processException(e);
1384        }
1385        finally {
1386            closeSession(session);
1387        }
1388    }
1389
1390    public BlogsEntry findByG_UT(long groupId, String urlTitle)
1391        throws NoSuchEntryException, SystemException {
1392        BlogsEntry blogsEntry = fetchByG_UT(groupId, urlTitle);
1393
1394        if (blogsEntry == null) {
1395            StringBuilder msg = new StringBuilder();
1396
1397            msg.append("No BlogsEntry exists with the key {");
1398
1399            msg.append("groupId=" + groupId);
1400
1401            msg.append(", ");
1402            msg.append("urlTitle=" + urlTitle);
1403
1404            msg.append(StringPool.CLOSE_CURLY_BRACE);
1405
1406            if (_log.isWarnEnabled()) {
1407                _log.warn(msg.toString());
1408            }
1409
1410            throw new NoSuchEntryException(msg.toString());
1411        }
1412
1413        return blogsEntry;
1414    }
1415
1416    public BlogsEntry fetchByG_UT(long groupId, String urlTitle)
1417        throws SystemException {
1418        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1419        String finderClassName = BlogsEntry.class.getName();
1420        String finderMethodName = "fetchByG_UT";
1421        String[] finderParams = new String[] {
1422                Long.class.getName(), String.class.getName()
1423            };
1424        Object[] finderArgs = new Object[] { new Long(groupId), urlTitle };
1425
1426        Object result = null;
1427
1428        if (finderClassNameCacheEnabled) {
1429            result = FinderCacheUtil.getResult(finderClassName,
1430                    finderMethodName, finderParams, finderArgs, this);
1431        }
1432
1433        if (result == null) {
1434            Session session = null;
1435
1436            try {
1437                session = openSession();
1438
1439                StringBuilder query = new StringBuilder();
1440
1441                query.append(
1442                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1443
1444                query.append("groupId = ?");
1445
1446                query.append(" AND ");
1447
1448                if (urlTitle == null) {
1449                    query.append("urlTitle IS NULL");
1450                }
1451                else {
1452                    query.append("urlTitle = ?");
1453                }
1454
1455                query.append(" ");
1456
1457                query.append("ORDER BY ");
1458
1459                query.append("displayDate DESC");
1460
1461                Query q = session.createQuery(query.toString());
1462
1463                QueryPos qPos = QueryPos.getInstance(q);
1464
1465                qPos.add(groupId);
1466
1467                if (urlTitle != null) {
1468                    qPos.add(urlTitle);
1469                }
1470
1471                List<BlogsEntry> list = q.list();
1472
1473                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1474                    finderClassName, finderMethodName, finderParams,
1475                    finderArgs, list);
1476
1477                if (list.size() == 0) {
1478                    return null;
1479                }
1480                else {
1481                    return list.get(0);
1482                }
1483            }
1484            catch (Exception e) {
1485                throw processException(e);
1486            }
1487            finally {
1488                closeSession(session);
1489            }
1490        }
1491        else {
1492            List<BlogsEntry> list = (List<BlogsEntry>)result;
1493
1494            if (list.size() == 0) {
1495                return null;
1496            }
1497            else {
1498                return list.get(0);
1499            }
1500        }
1501    }
1502
1503    public List<BlogsEntry> findByG_D_D(long groupId, Date displayDate,
1504        boolean draft) throws SystemException {
1505        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1506        String finderClassName = BlogsEntry.class.getName();
1507        String finderMethodName = "findByG_D_D";
1508        String[] finderParams = new String[] {
1509                Long.class.getName(), Date.class.getName(),
1510                Boolean.class.getName()
1511            };
1512        Object[] finderArgs = new Object[] {
1513                new Long(groupId),
1514                
1515                displayDate, Boolean.valueOf(draft)
1516            };
1517
1518        Object result = null;
1519
1520        if (finderClassNameCacheEnabled) {
1521            result = FinderCacheUtil.getResult(finderClassName,
1522                    finderMethodName, finderParams, finderArgs, this);
1523        }
1524
1525        if (result == null) {
1526            Session session = null;
1527
1528            try {
1529                session = openSession();
1530
1531                StringBuilder query = new StringBuilder();
1532
1533                query.append(
1534                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1535
1536                query.append("groupId = ?");
1537
1538                query.append(" AND ");
1539
1540                if (displayDate == null) {
1541                    query.append("displayDate < null");
1542                }
1543                else {
1544                    query.append("displayDate < ?");
1545                }
1546
1547                query.append(" AND ");
1548
1549                query.append("draft = ?");
1550
1551                query.append(" ");
1552
1553                query.append("ORDER BY ");
1554
1555                query.append("displayDate DESC");
1556
1557                Query q = session.createQuery(query.toString());
1558
1559                QueryPos qPos = QueryPos.getInstance(q);
1560
1561                qPos.add(groupId);
1562
1563                if (displayDate != null) {
1564                    qPos.add(CalendarUtil.getTimestamp(displayDate));
1565                }
1566
1567                qPos.add(draft);
1568
1569                List<BlogsEntry> list = q.list();
1570
1571                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1572                    finderClassName, finderMethodName, finderParams,
1573                    finderArgs, list);
1574
1575                return list;
1576            }
1577            catch (Exception e) {
1578                throw processException(e);
1579            }
1580            finally {
1581                closeSession(session);
1582            }
1583        }
1584        else {
1585            return (List<BlogsEntry>)result;
1586        }
1587    }
1588
1589    public List<BlogsEntry> findByG_D_D(long groupId, Date displayDate,
1590        boolean draft, int start, int end) throws SystemException {
1591        return findByG_D_D(groupId, displayDate, draft, start, end, null);
1592    }
1593
1594    public List<BlogsEntry> findByG_D_D(long groupId, Date displayDate,
1595        boolean draft, int start, int end, OrderByComparator obc)
1596        throws SystemException {
1597        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1598        String finderClassName = BlogsEntry.class.getName();
1599        String finderMethodName = "findByG_D_D";
1600        String[] finderParams = new String[] {
1601                Long.class.getName(), Date.class.getName(),
1602                Boolean.class.getName(),
1603                
1604                "java.lang.Integer", "java.lang.Integer",
1605                "com.liferay.portal.kernel.util.OrderByComparator"
1606            };
1607        Object[] finderArgs = new Object[] {
1608                new Long(groupId),
1609                
1610                displayDate, Boolean.valueOf(draft),
1611                
1612                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1613            };
1614
1615        Object result = null;
1616
1617        if (finderClassNameCacheEnabled) {
1618            result = FinderCacheUtil.getResult(finderClassName,
1619                    finderMethodName, finderParams, finderArgs, this);
1620        }
1621
1622        if (result == null) {
1623            Session session = null;
1624
1625            try {
1626                session = openSession();
1627
1628                StringBuilder query = new StringBuilder();
1629
1630                query.append(
1631                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1632
1633                query.append("groupId = ?");
1634
1635                query.append(" AND ");
1636
1637                if (displayDate == null) {
1638                    query.append("displayDate < null");
1639                }
1640                else {
1641                    query.append("displayDate < ?");
1642                }
1643
1644                query.append(" AND ");
1645
1646                query.append("draft = ?");
1647
1648                query.append(" ");
1649
1650                if (obc != null) {
1651                    query.append("ORDER BY ");
1652                    query.append(obc.getOrderBy());
1653                }
1654
1655                else {
1656                    query.append("ORDER BY ");
1657
1658                    query.append("displayDate DESC");
1659                }
1660
1661                Query q = session.createQuery(query.toString());
1662
1663                QueryPos qPos = QueryPos.getInstance(q);
1664
1665                qPos.add(groupId);
1666
1667                if (displayDate != null) {
1668                    qPos.add(CalendarUtil.getTimestamp(displayDate));
1669                }
1670
1671                qPos.add(draft);
1672
1673                List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
1674                        getDialect(), start, end);
1675
1676                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1677                    finderClassName, finderMethodName, finderParams,
1678                    finderArgs, list);
1679
1680                return list;
1681            }
1682            catch (Exception e) {
1683                throw processException(e);
1684            }
1685            finally {
1686                closeSession(session);
1687            }
1688        }
1689        else {
1690            return (List<BlogsEntry>)result;
1691        }
1692    }
1693
1694    public BlogsEntry findByG_D_D_First(long groupId, Date displayDate,
1695        boolean draft, OrderByComparator obc)
1696        throws NoSuchEntryException, SystemException {
1697        List<BlogsEntry> list = findByG_D_D(groupId, displayDate, draft, 0, 1,
1698                obc);
1699
1700        if (list.size() == 0) {
1701            StringBuilder msg = new StringBuilder();
1702
1703            msg.append("No BlogsEntry exists with the key {");
1704
1705            msg.append("groupId=" + groupId);
1706
1707            msg.append(", ");
1708            msg.append("displayDate=" + displayDate);
1709
1710            msg.append(", ");
1711            msg.append("draft=" + draft);
1712
1713            msg.append(StringPool.CLOSE_CURLY_BRACE);
1714
1715            throw new NoSuchEntryException(msg.toString());
1716        }
1717        else {
1718            return list.get(0);
1719        }
1720    }
1721
1722    public BlogsEntry findByG_D_D_Last(long groupId, Date displayDate,
1723        boolean draft, OrderByComparator obc)
1724        throws NoSuchEntryException, SystemException {
1725        int count = countByG_D_D(groupId, displayDate, draft);
1726
1727        List<BlogsEntry> list = findByG_D_D(groupId, displayDate, draft,
1728                count - 1, count, obc);
1729
1730        if (list.size() == 0) {
1731            StringBuilder msg = new StringBuilder();
1732
1733            msg.append("No BlogsEntry exists with the key {");
1734
1735            msg.append("groupId=" + groupId);
1736
1737            msg.append(", ");
1738            msg.append("displayDate=" + displayDate);
1739
1740            msg.append(", ");
1741            msg.append("draft=" + draft);
1742
1743            msg.append(StringPool.CLOSE_CURLY_BRACE);
1744
1745            throw new NoSuchEntryException(msg.toString());
1746        }
1747        else {
1748            return list.get(0);
1749        }
1750    }
1751
1752    public BlogsEntry[] findByG_D_D_PrevAndNext(long entryId, long groupId,
1753        Date displayDate, boolean draft, OrderByComparator obc)
1754        throws NoSuchEntryException, SystemException {
1755        BlogsEntry blogsEntry = findByPrimaryKey(entryId);
1756
1757        int count = countByG_D_D(groupId, displayDate, draft);
1758
1759        Session session = null;
1760
1761        try {
1762            session = openSession();
1763
1764            StringBuilder query = new StringBuilder();
1765
1766            query.append(
1767                "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1768
1769            query.append("groupId = ?");
1770
1771            query.append(" AND ");
1772
1773            if (displayDate == null) {
1774                query.append("displayDate < null");
1775            }
1776            else {
1777                query.append("displayDate < ?");
1778            }
1779
1780            query.append(" AND ");
1781
1782            query.append("draft = ?");
1783
1784            query.append(" ");
1785
1786            if (obc != null) {
1787                query.append("ORDER BY ");
1788                query.append(obc.getOrderBy());
1789            }
1790
1791            else {
1792                query.append("ORDER BY ");
1793
1794                query.append("displayDate DESC");
1795            }
1796
1797            Query q = session.createQuery(query.toString());
1798
1799            QueryPos qPos = QueryPos.getInstance(q);
1800
1801            qPos.add(groupId);
1802
1803            if (displayDate != null) {
1804                qPos.add(CalendarUtil.getTimestamp(displayDate));
1805            }
1806
1807            qPos.add(draft);
1808
1809            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1810                    blogsEntry);
1811
1812            BlogsEntry[] array = new BlogsEntryImpl[3];
1813
1814            array[0] = (BlogsEntry)objArray[0];
1815            array[1] = (BlogsEntry)objArray[1];
1816            array[2] = (BlogsEntry)objArray[2];
1817
1818            return array;
1819        }
1820        catch (Exception e) {
1821            throw processException(e);
1822        }
1823        finally {
1824            closeSession(session);
1825        }
1826    }
1827
1828    public List<BlogsEntry> findByC_D_D(long companyId, Date displayDate,
1829        boolean draft) throws SystemException {
1830        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1831        String finderClassName = BlogsEntry.class.getName();
1832        String finderMethodName = "findByC_D_D";
1833        String[] finderParams = new String[] {
1834                Long.class.getName(), Date.class.getName(),
1835                Boolean.class.getName()
1836            };
1837        Object[] finderArgs = new Object[] {
1838                new Long(companyId),
1839                
1840                displayDate, Boolean.valueOf(draft)
1841            };
1842
1843        Object result = null;
1844
1845        if (finderClassNameCacheEnabled) {
1846            result = FinderCacheUtil.getResult(finderClassName,
1847                    finderMethodName, finderParams, finderArgs, this);
1848        }
1849
1850        if (result == null) {
1851            Session session = null;
1852
1853            try {
1854                session = openSession();
1855
1856                StringBuilder query = new StringBuilder();
1857
1858                query.append(
1859                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1860
1861                query.append("companyId = ?");
1862
1863                query.append(" AND ");
1864
1865                if (displayDate == null) {
1866                    query.append("displayDate < null");
1867                }
1868                else {
1869                    query.append("displayDate < ?");
1870                }
1871
1872                query.append(" AND ");
1873
1874                query.append("draft = ?");
1875
1876                query.append(" ");
1877
1878                query.append("ORDER BY ");
1879
1880                query.append("displayDate DESC");
1881
1882                Query q = session.createQuery(query.toString());
1883
1884                QueryPos qPos = QueryPos.getInstance(q);
1885
1886                qPos.add(companyId);
1887
1888                if (displayDate != null) {
1889                    qPos.add(CalendarUtil.getTimestamp(displayDate));
1890                }
1891
1892                qPos.add(draft);
1893
1894                List<BlogsEntry> list = q.list();
1895
1896                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1897                    finderClassName, finderMethodName, finderParams,
1898                    finderArgs, list);
1899
1900                return list;
1901            }
1902            catch (Exception e) {
1903                throw processException(e);
1904            }
1905            finally {
1906                closeSession(session);
1907            }
1908        }
1909        else {
1910            return (List<BlogsEntry>)result;
1911        }
1912    }
1913
1914    public List<BlogsEntry> findByC_D_D(long companyId, Date displayDate,
1915        boolean draft, int start, int end) throws SystemException {
1916        return findByC_D_D(companyId, displayDate, draft, start, end, null);
1917    }
1918
1919    public List<BlogsEntry> findByC_D_D(long companyId, Date displayDate,
1920        boolean draft, int start, int end, OrderByComparator obc)
1921        throws SystemException {
1922        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
1923        String finderClassName = BlogsEntry.class.getName();
1924        String finderMethodName = "findByC_D_D";
1925        String[] finderParams = new String[] {
1926                Long.class.getName(), Date.class.getName(),
1927                Boolean.class.getName(),
1928                
1929                "java.lang.Integer", "java.lang.Integer",
1930                "com.liferay.portal.kernel.util.OrderByComparator"
1931            };
1932        Object[] finderArgs = new Object[] {
1933                new Long(companyId),
1934                
1935                displayDate, Boolean.valueOf(draft),
1936                
1937                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1938            };
1939
1940        Object result = null;
1941
1942        if (finderClassNameCacheEnabled) {
1943            result = FinderCacheUtil.getResult(finderClassName,
1944                    finderMethodName, finderParams, finderArgs, this);
1945        }
1946
1947        if (result == null) {
1948            Session session = null;
1949
1950            try {
1951                session = openSession();
1952
1953                StringBuilder query = new StringBuilder();
1954
1955                query.append(
1956                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1957
1958                query.append("companyId = ?");
1959
1960                query.append(" AND ");
1961
1962                if (displayDate == null) {
1963                    query.append("displayDate < null");
1964                }
1965                else {
1966                    query.append("displayDate < ?");
1967                }
1968
1969                query.append(" AND ");
1970
1971                query.append("draft = ?");
1972
1973                query.append(" ");
1974
1975                if (obc != null) {
1976                    query.append("ORDER BY ");
1977                    query.append(obc.getOrderBy());
1978                }
1979
1980                else {
1981                    query.append("ORDER BY ");
1982
1983                    query.append("displayDate DESC");
1984                }
1985
1986                Query q = session.createQuery(query.toString());
1987
1988                QueryPos qPos = QueryPos.getInstance(q);
1989
1990                qPos.add(companyId);
1991
1992                if (displayDate != null) {
1993                    qPos.add(CalendarUtil.getTimestamp(displayDate));
1994                }
1995
1996                qPos.add(draft);
1997
1998                List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
1999                        getDialect(), start, end);
2000
2001                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2002                    finderClassName, finderMethodName, finderParams,
2003                    finderArgs, list);
2004
2005                return list;
2006            }
2007            catch (Exception e) {
2008                throw processException(e);
2009            }
2010            finally {
2011                closeSession(session);
2012            }
2013        }
2014        else {
2015            return (List<BlogsEntry>)result;
2016        }
2017    }
2018
2019    public BlogsEntry findByC_D_D_First(long companyId, Date displayDate,
2020        boolean draft, OrderByComparator obc)
2021        throws NoSuchEntryException, SystemException {
2022        List<BlogsEntry> list = findByC_D_D(companyId, displayDate, draft, 0,
2023                1, obc);
2024
2025        if (list.size() == 0) {
2026            StringBuilder msg = new StringBuilder();
2027
2028            msg.append("No BlogsEntry exists with the key {");
2029
2030            msg.append("companyId=" + companyId);
2031
2032            msg.append(", ");
2033            msg.append("displayDate=" + displayDate);
2034
2035            msg.append(", ");
2036            msg.append("draft=" + draft);
2037
2038            msg.append(StringPool.CLOSE_CURLY_BRACE);
2039
2040            throw new NoSuchEntryException(msg.toString());
2041        }
2042        else {
2043            return list.get(0);
2044        }
2045    }
2046
2047    public BlogsEntry findByC_D_D_Last(long companyId, Date displayDate,
2048        boolean draft, OrderByComparator obc)
2049        throws NoSuchEntryException, SystemException {
2050        int count = countByC_D_D(companyId, displayDate, draft);
2051
2052        List<BlogsEntry> list = findByC_D_D(companyId, displayDate, draft,
2053                count - 1, count, obc);
2054
2055        if (list.size() == 0) {
2056            StringBuilder msg = new StringBuilder();
2057
2058            msg.append("No BlogsEntry exists with the key {");
2059
2060            msg.append("companyId=" + companyId);
2061
2062            msg.append(", ");
2063            msg.append("displayDate=" + displayDate);
2064
2065            msg.append(", ");
2066            msg.append("draft=" + draft);
2067
2068            msg.append(StringPool.CLOSE_CURLY_BRACE);
2069
2070            throw new NoSuchEntryException(msg.toString());
2071        }
2072        else {
2073            return list.get(0);
2074        }
2075    }
2076
2077    public BlogsEntry[] findByC_D_D_PrevAndNext(long entryId, long companyId,
2078        Date displayDate, boolean draft, OrderByComparator obc)
2079        throws NoSuchEntryException, SystemException {
2080        BlogsEntry blogsEntry = findByPrimaryKey(entryId);
2081
2082        int count = countByC_D_D(companyId, displayDate, draft);
2083
2084        Session session = null;
2085
2086        try {
2087            session = openSession();
2088
2089            StringBuilder query = new StringBuilder();
2090
2091            query.append(
2092                "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2093
2094            query.append("companyId = ?");
2095
2096            query.append(" AND ");
2097
2098            if (displayDate == null) {
2099                query.append("displayDate < null");
2100            }
2101            else {
2102                query.append("displayDate < ?");
2103            }
2104
2105            query.append(" AND ");
2106
2107            query.append("draft = ?");
2108
2109            query.append(" ");
2110
2111            if (obc != null) {
2112                query.append("ORDER BY ");
2113                query.append(obc.getOrderBy());
2114            }
2115
2116            else {
2117                query.append("ORDER BY ");
2118
2119                query.append("displayDate DESC");
2120            }
2121
2122            Query q = session.createQuery(query.toString());
2123
2124            QueryPos qPos = QueryPos.getInstance(q);
2125
2126            qPos.add(companyId);
2127
2128            if (displayDate != null) {
2129                qPos.add(CalendarUtil.getTimestamp(displayDate));
2130            }
2131
2132            qPos.add(draft);
2133
2134            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2135                    blogsEntry);
2136
2137            BlogsEntry[] array = new BlogsEntryImpl[3];
2138
2139            array[0] = (BlogsEntry)objArray[0];
2140            array[1] = (BlogsEntry)objArray[1];
2141            array[2] = (BlogsEntry)objArray[2];
2142
2143            return array;
2144        }
2145        catch (Exception e) {
2146            throw processException(e);
2147        }
2148        finally {
2149            closeSession(session);
2150        }
2151    }
2152
2153    public List<BlogsEntry> findByG_U_D_D(long groupId, long userId,
2154        Date displayDate, boolean draft) throws SystemException {
2155        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2156        String finderClassName = BlogsEntry.class.getName();
2157        String finderMethodName = "findByG_U_D_D";
2158        String[] finderParams = new String[] {
2159                Long.class.getName(), Long.class.getName(), Date.class.getName(),
2160                Boolean.class.getName()
2161            };
2162        Object[] finderArgs = new Object[] {
2163                new Long(groupId), new Long(userId),
2164                
2165                displayDate, Boolean.valueOf(draft)
2166            };
2167
2168        Object result = null;
2169
2170        if (finderClassNameCacheEnabled) {
2171            result = FinderCacheUtil.getResult(finderClassName,
2172                    finderMethodName, finderParams, finderArgs, this);
2173        }
2174
2175        if (result == null) {
2176            Session session = null;
2177
2178            try {
2179                session = openSession();
2180
2181                StringBuilder query = new StringBuilder();
2182
2183                query.append(
2184                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2185
2186                query.append("groupId = ?");
2187
2188                query.append(" AND ");
2189
2190                query.append("userId = ?");
2191
2192                query.append(" AND ");
2193
2194                if (displayDate == null) {
2195                    query.append("displayDate < null");
2196                }
2197                else {
2198                    query.append("displayDate < ?");
2199                }
2200
2201                query.append(" AND ");
2202
2203                query.append("draft = ?");
2204
2205                query.append(" ");
2206
2207                query.append("ORDER BY ");
2208
2209                query.append("displayDate DESC");
2210
2211                Query q = session.createQuery(query.toString());
2212
2213                QueryPos qPos = QueryPos.getInstance(q);
2214
2215                qPos.add(groupId);
2216
2217                qPos.add(userId);
2218
2219                if (displayDate != null) {
2220                    qPos.add(CalendarUtil.getTimestamp(displayDate));
2221                }
2222
2223                qPos.add(draft);
2224
2225                List<BlogsEntry> list = q.list();
2226
2227                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2228                    finderClassName, finderMethodName, finderParams,
2229                    finderArgs, list);
2230
2231                return list;
2232            }
2233            catch (Exception e) {
2234                throw processException(e);
2235            }
2236            finally {
2237                closeSession(session);
2238            }
2239        }
2240        else {
2241            return (List<BlogsEntry>)result;
2242        }
2243    }
2244
2245    public List<BlogsEntry> findByG_U_D_D(long groupId, long userId,
2246        Date displayDate, boolean draft, int start, int end)
2247        throws SystemException {
2248        return findByG_U_D_D(groupId, userId, displayDate, draft, start, end,
2249            null);
2250    }
2251
2252    public List<BlogsEntry> findByG_U_D_D(long groupId, long userId,
2253        Date displayDate, boolean draft, int start, int end,
2254        OrderByComparator obc) throws SystemException {
2255        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2256        String finderClassName = BlogsEntry.class.getName();
2257        String finderMethodName = "findByG_U_D_D";
2258        String[] finderParams = new String[] {
2259                Long.class.getName(), Long.class.getName(), Date.class.getName(),
2260                Boolean.class.getName(),
2261                
2262                "java.lang.Integer", "java.lang.Integer",
2263                "com.liferay.portal.kernel.util.OrderByComparator"
2264            };
2265        Object[] finderArgs = new Object[] {
2266                new Long(groupId), new Long(userId),
2267                
2268                displayDate, Boolean.valueOf(draft),
2269                
2270                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2271            };
2272
2273        Object result = null;
2274
2275        if (finderClassNameCacheEnabled) {
2276            result = FinderCacheUtil.getResult(finderClassName,
2277                    finderMethodName, finderParams, finderArgs, this);
2278        }
2279
2280        if (result == null) {
2281            Session session = null;
2282
2283            try {
2284                session = openSession();
2285
2286                StringBuilder query = new StringBuilder();
2287
2288                query.append(
2289                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2290
2291                query.append("groupId = ?");
2292
2293                query.append(" AND ");
2294
2295                query.append("userId = ?");
2296
2297                query.append(" AND ");
2298
2299                if (displayDate == null) {
2300                    query.append("displayDate < null");
2301                }
2302                else {
2303                    query.append("displayDate < ?");
2304                }
2305
2306                query.append(" AND ");
2307
2308                query.append("draft = ?");
2309
2310                query.append(" ");
2311
2312                if (obc != null) {
2313                    query.append("ORDER BY ");
2314                    query.append(obc.getOrderBy());
2315                }
2316
2317                else {
2318                    query.append("ORDER BY ");
2319
2320                    query.append("displayDate DESC");
2321                }
2322
2323                Query q = session.createQuery(query.toString());
2324
2325                QueryPos qPos = QueryPos.getInstance(q);
2326
2327                qPos.add(groupId);
2328
2329                qPos.add(userId);
2330
2331                if (displayDate != null) {
2332                    qPos.add(CalendarUtil.getTimestamp(displayDate));
2333                }
2334
2335                qPos.add(draft);
2336
2337                List<BlogsEntry> list = (List<BlogsEntry>)QueryUtil.list(q,
2338                        getDialect(), start, end);
2339
2340                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2341                    finderClassName, finderMethodName, finderParams,
2342                    finderArgs, list);
2343
2344                return list;
2345            }
2346            catch (Exception e) {
2347                throw processException(e);
2348            }
2349            finally {
2350                closeSession(session);
2351            }
2352        }
2353        else {
2354            return (List<BlogsEntry>)result;
2355        }
2356    }
2357
2358    public BlogsEntry findByG_U_D_D_First(long groupId, long userId,
2359        Date displayDate, boolean draft, OrderByComparator obc)
2360        throws NoSuchEntryException, SystemException {
2361        List<BlogsEntry> list = findByG_U_D_D(groupId, userId, displayDate,
2362                draft, 0, 1, obc);
2363
2364        if (list.size() == 0) {
2365            StringBuilder msg = new StringBuilder();
2366
2367            msg.append("No BlogsEntry exists with the key {");
2368
2369            msg.append("groupId=" + groupId);
2370
2371            msg.append(", ");
2372            msg.append("userId=" + userId);
2373
2374            msg.append(", ");
2375            msg.append("displayDate=" + displayDate);
2376
2377            msg.append(", ");
2378            msg.append("draft=" + draft);
2379
2380            msg.append(StringPool.CLOSE_CURLY_BRACE);
2381
2382            throw new NoSuchEntryException(msg.toString());
2383        }
2384        else {
2385            return list.get(0);
2386        }
2387    }
2388
2389    public BlogsEntry findByG_U_D_D_Last(long groupId, long userId,
2390        Date displayDate, boolean draft, OrderByComparator obc)
2391        throws NoSuchEntryException, SystemException {
2392        int count = countByG_U_D_D(groupId, userId, displayDate, draft);
2393
2394        List<BlogsEntry> list = findByG_U_D_D(groupId, userId, displayDate,
2395                draft, count - 1, count, obc);
2396
2397        if (list.size() == 0) {
2398            StringBuilder msg = new StringBuilder();
2399
2400            msg.append("No BlogsEntry exists with the key {");
2401
2402            msg.append("groupId=" + groupId);
2403
2404            msg.append(", ");
2405            msg.append("userId=" + userId);
2406
2407            msg.append(", ");
2408            msg.append("displayDate=" + displayDate);
2409
2410            msg.append(", ");
2411            msg.append("draft=" + draft);
2412
2413            msg.append(StringPool.CLOSE_CURLY_BRACE);
2414
2415            throw new NoSuchEntryException(msg.toString());
2416        }
2417        else {
2418            return list.get(0);
2419        }
2420    }
2421
2422    public BlogsEntry[] findByG_U_D_D_PrevAndNext(long entryId, long groupId,
2423        long userId, Date displayDate, boolean draft, OrderByComparator obc)
2424        throws NoSuchEntryException, SystemException {
2425        BlogsEntry blogsEntry = findByPrimaryKey(entryId);
2426
2427        int count = countByG_U_D_D(groupId, userId, displayDate, draft);
2428
2429        Session session = null;
2430
2431        try {
2432            session = openSession();
2433
2434            StringBuilder query = new StringBuilder();
2435
2436            query.append(
2437                "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2438
2439            query.append("groupId = ?");
2440
2441            query.append(" AND ");
2442
2443            query.append("userId = ?");
2444
2445            query.append(" AND ");
2446
2447            if (displayDate == null) {
2448                query.append("displayDate < null");
2449            }
2450            else {
2451                query.append("displayDate < ?");
2452            }
2453
2454            query.append(" AND ");
2455
2456            query.append("draft = ?");
2457
2458            query.append(" ");
2459
2460            if (obc != null) {
2461                query.append("ORDER BY ");
2462                query.append(obc.getOrderBy());
2463            }
2464
2465            else {
2466                query.append("ORDER BY ");
2467
2468                query.append("displayDate DESC");
2469            }
2470
2471            Query q = session.createQuery(query.toString());
2472
2473            QueryPos qPos = QueryPos.getInstance(q);
2474
2475            qPos.add(groupId);
2476
2477            qPos.add(userId);
2478
2479            if (displayDate != null) {
2480                qPos.add(CalendarUtil.getTimestamp(displayDate));
2481            }
2482
2483            qPos.add(draft);
2484
2485            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2486                    blogsEntry);
2487
2488            BlogsEntry[] array = new BlogsEntryImpl[3];
2489
2490            array[0] = (BlogsEntry)objArray[0];
2491            array[1] = (BlogsEntry)objArray[1];
2492            array[2] = (BlogsEntry)objArray[2];
2493
2494            return array;
2495        }
2496        catch (Exception e) {
2497            throw processException(e);
2498        }
2499        finally {
2500            closeSession(session);
2501        }
2502    }
2503
2504    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
2505        throws SystemException {
2506        Session session = null;
2507
2508        try {
2509            session = openSession();
2510
2511            dynamicQuery.compile(session);
2512
2513            return dynamicQuery.list();
2514        }
2515        catch (Exception e) {
2516            throw processException(e);
2517        }
2518        finally {
2519            closeSession(session);
2520        }
2521    }
2522
2523    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
2524        int start, int end) throws SystemException {
2525        Session session = null;
2526
2527        try {
2528            session = openSession();
2529
2530            dynamicQuery.setLimit(start, end);
2531
2532            dynamicQuery.compile(session);
2533
2534            return dynamicQuery.list();
2535        }
2536        catch (Exception e) {
2537            throw processException(e);
2538        }
2539        finally {
2540            closeSession(session);
2541        }
2542    }
2543
2544    public List<BlogsEntry> findAll() throws SystemException {
2545        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2546    }
2547
2548    public List<BlogsEntry> findAll(int start, int end)
2549        throws SystemException {
2550        return findAll(start, end, null);
2551    }
2552
2553    public List<BlogsEntry> findAll(int start, int end, OrderByComparator obc)
2554        throws SystemException {
2555        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2556        String finderClassName = BlogsEntry.class.getName();
2557        String finderMethodName = "findAll";
2558        String[] finderParams = new String[] {
2559                "java.lang.Integer", "java.lang.Integer",
2560                "com.liferay.portal.kernel.util.OrderByComparator"
2561            };
2562        Object[] finderArgs = new Object[] {
2563                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2564            };
2565
2566        Object result = null;
2567
2568        if (finderClassNameCacheEnabled) {
2569            result = FinderCacheUtil.getResult(finderClassName,
2570                    finderMethodName, finderParams, finderArgs, this);
2571        }
2572
2573        if (result == null) {
2574            Session session = null;
2575
2576            try {
2577                session = openSession();
2578
2579                StringBuilder query = new StringBuilder();
2580
2581                query.append("FROM com.liferay.portlet.blogs.model.BlogsEntry ");
2582
2583                if (obc != null) {
2584                    query.append("ORDER BY ");
2585                    query.append(obc.getOrderBy());
2586                }
2587
2588                else {
2589                    query.append("ORDER BY ");
2590
2591                    query.append("displayDate DESC");
2592                }
2593
2594                Query q = session.createQuery(query.toString());
2595
2596                List<BlogsEntry> list = null;
2597
2598                if (obc == null) {
2599                    list = (List<BlogsEntry>)QueryUtil.list(q, getDialect(),
2600                            start, end, false);
2601
2602                    Collections.sort(list);
2603                }
2604                else {
2605                    list = (List<BlogsEntry>)QueryUtil.list(q, getDialect(),
2606                            start, end);
2607                }
2608
2609                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2610                    finderClassName, finderMethodName, finderParams,
2611                    finderArgs, list);
2612
2613                return list;
2614            }
2615            catch (Exception e) {
2616                throw processException(e);
2617            }
2618            finally {
2619                closeSession(session);
2620            }
2621        }
2622        else {
2623            return (List<BlogsEntry>)result;
2624        }
2625    }
2626
2627    public void removeByUuid(String uuid) throws SystemException {
2628        for (BlogsEntry blogsEntry : findByUuid(uuid)) {
2629            remove(blogsEntry);
2630        }
2631    }
2632
2633    public void removeByUUID_G(String uuid, long groupId)
2634        throws NoSuchEntryException, SystemException {
2635        BlogsEntry blogsEntry = findByUUID_G(uuid, groupId);
2636
2637        remove(blogsEntry);
2638    }
2639
2640    public void removeByGroupId(long groupId) throws SystemException {
2641        for (BlogsEntry blogsEntry : findByGroupId(groupId)) {
2642            remove(blogsEntry);
2643        }
2644    }
2645
2646    public void removeByCompanyId(long companyId) throws SystemException {
2647        for (BlogsEntry blogsEntry : findByCompanyId(companyId)) {
2648            remove(blogsEntry);
2649        }
2650    }
2651
2652    public void removeByG_U(long groupId, long userId)
2653        throws SystemException {
2654        for (BlogsEntry blogsEntry : findByG_U(groupId, userId)) {
2655            remove(blogsEntry);
2656        }
2657    }
2658
2659    public void removeByG_UT(long groupId, String urlTitle)
2660        throws NoSuchEntryException, SystemException {
2661        BlogsEntry blogsEntry = findByG_UT(groupId, urlTitle);
2662
2663        remove(blogsEntry);
2664    }
2665
2666    public void removeByG_D_D(long groupId, Date displayDate, boolean draft)
2667        throws SystemException {
2668        for (BlogsEntry blogsEntry : findByG_D_D(groupId, displayDate, draft)) {
2669            remove(blogsEntry);
2670        }
2671    }
2672
2673    public void removeByC_D_D(long companyId, Date displayDate, boolean draft)
2674        throws SystemException {
2675        for (BlogsEntry blogsEntry : findByC_D_D(companyId, displayDate, draft)) {
2676            remove(blogsEntry);
2677        }
2678    }
2679
2680    public void removeByG_U_D_D(long groupId, long userId, Date displayDate,
2681        boolean draft) throws SystemException {
2682        for (BlogsEntry blogsEntry : findByG_U_D_D(groupId, userId,
2683                displayDate, draft)) {
2684            remove(blogsEntry);
2685        }
2686    }
2687
2688    public void removeAll() throws SystemException {
2689        for (BlogsEntry blogsEntry : findAll()) {
2690            remove(blogsEntry);
2691        }
2692    }
2693
2694    public int countByUuid(String uuid) throws SystemException {
2695        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2696        String finderClassName = BlogsEntry.class.getName();
2697        String finderMethodName = "countByUuid";
2698        String[] finderParams = new String[] { String.class.getName() };
2699        Object[] finderArgs = new Object[] { uuid };
2700
2701        Object result = null;
2702
2703        if (finderClassNameCacheEnabled) {
2704            result = FinderCacheUtil.getResult(finderClassName,
2705                    finderMethodName, finderParams, finderArgs, this);
2706        }
2707
2708        if (result == null) {
2709            Session session = null;
2710
2711            try {
2712                session = openSession();
2713
2714                StringBuilder query = new StringBuilder();
2715
2716                query.append("SELECT COUNT(*) ");
2717                query.append(
2718                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2719
2720                if (uuid == null) {
2721                    query.append("uuid_ IS NULL");
2722                }
2723                else {
2724                    query.append("uuid_ = ?");
2725                }
2726
2727                query.append(" ");
2728
2729                Query q = session.createQuery(query.toString());
2730
2731                QueryPos qPos = QueryPos.getInstance(q);
2732
2733                if (uuid != null) {
2734                    qPos.add(uuid);
2735                }
2736
2737                Long count = null;
2738
2739                Iterator<Long> itr = q.list().iterator();
2740
2741                if (itr.hasNext()) {
2742                    count = itr.next();
2743                }
2744
2745                if (count == null) {
2746                    count = new Long(0);
2747                }
2748
2749                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2750                    finderClassName, finderMethodName, finderParams,
2751                    finderArgs, count);
2752
2753                return count.intValue();
2754            }
2755            catch (Exception e) {
2756                throw processException(e);
2757            }
2758            finally {
2759                closeSession(session);
2760            }
2761        }
2762        else {
2763            return ((Long)result).intValue();
2764        }
2765    }
2766
2767    public int countByUUID_G(String uuid, long groupId)
2768        throws SystemException {
2769        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2770        String finderClassName = BlogsEntry.class.getName();
2771        String finderMethodName = "countByUUID_G";
2772        String[] finderParams = new String[] {
2773                String.class.getName(), Long.class.getName()
2774            };
2775        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
2776
2777        Object result = null;
2778
2779        if (finderClassNameCacheEnabled) {
2780            result = FinderCacheUtil.getResult(finderClassName,
2781                    finderMethodName, finderParams, finderArgs, this);
2782        }
2783
2784        if (result == null) {
2785            Session session = null;
2786
2787            try {
2788                session = openSession();
2789
2790                StringBuilder query = new StringBuilder();
2791
2792                query.append("SELECT COUNT(*) ");
2793                query.append(
2794                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2795
2796                if (uuid == null) {
2797                    query.append("uuid_ IS NULL");
2798                }
2799                else {
2800                    query.append("uuid_ = ?");
2801                }
2802
2803                query.append(" AND ");
2804
2805                query.append("groupId = ?");
2806
2807                query.append(" ");
2808
2809                Query q = session.createQuery(query.toString());
2810
2811                QueryPos qPos = QueryPos.getInstance(q);
2812
2813                if (uuid != null) {
2814                    qPos.add(uuid);
2815                }
2816
2817                qPos.add(groupId);
2818
2819                Long count = null;
2820
2821                Iterator<Long> itr = q.list().iterator();
2822
2823                if (itr.hasNext()) {
2824                    count = itr.next();
2825                }
2826
2827                if (count == null) {
2828                    count = new Long(0);
2829                }
2830
2831                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2832                    finderClassName, finderMethodName, finderParams,
2833                    finderArgs, count);
2834
2835                return count.intValue();
2836            }
2837            catch (Exception e) {
2838                throw processException(e);
2839            }
2840            finally {
2841                closeSession(session);
2842            }
2843        }
2844        else {
2845            return ((Long)result).intValue();
2846        }
2847    }
2848
2849    public int countByGroupId(long groupId) throws SystemException {
2850        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2851        String finderClassName = BlogsEntry.class.getName();
2852        String finderMethodName = "countByGroupId";
2853        String[] finderParams = new String[] { Long.class.getName() };
2854        Object[] finderArgs = new Object[] { new Long(groupId) };
2855
2856        Object result = null;
2857
2858        if (finderClassNameCacheEnabled) {
2859            result = FinderCacheUtil.getResult(finderClassName,
2860                    finderMethodName, finderParams, finderArgs, this);
2861        }
2862
2863        if (result == null) {
2864            Session session = null;
2865
2866            try {
2867                session = openSession();
2868
2869                StringBuilder query = new StringBuilder();
2870
2871                query.append("SELECT COUNT(*) ");
2872                query.append(
2873                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2874
2875                query.append("groupId = ?");
2876
2877                query.append(" ");
2878
2879                Query q = session.createQuery(query.toString());
2880
2881                QueryPos qPos = QueryPos.getInstance(q);
2882
2883                qPos.add(groupId);
2884
2885                Long count = null;
2886
2887                Iterator<Long> itr = q.list().iterator();
2888
2889                if (itr.hasNext()) {
2890                    count = itr.next();
2891                }
2892
2893                if (count == null) {
2894                    count = new Long(0);
2895                }
2896
2897                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2898                    finderClassName, finderMethodName, finderParams,
2899                    finderArgs, count);
2900
2901                return count.intValue();
2902            }
2903            catch (Exception e) {
2904                throw processException(e);
2905            }
2906            finally {
2907                closeSession(session);
2908            }
2909        }
2910        else {
2911            return ((Long)result).intValue();
2912        }
2913    }
2914
2915    public int countByCompanyId(long companyId) throws SystemException {
2916        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2917        String finderClassName = BlogsEntry.class.getName();
2918        String finderMethodName = "countByCompanyId";
2919        String[] finderParams = new String[] { Long.class.getName() };
2920        Object[] finderArgs = new Object[] { new Long(companyId) };
2921
2922        Object result = null;
2923
2924        if (finderClassNameCacheEnabled) {
2925            result = FinderCacheUtil.getResult(finderClassName,
2926                    finderMethodName, finderParams, finderArgs, this);
2927        }
2928
2929        if (result == null) {
2930            Session session = null;
2931
2932            try {
2933                session = openSession();
2934
2935                StringBuilder query = new StringBuilder();
2936
2937                query.append("SELECT COUNT(*) ");
2938                query.append(
2939                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
2940
2941                query.append("companyId = ?");
2942
2943                query.append(" ");
2944
2945                Query q = session.createQuery(query.toString());
2946
2947                QueryPos qPos = QueryPos.getInstance(q);
2948
2949                qPos.add(companyId);
2950
2951                Long count = null;
2952
2953                Iterator<Long> itr = q.list().iterator();
2954
2955                if (itr.hasNext()) {
2956                    count = itr.next();
2957                }
2958
2959                if (count == null) {
2960                    count = new Long(0);
2961                }
2962
2963                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2964                    finderClassName, finderMethodName, finderParams,
2965                    finderArgs, count);
2966
2967                return count.intValue();
2968            }
2969            catch (Exception e) {
2970                throw processException(e);
2971            }
2972            finally {
2973                closeSession(session);
2974            }
2975        }
2976        else {
2977            return ((Long)result).intValue();
2978        }
2979    }
2980
2981    public int countByG_U(long groupId, long userId) throws SystemException {
2982        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
2983        String finderClassName = BlogsEntry.class.getName();
2984        String finderMethodName = "countByG_U";
2985        String[] finderParams = new String[] {
2986                Long.class.getName(), Long.class.getName()
2987            };
2988        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
2989
2990        Object result = null;
2991
2992        if (finderClassNameCacheEnabled) {
2993            result = FinderCacheUtil.getResult(finderClassName,
2994                    finderMethodName, finderParams, finderArgs, this);
2995        }
2996
2997        if (result == null) {
2998            Session session = null;
2999
3000            try {
3001                session = openSession();
3002
3003                StringBuilder query = new StringBuilder();
3004
3005                query.append("SELECT COUNT(*) ");
3006                query.append(
3007                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
3008
3009                query.append("groupId = ?");
3010
3011                query.append(" AND ");
3012
3013                query.append("userId = ?");
3014
3015                query.append(" ");
3016
3017                Query q = session.createQuery(query.toString());
3018
3019                QueryPos qPos = QueryPos.getInstance(q);
3020
3021                qPos.add(groupId);
3022
3023                qPos.add(userId);
3024
3025                Long count = null;
3026
3027                Iterator<Long> itr = q.list().iterator();
3028
3029                if (itr.hasNext()) {
3030                    count = itr.next();
3031                }
3032
3033                if (count == null) {
3034                    count = new Long(0);
3035                }
3036
3037                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3038                    finderClassName, finderMethodName, finderParams,
3039                    finderArgs, count);
3040
3041                return count.intValue();
3042            }
3043            catch (Exception e) {
3044                throw processException(e);
3045            }
3046            finally {
3047                closeSession(session);
3048            }
3049        }
3050        else {
3051            return ((Long)result).intValue();
3052        }
3053    }
3054
3055    public int countByG_UT(long groupId, String urlTitle)
3056        throws SystemException {
3057        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
3058        String finderClassName = BlogsEntry.class.getName();
3059        String finderMethodName = "countByG_UT";
3060        String[] finderParams = new String[] {
3061                Long.class.getName(), String.class.getName()
3062            };
3063        Object[] finderArgs = new Object[] { new Long(groupId), urlTitle };
3064
3065        Object result = null;
3066
3067        if (finderClassNameCacheEnabled) {
3068            result = FinderCacheUtil.getResult(finderClassName,
3069                    finderMethodName, finderParams, finderArgs, this);
3070        }
3071
3072        if (result == null) {
3073            Session session = null;
3074
3075            try {
3076                session = openSession();
3077
3078                StringBuilder query = new StringBuilder();
3079
3080                query.append("SELECT COUNT(*) ");
3081                query.append(
3082                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
3083
3084                query.append("groupId = ?");
3085
3086                query.append(" AND ");
3087
3088                if (urlTitle == null) {
3089                    query.append("urlTitle IS NULL");
3090                }
3091                else {
3092                    query.append("urlTitle = ?");
3093                }
3094
3095                query.append(" ");
3096
3097                Query q = session.createQuery(query.toString());
3098
3099                QueryPos qPos = QueryPos.getInstance(q);
3100
3101                qPos.add(groupId);
3102
3103                if (urlTitle != null) {
3104                    qPos.add(urlTitle);
3105                }
3106
3107                Long count = null;
3108
3109                Iterator<Long> itr = q.list().iterator();
3110
3111                if (itr.hasNext()) {
3112                    count = itr.next();
3113                }
3114
3115                if (count == null) {
3116                    count = new Long(0);
3117                }
3118
3119                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3120                    finderClassName, finderMethodName, finderParams,
3121                    finderArgs, count);
3122
3123                return count.intValue();
3124            }
3125            catch (Exception e) {
3126                throw processException(e);
3127            }
3128            finally {
3129                closeSession(session);
3130            }
3131        }
3132        else {
3133            return ((Long)result).intValue();
3134        }
3135    }
3136
3137    public int countByG_D_D(long groupId, Date displayDate, boolean draft)
3138        throws SystemException {
3139        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
3140        String finderClassName = BlogsEntry.class.getName();
3141        String finderMethodName = "countByG_D_D";
3142        String[] finderParams = new String[] {
3143                Long.class.getName(), Date.class.getName(),
3144                Boolean.class.getName()
3145            };
3146        Object[] finderArgs = new Object[] {
3147                new Long(groupId),
3148                
3149                displayDate, Boolean.valueOf(draft)
3150            };
3151
3152        Object result = null;
3153
3154        if (finderClassNameCacheEnabled) {
3155            result = FinderCacheUtil.getResult(finderClassName,
3156                    finderMethodName, finderParams, finderArgs, this);
3157        }
3158
3159        if (result == null) {
3160            Session session = null;
3161
3162            try {
3163                session = openSession();
3164
3165                StringBuilder query = new StringBuilder();
3166
3167                query.append("SELECT COUNT(*) ");
3168                query.append(
3169                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
3170
3171                query.append("groupId = ?");
3172
3173                query.append(" AND ");
3174
3175                if (displayDate == null) {
3176                    query.append("displayDate < null");
3177                }
3178                else {
3179                    query.append("displayDate < ?");
3180                }
3181
3182                query.append(" AND ");
3183
3184                query.append("draft = ?");
3185
3186                query.append(" ");
3187
3188                Query q = session.createQuery(query.toString());
3189
3190                QueryPos qPos = QueryPos.getInstance(q);
3191
3192                qPos.add(groupId);
3193
3194                if (displayDate != null) {
3195                    qPos.add(CalendarUtil.getTimestamp(displayDate));
3196                }
3197
3198                qPos.add(draft);
3199
3200                Long count = null;
3201
3202                Iterator<Long> itr = q.list().iterator();
3203
3204                if (itr.hasNext()) {
3205                    count = itr.next();
3206                }
3207
3208                if (count == null) {
3209                    count = new Long(0);
3210                }
3211
3212                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3213                    finderClassName, finderMethodName, finderParams,
3214                    finderArgs, count);
3215
3216                return count.intValue();
3217            }
3218            catch (Exception e) {
3219                throw processException(e);
3220            }
3221            finally {
3222                closeSession(session);
3223            }
3224        }
3225        else {
3226            return ((Long)result).intValue();
3227        }
3228    }
3229
3230    public int countByC_D_D(long companyId, Date displayDate, boolean draft)
3231        throws SystemException {
3232        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
3233        String finderClassName = BlogsEntry.class.getName();
3234        String finderMethodName = "countByC_D_D";
3235        String[] finderParams = new String[] {
3236                Long.class.getName(), Date.class.getName(),
3237                Boolean.class.getName()
3238            };
3239        Object[] finderArgs = new Object[] {
3240                new Long(companyId),
3241                
3242                displayDate, Boolean.valueOf(draft)
3243            };
3244
3245        Object result = null;
3246
3247        if (finderClassNameCacheEnabled) {
3248            result = FinderCacheUtil.getResult(finderClassName,
3249                    finderMethodName, finderParams, finderArgs, this);
3250        }
3251
3252        if (result == null) {
3253            Session session = null;
3254
3255            try {
3256                session = openSession();
3257
3258                StringBuilder query = new StringBuilder();
3259
3260                query.append("SELECT COUNT(*) ");
3261                query.append(
3262                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
3263
3264                query.append("companyId = ?");
3265
3266                query.append(" AND ");
3267
3268                if (displayDate == null) {
3269                    query.append("displayDate < null");
3270                }
3271                else {
3272                    query.append("displayDate < ?");
3273                }
3274
3275                query.append(" AND ");
3276
3277                query.append("draft = ?");
3278
3279                query.append(" ");
3280
3281                Query q = session.createQuery(query.toString());
3282
3283                QueryPos qPos = QueryPos.getInstance(q);
3284
3285                qPos.add(companyId);
3286
3287                if (displayDate != null) {
3288                    qPos.add(CalendarUtil.getTimestamp(displayDate));
3289                }
3290
3291                qPos.add(draft);
3292
3293                Long count = null;
3294
3295                Iterator<Long> itr = q.list().iterator();
3296
3297                if (itr.hasNext()) {
3298                    count = itr.next();
3299                }
3300
3301                if (count == null) {
3302                    count = new Long(0);
3303                }
3304
3305                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3306                    finderClassName, finderMethodName, finderParams,
3307                    finderArgs, count);
3308
3309                return count.intValue();
3310            }
3311            catch (Exception e) {
3312                throw processException(e);
3313            }
3314            finally {
3315                closeSession(session);
3316            }
3317        }
3318        else {
3319            return ((Long)result).intValue();
3320        }
3321    }
3322
3323    public int countByG_U_D_D(long groupId, long userId, Date displayDate,
3324        boolean draft) throws SystemException {
3325        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
3326        String finderClassName = BlogsEntry.class.getName();
3327        String finderMethodName = "countByG_U_D_D";
3328        String[] finderParams = new String[] {
3329                Long.class.getName(), Long.class.getName(), Date.class.getName(),
3330                Boolean.class.getName()
3331            };
3332        Object[] finderArgs = new Object[] {
3333                new Long(groupId), new Long(userId),
3334                
3335                displayDate, Boolean.valueOf(draft)
3336            };
3337
3338        Object result = null;
3339
3340        if (finderClassNameCacheEnabled) {
3341            result = FinderCacheUtil.getResult(finderClassName,
3342                    finderMethodName, finderParams, finderArgs, this);
3343        }
3344
3345        if (result == null) {
3346            Session session = null;
3347
3348            try {
3349                session = openSession();
3350
3351                StringBuilder query = new StringBuilder();
3352
3353                query.append("SELECT COUNT(*) ");
3354                query.append(
3355                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
3356
3357                query.append("groupId = ?");
3358
3359                query.append(" AND ");
3360
3361                query.append("userId = ?");
3362
3363                query.append(" AND ");
3364
3365                if (displayDate == null) {
3366                    query.append("displayDate < null");
3367                }
3368                else {
3369                    query.append("displayDate < ?");
3370                }
3371
3372                query.append(" AND ");
3373
3374                query.append("draft = ?");
3375
3376                query.append(" ");
3377
3378                Query q = session.createQuery(query.toString());
3379
3380                QueryPos qPos = QueryPos.getInstance(q);
3381
3382                qPos.add(groupId);
3383
3384                qPos.add(userId);
3385
3386                if (displayDate != null) {
3387                    qPos.add(CalendarUtil.getTimestamp(displayDate));
3388                }
3389
3390                qPos.add(draft);
3391
3392                Long count = null;
3393
3394                Iterator<Long> itr = q.list().iterator();
3395
3396                if (itr.hasNext()) {
3397                    count = itr.next();
3398                }
3399
3400                if (count == null) {
3401                    count = new Long(0);
3402                }
3403
3404                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3405                    finderClassName, finderMethodName, finderParams,
3406                    finderArgs, count);
3407
3408                return count.intValue();
3409            }
3410            catch (Exception e) {
3411                throw processException(e);
3412            }
3413            finally {
3414                closeSession(session);
3415            }
3416        }
3417        else {
3418            return ((Long)result).intValue();
3419        }
3420    }
3421
3422    public int countAll() throws SystemException {
3423        boolean finderClassNameCacheEnabled = BlogsEntryModelImpl.CACHE_ENABLED;
3424        String finderClassName = BlogsEntry.class.getName();
3425        String finderMethodName = "countAll";
3426        String[] finderParams = new String[] {  };
3427        Object[] finderArgs = new Object[] {  };
3428
3429        Object result = null;
3430
3431        if (finderClassNameCacheEnabled) {
3432            result = FinderCacheUtil.getResult(finderClassName,
3433                    finderMethodName, finderParams, finderArgs, this);
3434        }
3435
3436        if (result == null) {
3437            Session session = null;
3438
3439            try {
3440                session = openSession();
3441
3442                Query q = session.createQuery(
3443                        "SELECT COUNT(*) FROM com.liferay.portlet.blogs.model.BlogsEntry");
3444
3445                Long count = null;
3446
3447                Iterator<Long> itr = q.list().iterator();
3448
3449                if (itr.hasNext()) {
3450                    count = itr.next();
3451                }
3452
3453                if (count == null) {
3454                    count = new Long(0);
3455                }
3456
3457                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3458                    finderClassName, finderMethodName, finderParams,
3459                    finderArgs, count);
3460
3461                return count.intValue();
3462            }
3463            catch (Exception e) {
3464                throw processException(e);
3465            }
3466            finally {
3467                closeSession(session);
3468            }
3469        }
3470        else {
3471            return ((Long)result).intValue();
3472        }
3473    }
3474
3475    public void afterPropertiesSet() {
3476        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3477                    com.liferay.portal.util.PropsUtil.get(
3478                        "value.object.listener.com.liferay.portlet.blogs.model.BlogsEntry")));
3479
3480        if (listenerClassNames.length > 0) {
3481            try {
3482                List<ModelListener> listenersList = new ArrayList<ModelListener>();
3483
3484                for (String listenerClassName : listenerClassNames) {
3485                    listenersList.add((ModelListener)Class.forName(
3486                            listenerClassName).newInstance());
3487                }
3488
3489                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3490            }
3491            catch (Exception e) {
3492                _log.error(e);
3493            }
3494        }
3495    }
3496
3497    private static Log _log = LogFactoryUtil.getLog(BlogsEntryPersistenceImpl.class);
3498}