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