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