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