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