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