001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.wiki.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.BatchSessionUtil;
040    import com.liferay.portal.service.persistence.CompanyPersistence;
041    import com.liferay.portal.service.persistence.GroupPersistence;
042    import com.liferay.portal.service.persistence.PortletPreferencesPersistence;
043    import com.liferay.portal.service.persistence.ResourcePersistence;
044    import com.liferay.portal.service.persistence.SubscriptionPersistence;
045    import com.liferay.portal.service.persistence.UserPersistence;
046    import com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.asset.service.persistence.AssetCategoryPersistence;
050    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
051    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
052    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
053    import com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence;
054    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
055    import com.liferay.portlet.social.service.persistence.SocialEquityLogPersistence;
056    import com.liferay.portlet.wiki.NoSuchPageException;
057    import com.liferay.portlet.wiki.model.WikiPage;
058    import com.liferay.portlet.wiki.model.impl.WikiPageImpl;
059    import com.liferay.portlet.wiki.model.impl.WikiPageModelImpl;
060    
061    import java.io.Serializable;
062    
063    import java.util.ArrayList;
064    import java.util.Collections;
065    import java.util.List;
066    
067    /**
068     * The persistence implementation for the wiki page service.
069     *
070     * <p>
071     * Never modify or reference this class directly. Always use {@link WikiPageUtil} to access the wiki page persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
072     * </p>
073     *
074     * <p>
075     * Caching information and settings can be found in <code>portal.properties</code>
076     * </p>
077     *
078     * @author Brian Wing Shun Chan
079     * @see WikiPagePersistence
080     * @see WikiPageUtil
081     * @generated
082     */
083    public class WikiPagePersistenceImpl extends BasePersistenceImpl<WikiPage>
084            implements WikiPagePersistence {
085            public static final String FINDER_CLASS_NAME_ENTITY = WikiPageImpl.class.getName();
086            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
087                    ".List";
088            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
089                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
090                            "findByUuid",
091                            new String[] {
092                                    String.class.getName(),
093                                    
094                            "java.lang.Integer", "java.lang.Integer",
095                                    "com.liferay.portal.kernel.util.OrderByComparator"
096                            });
097            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
098                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
099                            "countByUuid", new String[] { String.class.getName() });
100            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
101                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
102                            "fetchByUUID_G",
103                            new String[] { String.class.getName(), Long.class.getName() });
104            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
105                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106                            "countByUUID_G",
107                            new String[] { String.class.getName(), Long.class.getName() });
108            public static final FinderPath FINDER_PATH_FIND_BY_NODEID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
109                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
110                            "findByNodeId",
111                            new String[] {
112                                    Long.class.getName(),
113                                    
114                            "java.lang.Integer", "java.lang.Integer",
115                                    "com.liferay.portal.kernel.util.OrderByComparator"
116                            });
117            public static final FinderPath FINDER_PATH_COUNT_BY_NODEID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
118                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
119                            "countByNodeId", new String[] { Long.class.getName() });
120            public static final FinderPath FINDER_PATH_FIND_BY_FORMAT = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
121                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
122                            "findByFormat",
123                            new String[] {
124                                    String.class.getName(),
125                                    
126                            "java.lang.Integer", "java.lang.Integer",
127                                    "com.liferay.portal.kernel.util.OrderByComparator"
128                            });
129            public static final FinderPath FINDER_PATH_COUNT_BY_FORMAT = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
130                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
131                            "countByFormat", new String[] { String.class.getName() });
132            public static final FinderPath FINDER_PATH_FIND_BY_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
133                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
134                            "findByR_N",
135                            new String[] {
136                                    Long.class.getName(), Long.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_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
142                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
143                            "countByR_N",
144                            new String[] { Long.class.getName(), Long.class.getName() });
145            public static final FinderPath FINDER_PATH_FIND_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
146                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
147                            "findByN_T",
148                            new String[] {
149                                    Long.class.getName(), String.class.getName(),
150                                    
151                            "java.lang.Integer", "java.lang.Integer",
152                                    "com.liferay.portal.kernel.util.OrderByComparator"
153                            });
154            public static final FinderPath FINDER_PATH_COUNT_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
155                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
156                            "countByN_T",
157                            new String[] { Long.class.getName(), String.class.getName() });
158            public static final FinderPath FINDER_PATH_FIND_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
159                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
160                            "findByN_H",
161                            new String[] {
162                                    Long.class.getName(), Boolean.class.getName(),
163                                    
164                            "java.lang.Integer", "java.lang.Integer",
165                                    "com.liferay.portal.kernel.util.OrderByComparator"
166                            });
167            public static final FinderPath FINDER_PATH_COUNT_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
168                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
169                            "countByN_H",
170                            new String[] { Long.class.getName(), Boolean.class.getName() });
171            public static final FinderPath FINDER_PATH_FIND_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
172                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
173                            "findByN_P",
174                            new String[] {
175                                    Long.class.getName(), String.class.getName(),
176                                    
177                            "java.lang.Integer", "java.lang.Integer",
178                                    "com.liferay.portal.kernel.util.OrderByComparator"
179                            });
180            public static final FinderPath FINDER_PATH_COUNT_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
181                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
182                            "countByN_P",
183                            new String[] { Long.class.getName(), String.class.getName() });
184            public static final FinderPath FINDER_PATH_FIND_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
185                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
186                            "findByN_R",
187                            new String[] {
188                                    Long.class.getName(), String.class.getName(),
189                                    
190                            "java.lang.Integer", "java.lang.Integer",
191                                    "com.liferay.portal.kernel.util.OrderByComparator"
192                            });
193            public static final FinderPath FINDER_PATH_COUNT_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
194                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
195                            "countByN_R",
196                            new String[] { Long.class.getName(), String.class.getName() });
197            public static final FinderPath FINDER_PATH_FIND_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
198                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
199                            "findByN_S",
200                            new String[] {
201                                    Long.class.getName(), Integer.class.getName(),
202                                    
203                            "java.lang.Integer", "java.lang.Integer",
204                                    "com.liferay.portal.kernel.util.OrderByComparator"
205                            });
206            public static final FinderPath FINDER_PATH_COUNT_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
207                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
208                            "countByN_S",
209                            new String[] { Long.class.getName(), Integer.class.getName() });
210            public static final FinderPath FINDER_PATH_FETCH_BY_R_N_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
211                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
212                            "fetchByR_N_V",
213                            new String[] {
214                                    Long.class.getName(), Long.class.getName(),
215                                    Double.class.getName()
216                            });
217            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
218                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
219                            "countByR_N_V",
220                            new String[] {
221                                    Long.class.getName(), Long.class.getName(),
222                                    Double.class.getName()
223                            });
224            public static final FinderPath FINDER_PATH_FIND_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
225                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
226                            "findByR_N_S",
227                            new String[] {
228                                    Long.class.getName(), Long.class.getName(),
229                                    Integer.class.getName(),
230                                    
231                            "java.lang.Integer", "java.lang.Integer",
232                                    "com.liferay.portal.kernel.util.OrderByComparator"
233                            });
234            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
235                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
236                            "countByR_N_S",
237                            new String[] {
238                                    Long.class.getName(), Long.class.getName(),
239                                    Integer.class.getName()
240                            });
241            public static final FinderPath FINDER_PATH_FIND_BY_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
242                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
243                            "findByU_N_S",
244                            new String[] {
245                                    Long.class.getName(), Long.class.getName(),
246                                    Integer.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_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
252                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
253                            "countByU_N_S",
254                            new String[] {
255                                    Long.class.getName(), Long.class.getName(),
256                                    Integer.class.getName()
257                            });
258            public static final FinderPath FINDER_PATH_FETCH_BY_N_T_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
259                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
260                            "fetchByN_T_V",
261                            new String[] {
262                                    Long.class.getName(), String.class.getName(),
263                                    Double.class.getName()
264                            });
265            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
266                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
267                            "countByN_T_V",
268                            new String[] {
269                                    Long.class.getName(), String.class.getName(),
270                                    Double.class.getName()
271                            });
272            public static final FinderPath FINDER_PATH_FIND_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
273                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
274                            "findByN_T_H",
275                            new String[] {
276                                    Long.class.getName(), String.class.getName(),
277                                    Boolean.class.getName(),
278                                    
279                            "java.lang.Integer", "java.lang.Integer",
280                                    "com.liferay.portal.kernel.util.OrderByComparator"
281                            });
282            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
283                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
284                            "countByN_T_H",
285                            new String[] {
286                                    Long.class.getName(), String.class.getName(),
287                                    Boolean.class.getName()
288                            });
289            public static final FinderPath FINDER_PATH_FIND_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
290                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
291                            "findByN_T_S",
292                            new String[] {
293                                    Long.class.getName(), String.class.getName(),
294                                    Integer.class.getName(),
295                                    
296                            "java.lang.Integer", "java.lang.Integer",
297                                    "com.liferay.portal.kernel.util.OrderByComparator"
298                            });
299            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
300                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
301                            "countByN_T_S",
302                            new String[] {
303                                    Long.class.getName(), String.class.getName(),
304                                    Integer.class.getName()
305                            });
306            public static final FinderPath FINDER_PATH_FIND_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
307                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
308                            "findByN_H_P",
309                            new String[] {
310                                    Long.class.getName(), Boolean.class.getName(),
311                                    String.class.getName(),
312                                    
313                            "java.lang.Integer", "java.lang.Integer",
314                                    "com.liferay.portal.kernel.util.OrderByComparator"
315                            });
316            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
317                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
318                            "countByN_H_P",
319                            new String[] {
320                                    Long.class.getName(), Boolean.class.getName(),
321                                    String.class.getName()
322                            });
323            public static final FinderPath FINDER_PATH_FIND_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
324                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
325                            "findByN_H_S",
326                            new String[] {
327                                    Long.class.getName(), Boolean.class.getName(),
328                                    Integer.class.getName(),
329                                    
330                            "java.lang.Integer", "java.lang.Integer",
331                                    "com.liferay.portal.kernel.util.OrderByComparator"
332                            });
333            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
334                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
335                            "countByN_H_S",
336                            new String[] {
337                                    Long.class.getName(), Boolean.class.getName(),
338                                    Integer.class.getName()
339                            });
340            public static final FinderPath FINDER_PATH_FIND_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
341                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
342                            "findByN_H_P_S",
343                            new String[] {
344                                    Long.class.getName(), Boolean.class.getName(),
345                                    String.class.getName(), Integer.class.getName(),
346                                    
347                            "java.lang.Integer", "java.lang.Integer",
348                                    "com.liferay.portal.kernel.util.OrderByComparator"
349                            });
350            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
351                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
352                            "countByN_H_P_S",
353                            new String[] {
354                                    Long.class.getName(), Boolean.class.getName(),
355                                    String.class.getName(), Integer.class.getName()
356                            });
357            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
358                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
359                            "findAll", new String[0]);
360            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
361                            WikiPageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
362                            "countAll", new String[0]);
363    
364            /**
365             * Caches the wiki page in the entity cache if it is enabled.
366             *
367             * @param wikiPage the wiki page to cache
368             */
369            public void cacheResult(WikiPage wikiPage) {
370                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
371                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
372    
373                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
374                            new Object[] { wikiPage.getUuid(), new Long(wikiPage.getGroupId()) },
375                            wikiPage);
376    
377                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
378                            new Object[] {
379                                    new Long(wikiPage.getResourcePrimKey()),
380                                    new Long(wikiPage.getNodeId()),
381                                    new Double(wikiPage.getVersion())
382                            }, wikiPage);
383    
384                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
385                            new Object[] {
386                                    new Long(wikiPage.getNodeId()),
387                                    
388                            wikiPage.getTitle(), new Double(wikiPage.getVersion())
389                            }, wikiPage);
390            }
391    
392            /**
393             * Caches the wiki pages in the entity cache if it is enabled.
394             *
395             * @param wikiPages the wiki pages to cache
396             */
397            public void cacheResult(List<WikiPage> wikiPages) {
398                    for (WikiPage wikiPage : wikiPages) {
399                            if (EntityCacheUtil.getResult(
400                                                    WikiPageModelImpl.ENTITY_CACHE_ENABLED,
401                                                    WikiPageImpl.class, wikiPage.getPrimaryKey(), this) == null) {
402                                    cacheResult(wikiPage);
403                            }
404                    }
405            }
406    
407            /**
408             * Clears the cache for all wiki pages.
409             *
410             * <p>
411             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
412             * </p>
413             */
414            public void clearCache() {
415                    CacheRegistryUtil.clear(WikiPageImpl.class.getName());
416                    EntityCacheUtil.clearCache(WikiPageImpl.class.getName());
417                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
418                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
419            }
420    
421            /**
422             * Clears the cache for the wiki page.
423             *
424             * <p>
425             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
426             * </p>
427             */
428            public void clearCache(WikiPage wikiPage) {
429                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
430                            WikiPageImpl.class, wikiPage.getPrimaryKey());
431    
432                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
433                            new Object[] { wikiPage.getUuid(), new Long(wikiPage.getGroupId()) });
434    
435                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V,
436                            new Object[] {
437                                    new Long(wikiPage.getResourcePrimKey()),
438                                    new Long(wikiPage.getNodeId()),
439                                    new Double(wikiPage.getVersion())
440                            });
441    
442                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V,
443                            new Object[] {
444                                    new Long(wikiPage.getNodeId()),
445                                    
446                            wikiPage.getTitle(), new Double(wikiPage.getVersion())
447                            });
448            }
449    
450            /**
451             * Creates a new wiki page with the primary key. Does not add the wiki page to the database.
452             *
453             * @param pageId the primary key for the new wiki page
454             * @return the new wiki page
455             */
456            public WikiPage create(long pageId) {
457                    WikiPage wikiPage = new WikiPageImpl();
458    
459                    wikiPage.setNew(true);
460                    wikiPage.setPrimaryKey(pageId);
461    
462                    String uuid = PortalUUIDUtil.generate();
463    
464                    wikiPage.setUuid(uuid);
465    
466                    return wikiPage;
467            }
468    
469            /**
470             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
471             *
472             * @param primaryKey the primary key of the wiki page to remove
473             * @return the wiki page that was removed
474             * @throws com.liferay.portal.NoSuchModelException if a wiki page with the primary key could not be found
475             * @throws SystemException if a system exception occurred
476             */
477            public WikiPage remove(Serializable primaryKey)
478                    throws NoSuchModelException, SystemException {
479                    return remove(((Long)primaryKey).longValue());
480            }
481    
482            /**
483             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
484             *
485             * @param pageId the primary key of the wiki page to remove
486             * @return the wiki page that was removed
487             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
488             * @throws SystemException if a system exception occurred
489             */
490            public WikiPage remove(long pageId)
491                    throws NoSuchPageException, SystemException {
492                    Session session = null;
493    
494                    try {
495                            session = openSession();
496    
497                            WikiPage wikiPage = (WikiPage)session.get(WikiPageImpl.class,
498                                            new Long(pageId));
499    
500                            if (wikiPage == null) {
501                                    if (_log.isWarnEnabled()) {
502                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + pageId);
503                                    }
504    
505                                    throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
506                                            pageId);
507                            }
508    
509                            return remove(wikiPage);
510                    }
511                    catch (NoSuchPageException nsee) {
512                            throw nsee;
513                    }
514                    catch (Exception e) {
515                            throw processException(e);
516                    }
517                    finally {
518                            closeSession(session);
519                    }
520            }
521    
522            protected WikiPage removeImpl(WikiPage wikiPage) throws SystemException {
523                    wikiPage = toUnwrappedModel(wikiPage);
524    
525                    Session session = null;
526    
527                    try {
528                            session = openSession();
529    
530                            BatchSessionUtil.delete(session, wikiPage);
531                    }
532                    catch (Exception e) {
533                            throw processException(e);
534                    }
535                    finally {
536                            closeSession(session);
537                    }
538    
539                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
540    
541                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
542    
543                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
544                            new Object[] {
545                                    wikiPageModelImpl.getOriginalUuid(),
546                                    new Long(wikiPageModelImpl.getOriginalGroupId())
547                            });
548    
549                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V,
550                            new Object[] {
551                                    new Long(wikiPageModelImpl.getOriginalResourcePrimKey()),
552                                    new Long(wikiPageModelImpl.getOriginalNodeId()),
553                                    new Double(wikiPageModelImpl.getOriginalVersion())
554                            });
555    
556                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V,
557                            new Object[] {
558                                    new Long(wikiPageModelImpl.getOriginalNodeId()),
559                                    
560                            wikiPageModelImpl.getOriginalTitle(),
561                                    new Double(wikiPageModelImpl.getOriginalVersion())
562                            });
563    
564                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
565                            WikiPageImpl.class, wikiPage.getPrimaryKey());
566    
567                    return wikiPage;
568            }
569    
570            public WikiPage updateImpl(
571                    com.liferay.portlet.wiki.model.WikiPage wikiPage, boolean merge)
572                    throws SystemException {
573                    wikiPage = toUnwrappedModel(wikiPage);
574    
575                    boolean isNew = wikiPage.isNew();
576    
577                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
578    
579                    if (Validator.isNull(wikiPage.getUuid())) {
580                            String uuid = PortalUUIDUtil.generate();
581    
582                            wikiPage.setUuid(uuid);
583                    }
584    
585                    Session session = null;
586    
587                    try {
588                            session = openSession();
589    
590                            BatchSessionUtil.update(session, wikiPage, merge);
591    
592                            wikiPage.setNew(false);
593                    }
594                    catch (Exception e) {
595                            throw processException(e);
596                    }
597                    finally {
598                            closeSession(session);
599                    }
600    
601                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
602    
603                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
604                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
605    
606                    if (!isNew &&
607                                    (!Validator.equals(wikiPage.getUuid(),
608                                            wikiPageModelImpl.getOriginalUuid()) ||
609                                    (wikiPage.getGroupId() != wikiPageModelImpl.getOriginalGroupId()))) {
610                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
611                                    new Object[] {
612                                            wikiPageModelImpl.getOriginalUuid(),
613                                            new Long(wikiPageModelImpl.getOriginalGroupId())
614                                    });
615                    }
616    
617                    if (isNew ||
618                                    (!Validator.equals(wikiPage.getUuid(),
619                                            wikiPageModelImpl.getOriginalUuid()) ||
620                                    (wikiPage.getGroupId() != wikiPageModelImpl.getOriginalGroupId()))) {
621                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
622                                    new Object[] { wikiPage.getUuid(), new Long(
623                                                    wikiPage.getGroupId()) }, wikiPage);
624                    }
625    
626                    if (!isNew &&
627                                    ((wikiPage.getResourcePrimKey() != wikiPageModelImpl.getOriginalResourcePrimKey()) ||
628                                    (wikiPage.getNodeId() != wikiPageModelImpl.getOriginalNodeId()) ||
629                                    (wikiPage.getVersion() != wikiPageModelImpl.getOriginalVersion()))) {
630                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V,
631                                    new Object[] {
632                                            new Long(wikiPageModelImpl.getOriginalResourcePrimKey()),
633                                            new Long(wikiPageModelImpl.getOriginalNodeId()),
634                                            new Double(wikiPageModelImpl.getOriginalVersion())
635                                    });
636                    }
637    
638                    if (isNew ||
639                                    ((wikiPage.getResourcePrimKey() != wikiPageModelImpl.getOriginalResourcePrimKey()) ||
640                                    (wikiPage.getNodeId() != wikiPageModelImpl.getOriginalNodeId()) ||
641                                    (wikiPage.getVersion() != wikiPageModelImpl.getOriginalVersion()))) {
642                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
643                                    new Object[] {
644                                            new Long(wikiPage.getResourcePrimKey()),
645                                            new Long(wikiPage.getNodeId()),
646                                            new Double(wikiPage.getVersion())
647                                    }, wikiPage);
648                    }
649    
650                    if (!isNew &&
651                                    ((wikiPage.getNodeId() != wikiPageModelImpl.getOriginalNodeId()) ||
652                                    !Validator.equals(wikiPage.getTitle(),
653                                            wikiPageModelImpl.getOriginalTitle()) ||
654                                    (wikiPage.getVersion() != wikiPageModelImpl.getOriginalVersion()))) {
655                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V,
656                                    new Object[] {
657                                            new Long(wikiPageModelImpl.getOriginalNodeId()),
658                                            
659                                    wikiPageModelImpl.getOriginalTitle(),
660                                            new Double(wikiPageModelImpl.getOriginalVersion())
661                                    });
662                    }
663    
664                    if (isNew ||
665                                    ((wikiPage.getNodeId() != wikiPageModelImpl.getOriginalNodeId()) ||
666                                    !Validator.equals(wikiPage.getTitle(),
667                                            wikiPageModelImpl.getOriginalTitle()) ||
668                                    (wikiPage.getVersion() != wikiPageModelImpl.getOriginalVersion()))) {
669                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
670                                    new Object[] {
671                                            new Long(wikiPage.getNodeId()),
672                                            
673                                    wikiPage.getTitle(), new Double(wikiPage.getVersion())
674                                    }, wikiPage);
675                    }
676    
677                    return wikiPage;
678            }
679    
680            protected WikiPage toUnwrappedModel(WikiPage wikiPage) {
681                    if (wikiPage instanceof WikiPageImpl) {
682                            return wikiPage;
683                    }
684    
685                    WikiPageImpl wikiPageImpl = new WikiPageImpl();
686    
687                    wikiPageImpl.setNew(wikiPage.isNew());
688                    wikiPageImpl.setPrimaryKey(wikiPage.getPrimaryKey());
689    
690                    wikiPageImpl.setUuid(wikiPage.getUuid());
691                    wikiPageImpl.setPageId(wikiPage.getPageId());
692                    wikiPageImpl.setResourcePrimKey(wikiPage.getResourcePrimKey());
693                    wikiPageImpl.setGroupId(wikiPage.getGroupId());
694                    wikiPageImpl.setCompanyId(wikiPage.getCompanyId());
695                    wikiPageImpl.setUserId(wikiPage.getUserId());
696                    wikiPageImpl.setUserName(wikiPage.getUserName());
697                    wikiPageImpl.setCreateDate(wikiPage.getCreateDate());
698                    wikiPageImpl.setModifiedDate(wikiPage.getModifiedDate());
699                    wikiPageImpl.setNodeId(wikiPage.getNodeId());
700                    wikiPageImpl.setTitle(wikiPage.getTitle());
701                    wikiPageImpl.setVersion(wikiPage.getVersion());
702                    wikiPageImpl.setMinorEdit(wikiPage.isMinorEdit());
703                    wikiPageImpl.setContent(wikiPage.getContent());
704                    wikiPageImpl.setSummary(wikiPage.getSummary());
705                    wikiPageImpl.setFormat(wikiPage.getFormat());
706                    wikiPageImpl.setHead(wikiPage.isHead());
707                    wikiPageImpl.setParentTitle(wikiPage.getParentTitle());
708                    wikiPageImpl.setRedirectTitle(wikiPage.getRedirectTitle());
709                    wikiPageImpl.setStatus(wikiPage.getStatus());
710                    wikiPageImpl.setStatusByUserId(wikiPage.getStatusByUserId());
711                    wikiPageImpl.setStatusByUserName(wikiPage.getStatusByUserName());
712                    wikiPageImpl.setStatusDate(wikiPage.getStatusDate());
713    
714                    return wikiPageImpl;
715            }
716    
717            /**
718             * Finds the wiki page with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
719             *
720             * @param primaryKey the primary key of the wiki page to find
721             * @return the wiki page
722             * @throws com.liferay.portal.NoSuchModelException if a wiki page with the primary key could not be found
723             * @throws SystemException if a system exception occurred
724             */
725            public WikiPage findByPrimaryKey(Serializable primaryKey)
726                    throws NoSuchModelException, SystemException {
727                    return findByPrimaryKey(((Long)primaryKey).longValue());
728            }
729    
730            /**
731             * Finds the wiki page with the primary key or throws a {@link com.liferay.portlet.wiki.NoSuchPageException} if it could not be found.
732             *
733             * @param pageId the primary key of the wiki page to find
734             * @return the wiki page
735             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
736             * @throws SystemException if a system exception occurred
737             */
738            public WikiPage findByPrimaryKey(long pageId)
739                    throws NoSuchPageException, SystemException {
740                    WikiPage wikiPage = fetchByPrimaryKey(pageId);
741    
742                    if (wikiPage == null) {
743                            if (_log.isWarnEnabled()) {
744                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + pageId);
745                            }
746    
747                            throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
748                                    pageId);
749                    }
750    
751                    return wikiPage;
752            }
753    
754            /**
755             * Finds the wiki page with the primary key or returns <code>null</code> if it could not be found.
756             *
757             * @param primaryKey the primary key of the wiki page to find
758             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
759             * @throws SystemException if a system exception occurred
760             */
761            public WikiPage fetchByPrimaryKey(Serializable primaryKey)
762                    throws SystemException {
763                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
764            }
765    
766            /**
767             * Finds the wiki page with the primary key or returns <code>null</code> if it could not be found.
768             *
769             * @param pageId the primary key of the wiki page to find
770             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
771             * @throws SystemException if a system exception occurred
772             */
773            public WikiPage fetchByPrimaryKey(long pageId) throws SystemException {
774                    WikiPage wikiPage = (WikiPage)EntityCacheUtil.getResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
775                                    WikiPageImpl.class, pageId, this);
776    
777                    if (wikiPage == null) {
778                            Session session = null;
779    
780                            try {
781                                    session = openSession();
782    
783                                    wikiPage = (WikiPage)session.get(WikiPageImpl.class,
784                                                    new Long(pageId));
785                            }
786                            catch (Exception e) {
787                                    throw processException(e);
788                            }
789                            finally {
790                                    if (wikiPage != null) {
791                                            cacheResult(wikiPage);
792                                    }
793    
794                                    closeSession(session);
795                            }
796                    }
797    
798                    return wikiPage;
799            }
800    
801            /**
802             * Finds all the wiki pages where uuid = &#63;.
803             *
804             * @param uuid the uuid to search with
805             * @return the matching wiki pages
806             * @throws SystemException if a system exception occurred
807             */
808            public List<WikiPage> findByUuid(String uuid) throws SystemException {
809                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
810            }
811    
812            /**
813             * Finds a range of all the wiki pages where uuid = &#63;.
814             *
815             * <p>
816             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
817             * </p>
818             *
819             * @param uuid the uuid to search with
820             * @param start the lower bound of the range of wiki pages to return
821             * @param end the upper bound of the range of wiki pages to return (not inclusive)
822             * @return the range of matching wiki pages
823             * @throws SystemException if a system exception occurred
824             */
825            public List<WikiPage> findByUuid(String uuid, int start, int end)
826                    throws SystemException {
827                    return findByUuid(uuid, start, end, null);
828            }
829    
830            /**
831             * Finds an ordered range of all the wiki pages where uuid = &#63;.
832             *
833             * <p>
834             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
835             * </p>
836             *
837             * @param uuid the uuid to search with
838             * @param start the lower bound of the range of wiki pages to return
839             * @param end the upper bound of the range of wiki pages to return (not inclusive)
840             * @param orderByComparator the comparator to order the results by
841             * @return the ordered range of matching wiki pages
842             * @throws SystemException if a system exception occurred
843             */
844            public List<WikiPage> findByUuid(String uuid, int start, int end,
845                    OrderByComparator orderByComparator) throws SystemException {
846                    Object[] finderArgs = new Object[] {
847                                    uuid,
848                                    
849                                    String.valueOf(start), String.valueOf(end),
850                                    String.valueOf(orderByComparator)
851                            };
852    
853                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
854                                    finderArgs, this);
855    
856                    if (list == null) {
857                            Session session = null;
858    
859                            try {
860                                    session = openSession();
861    
862                                    StringBundler query = null;
863    
864                                    if (orderByComparator != null) {
865                                            query = new StringBundler(3 +
866                                                            (orderByComparator.getOrderByFields().length * 3));
867                                    }
868                                    else {
869                                            query = new StringBundler(3);
870                                    }
871    
872                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
873    
874                                    if (uuid == null) {
875                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
876                                    }
877                                    else {
878                                            if (uuid.equals(StringPool.BLANK)) {
879                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
880                                            }
881                                            else {
882                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
883                                            }
884                                    }
885    
886                                    if (orderByComparator != null) {
887                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
888                                                    orderByComparator);
889                                    }
890    
891                                    else {
892                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
893                                    }
894    
895                                    String sql = query.toString();
896    
897                                    Query q = session.createQuery(sql);
898    
899                                    QueryPos qPos = QueryPos.getInstance(q);
900    
901                                    if (uuid != null) {
902                                            qPos.add(uuid);
903                                    }
904    
905                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
906                                                    end);
907                            }
908                            catch (Exception e) {
909                                    throw processException(e);
910                            }
911                            finally {
912                                    if (list == null) {
913                                            list = new ArrayList<WikiPage>();
914                                    }
915    
916                                    cacheResult(list);
917    
918                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
919                                            list);
920    
921                                    closeSession(session);
922                            }
923                    }
924    
925                    return list;
926            }
927    
928            /**
929             * Finds the first wiki page in the ordered set where uuid = &#63;.
930             *
931             * <p>
932             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
933             * </p>
934             *
935             * @param uuid the uuid to search with
936             * @param orderByComparator the comparator to order the set by
937             * @return the first matching wiki page
938             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
939             * @throws SystemException if a system exception occurred
940             */
941            public WikiPage findByUuid_First(String uuid,
942                    OrderByComparator orderByComparator)
943                    throws NoSuchPageException, SystemException {
944                    List<WikiPage> list = findByUuid(uuid, 0, 1, orderByComparator);
945    
946                    if (list.isEmpty()) {
947                            StringBundler msg = new StringBundler(4);
948    
949                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
950    
951                            msg.append("uuid=");
952                            msg.append(uuid);
953    
954                            msg.append(StringPool.CLOSE_CURLY_BRACE);
955    
956                            throw new NoSuchPageException(msg.toString());
957                    }
958                    else {
959                            return list.get(0);
960                    }
961            }
962    
963            /**
964             * Finds the last wiki page in the ordered set where uuid = &#63;.
965             *
966             * <p>
967             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
968             * </p>
969             *
970             * @param uuid the uuid to search with
971             * @param orderByComparator the comparator to order the set by
972             * @return the last matching wiki page
973             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
974             * @throws SystemException if a system exception occurred
975             */
976            public WikiPage findByUuid_Last(String uuid,
977                    OrderByComparator orderByComparator)
978                    throws NoSuchPageException, SystemException {
979                    int count = countByUuid(uuid);
980    
981                    List<WikiPage> list = findByUuid(uuid, count - 1, count,
982                                    orderByComparator);
983    
984                    if (list.isEmpty()) {
985                            StringBundler msg = new StringBundler(4);
986    
987                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
988    
989                            msg.append("uuid=");
990                            msg.append(uuid);
991    
992                            msg.append(StringPool.CLOSE_CURLY_BRACE);
993    
994                            throw new NoSuchPageException(msg.toString());
995                    }
996                    else {
997                            return list.get(0);
998                    }
999            }
1000    
1001            /**
1002             * Finds the wiki pages before and after the current wiki page in the ordered set where uuid = &#63;.
1003             *
1004             * <p>
1005             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1006             * </p>
1007             *
1008             * @param pageId the primary key of the current wiki page
1009             * @param uuid the uuid to search with
1010             * @param orderByComparator the comparator to order the set by
1011             * @return the previous, current, and next wiki page
1012             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
1013             * @throws SystemException if a system exception occurred
1014             */
1015            public WikiPage[] findByUuid_PrevAndNext(long pageId, String uuid,
1016                    OrderByComparator orderByComparator)
1017                    throws NoSuchPageException, SystemException {
1018                    WikiPage wikiPage = findByPrimaryKey(pageId);
1019    
1020                    Session session = null;
1021    
1022                    try {
1023                            session = openSession();
1024    
1025                            WikiPage[] array = new WikiPageImpl[3];
1026    
1027                            array[0] = getByUuid_PrevAndNext(session, wikiPage, uuid,
1028                                            orderByComparator, true);
1029    
1030                            array[1] = wikiPage;
1031    
1032                            array[2] = getByUuid_PrevAndNext(session, wikiPage, uuid,
1033                                            orderByComparator, false);
1034    
1035                            return array;
1036                    }
1037                    catch (Exception e) {
1038                            throw processException(e);
1039                    }
1040                    finally {
1041                            closeSession(session);
1042                    }
1043            }
1044    
1045            protected WikiPage getByUuid_PrevAndNext(Session session,
1046                    WikiPage wikiPage, String uuid, OrderByComparator orderByComparator,
1047                    boolean previous) {
1048                    StringBundler query = null;
1049    
1050                    if (orderByComparator != null) {
1051                            query = new StringBundler(6 +
1052                                            (orderByComparator.getOrderByFields().length * 6));
1053                    }
1054                    else {
1055                            query = new StringBundler(3);
1056                    }
1057    
1058                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1059    
1060                    if (uuid == null) {
1061                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1062                    }
1063                    else {
1064                            if (uuid.equals(StringPool.BLANK)) {
1065                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1066                            }
1067                            else {
1068                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1069                            }
1070                    }
1071    
1072                    if (orderByComparator != null) {
1073                            String[] orderByFields = orderByComparator.getOrderByFields();
1074    
1075                            if (orderByFields.length > 0) {
1076                                    query.append(WHERE_AND);
1077                            }
1078    
1079                            for (int i = 0; i < orderByFields.length; i++) {
1080                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1081                                    query.append(orderByFields[i]);
1082    
1083                                    if ((i + 1) < orderByFields.length) {
1084                                            if (orderByComparator.isAscending() ^ previous) {
1085                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1086                                            }
1087                                            else {
1088                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1089                                            }
1090                                    }
1091                                    else {
1092                                            if (orderByComparator.isAscending() ^ previous) {
1093                                                    query.append(WHERE_GREATER_THAN);
1094                                            }
1095                                            else {
1096                                                    query.append(WHERE_LESSER_THAN);
1097                                            }
1098                                    }
1099                            }
1100    
1101                            query.append(ORDER_BY_CLAUSE);
1102    
1103                            for (int i = 0; i < orderByFields.length; i++) {
1104                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1105                                    query.append(orderByFields[i]);
1106    
1107                                    if ((i + 1) < orderByFields.length) {
1108                                            if (orderByComparator.isAscending() ^ previous) {
1109                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1110                                            }
1111                                            else {
1112                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1113                                            }
1114                                    }
1115                                    else {
1116                                            if (orderByComparator.isAscending() ^ previous) {
1117                                                    query.append(ORDER_BY_ASC);
1118                                            }
1119                                            else {
1120                                                    query.append(ORDER_BY_DESC);
1121                                            }
1122                                    }
1123                            }
1124                    }
1125    
1126                    else {
1127                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1128                    }
1129    
1130                    String sql = query.toString();
1131    
1132                    Query q = session.createQuery(sql);
1133    
1134                    q.setFirstResult(0);
1135                    q.setMaxResults(2);
1136    
1137                    QueryPos qPos = QueryPos.getInstance(q);
1138    
1139                    if (uuid != null) {
1140                            qPos.add(uuid);
1141                    }
1142    
1143                    if (orderByComparator != null) {
1144                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
1145    
1146                            for (Object value : values) {
1147                                    qPos.add(value);
1148                            }
1149                    }
1150    
1151                    List<WikiPage> list = q.list();
1152    
1153                    if (list.size() == 2) {
1154                            return list.get(1);
1155                    }
1156                    else {
1157                            return null;
1158                    }
1159            }
1160    
1161            /**
1162             * Finds the wiki page where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.wiki.NoSuchPageException} if it could not be found.
1163             *
1164             * @param uuid the uuid to search with
1165             * @param groupId the group id to search with
1166             * @return the matching wiki page
1167             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1168             * @throws SystemException if a system exception occurred
1169             */
1170            public WikiPage findByUUID_G(String uuid, long groupId)
1171                    throws NoSuchPageException, SystemException {
1172                    WikiPage wikiPage = fetchByUUID_G(uuid, groupId);
1173    
1174                    if (wikiPage == null) {
1175                            StringBundler msg = new StringBundler(6);
1176    
1177                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1178    
1179                            msg.append("uuid=");
1180                            msg.append(uuid);
1181    
1182                            msg.append(", groupId=");
1183                            msg.append(groupId);
1184    
1185                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1186    
1187                            if (_log.isWarnEnabled()) {
1188                                    _log.warn(msg.toString());
1189                            }
1190    
1191                            throw new NoSuchPageException(msg.toString());
1192                    }
1193    
1194                    return wikiPage;
1195            }
1196    
1197            /**
1198             * Finds the wiki page where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1199             *
1200             * @param uuid the uuid to search with
1201             * @param groupId the group id to search with
1202             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
1203             * @throws SystemException if a system exception occurred
1204             */
1205            public WikiPage fetchByUUID_G(String uuid, long groupId)
1206                    throws SystemException {
1207                    return fetchByUUID_G(uuid, groupId, true);
1208            }
1209    
1210            /**
1211             * Finds the wiki page where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1212             *
1213             * @param uuid the uuid to search with
1214             * @param groupId the group id to search with
1215             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
1216             * @throws SystemException if a system exception occurred
1217             */
1218            public WikiPage fetchByUUID_G(String uuid, long groupId,
1219                    boolean retrieveFromCache) throws SystemException {
1220                    Object[] finderArgs = new Object[] { uuid, groupId };
1221    
1222                    Object result = null;
1223    
1224                    if (retrieveFromCache) {
1225                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1226                                            finderArgs, this);
1227                    }
1228    
1229                    if (result == null) {
1230                            Session session = null;
1231    
1232                            try {
1233                                    session = openSession();
1234    
1235                                    StringBundler query = new StringBundler(4);
1236    
1237                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1238    
1239                                    if (uuid == null) {
1240                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1241                                    }
1242                                    else {
1243                                            if (uuid.equals(StringPool.BLANK)) {
1244                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1245                                            }
1246                                            else {
1247                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1248                                            }
1249                                    }
1250    
1251                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1252    
1253                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1254    
1255                                    String sql = query.toString();
1256    
1257                                    Query q = session.createQuery(sql);
1258    
1259                                    QueryPos qPos = QueryPos.getInstance(q);
1260    
1261                                    if (uuid != null) {
1262                                            qPos.add(uuid);
1263                                    }
1264    
1265                                    qPos.add(groupId);
1266    
1267                                    List<WikiPage> list = q.list();
1268    
1269                                    result = list;
1270    
1271                                    WikiPage wikiPage = null;
1272    
1273                                    if (list.isEmpty()) {
1274                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1275                                                    finderArgs, list);
1276                                    }
1277                                    else {
1278                                            wikiPage = list.get(0);
1279    
1280                                            cacheResult(wikiPage);
1281    
1282                                            if ((wikiPage.getUuid() == null) ||
1283                                                            !wikiPage.getUuid().equals(uuid) ||
1284                                                            (wikiPage.getGroupId() != groupId)) {
1285                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1286                                                            finderArgs, wikiPage);
1287                                            }
1288                                    }
1289    
1290                                    return wikiPage;
1291                            }
1292                            catch (Exception e) {
1293                                    throw processException(e);
1294                            }
1295                            finally {
1296                                    if (result == null) {
1297                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1298                                                    finderArgs, new ArrayList<WikiPage>());
1299                                    }
1300    
1301                                    closeSession(session);
1302                            }
1303                    }
1304                    else {
1305                            if (result instanceof List<?>) {
1306                                    return null;
1307                            }
1308                            else {
1309                                    return (WikiPage)result;
1310                            }
1311                    }
1312            }
1313    
1314            /**
1315             * Finds all the wiki pages where nodeId = &#63;.
1316             *
1317             * @param nodeId the node id to search with
1318             * @return the matching wiki pages
1319             * @throws SystemException if a system exception occurred
1320             */
1321            public List<WikiPage> findByNodeId(long nodeId) throws SystemException {
1322                    return findByNodeId(nodeId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1323            }
1324    
1325            /**
1326             * Finds a range of all the wiki pages where nodeId = &#63;.
1327             *
1328             * <p>
1329             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1330             * </p>
1331             *
1332             * @param nodeId the node id to search with
1333             * @param start the lower bound of the range of wiki pages to return
1334             * @param end the upper bound of the range of wiki pages to return (not inclusive)
1335             * @return the range of matching wiki pages
1336             * @throws SystemException if a system exception occurred
1337             */
1338            public List<WikiPage> findByNodeId(long nodeId, int start, int end)
1339                    throws SystemException {
1340                    return findByNodeId(nodeId, start, end, null);
1341            }
1342    
1343            /**
1344             * Finds an ordered range of all the wiki pages where nodeId = &#63;.
1345             *
1346             * <p>
1347             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1348             * </p>
1349             *
1350             * @param nodeId the node id to search with
1351             * @param start the lower bound of the range of wiki pages to return
1352             * @param end the upper bound of the range of wiki pages to return (not inclusive)
1353             * @param orderByComparator the comparator to order the results by
1354             * @return the ordered range of matching wiki pages
1355             * @throws SystemException if a system exception occurred
1356             */
1357            public List<WikiPage> findByNodeId(long nodeId, int start, int end,
1358                    OrderByComparator orderByComparator) throws SystemException {
1359                    Object[] finderArgs = new Object[] {
1360                                    nodeId,
1361                                    
1362                                    String.valueOf(start), String.valueOf(end),
1363                                    String.valueOf(orderByComparator)
1364                            };
1365    
1366                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_NODEID,
1367                                    finderArgs, this);
1368    
1369                    if (list == null) {
1370                            Session session = null;
1371    
1372                            try {
1373                                    session = openSession();
1374    
1375                                    StringBundler query = null;
1376    
1377                                    if (orderByComparator != null) {
1378                                            query = new StringBundler(3 +
1379                                                            (orderByComparator.getOrderByFields().length * 3));
1380                                    }
1381                                    else {
1382                                            query = new StringBundler(3);
1383                                    }
1384    
1385                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1386    
1387                                    query.append(_FINDER_COLUMN_NODEID_NODEID_2);
1388    
1389                                    if (orderByComparator != null) {
1390                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1391                                                    orderByComparator);
1392                                    }
1393    
1394                                    else {
1395                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1396                                    }
1397    
1398                                    String sql = query.toString();
1399    
1400                                    Query q = session.createQuery(sql);
1401    
1402                                    QueryPos qPos = QueryPos.getInstance(q);
1403    
1404                                    qPos.add(nodeId);
1405    
1406                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
1407                                                    end);
1408                            }
1409                            catch (Exception e) {
1410                                    throw processException(e);
1411                            }
1412                            finally {
1413                                    if (list == null) {
1414                                            list = new ArrayList<WikiPage>();
1415                                    }
1416    
1417                                    cacheResult(list);
1418    
1419                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_NODEID,
1420                                            finderArgs, list);
1421    
1422                                    closeSession(session);
1423                            }
1424                    }
1425    
1426                    return list;
1427            }
1428    
1429            /**
1430             * Finds the first wiki page in the ordered set where nodeId = &#63;.
1431             *
1432             * <p>
1433             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1434             * </p>
1435             *
1436             * @param nodeId the node id to search with
1437             * @param orderByComparator the comparator to order the set by
1438             * @return the first matching wiki page
1439             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1440             * @throws SystemException if a system exception occurred
1441             */
1442            public WikiPage findByNodeId_First(long nodeId,
1443                    OrderByComparator orderByComparator)
1444                    throws NoSuchPageException, SystemException {
1445                    List<WikiPage> list = findByNodeId(nodeId, 0, 1, orderByComparator);
1446    
1447                    if (list.isEmpty()) {
1448                            StringBundler msg = new StringBundler(4);
1449    
1450                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1451    
1452                            msg.append("nodeId=");
1453                            msg.append(nodeId);
1454    
1455                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1456    
1457                            throw new NoSuchPageException(msg.toString());
1458                    }
1459                    else {
1460                            return list.get(0);
1461                    }
1462            }
1463    
1464            /**
1465             * Finds the last wiki page in the ordered set where nodeId = &#63;.
1466             *
1467             * <p>
1468             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1469             * </p>
1470             *
1471             * @param nodeId the node id to search with
1472             * @param orderByComparator the comparator to order the set by
1473             * @return the last matching wiki page
1474             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1475             * @throws SystemException if a system exception occurred
1476             */
1477            public WikiPage findByNodeId_Last(long nodeId,
1478                    OrderByComparator orderByComparator)
1479                    throws NoSuchPageException, SystemException {
1480                    int count = countByNodeId(nodeId);
1481    
1482                    List<WikiPage> list = findByNodeId(nodeId, count - 1, count,
1483                                    orderByComparator);
1484    
1485                    if (list.isEmpty()) {
1486                            StringBundler msg = new StringBundler(4);
1487    
1488                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1489    
1490                            msg.append("nodeId=");
1491                            msg.append(nodeId);
1492    
1493                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1494    
1495                            throw new NoSuchPageException(msg.toString());
1496                    }
1497                    else {
1498                            return list.get(0);
1499                    }
1500            }
1501    
1502            /**
1503             * Finds the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63;.
1504             *
1505             * <p>
1506             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1507             * </p>
1508             *
1509             * @param pageId the primary key of the current wiki page
1510             * @param nodeId the node id to search with
1511             * @param orderByComparator the comparator to order the set by
1512             * @return the previous, current, and next wiki page
1513             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
1514             * @throws SystemException if a system exception occurred
1515             */
1516            public WikiPage[] findByNodeId_PrevAndNext(long pageId, long nodeId,
1517                    OrderByComparator orderByComparator)
1518                    throws NoSuchPageException, SystemException {
1519                    WikiPage wikiPage = findByPrimaryKey(pageId);
1520    
1521                    Session session = null;
1522    
1523                    try {
1524                            session = openSession();
1525    
1526                            WikiPage[] array = new WikiPageImpl[3];
1527    
1528                            array[0] = getByNodeId_PrevAndNext(session, wikiPage, nodeId,
1529                                            orderByComparator, true);
1530    
1531                            array[1] = wikiPage;
1532    
1533                            array[2] = getByNodeId_PrevAndNext(session, wikiPage, nodeId,
1534                                            orderByComparator, false);
1535    
1536                            return array;
1537                    }
1538                    catch (Exception e) {
1539                            throw processException(e);
1540                    }
1541                    finally {
1542                            closeSession(session);
1543                    }
1544            }
1545    
1546            protected WikiPage getByNodeId_PrevAndNext(Session session,
1547                    WikiPage wikiPage, long nodeId, OrderByComparator orderByComparator,
1548                    boolean previous) {
1549                    StringBundler query = null;
1550    
1551                    if (orderByComparator != null) {
1552                            query = new StringBundler(6 +
1553                                            (orderByComparator.getOrderByFields().length * 6));
1554                    }
1555                    else {
1556                            query = new StringBundler(3);
1557                    }
1558    
1559                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1560    
1561                    query.append(_FINDER_COLUMN_NODEID_NODEID_2);
1562    
1563                    if (orderByComparator != null) {
1564                            String[] orderByFields = orderByComparator.getOrderByFields();
1565    
1566                            if (orderByFields.length > 0) {
1567                                    query.append(WHERE_AND);
1568                            }
1569    
1570                            for (int i = 0; i < orderByFields.length; i++) {
1571                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1572                                    query.append(orderByFields[i]);
1573    
1574                                    if ((i + 1) < orderByFields.length) {
1575                                            if (orderByComparator.isAscending() ^ previous) {
1576                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1577                                            }
1578                                            else {
1579                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1580                                            }
1581                                    }
1582                                    else {
1583                                            if (orderByComparator.isAscending() ^ previous) {
1584                                                    query.append(WHERE_GREATER_THAN);
1585                                            }
1586                                            else {
1587                                                    query.append(WHERE_LESSER_THAN);
1588                                            }
1589                                    }
1590                            }
1591    
1592                            query.append(ORDER_BY_CLAUSE);
1593    
1594                            for (int i = 0; i < orderByFields.length; i++) {
1595                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1596                                    query.append(orderByFields[i]);
1597    
1598                                    if ((i + 1) < orderByFields.length) {
1599                                            if (orderByComparator.isAscending() ^ previous) {
1600                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1601                                            }
1602                                            else {
1603                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1604                                            }
1605                                    }
1606                                    else {
1607                                            if (orderByComparator.isAscending() ^ previous) {
1608                                                    query.append(ORDER_BY_ASC);
1609                                            }
1610                                            else {
1611                                                    query.append(ORDER_BY_DESC);
1612                                            }
1613                                    }
1614                            }
1615                    }
1616    
1617                    else {
1618                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1619                    }
1620    
1621                    String sql = query.toString();
1622    
1623                    Query q = session.createQuery(sql);
1624    
1625                    q.setFirstResult(0);
1626                    q.setMaxResults(2);
1627    
1628                    QueryPos qPos = QueryPos.getInstance(q);
1629    
1630                    qPos.add(nodeId);
1631    
1632                    if (orderByComparator != null) {
1633                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
1634    
1635                            for (Object value : values) {
1636                                    qPos.add(value);
1637                            }
1638                    }
1639    
1640                    List<WikiPage> list = q.list();
1641    
1642                    if (list.size() == 2) {
1643                            return list.get(1);
1644                    }
1645                    else {
1646                            return null;
1647                    }
1648            }
1649    
1650            /**
1651             * Finds all the wiki pages where format = &#63;.
1652             *
1653             * @param format the format to search with
1654             * @return the matching wiki pages
1655             * @throws SystemException if a system exception occurred
1656             */
1657            public List<WikiPage> findByFormat(String format) throws SystemException {
1658                    return findByFormat(format, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1659            }
1660    
1661            /**
1662             * Finds a range of all the wiki pages where format = &#63;.
1663             *
1664             * <p>
1665             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1666             * </p>
1667             *
1668             * @param format the format to search with
1669             * @param start the lower bound of the range of wiki pages to return
1670             * @param end the upper bound of the range of wiki pages to return (not inclusive)
1671             * @return the range of matching wiki pages
1672             * @throws SystemException if a system exception occurred
1673             */
1674            public List<WikiPage> findByFormat(String format, int start, int end)
1675                    throws SystemException {
1676                    return findByFormat(format, start, end, null);
1677            }
1678    
1679            /**
1680             * Finds an ordered range of all the wiki pages where format = &#63;.
1681             *
1682             * <p>
1683             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1684             * </p>
1685             *
1686             * @param format the format to search with
1687             * @param start the lower bound of the range of wiki pages to return
1688             * @param end the upper bound of the range of wiki pages to return (not inclusive)
1689             * @param orderByComparator the comparator to order the results by
1690             * @return the ordered range of matching wiki pages
1691             * @throws SystemException if a system exception occurred
1692             */
1693            public List<WikiPage> findByFormat(String format, int start, int end,
1694                    OrderByComparator orderByComparator) throws SystemException {
1695                    Object[] finderArgs = new Object[] {
1696                                    format,
1697                                    
1698                                    String.valueOf(start), String.valueOf(end),
1699                                    String.valueOf(orderByComparator)
1700                            };
1701    
1702                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_FORMAT,
1703                                    finderArgs, this);
1704    
1705                    if (list == null) {
1706                            Session session = null;
1707    
1708                            try {
1709                                    session = openSession();
1710    
1711                                    StringBundler query = null;
1712    
1713                                    if (orderByComparator != null) {
1714                                            query = new StringBundler(3 +
1715                                                            (orderByComparator.getOrderByFields().length * 3));
1716                                    }
1717                                    else {
1718                                            query = new StringBundler(3);
1719                                    }
1720    
1721                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1722    
1723                                    if (format == null) {
1724                                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
1725                                    }
1726                                    else {
1727                                            if (format.equals(StringPool.BLANK)) {
1728                                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
1729                                            }
1730                                            else {
1731                                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
1732                                            }
1733                                    }
1734    
1735                                    if (orderByComparator != null) {
1736                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1737                                                    orderByComparator);
1738                                    }
1739    
1740                                    else {
1741                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1742                                    }
1743    
1744                                    String sql = query.toString();
1745    
1746                                    Query q = session.createQuery(sql);
1747    
1748                                    QueryPos qPos = QueryPos.getInstance(q);
1749    
1750                                    if (format != null) {
1751                                            qPos.add(format);
1752                                    }
1753    
1754                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
1755                                                    end);
1756                            }
1757                            catch (Exception e) {
1758                                    throw processException(e);
1759                            }
1760                            finally {
1761                                    if (list == null) {
1762                                            list = new ArrayList<WikiPage>();
1763                                    }
1764    
1765                                    cacheResult(list);
1766    
1767                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_FORMAT,
1768                                            finderArgs, list);
1769    
1770                                    closeSession(session);
1771                            }
1772                    }
1773    
1774                    return list;
1775            }
1776    
1777            /**
1778             * Finds the first wiki page in the ordered set where format = &#63;.
1779             *
1780             * <p>
1781             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1782             * </p>
1783             *
1784             * @param format the format to search with
1785             * @param orderByComparator the comparator to order the set by
1786             * @return the first matching wiki page
1787             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1788             * @throws SystemException if a system exception occurred
1789             */
1790            public WikiPage findByFormat_First(String format,
1791                    OrderByComparator orderByComparator)
1792                    throws NoSuchPageException, SystemException {
1793                    List<WikiPage> list = findByFormat(format, 0, 1, orderByComparator);
1794    
1795                    if (list.isEmpty()) {
1796                            StringBundler msg = new StringBundler(4);
1797    
1798                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1799    
1800                            msg.append("format=");
1801                            msg.append(format);
1802    
1803                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1804    
1805                            throw new NoSuchPageException(msg.toString());
1806                    }
1807                    else {
1808                            return list.get(0);
1809                    }
1810            }
1811    
1812            /**
1813             * Finds the last wiki page in the ordered set where format = &#63;.
1814             *
1815             * <p>
1816             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1817             * </p>
1818             *
1819             * @param format the format to search with
1820             * @param orderByComparator the comparator to order the set by
1821             * @return the last matching wiki page
1822             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1823             * @throws SystemException if a system exception occurred
1824             */
1825            public WikiPage findByFormat_Last(String format,
1826                    OrderByComparator orderByComparator)
1827                    throws NoSuchPageException, SystemException {
1828                    int count = countByFormat(format);
1829    
1830                    List<WikiPage> list = findByFormat(format, count - 1, count,
1831                                    orderByComparator);
1832    
1833                    if (list.isEmpty()) {
1834                            StringBundler msg = new StringBundler(4);
1835    
1836                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1837    
1838                            msg.append("format=");
1839                            msg.append(format);
1840    
1841                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1842    
1843                            throw new NoSuchPageException(msg.toString());
1844                    }
1845                    else {
1846                            return list.get(0);
1847                    }
1848            }
1849    
1850            /**
1851             * Finds the wiki pages before and after the current wiki page in the ordered set where format = &#63;.
1852             *
1853             * <p>
1854             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1855             * </p>
1856             *
1857             * @param pageId the primary key of the current wiki page
1858             * @param format the format to search with
1859             * @param orderByComparator the comparator to order the set by
1860             * @return the previous, current, and next wiki page
1861             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
1862             * @throws SystemException if a system exception occurred
1863             */
1864            public WikiPage[] findByFormat_PrevAndNext(long pageId, String format,
1865                    OrderByComparator orderByComparator)
1866                    throws NoSuchPageException, SystemException {
1867                    WikiPage wikiPage = findByPrimaryKey(pageId);
1868    
1869                    Session session = null;
1870    
1871                    try {
1872                            session = openSession();
1873    
1874                            WikiPage[] array = new WikiPageImpl[3];
1875    
1876                            array[0] = getByFormat_PrevAndNext(session, wikiPage, format,
1877                                            orderByComparator, true);
1878    
1879                            array[1] = wikiPage;
1880    
1881                            array[2] = getByFormat_PrevAndNext(session, wikiPage, format,
1882                                            orderByComparator, false);
1883    
1884                            return array;
1885                    }
1886                    catch (Exception e) {
1887                            throw processException(e);
1888                    }
1889                    finally {
1890                            closeSession(session);
1891                    }
1892            }
1893    
1894            protected WikiPage getByFormat_PrevAndNext(Session session,
1895                    WikiPage wikiPage, String format, OrderByComparator orderByComparator,
1896                    boolean previous) {
1897                    StringBundler query = null;
1898    
1899                    if (orderByComparator != null) {
1900                            query = new StringBundler(6 +
1901                                            (orderByComparator.getOrderByFields().length * 6));
1902                    }
1903                    else {
1904                            query = new StringBundler(3);
1905                    }
1906    
1907                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1908    
1909                    if (format == null) {
1910                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
1911                    }
1912                    else {
1913                            if (format.equals(StringPool.BLANK)) {
1914                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
1915                            }
1916                            else {
1917                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
1918                            }
1919                    }
1920    
1921                    if (orderByComparator != null) {
1922                            String[] orderByFields = orderByComparator.getOrderByFields();
1923    
1924                            if (orderByFields.length > 0) {
1925                                    query.append(WHERE_AND);
1926                            }
1927    
1928                            for (int i = 0; i < orderByFields.length; i++) {
1929                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1930                                    query.append(orderByFields[i]);
1931    
1932                                    if ((i + 1) < orderByFields.length) {
1933                                            if (orderByComparator.isAscending() ^ previous) {
1934                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1935                                            }
1936                                            else {
1937                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1938                                            }
1939                                    }
1940                                    else {
1941                                            if (orderByComparator.isAscending() ^ previous) {
1942                                                    query.append(WHERE_GREATER_THAN);
1943                                            }
1944                                            else {
1945                                                    query.append(WHERE_LESSER_THAN);
1946                                            }
1947                                    }
1948                            }
1949    
1950                            query.append(ORDER_BY_CLAUSE);
1951    
1952                            for (int i = 0; i < orderByFields.length; i++) {
1953                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1954                                    query.append(orderByFields[i]);
1955    
1956                                    if ((i + 1) < orderByFields.length) {
1957                                            if (orderByComparator.isAscending() ^ previous) {
1958                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1959                                            }
1960                                            else {
1961                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1962                                            }
1963                                    }
1964                                    else {
1965                                            if (orderByComparator.isAscending() ^ previous) {
1966                                                    query.append(ORDER_BY_ASC);
1967                                            }
1968                                            else {
1969                                                    query.append(ORDER_BY_DESC);
1970                                            }
1971                                    }
1972                            }
1973                    }
1974    
1975                    else {
1976                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1977                    }
1978    
1979                    String sql = query.toString();
1980    
1981                    Query q = session.createQuery(sql);
1982    
1983                    q.setFirstResult(0);
1984                    q.setMaxResults(2);
1985    
1986                    QueryPos qPos = QueryPos.getInstance(q);
1987    
1988                    if (format != null) {
1989                            qPos.add(format);
1990                    }
1991    
1992                    if (orderByComparator != null) {
1993                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
1994    
1995                            for (Object value : values) {
1996                                    qPos.add(value);
1997                            }
1998                    }
1999    
2000                    List<WikiPage> list = q.list();
2001    
2002                    if (list.size() == 2) {
2003                            return list.get(1);
2004                    }
2005                    else {
2006                            return null;
2007                    }
2008            }
2009    
2010            /**
2011             * Finds all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2012             *
2013             * @param resourcePrimKey the resource prim key to search with
2014             * @param nodeId the node id to search with
2015             * @return the matching wiki pages
2016             * @throws SystemException if a system exception occurred
2017             */
2018            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId)
2019                    throws SystemException {
2020                    return findByR_N(resourcePrimKey, nodeId, QueryUtil.ALL_POS,
2021                            QueryUtil.ALL_POS, null);
2022            }
2023    
2024            /**
2025             * Finds a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2026             *
2027             * <p>
2028             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2029             * </p>
2030             *
2031             * @param resourcePrimKey the resource prim key to search with
2032             * @param nodeId the node id to search with
2033             * @param start the lower bound of the range of wiki pages to return
2034             * @param end the upper bound of the range of wiki pages to return (not inclusive)
2035             * @return the range of matching wiki pages
2036             * @throws SystemException if a system exception occurred
2037             */
2038            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId,
2039                    int start, int end) throws SystemException {
2040                    return findByR_N(resourcePrimKey, nodeId, start, end, null);
2041            }
2042    
2043            /**
2044             * Finds an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2045             *
2046             * <p>
2047             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2048             * </p>
2049             *
2050             * @param resourcePrimKey the resource prim key to search with
2051             * @param nodeId the node id to search with
2052             * @param start the lower bound of the range of wiki pages to return
2053             * @param end the upper bound of the range of wiki pages to return (not inclusive)
2054             * @param orderByComparator the comparator to order the results by
2055             * @return the ordered range of matching wiki pages
2056             * @throws SystemException if a system exception occurred
2057             */
2058            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId,
2059                    int start, int end, OrderByComparator orderByComparator)
2060                    throws SystemException {
2061                    Object[] finderArgs = new Object[] {
2062                                    resourcePrimKey, nodeId,
2063                                    
2064                                    String.valueOf(start), String.valueOf(end),
2065                                    String.valueOf(orderByComparator)
2066                            };
2067    
2068                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_R_N,
2069                                    finderArgs, this);
2070    
2071                    if (list == null) {
2072                            Session session = null;
2073    
2074                            try {
2075                                    session = openSession();
2076    
2077                                    StringBundler query = null;
2078    
2079                                    if (orderByComparator != null) {
2080                                            query = new StringBundler(4 +
2081                                                            (orderByComparator.getOrderByFields().length * 3));
2082                                    }
2083                                    else {
2084                                            query = new StringBundler(4);
2085                                    }
2086    
2087                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2088    
2089                                    query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
2090    
2091                                    query.append(_FINDER_COLUMN_R_N_NODEID_2);
2092    
2093                                    if (orderByComparator != null) {
2094                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2095                                                    orderByComparator);
2096                                    }
2097    
2098                                    else {
2099                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2100                                    }
2101    
2102                                    String sql = query.toString();
2103    
2104                                    Query q = session.createQuery(sql);
2105    
2106                                    QueryPos qPos = QueryPos.getInstance(q);
2107    
2108                                    qPos.add(resourcePrimKey);
2109    
2110                                    qPos.add(nodeId);
2111    
2112                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
2113                                                    end);
2114                            }
2115                            catch (Exception e) {
2116                                    throw processException(e);
2117                            }
2118                            finally {
2119                                    if (list == null) {
2120                                            list = new ArrayList<WikiPage>();
2121                                    }
2122    
2123                                    cacheResult(list);
2124    
2125                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_R_N, finderArgs,
2126                                            list);
2127    
2128                                    closeSession(session);
2129                            }
2130                    }
2131    
2132                    return list;
2133            }
2134    
2135            /**
2136             * Finds the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2137             *
2138             * <p>
2139             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2140             * </p>
2141             *
2142             * @param resourcePrimKey the resource prim key to search with
2143             * @param nodeId the node id to search with
2144             * @param orderByComparator the comparator to order the set by
2145             * @return the first matching wiki page
2146             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2147             * @throws SystemException if a system exception occurred
2148             */
2149            public WikiPage findByR_N_First(long resourcePrimKey, long nodeId,
2150                    OrderByComparator orderByComparator)
2151                    throws NoSuchPageException, SystemException {
2152                    List<WikiPage> list = findByR_N(resourcePrimKey, nodeId, 0, 1,
2153                                    orderByComparator);
2154    
2155                    if (list.isEmpty()) {
2156                            StringBundler msg = new StringBundler(6);
2157    
2158                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2159    
2160                            msg.append("resourcePrimKey=");
2161                            msg.append(resourcePrimKey);
2162    
2163                            msg.append(", nodeId=");
2164                            msg.append(nodeId);
2165    
2166                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2167    
2168                            throw new NoSuchPageException(msg.toString());
2169                    }
2170                    else {
2171                            return list.get(0);
2172                    }
2173            }
2174    
2175            /**
2176             * Finds the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2177             *
2178             * <p>
2179             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2180             * </p>
2181             *
2182             * @param resourcePrimKey the resource prim key to search with
2183             * @param nodeId the node id to search with
2184             * @param orderByComparator the comparator to order the set by
2185             * @return the last matching wiki page
2186             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2187             * @throws SystemException if a system exception occurred
2188             */
2189            public WikiPage findByR_N_Last(long resourcePrimKey, long nodeId,
2190                    OrderByComparator orderByComparator)
2191                    throws NoSuchPageException, SystemException {
2192                    int count = countByR_N(resourcePrimKey, nodeId);
2193    
2194                    List<WikiPage> list = findByR_N(resourcePrimKey, nodeId, count - 1,
2195                                    count, orderByComparator);
2196    
2197                    if (list.isEmpty()) {
2198                            StringBundler msg = new StringBundler(6);
2199    
2200                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2201    
2202                            msg.append("resourcePrimKey=");
2203                            msg.append(resourcePrimKey);
2204    
2205                            msg.append(", nodeId=");
2206                            msg.append(nodeId);
2207    
2208                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2209    
2210                            throw new NoSuchPageException(msg.toString());
2211                    }
2212                    else {
2213                            return list.get(0);
2214                    }
2215            }
2216    
2217            /**
2218             * Finds the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2219             *
2220             * <p>
2221             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2222             * </p>
2223             *
2224             * @param pageId the primary key of the current wiki page
2225             * @param resourcePrimKey the resource prim key to search with
2226             * @param nodeId the node id to search with
2227             * @param orderByComparator the comparator to order the set by
2228             * @return the previous, current, and next wiki page
2229             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
2230             * @throws SystemException if a system exception occurred
2231             */
2232            public WikiPage[] findByR_N_PrevAndNext(long pageId, long resourcePrimKey,
2233                    long nodeId, OrderByComparator orderByComparator)
2234                    throws NoSuchPageException, SystemException {
2235                    WikiPage wikiPage = findByPrimaryKey(pageId);
2236    
2237                    Session session = null;
2238    
2239                    try {
2240                            session = openSession();
2241    
2242                            WikiPage[] array = new WikiPageImpl[3];
2243    
2244                            array[0] = getByR_N_PrevAndNext(session, wikiPage, resourcePrimKey,
2245                                            nodeId, orderByComparator, true);
2246    
2247                            array[1] = wikiPage;
2248    
2249                            array[2] = getByR_N_PrevAndNext(session, wikiPage, resourcePrimKey,
2250                                            nodeId, orderByComparator, false);
2251    
2252                            return array;
2253                    }
2254                    catch (Exception e) {
2255                            throw processException(e);
2256                    }
2257                    finally {
2258                            closeSession(session);
2259                    }
2260            }
2261    
2262            protected WikiPage getByR_N_PrevAndNext(Session session, WikiPage wikiPage,
2263                    long resourcePrimKey, long nodeId, OrderByComparator orderByComparator,
2264                    boolean previous) {
2265                    StringBundler query = null;
2266    
2267                    if (orderByComparator != null) {
2268                            query = new StringBundler(6 +
2269                                            (orderByComparator.getOrderByFields().length * 6));
2270                    }
2271                    else {
2272                            query = new StringBundler(3);
2273                    }
2274    
2275                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2276    
2277                    query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
2278    
2279                    query.append(_FINDER_COLUMN_R_N_NODEID_2);
2280    
2281                    if (orderByComparator != null) {
2282                            String[] orderByFields = orderByComparator.getOrderByFields();
2283    
2284                            if (orderByFields.length > 0) {
2285                                    query.append(WHERE_AND);
2286                            }
2287    
2288                            for (int i = 0; i < orderByFields.length; i++) {
2289                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2290                                    query.append(orderByFields[i]);
2291    
2292                                    if ((i + 1) < orderByFields.length) {
2293                                            if (orderByComparator.isAscending() ^ previous) {
2294                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2295                                            }
2296                                            else {
2297                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2298                                            }
2299                                    }
2300                                    else {
2301                                            if (orderByComparator.isAscending() ^ previous) {
2302                                                    query.append(WHERE_GREATER_THAN);
2303                                            }
2304                                            else {
2305                                                    query.append(WHERE_LESSER_THAN);
2306                                            }
2307                                    }
2308                            }
2309    
2310                            query.append(ORDER_BY_CLAUSE);
2311    
2312                            for (int i = 0; i < orderByFields.length; i++) {
2313                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2314                                    query.append(orderByFields[i]);
2315    
2316                                    if ((i + 1) < orderByFields.length) {
2317                                            if (orderByComparator.isAscending() ^ previous) {
2318                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2319                                            }
2320                                            else {
2321                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2322                                            }
2323                                    }
2324                                    else {
2325                                            if (orderByComparator.isAscending() ^ previous) {
2326                                                    query.append(ORDER_BY_ASC);
2327                                            }
2328                                            else {
2329                                                    query.append(ORDER_BY_DESC);
2330                                            }
2331                                    }
2332                            }
2333                    }
2334    
2335                    else {
2336                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2337                    }
2338    
2339                    String sql = query.toString();
2340    
2341                    Query q = session.createQuery(sql);
2342    
2343                    q.setFirstResult(0);
2344                    q.setMaxResults(2);
2345    
2346                    QueryPos qPos = QueryPos.getInstance(q);
2347    
2348                    qPos.add(resourcePrimKey);
2349    
2350                    qPos.add(nodeId);
2351    
2352                    if (orderByComparator != null) {
2353                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
2354    
2355                            for (Object value : values) {
2356                                    qPos.add(value);
2357                            }
2358                    }
2359    
2360                    List<WikiPage> list = q.list();
2361    
2362                    if (list.size() == 2) {
2363                            return list.get(1);
2364                    }
2365                    else {
2366                            return null;
2367                    }
2368            }
2369    
2370            /**
2371             * Finds all the wiki pages where nodeId = &#63; and title = &#63;.
2372             *
2373             * @param nodeId the node id to search with
2374             * @param title the title to search with
2375             * @return the matching wiki pages
2376             * @throws SystemException if a system exception occurred
2377             */
2378            public List<WikiPage> findByN_T(long nodeId, String title)
2379                    throws SystemException {
2380                    return findByN_T(nodeId, title, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2381                            null);
2382            }
2383    
2384            /**
2385             * Finds a range of all the wiki pages where nodeId = &#63; and title = &#63;.
2386             *
2387             * <p>
2388             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2389             * </p>
2390             *
2391             * @param nodeId the node id to search with
2392             * @param title the title to search with
2393             * @param start the lower bound of the range of wiki pages to return
2394             * @param end the upper bound of the range of wiki pages to return (not inclusive)
2395             * @return the range of matching wiki pages
2396             * @throws SystemException if a system exception occurred
2397             */
2398            public List<WikiPage> findByN_T(long nodeId, String title, int start,
2399                    int end) throws SystemException {
2400                    return findByN_T(nodeId, title, start, end, null);
2401            }
2402    
2403            /**
2404             * Finds an ordered range of all the wiki pages where nodeId = &#63; and title = &#63;.
2405             *
2406             * <p>
2407             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2408             * </p>
2409             *
2410             * @param nodeId the node id to search with
2411             * @param title the title to search with
2412             * @param start the lower bound of the range of wiki pages to return
2413             * @param end the upper bound of the range of wiki pages to return (not inclusive)
2414             * @param orderByComparator the comparator to order the results by
2415             * @return the ordered range of matching wiki pages
2416             * @throws SystemException if a system exception occurred
2417             */
2418            public List<WikiPage> findByN_T(long nodeId, String title, int start,
2419                    int end, OrderByComparator orderByComparator) throws SystemException {
2420                    Object[] finderArgs = new Object[] {
2421                                    nodeId, title,
2422                                    
2423                                    String.valueOf(start), String.valueOf(end),
2424                                    String.valueOf(orderByComparator)
2425                            };
2426    
2427                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_N_T,
2428                                    finderArgs, this);
2429    
2430                    if (list == null) {
2431                            Session session = null;
2432    
2433                            try {
2434                                    session = openSession();
2435    
2436                                    StringBundler query = null;
2437    
2438                                    if (orderByComparator != null) {
2439                                            query = new StringBundler(4 +
2440                                                            (orderByComparator.getOrderByFields().length * 3));
2441                                    }
2442                                    else {
2443                                            query = new StringBundler(4);
2444                                    }
2445    
2446                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2447    
2448                                    query.append(_FINDER_COLUMN_N_T_NODEID_2);
2449    
2450                                    if (title == null) {
2451                                            query.append(_FINDER_COLUMN_N_T_TITLE_1);
2452                                    }
2453                                    else {
2454                                            if (title.equals(StringPool.BLANK)) {
2455                                                    query.append(_FINDER_COLUMN_N_T_TITLE_3);
2456                                            }
2457                                            else {
2458                                                    query.append(_FINDER_COLUMN_N_T_TITLE_2);
2459                                            }
2460                                    }
2461    
2462                                    if (orderByComparator != null) {
2463                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2464                                                    orderByComparator);
2465                                    }
2466    
2467                                    else {
2468                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2469                                    }
2470    
2471                                    String sql = query.toString();
2472    
2473                                    Query q = session.createQuery(sql);
2474    
2475                                    QueryPos qPos = QueryPos.getInstance(q);
2476    
2477                                    qPos.add(nodeId);
2478    
2479                                    if (title != null) {
2480                                            qPos.add(title);
2481                                    }
2482    
2483                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
2484                                                    end);
2485                            }
2486                            catch (Exception e) {
2487                                    throw processException(e);
2488                            }
2489                            finally {
2490                                    if (list == null) {
2491                                            list = new ArrayList<WikiPage>();
2492                                    }
2493    
2494                                    cacheResult(list);
2495    
2496                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_N_T, finderArgs,
2497                                            list);
2498    
2499                                    closeSession(session);
2500                            }
2501                    }
2502    
2503                    return list;
2504            }
2505    
2506            /**
2507             * Finds the first wiki page in the ordered set where nodeId = &#63; and title = &#63;.
2508             *
2509             * <p>
2510             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2511             * </p>
2512             *
2513             * @param nodeId the node id to search with
2514             * @param title the title to search with
2515             * @param orderByComparator the comparator to order the set by
2516             * @return the first matching wiki page
2517             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2518             * @throws SystemException if a system exception occurred
2519             */
2520            public WikiPage findByN_T_First(long nodeId, String title,
2521                    OrderByComparator orderByComparator)
2522                    throws NoSuchPageException, SystemException {
2523                    List<WikiPage> list = findByN_T(nodeId, title, 0, 1, orderByComparator);
2524    
2525                    if (list.isEmpty()) {
2526                            StringBundler msg = new StringBundler(6);
2527    
2528                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2529    
2530                            msg.append("nodeId=");
2531                            msg.append(nodeId);
2532    
2533                            msg.append(", title=");
2534                            msg.append(title);
2535    
2536                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2537    
2538                            throw new NoSuchPageException(msg.toString());
2539                    }
2540                    else {
2541                            return list.get(0);
2542                    }
2543            }
2544    
2545            /**
2546             * Finds the last wiki page in the ordered set where nodeId = &#63; and title = &#63;.
2547             *
2548             * <p>
2549             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2550             * </p>
2551             *
2552             * @param nodeId the node id to search with
2553             * @param title the title to search with
2554             * @param orderByComparator the comparator to order the set by
2555             * @return the last matching wiki page
2556             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2557             * @throws SystemException if a system exception occurred
2558             */
2559            public WikiPage findByN_T_Last(long nodeId, String title,
2560                    OrderByComparator orderByComparator)
2561                    throws NoSuchPageException, SystemException {
2562                    int count = countByN_T(nodeId, title);
2563    
2564                    List<WikiPage> list = findByN_T(nodeId, title, count - 1, count,
2565                                    orderByComparator);
2566    
2567                    if (list.isEmpty()) {
2568                            StringBundler msg = new StringBundler(6);
2569    
2570                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2571    
2572                            msg.append("nodeId=");
2573                            msg.append(nodeId);
2574    
2575                            msg.append(", title=");
2576                            msg.append(title);
2577    
2578                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2579    
2580                            throw new NoSuchPageException(msg.toString());
2581                    }
2582                    else {
2583                            return list.get(0);
2584                    }
2585            }
2586    
2587            /**
2588             * Finds the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63;.
2589             *
2590             * <p>
2591             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2592             * </p>
2593             *
2594             * @param pageId the primary key of the current wiki page
2595             * @param nodeId the node id to search with
2596             * @param title the title to search with
2597             * @param orderByComparator the comparator to order the set by
2598             * @return the previous, current, and next wiki page
2599             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
2600             * @throws SystemException if a system exception occurred
2601             */
2602            public WikiPage[] findByN_T_PrevAndNext(long pageId, long nodeId,
2603                    String title, OrderByComparator orderByComparator)
2604                    throws NoSuchPageException, SystemException {
2605                    WikiPage wikiPage = findByPrimaryKey(pageId);
2606    
2607                    Session session = null;
2608    
2609                    try {
2610                            session = openSession();
2611    
2612                            WikiPage[] array = new WikiPageImpl[3];
2613    
2614                            array[0] = getByN_T_PrevAndNext(session, wikiPage, nodeId, title,
2615                                            orderByComparator, true);
2616    
2617                            array[1] = wikiPage;
2618    
2619                            array[2] = getByN_T_PrevAndNext(session, wikiPage, nodeId, title,
2620                                            orderByComparator, false);
2621    
2622                            return array;
2623                    }
2624                    catch (Exception e) {
2625                            throw processException(e);
2626                    }
2627                    finally {
2628                            closeSession(session);
2629                    }
2630            }
2631    
2632            protected WikiPage getByN_T_PrevAndNext(Session session, WikiPage wikiPage,
2633                    long nodeId, String title, OrderByComparator orderByComparator,
2634                    boolean previous) {
2635                    StringBundler query = null;
2636    
2637                    if (orderByComparator != null) {
2638                            query = new StringBundler(6 +
2639                                            (orderByComparator.getOrderByFields().length * 6));
2640                    }
2641                    else {
2642                            query = new StringBundler(3);
2643                    }
2644    
2645                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2646    
2647                    query.append(_FINDER_COLUMN_N_T_NODEID_2);
2648    
2649                    if (title == null) {
2650                            query.append(_FINDER_COLUMN_N_T_TITLE_1);
2651                    }
2652                    else {
2653                            if (title.equals(StringPool.BLANK)) {
2654                                    query.append(_FINDER_COLUMN_N_T_TITLE_3);
2655                            }
2656                            else {
2657                                    query.append(_FINDER_COLUMN_N_T_TITLE_2);
2658                            }
2659                    }
2660    
2661                    if (orderByComparator != null) {
2662                            String[] orderByFields = orderByComparator.getOrderByFields();
2663    
2664                            if (orderByFields.length > 0) {
2665                                    query.append(WHERE_AND);
2666                            }
2667    
2668                            for (int i = 0; i < orderByFields.length; i++) {
2669                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2670                                    query.append(orderByFields[i]);
2671    
2672                                    if ((i + 1) < orderByFields.length) {
2673                                            if (orderByComparator.isAscending() ^ previous) {
2674                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2675                                            }
2676                                            else {
2677                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2678                                            }
2679                                    }
2680                                    else {
2681                                            if (orderByComparator.isAscending() ^ previous) {
2682                                                    query.append(WHERE_GREATER_THAN);
2683                                            }
2684                                            else {
2685                                                    query.append(WHERE_LESSER_THAN);
2686                                            }
2687                                    }
2688                            }
2689    
2690                            query.append(ORDER_BY_CLAUSE);
2691    
2692                            for (int i = 0; i < orderByFields.length; i++) {
2693                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2694                                    query.append(orderByFields[i]);
2695    
2696                                    if ((i + 1) < orderByFields.length) {
2697                                            if (orderByComparator.isAscending() ^ previous) {
2698                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2699                                            }
2700                                            else {
2701                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2702                                            }
2703                                    }
2704                                    else {
2705                                            if (orderByComparator.isAscending() ^ previous) {
2706                                                    query.append(ORDER_BY_ASC);
2707                                            }
2708                                            else {
2709                                                    query.append(ORDER_BY_DESC);
2710                                            }
2711                                    }
2712                            }
2713                    }
2714    
2715                    else {
2716                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2717                    }
2718    
2719                    String sql = query.toString();
2720    
2721                    Query q = session.createQuery(sql);
2722    
2723                    q.setFirstResult(0);
2724                    q.setMaxResults(2);
2725    
2726                    QueryPos qPos = QueryPos.getInstance(q);
2727    
2728                    qPos.add(nodeId);
2729    
2730                    if (title != null) {
2731                            qPos.add(title);
2732                    }
2733    
2734                    if (orderByComparator != null) {
2735                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
2736    
2737                            for (Object value : values) {
2738                                    qPos.add(value);
2739                            }
2740                    }
2741    
2742                    List<WikiPage> list = q.list();
2743    
2744                    if (list.size() == 2) {
2745                            return list.get(1);
2746                    }
2747                    else {
2748                            return null;
2749                    }
2750            }
2751    
2752            /**
2753             * Finds all the wiki pages where nodeId = &#63; and head = &#63;.
2754             *
2755             * @param nodeId the node id to search with
2756             * @param head the head to search with
2757             * @return the matching wiki pages
2758             * @throws SystemException if a system exception occurred
2759             */
2760            public List<WikiPage> findByN_H(long nodeId, boolean head)
2761                    throws SystemException {
2762                    return findByN_H(nodeId, head, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2763                            null);
2764            }
2765    
2766            /**
2767             * Finds a range of all the wiki pages where nodeId = &#63; and head = &#63;.
2768             *
2769             * <p>
2770             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2771             * </p>
2772             *
2773             * @param nodeId the node id to search with
2774             * @param head the head to search with
2775             * @param start the lower bound of the range of wiki pages to return
2776             * @param end the upper bound of the range of wiki pages to return (not inclusive)
2777             * @return the range of matching wiki pages
2778             * @throws SystemException if a system exception occurred
2779             */
2780            public List<WikiPage> findByN_H(long nodeId, boolean head, int start,
2781                    int end) throws SystemException {
2782                    return findByN_H(nodeId, head, start, end, null);
2783            }
2784    
2785            /**
2786             * Finds an ordered range of all the wiki pages where nodeId = &#63; and head = &#63;.
2787             *
2788             * <p>
2789             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2790             * </p>
2791             *
2792             * @param nodeId the node id to search with
2793             * @param head the head to search with
2794             * @param start the lower bound of the range of wiki pages to return
2795             * @param end the upper bound of the range of wiki pages to return (not inclusive)
2796             * @param orderByComparator the comparator to order the results by
2797             * @return the ordered range of matching wiki pages
2798             * @throws SystemException if a system exception occurred
2799             */
2800            public List<WikiPage> findByN_H(long nodeId, boolean head, int start,
2801                    int end, OrderByComparator orderByComparator) throws SystemException {
2802                    Object[] finderArgs = new Object[] {
2803                                    nodeId, head,
2804                                    
2805                                    String.valueOf(start), String.valueOf(end),
2806                                    String.valueOf(orderByComparator)
2807                            };
2808    
2809                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_N_H,
2810                                    finderArgs, this);
2811    
2812                    if (list == null) {
2813                            Session session = null;
2814    
2815                            try {
2816                                    session = openSession();
2817    
2818                                    StringBundler query = null;
2819    
2820                                    if (orderByComparator != null) {
2821                                            query = new StringBundler(4 +
2822                                                            (orderByComparator.getOrderByFields().length * 3));
2823                                    }
2824                                    else {
2825                                            query = new StringBundler(4);
2826                                    }
2827    
2828                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2829    
2830                                    query.append(_FINDER_COLUMN_N_H_NODEID_2);
2831    
2832                                    query.append(_FINDER_COLUMN_N_H_HEAD_2);
2833    
2834                                    if (orderByComparator != null) {
2835                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2836                                                    orderByComparator);
2837                                    }
2838    
2839                                    else {
2840                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2841                                    }
2842    
2843                                    String sql = query.toString();
2844    
2845                                    Query q = session.createQuery(sql);
2846    
2847                                    QueryPos qPos = QueryPos.getInstance(q);
2848    
2849                                    qPos.add(nodeId);
2850    
2851                                    qPos.add(head);
2852    
2853                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
2854                                                    end);
2855                            }
2856                            catch (Exception e) {
2857                                    throw processException(e);
2858                            }
2859                            finally {
2860                                    if (list == null) {
2861                                            list = new ArrayList<WikiPage>();
2862                                    }
2863    
2864                                    cacheResult(list);
2865    
2866                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_N_H, finderArgs,
2867                                            list);
2868    
2869                                    closeSession(session);
2870                            }
2871                    }
2872    
2873                    return list;
2874            }
2875    
2876            /**
2877             * Finds the first wiki page in the ordered set where nodeId = &#63; and head = &#63;.
2878             *
2879             * <p>
2880             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2881             * </p>
2882             *
2883             * @param nodeId the node id to search with
2884             * @param head the head to search with
2885             * @param orderByComparator the comparator to order the set by
2886             * @return the first matching wiki page
2887             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2888             * @throws SystemException if a system exception occurred
2889             */
2890            public WikiPage findByN_H_First(long nodeId, boolean head,
2891                    OrderByComparator orderByComparator)
2892                    throws NoSuchPageException, SystemException {
2893                    List<WikiPage> list = findByN_H(nodeId, head, 0, 1, orderByComparator);
2894    
2895                    if (list.isEmpty()) {
2896                            StringBundler msg = new StringBundler(6);
2897    
2898                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2899    
2900                            msg.append("nodeId=");
2901                            msg.append(nodeId);
2902    
2903                            msg.append(", head=");
2904                            msg.append(head);
2905    
2906                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2907    
2908                            throw new NoSuchPageException(msg.toString());
2909                    }
2910                    else {
2911                            return list.get(0);
2912                    }
2913            }
2914    
2915            /**
2916             * Finds the last wiki page in the ordered set where nodeId = &#63; and head = &#63;.
2917             *
2918             * <p>
2919             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2920             * </p>
2921             *
2922             * @param nodeId the node id to search with
2923             * @param head the head to search with
2924             * @param orderByComparator the comparator to order the set by
2925             * @return the last matching wiki page
2926             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2927             * @throws SystemException if a system exception occurred
2928             */
2929            public WikiPage findByN_H_Last(long nodeId, boolean head,
2930                    OrderByComparator orderByComparator)
2931                    throws NoSuchPageException, SystemException {
2932                    int count = countByN_H(nodeId, head);
2933    
2934                    List<WikiPage> list = findByN_H(nodeId, head, count - 1, count,
2935                                    orderByComparator);
2936    
2937                    if (list.isEmpty()) {
2938                            StringBundler msg = new StringBundler(6);
2939    
2940                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2941    
2942                            msg.append("nodeId=");
2943                            msg.append(nodeId);
2944    
2945                            msg.append(", head=");
2946                            msg.append(head);
2947    
2948                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2949    
2950                            throw new NoSuchPageException(msg.toString());
2951                    }
2952                    else {
2953                            return list.get(0);
2954                    }
2955            }
2956    
2957            /**
2958             * Finds the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63;.
2959             *
2960             * <p>
2961             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2962             * </p>
2963             *
2964             * @param pageId the primary key of the current wiki page
2965             * @param nodeId the node id to search with
2966             * @param head the head to search with
2967             * @param orderByComparator the comparator to order the set by
2968             * @return the previous, current, and next wiki page
2969             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
2970             * @throws SystemException if a system exception occurred
2971             */
2972            public WikiPage[] findByN_H_PrevAndNext(long pageId, long nodeId,
2973                    boolean head, OrderByComparator orderByComparator)
2974                    throws NoSuchPageException, SystemException {
2975                    WikiPage wikiPage = findByPrimaryKey(pageId);
2976    
2977                    Session session = null;
2978    
2979                    try {
2980                            session = openSession();
2981    
2982                            WikiPage[] array = new WikiPageImpl[3];
2983    
2984                            array[0] = getByN_H_PrevAndNext(session, wikiPage, nodeId, head,
2985                                            orderByComparator, true);
2986    
2987                            array[1] = wikiPage;
2988    
2989                            array[2] = getByN_H_PrevAndNext(session, wikiPage, nodeId, head,
2990                                            orderByComparator, false);
2991    
2992                            return array;
2993                    }
2994                    catch (Exception e) {
2995                            throw processException(e);
2996                    }
2997                    finally {
2998                            closeSession(session);
2999                    }
3000            }
3001    
3002            protected WikiPage getByN_H_PrevAndNext(Session session, WikiPage wikiPage,
3003                    long nodeId, boolean head, OrderByComparator orderByComparator,
3004                    boolean previous) {
3005                    StringBundler query = null;
3006    
3007                    if (orderByComparator != null) {
3008                            query = new StringBundler(6 +
3009                                            (orderByComparator.getOrderByFields().length * 6));
3010                    }
3011                    else {
3012                            query = new StringBundler(3);
3013                    }
3014    
3015                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3016    
3017                    query.append(_FINDER_COLUMN_N_H_NODEID_2);
3018    
3019                    query.append(_FINDER_COLUMN_N_H_HEAD_2);
3020    
3021                    if (orderByComparator != null) {
3022                            String[] orderByFields = orderByComparator.getOrderByFields();
3023    
3024                            if (orderByFields.length > 0) {
3025                                    query.append(WHERE_AND);
3026                            }
3027    
3028                            for (int i = 0; i < orderByFields.length; i++) {
3029                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3030                                    query.append(orderByFields[i]);
3031    
3032                                    if ((i + 1) < orderByFields.length) {
3033                                            if (orderByComparator.isAscending() ^ previous) {
3034                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3035                                            }
3036                                            else {
3037                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3038                                            }
3039                                    }
3040                                    else {
3041                                            if (orderByComparator.isAscending() ^ previous) {
3042                                                    query.append(WHERE_GREATER_THAN);
3043                                            }
3044                                            else {
3045                                                    query.append(WHERE_LESSER_THAN);
3046                                            }
3047                                    }
3048                            }
3049    
3050                            query.append(ORDER_BY_CLAUSE);
3051    
3052                            for (int i = 0; i < orderByFields.length; i++) {
3053                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3054                                    query.append(orderByFields[i]);
3055    
3056                                    if ((i + 1) < orderByFields.length) {
3057                                            if (orderByComparator.isAscending() ^ previous) {
3058                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3059                                            }
3060                                            else {
3061                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3062                                            }
3063                                    }
3064                                    else {
3065                                            if (orderByComparator.isAscending() ^ previous) {
3066                                                    query.append(ORDER_BY_ASC);
3067                                            }
3068                                            else {
3069                                                    query.append(ORDER_BY_DESC);
3070                                            }
3071                                    }
3072                            }
3073                    }
3074    
3075                    else {
3076                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3077                    }
3078    
3079                    String sql = query.toString();
3080    
3081                    Query q = session.createQuery(sql);
3082    
3083                    q.setFirstResult(0);
3084                    q.setMaxResults(2);
3085    
3086                    QueryPos qPos = QueryPos.getInstance(q);
3087    
3088                    qPos.add(nodeId);
3089    
3090                    qPos.add(head);
3091    
3092                    if (orderByComparator != null) {
3093                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
3094    
3095                            for (Object value : values) {
3096                                    qPos.add(value);
3097                            }
3098                    }
3099    
3100                    List<WikiPage> list = q.list();
3101    
3102                    if (list.size() == 2) {
3103                            return list.get(1);
3104                    }
3105                    else {
3106                            return null;
3107                    }
3108            }
3109    
3110            /**
3111             * Finds all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
3112             *
3113             * @param nodeId the node id to search with
3114             * @param parentTitle the parent title to search with
3115             * @return the matching wiki pages
3116             * @throws SystemException if a system exception occurred
3117             */
3118            public List<WikiPage> findByN_P(long nodeId, String parentTitle)
3119                    throws SystemException {
3120                    return findByN_P(nodeId, parentTitle, QueryUtil.ALL_POS,
3121                            QueryUtil.ALL_POS, null);
3122            }
3123    
3124            /**
3125             * Finds a range of all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
3126             *
3127             * <p>
3128             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3129             * </p>
3130             *
3131             * @param nodeId the node id to search with
3132             * @param parentTitle the parent title to search with
3133             * @param start the lower bound of the range of wiki pages to return
3134             * @param end the upper bound of the range of wiki pages to return (not inclusive)
3135             * @return the range of matching wiki pages
3136             * @throws SystemException if a system exception occurred
3137             */
3138            public List<WikiPage> findByN_P(long nodeId, String parentTitle, int start,
3139                    int end) throws SystemException {
3140                    return findByN_P(nodeId, parentTitle, start, end, null);
3141            }
3142    
3143            /**
3144             * Finds an ordered range of all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
3145             *
3146             * <p>
3147             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3148             * </p>
3149             *
3150             * @param nodeId the node id to search with
3151             * @param parentTitle the parent title to search with
3152             * @param start the lower bound of the range of wiki pages to return
3153             * @param end the upper bound of the range of wiki pages to return (not inclusive)
3154             * @param orderByComparator the comparator to order the results by
3155             * @return the ordered range of matching wiki pages
3156             * @throws SystemException if a system exception occurred
3157             */
3158            public List<WikiPage> findByN_P(long nodeId, String parentTitle, int start,
3159                    int end, OrderByComparator orderByComparator) throws SystemException {
3160                    Object[] finderArgs = new Object[] {
3161                                    nodeId, parentTitle,
3162                                    
3163                                    String.valueOf(start), String.valueOf(end),
3164                                    String.valueOf(orderByComparator)
3165                            };
3166    
3167                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_N_P,
3168                                    finderArgs, this);
3169    
3170                    if (list == null) {
3171                            Session session = null;
3172    
3173                            try {
3174                                    session = openSession();
3175    
3176                                    StringBundler query = null;
3177    
3178                                    if (orderByComparator != null) {
3179                                            query = new StringBundler(4 +
3180                                                            (orderByComparator.getOrderByFields().length * 3));
3181                                    }
3182                                    else {
3183                                            query = new StringBundler(4);
3184                                    }
3185    
3186                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3187    
3188                                    query.append(_FINDER_COLUMN_N_P_NODEID_2);
3189    
3190                                    if (parentTitle == null) {
3191                                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
3192                                    }
3193                                    else {
3194                                            if (parentTitle.equals(StringPool.BLANK)) {
3195                                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
3196                                            }
3197                                            else {
3198                                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
3199                                            }
3200                                    }
3201    
3202                                    if (orderByComparator != null) {
3203                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3204                                                    orderByComparator);
3205                                    }
3206    
3207                                    else {
3208                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3209                                    }
3210    
3211                                    String sql = query.toString();
3212    
3213                                    Query q = session.createQuery(sql);
3214    
3215                                    QueryPos qPos = QueryPos.getInstance(q);
3216    
3217                                    qPos.add(nodeId);
3218    
3219                                    if (parentTitle != null) {
3220                                            qPos.add(parentTitle);
3221                                    }
3222    
3223                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
3224                                                    end);
3225                            }
3226                            catch (Exception e) {
3227                                    throw processException(e);
3228                            }
3229                            finally {
3230                                    if (list == null) {
3231                                            list = new ArrayList<WikiPage>();
3232                                    }
3233    
3234                                    cacheResult(list);
3235    
3236                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_N_P, finderArgs,
3237                                            list);
3238    
3239                                    closeSession(session);
3240                            }
3241                    }
3242    
3243                    return list;
3244            }
3245    
3246            /**
3247             * Finds the first wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
3248             *
3249             * <p>
3250             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3251             * </p>
3252             *
3253             * @param nodeId the node id to search with
3254             * @param parentTitle the parent title to search with
3255             * @param orderByComparator the comparator to order the set by
3256             * @return the first matching wiki page
3257             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3258             * @throws SystemException if a system exception occurred
3259             */
3260            public WikiPage findByN_P_First(long nodeId, String parentTitle,
3261                    OrderByComparator orderByComparator)
3262                    throws NoSuchPageException, SystemException {
3263                    List<WikiPage> list = findByN_P(nodeId, parentTitle, 0, 1,
3264                                    orderByComparator);
3265    
3266                    if (list.isEmpty()) {
3267                            StringBundler msg = new StringBundler(6);
3268    
3269                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3270    
3271                            msg.append("nodeId=");
3272                            msg.append(nodeId);
3273    
3274                            msg.append(", parentTitle=");
3275                            msg.append(parentTitle);
3276    
3277                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3278    
3279                            throw new NoSuchPageException(msg.toString());
3280                    }
3281                    else {
3282                            return list.get(0);
3283                    }
3284            }
3285    
3286            /**
3287             * Finds the last wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
3288             *
3289             * <p>
3290             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3291             * </p>
3292             *
3293             * @param nodeId the node id to search with
3294             * @param parentTitle the parent title to search with
3295             * @param orderByComparator the comparator to order the set by
3296             * @return the last matching wiki page
3297             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3298             * @throws SystemException if a system exception occurred
3299             */
3300            public WikiPage findByN_P_Last(long nodeId, String parentTitle,
3301                    OrderByComparator orderByComparator)
3302                    throws NoSuchPageException, SystemException {
3303                    int count = countByN_P(nodeId, parentTitle);
3304    
3305                    List<WikiPage> list = findByN_P(nodeId, parentTitle, count - 1, count,
3306                                    orderByComparator);
3307    
3308                    if (list.isEmpty()) {
3309                            StringBundler msg = new StringBundler(6);
3310    
3311                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3312    
3313                            msg.append("nodeId=");
3314                            msg.append(nodeId);
3315    
3316                            msg.append(", parentTitle=");
3317                            msg.append(parentTitle);
3318    
3319                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3320    
3321                            throw new NoSuchPageException(msg.toString());
3322                    }
3323                    else {
3324                            return list.get(0);
3325                    }
3326            }
3327    
3328            /**
3329             * Finds the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
3330             *
3331             * <p>
3332             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3333             * </p>
3334             *
3335             * @param pageId the primary key of the current wiki page
3336             * @param nodeId the node id to search with
3337             * @param parentTitle the parent title to search with
3338             * @param orderByComparator the comparator to order the set by
3339             * @return the previous, current, and next wiki page
3340             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
3341             * @throws SystemException if a system exception occurred
3342             */
3343            public WikiPage[] findByN_P_PrevAndNext(long pageId, long nodeId,
3344                    String parentTitle, OrderByComparator orderByComparator)
3345                    throws NoSuchPageException, SystemException {
3346                    WikiPage wikiPage = findByPrimaryKey(pageId);
3347    
3348                    Session session = null;
3349    
3350                    try {
3351                            session = openSession();
3352    
3353                            WikiPage[] array = new WikiPageImpl[3];
3354    
3355                            array[0] = getByN_P_PrevAndNext(session, wikiPage, nodeId,
3356                                            parentTitle, orderByComparator, true);
3357    
3358                            array[1] = wikiPage;
3359    
3360                            array[2] = getByN_P_PrevAndNext(session, wikiPage, nodeId,
3361                                            parentTitle, orderByComparator, false);
3362    
3363                            return array;
3364                    }
3365                    catch (Exception e) {
3366                            throw processException(e);
3367                    }
3368                    finally {
3369                            closeSession(session);
3370                    }
3371            }
3372    
3373            protected WikiPage getByN_P_PrevAndNext(Session session, WikiPage wikiPage,
3374                    long nodeId, String parentTitle, OrderByComparator orderByComparator,
3375                    boolean previous) {
3376                    StringBundler query = null;
3377    
3378                    if (orderByComparator != null) {
3379                            query = new StringBundler(6 +
3380                                            (orderByComparator.getOrderByFields().length * 6));
3381                    }
3382                    else {
3383                            query = new StringBundler(3);
3384                    }
3385    
3386                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3387    
3388                    query.append(_FINDER_COLUMN_N_P_NODEID_2);
3389    
3390                    if (parentTitle == null) {
3391                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
3392                    }
3393                    else {
3394                            if (parentTitle.equals(StringPool.BLANK)) {
3395                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
3396                            }
3397                            else {
3398                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
3399                            }
3400                    }
3401    
3402                    if (orderByComparator != null) {
3403                            String[] orderByFields = orderByComparator.getOrderByFields();
3404    
3405                            if (orderByFields.length > 0) {
3406                                    query.append(WHERE_AND);
3407                            }
3408    
3409                            for (int i = 0; i < orderByFields.length; i++) {
3410                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3411                                    query.append(orderByFields[i]);
3412    
3413                                    if ((i + 1) < orderByFields.length) {
3414                                            if (orderByComparator.isAscending() ^ previous) {
3415                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3416                                            }
3417                                            else {
3418                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3419                                            }
3420                                    }
3421                                    else {
3422                                            if (orderByComparator.isAscending() ^ previous) {
3423                                                    query.append(WHERE_GREATER_THAN);
3424                                            }
3425                                            else {
3426                                                    query.append(WHERE_LESSER_THAN);
3427                                            }
3428                                    }
3429                            }
3430    
3431                            query.append(ORDER_BY_CLAUSE);
3432    
3433                            for (int i = 0; i < orderByFields.length; i++) {
3434                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3435                                    query.append(orderByFields[i]);
3436    
3437                                    if ((i + 1) < orderByFields.length) {
3438                                            if (orderByComparator.isAscending() ^ previous) {
3439                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3440                                            }
3441                                            else {
3442                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3443                                            }
3444                                    }
3445                                    else {
3446                                            if (orderByComparator.isAscending() ^ previous) {
3447                                                    query.append(ORDER_BY_ASC);
3448                                            }
3449                                            else {
3450                                                    query.append(ORDER_BY_DESC);
3451                                            }
3452                                    }
3453                            }
3454                    }
3455    
3456                    else {
3457                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3458                    }
3459    
3460                    String sql = query.toString();
3461    
3462                    Query q = session.createQuery(sql);
3463    
3464                    q.setFirstResult(0);
3465                    q.setMaxResults(2);
3466    
3467                    QueryPos qPos = QueryPos.getInstance(q);
3468    
3469                    qPos.add(nodeId);
3470    
3471                    if (parentTitle != null) {
3472                            qPos.add(parentTitle);
3473                    }
3474    
3475                    if (orderByComparator != null) {
3476                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
3477    
3478                            for (Object value : values) {
3479                                    qPos.add(value);
3480                            }
3481                    }
3482    
3483                    List<WikiPage> list = q.list();
3484    
3485                    if (list.size() == 2) {
3486                            return list.get(1);
3487                    }
3488                    else {
3489                            return null;
3490                    }
3491            }
3492    
3493            /**
3494             * Finds all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
3495             *
3496             * @param nodeId the node id to search with
3497             * @param redirectTitle the redirect title to search with
3498             * @return the matching wiki pages
3499             * @throws SystemException if a system exception occurred
3500             */
3501            public List<WikiPage> findByN_R(long nodeId, String redirectTitle)
3502                    throws SystemException {
3503                    return findByN_R(nodeId, redirectTitle, QueryUtil.ALL_POS,
3504                            QueryUtil.ALL_POS, null);
3505            }
3506    
3507            /**
3508             * Finds a range of all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
3509             *
3510             * <p>
3511             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3512             * </p>
3513             *
3514             * @param nodeId the node id to search with
3515             * @param redirectTitle the redirect title to search with
3516             * @param start the lower bound of the range of wiki pages to return
3517             * @param end the upper bound of the range of wiki pages to return (not inclusive)
3518             * @return the range of matching wiki pages
3519             * @throws SystemException if a system exception occurred
3520             */
3521            public List<WikiPage> findByN_R(long nodeId, String redirectTitle,
3522                    int start, int end) throws SystemException {
3523                    return findByN_R(nodeId, redirectTitle, start, end, null);
3524            }
3525    
3526            /**
3527             * Finds an ordered range of all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
3528             *
3529             * <p>
3530             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3531             * </p>
3532             *
3533             * @param nodeId the node id to search with
3534             * @param redirectTitle the redirect title to search with
3535             * @param start the lower bound of the range of wiki pages to return
3536             * @param end the upper bound of the range of wiki pages to return (not inclusive)
3537             * @param orderByComparator the comparator to order the results by
3538             * @return the ordered range of matching wiki pages
3539             * @throws SystemException if a system exception occurred
3540             */
3541            public List<WikiPage> findByN_R(long nodeId, String redirectTitle,
3542                    int start, int end, OrderByComparator orderByComparator)
3543                    throws SystemException {
3544                    Object[] finderArgs = new Object[] {
3545                                    nodeId, redirectTitle,
3546                                    
3547                                    String.valueOf(start), String.valueOf(end),
3548                                    String.valueOf(orderByComparator)
3549                            };
3550    
3551                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_N_R,
3552                                    finderArgs, this);
3553    
3554                    if (list == null) {
3555                            Session session = null;
3556    
3557                            try {
3558                                    session = openSession();
3559    
3560                                    StringBundler query = null;
3561    
3562                                    if (orderByComparator != null) {
3563                                            query = new StringBundler(4 +
3564                                                            (orderByComparator.getOrderByFields().length * 3));
3565                                    }
3566                                    else {
3567                                            query = new StringBundler(4);
3568                                    }
3569    
3570                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3571    
3572                                    query.append(_FINDER_COLUMN_N_R_NODEID_2);
3573    
3574                                    if (redirectTitle == null) {
3575                                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
3576                                    }
3577                                    else {
3578                                            if (redirectTitle.equals(StringPool.BLANK)) {
3579                                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
3580                                            }
3581                                            else {
3582                                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
3583                                            }
3584                                    }
3585    
3586                                    if (orderByComparator != null) {
3587                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3588                                                    orderByComparator);
3589                                    }
3590    
3591                                    else {
3592                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3593                                    }
3594    
3595                                    String sql = query.toString();
3596    
3597                                    Query q = session.createQuery(sql);
3598    
3599                                    QueryPos qPos = QueryPos.getInstance(q);
3600    
3601                                    qPos.add(nodeId);
3602    
3603                                    if (redirectTitle != null) {
3604                                            qPos.add(redirectTitle);
3605                                    }
3606    
3607                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
3608                                                    end);
3609                            }
3610                            catch (Exception e) {
3611                                    throw processException(e);
3612                            }
3613                            finally {
3614                                    if (list == null) {
3615                                            list = new ArrayList<WikiPage>();
3616                                    }
3617    
3618                                    cacheResult(list);
3619    
3620                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_N_R, finderArgs,
3621                                            list);
3622    
3623                                    closeSession(session);
3624                            }
3625                    }
3626    
3627                    return list;
3628            }
3629    
3630            /**
3631             * Finds the first wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
3632             *
3633             * <p>
3634             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3635             * </p>
3636             *
3637             * @param nodeId the node id to search with
3638             * @param redirectTitle the redirect title to search with
3639             * @param orderByComparator the comparator to order the set by
3640             * @return the first matching wiki page
3641             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3642             * @throws SystemException if a system exception occurred
3643             */
3644            public WikiPage findByN_R_First(long nodeId, String redirectTitle,
3645                    OrderByComparator orderByComparator)
3646                    throws NoSuchPageException, SystemException {
3647                    List<WikiPage> list = findByN_R(nodeId, redirectTitle, 0, 1,
3648                                    orderByComparator);
3649    
3650                    if (list.isEmpty()) {
3651                            StringBundler msg = new StringBundler(6);
3652    
3653                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3654    
3655                            msg.append("nodeId=");
3656                            msg.append(nodeId);
3657    
3658                            msg.append(", redirectTitle=");
3659                            msg.append(redirectTitle);
3660    
3661                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3662    
3663                            throw new NoSuchPageException(msg.toString());
3664                    }
3665                    else {
3666                            return list.get(0);
3667                    }
3668            }
3669    
3670            /**
3671             * Finds the last wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
3672             *
3673             * <p>
3674             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3675             * </p>
3676             *
3677             * @param nodeId the node id to search with
3678             * @param redirectTitle the redirect title to search with
3679             * @param orderByComparator the comparator to order the set by
3680             * @return the last matching wiki page
3681             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3682             * @throws SystemException if a system exception occurred
3683             */
3684            public WikiPage findByN_R_Last(long nodeId, String redirectTitle,
3685                    OrderByComparator orderByComparator)
3686                    throws NoSuchPageException, SystemException {
3687                    int count = countByN_R(nodeId, redirectTitle);
3688    
3689                    List<WikiPage> list = findByN_R(nodeId, redirectTitle, count - 1,
3690                                    count, orderByComparator);
3691    
3692                    if (list.isEmpty()) {
3693                            StringBundler msg = new StringBundler(6);
3694    
3695                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3696    
3697                            msg.append("nodeId=");
3698                            msg.append(nodeId);
3699    
3700                            msg.append(", redirectTitle=");
3701                            msg.append(redirectTitle);
3702    
3703                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3704    
3705                            throw new NoSuchPageException(msg.toString());
3706                    }
3707                    else {
3708                            return list.get(0);
3709                    }
3710            }
3711    
3712            /**
3713             * Finds the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
3714             *
3715             * <p>
3716             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3717             * </p>
3718             *
3719             * @param pageId the primary key of the current wiki page
3720             * @param nodeId the node id to search with
3721             * @param redirectTitle the redirect title to search with
3722             * @param orderByComparator the comparator to order the set by
3723             * @return the previous, current, and next wiki page
3724             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
3725             * @throws SystemException if a system exception occurred
3726             */
3727            public WikiPage[] findByN_R_PrevAndNext(long pageId, long nodeId,
3728                    String redirectTitle, OrderByComparator orderByComparator)
3729                    throws NoSuchPageException, SystemException {
3730                    WikiPage wikiPage = findByPrimaryKey(pageId);
3731    
3732                    Session session = null;
3733    
3734                    try {
3735                            session = openSession();
3736    
3737                            WikiPage[] array = new WikiPageImpl[3];
3738    
3739                            array[0] = getByN_R_PrevAndNext(session, wikiPage, nodeId,
3740                                            redirectTitle, orderByComparator, true);
3741    
3742                            array[1] = wikiPage;
3743    
3744                            array[2] = getByN_R_PrevAndNext(session, wikiPage, nodeId,
3745                                            redirectTitle, orderByComparator, false);
3746    
3747                            return array;
3748                    }
3749                    catch (Exception e) {
3750                            throw processException(e);
3751                    }
3752                    finally {
3753                            closeSession(session);
3754                    }
3755            }
3756    
3757            protected WikiPage getByN_R_PrevAndNext(Session session, WikiPage wikiPage,
3758                    long nodeId, String redirectTitle, OrderByComparator orderByComparator,
3759                    boolean previous) {
3760                    StringBundler query = null;
3761    
3762                    if (orderByComparator != null) {
3763                            query = new StringBundler(6 +
3764                                            (orderByComparator.getOrderByFields().length * 6));
3765                    }
3766                    else {
3767                            query = new StringBundler(3);
3768                    }
3769    
3770                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3771    
3772                    query.append(_FINDER_COLUMN_N_R_NODEID_2);
3773    
3774                    if (redirectTitle == null) {
3775                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
3776                    }
3777                    else {
3778                            if (redirectTitle.equals(StringPool.BLANK)) {
3779                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
3780                            }
3781                            else {
3782                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
3783                            }
3784                    }
3785    
3786                    if (orderByComparator != null) {
3787                            String[] orderByFields = orderByComparator.getOrderByFields();
3788    
3789                            if (orderByFields.length > 0) {
3790                                    query.append(WHERE_AND);
3791                            }
3792    
3793                            for (int i = 0; i < orderByFields.length; i++) {
3794                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3795                                    query.append(orderByFields[i]);
3796    
3797                                    if ((i + 1) < orderByFields.length) {
3798                                            if (orderByComparator.isAscending() ^ previous) {
3799                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3800                                            }
3801                                            else {
3802                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3803                                            }
3804                                    }
3805                                    else {
3806                                            if (orderByComparator.isAscending() ^ previous) {
3807                                                    query.append(WHERE_GREATER_THAN);
3808                                            }
3809                                            else {
3810                                                    query.append(WHERE_LESSER_THAN);
3811                                            }
3812                                    }
3813                            }
3814    
3815                            query.append(ORDER_BY_CLAUSE);
3816    
3817                            for (int i = 0; i < orderByFields.length; i++) {
3818                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3819                                    query.append(orderByFields[i]);
3820    
3821                                    if ((i + 1) < orderByFields.length) {
3822                                            if (orderByComparator.isAscending() ^ previous) {
3823                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3824                                            }
3825                                            else {
3826                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3827                                            }
3828                                    }
3829                                    else {
3830                                            if (orderByComparator.isAscending() ^ previous) {
3831                                                    query.append(ORDER_BY_ASC);
3832                                            }
3833                                            else {
3834                                                    query.append(ORDER_BY_DESC);
3835                                            }
3836                                    }
3837                            }
3838                    }
3839    
3840                    else {
3841                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3842                    }
3843    
3844                    String sql = query.toString();
3845    
3846                    Query q = session.createQuery(sql);
3847    
3848                    q.setFirstResult(0);
3849                    q.setMaxResults(2);
3850    
3851                    QueryPos qPos = QueryPos.getInstance(q);
3852    
3853                    qPos.add(nodeId);
3854    
3855                    if (redirectTitle != null) {
3856                            qPos.add(redirectTitle);
3857                    }
3858    
3859                    if (orderByComparator != null) {
3860                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
3861    
3862                            for (Object value : values) {
3863                                    qPos.add(value);
3864                            }
3865                    }
3866    
3867                    List<WikiPage> list = q.list();
3868    
3869                    if (list.size() == 2) {
3870                            return list.get(1);
3871                    }
3872                    else {
3873                            return null;
3874                    }
3875            }
3876    
3877            /**
3878             * Finds all the wiki pages where nodeId = &#63; and status = &#63;.
3879             *
3880             * @param nodeId the node id to search with
3881             * @param status the status to search with
3882             * @return the matching wiki pages
3883             * @throws SystemException if a system exception occurred
3884             */
3885            public List<WikiPage> findByN_S(long nodeId, int status)
3886                    throws SystemException {
3887                    return findByN_S(nodeId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3888                            null);
3889            }
3890    
3891            /**
3892             * Finds a range of all the wiki pages where nodeId = &#63; and status = &#63;.
3893             *
3894             * <p>
3895             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3896             * </p>
3897             *
3898             * @param nodeId the node id to search with
3899             * @param status the status to search with
3900             * @param start the lower bound of the range of wiki pages to return
3901             * @param end the upper bound of the range of wiki pages to return (not inclusive)
3902             * @return the range of matching wiki pages
3903             * @throws SystemException if a system exception occurred
3904             */
3905            public List<WikiPage> findByN_S(long nodeId, int status, int start, int end)
3906                    throws SystemException {
3907                    return findByN_S(nodeId, status, start, end, null);
3908            }
3909    
3910            /**
3911             * Finds an ordered range of all the wiki pages where nodeId = &#63; and status = &#63;.
3912             *
3913             * <p>
3914             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3915             * </p>
3916             *
3917             * @param nodeId the node id to search with
3918             * @param status the status to search with
3919             * @param start the lower bound of the range of wiki pages to return
3920             * @param end the upper bound of the range of wiki pages to return (not inclusive)
3921             * @param orderByComparator the comparator to order the results by
3922             * @return the ordered range of matching wiki pages
3923             * @throws SystemException if a system exception occurred
3924             */
3925            public List<WikiPage> findByN_S(long nodeId, int status, int start,
3926                    int end, OrderByComparator orderByComparator) throws SystemException {
3927                    Object[] finderArgs = new Object[] {
3928                                    nodeId, status,
3929                                    
3930                                    String.valueOf(start), String.valueOf(end),
3931                                    String.valueOf(orderByComparator)
3932                            };
3933    
3934                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_N_S,
3935                                    finderArgs, this);
3936    
3937                    if (list == null) {
3938                            Session session = null;
3939    
3940                            try {
3941                                    session = openSession();
3942    
3943                                    StringBundler query = null;
3944    
3945                                    if (orderByComparator != null) {
3946                                            query = new StringBundler(4 +
3947                                                            (orderByComparator.getOrderByFields().length * 3));
3948                                    }
3949                                    else {
3950                                            query = new StringBundler(4);
3951                                    }
3952    
3953                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3954    
3955                                    query.append(_FINDER_COLUMN_N_S_NODEID_2);
3956    
3957                                    query.append(_FINDER_COLUMN_N_S_STATUS_2);
3958    
3959                                    if (orderByComparator != null) {
3960                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3961                                                    orderByComparator);
3962                                    }
3963    
3964                                    else {
3965                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3966                                    }
3967    
3968                                    String sql = query.toString();
3969    
3970                                    Query q = session.createQuery(sql);
3971    
3972                                    QueryPos qPos = QueryPos.getInstance(q);
3973    
3974                                    qPos.add(nodeId);
3975    
3976                                    qPos.add(status);
3977    
3978                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
3979                                                    end);
3980                            }
3981                            catch (Exception e) {
3982                                    throw processException(e);
3983                            }
3984                            finally {
3985                                    if (list == null) {
3986                                            list = new ArrayList<WikiPage>();
3987                                    }
3988    
3989                                    cacheResult(list);
3990    
3991                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_N_S, finderArgs,
3992                                            list);
3993    
3994                                    closeSession(session);
3995                            }
3996                    }
3997    
3998                    return list;
3999            }
4000    
4001            /**
4002             * Finds the first wiki page in the ordered set where nodeId = &#63; and status = &#63;.
4003             *
4004             * <p>
4005             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4006             * </p>
4007             *
4008             * @param nodeId the node id to search with
4009             * @param status the status to search with
4010             * @param orderByComparator the comparator to order the set by
4011             * @return the first matching wiki page
4012             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4013             * @throws SystemException if a system exception occurred
4014             */
4015            public WikiPage findByN_S_First(long nodeId, int status,
4016                    OrderByComparator orderByComparator)
4017                    throws NoSuchPageException, SystemException {
4018                    List<WikiPage> list = findByN_S(nodeId, status, 0, 1, orderByComparator);
4019    
4020                    if (list.isEmpty()) {
4021                            StringBundler msg = new StringBundler(6);
4022    
4023                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4024    
4025                            msg.append("nodeId=");
4026                            msg.append(nodeId);
4027    
4028                            msg.append(", status=");
4029                            msg.append(status);
4030    
4031                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4032    
4033                            throw new NoSuchPageException(msg.toString());
4034                    }
4035                    else {
4036                            return list.get(0);
4037                    }
4038            }
4039    
4040            /**
4041             * Finds the last wiki page in the ordered set where nodeId = &#63; and status = &#63;.
4042             *
4043             * <p>
4044             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4045             * </p>
4046             *
4047             * @param nodeId the node id to search with
4048             * @param status the status to search with
4049             * @param orderByComparator the comparator to order the set by
4050             * @return the last matching wiki page
4051             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4052             * @throws SystemException if a system exception occurred
4053             */
4054            public WikiPage findByN_S_Last(long nodeId, int status,
4055                    OrderByComparator orderByComparator)
4056                    throws NoSuchPageException, SystemException {
4057                    int count = countByN_S(nodeId, status);
4058    
4059                    List<WikiPage> list = findByN_S(nodeId, status, count - 1, count,
4060                                    orderByComparator);
4061    
4062                    if (list.isEmpty()) {
4063                            StringBundler msg = new StringBundler(6);
4064    
4065                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4066    
4067                            msg.append("nodeId=");
4068                            msg.append(nodeId);
4069    
4070                            msg.append(", status=");
4071                            msg.append(status);
4072    
4073                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4074    
4075                            throw new NoSuchPageException(msg.toString());
4076                    }
4077                    else {
4078                            return list.get(0);
4079                    }
4080            }
4081    
4082            /**
4083             * Finds the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and status = &#63;.
4084             *
4085             * <p>
4086             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4087             * </p>
4088             *
4089             * @param pageId the primary key of the current wiki page
4090             * @param nodeId the node id to search with
4091             * @param status the status to search with
4092             * @param orderByComparator the comparator to order the set by
4093             * @return the previous, current, and next wiki page
4094             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
4095             * @throws SystemException if a system exception occurred
4096             */
4097            public WikiPage[] findByN_S_PrevAndNext(long pageId, long nodeId,
4098                    int status, OrderByComparator orderByComparator)
4099                    throws NoSuchPageException, SystemException {
4100                    WikiPage wikiPage = findByPrimaryKey(pageId);
4101    
4102                    Session session = null;
4103    
4104                    try {
4105                            session = openSession();
4106    
4107                            WikiPage[] array = new WikiPageImpl[3];
4108    
4109                            array[0] = getByN_S_PrevAndNext(session, wikiPage, nodeId, status,
4110                                            orderByComparator, true);
4111    
4112                            array[1] = wikiPage;
4113    
4114                            array[2] = getByN_S_PrevAndNext(session, wikiPage, nodeId, status,
4115                                            orderByComparator, false);
4116    
4117                            return array;
4118                    }
4119                    catch (Exception e) {
4120                            throw processException(e);
4121                    }
4122                    finally {
4123                            closeSession(session);
4124                    }
4125            }
4126    
4127            protected WikiPage getByN_S_PrevAndNext(Session session, WikiPage wikiPage,
4128                    long nodeId, int status, OrderByComparator orderByComparator,
4129                    boolean previous) {
4130                    StringBundler query = null;
4131    
4132                    if (orderByComparator != null) {
4133                            query = new StringBundler(6 +
4134                                            (orderByComparator.getOrderByFields().length * 6));
4135                    }
4136                    else {
4137                            query = new StringBundler(3);
4138                    }
4139    
4140                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4141    
4142                    query.append(_FINDER_COLUMN_N_S_NODEID_2);
4143    
4144                    query.append(_FINDER_COLUMN_N_S_STATUS_2);
4145    
4146                    if (orderByComparator != null) {
4147                            String[] orderByFields = orderByComparator.getOrderByFields();
4148    
4149                            if (orderByFields.length > 0) {
4150                                    query.append(WHERE_AND);
4151                            }
4152    
4153                            for (int i = 0; i < orderByFields.length; i++) {
4154                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4155                                    query.append(orderByFields[i]);
4156    
4157                                    if ((i + 1) < orderByFields.length) {
4158                                            if (orderByComparator.isAscending() ^ previous) {
4159                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4160                                            }
4161                                            else {
4162                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4163                                            }
4164                                    }
4165                                    else {
4166                                            if (orderByComparator.isAscending() ^ previous) {
4167                                                    query.append(WHERE_GREATER_THAN);
4168                                            }
4169                                            else {
4170                                                    query.append(WHERE_LESSER_THAN);
4171                                            }
4172                                    }
4173                            }
4174    
4175                            query.append(ORDER_BY_CLAUSE);
4176    
4177                            for (int i = 0; i < orderByFields.length; i++) {
4178                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4179                                    query.append(orderByFields[i]);
4180    
4181                                    if ((i + 1) < orderByFields.length) {
4182                                            if (orderByComparator.isAscending() ^ previous) {
4183                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4184                                            }
4185                                            else {
4186                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4187                                            }
4188                                    }
4189                                    else {
4190                                            if (orderByComparator.isAscending() ^ previous) {
4191                                                    query.append(ORDER_BY_ASC);
4192                                            }
4193                                            else {
4194                                                    query.append(ORDER_BY_DESC);
4195                                            }
4196                                    }
4197                            }
4198                    }
4199    
4200                    else {
4201                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4202                    }
4203    
4204                    String sql = query.toString();
4205    
4206                    Query q = session.createQuery(sql);
4207    
4208                    q.setFirstResult(0);
4209                    q.setMaxResults(2);
4210    
4211                    QueryPos qPos = QueryPos.getInstance(q);
4212    
4213                    qPos.add(nodeId);
4214    
4215                    qPos.add(status);
4216    
4217                    if (orderByComparator != null) {
4218                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
4219    
4220                            for (Object value : values) {
4221                                    qPos.add(value);
4222                            }
4223                    }
4224    
4225                    List<WikiPage> list = q.list();
4226    
4227                    if (list.size() == 2) {
4228                            return list.get(1);
4229                    }
4230                    else {
4231                            return null;
4232                    }
4233            }
4234    
4235            /**
4236             * Finds the wiki page where resourcePrimKey = &#63; and nodeId = &#63; and version = &#63; or throws a {@link com.liferay.portlet.wiki.NoSuchPageException} if it could not be found.
4237             *
4238             * @param resourcePrimKey the resource prim key to search with
4239             * @param nodeId the node id to search with
4240             * @param version the version to search with
4241             * @return the matching wiki page
4242             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4243             * @throws SystemException if a system exception occurred
4244             */
4245            public WikiPage findByR_N_V(long resourcePrimKey, long nodeId,
4246                    double version) throws NoSuchPageException, SystemException {
4247                    WikiPage wikiPage = fetchByR_N_V(resourcePrimKey, nodeId, version);
4248    
4249                    if (wikiPage == null) {
4250                            StringBundler msg = new StringBundler(8);
4251    
4252                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4253    
4254                            msg.append("resourcePrimKey=");
4255                            msg.append(resourcePrimKey);
4256    
4257                            msg.append(", nodeId=");
4258                            msg.append(nodeId);
4259    
4260                            msg.append(", version=");
4261                            msg.append(version);
4262    
4263                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4264    
4265                            if (_log.isWarnEnabled()) {
4266                                    _log.warn(msg.toString());
4267                            }
4268    
4269                            throw new NoSuchPageException(msg.toString());
4270                    }
4271    
4272                    return wikiPage;
4273            }
4274    
4275            /**
4276             * Finds the wiki page where resourcePrimKey = &#63; and nodeId = &#63; and version = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4277             *
4278             * @param resourcePrimKey the resource prim key to search with
4279             * @param nodeId the node id to search with
4280             * @param version the version to search with
4281             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
4282             * @throws SystemException if a system exception occurred
4283             */
4284            public WikiPage fetchByR_N_V(long resourcePrimKey, long nodeId,
4285                    double version) throws SystemException {
4286                    return fetchByR_N_V(resourcePrimKey, nodeId, version, true);
4287            }
4288    
4289            /**
4290             * Finds the wiki page where resourcePrimKey = &#63; and nodeId = &#63; and version = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4291             *
4292             * @param resourcePrimKey the resource prim key to search with
4293             * @param nodeId the node id to search with
4294             * @param version the version to search with
4295             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
4296             * @throws SystemException if a system exception occurred
4297             */
4298            public WikiPage fetchByR_N_V(long resourcePrimKey, long nodeId,
4299                    double version, boolean retrieveFromCache) throws SystemException {
4300                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, version };
4301    
4302                    Object result = null;
4303    
4304                    if (retrieveFromCache) {
4305                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_R_N_V,
4306                                            finderArgs, this);
4307                    }
4308    
4309                    if (result == null) {
4310                            Session session = null;
4311    
4312                            try {
4313                                    session = openSession();
4314    
4315                                    StringBundler query = new StringBundler(5);
4316    
4317                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4318    
4319                                    query.append(_FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2);
4320    
4321                                    query.append(_FINDER_COLUMN_R_N_V_NODEID_2);
4322    
4323                                    query.append(_FINDER_COLUMN_R_N_V_VERSION_2);
4324    
4325                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4326    
4327                                    String sql = query.toString();
4328    
4329                                    Query q = session.createQuery(sql);
4330    
4331                                    QueryPos qPos = QueryPos.getInstance(q);
4332    
4333                                    qPos.add(resourcePrimKey);
4334    
4335                                    qPos.add(nodeId);
4336    
4337                                    qPos.add(version);
4338    
4339                                    List<WikiPage> list = q.list();
4340    
4341                                    result = list;
4342    
4343                                    WikiPage wikiPage = null;
4344    
4345                                    if (list.isEmpty()) {
4346                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
4347                                                    finderArgs, list);
4348                                    }
4349                                    else {
4350                                            wikiPage = list.get(0);
4351    
4352                                            cacheResult(wikiPage);
4353    
4354                                            if ((wikiPage.getResourcePrimKey() != resourcePrimKey) ||
4355                                                            (wikiPage.getNodeId() != nodeId) ||
4356                                                            (wikiPage.getVersion() != version)) {
4357                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
4358                                                            finderArgs, wikiPage);
4359                                            }
4360                                    }
4361    
4362                                    return wikiPage;
4363                            }
4364                            catch (Exception e) {
4365                                    throw processException(e);
4366                            }
4367                            finally {
4368                                    if (result == null) {
4369                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
4370                                                    finderArgs, new ArrayList<WikiPage>());
4371                                    }
4372    
4373                                    closeSession(session);
4374                            }
4375                    }
4376                    else {
4377                            if (result instanceof List<?>) {
4378                                    return null;
4379                            }
4380                            else {
4381                                    return (WikiPage)result;
4382                            }
4383                    }
4384            }
4385    
4386            /**
4387             * Finds all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
4388             *
4389             * @param resourcePrimKey the resource prim key to search with
4390             * @param nodeId the node id to search with
4391             * @param status the status to search with
4392             * @return the matching wiki pages
4393             * @throws SystemException if a system exception occurred
4394             */
4395            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
4396                    int status) throws SystemException {
4397                    return findByR_N_S(resourcePrimKey, nodeId, status, QueryUtil.ALL_POS,
4398                            QueryUtil.ALL_POS, null);
4399            }
4400    
4401            /**
4402             * Finds a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
4403             *
4404             * <p>
4405             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4406             * </p>
4407             *
4408             * @param resourcePrimKey the resource prim key to search with
4409             * @param nodeId the node id to search with
4410             * @param status the status to search with
4411             * @param start the lower bound of the range of wiki pages to return
4412             * @param end the upper bound of the range of wiki pages to return (not inclusive)
4413             * @return the range of matching wiki pages
4414             * @throws SystemException if a system exception occurred
4415             */
4416            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
4417                    int status, int start, int end) throws SystemException {
4418                    return findByR_N_S(resourcePrimKey, nodeId, status, start, end, null);
4419            }
4420    
4421            /**
4422             * Finds an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
4423             *
4424             * <p>
4425             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4426             * </p>
4427             *
4428             * @param resourcePrimKey the resource prim key to search with
4429             * @param nodeId the node id to search with
4430             * @param status the status to search with
4431             * @param start the lower bound of the range of wiki pages to return
4432             * @param end the upper bound of the range of wiki pages to return (not inclusive)
4433             * @param orderByComparator the comparator to order the results by
4434             * @return the ordered range of matching wiki pages
4435             * @throws SystemException if a system exception occurred
4436             */
4437            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
4438                    int status, int start, int end, OrderByComparator orderByComparator)
4439                    throws SystemException {
4440                    Object[] finderArgs = new Object[] {
4441                                    resourcePrimKey, nodeId, status,
4442                                    
4443                                    String.valueOf(start), String.valueOf(end),
4444                                    String.valueOf(orderByComparator)
4445                            };
4446    
4447                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_R_N_S,
4448                                    finderArgs, this);
4449    
4450                    if (list == null) {
4451                            Session session = null;
4452    
4453                            try {
4454                                    session = openSession();
4455    
4456                                    StringBundler query = null;
4457    
4458                                    if (orderByComparator != null) {
4459                                            query = new StringBundler(5 +
4460                                                            (orderByComparator.getOrderByFields().length * 3));
4461                                    }
4462                                    else {
4463                                            query = new StringBundler(5);
4464                                    }
4465    
4466                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4467    
4468                                    query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
4469    
4470                                    query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
4471    
4472                                    query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
4473    
4474                                    if (orderByComparator != null) {
4475                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4476                                                    orderByComparator);
4477                                    }
4478    
4479                                    else {
4480                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4481                                    }
4482    
4483                                    String sql = query.toString();
4484    
4485                                    Query q = session.createQuery(sql);
4486    
4487                                    QueryPos qPos = QueryPos.getInstance(q);
4488    
4489                                    qPos.add(resourcePrimKey);
4490    
4491                                    qPos.add(nodeId);
4492    
4493                                    qPos.add(status);
4494    
4495                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
4496                                                    end);
4497                            }
4498                            catch (Exception e) {
4499                                    throw processException(e);
4500                            }
4501                            finally {
4502                                    if (list == null) {
4503                                            list = new ArrayList<WikiPage>();
4504                                    }
4505    
4506                                    cacheResult(list);
4507    
4508                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_R_N_S,
4509                                            finderArgs, list);
4510    
4511                                    closeSession(session);
4512                            }
4513                    }
4514    
4515                    return list;
4516            }
4517    
4518            /**
4519             * Finds the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
4520             *
4521             * <p>
4522             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4523             * </p>
4524             *
4525             * @param resourcePrimKey the resource prim key to search with
4526             * @param nodeId the node id to search with
4527             * @param status the status to search with
4528             * @param orderByComparator the comparator to order the set by
4529             * @return the first matching wiki page
4530             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4531             * @throws SystemException if a system exception occurred
4532             */
4533            public WikiPage findByR_N_S_First(long resourcePrimKey, long nodeId,
4534                    int status, OrderByComparator orderByComparator)
4535                    throws NoSuchPageException, SystemException {
4536                    List<WikiPage> list = findByR_N_S(resourcePrimKey, nodeId, status, 0,
4537                                    1, orderByComparator);
4538    
4539                    if (list.isEmpty()) {
4540                            StringBundler msg = new StringBundler(8);
4541    
4542                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4543    
4544                            msg.append("resourcePrimKey=");
4545                            msg.append(resourcePrimKey);
4546    
4547                            msg.append(", nodeId=");
4548                            msg.append(nodeId);
4549    
4550                            msg.append(", status=");
4551                            msg.append(status);
4552    
4553                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4554    
4555                            throw new NoSuchPageException(msg.toString());
4556                    }
4557                    else {
4558                            return list.get(0);
4559                    }
4560            }
4561    
4562            /**
4563             * Finds the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
4564             *
4565             * <p>
4566             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4567             * </p>
4568             *
4569             * @param resourcePrimKey the resource prim key to search with
4570             * @param nodeId the node id to search with
4571             * @param status the status to search with
4572             * @param orderByComparator the comparator to order the set by
4573             * @return the last matching wiki page
4574             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4575             * @throws SystemException if a system exception occurred
4576             */
4577            public WikiPage findByR_N_S_Last(long resourcePrimKey, long nodeId,
4578                    int status, OrderByComparator orderByComparator)
4579                    throws NoSuchPageException, SystemException {
4580                    int count = countByR_N_S(resourcePrimKey, nodeId, status);
4581    
4582                    List<WikiPage> list = findByR_N_S(resourcePrimKey, nodeId, status,
4583                                    count - 1, count, orderByComparator);
4584    
4585                    if (list.isEmpty()) {
4586                            StringBundler msg = new StringBundler(8);
4587    
4588                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4589    
4590                            msg.append("resourcePrimKey=");
4591                            msg.append(resourcePrimKey);
4592    
4593                            msg.append(", nodeId=");
4594                            msg.append(nodeId);
4595    
4596                            msg.append(", status=");
4597                            msg.append(status);
4598    
4599                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4600    
4601                            throw new NoSuchPageException(msg.toString());
4602                    }
4603                    else {
4604                            return list.get(0);
4605                    }
4606            }
4607    
4608            /**
4609             * Finds the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
4610             *
4611             * <p>
4612             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4613             * </p>
4614             *
4615             * @param pageId the primary key of the current wiki page
4616             * @param resourcePrimKey the resource prim key to search with
4617             * @param nodeId the node id to search with
4618             * @param status the status to search with
4619             * @param orderByComparator the comparator to order the set by
4620             * @return the previous, current, and next wiki page
4621             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
4622             * @throws SystemException if a system exception occurred
4623             */
4624            public WikiPage[] findByR_N_S_PrevAndNext(long pageId,
4625                    long resourcePrimKey, long nodeId, int status,
4626                    OrderByComparator orderByComparator)
4627                    throws NoSuchPageException, SystemException {
4628                    WikiPage wikiPage = findByPrimaryKey(pageId);
4629    
4630                    Session session = null;
4631    
4632                    try {
4633                            session = openSession();
4634    
4635                            WikiPage[] array = new WikiPageImpl[3];
4636    
4637                            array[0] = getByR_N_S_PrevAndNext(session, wikiPage,
4638                                            resourcePrimKey, nodeId, status, orderByComparator, true);
4639    
4640                            array[1] = wikiPage;
4641    
4642                            array[2] = getByR_N_S_PrevAndNext(session, wikiPage,
4643                                            resourcePrimKey, nodeId, status, orderByComparator, false);
4644    
4645                            return array;
4646                    }
4647                    catch (Exception e) {
4648                            throw processException(e);
4649                    }
4650                    finally {
4651                            closeSession(session);
4652                    }
4653            }
4654    
4655            protected WikiPage getByR_N_S_PrevAndNext(Session session,
4656                    WikiPage wikiPage, long resourcePrimKey, long nodeId, int status,
4657                    OrderByComparator orderByComparator, boolean previous) {
4658                    StringBundler query = null;
4659    
4660                    if (orderByComparator != null) {
4661                            query = new StringBundler(6 +
4662                                            (orderByComparator.getOrderByFields().length * 6));
4663                    }
4664                    else {
4665                            query = new StringBundler(3);
4666                    }
4667    
4668                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4669    
4670                    query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
4671    
4672                    query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
4673    
4674                    query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
4675    
4676                    if (orderByComparator != null) {
4677                            String[] orderByFields = orderByComparator.getOrderByFields();
4678    
4679                            if (orderByFields.length > 0) {
4680                                    query.append(WHERE_AND);
4681                            }
4682    
4683                            for (int i = 0; i < orderByFields.length; i++) {
4684                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4685                                    query.append(orderByFields[i]);
4686    
4687                                    if ((i + 1) < orderByFields.length) {
4688                                            if (orderByComparator.isAscending() ^ previous) {
4689                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4690                                            }
4691                                            else {
4692                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4693                                            }
4694                                    }
4695                                    else {
4696                                            if (orderByComparator.isAscending() ^ previous) {
4697                                                    query.append(WHERE_GREATER_THAN);
4698                                            }
4699                                            else {
4700                                                    query.append(WHERE_LESSER_THAN);
4701                                            }
4702                                    }
4703                            }
4704    
4705                            query.append(ORDER_BY_CLAUSE);
4706    
4707                            for (int i = 0; i < orderByFields.length; i++) {
4708                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4709                                    query.append(orderByFields[i]);
4710    
4711                                    if ((i + 1) < orderByFields.length) {
4712                                            if (orderByComparator.isAscending() ^ previous) {
4713                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4714                                            }
4715                                            else {
4716                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4717                                            }
4718                                    }
4719                                    else {
4720                                            if (orderByComparator.isAscending() ^ previous) {
4721                                                    query.append(ORDER_BY_ASC);
4722                                            }
4723                                            else {
4724                                                    query.append(ORDER_BY_DESC);
4725                                            }
4726                                    }
4727                            }
4728                    }
4729    
4730                    else {
4731                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4732                    }
4733    
4734                    String sql = query.toString();
4735    
4736                    Query q = session.createQuery(sql);
4737    
4738                    q.setFirstResult(0);
4739                    q.setMaxResults(2);
4740    
4741                    QueryPos qPos = QueryPos.getInstance(q);
4742    
4743                    qPos.add(resourcePrimKey);
4744    
4745                    qPos.add(nodeId);
4746    
4747                    qPos.add(status);
4748    
4749                    if (orderByComparator != null) {
4750                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
4751    
4752                            for (Object value : values) {
4753                                    qPos.add(value);
4754                            }
4755                    }
4756    
4757                    List<WikiPage> list = q.list();
4758    
4759                    if (list.size() == 2) {
4760                            return list.get(1);
4761                    }
4762                    else {
4763                            return null;
4764                    }
4765            }
4766    
4767            /**
4768             * Finds all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
4769             *
4770             * @param userId the user id to search with
4771             * @param nodeId the node id to search with
4772             * @param status the status to search with
4773             * @return the matching wiki pages
4774             * @throws SystemException if a system exception occurred
4775             */
4776            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status)
4777                    throws SystemException {
4778                    return findByU_N_S(userId, nodeId, status, QueryUtil.ALL_POS,
4779                            QueryUtil.ALL_POS, null);
4780            }
4781    
4782            /**
4783             * Finds a range of all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
4784             *
4785             * <p>
4786             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4787             * </p>
4788             *
4789             * @param userId the user id to search with
4790             * @param nodeId the node id to search with
4791             * @param status the status to search with
4792             * @param start the lower bound of the range of wiki pages to return
4793             * @param end the upper bound of the range of wiki pages to return (not inclusive)
4794             * @return the range of matching wiki pages
4795             * @throws SystemException if a system exception occurred
4796             */
4797            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status,
4798                    int start, int end) throws SystemException {
4799                    return findByU_N_S(userId, nodeId, status, start, end, null);
4800            }
4801    
4802            /**
4803             * Finds an ordered range of all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
4804             *
4805             * <p>
4806             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4807             * </p>
4808             *
4809             * @param userId the user id to search with
4810             * @param nodeId the node id to search with
4811             * @param status the status to search with
4812             * @param start the lower bound of the range of wiki pages to return
4813             * @param end the upper bound of the range of wiki pages to return (not inclusive)
4814             * @param orderByComparator the comparator to order the results by
4815             * @return the ordered range of matching wiki pages
4816             * @throws SystemException if a system exception occurred
4817             */
4818            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status,
4819                    int start, int end, OrderByComparator orderByComparator)
4820                    throws SystemException {
4821                    Object[] finderArgs = new Object[] {
4822                                    userId, nodeId, status,
4823                                    
4824                                    String.valueOf(start), String.valueOf(end),
4825                                    String.valueOf(orderByComparator)
4826                            };
4827    
4828                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_N_S,
4829                                    finderArgs, this);
4830    
4831                    if (list == null) {
4832                            Session session = null;
4833    
4834                            try {
4835                                    session = openSession();
4836    
4837                                    StringBundler query = null;
4838    
4839                                    if (orderByComparator != null) {
4840                                            query = new StringBundler(5 +
4841                                                            (orderByComparator.getOrderByFields().length * 3));
4842                                    }
4843                                    else {
4844                                            query = new StringBundler(5);
4845                                    }
4846    
4847                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4848    
4849                                    query.append(_FINDER_COLUMN_U_N_S_USERID_2);
4850    
4851                                    query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
4852    
4853                                    query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
4854    
4855                                    if (orderByComparator != null) {
4856                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4857                                                    orderByComparator);
4858                                    }
4859    
4860                                    else {
4861                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4862                                    }
4863    
4864                                    String sql = query.toString();
4865    
4866                                    Query q = session.createQuery(sql);
4867    
4868                                    QueryPos qPos = QueryPos.getInstance(q);
4869    
4870                                    qPos.add(userId);
4871    
4872                                    qPos.add(nodeId);
4873    
4874                                    qPos.add(status);
4875    
4876                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
4877                                                    end);
4878                            }
4879                            catch (Exception e) {
4880                                    throw processException(e);
4881                            }
4882                            finally {
4883                                    if (list == null) {
4884                                            list = new ArrayList<WikiPage>();
4885                                    }
4886    
4887                                    cacheResult(list);
4888    
4889                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_N_S,
4890                                            finderArgs, list);
4891    
4892                                    closeSession(session);
4893                            }
4894                    }
4895    
4896                    return list;
4897            }
4898    
4899            /**
4900             * Finds the first wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
4901             *
4902             * <p>
4903             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4904             * </p>
4905             *
4906             * @param userId the user id to search with
4907             * @param nodeId the node id to search with
4908             * @param status the status to search with
4909             * @param orderByComparator the comparator to order the set by
4910             * @return the first matching wiki page
4911             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4912             * @throws SystemException if a system exception occurred
4913             */
4914            public WikiPage findByU_N_S_First(long userId, long nodeId, int status,
4915                    OrderByComparator orderByComparator)
4916                    throws NoSuchPageException, SystemException {
4917                    List<WikiPage> list = findByU_N_S(userId, nodeId, status, 0, 1,
4918                                    orderByComparator);
4919    
4920                    if (list.isEmpty()) {
4921                            StringBundler msg = new StringBundler(8);
4922    
4923                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4924    
4925                            msg.append("userId=");
4926                            msg.append(userId);
4927    
4928                            msg.append(", nodeId=");
4929                            msg.append(nodeId);
4930    
4931                            msg.append(", status=");
4932                            msg.append(status);
4933    
4934                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4935    
4936                            throw new NoSuchPageException(msg.toString());
4937                    }
4938                    else {
4939                            return list.get(0);
4940                    }
4941            }
4942    
4943            /**
4944             * Finds the last wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
4945             *
4946             * <p>
4947             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4948             * </p>
4949             *
4950             * @param userId the user id to search with
4951             * @param nodeId the node id to search with
4952             * @param status the status to search with
4953             * @param orderByComparator the comparator to order the set by
4954             * @return the last matching wiki page
4955             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4956             * @throws SystemException if a system exception occurred
4957             */
4958            public WikiPage findByU_N_S_Last(long userId, long nodeId, int status,
4959                    OrderByComparator orderByComparator)
4960                    throws NoSuchPageException, SystemException {
4961                    int count = countByU_N_S(userId, nodeId, status);
4962    
4963                    List<WikiPage> list = findByU_N_S(userId, nodeId, status, count - 1,
4964                                    count, orderByComparator);
4965    
4966                    if (list.isEmpty()) {
4967                            StringBundler msg = new StringBundler(8);
4968    
4969                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4970    
4971                            msg.append("userId=");
4972                            msg.append(userId);
4973    
4974                            msg.append(", nodeId=");
4975                            msg.append(nodeId);
4976    
4977                            msg.append(", status=");
4978                            msg.append(status);
4979    
4980                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4981    
4982                            throw new NoSuchPageException(msg.toString());
4983                    }
4984                    else {
4985                            return list.get(0);
4986                    }
4987            }
4988    
4989            /**
4990             * Finds the wiki pages before and after the current wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
4991             *
4992             * <p>
4993             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4994             * </p>
4995             *
4996             * @param pageId the primary key of the current wiki page
4997             * @param userId the user id to search with
4998             * @param nodeId the node id to search with
4999             * @param status the status to search with
5000             * @param orderByComparator the comparator to order the set by
5001             * @return the previous, current, and next wiki page
5002             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
5003             * @throws SystemException if a system exception occurred
5004             */
5005            public WikiPage[] findByU_N_S_PrevAndNext(long pageId, long userId,
5006                    long nodeId, int status, OrderByComparator orderByComparator)
5007                    throws NoSuchPageException, SystemException {
5008                    WikiPage wikiPage = findByPrimaryKey(pageId);
5009    
5010                    Session session = null;
5011    
5012                    try {
5013                            session = openSession();
5014    
5015                            WikiPage[] array = new WikiPageImpl[3];
5016    
5017                            array[0] = getByU_N_S_PrevAndNext(session, wikiPage, userId,
5018                                            nodeId, status, orderByComparator, true);
5019    
5020                            array[1] = wikiPage;
5021    
5022                            array[2] = getByU_N_S_PrevAndNext(session, wikiPage, userId,
5023                                            nodeId, status, orderByComparator, false);
5024    
5025                            return array;
5026                    }
5027                    catch (Exception e) {
5028                            throw processException(e);
5029                    }
5030                    finally {
5031                            closeSession(session);
5032                    }
5033            }
5034    
5035            protected WikiPage getByU_N_S_PrevAndNext(Session session,
5036                    WikiPage wikiPage, long userId, long nodeId, int status,
5037                    OrderByComparator orderByComparator, boolean previous) {
5038                    StringBundler query = null;
5039    
5040                    if (orderByComparator != null) {
5041                            query = new StringBundler(6 +
5042                                            (orderByComparator.getOrderByFields().length * 6));
5043                    }
5044                    else {
5045                            query = new StringBundler(3);
5046                    }
5047    
5048                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5049    
5050                    query.append(_FINDER_COLUMN_U_N_S_USERID_2);
5051    
5052                    query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
5053    
5054                    query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
5055    
5056                    if (orderByComparator != null) {
5057                            String[] orderByFields = orderByComparator.getOrderByFields();
5058    
5059                            if (orderByFields.length > 0) {
5060                                    query.append(WHERE_AND);
5061                            }
5062    
5063                            for (int i = 0; i < orderByFields.length; i++) {
5064                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5065                                    query.append(orderByFields[i]);
5066    
5067                                    if ((i + 1) < orderByFields.length) {
5068                                            if (orderByComparator.isAscending() ^ previous) {
5069                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5070                                            }
5071                                            else {
5072                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5073                                            }
5074                                    }
5075                                    else {
5076                                            if (orderByComparator.isAscending() ^ previous) {
5077                                                    query.append(WHERE_GREATER_THAN);
5078                                            }
5079                                            else {
5080                                                    query.append(WHERE_LESSER_THAN);
5081                                            }
5082                                    }
5083                            }
5084    
5085                            query.append(ORDER_BY_CLAUSE);
5086    
5087                            for (int i = 0; i < orderByFields.length; i++) {
5088                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5089                                    query.append(orderByFields[i]);
5090    
5091                                    if ((i + 1) < orderByFields.length) {
5092                                            if (orderByComparator.isAscending() ^ previous) {
5093                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5094                                            }
5095                                            else {
5096                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5097                                            }
5098                                    }
5099                                    else {
5100                                            if (orderByComparator.isAscending() ^ previous) {
5101                                                    query.append(ORDER_BY_ASC);
5102                                            }
5103                                            else {
5104                                                    query.append(ORDER_BY_DESC);
5105                                            }
5106                                    }
5107                            }
5108                    }
5109    
5110                    else {
5111                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5112                    }
5113    
5114                    String sql = query.toString();
5115    
5116                    Query q = session.createQuery(sql);
5117    
5118                    q.setFirstResult(0);
5119                    q.setMaxResults(2);
5120    
5121                    QueryPos qPos = QueryPos.getInstance(q);
5122    
5123                    qPos.add(userId);
5124    
5125                    qPos.add(nodeId);
5126    
5127                    qPos.add(status);
5128    
5129                    if (orderByComparator != null) {
5130                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
5131    
5132                            for (Object value : values) {
5133                                    qPos.add(value);
5134                            }
5135                    }
5136    
5137                    List<WikiPage> list = q.list();
5138    
5139                    if (list.size() == 2) {
5140                            return list.get(1);
5141                    }
5142                    else {
5143                            return null;
5144                    }
5145            }
5146    
5147            /**
5148             * Finds the wiki page where nodeId = &#63; and title = &#63; and version = &#63; or throws a {@link com.liferay.portlet.wiki.NoSuchPageException} if it could not be found.
5149             *
5150             * @param nodeId the node id to search with
5151             * @param title the title to search with
5152             * @param version the version to search with
5153             * @return the matching wiki page
5154             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5155             * @throws SystemException if a system exception occurred
5156             */
5157            public WikiPage findByN_T_V(long nodeId, String title, double version)
5158                    throws NoSuchPageException, SystemException {
5159                    WikiPage wikiPage = fetchByN_T_V(nodeId, title, version);
5160    
5161                    if (wikiPage == null) {
5162                            StringBundler msg = new StringBundler(8);
5163    
5164                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5165    
5166                            msg.append("nodeId=");
5167                            msg.append(nodeId);
5168    
5169                            msg.append(", title=");
5170                            msg.append(title);
5171    
5172                            msg.append(", version=");
5173                            msg.append(version);
5174    
5175                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5176    
5177                            if (_log.isWarnEnabled()) {
5178                                    _log.warn(msg.toString());
5179                            }
5180    
5181                            throw new NoSuchPageException(msg.toString());
5182                    }
5183    
5184                    return wikiPage;
5185            }
5186    
5187            /**
5188             * Finds the wiki page where nodeId = &#63; and title = &#63; and version = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
5189             *
5190             * @param nodeId the node id to search with
5191             * @param title the title to search with
5192             * @param version the version to search with
5193             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
5194             * @throws SystemException if a system exception occurred
5195             */
5196            public WikiPage fetchByN_T_V(long nodeId, String title, double version)
5197                    throws SystemException {
5198                    return fetchByN_T_V(nodeId, title, version, true);
5199            }
5200    
5201            /**
5202             * Finds the wiki page where nodeId = &#63; and title = &#63; and version = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
5203             *
5204             * @param nodeId the node id to search with
5205             * @param title the title to search with
5206             * @param version the version to search with
5207             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
5208             * @throws SystemException if a system exception occurred
5209             */
5210            public WikiPage fetchByN_T_V(long nodeId, String title, double version,
5211                    boolean retrieveFromCache) throws SystemException {
5212                    Object[] finderArgs = new Object[] { nodeId, title, version };
5213    
5214                    Object result = null;
5215    
5216                    if (retrieveFromCache) {
5217                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T_V,
5218                                            finderArgs, this);
5219                    }
5220    
5221                    if (result == null) {
5222                            Session session = null;
5223    
5224                            try {
5225                                    session = openSession();
5226    
5227                                    StringBundler query = new StringBundler(5);
5228    
5229                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5230    
5231                                    query.append(_FINDER_COLUMN_N_T_V_NODEID_2);
5232    
5233                                    if (title == null) {
5234                                            query.append(_FINDER_COLUMN_N_T_V_TITLE_1);
5235                                    }
5236                                    else {
5237                                            if (title.equals(StringPool.BLANK)) {
5238                                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_3);
5239                                            }
5240                                            else {
5241                                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_2);
5242                                            }
5243                                    }
5244    
5245                                    query.append(_FINDER_COLUMN_N_T_V_VERSION_2);
5246    
5247                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5248    
5249                                    String sql = query.toString();
5250    
5251                                    Query q = session.createQuery(sql);
5252    
5253                                    QueryPos qPos = QueryPos.getInstance(q);
5254    
5255                                    qPos.add(nodeId);
5256    
5257                                    if (title != null) {
5258                                            qPos.add(title);
5259                                    }
5260    
5261                                    qPos.add(version);
5262    
5263                                    List<WikiPage> list = q.list();
5264    
5265                                    result = list;
5266    
5267                                    WikiPage wikiPage = null;
5268    
5269                                    if (list.isEmpty()) {
5270                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
5271                                                    finderArgs, list);
5272                                    }
5273                                    else {
5274                                            wikiPage = list.get(0);
5275    
5276                                            cacheResult(wikiPage);
5277    
5278                                            if ((wikiPage.getNodeId() != nodeId) ||
5279                                                            (wikiPage.getTitle() == null) ||
5280                                                            !wikiPage.getTitle().equals(title) ||
5281                                                            (wikiPage.getVersion() != version)) {
5282                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
5283                                                            finderArgs, wikiPage);
5284                                            }
5285                                    }
5286    
5287                                    return wikiPage;
5288                            }
5289                            catch (Exception e) {
5290                                    throw processException(e);
5291                            }
5292                            finally {
5293                                    if (result == null) {
5294                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
5295                                                    finderArgs, new ArrayList<WikiPage>());
5296                                    }
5297    
5298                                    closeSession(session);
5299                            }
5300                    }
5301                    else {
5302                            if (result instanceof List<?>) {
5303                                    return null;
5304                            }
5305                            else {
5306                                    return (WikiPage)result;
5307                            }
5308                    }
5309            }
5310    
5311            /**
5312             * Finds all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
5313             *
5314             * @param nodeId the node id to search with
5315             * @param title the title to search with
5316             * @param head the head to search with
5317             * @return the matching wiki pages
5318             * @throws SystemException if a system exception occurred
5319             */
5320            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head)
5321                    throws SystemException {
5322                    return findByN_T_H(nodeId, title, head, QueryUtil.ALL_POS,
5323                            QueryUtil.ALL_POS, null);
5324            }
5325    
5326            /**
5327             * Finds a range of all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
5328             *
5329             * <p>
5330             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5331             * </p>
5332             *
5333             * @param nodeId the node id to search with
5334             * @param title the title to search with
5335             * @param head the head to search with
5336             * @param start the lower bound of the range of wiki pages to return
5337             * @param end the upper bound of the range of wiki pages to return (not inclusive)
5338             * @return the range of matching wiki pages
5339             * @throws SystemException if a system exception occurred
5340             */
5341            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head,
5342                    int start, int end) throws SystemException {
5343                    return findByN_T_H(nodeId, title, head, start, end, null);
5344            }
5345    
5346            /**
5347             * Finds an ordered range of all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
5348             *
5349             * <p>
5350             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5351             * </p>
5352             *
5353             * @param nodeId the node id to search with
5354             * @param title the title to search with
5355             * @param head the head to search with
5356             * @param start the lower bound of the range of wiki pages to return
5357             * @param end the upper bound of the range of wiki pages to return (not inclusive)
5358             * @param orderByComparator the comparator to order the results by
5359             * @return the ordered range of matching wiki pages
5360             * @throws SystemException if a system exception occurred
5361             */
5362            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head,
5363                    int start, int end, OrderByComparator orderByComparator)
5364                    throws SystemException {
5365                    Object[] finderArgs = new Object[] {
5366                                    nodeId, title, head,
5367                                    
5368                                    String.valueOf(start), String.valueOf(end),
5369                                    String.valueOf(orderByComparator)
5370                            };
5371    
5372                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_N_T_H,
5373                                    finderArgs, this);
5374    
5375                    if (list == null) {
5376                            Session session = null;
5377    
5378                            try {
5379                                    session = openSession();
5380    
5381                                    StringBundler query = null;
5382    
5383                                    if (orderByComparator != null) {
5384                                            query = new StringBundler(5 +
5385                                                            (orderByComparator.getOrderByFields().length * 3));
5386                                    }
5387                                    else {
5388                                            query = new StringBundler(5);
5389                                    }
5390    
5391                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5392    
5393                                    query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
5394    
5395                                    if (title == null) {
5396                                            query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
5397                                    }
5398                                    else {
5399                                            if (title.equals(StringPool.BLANK)) {
5400                                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
5401                                            }
5402                                            else {
5403                                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
5404                                            }
5405                                    }
5406    
5407                                    query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
5408    
5409                                    if (orderByComparator != null) {
5410                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5411                                                    orderByComparator);
5412                                    }
5413    
5414                                    else {
5415                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5416                                    }
5417    
5418                                    String sql = query.toString();
5419    
5420                                    Query q = session.createQuery(sql);
5421    
5422                                    QueryPos qPos = QueryPos.getInstance(q);
5423    
5424                                    qPos.add(nodeId);
5425    
5426                                    if (title != null) {
5427                                            qPos.add(title);
5428                                    }
5429    
5430                                    qPos.add(head);
5431    
5432                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
5433                                                    end);
5434                            }
5435                            catch (Exception e) {
5436                                    throw processException(e);
5437                            }
5438                            finally {
5439                                    if (list == null) {
5440                                            list = new ArrayList<WikiPage>();
5441                                    }
5442    
5443                                    cacheResult(list);
5444    
5445                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_N_T_H,
5446                                            finderArgs, list);
5447    
5448                                    closeSession(session);
5449                            }
5450                    }
5451    
5452                    return list;
5453            }
5454    
5455            /**
5456             * Finds the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
5457             *
5458             * <p>
5459             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5460             * </p>
5461             *
5462             * @param nodeId the node id to search with
5463             * @param title the title to search with
5464             * @param head the head to search with
5465             * @param orderByComparator the comparator to order the set by
5466             * @return the first matching wiki page
5467             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5468             * @throws SystemException if a system exception occurred
5469             */
5470            public WikiPage findByN_T_H_First(long nodeId, String title, boolean head,
5471                    OrderByComparator orderByComparator)
5472                    throws NoSuchPageException, SystemException {
5473                    List<WikiPage> list = findByN_T_H(nodeId, title, head, 0, 1,
5474                                    orderByComparator);
5475    
5476                    if (list.isEmpty()) {
5477                            StringBundler msg = new StringBundler(8);
5478    
5479                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5480    
5481                            msg.append("nodeId=");
5482                            msg.append(nodeId);
5483    
5484                            msg.append(", title=");
5485                            msg.append(title);
5486    
5487                            msg.append(", head=");
5488                            msg.append(head);
5489    
5490                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5491    
5492                            throw new NoSuchPageException(msg.toString());
5493                    }
5494                    else {
5495                            return list.get(0);
5496                    }
5497            }
5498    
5499            /**
5500             * Finds the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
5501             *
5502             * <p>
5503             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5504             * </p>
5505             *
5506             * @param nodeId the node id to search with
5507             * @param title the title to search with
5508             * @param head the head to search with
5509             * @param orderByComparator the comparator to order the set by
5510             * @return the last matching wiki page
5511             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5512             * @throws SystemException if a system exception occurred
5513             */
5514            public WikiPage findByN_T_H_Last(long nodeId, String title, boolean head,
5515                    OrderByComparator orderByComparator)
5516                    throws NoSuchPageException, SystemException {
5517                    int count = countByN_T_H(nodeId, title, head);
5518    
5519                    List<WikiPage> list = findByN_T_H(nodeId, title, head, count - 1,
5520                                    count, orderByComparator);
5521    
5522                    if (list.isEmpty()) {
5523                            StringBundler msg = new StringBundler(8);
5524    
5525                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5526    
5527                            msg.append("nodeId=");
5528                            msg.append(nodeId);
5529    
5530                            msg.append(", title=");
5531                            msg.append(title);
5532    
5533                            msg.append(", head=");
5534                            msg.append(head);
5535    
5536                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5537    
5538                            throw new NoSuchPageException(msg.toString());
5539                    }
5540                    else {
5541                            return list.get(0);
5542                    }
5543            }
5544    
5545            /**
5546             * Finds the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
5547             *
5548             * <p>
5549             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5550             * </p>
5551             *
5552             * @param pageId the primary key of the current wiki page
5553             * @param nodeId the node id to search with
5554             * @param title the title to search with
5555             * @param head the head to search with
5556             * @param orderByComparator the comparator to order the set by
5557             * @return the previous, current, and next wiki page
5558             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
5559             * @throws SystemException if a system exception occurred
5560             */
5561            public WikiPage[] findByN_T_H_PrevAndNext(long pageId, long nodeId,
5562                    String title, boolean head, OrderByComparator orderByComparator)
5563                    throws NoSuchPageException, SystemException {
5564                    WikiPage wikiPage = findByPrimaryKey(pageId);
5565    
5566                    Session session = null;
5567    
5568                    try {
5569                            session = openSession();
5570    
5571                            WikiPage[] array = new WikiPageImpl[3];
5572    
5573                            array[0] = getByN_T_H_PrevAndNext(session, wikiPage, nodeId, title,
5574                                            head, orderByComparator, true);
5575    
5576                            array[1] = wikiPage;
5577    
5578                            array[2] = getByN_T_H_PrevAndNext(session, wikiPage, nodeId, title,
5579                                            head, orderByComparator, false);
5580    
5581                            return array;
5582                    }
5583                    catch (Exception e) {
5584                            throw processException(e);
5585                    }
5586                    finally {
5587                            closeSession(session);
5588                    }
5589            }
5590    
5591            protected WikiPage getByN_T_H_PrevAndNext(Session session,
5592                    WikiPage wikiPage, long nodeId, String title, boolean head,
5593                    OrderByComparator orderByComparator, boolean previous) {
5594                    StringBundler query = null;
5595    
5596                    if (orderByComparator != null) {
5597                            query = new StringBundler(6 +
5598                                            (orderByComparator.getOrderByFields().length * 6));
5599                    }
5600                    else {
5601                            query = new StringBundler(3);
5602                    }
5603    
5604                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5605    
5606                    query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
5607    
5608                    if (title == null) {
5609                            query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
5610                    }
5611                    else {
5612                            if (title.equals(StringPool.BLANK)) {
5613                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
5614                            }
5615                            else {
5616                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
5617                            }
5618                    }
5619    
5620                    query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
5621    
5622                    if (orderByComparator != null) {
5623                            String[] orderByFields = orderByComparator.getOrderByFields();
5624    
5625                            if (orderByFields.length > 0) {
5626                                    query.append(WHERE_AND);
5627                            }
5628    
5629                            for (int i = 0; i < orderByFields.length; i++) {
5630                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5631                                    query.append(orderByFields[i]);
5632    
5633                                    if ((i + 1) < orderByFields.length) {
5634                                            if (orderByComparator.isAscending() ^ previous) {
5635                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5636                                            }
5637                                            else {
5638                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5639                                            }
5640                                    }
5641                                    else {
5642                                            if (orderByComparator.isAscending() ^ previous) {
5643                                                    query.append(WHERE_GREATER_THAN);
5644                                            }
5645                                            else {
5646                                                    query.append(WHERE_LESSER_THAN);
5647                                            }
5648                                    }
5649                            }
5650    
5651                            query.append(ORDER_BY_CLAUSE);
5652    
5653                            for (int i = 0; i < orderByFields.length; i++) {
5654                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5655                                    query.append(orderByFields[i]);
5656    
5657                                    if ((i + 1) < orderByFields.length) {
5658                                            if (orderByComparator.isAscending() ^ previous) {
5659                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5660                                            }
5661                                            else {
5662                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5663                                            }
5664                                    }
5665                                    else {
5666                                            if (orderByComparator.isAscending() ^ previous) {
5667                                                    query.append(ORDER_BY_ASC);
5668                                            }
5669                                            else {
5670                                                    query.append(ORDER_BY_DESC);
5671                                            }
5672                                    }
5673                            }
5674                    }
5675    
5676                    else {
5677                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5678                    }
5679    
5680                    String sql = query.toString();
5681    
5682                    Query q = session.createQuery(sql);
5683    
5684                    q.setFirstResult(0);
5685                    q.setMaxResults(2);
5686    
5687                    QueryPos qPos = QueryPos.getInstance(q);
5688    
5689                    qPos.add(nodeId);
5690    
5691                    if (title != null) {
5692                            qPos.add(title);
5693                    }
5694    
5695                    qPos.add(head);
5696    
5697                    if (orderByComparator != null) {
5698                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
5699    
5700                            for (Object value : values) {
5701                                    qPos.add(value);
5702                            }
5703                    }
5704    
5705                    List<WikiPage> list = q.list();
5706    
5707                    if (list.size() == 2) {
5708                            return list.get(1);
5709                    }
5710                    else {
5711                            return null;
5712                    }
5713            }
5714    
5715            /**
5716             * Finds all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
5717             *
5718             * @param nodeId the node id to search with
5719             * @param title the title to search with
5720             * @param status the status to search with
5721             * @return the matching wiki pages
5722             * @throws SystemException if a system exception occurred
5723             */
5724            public List<WikiPage> findByN_T_S(long nodeId, String title, int status)
5725                    throws SystemException {
5726                    return findByN_T_S(nodeId, title, status, QueryUtil.ALL_POS,
5727                            QueryUtil.ALL_POS, null);
5728            }
5729    
5730            /**
5731             * Finds a range of all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
5732             *
5733             * <p>
5734             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5735             * </p>
5736             *
5737             * @param nodeId the node id to search with
5738             * @param title the title to search with
5739             * @param status the status to search with
5740             * @param start the lower bound of the range of wiki pages to return
5741             * @param end the upper bound of the range of wiki pages to return (not inclusive)
5742             * @return the range of matching wiki pages
5743             * @throws SystemException if a system exception occurred
5744             */
5745            public List<WikiPage> findByN_T_S(long nodeId, String title, int status,
5746                    int start, int end) throws SystemException {
5747                    return findByN_T_S(nodeId, title, status, start, end, null);
5748            }
5749    
5750            /**
5751             * Finds an ordered range of all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
5752             *
5753             * <p>
5754             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5755             * </p>
5756             *
5757             * @param nodeId the node id to search with
5758             * @param title the title to search with
5759             * @param status the status to search with
5760             * @param start the lower bound of the range of wiki pages to return
5761             * @param end the upper bound of the range of wiki pages to return (not inclusive)
5762             * @param orderByComparator the comparator to order the results by
5763             * @return the ordered range of matching wiki pages
5764             * @throws SystemException if a system exception occurred
5765             */
5766            public List<WikiPage> findByN_T_S(long nodeId, String title, int status,
5767                    int start, int end, OrderByComparator orderByComparator)
5768                    throws SystemException {
5769                    Object[] finderArgs = new Object[] {
5770                                    nodeId, title, status,
5771                                    
5772                                    String.valueOf(start), String.valueOf(end),
5773                                    String.valueOf(orderByComparator)
5774                            };
5775    
5776                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_N_T_S,
5777                                    finderArgs, this);
5778    
5779                    if (list == null) {
5780                            Session session = null;
5781    
5782                            try {
5783                                    session = openSession();
5784    
5785                                    StringBundler query = null;
5786    
5787                                    if (orderByComparator != null) {
5788                                            query = new StringBundler(5 +
5789                                                            (orderByComparator.getOrderByFields().length * 3));
5790                                    }
5791                                    else {
5792                                            query = new StringBundler(5);
5793                                    }
5794    
5795                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5796    
5797                                    query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
5798    
5799                                    if (title == null) {
5800                                            query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
5801                                    }
5802                                    else {
5803                                            if (title.equals(StringPool.BLANK)) {
5804                                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
5805                                            }
5806                                            else {
5807                                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
5808                                            }
5809                                    }
5810    
5811                                    query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
5812    
5813                                    if (orderByComparator != null) {
5814                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5815                                                    orderByComparator);
5816                                    }
5817    
5818                                    else {
5819                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5820                                    }
5821    
5822                                    String sql = query.toString();
5823    
5824                                    Query q = session.createQuery(sql);
5825    
5826                                    QueryPos qPos = QueryPos.getInstance(q);
5827    
5828                                    qPos.add(nodeId);
5829    
5830                                    if (title != null) {
5831                                            qPos.add(title);
5832                                    }
5833    
5834                                    qPos.add(status);
5835    
5836                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
5837                                                    end);
5838                            }
5839                            catch (Exception e) {
5840                                    throw processException(e);
5841                            }
5842                            finally {
5843                                    if (list == null) {
5844                                            list = new ArrayList<WikiPage>();
5845                                    }
5846    
5847                                    cacheResult(list);
5848    
5849                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_N_T_S,
5850                                            finderArgs, list);
5851    
5852                                    closeSession(session);
5853                            }
5854                    }
5855    
5856                    return list;
5857            }
5858    
5859            /**
5860             * Finds the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
5861             *
5862             * <p>
5863             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5864             * </p>
5865             *
5866             * @param nodeId the node id to search with
5867             * @param title the title to search with
5868             * @param status the status to search with
5869             * @param orderByComparator the comparator to order the set by
5870             * @return the first matching wiki page
5871             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5872             * @throws SystemException if a system exception occurred
5873             */
5874            public WikiPage findByN_T_S_First(long nodeId, String title, int status,
5875                    OrderByComparator orderByComparator)
5876                    throws NoSuchPageException, SystemException {
5877                    List<WikiPage> list = findByN_T_S(nodeId, title, status, 0, 1,
5878                                    orderByComparator);
5879    
5880                    if (list.isEmpty()) {
5881                            StringBundler msg = new StringBundler(8);
5882    
5883                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5884    
5885                            msg.append("nodeId=");
5886                            msg.append(nodeId);
5887    
5888                            msg.append(", title=");
5889                            msg.append(title);
5890    
5891                            msg.append(", status=");
5892                            msg.append(status);
5893    
5894                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5895    
5896                            throw new NoSuchPageException(msg.toString());
5897                    }
5898                    else {
5899                            return list.get(0);
5900                    }
5901            }
5902    
5903            /**
5904             * Finds the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
5905             *
5906             * <p>
5907             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5908             * </p>
5909             *
5910             * @param nodeId the node id to search with
5911             * @param title the title to search with
5912             * @param status the status to search with
5913             * @param orderByComparator the comparator to order the set by
5914             * @return the last matching wiki page
5915             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5916             * @throws SystemException if a system exception occurred
5917             */
5918            public WikiPage findByN_T_S_Last(long nodeId, String title, int status,
5919                    OrderByComparator orderByComparator)
5920                    throws NoSuchPageException, SystemException {
5921                    int count = countByN_T_S(nodeId, title, status);
5922    
5923                    List<WikiPage> list = findByN_T_S(nodeId, title, status, count - 1,
5924                                    count, orderByComparator);
5925    
5926                    if (list.isEmpty()) {
5927                            StringBundler msg = new StringBundler(8);
5928    
5929                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5930    
5931                            msg.append("nodeId=");
5932                            msg.append(nodeId);
5933    
5934                            msg.append(", title=");
5935                            msg.append(title);
5936    
5937                            msg.append(", status=");
5938                            msg.append(status);
5939    
5940                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5941    
5942                            throw new NoSuchPageException(msg.toString());
5943                    }
5944                    else {
5945                            return list.get(0);
5946                    }
5947            }
5948    
5949            /**
5950             * Finds the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
5951             *
5952             * <p>
5953             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5954             * </p>
5955             *
5956             * @param pageId the primary key of the current wiki page
5957             * @param nodeId the node id to search with
5958             * @param title the title to search with
5959             * @param status the status to search with
5960             * @param orderByComparator the comparator to order the set by
5961             * @return the previous, current, and next wiki page
5962             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
5963             * @throws SystemException if a system exception occurred
5964             */
5965            public WikiPage[] findByN_T_S_PrevAndNext(long pageId, long nodeId,
5966                    String title, int status, OrderByComparator orderByComparator)
5967                    throws NoSuchPageException, SystemException {
5968                    WikiPage wikiPage = findByPrimaryKey(pageId);
5969    
5970                    Session session = null;
5971    
5972                    try {
5973                            session = openSession();
5974    
5975                            WikiPage[] array = new WikiPageImpl[3];
5976    
5977                            array[0] = getByN_T_S_PrevAndNext(session, wikiPage, nodeId, title,
5978                                            status, orderByComparator, true);
5979    
5980                            array[1] = wikiPage;
5981    
5982                            array[2] = getByN_T_S_PrevAndNext(session, wikiPage, nodeId, title,
5983                                            status, orderByComparator, false);
5984    
5985                            return array;
5986                    }
5987                    catch (Exception e) {
5988                            throw processException(e);
5989                    }
5990                    finally {
5991                            closeSession(session);
5992                    }
5993            }
5994    
5995            protected WikiPage getByN_T_S_PrevAndNext(Session session,
5996                    WikiPage wikiPage, long nodeId, String title, int status,
5997                    OrderByComparator orderByComparator, boolean previous) {
5998                    StringBundler query = null;
5999    
6000                    if (orderByComparator != null) {
6001                            query = new StringBundler(6 +
6002                                            (orderByComparator.getOrderByFields().length * 6));
6003                    }
6004                    else {
6005                            query = new StringBundler(3);
6006                    }
6007    
6008                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6009    
6010                    query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
6011    
6012                    if (title == null) {
6013                            query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
6014                    }
6015                    else {
6016                            if (title.equals(StringPool.BLANK)) {
6017                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
6018                            }
6019                            else {
6020                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
6021                            }
6022                    }
6023    
6024                    query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
6025    
6026                    if (orderByComparator != null) {
6027                            String[] orderByFields = orderByComparator.getOrderByFields();
6028    
6029                            if (orderByFields.length > 0) {
6030                                    query.append(WHERE_AND);
6031                            }
6032    
6033                            for (int i = 0; i < orderByFields.length; i++) {
6034                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6035                                    query.append(orderByFields[i]);
6036    
6037                                    if ((i + 1) < orderByFields.length) {
6038                                            if (orderByComparator.isAscending() ^ previous) {
6039                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6040                                            }
6041                                            else {
6042                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6043                                            }
6044                                    }
6045                                    else {
6046                                            if (orderByComparator.isAscending() ^ previous) {
6047                                                    query.append(WHERE_GREATER_THAN);
6048                                            }
6049                                            else {
6050                                                    query.append(WHERE_LESSER_THAN);
6051                                            }
6052                                    }
6053                            }
6054    
6055                            query.append(ORDER_BY_CLAUSE);
6056    
6057                            for (int i = 0; i < orderByFields.length; i++) {
6058                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6059                                    query.append(orderByFields[i]);
6060    
6061                                    if ((i + 1) < orderByFields.length) {
6062                                            if (orderByComparator.isAscending() ^ previous) {
6063                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6064                                            }
6065                                            else {
6066                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6067                                            }
6068                                    }
6069                                    else {
6070                                            if (orderByComparator.isAscending() ^ previous) {
6071                                                    query.append(ORDER_BY_ASC);
6072                                            }
6073                                            else {
6074                                                    query.append(ORDER_BY_DESC);
6075                                            }
6076                                    }
6077                            }
6078                    }
6079    
6080                    else {
6081                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6082                    }
6083    
6084                    String sql = query.toString();
6085    
6086                    Query q = session.createQuery(sql);
6087    
6088                    q.setFirstResult(0);
6089                    q.setMaxResults(2);
6090    
6091                    QueryPos qPos = QueryPos.getInstance(q);
6092    
6093                    qPos.add(nodeId);
6094    
6095                    if (title != null) {
6096                            qPos.add(title);
6097                    }
6098    
6099                    qPos.add(status);
6100    
6101                    if (orderByComparator != null) {
6102                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
6103    
6104                            for (Object value : values) {
6105                                    qPos.add(value);
6106                            }
6107                    }
6108    
6109                    List<WikiPage> list = q.list();
6110    
6111                    if (list.size() == 2) {
6112                            return list.get(1);
6113                    }
6114                    else {
6115                            return null;
6116                    }
6117            }
6118    
6119            /**
6120             * Finds all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
6121             *
6122             * @param nodeId the node id to search with
6123             * @param head the head to search with
6124             * @param parentTitle the parent title to search with
6125             * @return the matching wiki pages
6126             * @throws SystemException if a system exception occurred
6127             */
6128            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
6129                    String parentTitle) throws SystemException {
6130                    return findByN_H_P(nodeId, head, parentTitle, QueryUtil.ALL_POS,
6131                            QueryUtil.ALL_POS, null);
6132            }
6133    
6134            /**
6135             * Finds a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
6136             *
6137             * <p>
6138             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6139             * </p>
6140             *
6141             * @param nodeId the node id to search with
6142             * @param head the head to search with
6143             * @param parentTitle the parent title to search with
6144             * @param start the lower bound of the range of wiki pages to return
6145             * @param end the upper bound of the range of wiki pages to return (not inclusive)
6146             * @return the range of matching wiki pages
6147             * @throws SystemException if a system exception occurred
6148             */
6149            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
6150                    String parentTitle, int start, int end) throws SystemException {
6151                    return findByN_H_P(nodeId, head, parentTitle, start, end, null);
6152            }
6153    
6154            /**
6155             * Finds an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
6156             *
6157             * <p>
6158             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6159             * </p>
6160             *
6161             * @param nodeId the node id to search with
6162             * @param head the head to search with
6163             * @param parentTitle the parent title to search with
6164             * @param start the lower bound of the range of wiki pages to return
6165             * @param end the upper bound of the range of wiki pages to return (not inclusive)
6166             * @param orderByComparator the comparator to order the results by
6167             * @return the ordered range of matching wiki pages
6168             * @throws SystemException if a system exception occurred
6169             */
6170            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
6171                    String parentTitle, int start, int end,
6172                    OrderByComparator orderByComparator) throws SystemException {
6173                    Object[] finderArgs = new Object[] {
6174                                    nodeId, head, parentTitle,
6175                                    
6176                                    String.valueOf(start), String.valueOf(end),
6177                                    String.valueOf(orderByComparator)
6178                            };
6179    
6180                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_N_H_P,
6181                                    finderArgs, this);
6182    
6183                    if (list == null) {
6184                            Session session = null;
6185    
6186                            try {
6187                                    session = openSession();
6188    
6189                                    StringBundler query = null;
6190    
6191                                    if (orderByComparator != null) {
6192                                            query = new StringBundler(5 +
6193                                                            (orderByComparator.getOrderByFields().length * 3));
6194                                    }
6195                                    else {
6196                                            query = new StringBundler(5);
6197                                    }
6198    
6199                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6200    
6201                                    query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
6202    
6203                                    query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
6204    
6205                                    if (parentTitle == null) {
6206                                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
6207                                    }
6208                                    else {
6209                                            if (parentTitle.equals(StringPool.BLANK)) {
6210                                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
6211                                            }
6212                                            else {
6213                                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
6214                                            }
6215                                    }
6216    
6217                                    if (orderByComparator != null) {
6218                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6219                                                    orderByComparator);
6220                                    }
6221    
6222                                    else {
6223                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6224                                    }
6225    
6226                                    String sql = query.toString();
6227    
6228                                    Query q = session.createQuery(sql);
6229    
6230                                    QueryPos qPos = QueryPos.getInstance(q);
6231    
6232                                    qPos.add(nodeId);
6233    
6234                                    qPos.add(head);
6235    
6236                                    if (parentTitle != null) {
6237                                            qPos.add(parentTitle);
6238                                    }
6239    
6240                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
6241                                                    end);
6242                            }
6243                            catch (Exception e) {
6244                                    throw processException(e);
6245                            }
6246                            finally {
6247                                    if (list == null) {
6248                                            list = new ArrayList<WikiPage>();
6249                                    }
6250    
6251                                    cacheResult(list);
6252    
6253                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_N_H_P,
6254                                            finderArgs, list);
6255    
6256                                    closeSession(session);
6257                            }
6258                    }
6259    
6260                    return list;
6261            }
6262    
6263            /**
6264             * Finds the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
6265             *
6266             * <p>
6267             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6268             * </p>
6269             *
6270             * @param nodeId the node id to search with
6271             * @param head the head to search with
6272             * @param parentTitle the parent title to search with
6273             * @param orderByComparator the comparator to order the set by
6274             * @return the first matching wiki page
6275             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6276             * @throws SystemException if a system exception occurred
6277             */
6278            public WikiPage findByN_H_P_First(long nodeId, boolean head,
6279                    String parentTitle, OrderByComparator orderByComparator)
6280                    throws NoSuchPageException, SystemException {
6281                    List<WikiPage> list = findByN_H_P(nodeId, head, parentTitle, 0, 1,
6282                                    orderByComparator);
6283    
6284                    if (list.isEmpty()) {
6285                            StringBundler msg = new StringBundler(8);
6286    
6287                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6288    
6289                            msg.append("nodeId=");
6290                            msg.append(nodeId);
6291    
6292                            msg.append(", head=");
6293                            msg.append(head);
6294    
6295                            msg.append(", parentTitle=");
6296                            msg.append(parentTitle);
6297    
6298                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6299    
6300                            throw new NoSuchPageException(msg.toString());
6301                    }
6302                    else {
6303                            return list.get(0);
6304                    }
6305            }
6306    
6307            /**
6308             * Finds the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
6309             *
6310             * <p>
6311             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6312             * </p>
6313             *
6314             * @param nodeId the node id to search with
6315             * @param head the head to search with
6316             * @param parentTitle the parent title to search with
6317             * @param orderByComparator the comparator to order the set by
6318             * @return the last matching wiki page
6319             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6320             * @throws SystemException if a system exception occurred
6321             */
6322            public WikiPage findByN_H_P_Last(long nodeId, boolean head,
6323                    String parentTitle, OrderByComparator orderByComparator)
6324                    throws NoSuchPageException, SystemException {
6325                    int count = countByN_H_P(nodeId, head, parentTitle);
6326    
6327                    List<WikiPage> list = findByN_H_P(nodeId, head, parentTitle, count - 1,
6328                                    count, orderByComparator);
6329    
6330                    if (list.isEmpty()) {
6331                            StringBundler msg = new StringBundler(8);
6332    
6333                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6334    
6335                            msg.append("nodeId=");
6336                            msg.append(nodeId);
6337    
6338                            msg.append(", head=");
6339                            msg.append(head);
6340    
6341                            msg.append(", parentTitle=");
6342                            msg.append(parentTitle);
6343    
6344                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6345    
6346                            throw new NoSuchPageException(msg.toString());
6347                    }
6348                    else {
6349                            return list.get(0);
6350                    }
6351            }
6352    
6353            /**
6354             * Finds the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
6355             *
6356             * <p>
6357             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6358             * </p>
6359             *
6360             * @param pageId the primary key of the current wiki page
6361             * @param nodeId the node id to search with
6362             * @param head the head to search with
6363             * @param parentTitle the parent title to search with
6364             * @param orderByComparator the comparator to order the set by
6365             * @return the previous, current, and next wiki page
6366             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
6367             * @throws SystemException if a system exception occurred
6368             */
6369            public WikiPage[] findByN_H_P_PrevAndNext(long pageId, long nodeId,
6370                    boolean head, String parentTitle, OrderByComparator orderByComparator)
6371                    throws NoSuchPageException, SystemException {
6372                    WikiPage wikiPage = findByPrimaryKey(pageId);
6373    
6374                    Session session = null;
6375    
6376                    try {
6377                            session = openSession();
6378    
6379                            WikiPage[] array = new WikiPageImpl[3];
6380    
6381                            array[0] = getByN_H_P_PrevAndNext(session, wikiPage, nodeId, head,
6382                                            parentTitle, orderByComparator, true);
6383    
6384                            array[1] = wikiPage;
6385    
6386                            array[2] = getByN_H_P_PrevAndNext(session, wikiPage, nodeId, head,
6387                                            parentTitle, orderByComparator, false);
6388    
6389                            return array;
6390                    }
6391                    catch (Exception e) {
6392                            throw processException(e);
6393                    }
6394                    finally {
6395                            closeSession(session);
6396                    }
6397            }
6398    
6399            protected WikiPage getByN_H_P_PrevAndNext(Session session,
6400                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
6401                    OrderByComparator orderByComparator, boolean previous) {
6402                    StringBundler query = null;
6403    
6404                    if (orderByComparator != null) {
6405                            query = new StringBundler(6 +
6406                                            (orderByComparator.getOrderByFields().length * 6));
6407                    }
6408                    else {
6409                            query = new StringBundler(3);
6410                    }
6411    
6412                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6413    
6414                    query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
6415    
6416                    query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
6417    
6418                    if (parentTitle == null) {
6419                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
6420                    }
6421                    else {
6422                            if (parentTitle.equals(StringPool.BLANK)) {
6423                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
6424                            }
6425                            else {
6426                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
6427                            }
6428                    }
6429    
6430                    if (orderByComparator != null) {
6431                            String[] orderByFields = orderByComparator.getOrderByFields();
6432    
6433                            if (orderByFields.length > 0) {
6434                                    query.append(WHERE_AND);
6435                            }
6436    
6437                            for (int i = 0; i < orderByFields.length; i++) {
6438                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6439                                    query.append(orderByFields[i]);
6440    
6441                                    if ((i + 1) < orderByFields.length) {
6442                                            if (orderByComparator.isAscending() ^ previous) {
6443                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6444                                            }
6445                                            else {
6446                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6447                                            }
6448                                    }
6449                                    else {
6450                                            if (orderByComparator.isAscending() ^ previous) {
6451                                                    query.append(WHERE_GREATER_THAN);
6452                                            }
6453                                            else {
6454                                                    query.append(WHERE_LESSER_THAN);
6455                                            }
6456                                    }
6457                            }
6458    
6459                            query.append(ORDER_BY_CLAUSE);
6460    
6461                            for (int i = 0; i < orderByFields.length; i++) {
6462                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6463                                    query.append(orderByFields[i]);
6464    
6465                                    if ((i + 1) < orderByFields.length) {
6466                                            if (orderByComparator.isAscending() ^ previous) {
6467                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6468                                            }
6469                                            else {
6470                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6471                                            }
6472                                    }
6473                                    else {
6474                                            if (orderByComparator.isAscending() ^ previous) {
6475                                                    query.append(ORDER_BY_ASC);
6476                                            }
6477                                            else {
6478                                                    query.append(ORDER_BY_DESC);
6479                                            }
6480                                    }
6481                            }
6482                    }
6483    
6484                    else {
6485                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6486                    }
6487    
6488                    String sql = query.toString();
6489    
6490                    Query q = session.createQuery(sql);
6491    
6492                    q.setFirstResult(0);
6493                    q.setMaxResults(2);
6494    
6495                    QueryPos qPos = QueryPos.getInstance(q);
6496    
6497                    qPos.add(nodeId);
6498    
6499                    qPos.add(head);
6500    
6501                    if (parentTitle != null) {
6502                            qPos.add(parentTitle);
6503                    }
6504    
6505                    if (orderByComparator != null) {
6506                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
6507    
6508                            for (Object value : values) {
6509                                    qPos.add(value);
6510                            }
6511                    }
6512    
6513                    List<WikiPage> list = q.list();
6514    
6515                    if (list.size() == 2) {
6516                            return list.get(1);
6517                    }
6518                    else {
6519                            return null;
6520                    }
6521            }
6522    
6523            /**
6524             * Finds all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
6525             *
6526             * @param nodeId the node id to search with
6527             * @param head the head to search with
6528             * @param status the status to search with
6529             * @return the matching wiki pages
6530             * @throws SystemException if a system exception occurred
6531             */
6532            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status)
6533                    throws SystemException {
6534                    return findByN_H_S(nodeId, head, status, QueryUtil.ALL_POS,
6535                            QueryUtil.ALL_POS, null);
6536            }
6537    
6538            /**
6539             * Finds a range of all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
6540             *
6541             * <p>
6542             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6543             * </p>
6544             *
6545             * @param nodeId the node id to search with
6546             * @param head the head to search with
6547             * @param status the status to search with
6548             * @param start the lower bound of the range of wiki pages to return
6549             * @param end the upper bound of the range of wiki pages to return (not inclusive)
6550             * @return the range of matching wiki pages
6551             * @throws SystemException if a system exception occurred
6552             */
6553            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status,
6554                    int start, int end) throws SystemException {
6555                    return findByN_H_S(nodeId, head, status, start, end, null);
6556            }
6557    
6558            /**
6559             * Finds an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
6560             *
6561             * <p>
6562             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6563             * </p>
6564             *
6565             * @param nodeId the node id to search with
6566             * @param head the head to search with
6567             * @param status the status to search with
6568             * @param start the lower bound of the range of wiki pages to return
6569             * @param end the upper bound of the range of wiki pages to return (not inclusive)
6570             * @param orderByComparator the comparator to order the results by
6571             * @return the ordered range of matching wiki pages
6572             * @throws SystemException if a system exception occurred
6573             */
6574            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status,
6575                    int start, int end, OrderByComparator orderByComparator)
6576                    throws SystemException {
6577                    Object[] finderArgs = new Object[] {
6578                                    nodeId, head, status,
6579                                    
6580                                    String.valueOf(start), String.valueOf(end),
6581                                    String.valueOf(orderByComparator)
6582                            };
6583    
6584                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_N_H_S,
6585                                    finderArgs, this);
6586    
6587                    if (list == null) {
6588                            Session session = null;
6589    
6590                            try {
6591                                    session = openSession();
6592    
6593                                    StringBundler query = null;
6594    
6595                                    if (orderByComparator != null) {
6596                                            query = new StringBundler(5 +
6597                                                            (orderByComparator.getOrderByFields().length * 3));
6598                                    }
6599                                    else {
6600                                            query = new StringBundler(5);
6601                                    }
6602    
6603                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6604    
6605                                    query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
6606    
6607                                    query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
6608    
6609                                    query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
6610    
6611                                    if (orderByComparator != null) {
6612                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6613                                                    orderByComparator);
6614                                    }
6615    
6616                                    else {
6617                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6618                                    }
6619    
6620                                    String sql = query.toString();
6621    
6622                                    Query q = session.createQuery(sql);
6623    
6624                                    QueryPos qPos = QueryPos.getInstance(q);
6625    
6626                                    qPos.add(nodeId);
6627    
6628                                    qPos.add(head);
6629    
6630                                    qPos.add(status);
6631    
6632                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
6633                                                    end);
6634                            }
6635                            catch (Exception e) {
6636                                    throw processException(e);
6637                            }
6638                            finally {
6639                                    if (list == null) {
6640                                            list = new ArrayList<WikiPage>();
6641                                    }
6642    
6643                                    cacheResult(list);
6644    
6645                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_N_H_S,
6646                                            finderArgs, list);
6647    
6648                                    closeSession(session);
6649                            }
6650                    }
6651    
6652                    return list;
6653            }
6654    
6655            /**
6656             * Finds the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
6657             *
6658             * <p>
6659             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6660             * </p>
6661             *
6662             * @param nodeId the node id to search with
6663             * @param head the head to search with
6664             * @param status the status to search with
6665             * @param orderByComparator the comparator to order the set by
6666             * @return the first matching wiki page
6667             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6668             * @throws SystemException if a system exception occurred
6669             */
6670            public WikiPage findByN_H_S_First(long nodeId, boolean head, int status,
6671                    OrderByComparator orderByComparator)
6672                    throws NoSuchPageException, SystemException {
6673                    List<WikiPage> list = findByN_H_S(nodeId, head, status, 0, 1,
6674                                    orderByComparator);
6675    
6676                    if (list.isEmpty()) {
6677                            StringBundler msg = new StringBundler(8);
6678    
6679                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6680    
6681                            msg.append("nodeId=");
6682                            msg.append(nodeId);
6683    
6684                            msg.append(", head=");
6685                            msg.append(head);
6686    
6687                            msg.append(", status=");
6688                            msg.append(status);
6689    
6690                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6691    
6692                            throw new NoSuchPageException(msg.toString());
6693                    }
6694                    else {
6695                            return list.get(0);
6696                    }
6697            }
6698    
6699            /**
6700             * Finds the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
6701             *
6702             * <p>
6703             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6704             * </p>
6705             *
6706             * @param nodeId the node id to search with
6707             * @param head the head to search with
6708             * @param status the status to search with
6709             * @param orderByComparator the comparator to order the set by
6710             * @return the last matching wiki page
6711             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6712             * @throws SystemException if a system exception occurred
6713             */
6714            public WikiPage findByN_H_S_Last(long nodeId, boolean head, int status,
6715                    OrderByComparator orderByComparator)
6716                    throws NoSuchPageException, SystemException {
6717                    int count = countByN_H_S(nodeId, head, status);
6718    
6719                    List<WikiPage> list = findByN_H_S(nodeId, head, status, count - 1,
6720                                    count, orderByComparator);
6721    
6722                    if (list.isEmpty()) {
6723                            StringBundler msg = new StringBundler(8);
6724    
6725                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6726    
6727                            msg.append("nodeId=");
6728                            msg.append(nodeId);
6729    
6730                            msg.append(", head=");
6731                            msg.append(head);
6732    
6733                            msg.append(", status=");
6734                            msg.append(status);
6735    
6736                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6737    
6738                            throw new NoSuchPageException(msg.toString());
6739                    }
6740                    else {
6741                            return list.get(0);
6742                    }
6743            }
6744    
6745            /**
6746             * Finds the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
6747             *
6748             * <p>
6749             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6750             * </p>
6751             *
6752             * @param pageId the primary key of the current wiki page
6753             * @param nodeId the node id to search with
6754             * @param head the head to search with
6755             * @param status the status to search with
6756             * @param orderByComparator the comparator to order the set by
6757             * @return the previous, current, and next wiki page
6758             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
6759             * @throws SystemException if a system exception occurred
6760             */
6761            public WikiPage[] findByN_H_S_PrevAndNext(long pageId, long nodeId,
6762                    boolean head, int status, OrderByComparator orderByComparator)
6763                    throws NoSuchPageException, SystemException {
6764                    WikiPage wikiPage = findByPrimaryKey(pageId);
6765    
6766                    Session session = null;
6767    
6768                    try {
6769                            session = openSession();
6770    
6771                            WikiPage[] array = new WikiPageImpl[3];
6772    
6773                            array[0] = getByN_H_S_PrevAndNext(session, wikiPage, nodeId, head,
6774                                            status, orderByComparator, true);
6775    
6776                            array[1] = wikiPage;
6777    
6778                            array[2] = getByN_H_S_PrevAndNext(session, wikiPage, nodeId, head,
6779                                            status, orderByComparator, false);
6780    
6781                            return array;
6782                    }
6783                    catch (Exception e) {
6784                            throw processException(e);
6785                    }
6786                    finally {
6787                            closeSession(session);
6788                    }
6789            }
6790    
6791            protected WikiPage getByN_H_S_PrevAndNext(Session session,
6792                    WikiPage wikiPage, long nodeId, boolean head, int status,
6793                    OrderByComparator orderByComparator, boolean previous) {
6794                    StringBundler query = null;
6795    
6796                    if (orderByComparator != null) {
6797                            query = new StringBundler(6 +
6798                                            (orderByComparator.getOrderByFields().length * 6));
6799                    }
6800                    else {
6801                            query = new StringBundler(3);
6802                    }
6803    
6804                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6805    
6806                    query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
6807    
6808                    query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
6809    
6810                    query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
6811    
6812                    if (orderByComparator != null) {
6813                            String[] orderByFields = orderByComparator.getOrderByFields();
6814    
6815                            if (orderByFields.length > 0) {
6816                                    query.append(WHERE_AND);
6817                            }
6818    
6819                            for (int i = 0; i < orderByFields.length; i++) {
6820                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6821                                    query.append(orderByFields[i]);
6822    
6823                                    if ((i + 1) < orderByFields.length) {
6824                                            if (orderByComparator.isAscending() ^ previous) {
6825                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6826                                            }
6827                                            else {
6828                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6829                                            }
6830                                    }
6831                                    else {
6832                                            if (orderByComparator.isAscending() ^ previous) {
6833                                                    query.append(WHERE_GREATER_THAN);
6834                                            }
6835                                            else {
6836                                                    query.append(WHERE_LESSER_THAN);
6837                                            }
6838                                    }
6839                            }
6840    
6841                            query.append(ORDER_BY_CLAUSE);
6842    
6843                            for (int i = 0; i < orderByFields.length; i++) {
6844                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6845                                    query.append(orderByFields[i]);
6846    
6847                                    if ((i + 1) < orderByFields.length) {
6848                                            if (orderByComparator.isAscending() ^ previous) {
6849                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6850                                            }
6851                                            else {
6852                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6853                                            }
6854                                    }
6855                                    else {
6856                                            if (orderByComparator.isAscending() ^ previous) {
6857                                                    query.append(ORDER_BY_ASC);
6858                                            }
6859                                            else {
6860                                                    query.append(ORDER_BY_DESC);
6861                                            }
6862                                    }
6863                            }
6864                    }
6865    
6866                    else {
6867                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6868                    }
6869    
6870                    String sql = query.toString();
6871    
6872                    Query q = session.createQuery(sql);
6873    
6874                    q.setFirstResult(0);
6875                    q.setMaxResults(2);
6876    
6877                    QueryPos qPos = QueryPos.getInstance(q);
6878    
6879                    qPos.add(nodeId);
6880    
6881                    qPos.add(head);
6882    
6883                    qPos.add(status);
6884    
6885                    if (orderByComparator != null) {
6886                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
6887    
6888                            for (Object value : values) {
6889                                    qPos.add(value);
6890                            }
6891                    }
6892    
6893                    List<WikiPage> list = q.list();
6894    
6895                    if (list.size() == 2) {
6896                            return list.get(1);
6897                    }
6898                    else {
6899                            return null;
6900                    }
6901            }
6902    
6903            /**
6904             * Finds all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
6905             *
6906             * @param nodeId the node id to search with
6907             * @param head the head to search with
6908             * @param parentTitle the parent title to search with
6909             * @param status the status to search with
6910             * @return the matching wiki pages
6911             * @throws SystemException if a system exception occurred
6912             */
6913            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
6914                    String parentTitle, int status) throws SystemException {
6915                    return findByN_H_P_S(nodeId, head, parentTitle, status,
6916                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6917            }
6918    
6919            /**
6920             * Finds a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
6921             *
6922             * <p>
6923             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6924             * </p>
6925             *
6926             * @param nodeId the node id to search with
6927             * @param head the head to search with
6928             * @param parentTitle the parent title to search with
6929             * @param status the status to search with
6930             * @param start the lower bound of the range of wiki pages to return
6931             * @param end the upper bound of the range of wiki pages to return (not inclusive)
6932             * @return the range of matching wiki pages
6933             * @throws SystemException if a system exception occurred
6934             */
6935            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
6936                    String parentTitle, int status, int start, int end)
6937                    throws SystemException {
6938                    return findByN_H_P_S(nodeId, head, parentTitle, status, start, end, null);
6939            }
6940    
6941            /**
6942             * Finds an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
6943             *
6944             * <p>
6945             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6946             * </p>
6947             *
6948             * @param nodeId the node id to search with
6949             * @param head the head to search with
6950             * @param parentTitle the parent title to search with
6951             * @param status the status to search with
6952             * @param start the lower bound of the range of wiki pages to return
6953             * @param end the upper bound of the range of wiki pages to return (not inclusive)
6954             * @param orderByComparator the comparator to order the results by
6955             * @return the ordered range of matching wiki pages
6956             * @throws SystemException if a system exception occurred
6957             */
6958            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
6959                    String parentTitle, int status, int start, int end,
6960                    OrderByComparator orderByComparator) throws SystemException {
6961                    Object[] finderArgs = new Object[] {
6962                                    nodeId, head, parentTitle, status,
6963                                    
6964                                    String.valueOf(start), String.valueOf(end),
6965                                    String.valueOf(orderByComparator)
6966                            };
6967    
6968                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_N_H_P_S,
6969                                    finderArgs, this);
6970    
6971                    if (list == null) {
6972                            Session session = null;
6973    
6974                            try {
6975                                    session = openSession();
6976    
6977                                    StringBundler query = null;
6978    
6979                                    if (orderByComparator != null) {
6980                                            query = new StringBundler(6 +
6981                                                            (orderByComparator.getOrderByFields().length * 3));
6982                                    }
6983                                    else {
6984                                            query = new StringBundler(6);
6985                                    }
6986    
6987                                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6988    
6989                                    query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
6990    
6991                                    query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
6992    
6993                                    if (parentTitle == null) {
6994                                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
6995                                    }
6996                                    else {
6997                                            if (parentTitle.equals(StringPool.BLANK)) {
6998                                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
6999                                            }
7000                                            else {
7001                                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
7002                                            }
7003                                    }
7004    
7005                                    query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
7006    
7007                                    if (orderByComparator != null) {
7008                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7009                                                    orderByComparator);
7010                                    }
7011    
7012                                    else {
7013                                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7014                                    }
7015    
7016                                    String sql = query.toString();
7017    
7018                                    Query q = session.createQuery(sql);
7019    
7020                                    QueryPos qPos = QueryPos.getInstance(q);
7021    
7022                                    qPos.add(nodeId);
7023    
7024                                    qPos.add(head);
7025    
7026                                    if (parentTitle != null) {
7027                                            qPos.add(parentTitle);
7028                                    }
7029    
7030                                    qPos.add(status);
7031    
7032                                    list = (List<WikiPage>)QueryUtil.list(q, getDialect(), start,
7033                                                    end);
7034                            }
7035                            catch (Exception e) {
7036                                    throw processException(e);
7037                            }
7038                            finally {
7039                                    if (list == null) {
7040                                            list = new ArrayList<WikiPage>();
7041                                    }
7042    
7043                                    cacheResult(list);
7044    
7045                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_N_H_P_S,
7046                                            finderArgs, list);
7047    
7048                                    closeSession(session);
7049                            }
7050                    }
7051    
7052                    return list;
7053            }
7054    
7055            /**
7056             * Finds the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
7057             *
7058             * <p>
7059             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7060             * </p>
7061             *
7062             * @param nodeId the node id to search with
7063             * @param head the head to search with
7064             * @param parentTitle the parent title to search with
7065             * @param status the status to search with
7066             * @param orderByComparator the comparator to order the set by
7067             * @return the first matching wiki page
7068             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
7069             * @throws SystemException if a system exception occurred
7070             */
7071            public WikiPage findByN_H_P_S_First(long nodeId, boolean head,
7072                    String parentTitle, int status, OrderByComparator orderByComparator)
7073                    throws NoSuchPageException, SystemException {
7074                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
7075                                    0, 1, orderByComparator);
7076    
7077                    if (list.isEmpty()) {
7078                            StringBundler msg = new StringBundler(10);
7079    
7080                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7081    
7082                            msg.append("nodeId=");
7083                            msg.append(nodeId);
7084    
7085                            msg.append(", head=");
7086                            msg.append(head);
7087    
7088                            msg.append(", parentTitle=");
7089                            msg.append(parentTitle);
7090    
7091                            msg.append(", status=");
7092                            msg.append(status);
7093    
7094                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7095    
7096                            throw new NoSuchPageException(msg.toString());
7097                    }
7098                    else {
7099                            return list.get(0);
7100                    }
7101            }
7102    
7103            /**
7104             * Finds the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
7105             *
7106             * <p>
7107             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7108             * </p>
7109             *
7110             * @param nodeId the node id to search with
7111             * @param head the head to search with
7112             * @param parentTitle the parent title to search with
7113             * @param status the status to search with
7114             * @param orderByComparator the comparator to order the set by
7115             * @return the last matching wiki page
7116             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
7117             * @throws SystemException if a system exception occurred
7118             */
7119            public WikiPage findByN_H_P_S_Last(long nodeId, boolean head,
7120                    String parentTitle, int status, OrderByComparator orderByComparator)
7121                    throws NoSuchPageException, SystemException {
7122                    int count = countByN_H_P_S(nodeId, head, parentTitle, status);
7123    
7124                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
7125                                    count - 1, count, orderByComparator);
7126    
7127                    if (list.isEmpty()) {
7128                            StringBundler msg = new StringBundler(10);
7129    
7130                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7131    
7132                            msg.append("nodeId=");
7133                            msg.append(nodeId);
7134    
7135                            msg.append(", head=");
7136                            msg.append(head);
7137    
7138                            msg.append(", parentTitle=");
7139                            msg.append(parentTitle);
7140    
7141                            msg.append(", status=");
7142                            msg.append(status);
7143    
7144                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7145    
7146                            throw new NoSuchPageException(msg.toString());
7147                    }
7148                    else {
7149                            return list.get(0);
7150                    }
7151            }
7152    
7153            /**
7154             * Finds the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
7155             *
7156             * <p>
7157             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7158             * </p>
7159             *
7160             * @param pageId the primary key of the current wiki page
7161             * @param nodeId the node id to search with
7162             * @param head the head to search with
7163             * @param parentTitle the parent title to search with
7164             * @param status the status to search with
7165             * @param orderByComparator the comparator to order the set by
7166             * @return the previous, current, and next wiki page
7167             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
7168             * @throws SystemException if a system exception occurred
7169             */
7170            public WikiPage[] findByN_H_P_S_PrevAndNext(long pageId, long nodeId,
7171                    boolean head, String parentTitle, int status,
7172                    OrderByComparator orderByComparator)
7173                    throws NoSuchPageException, SystemException {
7174                    WikiPage wikiPage = findByPrimaryKey(pageId);
7175    
7176                    Session session = null;
7177    
7178                    try {
7179                            session = openSession();
7180    
7181                            WikiPage[] array = new WikiPageImpl[3];
7182    
7183                            array[0] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
7184                                            head, parentTitle, status, orderByComparator, true);
7185    
7186                            array[1] = wikiPage;
7187    
7188                            array[2] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
7189                                            head, parentTitle, status, orderByComparator, false);
7190    
7191                            return array;
7192                    }
7193                    catch (Exception e) {
7194                            throw processException(e);
7195                    }
7196                    finally {
7197                            closeSession(session);
7198                    }
7199            }
7200    
7201            protected WikiPage getByN_H_P_S_PrevAndNext(Session session,
7202                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
7203                    int status, OrderByComparator orderByComparator, boolean previous) {
7204                    StringBundler query = null;
7205    
7206                    if (orderByComparator != null) {
7207                            query = new StringBundler(6 +
7208                                            (orderByComparator.getOrderByFields().length * 6));
7209                    }
7210                    else {
7211                            query = new StringBundler(3);
7212                    }
7213    
7214                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
7215    
7216                    query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
7217    
7218                    query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
7219    
7220                    if (parentTitle == null) {
7221                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
7222                    }
7223                    else {
7224                            if (parentTitle.equals(StringPool.BLANK)) {
7225                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
7226                            }
7227                            else {
7228                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
7229                            }
7230                    }
7231    
7232                    query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
7233    
7234                    if (orderByComparator != null) {
7235                            String[] orderByFields = orderByComparator.getOrderByFields();
7236    
7237                            if (orderByFields.length > 0) {
7238                                    query.append(WHERE_AND);
7239                            }
7240    
7241                            for (int i = 0; i < orderByFields.length; i++) {
7242                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7243                                    query.append(orderByFields[i]);
7244    
7245                                    if ((i + 1) < orderByFields.length) {
7246                                            if (orderByComparator.isAscending() ^ previous) {
7247                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7248                                            }
7249                                            else {
7250                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7251                                            }
7252                                    }
7253                                    else {
7254                                            if (orderByComparator.isAscending() ^ previous) {
7255                                                    query.append(WHERE_GREATER_THAN);
7256                                            }
7257                                            else {
7258                                                    query.append(WHERE_LESSER_THAN);
7259                                            }
7260                                    }
7261                            }
7262    
7263                            query.append(ORDER_BY_CLAUSE);
7264    
7265                            for (int i = 0; i < orderByFields.length; i++) {
7266                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7267                                    query.append(orderByFields[i]);
7268    
7269                                    if ((i + 1) < orderByFields.length) {
7270                                            if (orderByComparator.isAscending() ^ previous) {
7271                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7272                                            }
7273                                            else {
7274                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7275                                            }
7276                                    }
7277                                    else {
7278                                            if (orderByComparator.isAscending() ^ previous) {
7279                                                    query.append(ORDER_BY_ASC);
7280                                            }
7281                                            else {
7282                                                    query.append(ORDER_BY_DESC);
7283                                            }
7284                                    }
7285                            }
7286                    }
7287    
7288                    else {
7289                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7290                    }
7291    
7292                    String sql = query.toString();
7293    
7294                    Query q = session.createQuery(sql);
7295    
7296                    q.setFirstResult(0);
7297                    q.setMaxResults(2);
7298    
7299                    QueryPos qPos = QueryPos.getInstance(q);
7300    
7301                    qPos.add(nodeId);
7302    
7303                    qPos.add(head);
7304    
7305                    if (parentTitle != null) {
7306                            qPos.add(parentTitle);
7307                    }
7308    
7309                    qPos.add(status);
7310    
7311                    if (orderByComparator != null) {
7312                            Object[] values = orderByComparator.getOrderByValues(wikiPage);
7313    
7314                            for (Object value : values) {
7315                                    qPos.add(value);
7316                            }
7317                    }
7318    
7319                    List<WikiPage> list = q.list();
7320    
7321                    if (list.size() == 2) {
7322                            return list.get(1);
7323                    }
7324                    else {
7325                            return null;
7326                    }
7327            }
7328    
7329            /**
7330             * Finds all the wiki pages.
7331             *
7332             * @return the wiki pages
7333             * @throws SystemException if a system exception occurred
7334             */
7335            public List<WikiPage> findAll() throws SystemException {
7336                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7337            }
7338    
7339            /**
7340             * Finds a range of all the wiki pages.
7341             *
7342             * <p>
7343             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7344             * </p>
7345             *
7346             * @param start the lower bound of the range of wiki pages to return
7347             * @param end the upper bound of the range of wiki pages to return (not inclusive)
7348             * @return the range of wiki pages
7349             * @throws SystemException if a system exception occurred
7350             */
7351            public List<WikiPage> findAll(int start, int end) throws SystemException {
7352                    return findAll(start, end, null);
7353            }
7354    
7355            /**
7356             * Finds an ordered range of all the wiki pages.
7357             *
7358             * <p>
7359             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7360             * </p>
7361             *
7362             * @param start the lower bound of the range of wiki pages to return
7363             * @param end the upper bound of the range of wiki pages to return (not inclusive)
7364             * @param orderByComparator the comparator to order the results by
7365             * @return the ordered range of wiki pages
7366             * @throws SystemException if a system exception occurred
7367             */
7368            public List<WikiPage> findAll(int start, int end,
7369                    OrderByComparator orderByComparator) throws SystemException {
7370                    Object[] finderArgs = new Object[] {
7371                                    String.valueOf(start), String.valueOf(end),
7372                                    String.valueOf(orderByComparator)
7373                            };
7374    
7375                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
7376                                    finderArgs, this);
7377    
7378                    if (list == null) {
7379                            Session session = null;
7380    
7381                            try {
7382                                    session = openSession();
7383    
7384                                    StringBundler query = null;
7385                                    String sql = null;
7386    
7387                                    if (orderByComparator != null) {
7388                                            query = new StringBundler(2 +
7389                                                            (orderByComparator.getOrderByFields().length * 3));
7390    
7391                                            query.append(_SQL_SELECT_WIKIPAGE);
7392    
7393                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7394                                                    orderByComparator);
7395    
7396                                            sql = query.toString();
7397                                    }
7398                                    else {
7399                                            sql = _SQL_SELECT_WIKIPAGE.concat(WikiPageModelImpl.ORDER_BY_JPQL);
7400                                    }
7401    
7402                                    Query q = session.createQuery(sql);
7403    
7404                                    if (orderByComparator == null) {
7405                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
7406                                                            start, end, false);
7407    
7408                                            Collections.sort(list);
7409                                    }
7410                                    else {
7411                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
7412                                                            start, end);
7413                                    }
7414                            }
7415                            catch (Exception e) {
7416                                    throw processException(e);
7417                            }
7418                            finally {
7419                                    if (list == null) {
7420                                            list = new ArrayList<WikiPage>();
7421                                    }
7422    
7423                                    cacheResult(list);
7424    
7425                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
7426    
7427                                    closeSession(session);
7428                            }
7429                    }
7430    
7431                    return list;
7432            }
7433    
7434            /**
7435             * Removes all the wiki pages where uuid = &#63; from the database.
7436             *
7437             * @param uuid the uuid to search with
7438             * @throws SystemException if a system exception occurred
7439             */
7440            public void removeByUuid(String uuid) throws SystemException {
7441                    for (WikiPage wikiPage : findByUuid(uuid)) {
7442                            remove(wikiPage);
7443                    }
7444            }
7445    
7446            /**
7447             * Removes the wiki page where uuid = &#63; and groupId = &#63; from the database.
7448             *
7449             * @param uuid the uuid to search with
7450             * @param groupId the group id to search with
7451             * @throws SystemException if a system exception occurred
7452             */
7453            public void removeByUUID_G(String uuid, long groupId)
7454                    throws NoSuchPageException, SystemException {
7455                    WikiPage wikiPage = findByUUID_G(uuid, groupId);
7456    
7457                    remove(wikiPage);
7458            }
7459    
7460            /**
7461             * Removes all the wiki pages where nodeId = &#63; from the database.
7462             *
7463             * @param nodeId the node id to search with
7464             * @throws SystemException if a system exception occurred
7465             */
7466            public void removeByNodeId(long nodeId) throws SystemException {
7467                    for (WikiPage wikiPage : findByNodeId(nodeId)) {
7468                            remove(wikiPage);
7469                    }
7470            }
7471    
7472            /**
7473             * Removes all the wiki pages where format = &#63; from the database.
7474             *
7475             * @param format the format to search with
7476             * @throws SystemException if a system exception occurred
7477             */
7478            public void removeByFormat(String format) throws SystemException {
7479                    for (WikiPage wikiPage : findByFormat(format)) {
7480                            remove(wikiPage);
7481                    }
7482            }
7483    
7484            /**
7485             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; from the database.
7486             *
7487             * @param resourcePrimKey the resource prim key to search with
7488             * @param nodeId the node id to search with
7489             * @throws SystemException if a system exception occurred
7490             */
7491            public void removeByR_N(long resourcePrimKey, long nodeId)
7492                    throws SystemException {
7493                    for (WikiPage wikiPage : findByR_N(resourcePrimKey, nodeId)) {
7494                            remove(wikiPage);
7495                    }
7496            }
7497    
7498            /**
7499             * Removes all the wiki pages where nodeId = &#63; and title = &#63; from the database.
7500             *
7501             * @param nodeId the node id to search with
7502             * @param title the title to search with
7503             * @throws SystemException if a system exception occurred
7504             */
7505            public void removeByN_T(long nodeId, String title)
7506                    throws SystemException {
7507                    for (WikiPage wikiPage : findByN_T(nodeId, title)) {
7508                            remove(wikiPage);
7509                    }
7510            }
7511    
7512            /**
7513             * Removes all the wiki pages where nodeId = &#63; and head = &#63; from the database.
7514             *
7515             * @param nodeId the node id to search with
7516             * @param head the head to search with
7517             * @throws SystemException if a system exception occurred
7518             */
7519            public void removeByN_H(long nodeId, boolean head)
7520                    throws SystemException {
7521                    for (WikiPage wikiPage : findByN_H(nodeId, head)) {
7522                            remove(wikiPage);
7523                    }
7524            }
7525    
7526            /**
7527             * Removes all the wiki pages where nodeId = &#63; and parentTitle = &#63; from the database.
7528             *
7529             * @param nodeId the node id to search with
7530             * @param parentTitle the parent title to search with
7531             * @throws SystemException if a system exception occurred
7532             */
7533            public void removeByN_P(long nodeId, String parentTitle)
7534                    throws SystemException {
7535                    for (WikiPage wikiPage : findByN_P(nodeId, parentTitle)) {
7536                            remove(wikiPage);
7537                    }
7538            }
7539    
7540            /**
7541             * Removes all the wiki pages where nodeId = &#63; and redirectTitle = &#63; from the database.
7542             *
7543             * @param nodeId the node id to search with
7544             * @param redirectTitle the redirect title to search with
7545             * @throws SystemException if a system exception occurred
7546             */
7547            public void removeByN_R(long nodeId, String redirectTitle)
7548                    throws SystemException {
7549                    for (WikiPage wikiPage : findByN_R(nodeId, redirectTitle)) {
7550                            remove(wikiPage);
7551                    }
7552            }
7553    
7554            /**
7555             * Removes all the wiki pages where nodeId = &#63; and status = &#63; from the database.
7556             *
7557             * @param nodeId the node id to search with
7558             * @param status the status to search with
7559             * @throws SystemException if a system exception occurred
7560             */
7561            public void removeByN_S(long nodeId, int status) throws SystemException {
7562                    for (WikiPage wikiPage : findByN_S(nodeId, status)) {
7563                            remove(wikiPage);
7564                    }
7565            }
7566    
7567            /**
7568             * Removes the wiki page where resourcePrimKey = &#63; and nodeId = &#63; and version = &#63; from the database.
7569             *
7570             * @param resourcePrimKey the resource prim key to search with
7571             * @param nodeId the node id to search with
7572             * @param version the version to search with
7573             * @throws SystemException if a system exception occurred
7574             */
7575            public void removeByR_N_V(long resourcePrimKey, long nodeId, double version)
7576                    throws NoSuchPageException, SystemException {
7577                    WikiPage wikiPage = findByR_N_V(resourcePrimKey, nodeId, version);
7578    
7579                    remove(wikiPage);
7580            }
7581    
7582            /**
7583             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63; from the database.
7584             *
7585             * @param resourcePrimKey the resource prim key to search with
7586             * @param nodeId the node id to search with
7587             * @param status the status to search with
7588             * @throws SystemException if a system exception occurred
7589             */
7590            public void removeByR_N_S(long resourcePrimKey, long nodeId, int status)
7591                    throws SystemException {
7592                    for (WikiPage wikiPage : findByR_N_S(resourcePrimKey, nodeId, status)) {
7593                            remove(wikiPage);
7594                    }
7595            }
7596    
7597            /**
7598             * Removes all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63; from the database.
7599             *
7600             * @param userId the user id to search with
7601             * @param nodeId the node id to search with
7602             * @param status the status to search with
7603             * @throws SystemException if a system exception occurred
7604             */
7605            public void removeByU_N_S(long userId, long nodeId, int status)
7606                    throws SystemException {
7607                    for (WikiPage wikiPage : findByU_N_S(userId, nodeId, status)) {
7608                            remove(wikiPage);
7609                    }
7610            }
7611    
7612            /**
7613             * Removes the wiki page where nodeId = &#63; and title = &#63; and version = &#63; from the database.
7614             *
7615             * @param nodeId the node id to search with
7616             * @param title the title to search with
7617             * @param version the version to search with
7618             * @throws SystemException if a system exception occurred
7619             */
7620            public void removeByN_T_V(long nodeId, String title, double version)
7621                    throws NoSuchPageException, SystemException {
7622                    WikiPage wikiPage = findByN_T_V(nodeId, title, version);
7623    
7624                    remove(wikiPage);
7625            }
7626    
7627            /**
7628             * Removes all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63; from the database.
7629             *
7630             * @param nodeId the node id to search with
7631             * @param title the title to search with
7632             * @param head the head to search with
7633             * @throws SystemException if a system exception occurred
7634             */
7635            public void removeByN_T_H(long nodeId, String title, boolean head)
7636                    throws SystemException {
7637                    for (WikiPage wikiPage : findByN_T_H(nodeId, title, head)) {
7638                            remove(wikiPage);
7639                    }
7640            }
7641    
7642            /**
7643             * Removes all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63; from the database.
7644             *
7645             * @param nodeId the node id to search with
7646             * @param title the title to search with
7647             * @param status the status to search with
7648             * @throws SystemException if a system exception occurred
7649             */
7650            public void removeByN_T_S(long nodeId, String title, int status)
7651                    throws SystemException {
7652                    for (WikiPage wikiPage : findByN_T_S(nodeId, title, status)) {
7653                            remove(wikiPage);
7654                    }
7655            }
7656    
7657            /**
7658             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; from the database.
7659             *
7660             * @param nodeId the node id to search with
7661             * @param head the head to search with
7662             * @param parentTitle the parent title to search with
7663             * @throws SystemException if a system exception occurred
7664             */
7665            public void removeByN_H_P(long nodeId, boolean head, String parentTitle)
7666                    throws SystemException {
7667                    for (WikiPage wikiPage : findByN_H_P(nodeId, head, parentTitle)) {
7668                            remove(wikiPage);
7669                    }
7670            }
7671    
7672            /**
7673             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63; from the database.
7674             *
7675             * @param nodeId the node id to search with
7676             * @param head the head to search with
7677             * @param status the status to search with
7678             * @throws SystemException if a system exception occurred
7679             */
7680            public void removeByN_H_S(long nodeId, boolean head, int status)
7681                    throws SystemException {
7682                    for (WikiPage wikiPage : findByN_H_S(nodeId, head, status)) {
7683                            remove(wikiPage);
7684                    }
7685            }
7686    
7687            /**
7688             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63; from the database.
7689             *
7690             * @param nodeId the node id to search with
7691             * @param head the head to search with
7692             * @param parentTitle the parent title to search with
7693             * @param status the status to search with
7694             * @throws SystemException if a system exception occurred
7695             */
7696            public void removeByN_H_P_S(long nodeId, boolean head, String parentTitle,
7697                    int status) throws SystemException {
7698                    for (WikiPage wikiPage : findByN_H_P_S(nodeId, head, parentTitle, status)) {
7699                            remove(wikiPage);
7700                    }
7701            }
7702    
7703            /**
7704             * Removes all the wiki pages from the database.
7705             *
7706             * @throws SystemException if a system exception occurred
7707             */
7708            public void removeAll() throws SystemException {
7709                    for (WikiPage wikiPage : findAll()) {
7710                            remove(wikiPage);
7711                    }
7712            }
7713    
7714            /**
7715             * Counts all the wiki pages where uuid = &#63;.
7716             *
7717             * @param uuid the uuid to search with
7718             * @return the number of matching wiki pages
7719             * @throws SystemException if a system exception occurred
7720             */
7721            public int countByUuid(String uuid) throws SystemException {
7722                    Object[] finderArgs = new Object[] { uuid };
7723    
7724                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
7725                                    finderArgs, this);
7726    
7727                    if (count == null) {
7728                            Session session = null;
7729    
7730                            try {
7731                                    session = openSession();
7732    
7733                                    StringBundler query = new StringBundler(2);
7734    
7735                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
7736    
7737                                    if (uuid == null) {
7738                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
7739                                    }
7740                                    else {
7741                                            if (uuid.equals(StringPool.BLANK)) {
7742                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
7743                                            }
7744                                            else {
7745                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
7746                                            }
7747                                    }
7748    
7749                                    String sql = query.toString();
7750    
7751                                    Query q = session.createQuery(sql);
7752    
7753                                    QueryPos qPos = QueryPos.getInstance(q);
7754    
7755                                    if (uuid != null) {
7756                                            qPos.add(uuid);
7757                                    }
7758    
7759                                    count = (Long)q.uniqueResult();
7760                            }
7761                            catch (Exception e) {
7762                                    throw processException(e);
7763                            }
7764                            finally {
7765                                    if (count == null) {
7766                                            count = Long.valueOf(0);
7767                                    }
7768    
7769                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
7770                                            finderArgs, count);
7771    
7772                                    closeSession(session);
7773                            }
7774                    }
7775    
7776                    return count.intValue();
7777            }
7778    
7779            /**
7780             * Counts all the wiki pages where uuid = &#63; and groupId = &#63;.
7781             *
7782             * @param uuid the uuid to search with
7783             * @param groupId the group id to search with
7784             * @return the number of matching wiki pages
7785             * @throws SystemException if a system exception occurred
7786             */
7787            public int countByUUID_G(String uuid, long groupId)
7788                    throws SystemException {
7789                    Object[] finderArgs = new Object[] { uuid, groupId };
7790    
7791                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
7792                                    finderArgs, this);
7793    
7794                    if (count == null) {
7795                            Session session = null;
7796    
7797                            try {
7798                                    session = openSession();
7799    
7800                                    StringBundler query = new StringBundler(3);
7801    
7802                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
7803    
7804                                    if (uuid == null) {
7805                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
7806                                    }
7807                                    else {
7808                                            if (uuid.equals(StringPool.BLANK)) {
7809                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
7810                                            }
7811                                            else {
7812                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
7813                                            }
7814                                    }
7815    
7816                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
7817    
7818                                    String sql = query.toString();
7819    
7820                                    Query q = session.createQuery(sql);
7821    
7822                                    QueryPos qPos = QueryPos.getInstance(q);
7823    
7824                                    if (uuid != null) {
7825                                            qPos.add(uuid);
7826                                    }
7827    
7828                                    qPos.add(groupId);
7829    
7830                                    count = (Long)q.uniqueResult();
7831                            }
7832                            catch (Exception e) {
7833                                    throw processException(e);
7834                            }
7835                            finally {
7836                                    if (count == null) {
7837                                            count = Long.valueOf(0);
7838                                    }
7839    
7840                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
7841                                            finderArgs, count);
7842    
7843                                    closeSession(session);
7844                            }
7845                    }
7846    
7847                    return count.intValue();
7848            }
7849    
7850            /**
7851             * Counts all the wiki pages where nodeId = &#63;.
7852             *
7853             * @param nodeId the node id to search with
7854             * @return the number of matching wiki pages
7855             * @throws SystemException if a system exception occurred
7856             */
7857            public int countByNodeId(long nodeId) throws SystemException {
7858                    Object[] finderArgs = new Object[] { nodeId };
7859    
7860                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NODEID,
7861                                    finderArgs, this);
7862    
7863                    if (count == null) {
7864                            Session session = null;
7865    
7866                            try {
7867                                    session = openSession();
7868    
7869                                    StringBundler query = new StringBundler(2);
7870    
7871                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
7872    
7873                                    query.append(_FINDER_COLUMN_NODEID_NODEID_2);
7874    
7875                                    String sql = query.toString();
7876    
7877                                    Query q = session.createQuery(sql);
7878    
7879                                    QueryPos qPos = QueryPos.getInstance(q);
7880    
7881                                    qPos.add(nodeId);
7882    
7883                                    count = (Long)q.uniqueResult();
7884                            }
7885                            catch (Exception e) {
7886                                    throw processException(e);
7887                            }
7888                            finally {
7889                                    if (count == null) {
7890                                            count = Long.valueOf(0);
7891                                    }
7892    
7893                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NODEID,
7894                                            finderArgs, count);
7895    
7896                                    closeSession(session);
7897                            }
7898                    }
7899    
7900                    return count.intValue();
7901            }
7902    
7903            /**
7904             * Counts all the wiki pages where format = &#63;.
7905             *
7906             * @param format the format to search with
7907             * @return the number of matching wiki pages
7908             * @throws SystemException if a system exception occurred
7909             */
7910            public int countByFormat(String format) throws SystemException {
7911                    Object[] finderArgs = new Object[] { format };
7912    
7913                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FORMAT,
7914                                    finderArgs, this);
7915    
7916                    if (count == null) {
7917                            Session session = null;
7918    
7919                            try {
7920                                    session = openSession();
7921    
7922                                    StringBundler query = new StringBundler(2);
7923    
7924                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
7925    
7926                                    if (format == null) {
7927                                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
7928                                    }
7929                                    else {
7930                                            if (format.equals(StringPool.BLANK)) {
7931                                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
7932                                            }
7933                                            else {
7934                                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
7935                                            }
7936                                    }
7937    
7938                                    String sql = query.toString();
7939    
7940                                    Query q = session.createQuery(sql);
7941    
7942                                    QueryPos qPos = QueryPos.getInstance(q);
7943    
7944                                    if (format != null) {
7945                                            qPos.add(format);
7946                                    }
7947    
7948                                    count = (Long)q.uniqueResult();
7949                            }
7950                            catch (Exception e) {
7951                                    throw processException(e);
7952                            }
7953                            finally {
7954                                    if (count == null) {
7955                                            count = Long.valueOf(0);
7956                                    }
7957    
7958                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FORMAT,
7959                                            finderArgs, count);
7960    
7961                                    closeSession(session);
7962                            }
7963                    }
7964    
7965                    return count.intValue();
7966            }
7967    
7968            /**
7969             * Counts all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
7970             *
7971             * @param resourcePrimKey the resource prim key to search with
7972             * @param nodeId the node id to search with
7973             * @return the number of matching wiki pages
7974             * @throws SystemException if a system exception occurred
7975             */
7976            public int countByR_N(long resourcePrimKey, long nodeId)
7977                    throws SystemException {
7978                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId };
7979    
7980                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_R_N,
7981                                    finderArgs, this);
7982    
7983                    if (count == null) {
7984                            Session session = null;
7985    
7986                            try {
7987                                    session = openSession();
7988    
7989                                    StringBundler query = new StringBundler(3);
7990    
7991                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
7992    
7993                                    query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
7994    
7995                                    query.append(_FINDER_COLUMN_R_N_NODEID_2);
7996    
7997                                    String sql = query.toString();
7998    
7999                                    Query q = session.createQuery(sql);
8000    
8001                                    QueryPos qPos = QueryPos.getInstance(q);
8002    
8003                                    qPos.add(resourcePrimKey);
8004    
8005                                    qPos.add(nodeId);
8006    
8007                                    count = (Long)q.uniqueResult();
8008                            }
8009                            catch (Exception e) {
8010                                    throw processException(e);
8011                            }
8012                            finally {
8013                                    if (count == null) {
8014                                            count = Long.valueOf(0);
8015                                    }
8016    
8017                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N, finderArgs,
8018                                            count);
8019    
8020                                    closeSession(session);
8021                            }
8022                    }
8023    
8024                    return count.intValue();
8025            }
8026    
8027            /**
8028             * Counts all the wiki pages where nodeId = &#63; and title = &#63;.
8029             *
8030             * @param nodeId the node id to search with
8031             * @param title the title to search with
8032             * @return the number of matching wiki pages
8033             * @throws SystemException if a system exception occurred
8034             */
8035            public int countByN_T(long nodeId, String title) throws SystemException {
8036                    Object[] finderArgs = new Object[] { nodeId, title };
8037    
8038                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_T,
8039                                    finderArgs, this);
8040    
8041                    if (count == null) {
8042                            Session session = null;
8043    
8044                            try {
8045                                    session = openSession();
8046    
8047                                    StringBundler query = new StringBundler(3);
8048    
8049                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8050    
8051                                    query.append(_FINDER_COLUMN_N_T_NODEID_2);
8052    
8053                                    if (title == null) {
8054                                            query.append(_FINDER_COLUMN_N_T_TITLE_1);
8055                                    }
8056                                    else {
8057                                            if (title.equals(StringPool.BLANK)) {
8058                                                    query.append(_FINDER_COLUMN_N_T_TITLE_3);
8059                                            }
8060                                            else {
8061                                                    query.append(_FINDER_COLUMN_N_T_TITLE_2);
8062                                            }
8063                                    }
8064    
8065                                    String sql = query.toString();
8066    
8067                                    Query q = session.createQuery(sql);
8068    
8069                                    QueryPos qPos = QueryPos.getInstance(q);
8070    
8071                                    qPos.add(nodeId);
8072    
8073                                    if (title != null) {
8074                                            qPos.add(title);
8075                                    }
8076    
8077                                    count = (Long)q.uniqueResult();
8078                            }
8079                            catch (Exception e) {
8080                                    throw processException(e);
8081                            }
8082                            finally {
8083                                    if (count == null) {
8084                                            count = Long.valueOf(0);
8085                                    }
8086    
8087                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T, finderArgs,
8088                                            count);
8089    
8090                                    closeSession(session);
8091                            }
8092                    }
8093    
8094                    return count.intValue();
8095            }
8096    
8097            /**
8098             * Counts all the wiki pages where nodeId = &#63; and head = &#63;.
8099             *
8100             * @param nodeId the node id to search with
8101             * @param head the head to search with
8102             * @return the number of matching wiki pages
8103             * @throws SystemException if a system exception occurred
8104             */
8105            public int countByN_H(long nodeId, boolean head) throws SystemException {
8106                    Object[] finderArgs = new Object[] { nodeId, head };
8107    
8108                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_H,
8109                                    finderArgs, this);
8110    
8111                    if (count == null) {
8112                            Session session = null;
8113    
8114                            try {
8115                                    session = openSession();
8116    
8117                                    StringBundler query = new StringBundler(3);
8118    
8119                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8120    
8121                                    query.append(_FINDER_COLUMN_N_H_NODEID_2);
8122    
8123                                    query.append(_FINDER_COLUMN_N_H_HEAD_2);
8124    
8125                                    String sql = query.toString();
8126    
8127                                    Query q = session.createQuery(sql);
8128    
8129                                    QueryPos qPos = QueryPos.getInstance(q);
8130    
8131                                    qPos.add(nodeId);
8132    
8133                                    qPos.add(head);
8134    
8135                                    count = (Long)q.uniqueResult();
8136                            }
8137                            catch (Exception e) {
8138                                    throw processException(e);
8139                            }
8140                            finally {
8141                                    if (count == null) {
8142                                            count = Long.valueOf(0);
8143                                    }
8144    
8145                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_H, finderArgs,
8146                                            count);
8147    
8148                                    closeSession(session);
8149                            }
8150                    }
8151    
8152                    return count.intValue();
8153            }
8154    
8155            /**
8156             * Counts all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
8157             *
8158             * @param nodeId the node id to search with
8159             * @param parentTitle the parent title to search with
8160             * @return the number of matching wiki pages
8161             * @throws SystemException if a system exception occurred
8162             */
8163            public int countByN_P(long nodeId, String parentTitle)
8164                    throws SystemException {
8165                    Object[] finderArgs = new Object[] { nodeId, parentTitle };
8166    
8167                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_P,
8168                                    finderArgs, this);
8169    
8170                    if (count == null) {
8171                            Session session = null;
8172    
8173                            try {
8174                                    session = openSession();
8175    
8176                                    StringBundler query = new StringBundler(3);
8177    
8178                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8179    
8180                                    query.append(_FINDER_COLUMN_N_P_NODEID_2);
8181    
8182                                    if (parentTitle == null) {
8183                                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
8184                                    }
8185                                    else {
8186                                            if (parentTitle.equals(StringPool.BLANK)) {
8187                                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
8188                                            }
8189                                            else {
8190                                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
8191                                            }
8192                                    }
8193    
8194                                    String sql = query.toString();
8195    
8196                                    Query q = session.createQuery(sql);
8197    
8198                                    QueryPos qPos = QueryPos.getInstance(q);
8199    
8200                                    qPos.add(nodeId);
8201    
8202                                    if (parentTitle != null) {
8203                                            qPos.add(parentTitle);
8204                                    }
8205    
8206                                    count = (Long)q.uniqueResult();
8207                            }
8208                            catch (Exception e) {
8209                                    throw processException(e);
8210                            }
8211                            finally {
8212                                    if (count == null) {
8213                                            count = Long.valueOf(0);
8214                                    }
8215    
8216                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_P, finderArgs,
8217                                            count);
8218    
8219                                    closeSession(session);
8220                            }
8221                    }
8222    
8223                    return count.intValue();
8224            }
8225    
8226            /**
8227             * Counts all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
8228             *
8229             * @param nodeId the node id to search with
8230             * @param redirectTitle the redirect title to search with
8231             * @return the number of matching wiki pages
8232             * @throws SystemException if a system exception occurred
8233             */
8234            public int countByN_R(long nodeId, String redirectTitle)
8235                    throws SystemException {
8236                    Object[] finderArgs = new Object[] { nodeId, redirectTitle };
8237    
8238                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_R,
8239                                    finderArgs, this);
8240    
8241                    if (count == null) {
8242                            Session session = null;
8243    
8244                            try {
8245                                    session = openSession();
8246    
8247                                    StringBundler query = new StringBundler(3);
8248    
8249                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8250    
8251                                    query.append(_FINDER_COLUMN_N_R_NODEID_2);
8252    
8253                                    if (redirectTitle == null) {
8254                                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
8255                                    }
8256                                    else {
8257                                            if (redirectTitle.equals(StringPool.BLANK)) {
8258                                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
8259                                            }
8260                                            else {
8261                                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
8262                                            }
8263                                    }
8264    
8265                                    String sql = query.toString();
8266    
8267                                    Query q = session.createQuery(sql);
8268    
8269                                    QueryPos qPos = QueryPos.getInstance(q);
8270    
8271                                    qPos.add(nodeId);
8272    
8273                                    if (redirectTitle != null) {
8274                                            qPos.add(redirectTitle);
8275                                    }
8276    
8277                                    count = (Long)q.uniqueResult();
8278                            }
8279                            catch (Exception e) {
8280                                    throw processException(e);
8281                            }
8282                            finally {
8283                                    if (count == null) {
8284                                            count = Long.valueOf(0);
8285                                    }
8286    
8287                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_R, finderArgs,
8288                                            count);
8289    
8290                                    closeSession(session);
8291                            }
8292                    }
8293    
8294                    return count.intValue();
8295            }
8296    
8297            /**
8298             * Counts all the wiki pages where nodeId = &#63; and status = &#63;.
8299             *
8300             * @param nodeId the node id to search with
8301             * @param status the status to search with
8302             * @return the number of matching wiki pages
8303             * @throws SystemException if a system exception occurred
8304             */
8305            public int countByN_S(long nodeId, int status) throws SystemException {
8306                    Object[] finderArgs = new Object[] { nodeId, status };
8307    
8308                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_S,
8309                                    finderArgs, this);
8310    
8311                    if (count == null) {
8312                            Session session = null;
8313    
8314                            try {
8315                                    session = openSession();
8316    
8317                                    StringBundler query = new StringBundler(3);
8318    
8319                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8320    
8321                                    query.append(_FINDER_COLUMN_N_S_NODEID_2);
8322    
8323                                    query.append(_FINDER_COLUMN_N_S_STATUS_2);
8324    
8325                                    String sql = query.toString();
8326    
8327                                    Query q = session.createQuery(sql);
8328    
8329                                    QueryPos qPos = QueryPos.getInstance(q);
8330    
8331                                    qPos.add(nodeId);
8332    
8333                                    qPos.add(status);
8334    
8335                                    count = (Long)q.uniqueResult();
8336                            }
8337                            catch (Exception e) {
8338                                    throw processException(e);
8339                            }
8340                            finally {
8341                                    if (count == null) {
8342                                            count = Long.valueOf(0);
8343                                    }
8344    
8345                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_S, finderArgs,
8346                                            count);
8347    
8348                                    closeSession(session);
8349                            }
8350                    }
8351    
8352                    return count.intValue();
8353            }
8354    
8355            /**
8356             * Counts all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and version = &#63;.
8357             *
8358             * @param resourcePrimKey the resource prim key to search with
8359             * @param nodeId the node id to search with
8360             * @param version the version to search with
8361             * @return the number of matching wiki pages
8362             * @throws SystemException if a system exception occurred
8363             */
8364            public int countByR_N_V(long resourcePrimKey, long nodeId, double version)
8365                    throws SystemException {
8366                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, version };
8367    
8368                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_R_N_V,
8369                                    finderArgs, this);
8370    
8371                    if (count == null) {
8372                            Session session = null;
8373    
8374                            try {
8375                                    session = openSession();
8376    
8377                                    StringBundler query = new StringBundler(4);
8378    
8379                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8380    
8381                                    query.append(_FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2);
8382    
8383                                    query.append(_FINDER_COLUMN_R_N_V_NODEID_2);
8384    
8385                                    query.append(_FINDER_COLUMN_R_N_V_VERSION_2);
8386    
8387                                    String sql = query.toString();
8388    
8389                                    Query q = session.createQuery(sql);
8390    
8391                                    QueryPos qPos = QueryPos.getInstance(q);
8392    
8393                                    qPos.add(resourcePrimKey);
8394    
8395                                    qPos.add(nodeId);
8396    
8397                                    qPos.add(version);
8398    
8399                                    count = (Long)q.uniqueResult();
8400                            }
8401                            catch (Exception e) {
8402                                    throw processException(e);
8403                            }
8404                            finally {
8405                                    if (count == null) {
8406                                            count = Long.valueOf(0);
8407                                    }
8408    
8409                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_V,
8410                                            finderArgs, count);
8411    
8412                                    closeSession(session);
8413                            }
8414                    }
8415    
8416                    return count.intValue();
8417            }
8418    
8419            /**
8420             * Counts all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
8421             *
8422             * @param resourcePrimKey the resource prim key to search with
8423             * @param nodeId the node id to search with
8424             * @param status the status to search with
8425             * @return the number of matching wiki pages
8426             * @throws SystemException if a system exception occurred
8427             */
8428            public int countByR_N_S(long resourcePrimKey, long nodeId, int status)
8429                    throws SystemException {
8430                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, status };
8431    
8432                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_R_N_S,
8433                                    finderArgs, this);
8434    
8435                    if (count == null) {
8436                            Session session = null;
8437    
8438                            try {
8439                                    session = openSession();
8440    
8441                                    StringBundler query = new StringBundler(4);
8442    
8443                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8444    
8445                                    query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
8446    
8447                                    query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
8448    
8449                                    query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
8450    
8451                                    String sql = query.toString();
8452    
8453                                    Query q = session.createQuery(sql);
8454    
8455                                    QueryPos qPos = QueryPos.getInstance(q);
8456    
8457                                    qPos.add(resourcePrimKey);
8458    
8459                                    qPos.add(nodeId);
8460    
8461                                    qPos.add(status);
8462    
8463                                    count = (Long)q.uniqueResult();
8464                            }
8465                            catch (Exception e) {
8466                                    throw processException(e);
8467                            }
8468                            finally {
8469                                    if (count == null) {
8470                                            count = Long.valueOf(0);
8471                                    }
8472    
8473                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_S,
8474                                            finderArgs, count);
8475    
8476                                    closeSession(session);
8477                            }
8478                    }
8479    
8480                    return count.intValue();
8481            }
8482    
8483            /**
8484             * Counts all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
8485             *
8486             * @param userId the user id to search with
8487             * @param nodeId the node id to search with
8488             * @param status the status to search with
8489             * @return the number of matching wiki pages
8490             * @throws SystemException if a system exception occurred
8491             */
8492            public int countByU_N_S(long userId, long nodeId, int status)
8493                    throws SystemException {
8494                    Object[] finderArgs = new Object[] { userId, nodeId, status };
8495    
8496                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_N_S,
8497                                    finderArgs, this);
8498    
8499                    if (count == null) {
8500                            Session session = null;
8501    
8502                            try {
8503                                    session = openSession();
8504    
8505                                    StringBundler query = new StringBundler(4);
8506    
8507                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8508    
8509                                    query.append(_FINDER_COLUMN_U_N_S_USERID_2);
8510    
8511                                    query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
8512    
8513                                    query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
8514    
8515                                    String sql = query.toString();
8516    
8517                                    Query q = session.createQuery(sql);
8518    
8519                                    QueryPos qPos = QueryPos.getInstance(q);
8520    
8521                                    qPos.add(userId);
8522    
8523                                    qPos.add(nodeId);
8524    
8525                                    qPos.add(status);
8526    
8527                                    count = (Long)q.uniqueResult();
8528                            }
8529                            catch (Exception e) {
8530                                    throw processException(e);
8531                            }
8532                            finally {
8533                                    if (count == null) {
8534                                            count = Long.valueOf(0);
8535                                    }
8536    
8537                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_N_S,
8538                                            finderArgs, count);
8539    
8540                                    closeSession(session);
8541                            }
8542                    }
8543    
8544                    return count.intValue();
8545            }
8546    
8547            /**
8548             * Counts all the wiki pages where nodeId = &#63; and title = &#63; and version = &#63;.
8549             *
8550             * @param nodeId the node id to search with
8551             * @param title the title to search with
8552             * @param version the version to search with
8553             * @return the number of matching wiki pages
8554             * @throws SystemException if a system exception occurred
8555             */
8556            public int countByN_T_V(long nodeId, String title, double version)
8557                    throws SystemException {
8558                    Object[] finderArgs = new Object[] { nodeId, title, version };
8559    
8560                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_T_V,
8561                                    finderArgs, this);
8562    
8563                    if (count == null) {
8564                            Session session = null;
8565    
8566                            try {
8567                                    session = openSession();
8568    
8569                                    StringBundler query = new StringBundler(4);
8570    
8571                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8572    
8573                                    query.append(_FINDER_COLUMN_N_T_V_NODEID_2);
8574    
8575                                    if (title == null) {
8576                                            query.append(_FINDER_COLUMN_N_T_V_TITLE_1);
8577                                    }
8578                                    else {
8579                                            if (title.equals(StringPool.BLANK)) {
8580                                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_3);
8581                                            }
8582                                            else {
8583                                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_2);
8584                                            }
8585                                    }
8586    
8587                                    query.append(_FINDER_COLUMN_N_T_V_VERSION_2);
8588    
8589                                    String sql = query.toString();
8590    
8591                                    Query q = session.createQuery(sql);
8592    
8593                                    QueryPos qPos = QueryPos.getInstance(q);
8594    
8595                                    qPos.add(nodeId);
8596    
8597                                    if (title != null) {
8598                                            qPos.add(title);
8599                                    }
8600    
8601                                    qPos.add(version);
8602    
8603                                    count = (Long)q.uniqueResult();
8604                            }
8605                            catch (Exception e) {
8606                                    throw processException(e);
8607                            }
8608                            finally {
8609                                    if (count == null) {
8610                                            count = Long.valueOf(0);
8611                                    }
8612    
8613                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_V,
8614                                            finderArgs, count);
8615    
8616                                    closeSession(session);
8617                            }
8618                    }
8619    
8620                    return count.intValue();
8621            }
8622    
8623            /**
8624             * Counts all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
8625             *
8626             * @param nodeId the node id to search with
8627             * @param title the title to search with
8628             * @param head the head to search with
8629             * @return the number of matching wiki pages
8630             * @throws SystemException if a system exception occurred
8631             */
8632            public int countByN_T_H(long nodeId, String title, boolean head)
8633                    throws SystemException {
8634                    Object[] finderArgs = new Object[] { nodeId, title, head };
8635    
8636                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_T_H,
8637                                    finderArgs, this);
8638    
8639                    if (count == null) {
8640                            Session session = null;
8641    
8642                            try {
8643                                    session = openSession();
8644    
8645                                    StringBundler query = new StringBundler(4);
8646    
8647                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8648    
8649                                    query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
8650    
8651                                    if (title == null) {
8652                                            query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
8653                                    }
8654                                    else {
8655                                            if (title.equals(StringPool.BLANK)) {
8656                                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
8657                                            }
8658                                            else {
8659                                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
8660                                            }
8661                                    }
8662    
8663                                    query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
8664    
8665                                    String sql = query.toString();
8666    
8667                                    Query q = session.createQuery(sql);
8668    
8669                                    QueryPos qPos = QueryPos.getInstance(q);
8670    
8671                                    qPos.add(nodeId);
8672    
8673                                    if (title != null) {
8674                                            qPos.add(title);
8675                                    }
8676    
8677                                    qPos.add(head);
8678    
8679                                    count = (Long)q.uniqueResult();
8680                            }
8681                            catch (Exception e) {
8682                                    throw processException(e);
8683                            }
8684                            finally {
8685                                    if (count == null) {
8686                                            count = Long.valueOf(0);
8687                                    }
8688    
8689                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_H,
8690                                            finderArgs, count);
8691    
8692                                    closeSession(session);
8693                            }
8694                    }
8695    
8696                    return count.intValue();
8697            }
8698    
8699            /**
8700             * Counts all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
8701             *
8702             * @param nodeId the node id to search with
8703             * @param title the title to search with
8704             * @param status the status to search with
8705             * @return the number of matching wiki pages
8706             * @throws SystemException if a system exception occurred
8707             */
8708            public int countByN_T_S(long nodeId, String title, int status)
8709                    throws SystemException {
8710                    Object[] finderArgs = new Object[] { nodeId, title, status };
8711    
8712                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_T_S,
8713                                    finderArgs, this);
8714    
8715                    if (count == null) {
8716                            Session session = null;
8717    
8718                            try {
8719                                    session = openSession();
8720    
8721                                    StringBundler query = new StringBundler(4);
8722    
8723                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8724    
8725                                    query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
8726    
8727                                    if (title == null) {
8728                                            query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
8729                                    }
8730                                    else {
8731                                            if (title.equals(StringPool.BLANK)) {
8732                                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
8733                                            }
8734                                            else {
8735                                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
8736                                            }
8737                                    }
8738    
8739                                    query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
8740    
8741                                    String sql = query.toString();
8742    
8743                                    Query q = session.createQuery(sql);
8744    
8745                                    QueryPos qPos = QueryPos.getInstance(q);
8746    
8747                                    qPos.add(nodeId);
8748    
8749                                    if (title != null) {
8750                                            qPos.add(title);
8751                                    }
8752    
8753                                    qPos.add(status);
8754    
8755                                    count = (Long)q.uniqueResult();
8756                            }
8757                            catch (Exception e) {
8758                                    throw processException(e);
8759                            }
8760                            finally {
8761                                    if (count == null) {
8762                                            count = Long.valueOf(0);
8763                                    }
8764    
8765                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_S,
8766                                            finderArgs, count);
8767    
8768                                    closeSession(session);
8769                            }
8770                    }
8771    
8772                    return count.intValue();
8773            }
8774    
8775            /**
8776             * Counts all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
8777             *
8778             * @param nodeId the node id to search with
8779             * @param head the head to search with
8780             * @param parentTitle the parent title to search with
8781             * @return the number of matching wiki pages
8782             * @throws SystemException if a system exception occurred
8783             */
8784            public int countByN_H_P(long nodeId, boolean head, String parentTitle)
8785                    throws SystemException {
8786                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle };
8787    
8788                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_H_P,
8789                                    finderArgs, this);
8790    
8791                    if (count == null) {
8792                            Session session = null;
8793    
8794                            try {
8795                                    session = openSession();
8796    
8797                                    StringBundler query = new StringBundler(4);
8798    
8799                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8800    
8801                                    query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
8802    
8803                                    query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
8804    
8805                                    if (parentTitle == null) {
8806                                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
8807                                    }
8808                                    else {
8809                                            if (parentTitle.equals(StringPool.BLANK)) {
8810                                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
8811                                            }
8812                                            else {
8813                                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
8814                                            }
8815                                    }
8816    
8817                                    String sql = query.toString();
8818    
8819                                    Query q = session.createQuery(sql);
8820    
8821                                    QueryPos qPos = QueryPos.getInstance(q);
8822    
8823                                    qPos.add(nodeId);
8824    
8825                                    qPos.add(head);
8826    
8827                                    if (parentTitle != null) {
8828                                            qPos.add(parentTitle);
8829                                    }
8830    
8831                                    count = (Long)q.uniqueResult();
8832                            }
8833                            catch (Exception e) {
8834                                    throw processException(e);
8835                            }
8836                            finally {
8837                                    if (count == null) {
8838                                            count = Long.valueOf(0);
8839                                    }
8840    
8841                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_H_P,
8842                                            finderArgs, count);
8843    
8844                                    closeSession(session);
8845                            }
8846                    }
8847    
8848                    return count.intValue();
8849            }
8850    
8851            /**
8852             * Counts all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
8853             *
8854             * @param nodeId the node id to search with
8855             * @param head the head to search with
8856             * @param status the status to search with
8857             * @return the number of matching wiki pages
8858             * @throws SystemException if a system exception occurred
8859             */
8860            public int countByN_H_S(long nodeId, boolean head, int status)
8861                    throws SystemException {
8862                    Object[] finderArgs = new Object[] { nodeId, head, status };
8863    
8864                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_H_S,
8865                                    finderArgs, this);
8866    
8867                    if (count == null) {
8868                            Session session = null;
8869    
8870                            try {
8871                                    session = openSession();
8872    
8873                                    StringBundler query = new StringBundler(4);
8874    
8875                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8876    
8877                                    query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
8878    
8879                                    query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
8880    
8881                                    query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
8882    
8883                                    String sql = query.toString();
8884    
8885                                    Query q = session.createQuery(sql);
8886    
8887                                    QueryPos qPos = QueryPos.getInstance(q);
8888    
8889                                    qPos.add(nodeId);
8890    
8891                                    qPos.add(head);
8892    
8893                                    qPos.add(status);
8894    
8895                                    count = (Long)q.uniqueResult();
8896                            }
8897                            catch (Exception e) {
8898                                    throw processException(e);
8899                            }
8900                            finally {
8901                                    if (count == null) {
8902                                            count = Long.valueOf(0);
8903                                    }
8904    
8905                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_H_S,
8906                                            finderArgs, count);
8907    
8908                                    closeSession(session);
8909                            }
8910                    }
8911    
8912                    return count.intValue();
8913            }
8914    
8915            /**
8916             * Counts all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
8917             *
8918             * @param nodeId the node id to search with
8919             * @param head the head to search with
8920             * @param parentTitle the parent title to search with
8921             * @param status the status to search with
8922             * @return the number of matching wiki pages
8923             * @throws SystemException if a system exception occurred
8924             */
8925            public int countByN_H_P_S(long nodeId, boolean head, String parentTitle,
8926                    int status) throws SystemException {
8927                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle, status };
8928    
8929                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_H_P_S,
8930                                    finderArgs, this);
8931    
8932                    if (count == null) {
8933                            Session session = null;
8934    
8935                            try {
8936                                    session = openSession();
8937    
8938                                    StringBundler query = new StringBundler(5);
8939    
8940                                    query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8941    
8942                                    query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
8943    
8944                                    query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
8945    
8946                                    if (parentTitle == null) {
8947                                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
8948                                    }
8949                                    else {
8950                                            if (parentTitle.equals(StringPool.BLANK)) {
8951                                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
8952                                            }
8953                                            else {
8954                                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
8955                                            }
8956                                    }
8957    
8958                                    query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
8959    
8960                                    String sql = query.toString();
8961    
8962                                    Query q = session.createQuery(sql);
8963    
8964                                    QueryPos qPos = QueryPos.getInstance(q);
8965    
8966                                    qPos.add(nodeId);
8967    
8968                                    qPos.add(head);
8969    
8970                                    if (parentTitle != null) {
8971                                            qPos.add(parentTitle);
8972                                    }
8973    
8974                                    qPos.add(status);
8975    
8976                                    count = (Long)q.uniqueResult();
8977                            }
8978                            catch (Exception e) {
8979                                    throw processException(e);
8980                            }
8981                            finally {
8982                                    if (count == null) {
8983                                            count = Long.valueOf(0);
8984                                    }
8985    
8986                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_H_P_S,
8987                                            finderArgs, count);
8988    
8989                                    closeSession(session);
8990                            }
8991                    }
8992    
8993                    return count.intValue();
8994            }
8995    
8996            /**
8997             * Counts all the wiki pages.
8998             *
8999             * @return the number of wiki pages
9000             * @throws SystemException if a system exception occurred
9001             */
9002            public int countAll() throws SystemException {
9003                    Object[] finderArgs = new Object[0];
9004    
9005                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
9006                                    finderArgs, this);
9007    
9008                    if (count == null) {
9009                            Session session = null;
9010    
9011                            try {
9012                                    session = openSession();
9013    
9014                                    Query q = session.createQuery(_SQL_COUNT_WIKIPAGE);
9015    
9016                                    count = (Long)q.uniqueResult();
9017                            }
9018                            catch (Exception e) {
9019                                    throw processException(e);
9020                            }
9021                            finally {
9022                                    if (count == null) {
9023                                            count = Long.valueOf(0);
9024                                    }
9025    
9026                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
9027                                            count);
9028    
9029                                    closeSession(session);
9030                            }
9031                    }
9032    
9033                    return count.intValue();
9034            }
9035    
9036            /**
9037             * Initializes the wiki page persistence.
9038             */
9039            public void afterPropertiesSet() {
9040                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
9041                                            com.liferay.portal.util.PropsUtil.get(
9042                                                    "value.object.listener.com.liferay.portlet.wiki.model.WikiPage")));
9043    
9044                    if (listenerClassNames.length > 0) {
9045                            try {
9046                                    List<ModelListener<WikiPage>> listenersList = new ArrayList<ModelListener<WikiPage>>();
9047    
9048                                    for (String listenerClassName : listenerClassNames) {
9049                                            listenersList.add((ModelListener<WikiPage>)InstanceFactory.newInstance(
9050                                                            listenerClassName));
9051                                    }
9052    
9053                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
9054                            }
9055                            catch (Exception e) {
9056                                    _log.error(e);
9057                            }
9058                    }
9059            }
9060    
9061            public void destroy() {
9062                    EntityCacheUtil.removeCache(WikiPageImpl.class.getName());
9063                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
9064                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
9065            }
9066    
9067            @BeanReference(type = WikiNodePersistence.class)
9068            protected WikiNodePersistence wikiNodePersistence;
9069            @BeanReference(type = WikiPagePersistence.class)
9070            protected WikiPagePersistence wikiPagePersistence;
9071            @BeanReference(type = WikiPageResourcePersistence.class)
9072            protected WikiPageResourcePersistence wikiPageResourcePersistence;
9073            @BeanReference(type = CompanyPersistence.class)
9074            protected CompanyPersistence companyPersistence;
9075            @BeanReference(type = GroupPersistence.class)
9076            protected GroupPersistence groupPersistence;
9077            @BeanReference(type = PortletPreferencesPersistence.class)
9078            protected PortletPreferencesPersistence portletPreferencesPersistence;
9079            @BeanReference(type = ResourcePersistence.class)
9080            protected ResourcePersistence resourcePersistence;
9081            @BeanReference(type = SubscriptionPersistence.class)
9082            protected SubscriptionPersistence subscriptionPersistence;
9083            @BeanReference(type = UserPersistence.class)
9084            protected UserPersistence userPersistence;
9085            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
9086            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
9087            @BeanReference(type = AssetCategoryPersistence.class)
9088            protected AssetCategoryPersistence assetCategoryPersistence;
9089            @BeanReference(type = AssetEntryPersistence.class)
9090            protected AssetEntryPersistence assetEntryPersistence;
9091            @BeanReference(type = AssetTagPersistence.class)
9092            protected AssetTagPersistence assetTagPersistence;
9093            @BeanReference(type = ExpandoValuePersistence.class)
9094            protected ExpandoValuePersistence expandoValuePersistence;
9095            @BeanReference(type = MBMessagePersistence.class)
9096            protected MBMessagePersistence mbMessagePersistence;
9097            @BeanReference(type = SocialActivityPersistence.class)
9098            protected SocialActivityPersistence socialActivityPersistence;
9099            @BeanReference(type = SocialEquityLogPersistence.class)
9100            protected SocialEquityLogPersistence socialEquityLogPersistence;
9101            private static final String _SQL_SELECT_WIKIPAGE = "SELECT wikiPage FROM WikiPage wikiPage";
9102            private static final String _SQL_SELECT_WIKIPAGE_WHERE = "SELECT wikiPage FROM WikiPage wikiPage WHERE ";
9103            private static final String _SQL_COUNT_WIKIPAGE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage";
9104            private static final String _SQL_COUNT_WIKIPAGE_WHERE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage WHERE ";
9105            private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiPage.uuid IS NULL";
9106            private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiPage.uuid = ?";
9107            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiPage.uuid IS NULL OR wikiPage.uuid = ?)";
9108            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "wikiPage.uuid IS NULL AND ";
9109            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "wikiPage.uuid = ? AND ";
9110            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(wikiPage.uuid IS NULL OR wikiPage.uuid = ?) AND ";
9111            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "wikiPage.groupId = ?";
9112            private static final String _FINDER_COLUMN_NODEID_NODEID_2 = "wikiPage.nodeId = ?";
9113            private static final String _FINDER_COLUMN_FORMAT_FORMAT_1 = "wikiPage.format IS NULL";
9114            private static final String _FINDER_COLUMN_FORMAT_FORMAT_2 = "wikiPage.format = ?";
9115            private static final String _FINDER_COLUMN_FORMAT_FORMAT_3 = "(wikiPage.format IS NULL OR wikiPage.format = ?)";
9116            private static final String _FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
9117            private static final String _FINDER_COLUMN_R_N_NODEID_2 = "wikiPage.nodeId = ?";
9118            private static final String _FINDER_COLUMN_N_T_NODEID_2 = "wikiPage.nodeId = ? AND ";
9119            private static final String _FINDER_COLUMN_N_T_TITLE_1 = "wikiPage.title IS NULL";
9120            private static final String _FINDER_COLUMN_N_T_TITLE_2 = "lower(wikiPage.title) = lower(?)";
9121            private static final String _FINDER_COLUMN_N_T_TITLE_3 = "(wikiPage.title IS NULL OR lower(wikiPage.title) = lower(?))";
9122            private static final String _FINDER_COLUMN_N_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
9123            private static final String _FINDER_COLUMN_N_H_HEAD_2 = "wikiPage.head = ?";
9124            private static final String _FINDER_COLUMN_N_P_NODEID_2 = "wikiPage.nodeId = ? AND ";
9125            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL";
9126            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = lower(?)";
9127            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR lower(wikiPage.parentTitle) = lower(?))";
9128            private static final String _FINDER_COLUMN_N_R_NODEID_2 = "wikiPage.nodeId = ? AND ";
9129            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_1 = "wikiPage.redirectTitle IS NULL";
9130            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_2 = "lower(wikiPage.redirectTitle) = lower(?)";
9131            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_3 = "(wikiPage.redirectTitle IS NULL OR lower(wikiPage.redirectTitle) = lower(?))";
9132            private static final String _FINDER_COLUMN_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
9133            private static final String _FINDER_COLUMN_N_S_STATUS_2 = "wikiPage.status = ?";
9134            private static final String _FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
9135            private static final String _FINDER_COLUMN_R_N_V_NODEID_2 = "wikiPage.nodeId = ? AND ";
9136            private static final String _FINDER_COLUMN_R_N_V_VERSION_2 = "wikiPage.version = ?";
9137            private static final String _FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
9138            private static final String _FINDER_COLUMN_R_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
9139            private static final String _FINDER_COLUMN_R_N_S_STATUS_2 = "wikiPage.status = ?";
9140            private static final String _FINDER_COLUMN_U_N_S_USERID_2 = "wikiPage.userId = ? AND ";
9141            private static final String _FINDER_COLUMN_U_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
9142            private static final String _FINDER_COLUMN_U_N_S_STATUS_2 = "wikiPage.status = ?";
9143            private static final String _FINDER_COLUMN_N_T_V_NODEID_2 = "wikiPage.nodeId = ? AND ";
9144            private static final String _FINDER_COLUMN_N_T_V_TITLE_1 = "wikiPage.title IS NULL AND ";
9145            private static final String _FINDER_COLUMN_N_T_V_TITLE_2 = "lower(wikiPage.title) = lower(?) AND ";
9146            private static final String _FINDER_COLUMN_N_T_V_TITLE_3 = "(wikiPage.title IS NULL OR lower(wikiPage.title) = lower(?)) AND ";
9147            private static final String _FINDER_COLUMN_N_T_V_VERSION_2 = "wikiPage.version = ?";
9148            private static final String _FINDER_COLUMN_N_T_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
9149            private static final String _FINDER_COLUMN_N_T_H_TITLE_1 = "wikiPage.title IS NULL AND ";
9150            private static final String _FINDER_COLUMN_N_T_H_TITLE_2 = "lower(wikiPage.title) = lower(?) AND ";
9151            private static final String _FINDER_COLUMN_N_T_H_TITLE_3 = "(wikiPage.title IS NULL OR lower(wikiPage.title) = lower(?)) AND ";
9152            private static final String _FINDER_COLUMN_N_T_H_HEAD_2 = "wikiPage.head = ?";
9153            private static final String _FINDER_COLUMN_N_T_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
9154            private static final String _FINDER_COLUMN_N_T_S_TITLE_1 = "wikiPage.title IS NULL AND ";
9155            private static final String _FINDER_COLUMN_N_T_S_TITLE_2 = "lower(wikiPage.title) = lower(?) AND ";
9156            private static final String _FINDER_COLUMN_N_T_S_TITLE_3 = "(wikiPage.title IS NULL OR lower(wikiPage.title) = lower(?)) AND ";
9157            private static final String _FINDER_COLUMN_N_T_S_STATUS_2 = "wikiPage.status = ?";
9158            private static final String _FINDER_COLUMN_N_H_P_NODEID_2 = "wikiPage.nodeId = ? AND ";
9159            private static final String _FINDER_COLUMN_N_H_P_HEAD_2 = "wikiPage.head = ? AND ";
9160            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL";
9161            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = lower(?)";
9162            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR lower(wikiPage.parentTitle) = lower(?))";
9163            private static final String _FINDER_COLUMN_N_H_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
9164            private static final String _FINDER_COLUMN_N_H_S_HEAD_2 = "wikiPage.head = ? AND ";
9165            private static final String _FINDER_COLUMN_N_H_S_STATUS_2 = "wikiPage.status = ?";
9166            private static final String _FINDER_COLUMN_N_H_P_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
9167            private static final String _FINDER_COLUMN_N_H_P_S_HEAD_2 = "wikiPage.head = ? AND ";
9168            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
9169            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = lower(?) AND ";
9170            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR lower(wikiPage.parentTitle) = lower(?)) AND ";
9171            private static final String _FINDER_COLUMN_N_H_P_S_STATUS_2 = "wikiPage.status = ?";
9172            private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPage.";
9173            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPage exists with the primary key ";
9174            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPage exists with the key {";
9175            private static Log _log = LogFactoryUtil.getLog(WikiPagePersistenceImpl.class);
9176    }