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