001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.wiki.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.SQLQuery;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.sanitizer.Sanitizer;
030    import com.liferay.portal.kernel.sanitizer.SanitizerException;
031    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
032    import com.liferay.portal.kernel.util.ContentTypes;
033    import com.liferay.portal.kernel.util.GetterUtil;
034    import com.liferay.portal.kernel.util.InstanceFactory;
035    import com.liferay.portal.kernel.util.OrderByComparator;
036    import com.liferay.portal.kernel.util.SetUtil;
037    import com.liferay.portal.kernel.util.StringBundler;
038    import com.liferay.portal.kernel.util.StringPool;
039    import com.liferay.portal.kernel.util.StringUtil;
040    import com.liferay.portal.kernel.util.UnmodifiableList;
041    import com.liferay.portal.kernel.util.Validator;
042    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
043    import com.liferay.portal.model.CacheModel;
044    import com.liferay.portal.model.ModelListener;
045    import com.liferay.portal.security.auth.PrincipalThreadLocal;
046    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.wiki.NoSuchPageException;
050    import com.liferay.portlet.wiki.model.WikiPage;
051    import com.liferay.portlet.wiki.model.impl.WikiPageImpl;
052    import com.liferay.portlet.wiki.model.impl.WikiPageModelImpl;
053    
054    import java.io.Serializable;
055    
056    import java.util.ArrayList;
057    import java.util.Collections;
058    import java.util.List;
059    import java.util.Set;
060    
061    /**
062     * The persistence implementation for the wiki page service.
063     *
064     * <p>
065     * Caching information and settings can be found in <code>portal.properties</code>
066     * </p>
067     *
068     * @author Brian Wing Shun Chan
069     * @see WikiPagePersistence
070     * @see WikiPageUtil
071     * @generated
072     */
073    public class WikiPagePersistenceImpl extends BasePersistenceImpl<WikiPage>
074            implements WikiPagePersistence {
075            /*
076             * NOTE FOR DEVELOPERS:
077             *
078             * 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.
079             */
080            public static final String FINDER_CLASS_NAME_ENTITY = WikiPageImpl.class.getName();
081            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List1";
083            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List2";
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
086                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
089                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
092                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
095                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
097                            new String[] {
098                                    String.class.getName(),
099                                    
100                            Integer.class.getName(), Integer.class.getName(),
101                                    OrderByComparator.class.getName()
102                            });
103            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
104                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
106                            new String[] { String.class.getName() },
107                            WikiPageModelImpl.UUID_COLUMN_BITMASK |
108                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
109                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
110                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
111            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
112                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
114                            new String[] { String.class.getName() });
115    
116            /**
117             * Returns all the wiki pages where uuid = &#63;.
118             *
119             * @param uuid the uuid
120             * @return the matching wiki pages
121             * @throws SystemException if a system exception occurred
122             */
123            public List<WikiPage> findByUuid(String uuid) throws SystemException {
124                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
125            }
126    
127            /**
128             * Returns a range of all the wiki pages where uuid = &#63;.
129             *
130             * <p>
131             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
132             * </p>
133             *
134             * @param uuid the uuid
135             * @param start the lower bound of the range of wiki pages
136             * @param end the upper bound of the range of wiki pages (not inclusive)
137             * @return the range of matching wiki pages
138             * @throws SystemException if a system exception occurred
139             */
140            public List<WikiPage> findByUuid(String uuid, int start, int end)
141                    throws SystemException {
142                    return findByUuid(uuid, start, end, null);
143            }
144    
145            /**
146             * Returns an ordered range of all the wiki pages where uuid = &#63;.
147             *
148             * <p>
149             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
150             * </p>
151             *
152             * @param uuid the uuid
153             * @param start the lower bound of the range of wiki pages
154             * @param end the upper bound of the range of wiki pages (not inclusive)
155             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
156             * @return the ordered range of matching wiki pages
157             * @throws SystemException if a system exception occurred
158             */
159            public List<WikiPage> findByUuid(String uuid, int start, int end,
160                    OrderByComparator orderByComparator) throws SystemException {
161                    boolean pagination = true;
162                    FinderPath finderPath = null;
163                    Object[] finderArgs = null;
164    
165                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
166                                    (orderByComparator == null)) {
167                            pagination = false;
168                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
169                            finderArgs = new Object[] { uuid };
170                    }
171                    else {
172                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
173                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
174                    }
175    
176                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
177                                    finderArgs, this);
178    
179                    if ((list != null) && !list.isEmpty()) {
180                            for (WikiPage wikiPage : list) {
181                                    if (!Validator.equals(uuid, wikiPage.getUuid())) {
182                                            list = null;
183    
184                                            break;
185                                    }
186                            }
187                    }
188    
189                    if (list == null) {
190                            StringBundler query = null;
191    
192                            if (orderByComparator != null) {
193                                    query = new StringBundler(3 +
194                                                    (orderByComparator.getOrderByFields().length * 3));
195                            }
196                            else {
197                                    query = new StringBundler(3);
198                            }
199    
200                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
201    
202                            boolean bindUuid = false;
203    
204                            if (uuid == null) {
205                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
206                            }
207                            else if (uuid.equals(StringPool.BLANK)) {
208                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
209                            }
210                            else {
211                                    bindUuid = true;
212    
213                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
214                            }
215    
216                            if (orderByComparator != null) {
217                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
218                                            orderByComparator);
219                            }
220                            else
221                             if (pagination) {
222                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
223                            }
224    
225                            String sql = query.toString();
226    
227                            Session session = null;
228    
229                            try {
230                                    session = openSession();
231    
232                                    Query q = session.createQuery(sql);
233    
234                                    QueryPos qPos = QueryPos.getInstance(q);
235    
236                                    if (bindUuid) {
237                                            qPos.add(uuid);
238                                    }
239    
240                                    if (!pagination) {
241                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
242                                                            start, end, false);
243    
244                                            Collections.sort(list);
245    
246                                            list = new UnmodifiableList<WikiPage>(list);
247                                    }
248                                    else {
249                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
250                                                            start, end);
251                                    }
252    
253                                    cacheResult(list);
254    
255                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
256                            }
257                            catch (Exception e) {
258                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
259    
260                                    throw processException(e);
261                            }
262                            finally {
263                                    closeSession(session);
264                            }
265                    }
266    
267                    return list;
268            }
269    
270            /**
271             * Returns the first wiki page in the ordered set where uuid = &#63;.
272             *
273             * @param uuid the uuid
274             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
275             * @return the first matching wiki page
276             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
277             * @throws SystemException if a system exception occurred
278             */
279            public WikiPage findByUuid_First(String uuid,
280                    OrderByComparator orderByComparator)
281                    throws NoSuchPageException, SystemException {
282                    WikiPage wikiPage = fetchByUuid_First(uuid, orderByComparator);
283    
284                    if (wikiPage != null) {
285                            return wikiPage;
286                    }
287    
288                    StringBundler msg = new StringBundler(4);
289    
290                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
291    
292                    msg.append("uuid=");
293                    msg.append(uuid);
294    
295                    msg.append(StringPool.CLOSE_CURLY_BRACE);
296    
297                    throw new NoSuchPageException(msg.toString());
298            }
299    
300            /**
301             * Returns the first wiki page in the ordered set where uuid = &#63;.
302             *
303             * @param uuid the uuid
304             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
305             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
306             * @throws SystemException if a system exception occurred
307             */
308            public WikiPage fetchByUuid_First(String uuid,
309                    OrderByComparator orderByComparator) throws SystemException {
310                    List<WikiPage> list = findByUuid(uuid, 0, 1, orderByComparator);
311    
312                    if (!list.isEmpty()) {
313                            return list.get(0);
314                    }
315    
316                    return null;
317            }
318    
319            /**
320             * Returns the last wiki page in the ordered set where uuid = &#63;.
321             *
322             * @param uuid the uuid
323             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
324             * @return the last matching wiki page
325             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
326             * @throws SystemException if a system exception occurred
327             */
328            public WikiPage findByUuid_Last(String uuid,
329                    OrderByComparator orderByComparator)
330                    throws NoSuchPageException, SystemException {
331                    WikiPage wikiPage = fetchByUuid_Last(uuid, orderByComparator);
332    
333                    if (wikiPage != null) {
334                            return wikiPage;
335                    }
336    
337                    StringBundler msg = new StringBundler(4);
338    
339                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
340    
341                    msg.append("uuid=");
342                    msg.append(uuid);
343    
344                    msg.append(StringPool.CLOSE_CURLY_BRACE);
345    
346                    throw new NoSuchPageException(msg.toString());
347            }
348    
349            /**
350             * Returns the last wiki page in the ordered set where uuid = &#63;.
351             *
352             * @param uuid the uuid
353             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
354             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
355             * @throws SystemException if a system exception occurred
356             */
357            public WikiPage fetchByUuid_Last(String uuid,
358                    OrderByComparator orderByComparator) throws SystemException {
359                    int count = countByUuid(uuid);
360    
361                    List<WikiPage> list = findByUuid(uuid, count - 1, count,
362                                    orderByComparator);
363    
364                    if (!list.isEmpty()) {
365                            return list.get(0);
366                    }
367    
368                    return null;
369            }
370    
371            /**
372             * Returns the wiki pages before and after the current wiki page in the ordered set where uuid = &#63;.
373             *
374             * @param pageId the primary key of the current wiki page
375             * @param uuid the uuid
376             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
377             * @return the previous, current, and next wiki page
378             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
379             * @throws SystemException if a system exception occurred
380             */
381            public WikiPage[] findByUuid_PrevAndNext(long pageId, String uuid,
382                    OrderByComparator orderByComparator)
383                    throws NoSuchPageException, SystemException {
384                    WikiPage wikiPage = findByPrimaryKey(pageId);
385    
386                    Session session = null;
387    
388                    try {
389                            session = openSession();
390    
391                            WikiPage[] array = new WikiPageImpl[3];
392    
393                            array[0] = getByUuid_PrevAndNext(session, wikiPage, uuid,
394                                            orderByComparator, true);
395    
396                            array[1] = wikiPage;
397    
398                            array[2] = getByUuid_PrevAndNext(session, wikiPage, uuid,
399                                            orderByComparator, false);
400    
401                            return array;
402                    }
403                    catch (Exception e) {
404                            throw processException(e);
405                    }
406                    finally {
407                            closeSession(session);
408                    }
409            }
410    
411            protected WikiPage getByUuid_PrevAndNext(Session session,
412                    WikiPage wikiPage, String uuid, OrderByComparator orderByComparator,
413                    boolean previous) {
414                    StringBundler query = null;
415    
416                    if (orderByComparator != null) {
417                            query = new StringBundler(6 +
418                                            (orderByComparator.getOrderByFields().length * 6));
419                    }
420                    else {
421                            query = new StringBundler(3);
422                    }
423    
424                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
425    
426                    boolean bindUuid = false;
427    
428                    if (uuid == null) {
429                            query.append(_FINDER_COLUMN_UUID_UUID_1);
430                    }
431                    else if (uuid.equals(StringPool.BLANK)) {
432                            query.append(_FINDER_COLUMN_UUID_UUID_3);
433                    }
434                    else {
435                            bindUuid = true;
436    
437                            query.append(_FINDER_COLUMN_UUID_UUID_2);
438                    }
439    
440                    if (orderByComparator != null) {
441                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
442    
443                            if (orderByConditionFields.length > 0) {
444                                    query.append(WHERE_AND);
445                            }
446    
447                            for (int i = 0; i < orderByConditionFields.length; i++) {
448                                    query.append(_ORDER_BY_ENTITY_ALIAS);
449                                    query.append(orderByConditionFields[i]);
450    
451                                    if ((i + 1) < orderByConditionFields.length) {
452                                            if (orderByComparator.isAscending() ^ previous) {
453                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
454                                            }
455                                            else {
456                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
457                                            }
458                                    }
459                                    else {
460                                            if (orderByComparator.isAscending() ^ previous) {
461                                                    query.append(WHERE_GREATER_THAN);
462                                            }
463                                            else {
464                                                    query.append(WHERE_LESSER_THAN);
465                                            }
466                                    }
467                            }
468    
469                            query.append(ORDER_BY_CLAUSE);
470    
471                            String[] orderByFields = orderByComparator.getOrderByFields();
472    
473                            for (int i = 0; i < orderByFields.length; i++) {
474                                    query.append(_ORDER_BY_ENTITY_ALIAS);
475                                    query.append(orderByFields[i]);
476    
477                                    if ((i + 1) < orderByFields.length) {
478                                            if (orderByComparator.isAscending() ^ previous) {
479                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
480                                            }
481                                            else {
482                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
483                                            }
484                                    }
485                                    else {
486                                            if (orderByComparator.isAscending() ^ previous) {
487                                                    query.append(ORDER_BY_ASC);
488                                            }
489                                            else {
490                                                    query.append(ORDER_BY_DESC);
491                                            }
492                                    }
493                            }
494                    }
495                    else {
496                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
497                    }
498    
499                    String sql = query.toString();
500    
501                    Query q = session.createQuery(sql);
502    
503                    q.setFirstResult(0);
504                    q.setMaxResults(2);
505    
506                    QueryPos qPos = QueryPos.getInstance(q);
507    
508                    if (bindUuid) {
509                            qPos.add(uuid);
510                    }
511    
512                    if (orderByComparator != null) {
513                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
514    
515                            for (Object value : values) {
516                                    qPos.add(value);
517                            }
518                    }
519    
520                    List<WikiPage> list = q.list();
521    
522                    if (list.size() == 2) {
523                            return list.get(1);
524                    }
525                    else {
526                            return null;
527                    }
528            }
529    
530            /**
531             * Removes all the wiki pages where uuid = &#63; from the database.
532             *
533             * @param uuid the uuid
534             * @throws SystemException if a system exception occurred
535             */
536            public void removeByUuid(String uuid) throws SystemException {
537                    for (WikiPage wikiPage : findByUuid(uuid, QueryUtil.ALL_POS,
538                                    QueryUtil.ALL_POS, null)) {
539                            remove(wikiPage);
540                    }
541            }
542    
543            /**
544             * Returns the number of wiki pages where uuid = &#63;.
545             *
546             * @param uuid the uuid
547             * @return the number of matching wiki pages
548             * @throws SystemException if a system exception occurred
549             */
550            public int countByUuid(String uuid) throws SystemException {
551                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
552    
553                    Object[] finderArgs = new Object[] { uuid };
554    
555                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
556                                    this);
557    
558                    if (count == null) {
559                            StringBundler query = new StringBundler(2);
560    
561                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
562    
563                            boolean bindUuid = false;
564    
565                            if (uuid == null) {
566                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
567                            }
568                            else if (uuid.equals(StringPool.BLANK)) {
569                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
570                            }
571                            else {
572                                    bindUuid = true;
573    
574                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
575                            }
576    
577                            String sql = query.toString();
578    
579                            Session session = null;
580    
581                            try {
582                                    session = openSession();
583    
584                                    Query q = session.createQuery(sql);
585    
586                                    QueryPos qPos = QueryPos.getInstance(q);
587    
588                                    if (bindUuid) {
589                                            qPos.add(uuid);
590                                    }
591    
592                                    count = (Long)q.uniqueResult();
593    
594                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
595                            }
596                            catch (Exception e) {
597                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
598    
599                                    throw processException(e);
600                            }
601                            finally {
602                                    closeSession(session);
603                            }
604                    }
605    
606                    return count.intValue();
607            }
608    
609            private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiPage.uuid IS NULL";
610            private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiPage.uuid = ?";
611            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiPage.uuid IS NULL OR wikiPage.uuid = '')";
612            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
613                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
614                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
615                            new String[] { String.class.getName(), Long.class.getName() },
616                            WikiPageModelImpl.UUID_COLUMN_BITMASK |
617                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK);
618            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
619                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
620                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
621                            new String[] { String.class.getName(), Long.class.getName() });
622    
623            /**
624             * Returns the wiki page where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.wiki.NoSuchPageException} if it could not be found.
625             *
626             * @param uuid the uuid
627             * @param groupId the group ID
628             * @return the matching wiki page
629             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
630             * @throws SystemException if a system exception occurred
631             */
632            public WikiPage findByUUID_G(String uuid, long groupId)
633                    throws NoSuchPageException, SystemException {
634                    WikiPage wikiPage = fetchByUUID_G(uuid, groupId);
635    
636                    if (wikiPage == null) {
637                            StringBundler msg = new StringBundler(6);
638    
639                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
640    
641                            msg.append("uuid=");
642                            msg.append(uuid);
643    
644                            msg.append(", groupId=");
645                            msg.append(groupId);
646    
647                            msg.append(StringPool.CLOSE_CURLY_BRACE);
648    
649                            if (_log.isWarnEnabled()) {
650                                    _log.warn(msg.toString());
651                            }
652    
653                            throw new NoSuchPageException(msg.toString());
654                    }
655    
656                    return wikiPage;
657            }
658    
659            /**
660             * Returns the wiki page where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
661             *
662             * @param uuid the uuid
663             * @param groupId the group ID
664             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
665             * @throws SystemException if a system exception occurred
666             */
667            public WikiPage fetchByUUID_G(String uuid, long groupId)
668                    throws SystemException {
669                    return fetchByUUID_G(uuid, groupId, true);
670            }
671    
672            /**
673             * Returns 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.
674             *
675             * @param uuid the uuid
676             * @param groupId the group ID
677             * @param retrieveFromCache whether to use the finder cache
678             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
679             * @throws SystemException if a system exception occurred
680             */
681            public WikiPage fetchByUUID_G(String uuid, long groupId,
682                    boolean retrieveFromCache) throws SystemException {
683                    Object[] finderArgs = new Object[] { uuid, groupId };
684    
685                    Object result = null;
686    
687                    if (retrieveFromCache) {
688                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
689                                            finderArgs, this);
690                    }
691    
692                    if (result instanceof WikiPage) {
693                            WikiPage wikiPage = (WikiPage)result;
694    
695                            if (!Validator.equals(uuid, wikiPage.getUuid()) ||
696                                            (groupId != wikiPage.getGroupId())) {
697                                    result = null;
698                            }
699                    }
700    
701                    if (result == null) {
702                            StringBundler query = new StringBundler(4);
703    
704                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
705    
706                            boolean bindUuid = false;
707    
708                            if (uuid == null) {
709                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
710                            }
711                            else if (uuid.equals(StringPool.BLANK)) {
712                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
713                            }
714                            else {
715                                    bindUuid = true;
716    
717                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
718                            }
719    
720                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
721    
722                            String sql = query.toString();
723    
724                            Session session = null;
725    
726                            try {
727                                    session = openSession();
728    
729                                    Query q = session.createQuery(sql);
730    
731                                    QueryPos qPos = QueryPos.getInstance(q);
732    
733                                    if (bindUuid) {
734                                            qPos.add(uuid);
735                                    }
736    
737                                    qPos.add(groupId);
738    
739                                    List<WikiPage> list = q.list();
740    
741                                    if (list.isEmpty()) {
742                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
743                                                    finderArgs, list);
744                                    }
745                                    else {
746                                            WikiPage wikiPage = list.get(0);
747    
748                                            result = wikiPage;
749    
750                                            cacheResult(wikiPage);
751    
752                                            if ((wikiPage.getUuid() == null) ||
753                                                            !wikiPage.getUuid().equals(uuid) ||
754                                                            (wikiPage.getGroupId() != groupId)) {
755                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
756                                                            finderArgs, wikiPage);
757                                            }
758                                    }
759                            }
760                            catch (Exception e) {
761                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
762                                            finderArgs);
763    
764                                    throw processException(e);
765                            }
766                            finally {
767                                    closeSession(session);
768                            }
769                    }
770    
771                    if (result instanceof List<?>) {
772                            return null;
773                    }
774                    else {
775                            return (WikiPage)result;
776                    }
777            }
778    
779            /**
780             * Removes the wiki page where uuid = &#63; and groupId = &#63; from the database.
781             *
782             * @param uuid the uuid
783             * @param groupId the group ID
784             * @return the wiki page that was removed
785             * @throws SystemException if a system exception occurred
786             */
787            public WikiPage removeByUUID_G(String uuid, long groupId)
788                    throws NoSuchPageException, SystemException {
789                    WikiPage wikiPage = findByUUID_G(uuid, groupId);
790    
791                    return remove(wikiPage);
792            }
793    
794            /**
795             * Returns the number of wiki pages where uuid = &#63; and groupId = &#63;.
796             *
797             * @param uuid the uuid
798             * @param groupId the group ID
799             * @return the number of matching wiki pages
800             * @throws SystemException if a system exception occurred
801             */
802            public int countByUUID_G(String uuid, long groupId)
803                    throws SystemException {
804                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
805    
806                    Object[] finderArgs = new Object[] { uuid, groupId };
807    
808                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
809                                    this);
810    
811                    if (count == null) {
812                            StringBundler query = new StringBundler(3);
813    
814                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
815    
816                            boolean bindUuid = false;
817    
818                            if (uuid == null) {
819                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
820                            }
821                            else if (uuid.equals(StringPool.BLANK)) {
822                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
823                            }
824                            else {
825                                    bindUuid = true;
826    
827                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
828                            }
829    
830                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
831    
832                            String sql = query.toString();
833    
834                            Session session = null;
835    
836                            try {
837                                    session = openSession();
838    
839                                    Query q = session.createQuery(sql);
840    
841                                    QueryPos qPos = QueryPos.getInstance(q);
842    
843                                    if (bindUuid) {
844                                            qPos.add(uuid);
845                                    }
846    
847                                    qPos.add(groupId);
848    
849                                    count = (Long)q.uniqueResult();
850    
851                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
852                            }
853                            catch (Exception e) {
854                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
855    
856                                    throw processException(e);
857                            }
858                            finally {
859                                    closeSession(session);
860                            }
861                    }
862    
863                    return count.intValue();
864            }
865    
866            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "wikiPage.uuid IS NULL AND ";
867            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "wikiPage.uuid = ? AND ";
868            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(wikiPage.uuid IS NULL OR wikiPage.uuid = '') AND ";
869            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "wikiPage.groupId = ?";
870            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
871                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
872                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
873                            new String[] {
874                                    String.class.getName(), Long.class.getName(),
875                                    
876                            Integer.class.getName(), Integer.class.getName(),
877                                    OrderByComparator.class.getName()
878                            });
879            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
880                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
881                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
882                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
883                            new String[] { String.class.getName(), Long.class.getName() },
884                            WikiPageModelImpl.UUID_COLUMN_BITMASK |
885                            WikiPageModelImpl.COMPANYID_COLUMN_BITMASK |
886                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
887                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
888                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
889            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
890                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
891                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
892                            new String[] { String.class.getName(), Long.class.getName() });
893    
894            /**
895             * Returns all the wiki pages where uuid = &#63; and companyId = &#63;.
896             *
897             * @param uuid the uuid
898             * @param companyId the company ID
899             * @return the matching wiki pages
900             * @throws SystemException if a system exception occurred
901             */
902            public List<WikiPage> findByUuid_C(String uuid, long companyId)
903                    throws SystemException {
904                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
905                            QueryUtil.ALL_POS, null);
906            }
907    
908            /**
909             * Returns a range of all the wiki pages where uuid = &#63; and companyId = &#63;.
910             *
911             * <p>
912             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
913             * </p>
914             *
915             * @param uuid the uuid
916             * @param companyId the company ID
917             * @param start the lower bound of the range of wiki pages
918             * @param end the upper bound of the range of wiki pages (not inclusive)
919             * @return the range of matching wiki pages
920             * @throws SystemException if a system exception occurred
921             */
922            public List<WikiPage> findByUuid_C(String uuid, long companyId, int start,
923                    int end) throws SystemException {
924                    return findByUuid_C(uuid, companyId, start, end, null);
925            }
926    
927            /**
928             * Returns an ordered range of all the wiki pages where uuid = &#63; and companyId = &#63;.
929             *
930             * <p>
931             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
932             * </p>
933             *
934             * @param uuid the uuid
935             * @param companyId the company ID
936             * @param start the lower bound of the range of wiki pages
937             * @param end the upper bound of the range of wiki pages (not inclusive)
938             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
939             * @return the ordered range of matching wiki pages
940             * @throws SystemException if a system exception occurred
941             */
942            public List<WikiPage> findByUuid_C(String uuid, long companyId, int start,
943                    int end, OrderByComparator orderByComparator) throws SystemException {
944                    boolean pagination = true;
945                    FinderPath finderPath = null;
946                    Object[] finderArgs = null;
947    
948                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
949                                    (orderByComparator == null)) {
950                            pagination = false;
951                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
952                            finderArgs = new Object[] { uuid, companyId };
953                    }
954                    else {
955                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
956                            finderArgs = new Object[] {
957                                            uuid, companyId,
958                                            
959                                            start, end, orderByComparator
960                                    };
961                    }
962    
963                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
964                                    finderArgs, this);
965    
966                    if ((list != null) && !list.isEmpty()) {
967                            for (WikiPage wikiPage : list) {
968                                    if (!Validator.equals(uuid, wikiPage.getUuid()) ||
969                                                    (companyId != wikiPage.getCompanyId())) {
970                                            list = null;
971    
972                                            break;
973                                    }
974                            }
975                    }
976    
977                    if (list == null) {
978                            StringBundler query = null;
979    
980                            if (orderByComparator != null) {
981                                    query = new StringBundler(4 +
982                                                    (orderByComparator.getOrderByFields().length * 3));
983                            }
984                            else {
985                                    query = new StringBundler(4);
986                            }
987    
988                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
989    
990                            boolean bindUuid = false;
991    
992                            if (uuid == null) {
993                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
994                            }
995                            else if (uuid.equals(StringPool.BLANK)) {
996                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
997                            }
998                            else {
999                                    bindUuid = true;
1000    
1001                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1002                            }
1003    
1004                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1005    
1006                            if (orderByComparator != null) {
1007                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1008                                            orderByComparator);
1009                            }
1010                            else
1011                             if (pagination) {
1012                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1013                            }
1014    
1015                            String sql = query.toString();
1016    
1017                            Session session = null;
1018    
1019                            try {
1020                                    session = openSession();
1021    
1022                                    Query q = session.createQuery(sql);
1023    
1024                                    QueryPos qPos = QueryPos.getInstance(q);
1025    
1026                                    if (bindUuid) {
1027                                            qPos.add(uuid);
1028                                    }
1029    
1030                                    qPos.add(companyId);
1031    
1032                                    if (!pagination) {
1033                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1034                                                            start, end, false);
1035    
1036                                            Collections.sort(list);
1037    
1038                                            list = new UnmodifiableList<WikiPage>(list);
1039                                    }
1040                                    else {
1041                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1042                                                            start, end);
1043                                    }
1044    
1045                                    cacheResult(list);
1046    
1047                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1048                            }
1049                            catch (Exception e) {
1050                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1051    
1052                                    throw processException(e);
1053                            }
1054                            finally {
1055                                    closeSession(session);
1056                            }
1057                    }
1058    
1059                    return list;
1060            }
1061    
1062            /**
1063             * Returns the first wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1064             *
1065             * @param uuid the uuid
1066             * @param companyId the company ID
1067             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1068             * @return the first matching wiki page
1069             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1070             * @throws SystemException if a system exception occurred
1071             */
1072            public WikiPage findByUuid_C_First(String uuid, long companyId,
1073                    OrderByComparator orderByComparator)
1074                    throws NoSuchPageException, SystemException {
1075                    WikiPage wikiPage = fetchByUuid_C_First(uuid, companyId,
1076                                    orderByComparator);
1077    
1078                    if (wikiPage != null) {
1079                            return wikiPage;
1080                    }
1081    
1082                    StringBundler msg = new StringBundler(6);
1083    
1084                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1085    
1086                    msg.append("uuid=");
1087                    msg.append(uuid);
1088    
1089                    msg.append(", companyId=");
1090                    msg.append(companyId);
1091    
1092                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1093    
1094                    throw new NoSuchPageException(msg.toString());
1095            }
1096    
1097            /**
1098             * Returns the first wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1099             *
1100             * @param uuid the uuid
1101             * @param companyId the company ID
1102             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1103             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
1104             * @throws SystemException if a system exception occurred
1105             */
1106            public WikiPage fetchByUuid_C_First(String uuid, long companyId,
1107                    OrderByComparator orderByComparator) throws SystemException {
1108                    List<WikiPage> list = findByUuid_C(uuid, companyId, 0, 1,
1109                                    orderByComparator);
1110    
1111                    if (!list.isEmpty()) {
1112                            return list.get(0);
1113                    }
1114    
1115                    return null;
1116            }
1117    
1118            /**
1119             * Returns the last wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1120             *
1121             * @param uuid the uuid
1122             * @param companyId the company ID
1123             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1124             * @return the last matching wiki page
1125             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1126             * @throws SystemException if a system exception occurred
1127             */
1128            public WikiPage findByUuid_C_Last(String uuid, long companyId,
1129                    OrderByComparator orderByComparator)
1130                    throws NoSuchPageException, SystemException {
1131                    WikiPage wikiPage = fetchByUuid_C_Last(uuid, companyId,
1132                                    orderByComparator);
1133    
1134                    if (wikiPage != null) {
1135                            return wikiPage;
1136                    }
1137    
1138                    StringBundler msg = new StringBundler(6);
1139    
1140                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1141    
1142                    msg.append("uuid=");
1143                    msg.append(uuid);
1144    
1145                    msg.append(", companyId=");
1146                    msg.append(companyId);
1147    
1148                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1149    
1150                    throw new NoSuchPageException(msg.toString());
1151            }
1152    
1153            /**
1154             * Returns the last wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1155             *
1156             * @param uuid the uuid
1157             * @param companyId the company ID
1158             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1159             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
1160             * @throws SystemException if a system exception occurred
1161             */
1162            public WikiPage fetchByUuid_C_Last(String uuid, long companyId,
1163                    OrderByComparator orderByComparator) throws SystemException {
1164                    int count = countByUuid_C(uuid, companyId);
1165    
1166                    List<WikiPage> list = findByUuid_C(uuid, companyId, count - 1, count,
1167                                    orderByComparator);
1168    
1169                    if (!list.isEmpty()) {
1170                            return list.get(0);
1171                    }
1172    
1173                    return null;
1174            }
1175    
1176            /**
1177             * Returns the wiki pages before and after the current wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1178             *
1179             * @param pageId the primary key of the current wiki page
1180             * @param uuid the uuid
1181             * @param companyId the company ID
1182             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1183             * @return the previous, current, and next wiki page
1184             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
1185             * @throws SystemException if a system exception occurred
1186             */
1187            public WikiPage[] findByUuid_C_PrevAndNext(long pageId, String uuid,
1188                    long companyId, OrderByComparator orderByComparator)
1189                    throws NoSuchPageException, SystemException {
1190                    WikiPage wikiPage = findByPrimaryKey(pageId);
1191    
1192                    Session session = null;
1193    
1194                    try {
1195                            session = openSession();
1196    
1197                            WikiPage[] array = new WikiPageImpl[3];
1198    
1199                            array[0] = getByUuid_C_PrevAndNext(session, wikiPage, uuid,
1200                                            companyId, orderByComparator, true);
1201    
1202                            array[1] = wikiPage;
1203    
1204                            array[2] = getByUuid_C_PrevAndNext(session, wikiPage, uuid,
1205                                            companyId, orderByComparator, false);
1206    
1207                            return array;
1208                    }
1209                    catch (Exception e) {
1210                            throw processException(e);
1211                    }
1212                    finally {
1213                            closeSession(session);
1214                    }
1215            }
1216    
1217            protected WikiPage getByUuid_C_PrevAndNext(Session session,
1218                    WikiPage wikiPage, String uuid, long companyId,
1219                    OrderByComparator orderByComparator, boolean previous) {
1220                    StringBundler query = null;
1221    
1222                    if (orderByComparator != null) {
1223                            query = new StringBundler(6 +
1224                                            (orderByComparator.getOrderByFields().length * 6));
1225                    }
1226                    else {
1227                            query = new StringBundler(3);
1228                    }
1229    
1230                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1231    
1232                    boolean bindUuid = false;
1233    
1234                    if (uuid == null) {
1235                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1236                    }
1237                    else if (uuid.equals(StringPool.BLANK)) {
1238                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1239                    }
1240                    else {
1241                            bindUuid = true;
1242    
1243                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1244                    }
1245    
1246                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1247    
1248                    if (orderByComparator != null) {
1249                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1250    
1251                            if (orderByConditionFields.length > 0) {
1252                                    query.append(WHERE_AND);
1253                            }
1254    
1255                            for (int i = 0; i < orderByConditionFields.length; i++) {
1256                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1257                                    query.append(orderByConditionFields[i]);
1258    
1259                                    if ((i + 1) < orderByConditionFields.length) {
1260                                            if (orderByComparator.isAscending() ^ previous) {
1261                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1262                                            }
1263                                            else {
1264                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1265                                            }
1266                                    }
1267                                    else {
1268                                            if (orderByComparator.isAscending() ^ previous) {
1269                                                    query.append(WHERE_GREATER_THAN);
1270                                            }
1271                                            else {
1272                                                    query.append(WHERE_LESSER_THAN);
1273                                            }
1274                                    }
1275                            }
1276    
1277                            query.append(ORDER_BY_CLAUSE);
1278    
1279                            String[] orderByFields = orderByComparator.getOrderByFields();
1280    
1281                            for (int i = 0; i < orderByFields.length; i++) {
1282                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1283                                    query.append(orderByFields[i]);
1284    
1285                                    if ((i + 1) < orderByFields.length) {
1286                                            if (orderByComparator.isAscending() ^ previous) {
1287                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1288                                            }
1289                                            else {
1290                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1291                                            }
1292                                    }
1293                                    else {
1294                                            if (orderByComparator.isAscending() ^ previous) {
1295                                                    query.append(ORDER_BY_ASC);
1296                                            }
1297                                            else {
1298                                                    query.append(ORDER_BY_DESC);
1299                                            }
1300                                    }
1301                            }
1302                    }
1303                    else {
1304                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1305                    }
1306    
1307                    String sql = query.toString();
1308    
1309                    Query q = session.createQuery(sql);
1310    
1311                    q.setFirstResult(0);
1312                    q.setMaxResults(2);
1313    
1314                    QueryPos qPos = QueryPos.getInstance(q);
1315    
1316                    if (bindUuid) {
1317                            qPos.add(uuid);
1318                    }
1319    
1320                    qPos.add(companyId);
1321    
1322                    if (orderByComparator != null) {
1323                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
1324    
1325                            for (Object value : values) {
1326                                    qPos.add(value);
1327                            }
1328                    }
1329    
1330                    List<WikiPage> list = q.list();
1331    
1332                    if (list.size() == 2) {
1333                            return list.get(1);
1334                    }
1335                    else {
1336                            return null;
1337                    }
1338            }
1339    
1340            /**
1341             * Removes all the wiki pages where uuid = &#63; and companyId = &#63; from the database.
1342             *
1343             * @param uuid the uuid
1344             * @param companyId the company ID
1345             * @throws SystemException if a system exception occurred
1346             */
1347            public void removeByUuid_C(String uuid, long companyId)
1348                    throws SystemException {
1349                    for (WikiPage wikiPage : findByUuid_C(uuid, companyId,
1350                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1351                            remove(wikiPage);
1352                    }
1353            }
1354    
1355            /**
1356             * Returns the number of wiki pages where uuid = &#63; and companyId = &#63;.
1357             *
1358             * @param uuid the uuid
1359             * @param companyId the company ID
1360             * @return the number of matching wiki pages
1361             * @throws SystemException if a system exception occurred
1362             */
1363            public int countByUuid_C(String uuid, long companyId)
1364                    throws SystemException {
1365                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1366    
1367                    Object[] finderArgs = new Object[] { uuid, companyId };
1368    
1369                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1370                                    this);
1371    
1372                    if (count == null) {
1373                            StringBundler query = new StringBundler(3);
1374    
1375                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
1376    
1377                            boolean bindUuid = false;
1378    
1379                            if (uuid == null) {
1380                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1381                            }
1382                            else if (uuid.equals(StringPool.BLANK)) {
1383                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1384                            }
1385                            else {
1386                                    bindUuid = true;
1387    
1388                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1389                            }
1390    
1391                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1392    
1393                            String sql = query.toString();
1394    
1395                            Session session = null;
1396    
1397                            try {
1398                                    session = openSession();
1399    
1400                                    Query q = session.createQuery(sql);
1401    
1402                                    QueryPos qPos = QueryPos.getInstance(q);
1403    
1404                                    if (bindUuid) {
1405                                            qPos.add(uuid);
1406                                    }
1407    
1408                                    qPos.add(companyId);
1409    
1410                                    count = (Long)q.uniqueResult();
1411    
1412                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1413                            }
1414                            catch (Exception e) {
1415                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1416    
1417                                    throw processException(e);
1418                            }
1419                            finally {
1420                                    closeSession(session);
1421                            }
1422                    }
1423    
1424                    return count.intValue();
1425            }
1426    
1427            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "wikiPage.uuid IS NULL AND ";
1428            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "wikiPage.uuid = ? AND ";
1429            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(wikiPage.uuid IS NULL OR wikiPage.uuid = '') AND ";
1430            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "wikiPage.companyId = ?";
1431            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NODEID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1432                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1433                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByNodeId",
1434                            new String[] {
1435                                    Long.class.getName(),
1436                                    
1437                            Integer.class.getName(), Integer.class.getName(),
1438                                    OrderByComparator.class.getName()
1439                            });
1440            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID =
1441                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1442                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1443                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByNodeId",
1444                            new String[] { Long.class.getName() },
1445                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
1446                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
1447                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
1448            public static final FinderPath FINDER_PATH_COUNT_BY_NODEID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1449                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1450                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByNodeId",
1451                            new String[] { Long.class.getName() });
1452    
1453            /**
1454             * Returns all the wiki pages where nodeId = &#63;.
1455             *
1456             * @param nodeId the node ID
1457             * @return the matching wiki pages
1458             * @throws SystemException if a system exception occurred
1459             */
1460            public List<WikiPage> findByNodeId(long nodeId) throws SystemException {
1461                    return findByNodeId(nodeId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1462            }
1463    
1464            /**
1465             * Returns a range of all the wiki pages 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1469             * </p>
1470             *
1471             * @param nodeId the node ID
1472             * @param start the lower bound of the range of wiki pages
1473             * @param end the upper bound of the range of wiki pages (not inclusive)
1474             * @return the range of matching wiki pages
1475             * @throws SystemException if a system exception occurred
1476             */
1477            public List<WikiPage> findByNodeId(long nodeId, int start, int end)
1478                    throws SystemException {
1479                    return findByNodeId(nodeId, start, end, null);
1480            }
1481    
1482            /**
1483             * Returns an ordered range of all the wiki pages where nodeId = &#63;.
1484             *
1485             * <p>
1486             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1487             * </p>
1488             *
1489             * @param nodeId the node ID
1490             * @param start the lower bound of the range of wiki pages
1491             * @param end the upper bound of the range of wiki pages (not inclusive)
1492             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1493             * @return the ordered range of matching wiki pages
1494             * @throws SystemException if a system exception occurred
1495             */
1496            public List<WikiPage> findByNodeId(long nodeId, int start, int end,
1497                    OrderByComparator orderByComparator) throws SystemException {
1498                    boolean pagination = true;
1499                    FinderPath finderPath = null;
1500                    Object[] finderArgs = null;
1501    
1502                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1503                                    (orderByComparator == null)) {
1504                            pagination = false;
1505                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID;
1506                            finderArgs = new Object[] { nodeId };
1507                    }
1508                    else {
1509                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NODEID;
1510                            finderArgs = new Object[] { nodeId, start, end, orderByComparator };
1511                    }
1512    
1513                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
1514                                    finderArgs, this);
1515    
1516                    if ((list != null) && !list.isEmpty()) {
1517                            for (WikiPage wikiPage : list) {
1518                                    if ((nodeId != wikiPage.getNodeId())) {
1519                                            list = null;
1520    
1521                                            break;
1522                                    }
1523                            }
1524                    }
1525    
1526                    if (list == null) {
1527                            StringBundler query = null;
1528    
1529                            if (orderByComparator != null) {
1530                                    query = new StringBundler(3 +
1531                                                    (orderByComparator.getOrderByFields().length * 3));
1532                            }
1533                            else {
1534                                    query = new StringBundler(3);
1535                            }
1536    
1537                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1538    
1539                            query.append(_FINDER_COLUMN_NODEID_NODEID_2);
1540    
1541                            if (orderByComparator != null) {
1542                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1543                                            orderByComparator);
1544                            }
1545                            else
1546                             if (pagination) {
1547                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1548                            }
1549    
1550                            String sql = query.toString();
1551    
1552                            Session session = null;
1553    
1554                            try {
1555                                    session = openSession();
1556    
1557                                    Query q = session.createQuery(sql);
1558    
1559                                    QueryPos qPos = QueryPos.getInstance(q);
1560    
1561                                    qPos.add(nodeId);
1562    
1563                                    if (!pagination) {
1564                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1565                                                            start, end, false);
1566    
1567                                            Collections.sort(list);
1568    
1569                                            list = new UnmodifiableList<WikiPage>(list);
1570                                    }
1571                                    else {
1572                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1573                                                            start, end);
1574                                    }
1575    
1576                                    cacheResult(list);
1577    
1578                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1579                            }
1580                            catch (Exception e) {
1581                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1582    
1583                                    throw processException(e);
1584                            }
1585                            finally {
1586                                    closeSession(session);
1587                            }
1588                    }
1589    
1590                    return list;
1591            }
1592    
1593            /**
1594             * Returns the first wiki page in the ordered set where nodeId = &#63;.
1595             *
1596             * @param nodeId the node ID
1597             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1598             * @return the first matching wiki page
1599             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1600             * @throws SystemException if a system exception occurred
1601             */
1602            public WikiPage findByNodeId_First(long nodeId,
1603                    OrderByComparator orderByComparator)
1604                    throws NoSuchPageException, SystemException {
1605                    WikiPage wikiPage = fetchByNodeId_First(nodeId, orderByComparator);
1606    
1607                    if (wikiPage != null) {
1608                            return wikiPage;
1609                    }
1610    
1611                    StringBundler msg = new StringBundler(4);
1612    
1613                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1614    
1615                    msg.append("nodeId=");
1616                    msg.append(nodeId);
1617    
1618                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1619    
1620                    throw new NoSuchPageException(msg.toString());
1621            }
1622    
1623            /**
1624             * Returns the first wiki page in the ordered set where nodeId = &#63;.
1625             *
1626             * @param nodeId the node ID
1627             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1628             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
1629             * @throws SystemException if a system exception occurred
1630             */
1631            public WikiPage fetchByNodeId_First(long nodeId,
1632                    OrderByComparator orderByComparator) throws SystemException {
1633                    List<WikiPage> list = findByNodeId(nodeId, 0, 1, orderByComparator);
1634    
1635                    if (!list.isEmpty()) {
1636                            return list.get(0);
1637                    }
1638    
1639                    return null;
1640            }
1641    
1642            /**
1643             * Returns the last wiki page in the ordered set where nodeId = &#63;.
1644             *
1645             * @param nodeId the node ID
1646             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1647             * @return the last matching wiki page
1648             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1649             * @throws SystemException if a system exception occurred
1650             */
1651            public WikiPage findByNodeId_Last(long nodeId,
1652                    OrderByComparator orderByComparator)
1653                    throws NoSuchPageException, SystemException {
1654                    WikiPage wikiPage = fetchByNodeId_Last(nodeId, orderByComparator);
1655    
1656                    if (wikiPage != null) {
1657                            return wikiPage;
1658                    }
1659    
1660                    StringBundler msg = new StringBundler(4);
1661    
1662                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1663    
1664                    msg.append("nodeId=");
1665                    msg.append(nodeId);
1666    
1667                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1668    
1669                    throw new NoSuchPageException(msg.toString());
1670            }
1671    
1672            /**
1673             * Returns the last wiki page in the ordered set where nodeId = &#63;.
1674             *
1675             * @param nodeId the node ID
1676             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1677             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
1678             * @throws SystemException if a system exception occurred
1679             */
1680            public WikiPage fetchByNodeId_Last(long nodeId,
1681                    OrderByComparator orderByComparator) throws SystemException {
1682                    int count = countByNodeId(nodeId);
1683    
1684                    List<WikiPage> list = findByNodeId(nodeId, count - 1, count,
1685                                    orderByComparator);
1686    
1687                    if (!list.isEmpty()) {
1688                            return list.get(0);
1689                    }
1690    
1691                    return null;
1692            }
1693    
1694            /**
1695             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63;.
1696             *
1697             * @param pageId the primary key of the current wiki page
1698             * @param nodeId the node ID
1699             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1700             * @return the previous, current, and next wiki page
1701             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
1702             * @throws SystemException if a system exception occurred
1703             */
1704            public WikiPage[] findByNodeId_PrevAndNext(long pageId, long nodeId,
1705                    OrderByComparator orderByComparator)
1706                    throws NoSuchPageException, SystemException {
1707                    WikiPage wikiPage = findByPrimaryKey(pageId);
1708    
1709                    Session session = null;
1710    
1711                    try {
1712                            session = openSession();
1713    
1714                            WikiPage[] array = new WikiPageImpl[3];
1715    
1716                            array[0] = getByNodeId_PrevAndNext(session, wikiPage, nodeId,
1717                                            orderByComparator, true);
1718    
1719                            array[1] = wikiPage;
1720    
1721                            array[2] = getByNodeId_PrevAndNext(session, wikiPage, nodeId,
1722                                            orderByComparator, false);
1723    
1724                            return array;
1725                    }
1726                    catch (Exception e) {
1727                            throw processException(e);
1728                    }
1729                    finally {
1730                            closeSession(session);
1731                    }
1732            }
1733    
1734            protected WikiPage getByNodeId_PrevAndNext(Session session,
1735                    WikiPage wikiPage, long nodeId, OrderByComparator orderByComparator,
1736                    boolean previous) {
1737                    StringBundler query = null;
1738    
1739                    if (orderByComparator != null) {
1740                            query = new StringBundler(6 +
1741                                            (orderByComparator.getOrderByFields().length * 6));
1742                    }
1743                    else {
1744                            query = new StringBundler(3);
1745                    }
1746    
1747                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1748    
1749                    query.append(_FINDER_COLUMN_NODEID_NODEID_2);
1750    
1751                    if (orderByComparator != null) {
1752                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1753    
1754                            if (orderByConditionFields.length > 0) {
1755                                    query.append(WHERE_AND);
1756                            }
1757    
1758                            for (int i = 0; i < orderByConditionFields.length; i++) {
1759                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1760                                    query.append(orderByConditionFields[i]);
1761    
1762                                    if ((i + 1) < orderByConditionFields.length) {
1763                                            if (orderByComparator.isAscending() ^ previous) {
1764                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1765                                            }
1766                                            else {
1767                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1768                                            }
1769                                    }
1770                                    else {
1771                                            if (orderByComparator.isAscending() ^ previous) {
1772                                                    query.append(WHERE_GREATER_THAN);
1773                                            }
1774                                            else {
1775                                                    query.append(WHERE_LESSER_THAN);
1776                                            }
1777                                    }
1778                            }
1779    
1780                            query.append(ORDER_BY_CLAUSE);
1781    
1782                            String[] orderByFields = orderByComparator.getOrderByFields();
1783    
1784                            for (int i = 0; i < orderByFields.length; i++) {
1785                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1786                                    query.append(orderByFields[i]);
1787    
1788                                    if ((i + 1) < orderByFields.length) {
1789                                            if (orderByComparator.isAscending() ^ previous) {
1790                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1791                                            }
1792                                            else {
1793                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1794                                            }
1795                                    }
1796                                    else {
1797                                            if (orderByComparator.isAscending() ^ previous) {
1798                                                    query.append(ORDER_BY_ASC);
1799                                            }
1800                                            else {
1801                                                    query.append(ORDER_BY_DESC);
1802                                            }
1803                                    }
1804                            }
1805                    }
1806                    else {
1807                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1808                    }
1809    
1810                    String sql = query.toString();
1811    
1812                    Query q = session.createQuery(sql);
1813    
1814                    q.setFirstResult(0);
1815                    q.setMaxResults(2);
1816    
1817                    QueryPos qPos = QueryPos.getInstance(q);
1818    
1819                    qPos.add(nodeId);
1820    
1821                    if (orderByComparator != null) {
1822                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
1823    
1824                            for (Object value : values) {
1825                                    qPos.add(value);
1826                            }
1827                    }
1828    
1829                    List<WikiPage> list = q.list();
1830    
1831                    if (list.size() == 2) {
1832                            return list.get(1);
1833                    }
1834                    else {
1835                            return null;
1836                    }
1837            }
1838    
1839            /**
1840             * Removes all the wiki pages where nodeId = &#63; from the database.
1841             *
1842             * @param nodeId the node ID
1843             * @throws SystemException if a system exception occurred
1844             */
1845            public void removeByNodeId(long nodeId) throws SystemException {
1846                    for (WikiPage wikiPage : findByNodeId(nodeId, QueryUtil.ALL_POS,
1847                                    QueryUtil.ALL_POS, null)) {
1848                            remove(wikiPage);
1849                    }
1850            }
1851    
1852            /**
1853             * Returns the number of wiki pages where nodeId = &#63;.
1854             *
1855             * @param nodeId the node ID
1856             * @return the number of matching wiki pages
1857             * @throws SystemException if a system exception occurred
1858             */
1859            public int countByNodeId(long nodeId) throws SystemException {
1860                    FinderPath finderPath = FINDER_PATH_COUNT_BY_NODEID;
1861    
1862                    Object[] finderArgs = new Object[] { nodeId };
1863    
1864                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1865                                    this);
1866    
1867                    if (count == null) {
1868                            StringBundler query = new StringBundler(2);
1869    
1870                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
1871    
1872                            query.append(_FINDER_COLUMN_NODEID_NODEID_2);
1873    
1874                            String sql = query.toString();
1875    
1876                            Session session = null;
1877    
1878                            try {
1879                                    session = openSession();
1880    
1881                                    Query q = session.createQuery(sql);
1882    
1883                                    QueryPos qPos = QueryPos.getInstance(q);
1884    
1885                                    qPos.add(nodeId);
1886    
1887                                    count = (Long)q.uniqueResult();
1888    
1889                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1890                            }
1891                            catch (Exception e) {
1892                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1893    
1894                                    throw processException(e);
1895                            }
1896                            finally {
1897                                    closeSession(session);
1898                            }
1899                    }
1900    
1901                    return count.intValue();
1902            }
1903    
1904            private static final String _FINDER_COLUMN_NODEID_NODEID_2 = "wikiPage.nodeId = ?";
1905            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FORMAT = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1906                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1907                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByFormat",
1908                            new String[] {
1909                                    String.class.getName(),
1910                                    
1911                            Integer.class.getName(), Integer.class.getName(),
1912                                    OrderByComparator.class.getName()
1913                            });
1914            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT =
1915                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1916                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1917                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByFormat",
1918                            new String[] { String.class.getName() },
1919                            WikiPageModelImpl.FORMAT_COLUMN_BITMASK |
1920                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
1921                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
1922                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
1923            public static final FinderPath FINDER_PATH_COUNT_BY_FORMAT = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1924                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1925                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFormat",
1926                            new String[] { String.class.getName() });
1927    
1928            /**
1929             * Returns all the wiki pages where format = &#63;.
1930             *
1931             * @param format the format
1932             * @return the matching wiki pages
1933             * @throws SystemException if a system exception occurred
1934             */
1935            public List<WikiPage> findByFormat(String format) throws SystemException {
1936                    return findByFormat(format, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1937            }
1938    
1939            /**
1940             * Returns a range of all the wiki pages where format = &#63;.
1941             *
1942             * <p>
1943             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1944             * </p>
1945             *
1946             * @param format the format
1947             * @param start the lower bound of the range of wiki pages
1948             * @param end the upper bound of the range of wiki pages (not inclusive)
1949             * @return the range of matching wiki pages
1950             * @throws SystemException if a system exception occurred
1951             */
1952            public List<WikiPage> findByFormat(String format, int start, int end)
1953                    throws SystemException {
1954                    return findByFormat(format, start, end, null);
1955            }
1956    
1957            /**
1958             * Returns an ordered range of all the wiki pages where format = &#63;.
1959             *
1960             * <p>
1961             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1962             * </p>
1963             *
1964             * @param format the format
1965             * @param start the lower bound of the range of wiki pages
1966             * @param end the upper bound of the range of wiki pages (not inclusive)
1967             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1968             * @return the ordered range of matching wiki pages
1969             * @throws SystemException if a system exception occurred
1970             */
1971            public List<WikiPage> findByFormat(String format, int start, int end,
1972                    OrderByComparator orderByComparator) throws SystemException {
1973                    boolean pagination = true;
1974                    FinderPath finderPath = null;
1975                    Object[] finderArgs = null;
1976    
1977                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1978                                    (orderByComparator == null)) {
1979                            pagination = false;
1980                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT;
1981                            finderArgs = new Object[] { format };
1982                    }
1983                    else {
1984                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FORMAT;
1985                            finderArgs = new Object[] { format, start, end, orderByComparator };
1986                    }
1987    
1988                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
1989                                    finderArgs, this);
1990    
1991                    if ((list != null) && !list.isEmpty()) {
1992                            for (WikiPage wikiPage : list) {
1993                                    if (!Validator.equals(format, wikiPage.getFormat())) {
1994                                            list = null;
1995    
1996                                            break;
1997                                    }
1998                            }
1999                    }
2000    
2001                    if (list == null) {
2002                            StringBundler query = null;
2003    
2004                            if (orderByComparator != null) {
2005                                    query = new StringBundler(3 +
2006                                                    (orderByComparator.getOrderByFields().length * 3));
2007                            }
2008                            else {
2009                                    query = new StringBundler(3);
2010                            }
2011    
2012                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2013    
2014                            boolean bindFormat = false;
2015    
2016                            if (format == null) {
2017                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
2018                            }
2019                            else if (format.equals(StringPool.BLANK)) {
2020                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
2021                            }
2022                            else {
2023                                    bindFormat = true;
2024    
2025                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
2026                            }
2027    
2028                            if (orderByComparator != null) {
2029                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2030                                            orderByComparator);
2031                            }
2032                            else
2033                             if (pagination) {
2034                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2035                            }
2036    
2037                            String sql = query.toString();
2038    
2039                            Session session = null;
2040    
2041                            try {
2042                                    session = openSession();
2043    
2044                                    Query q = session.createQuery(sql);
2045    
2046                                    QueryPos qPos = QueryPos.getInstance(q);
2047    
2048                                    if (bindFormat) {
2049                                            qPos.add(format);
2050                                    }
2051    
2052                                    if (!pagination) {
2053                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2054                                                            start, end, false);
2055    
2056                                            Collections.sort(list);
2057    
2058                                            list = new UnmodifiableList<WikiPage>(list);
2059                                    }
2060                                    else {
2061                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2062                                                            start, end);
2063                                    }
2064    
2065                                    cacheResult(list);
2066    
2067                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2068                            }
2069                            catch (Exception e) {
2070                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2071    
2072                                    throw processException(e);
2073                            }
2074                            finally {
2075                                    closeSession(session);
2076                            }
2077                    }
2078    
2079                    return list;
2080            }
2081    
2082            /**
2083             * Returns the first wiki page in the ordered set where format = &#63;.
2084             *
2085             * @param format the format
2086             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2087             * @return the first matching wiki page
2088             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2089             * @throws SystemException if a system exception occurred
2090             */
2091            public WikiPage findByFormat_First(String format,
2092                    OrderByComparator orderByComparator)
2093                    throws NoSuchPageException, SystemException {
2094                    WikiPage wikiPage = fetchByFormat_First(format, orderByComparator);
2095    
2096                    if (wikiPage != null) {
2097                            return wikiPage;
2098                    }
2099    
2100                    StringBundler msg = new StringBundler(4);
2101    
2102                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2103    
2104                    msg.append("format=");
2105                    msg.append(format);
2106    
2107                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2108    
2109                    throw new NoSuchPageException(msg.toString());
2110            }
2111    
2112            /**
2113             * Returns the first wiki page in the ordered set where format = &#63;.
2114             *
2115             * @param format the format
2116             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2117             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
2118             * @throws SystemException if a system exception occurred
2119             */
2120            public WikiPage fetchByFormat_First(String format,
2121                    OrderByComparator orderByComparator) throws SystemException {
2122                    List<WikiPage> list = findByFormat(format, 0, 1, orderByComparator);
2123    
2124                    if (!list.isEmpty()) {
2125                            return list.get(0);
2126                    }
2127    
2128                    return null;
2129            }
2130    
2131            /**
2132             * Returns the last wiki page in the ordered set where format = &#63;.
2133             *
2134             * @param format the format
2135             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2136             * @return the last matching wiki page
2137             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2138             * @throws SystemException if a system exception occurred
2139             */
2140            public WikiPage findByFormat_Last(String format,
2141                    OrderByComparator orderByComparator)
2142                    throws NoSuchPageException, SystemException {
2143                    WikiPage wikiPage = fetchByFormat_Last(format, orderByComparator);
2144    
2145                    if (wikiPage != null) {
2146                            return wikiPage;
2147                    }
2148    
2149                    StringBundler msg = new StringBundler(4);
2150    
2151                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2152    
2153                    msg.append("format=");
2154                    msg.append(format);
2155    
2156                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2157    
2158                    throw new NoSuchPageException(msg.toString());
2159            }
2160    
2161            /**
2162             * Returns the last wiki page in the ordered set where format = &#63;.
2163             *
2164             * @param format the format
2165             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2166             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
2167             * @throws SystemException if a system exception occurred
2168             */
2169            public WikiPage fetchByFormat_Last(String format,
2170                    OrderByComparator orderByComparator) throws SystemException {
2171                    int count = countByFormat(format);
2172    
2173                    List<WikiPage> list = findByFormat(format, count - 1, count,
2174                                    orderByComparator);
2175    
2176                    if (!list.isEmpty()) {
2177                            return list.get(0);
2178                    }
2179    
2180                    return null;
2181            }
2182    
2183            /**
2184             * Returns the wiki pages before and after the current wiki page in the ordered set where format = &#63;.
2185             *
2186             * @param pageId the primary key of the current wiki page
2187             * @param format the format
2188             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2189             * @return the previous, current, and next wiki page
2190             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
2191             * @throws SystemException if a system exception occurred
2192             */
2193            public WikiPage[] findByFormat_PrevAndNext(long pageId, String format,
2194                    OrderByComparator orderByComparator)
2195                    throws NoSuchPageException, SystemException {
2196                    WikiPage wikiPage = findByPrimaryKey(pageId);
2197    
2198                    Session session = null;
2199    
2200                    try {
2201                            session = openSession();
2202    
2203                            WikiPage[] array = new WikiPageImpl[3];
2204    
2205                            array[0] = getByFormat_PrevAndNext(session, wikiPage, format,
2206                                            orderByComparator, true);
2207    
2208                            array[1] = wikiPage;
2209    
2210                            array[2] = getByFormat_PrevAndNext(session, wikiPage, format,
2211                                            orderByComparator, false);
2212    
2213                            return array;
2214                    }
2215                    catch (Exception e) {
2216                            throw processException(e);
2217                    }
2218                    finally {
2219                            closeSession(session);
2220                    }
2221            }
2222    
2223            protected WikiPage getByFormat_PrevAndNext(Session session,
2224                    WikiPage wikiPage, String format, OrderByComparator orderByComparator,
2225                    boolean previous) {
2226                    StringBundler query = null;
2227    
2228                    if (orderByComparator != null) {
2229                            query = new StringBundler(6 +
2230                                            (orderByComparator.getOrderByFields().length * 6));
2231                    }
2232                    else {
2233                            query = new StringBundler(3);
2234                    }
2235    
2236                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2237    
2238                    boolean bindFormat = false;
2239    
2240                    if (format == null) {
2241                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
2242                    }
2243                    else if (format.equals(StringPool.BLANK)) {
2244                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
2245                    }
2246                    else {
2247                            bindFormat = true;
2248    
2249                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
2250                    }
2251    
2252                    if (orderByComparator != null) {
2253                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2254    
2255                            if (orderByConditionFields.length > 0) {
2256                                    query.append(WHERE_AND);
2257                            }
2258    
2259                            for (int i = 0; i < orderByConditionFields.length; i++) {
2260                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2261                                    query.append(orderByConditionFields[i]);
2262    
2263                                    if ((i + 1) < orderByConditionFields.length) {
2264                                            if (orderByComparator.isAscending() ^ previous) {
2265                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2266                                            }
2267                                            else {
2268                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2269                                            }
2270                                    }
2271                                    else {
2272                                            if (orderByComparator.isAscending() ^ previous) {
2273                                                    query.append(WHERE_GREATER_THAN);
2274                                            }
2275                                            else {
2276                                                    query.append(WHERE_LESSER_THAN);
2277                                            }
2278                                    }
2279                            }
2280    
2281                            query.append(ORDER_BY_CLAUSE);
2282    
2283                            String[] orderByFields = orderByComparator.getOrderByFields();
2284    
2285                            for (int i = 0; i < orderByFields.length; i++) {
2286                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2287                                    query.append(orderByFields[i]);
2288    
2289                                    if ((i + 1) < orderByFields.length) {
2290                                            if (orderByComparator.isAscending() ^ previous) {
2291                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2292                                            }
2293                                            else {
2294                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2295                                            }
2296                                    }
2297                                    else {
2298                                            if (orderByComparator.isAscending() ^ previous) {
2299                                                    query.append(ORDER_BY_ASC);
2300                                            }
2301                                            else {
2302                                                    query.append(ORDER_BY_DESC);
2303                                            }
2304                                    }
2305                            }
2306                    }
2307                    else {
2308                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2309                    }
2310    
2311                    String sql = query.toString();
2312    
2313                    Query q = session.createQuery(sql);
2314    
2315                    q.setFirstResult(0);
2316                    q.setMaxResults(2);
2317    
2318                    QueryPos qPos = QueryPos.getInstance(q);
2319    
2320                    if (bindFormat) {
2321                            qPos.add(format);
2322                    }
2323    
2324                    if (orderByComparator != null) {
2325                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
2326    
2327                            for (Object value : values) {
2328                                    qPos.add(value);
2329                            }
2330                    }
2331    
2332                    List<WikiPage> list = q.list();
2333    
2334                    if (list.size() == 2) {
2335                            return list.get(1);
2336                    }
2337                    else {
2338                            return null;
2339                    }
2340            }
2341    
2342            /**
2343             * Removes all the wiki pages where format = &#63; from the database.
2344             *
2345             * @param format the format
2346             * @throws SystemException if a system exception occurred
2347             */
2348            public void removeByFormat(String format) throws SystemException {
2349                    for (WikiPage wikiPage : findByFormat(format, QueryUtil.ALL_POS,
2350                                    QueryUtil.ALL_POS, null)) {
2351                            remove(wikiPage);
2352                    }
2353            }
2354    
2355            /**
2356             * Returns the number of wiki pages where format = &#63;.
2357             *
2358             * @param format the format
2359             * @return the number of matching wiki pages
2360             * @throws SystemException if a system exception occurred
2361             */
2362            public int countByFormat(String format) throws SystemException {
2363                    FinderPath finderPath = FINDER_PATH_COUNT_BY_FORMAT;
2364    
2365                    Object[] finderArgs = new Object[] { format };
2366    
2367                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2368                                    this);
2369    
2370                    if (count == null) {
2371                            StringBundler query = new StringBundler(2);
2372    
2373                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
2374    
2375                            boolean bindFormat = false;
2376    
2377                            if (format == null) {
2378                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
2379                            }
2380                            else if (format.equals(StringPool.BLANK)) {
2381                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
2382                            }
2383                            else {
2384                                    bindFormat = true;
2385    
2386                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
2387                            }
2388    
2389                            String sql = query.toString();
2390    
2391                            Session session = null;
2392    
2393                            try {
2394                                    session = openSession();
2395    
2396                                    Query q = session.createQuery(sql);
2397    
2398                                    QueryPos qPos = QueryPos.getInstance(q);
2399    
2400                                    if (bindFormat) {
2401                                            qPos.add(format);
2402                                    }
2403    
2404                                    count = (Long)q.uniqueResult();
2405    
2406                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2407                            }
2408                            catch (Exception e) {
2409                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2410    
2411                                    throw processException(e);
2412                            }
2413                            finally {
2414                                    closeSession(session);
2415                            }
2416                    }
2417    
2418                    return count.intValue();
2419            }
2420    
2421            private static final String _FINDER_COLUMN_FORMAT_FORMAT_1 = "wikiPage.format IS NULL";
2422            private static final String _FINDER_COLUMN_FORMAT_FORMAT_2 = "wikiPage.format = ?";
2423            private static final String _FINDER_COLUMN_FORMAT_FORMAT_3 = "(wikiPage.format IS NULL OR wikiPage.format = '')";
2424            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2425                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2426                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_N",
2427                            new String[] {
2428                                    Long.class.getName(), Long.class.getName(),
2429                                    
2430                            Integer.class.getName(), Integer.class.getName(),
2431                                    OrderByComparator.class.getName()
2432                            });
2433            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2434                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2435                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_N",
2436                            new String[] { Long.class.getName(), Long.class.getName() },
2437                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
2438                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
2439                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
2440                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
2441            public static final FinderPath FINDER_PATH_COUNT_BY_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2442                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2443                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N",
2444                            new String[] { Long.class.getName(), Long.class.getName() });
2445    
2446            /**
2447             * Returns all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2448             *
2449             * @param resourcePrimKey the resource prim key
2450             * @param nodeId the node ID
2451             * @return the matching wiki pages
2452             * @throws SystemException if a system exception occurred
2453             */
2454            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId)
2455                    throws SystemException {
2456                    return findByR_N(resourcePrimKey, nodeId, QueryUtil.ALL_POS,
2457                            QueryUtil.ALL_POS, null);
2458            }
2459    
2460            /**
2461             * Returns a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2462             *
2463             * <p>
2464             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2465             * </p>
2466             *
2467             * @param resourcePrimKey the resource prim key
2468             * @param nodeId the node ID
2469             * @param start the lower bound of the range of wiki pages
2470             * @param end the upper bound of the range of wiki pages (not inclusive)
2471             * @return the range of matching wiki pages
2472             * @throws SystemException if a system exception occurred
2473             */
2474            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId,
2475                    int start, int end) throws SystemException {
2476                    return findByR_N(resourcePrimKey, nodeId, start, end, null);
2477            }
2478    
2479            /**
2480             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2481             *
2482             * <p>
2483             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2484             * </p>
2485             *
2486             * @param resourcePrimKey the resource prim key
2487             * @param nodeId the node ID
2488             * @param start the lower bound of the range of wiki pages
2489             * @param end the upper bound of the range of wiki pages (not inclusive)
2490             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2491             * @return the ordered range of matching wiki pages
2492             * @throws SystemException if a system exception occurred
2493             */
2494            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId,
2495                    int start, int end, OrderByComparator orderByComparator)
2496                    throws SystemException {
2497                    boolean pagination = true;
2498                    FinderPath finderPath = null;
2499                    Object[] finderArgs = null;
2500    
2501                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2502                                    (orderByComparator == null)) {
2503                            pagination = false;
2504                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N;
2505                            finderArgs = new Object[] { resourcePrimKey, nodeId };
2506                    }
2507                    else {
2508                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N;
2509                            finderArgs = new Object[] {
2510                                            resourcePrimKey, nodeId,
2511                                            
2512                                            start, end, orderByComparator
2513                                    };
2514                    }
2515    
2516                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
2517                                    finderArgs, this);
2518    
2519                    if ((list != null) && !list.isEmpty()) {
2520                            for (WikiPage wikiPage : list) {
2521                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
2522                                                    (nodeId != wikiPage.getNodeId())) {
2523                                            list = null;
2524    
2525                                            break;
2526                                    }
2527                            }
2528                    }
2529    
2530                    if (list == null) {
2531                            StringBundler query = null;
2532    
2533                            if (orderByComparator != null) {
2534                                    query = new StringBundler(4 +
2535                                                    (orderByComparator.getOrderByFields().length * 3));
2536                            }
2537                            else {
2538                                    query = new StringBundler(4);
2539                            }
2540    
2541                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2542    
2543                            query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
2544    
2545                            query.append(_FINDER_COLUMN_R_N_NODEID_2);
2546    
2547                            if (orderByComparator != null) {
2548                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2549                                            orderByComparator);
2550                            }
2551                            else
2552                             if (pagination) {
2553                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2554                            }
2555    
2556                            String sql = query.toString();
2557    
2558                            Session session = null;
2559    
2560                            try {
2561                                    session = openSession();
2562    
2563                                    Query q = session.createQuery(sql);
2564    
2565                                    QueryPos qPos = QueryPos.getInstance(q);
2566    
2567                                    qPos.add(resourcePrimKey);
2568    
2569                                    qPos.add(nodeId);
2570    
2571                                    if (!pagination) {
2572                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2573                                                            start, end, false);
2574    
2575                                            Collections.sort(list);
2576    
2577                                            list = new UnmodifiableList<WikiPage>(list);
2578                                    }
2579                                    else {
2580                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2581                                                            start, end);
2582                                    }
2583    
2584                                    cacheResult(list);
2585    
2586                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2587                            }
2588                            catch (Exception e) {
2589                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2590    
2591                                    throw processException(e);
2592                            }
2593                            finally {
2594                                    closeSession(session);
2595                            }
2596                    }
2597    
2598                    return list;
2599            }
2600    
2601            /**
2602             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2603             *
2604             * @param resourcePrimKey the resource prim key
2605             * @param nodeId the node ID
2606             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2607             * @return the first matching wiki page
2608             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2609             * @throws SystemException if a system exception occurred
2610             */
2611            public WikiPage findByR_N_First(long resourcePrimKey, long nodeId,
2612                    OrderByComparator orderByComparator)
2613                    throws NoSuchPageException, SystemException {
2614                    WikiPage wikiPage = fetchByR_N_First(resourcePrimKey, nodeId,
2615                                    orderByComparator);
2616    
2617                    if (wikiPage != null) {
2618                            return wikiPage;
2619                    }
2620    
2621                    StringBundler msg = new StringBundler(6);
2622    
2623                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2624    
2625                    msg.append("resourcePrimKey=");
2626                    msg.append(resourcePrimKey);
2627    
2628                    msg.append(", nodeId=");
2629                    msg.append(nodeId);
2630    
2631                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2632    
2633                    throw new NoSuchPageException(msg.toString());
2634            }
2635    
2636            /**
2637             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2638             *
2639             * @param resourcePrimKey the resource prim key
2640             * @param nodeId the node ID
2641             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2642             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
2643             * @throws SystemException if a system exception occurred
2644             */
2645            public WikiPage fetchByR_N_First(long resourcePrimKey, long nodeId,
2646                    OrderByComparator orderByComparator) throws SystemException {
2647                    List<WikiPage> list = findByR_N(resourcePrimKey, nodeId, 0, 1,
2648                                    orderByComparator);
2649    
2650                    if (!list.isEmpty()) {
2651                            return list.get(0);
2652                    }
2653    
2654                    return null;
2655            }
2656    
2657            /**
2658             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2659             *
2660             * @param resourcePrimKey the resource prim key
2661             * @param nodeId the node ID
2662             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2663             * @return the last matching wiki page
2664             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2665             * @throws SystemException if a system exception occurred
2666             */
2667            public WikiPage findByR_N_Last(long resourcePrimKey, long nodeId,
2668                    OrderByComparator orderByComparator)
2669                    throws NoSuchPageException, SystemException {
2670                    WikiPage wikiPage = fetchByR_N_Last(resourcePrimKey, nodeId,
2671                                    orderByComparator);
2672    
2673                    if (wikiPage != null) {
2674                            return wikiPage;
2675                    }
2676    
2677                    StringBundler msg = new StringBundler(6);
2678    
2679                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2680    
2681                    msg.append("resourcePrimKey=");
2682                    msg.append(resourcePrimKey);
2683    
2684                    msg.append(", nodeId=");
2685                    msg.append(nodeId);
2686    
2687                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2688    
2689                    throw new NoSuchPageException(msg.toString());
2690            }
2691    
2692            /**
2693             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2694             *
2695             * @param resourcePrimKey the resource prim key
2696             * @param nodeId the node ID
2697             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2698             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
2699             * @throws SystemException if a system exception occurred
2700             */
2701            public WikiPage fetchByR_N_Last(long resourcePrimKey, long nodeId,
2702                    OrderByComparator orderByComparator) throws SystemException {
2703                    int count = countByR_N(resourcePrimKey, nodeId);
2704    
2705                    List<WikiPage> list = findByR_N(resourcePrimKey, nodeId, count - 1,
2706                                    count, orderByComparator);
2707    
2708                    if (!list.isEmpty()) {
2709                            return list.get(0);
2710                    }
2711    
2712                    return null;
2713            }
2714    
2715            /**
2716             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2717             *
2718             * @param pageId the primary key of the current wiki page
2719             * @param resourcePrimKey the resource prim key
2720             * @param nodeId the node ID
2721             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2722             * @return the previous, current, and next wiki page
2723             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
2724             * @throws SystemException if a system exception occurred
2725             */
2726            public WikiPage[] findByR_N_PrevAndNext(long pageId, long resourcePrimKey,
2727                    long nodeId, OrderByComparator orderByComparator)
2728                    throws NoSuchPageException, SystemException {
2729                    WikiPage wikiPage = findByPrimaryKey(pageId);
2730    
2731                    Session session = null;
2732    
2733                    try {
2734                            session = openSession();
2735    
2736                            WikiPage[] array = new WikiPageImpl[3];
2737    
2738                            array[0] = getByR_N_PrevAndNext(session, wikiPage, resourcePrimKey,
2739                                            nodeId, orderByComparator, true);
2740    
2741                            array[1] = wikiPage;
2742    
2743                            array[2] = getByR_N_PrevAndNext(session, wikiPage, resourcePrimKey,
2744                                            nodeId, orderByComparator, false);
2745    
2746                            return array;
2747                    }
2748                    catch (Exception e) {
2749                            throw processException(e);
2750                    }
2751                    finally {
2752                            closeSession(session);
2753                    }
2754            }
2755    
2756            protected WikiPage getByR_N_PrevAndNext(Session session, WikiPage wikiPage,
2757                    long resourcePrimKey, long nodeId, OrderByComparator orderByComparator,
2758                    boolean previous) {
2759                    StringBundler query = null;
2760    
2761                    if (orderByComparator != null) {
2762                            query = new StringBundler(6 +
2763                                            (orderByComparator.getOrderByFields().length * 6));
2764                    }
2765                    else {
2766                            query = new StringBundler(3);
2767                    }
2768    
2769                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2770    
2771                    query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
2772    
2773                    query.append(_FINDER_COLUMN_R_N_NODEID_2);
2774    
2775                    if (orderByComparator != null) {
2776                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2777    
2778                            if (orderByConditionFields.length > 0) {
2779                                    query.append(WHERE_AND);
2780                            }
2781    
2782                            for (int i = 0; i < orderByConditionFields.length; i++) {
2783                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2784                                    query.append(orderByConditionFields[i]);
2785    
2786                                    if ((i + 1) < orderByConditionFields.length) {
2787                                            if (orderByComparator.isAscending() ^ previous) {
2788                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2789                                            }
2790                                            else {
2791                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2792                                            }
2793                                    }
2794                                    else {
2795                                            if (orderByComparator.isAscending() ^ previous) {
2796                                                    query.append(WHERE_GREATER_THAN);
2797                                            }
2798                                            else {
2799                                                    query.append(WHERE_LESSER_THAN);
2800                                            }
2801                                    }
2802                            }
2803    
2804                            query.append(ORDER_BY_CLAUSE);
2805    
2806                            String[] orderByFields = orderByComparator.getOrderByFields();
2807    
2808                            for (int i = 0; i < orderByFields.length; i++) {
2809                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2810                                    query.append(orderByFields[i]);
2811    
2812                                    if ((i + 1) < orderByFields.length) {
2813                                            if (orderByComparator.isAscending() ^ previous) {
2814                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2815                                            }
2816                                            else {
2817                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2818                                            }
2819                                    }
2820                                    else {
2821                                            if (orderByComparator.isAscending() ^ previous) {
2822                                                    query.append(ORDER_BY_ASC);
2823                                            }
2824                                            else {
2825                                                    query.append(ORDER_BY_DESC);
2826                                            }
2827                                    }
2828                            }
2829                    }
2830                    else {
2831                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2832                    }
2833    
2834                    String sql = query.toString();
2835    
2836                    Query q = session.createQuery(sql);
2837    
2838                    q.setFirstResult(0);
2839                    q.setMaxResults(2);
2840    
2841                    QueryPos qPos = QueryPos.getInstance(q);
2842    
2843                    qPos.add(resourcePrimKey);
2844    
2845                    qPos.add(nodeId);
2846    
2847                    if (orderByComparator != null) {
2848                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
2849    
2850                            for (Object value : values) {
2851                                    qPos.add(value);
2852                            }
2853                    }
2854    
2855                    List<WikiPage> list = q.list();
2856    
2857                    if (list.size() == 2) {
2858                            return list.get(1);
2859                    }
2860                    else {
2861                            return null;
2862                    }
2863            }
2864    
2865            /**
2866             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; from the database.
2867             *
2868             * @param resourcePrimKey the resource prim key
2869             * @param nodeId the node ID
2870             * @throws SystemException if a system exception occurred
2871             */
2872            public void removeByR_N(long resourcePrimKey, long nodeId)
2873                    throws SystemException {
2874                    for (WikiPage wikiPage : findByR_N(resourcePrimKey, nodeId,
2875                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2876                            remove(wikiPage);
2877                    }
2878            }
2879    
2880            /**
2881             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2882             *
2883             * @param resourcePrimKey the resource prim key
2884             * @param nodeId the node ID
2885             * @return the number of matching wiki pages
2886             * @throws SystemException if a system exception occurred
2887             */
2888            public int countByR_N(long resourcePrimKey, long nodeId)
2889                    throws SystemException {
2890                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N;
2891    
2892                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId };
2893    
2894                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2895                                    this);
2896    
2897                    if (count == null) {
2898                            StringBundler query = new StringBundler(3);
2899    
2900                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
2901    
2902                            query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
2903    
2904                            query.append(_FINDER_COLUMN_R_N_NODEID_2);
2905    
2906                            String sql = query.toString();
2907    
2908                            Session session = null;
2909    
2910                            try {
2911                                    session = openSession();
2912    
2913                                    Query q = session.createQuery(sql);
2914    
2915                                    QueryPos qPos = QueryPos.getInstance(q);
2916    
2917                                    qPos.add(resourcePrimKey);
2918    
2919                                    qPos.add(nodeId);
2920    
2921                                    count = (Long)q.uniqueResult();
2922    
2923                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2924                            }
2925                            catch (Exception e) {
2926                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2927    
2928                                    throw processException(e);
2929                            }
2930                            finally {
2931                                    closeSession(session);
2932                            }
2933                    }
2934    
2935                    return count.intValue();
2936            }
2937    
2938            private static final String _FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
2939            private static final String _FINDER_COLUMN_R_N_NODEID_2 = "wikiPage.nodeId = ?";
2940            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2941                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2942                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_T",
2943                            new String[] {
2944                                    Long.class.getName(), String.class.getName(),
2945                                    
2946                            Integer.class.getName(), Integer.class.getName(),
2947                                    OrderByComparator.class.getName()
2948                            });
2949            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2950                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2951                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_T",
2952                            new String[] { Long.class.getName(), String.class.getName() },
2953                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
2954                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
2955                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
2956            public static final FinderPath FINDER_PATH_COUNT_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2957                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2958                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T",
2959                            new String[] { Long.class.getName(), String.class.getName() });
2960    
2961            /**
2962             * Returns all the wiki pages where nodeId = &#63; and title = &#63;.
2963             *
2964             * @param nodeId the node ID
2965             * @param title the title
2966             * @return the matching wiki pages
2967             * @throws SystemException if a system exception occurred
2968             */
2969            public List<WikiPage> findByN_T(long nodeId, String title)
2970                    throws SystemException {
2971                    return findByN_T(nodeId, title, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2972                            null);
2973            }
2974    
2975            /**
2976             * Returns a range of all the wiki pages where nodeId = &#63; and title = &#63;.
2977             *
2978             * <p>
2979             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2980             * </p>
2981             *
2982             * @param nodeId the node ID
2983             * @param title the title
2984             * @param start the lower bound of the range of wiki pages
2985             * @param end the upper bound of the range of wiki pages (not inclusive)
2986             * @return the range of matching wiki pages
2987             * @throws SystemException if a system exception occurred
2988             */
2989            public List<WikiPage> findByN_T(long nodeId, String title, int start,
2990                    int end) throws SystemException {
2991                    return findByN_T(nodeId, title, start, end, null);
2992            }
2993    
2994            /**
2995             * Returns an ordered range of all the wiki pages where nodeId = &#63; and title = &#63;.
2996             *
2997             * <p>
2998             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2999             * </p>
3000             *
3001             * @param nodeId the node ID
3002             * @param title the title
3003             * @param start the lower bound of the range of wiki pages
3004             * @param end the upper bound of the range of wiki pages (not inclusive)
3005             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3006             * @return the ordered range of matching wiki pages
3007             * @throws SystemException if a system exception occurred
3008             */
3009            public List<WikiPage> findByN_T(long nodeId, String title, int start,
3010                    int end, OrderByComparator orderByComparator) throws SystemException {
3011                    boolean pagination = true;
3012                    FinderPath finderPath = null;
3013                    Object[] finderArgs = null;
3014    
3015                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3016                                    (orderByComparator == null)) {
3017                            pagination = false;
3018                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T;
3019                            finderArgs = new Object[] { nodeId, title };
3020                    }
3021                    else {
3022                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T;
3023                            finderArgs = new Object[] {
3024                                            nodeId, title,
3025                                            
3026                                            start, end, orderByComparator
3027                                    };
3028                    }
3029    
3030                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
3031                                    finderArgs, this);
3032    
3033                    if ((list != null) && !list.isEmpty()) {
3034                            for (WikiPage wikiPage : list) {
3035                                    if ((nodeId != wikiPage.getNodeId()) ||
3036                                                    !Validator.equals(title, wikiPage.getTitle())) {
3037                                            list = null;
3038    
3039                                            break;
3040                                    }
3041                            }
3042                    }
3043    
3044                    if (list == null) {
3045                            StringBundler query = null;
3046    
3047                            if (orderByComparator != null) {
3048                                    query = new StringBundler(4 +
3049                                                    (orderByComparator.getOrderByFields().length * 3));
3050                            }
3051                            else {
3052                                    query = new StringBundler(4);
3053                            }
3054    
3055                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3056    
3057                            query.append(_FINDER_COLUMN_N_T_NODEID_2);
3058    
3059                            boolean bindTitle = false;
3060    
3061                            if (title == null) {
3062                                    query.append(_FINDER_COLUMN_N_T_TITLE_1);
3063                            }
3064                            else if (title.equals(StringPool.BLANK)) {
3065                                    query.append(_FINDER_COLUMN_N_T_TITLE_3);
3066                            }
3067                            else {
3068                                    bindTitle = true;
3069    
3070                                    query.append(_FINDER_COLUMN_N_T_TITLE_2);
3071                            }
3072    
3073                            if (orderByComparator != null) {
3074                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3075                                            orderByComparator);
3076                            }
3077                            else
3078                             if (pagination) {
3079                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3080                            }
3081    
3082                            String sql = query.toString();
3083    
3084                            Session session = null;
3085    
3086                            try {
3087                                    session = openSession();
3088    
3089                                    Query q = session.createQuery(sql);
3090    
3091                                    QueryPos qPos = QueryPos.getInstance(q);
3092    
3093                                    qPos.add(nodeId);
3094    
3095                                    if (bindTitle) {
3096                                            qPos.add(title.toLowerCase());
3097                                    }
3098    
3099                                    if (!pagination) {
3100                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3101                                                            start, end, false);
3102    
3103                                            Collections.sort(list);
3104    
3105                                            list = new UnmodifiableList<WikiPage>(list);
3106                                    }
3107                                    else {
3108                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3109                                                            start, end);
3110                                    }
3111    
3112                                    cacheResult(list);
3113    
3114                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3115                            }
3116                            catch (Exception e) {
3117                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3118    
3119                                    throw processException(e);
3120                            }
3121                            finally {
3122                                    closeSession(session);
3123                            }
3124                    }
3125    
3126                    return list;
3127            }
3128    
3129            /**
3130             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3131             *
3132             * @param nodeId the node ID
3133             * @param title the title
3134             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3135             * @return the first matching wiki page
3136             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3137             * @throws SystemException if a system exception occurred
3138             */
3139            public WikiPage findByN_T_First(long nodeId, String title,
3140                    OrderByComparator orderByComparator)
3141                    throws NoSuchPageException, SystemException {
3142                    WikiPage wikiPage = fetchByN_T_First(nodeId, title, orderByComparator);
3143    
3144                    if (wikiPage != null) {
3145                            return wikiPage;
3146                    }
3147    
3148                    StringBundler msg = new StringBundler(6);
3149    
3150                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3151    
3152                    msg.append("nodeId=");
3153                    msg.append(nodeId);
3154    
3155                    msg.append(", title=");
3156                    msg.append(title);
3157    
3158                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3159    
3160                    throw new NoSuchPageException(msg.toString());
3161            }
3162    
3163            /**
3164             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3165             *
3166             * @param nodeId the node ID
3167             * @param title the title
3168             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3169             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
3170             * @throws SystemException if a system exception occurred
3171             */
3172            public WikiPage fetchByN_T_First(long nodeId, String title,
3173                    OrderByComparator orderByComparator) throws SystemException {
3174                    List<WikiPage> list = findByN_T(nodeId, title, 0, 1, orderByComparator);
3175    
3176                    if (!list.isEmpty()) {
3177                            return list.get(0);
3178                    }
3179    
3180                    return null;
3181            }
3182    
3183            /**
3184             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3185             *
3186             * @param nodeId the node ID
3187             * @param title the title
3188             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3189             * @return the last matching wiki page
3190             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3191             * @throws SystemException if a system exception occurred
3192             */
3193            public WikiPage findByN_T_Last(long nodeId, String title,
3194                    OrderByComparator orderByComparator)
3195                    throws NoSuchPageException, SystemException {
3196                    WikiPage wikiPage = fetchByN_T_Last(nodeId, title, orderByComparator);
3197    
3198                    if (wikiPage != null) {
3199                            return wikiPage;
3200                    }
3201    
3202                    StringBundler msg = new StringBundler(6);
3203    
3204                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3205    
3206                    msg.append("nodeId=");
3207                    msg.append(nodeId);
3208    
3209                    msg.append(", title=");
3210                    msg.append(title);
3211    
3212                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3213    
3214                    throw new NoSuchPageException(msg.toString());
3215            }
3216    
3217            /**
3218             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3219             *
3220             * @param nodeId the node ID
3221             * @param title the title
3222             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3223             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
3224             * @throws SystemException if a system exception occurred
3225             */
3226            public WikiPage fetchByN_T_Last(long nodeId, String title,
3227                    OrderByComparator orderByComparator) throws SystemException {
3228                    int count = countByN_T(nodeId, title);
3229    
3230                    List<WikiPage> list = findByN_T(nodeId, title, count - 1, count,
3231                                    orderByComparator);
3232    
3233                    if (!list.isEmpty()) {
3234                            return list.get(0);
3235                    }
3236    
3237                    return null;
3238            }
3239    
3240            /**
3241             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3242             *
3243             * @param pageId the primary key of the current wiki page
3244             * @param nodeId the node ID
3245             * @param title the title
3246             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3247             * @return the previous, current, and next wiki page
3248             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
3249             * @throws SystemException if a system exception occurred
3250             */
3251            public WikiPage[] findByN_T_PrevAndNext(long pageId, long nodeId,
3252                    String title, OrderByComparator orderByComparator)
3253                    throws NoSuchPageException, SystemException {
3254                    WikiPage wikiPage = findByPrimaryKey(pageId);
3255    
3256                    Session session = null;
3257    
3258                    try {
3259                            session = openSession();
3260    
3261                            WikiPage[] array = new WikiPageImpl[3];
3262    
3263                            array[0] = getByN_T_PrevAndNext(session, wikiPage, nodeId, title,
3264                                            orderByComparator, true);
3265    
3266                            array[1] = wikiPage;
3267    
3268                            array[2] = getByN_T_PrevAndNext(session, wikiPage, nodeId, title,
3269                                            orderByComparator, false);
3270    
3271                            return array;
3272                    }
3273                    catch (Exception e) {
3274                            throw processException(e);
3275                    }
3276                    finally {
3277                            closeSession(session);
3278                    }
3279            }
3280    
3281            protected WikiPage getByN_T_PrevAndNext(Session session, WikiPage wikiPage,
3282                    long nodeId, String title, OrderByComparator orderByComparator,
3283                    boolean previous) {
3284                    StringBundler query = null;
3285    
3286                    if (orderByComparator != null) {
3287                            query = new StringBundler(6 +
3288                                            (orderByComparator.getOrderByFields().length * 6));
3289                    }
3290                    else {
3291                            query = new StringBundler(3);
3292                    }
3293    
3294                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3295    
3296                    query.append(_FINDER_COLUMN_N_T_NODEID_2);
3297    
3298                    boolean bindTitle = false;
3299    
3300                    if (title == null) {
3301                            query.append(_FINDER_COLUMN_N_T_TITLE_1);
3302                    }
3303                    else if (title.equals(StringPool.BLANK)) {
3304                            query.append(_FINDER_COLUMN_N_T_TITLE_3);
3305                    }
3306                    else {
3307                            bindTitle = true;
3308    
3309                            query.append(_FINDER_COLUMN_N_T_TITLE_2);
3310                    }
3311    
3312                    if (orderByComparator != null) {
3313                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3314    
3315                            if (orderByConditionFields.length > 0) {
3316                                    query.append(WHERE_AND);
3317                            }
3318    
3319                            for (int i = 0; i < orderByConditionFields.length; i++) {
3320                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3321                                    query.append(orderByConditionFields[i]);
3322    
3323                                    if ((i + 1) < orderByConditionFields.length) {
3324                                            if (orderByComparator.isAscending() ^ previous) {
3325                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3326                                            }
3327                                            else {
3328                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3329                                            }
3330                                    }
3331                                    else {
3332                                            if (orderByComparator.isAscending() ^ previous) {
3333                                                    query.append(WHERE_GREATER_THAN);
3334                                            }
3335                                            else {
3336                                                    query.append(WHERE_LESSER_THAN);
3337                                            }
3338                                    }
3339                            }
3340    
3341                            query.append(ORDER_BY_CLAUSE);
3342    
3343                            String[] orderByFields = orderByComparator.getOrderByFields();
3344    
3345                            for (int i = 0; i < orderByFields.length; i++) {
3346                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3347                                    query.append(orderByFields[i]);
3348    
3349                                    if ((i + 1) < orderByFields.length) {
3350                                            if (orderByComparator.isAscending() ^ previous) {
3351                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3352                                            }
3353                                            else {
3354                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3355                                            }
3356                                    }
3357                                    else {
3358                                            if (orderByComparator.isAscending() ^ previous) {
3359                                                    query.append(ORDER_BY_ASC);
3360                                            }
3361                                            else {
3362                                                    query.append(ORDER_BY_DESC);
3363                                            }
3364                                    }
3365                            }
3366                    }
3367                    else {
3368                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3369                    }
3370    
3371                    String sql = query.toString();
3372    
3373                    Query q = session.createQuery(sql);
3374    
3375                    q.setFirstResult(0);
3376                    q.setMaxResults(2);
3377    
3378                    QueryPos qPos = QueryPos.getInstance(q);
3379    
3380                    qPos.add(nodeId);
3381    
3382                    if (bindTitle) {
3383                            qPos.add(title.toLowerCase());
3384                    }
3385    
3386                    if (orderByComparator != null) {
3387                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
3388    
3389                            for (Object value : values) {
3390                                    qPos.add(value);
3391                            }
3392                    }
3393    
3394                    List<WikiPage> list = q.list();
3395    
3396                    if (list.size() == 2) {
3397                            return list.get(1);
3398                    }
3399                    else {
3400                            return null;
3401                    }
3402            }
3403    
3404            /**
3405             * Removes all the wiki pages where nodeId = &#63; and title = &#63; from the database.
3406             *
3407             * @param nodeId the node ID
3408             * @param title the title
3409             * @throws SystemException if a system exception occurred
3410             */
3411            public void removeByN_T(long nodeId, String title)
3412                    throws SystemException {
3413                    for (WikiPage wikiPage : findByN_T(nodeId, title, QueryUtil.ALL_POS,
3414                                    QueryUtil.ALL_POS, null)) {
3415                            remove(wikiPage);
3416                    }
3417            }
3418    
3419            /**
3420             * Returns the number of wiki pages where nodeId = &#63; and title = &#63;.
3421             *
3422             * @param nodeId the node ID
3423             * @param title the title
3424             * @return the number of matching wiki pages
3425             * @throws SystemException if a system exception occurred
3426             */
3427            public int countByN_T(long nodeId, String title) throws SystemException {
3428                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T;
3429    
3430                    Object[] finderArgs = new Object[] { nodeId, title };
3431    
3432                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3433                                    this);
3434    
3435                    if (count == null) {
3436                            StringBundler query = new StringBundler(3);
3437    
3438                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
3439    
3440                            query.append(_FINDER_COLUMN_N_T_NODEID_2);
3441    
3442                            boolean bindTitle = false;
3443    
3444                            if (title == null) {
3445                                    query.append(_FINDER_COLUMN_N_T_TITLE_1);
3446                            }
3447                            else if (title.equals(StringPool.BLANK)) {
3448                                    query.append(_FINDER_COLUMN_N_T_TITLE_3);
3449                            }
3450                            else {
3451                                    bindTitle = true;
3452    
3453                                    query.append(_FINDER_COLUMN_N_T_TITLE_2);
3454                            }
3455    
3456                            String sql = query.toString();
3457    
3458                            Session session = null;
3459    
3460                            try {
3461                                    session = openSession();
3462    
3463                                    Query q = session.createQuery(sql);
3464    
3465                                    QueryPos qPos = QueryPos.getInstance(q);
3466    
3467                                    qPos.add(nodeId);
3468    
3469                                    if (bindTitle) {
3470                                            qPos.add(title.toLowerCase());
3471                                    }
3472    
3473                                    count = (Long)q.uniqueResult();
3474    
3475                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3476                            }
3477                            catch (Exception e) {
3478                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3479    
3480                                    throw processException(e);
3481                            }
3482                            finally {
3483                                    closeSession(session);
3484                            }
3485                    }
3486    
3487                    return count.intValue();
3488            }
3489    
3490            private static final String _FINDER_COLUMN_N_T_NODEID_2 = "wikiPage.nodeId = ? AND ";
3491            private static final String _FINDER_COLUMN_N_T_TITLE_1 = "wikiPage.title IS NULL";
3492            private static final String _FINDER_COLUMN_N_T_TITLE_2 = "lower(wikiPage.title) = ?";
3493            private static final String _FINDER_COLUMN_N_T_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '')";
3494            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3495                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
3496                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H",
3497                            new String[] {
3498                                    Long.class.getName(), Boolean.class.getName(),
3499                                    
3500                            Integer.class.getName(), Integer.class.getName(),
3501                                    OrderByComparator.class.getName()
3502                            });
3503            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3504                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
3505                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H",
3506                            new String[] { Long.class.getName(), Boolean.class.getName() },
3507                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
3508                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
3509                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
3510                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
3511            public static final FinderPath FINDER_PATH_COUNT_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3512                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3513                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H",
3514                            new String[] { Long.class.getName(), Boolean.class.getName() });
3515    
3516            /**
3517             * Returns all the wiki pages where nodeId = &#63; and head = &#63;.
3518             *
3519             * @param nodeId the node ID
3520             * @param head the head
3521             * @return the matching wiki pages
3522             * @throws SystemException if a system exception occurred
3523             */
3524            public List<WikiPage> findByN_H(long nodeId, boolean head)
3525                    throws SystemException {
3526                    return findByN_H(nodeId, head, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3527                            null);
3528            }
3529    
3530            /**
3531             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63;.
3532             *
3533             * <p>
3534             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3535             * </p>
3536             *
3537             * @param nodeId the node ID
3538             * @param head the head
3539             * @param start the lower bound of the range of wiki pages
3540             * @param end the upper bound of the range of wiki pages (not inclusive)
3541             * @return the range of matching wiki pages
3542             * @throws SystemException if a system exception occurred
3543             */
3544            public List<WikiPage> findByN_H(long nodeId, boolean head, int start,
3545                    int end) throws SystemException {
3546                    return findByN_H(nodeId, head, start, end, null);
3547            }
3548    
3549            /**
3550             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63;.
3551             *
3552             * <p>
3553             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3554             * </p>
3555             *
3556             * @param nodeId the node ID
3557             * @param head the head
3558             * @param start the lower bound of the range of wiki pages
3559             * @param end the upper bound of the range of wiki pages (not inclusive)
3560             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3561             * @return the ordered range of matching wiki pages
3562             * @throws SystemException if a system exception occurred
3563             */
3564            public List<WikiPage> findByN_H(long nodeId, boolean head, int start,
3565                    int end, OrderByComparator orderByComparator) throws SystemException {
3566                    boolean pagination = true;
3567                    FinderPath finderPath = null;
3568                    Object[] finderArgs = null;
3569    
3570                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3571                                    (orderByComparator == null)) {
3572                            pagination = false;
3573                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H;
3574                            finderArgs = new Object[] { nodeId, head };
3575                    }
3576                    else {
3577                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H;
3578                            finderArgs = new Object[] {
3579                                            nodeId, head,
3580                                            
3581                                            start, end, orderByComparator
3582                                    };
3583                    }
3584    
3585                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
3586                                    finderArgs, this);
3587    
3588                    if ((list != null) && !list.isEmpty()) {
3589                            for (WikiPage wikiPage : list) {
3590                                    if ((nodeId != wikiPage.getNodeId()) ||
3591                                                    (head != wikiPage.getHead())) {
3592                                            list = null;
3593    
3594                                            break;
3595                                    }
3596                            }
3597                    }
3598    
3599                    if (list == null) {
3600                            StringBundler query = null;
3601    
3602                            if (orderByComparator != null) {
3603                                    query = new StringBundler(4 +
3604                                                    (orderByComparator.getOrderByFields().length * 3));
3605                            }
3606                            else {
3607                                    query = new StringBundler(4);
3608                            }
3609    
3610                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3611    
3612                            query.append(_FINDER_COLUMN_N_H_NODEID_2);
3613    
3614                            query.append(_FINDER_COLUMN_N_H_HEAD_2);
3615    
3616                            if (orderByComparator != null) {
3617                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3618                                            orderByComparator);
3619                            }
3620                            else
3621                             if (pagination) {
3622                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3623                            }
3624    
3625                            String sql = query.toString();
3626    
3627                            Session session = null;
3628    
3629                            try {
3630                                    session = openSession();
3631    
3632                                    Query q = session.createQuery(sql);
3633    
3634                                    QueryPos qPos = QueryPos.getInstance(q);
3635    
3636                                    qPos.add(nodeId);
3637    
3638                                    qPos.add(head);
3639    
3640                                    if (!pagination) {
3641                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3642                                                            start, end, false);
3643    
3644                                            Collections.sort(list);
3645    
3646                                            list = new UnmodifiableList<WikiPage>(list);
3647                                    }
3648                                    else {
3649                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3650                                                            start, end);
3651                                    }
3652    
3653                                    cacheResult(list);
3654    
3655                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3656                            }
3657                            catch (Exception e) {
3658                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3659    
3660                                    throw processException(e);
3661                            }
3662                            finally {
3663                                    closeSession(session);
3664                            }
3665                    }
3666    
3667                    return list;
3668            }
3669    
3670            /**
3671             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3672             *
3673             * @param nodeId the node ID
3674             * @param head the head
3675             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3676             * @return the first matching wiki page
3677             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3678             * @throws SystemException if a system exception occurred
3679             */
3680            public WikiPage findByN_H_First(long nodeId, boolean head,
3681                    OrderByComparator orderByComparator)
3682                    throws NoSuchPageException, SystemException {
3683                    WikiPage wikiPage = fetchByN_H_First(nodeId, head, orderByComparator);
3684    
3685                    if (wikiPage != null) {
3686                            return wikiPage;
3687                    }
3688    
3689                    StringBundler msg = new StringBundler(6);
3690    
3691                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3692    
3693                    msg.append("nodeId=");
3694                    msg.append(nodeId);
3695    
3696                    msg.append(", head=");
3697                    msg.append(head);
3698    
3699                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3700    
3701                    throw new NoSuchPageException(msg.toString());
3702            }
3703    
3704            /**
3705             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3706             *
3707             * @param nodeId the node ID
3708             * @param head the head
3709             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3710             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
3711             * @throws SystemException if a system exception occurred
3712             */
3713            public WikiPage fetchByN_H_First(long nodeId, boolean head,
3714                    OrderByComparator orderByComparator) throws SystemException {
3715                    List<WikiPage> list = findByN_H(nodeId, head, 0, 1, orderByComparator);
3716    
3717                    if (!list.isEmpty()) {
3718                            return list.get(0);
3719                    }
3720    
3721                    return null;
3722            }
3723    
3724            /**
3725             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3726             *
3727             * @param nodeId the node ID
3728             * @param head the head
3729             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3730             * @return the last matching wiki page
3731             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3732             * @throws SystemException if a system exception occurred
3733             */
3734            public WikiPage findByN_H_Last(long nodeId, boolean head,
3735                    OrderByComparator orderByComparator)
3736                    throws NoSuchPageException, SystemException {
3737                    WikiPage wikiPage = fetchByN_H_Last(nodeId, head, orderByComparator);
3738    
3739                    if (wikiPage != null) {
3740                            return wikiPage;
3741                    }
3742    
3743                    StringBundler msg = new StringBundler(6);
3744    
3745                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3746    
3747                    msg.append("nodeId=");
3748                    msg.append(nodeId);
3749    
3750                    msg.append(", head=");
3751                    msg.append(head);
3752    
3753                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3754    
3755                    throw new NoSuchPageException(msg.toString());
3756            }
3757    
3758            /**
3759             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3760             *
3761             * @param nodeId the node ID
3762             * @param head the head
3763             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3764             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
3765             * @throws SystemException if a system exception occurred
3766             */
3767            public WikiPage fetchByN_H_Last(long nodeId, boolean head,
3768                    OrderByComparator orderByComparator) throws SystemException {
3769                    int count = countByN_H(nodeId, head);
3770    
3771                    List<WikiPage> list = findByN_H(nodeId, head, count - 1, count,
3772                                    orderByComparator);
3773    
3774                    if (!list.isEmpty()) {
3775                            return list.get(0);
3776                    }
3777    
3778                    return null;
3779            }
3780    
3781            /**
3782             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3783             *
3784             * @param pageId the primary key of the current wiki page
3785             * @param nodeId the node ID
3786             * @param head the head
3787             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3788             * @return the previous, current, and next wiki page
3789             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
3790             * @throws SystemException if a system exception occurred
3791             */
3792            public WikiPage[] findByN_H_PrevAndNext(long pageId, long nodeId,
3793                    boolean head, OrderByComparator orderByComparator)
3794                    throws NoSuchPageException, SystemException {
3795                    WikiPage wikiPage = findByPrimaryKey(pageId);
3796    
3797                    Session session = null;
3798    
3799                    try {
3800                            session = openSession();
3801    
3802                            WikiPage[] array = new WikiPageImpl[3];
3803    
3804                            array[0] = getByN_H_PrevAndNext(session, wikiPage, nodeId, head,
3805                                            orderByComparator, true);
3806    
3807                            array[1] = wikiPage;
3808    
3809                            array[2] = getByN_H_PrevAndNext(session, wikiPage, nodeId, head,
3810                                            orderByComparator, false);
3811    
3812                            return array;
3813                    }
3814                    catch (Exception e) {
3815                            throw processException(e);
3816                    }
3817                    finally {
3818                            closeSession(session);
3819                    }
3820            }
3821    
3822            protected WikiPage getByN_H_PrevAndNext(Session session, WikiPage wikiPage,
3823                    long nodeId, boolean head, OrderByComparator orderByComparator,
3824                    boolean previous) {
3825                    StringBundler query = null;
3826    
3827                    if (orderByComparator != null) {
3828                            query = new StringBundler(6 +
3829                                            (orderByComparator.getOrderByFields().length * 6));
3830                    }
3831                    else {
3832                            query = new StringBundler(3);
3833                    }
3834    
3835                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3836    
3837                    query.append(_FINDER_COLUMN_N_H_NODEID_2);
3838    
3839                    query.append(_FINDER_COLUMN_N_H_HEAD_2);
3840    
3841                    if (orderByComparator != null) {
3842                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3843    
3844                            if (orderByConditionFields.length > 0) {
3845                                    query.append(WHERE_AND);
3846                            }
3847    
3848                            for (int i = 0; i < orderByConditionFields.length; i++) {
3849                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3850                                    query.append(orderByConditionFields[i]);
3851    
3852                                    if ((i + 1) < orderByConditionFields.length) {
3853                                            if (orderByComparator.isAscending() ^ previous) {
3854                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3855                                            }
3856                                            else {
3857                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3858                                            }
3859                                    }
3860                                    else {
3861                                            if (orderByComparator.isAscending() ^ previous) {
3862                                                    query.append(WHERE_GREATER_THAN);
3863                                            }
3864                                            else {
3865                                                    query.append(WHERE_LESSER_THAN);
3866                                            }
3867                                    }
3868                            }
3869    
3870                            query.append(ORDER_BY_CLAUSE);
3871    
3872                            String[] orderByFields = orderByComparator.getOrderByFields();
3873    
3874                            for (int i = 0; i < orderByFields.length; i++) {
3875                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3876                                    query.append(orderByFields[i]);
3877    
3878                                    if ((i + 1) < orderByFields.length) {
3879                                            if (orderByComparator.isAscending() ^ previous) {
3880                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3881                                            }
3882                                            else {
3883                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3884                                            }
3885                                    }
3886                                    else {
3887                                            if (orderByComparator.isAscending() ^ previous) {
3888                                                    query.append(ORDER_BY_ASC);
3889                                            }
3890                                            else {
3891                                                    query.append(ORDER_BY_DESC);
3892                                            }
3893                                    }
3894                            }
3895                    }
3896                    else {
3897                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3898                    }
3899    
3900                    String sql = query.toString();
3901    
3902                    Query q = session.createQuery(sql);
3903    
3904                    q.setFirstResult(0);
3905                    q.setMaxResults(2);
3906    
3907                    QueryPos qPos = QueryPos.getInstance(q);
3908    
3909                    qPos.add(nodeId);
3910    
3911                    qPos.add(head);
3912    
3913                    if (orderByComparator != null) {
3914                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
3915    
3916                            for (Object value : values) {
3917                                    qPos.add(value);
3918                            }
3919                    }
3920    
3921                    List<WikiPage> list = q.list();
3922    
3923                    if (list.size() == 2) {
3924                            return list.get(1);
3925                    }
3926                    else {
3927                            return null;
3928                    }
3929            }
3930    
3931            /**
3932             * Removes all the wiki pages where nodeId = &#63; and head = &#63; from the database.
3933             *
3934             * @param nodeId the node ID
3935             * @param head the head
3936             * @throws SystemException if a system exception occurred
3937             */
3938            public void removeByN_H(long nodeId, boolean head)
3939                    throws SystemException {
3940                    for (WikiPage wikiPage : findByN_H(nodeId, head, QueryUtil.ALL_POS,
3941                                    QueryUtil.ALL_POS, null)) {
3942                            remove(wikiPage);
3943                    }
3944            }
3945    
3946            /**
3947             * Returns the number of wiki pages where nodeId = &#63; and head = &#63;.
3948             *
3949             * @param nodeId the node ID
3950             * @param head the head
3951             * @return the number of matching wiki pages
3952             * @throws SystemException if a system exception occurred
3953             */
3954            public int countByN_H(long nodeId, boolean head) throws SystemException {
3955                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H;
3956    
3957                    Object[] finderArgs = new Object[] { nodeId, head };
3958    
3959                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3960                                    this);
3961    
3962                    if (count == null) {
3963                            StringBundler query = new StringBundler(3);
3964    
3965                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
3966    
3967                            query.append(_FINDER_COLUMN_N_H_NODEID_2);
3968    
3969                            query.append(_FINDER_COLUMN_N_H_HEAD_2);
3970    
3971                            String sql = query.toString();
3972    
3973                            Session session = null;
3974    
3975                            try {
3976                                    session = openSession();
3977    
3978                                    Query q = session.createQuery(sql);
3979    
3980                                    QueryPos qPos = QueryPos.getInstance(q);
3981    
3982                                    qPos.add(nodeId);
3983    
3984                                    qPos.add(head);
3985    
3986                                    count = (Long)q.uniqueResult();
3987    
3988                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3989                            }
3990                            catch (Exception e) {
3991                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3992    
3993                                    throw processException(e);
3994                            }
3995                            finally {
3996                                    closeSession(session);
3997                            }
3998                    }
3999    
4000                    return count.intValue();
4001            }
4002    
4003            private static final String _FINDER_COLUMN_N_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
4004            private static final String _FINDER_COLUMN_N_H_HEAD_2 = "wikiPage.head = ?";
4005            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4006                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4007                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_P",
4008                            new String[] {
4009                                    Long.class.getName(), String.class.getName(),
4010                                    
4011                            Integer.class.getName(), Integer.class.getName(),
4012                                    OrderByComparator.class.getName()
4013                            });
4014            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4015                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4016                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_P",
4017                            new String[] { Long.class.getName(), String.class.getName() },
4018                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
4019                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
4020                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
4021                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
4022            public static final FinderPath FINDER_PATH_COUNT_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4023                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4024                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_P",
4025                            new String[] { Long.class.getName(), String.class.getName() });
4026    
4027            /**
4028             * Returns all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
4029             *
4030             * @param nodeId the node ID
4031             * @param parentTitle the parent title
4032             * @return the matching wiki pages
4033             * @throws SystemException if a system exception occurred
4034             */
4035            public List<WikiPage> findByN_P(long nodeId, String parentTitle)
4036                    throws SystemException {
4037                    return findByN_P(nodeId, parentTitle, QueryUtil.ALL_POS,
4038                            QueryUtil.ALL_POS, null);
4039            }
4040    
4041            /**
4042             * Returns a range of all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
4043             *
4044             * <p>
4045             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4046             * </p>
4047             *
4048             * @param nodeId the node ID
4049             * @param parentTitle the parent title
4050             * @param start the lower bound of the range of wiki pages
4051             * @param end the upper bound of the range of wiki pages (not inclusive)
4052             * @return the range of matching wiki pages
4053             * @throws SystemException if a system exception occurred
4054             */
4055            public List<WikiPage> findByN_P(long nodeId, String parentTitle, int start,
4056                    int end) throws SystemException {
4057                    return findByN_P(nodeId, parentTitle, start, end, null);
4058            }
4059    
4060            /**
4061             * Returns an ordered range of all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
4062             *
4063             * <p>
4064             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4065             * </p>
4066             *
4067             * @param nodeId the node ID
4068             * @param parentTitle the parent title
4069             * @param start the lower bound of the range of wiki pages
4070             * @param end the upper bound of the range of wiki pages (not inclusive)
4071             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4072             * @return the ordered range of matching wiki pages
4073             * @throws SystemException if a system exception occurred
4074             */
4075            public List<WikiPage> findByN_P(long nodeId, String parentTitle, int start,
4076                    int end, OrderByComparator orderByComparator) throws SystemException {
4077                    boolean pagination = true;
4078                    FinderPath finderPath = null;
4079                    Object[] finderArgs = null;
4080    
4081                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4082                                    (orderByComparator == null)) {
4083                            pagination = false;
4084                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P;
4085                            finderArgs = new Object[] { nodeId, parentTitle };
4086                    }
4087                    else {
4088                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_P;
4089                            finderArgs = new Object[] {
4090                                            nodeId, parentTitle,
4091                                            
4092                                            start, end, orderByComparator
4093                                    };
4094                    }
4095    
4096                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
4097                                    finderArgs, this);
4098    
4099                    if ((list != null) && !list.isEmpty()) {
4100                            for (WikiPage wikiPage : list) {
4101                                    if ((nodeId != wikiPage.getNodeId()) ||
4102                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle())) {
4103                                            list = null;
4104    
4105                                            break;
4106                                    }
4107                            }
4108                    }
4109    
4110                    if (list == null) {
4111                            StringBundler query = null;
4112    
4113                            if (orderByComparator != null) {
4114                                    query = new StringBundler(4 +
4115                                                    (orderByComparator.getOrderByFields().length * 3));
4116                            }
4117                            else {
4118                                    query = new StringBundler(4);
4119                            }
4120    
4121                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4122    
4123                            query.append(_FINDER_COLUMN_N_P_NODEID_2);
4124    
4125                            boolean bindParentTitle = false;
4126    
4127                            if (parentTitle == null) {
4128                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
4129                            }
4130                            else if (parentTitle.equals(StringPool.BLANK)) {
4131                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
4132                            }
4133                            else {
4134                                    bindParentTitle = true;
4135    
4136                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
4137                            }
4138    
4139                            if (orderByComparator != null) {
4140                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4141                                            orderByComparator);
4142                            }
4143                            else
4144                             if (pagination) {
4145                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4146                            }
4147    
4148                            String sql = query.toString();
4149    
4150                            Session session = null;
4151    
4152                            try {
4153                                    session = openSession();
4154    
4155                                    Query q = session.createQuery(sql);
4156    
4157                                    QueryPos qPos = QueryPos.getInstance(q);
4158    
4159                                    qPos.add(nodeId);
4160    
4161                                    if (bindParentTitle) {
4162                                            qPos.add(parentTitle.toLowerCase());
4163                                    }
4164    
4165                                    if (!pagination) {
4166                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4167                                                            start, end, false);
4168    
4169                                            Collections.sort(list);
4170    
4171                                            list = new UnmodifiableList<WikiPage>(list);
4172                                    }
4173                                    else {
4174                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4175                                                            start, end);
4176                                    }
4177    
4178                                    cacheResult(list);
4179    
4180                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4181                            }
4182                            catch (Exception e) {
4183                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4184    
4185                                    throw processException(e);
4186                            }
4187                            finally {
4188                                    closeSession(session);
4189                            }
4190                    }
4191    
4192                    return list;
4193            }
4194    
4195            /**
4196             * Returns the first wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4197             *
4198             * @param nodeId the node ID
4199             * @param parentTitle the parent title
4200             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4201             * @return the first matching wiki page
4202             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4203             * @throws SystemException if a system exception occurred
4204             */
4205            public WikiPage findByN_P_First(long nodeId, String parentTitle,
4206                    OrderByComparator orderByComparator)
4207                    throws NoSuchPageException, SystemException {
4208                    WikiPage wikiPage = fetchByN_P_First(nodeId, parentTitle,
4209                                    orderByComparator);
4210    
4211                    if (wikiPage != null) {
4212                            return wikiPage;
4213                    }
4214    
4215                    StringBundler msg = new StringBundler(6);
4216    
4217                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4218    
4219                    msg.append("nodeId=");
4220                    msg.append(nodeId);
4221    
4222                    msg.append(", parentTitle=");
4223                    msg.append(parentTitle);
4224    
4225                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4226    
4227                    throw new NoSuchPageException(msg.toString());
4228            }
4229    
4230            /**
4231             * Returns the first wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4232             *
4233             * @param nodeId the node ID
4234             * @param parentTitle the parent title
4235             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4236             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
4237             * @throws SystemException if a system exception occurred
4238             */
4239            public WikiPage fetchByN_P_First(long nodeId, String parentTitle,
4240                    OrderByComparator orderByComparator) throws SystemException {
4241                    List<WikiPage> list = findByN_P(nodeId, parentTitle, 0, 1,
4242                                    orderByComparator);
4243    
4244                    if (!list.isEmpty()) {
4245                            return list.get(0);
4246                    }
4247    
4248                    return null;
4249            }
4250    
4251            /**
4252             * Returns the last wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4253             *
4254             * @param nodeId the node ID
4255             * @param parentTitle the parent title
4256             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4257             * @return the last matching wiki page
4258             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4259             * @throws SystemException if a system exception occurred
4260             */
4261            public WikiPage findByN_P_Last(long nodeId, String parentTitle,
4262                    OrderByComparator orderByComparator)
4263                    throws NoSuchPageException, SystemException {
4264                    WikiPage wikiPage = fetchByN_P_Last(nodeId, parentTitle,
4265                                    orderByComparator);
4266    
4267                    if (wikiPage != null) {
4268                            return wikiPage;
4269                    }
4270    
4271                    StringBundler msg = new StringBundler(6);
4272    
4273                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4274    
4275                    msg.append("nodeId=");
4276                    msg.append(nodeId);
4277    
4278                    msg.append(", parentTitle=");
4279                    msg.append(parentTitle);
4280    
4281                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4282    
4283                    throw new NoSuchPageException(msg.toString());
4284            }
4285    
4286            /**
4287             * Returns the last wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4288             *
4289             * @param nodeId the node ID
4290             * @param parentTitle the parent title
4291             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4292             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
4293             * @throws SystemException if a system exception occurred
4294             */
4295            public WikiPage fetchByN_P_Last(long nodeId, String parentTitle,
4296                    OrderByComparator orderByComparator) throws SystemException {
4297                    int count = countByN_P(nodeId, parentTitle);
4298    
4299                    List<WikiPage> list = findByN_P(nodeId, parentTitle, count - 1, count,
4300                                    orderByComparator);
4301    
4302                    if (!list.isEmpty()) {
4303                            return list.get(0);
4304                    }
4305    
4306                    return null;
4307            }
4308    
4309            /**
4310             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4311             *
4312             * @param pageId the primary key of the current wiki page
4313             * @param nodeId the node ID
4314             * @param parentTitle the parent title
4315             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4316             * @return the previous, current, and next wiki page
4317             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
4318             * @throws SystemException if a system exception occurred
4319             */
4320            public WikiPage[] findByN_P_PrevAndNext(long pageId, long nodeId,
4321                    String parentTitle, OrderByComparator orderByComparator)
4322                    throws NoSuchPageException, SystemException {
4323                    WikiPage wikiPage = findByPrimaryKey(pageId);
4324    
4325                    Session session = null;
4326    
4327                    try {
4328                            session = openSession();
4329    
4330                            WikiPage[] array = new WikiPageImpl[3];
4331    
4332                            array[0] = getByN_P_PrevAndNext(session, wikiPage, nodeId,
4333                                            parentTitle, orderByComparator, true);
4334    
4335                            array[1] = wikiPage;
4336    
4337                            array[2] = getByN_P_PrevAndNext(session, wikiPage, nodeId,
4338                                            parentTitle, orderByComparator, false);
4339    
4340                            return array;
4341                    }
4342                    catch (Exception e) {
4343                            throw processException(e);
4344                    }
4345                    finally {
4346                            closeSession(session);
4347                    }
4348            }
4349    
4350            protected WikiPage getByN_P_PrevAndNext(Session session, WikiPage wikiPage,
4351                    long nodeId, String parentTitle, OrderByComparator orderByComparator,
4352                    boolean previous) {
4353                    StringBundler query = null;
4354    
4355                    if (orderByComparator != null) {
4356                            query = new StringBundler(6 +
4357                                            (orderByComparator.getOrderByFields().length * 6));
4358                    }
4359                    else {
4360                            query = new StringBundler(3);
4361                    }
4362    
4363                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4364    
4365                    query.append(_FINDER_COLUMN_N_P_NODEID_2);
4366    
4367                    boolean bindParentTitle = false;
4368    
4369                    if (parentTitle == null) {
4370                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
4371                    }
4372                    else if (parentTitle.equals(StringPool.BLANK)) {
4373                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
4374                    }
4375                    else {
4376                            bindParentTitle = true;
4377    
4378                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
4379                    }
4380    
4381                    if (orderByComparator != null) {
4382                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4383    
4384                            if (orderByConditionFields.length > 0) {
4385                                    query.append(WHERE_AND);
4386                            }
4387    
4388                            for (int i = 0; i < orderByConditionFields.length; i++) {
4389                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4390                                    query.append(orderByConditionFields[i]);
4391    
4392                                    if ((i + 1) < orderByConditionFields.length) {
4393                                            if (orderByComparator.isAscending() ^ previous) {
4394                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4395                                            }
4396                                            else {
4397                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4398                                            }
4399                                    }
4400                                    else {
4401                                            if (orderByComparator.isAscending() ^ previous) {
4402                                                    query.append(WHERE_GREATER_THAN);
4403                                            }
4404                                            else {
4405                                                    query.append(WHERE_LESSER_THAN);
4406                                            }
4407                                    }
4408                            }
4409    
4410                            query.append(ORDER_BY_CLAUSE);
4411    
4412                            String[] orderByFields = orderByComparator.getOrderByFields();
4413    
4414                            for (int i = 0; i < orderByFields.length; i++) {
4415                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4416                                    query.append(orderByFields[i]);
4417    
4418                                    if ((i + 1) < orderByFields.length) {
4419                                            if (orderByComparator.isAscending() ^ previous) {
4420                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4421                                            }
4422                                            else {
4423                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4424                                            }
4425                                    }
4426                                    else {
4427                                            if (orderByComparator.isAscending() ^ previous) {
4428                                                    query.append(ORDER_BY_ASC);
4429                                            }
4430                                            else {
4431                                                    query.append(ORDER_BY_DESC);
4432                                            }
4433                                    }
4434                            }
4435                    }
4436                    else {
4437                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4438                    }
4439    
4440                    String sql = query.toString();
4441    
4442                    Query q = session.createQuery(sql);
4443    
4444                    q.setFirstResult(0);
4445                    q.setMaxResults(2);
4446    
4447                    QueryPos qPos = QueryPos.getInstance(q);
4448    
4449                    qPos.add(nodeId);
4450    
4451                    if (bindParentTitle) {
4452                            qPos.add(parentTitle.toLowerCase());
4453                    }
4454    
4455                    if (orderByComparator != null) {
4456                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
4457    
4458                            for (Object value : values) {
4459                                    qPos.add(value);
4460                            }
4461                    }
4462    
4463                    List<WikiPage> list = q.list();
4464    
4465                    if (list.size() == 2) {
4466                            return list.get(1);
4467                    }
4468                    else {
4469                            return null;
4470                    }
4471            }
4472    
4473            /**
4474             * Removes all the wiki pages where nodeId = &#63; and parentTitle = &#63; from the database.
4475             *
4476             * @param nodeId the node ID
4477             * @param parentTitle the parent title
4478             * @throws SystemException if a system exception occurred
4479             */
4480            public void removeByN_P(long nodeId, String parentTitle)
4481                    throws SystemException {
4482                    for (WikiPage wikiPage : findByN_P(nodeId, parentTitle,
4483                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4484                            remove(wikiPage);
4485                    }
4486            }
4487    
4488            /**
4489             * Returns the number of wiki pages where nodeId = &#63; and parentTitle = &#63;.
4490             *
4491             * @param nodeId the node ID
4492             * @param parentTitle the parent title
4493             * @return the number of matching wiki pages
4494             * @throws SystemException if a system exception occurred
4495             */
4496            public int countByN_P(long nodeId, String parentTitle)
4497                    throws SystemException {
4498                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_P;
4499    
4500                    Object[] finderArgs = new Object[] { nodeId, parentTitle };
4501    
4502                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4503                                    this);
4504    
4505                    if (count == null) {
4506                            StringBundler query = new StringBundler(3);
4507    
4508                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
4509    
4510                            query.append(_FINDER_COLUMN_N_P_NODEID_2);
4511    
4512                            boolean bindParentTitle = false;
4513    
4514                            if (parentTitle == null) {
4515                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
4516                            }
4517                            else if (parentTitle.equals(StringPool.BLANK)) {
4518                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
4519                            }
4520                            else {
4521                                    bindParentTitle = true;
4522    
4523                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
4524                            }
4525    
4526                            String sql = query.toString();
4527    
4528                            Session session = null;
4529    
4530                            try {
4531                                    session = openSession();
4532    
4533                                    Query q = session.createQuery(sql);
4534    
4535                                    QueryPos qPos = QueryPos.getInstance(q);
4536    
4537                                    qPos.add(nodeId);
4538    
4539                                    if (bindParentTitle) {
4540                                            qPos.add(parentTitle.toLowerCase());
4541                                    }
4542    
4543                                    count = (Long)q.uniqueResult();
4544    
4545                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4546                            }
4547                            catch (Exception e) {
4548                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4549    
4550                                    throw processException(e);
4551                            }
4552                            finally {
4553                                    closeSession(session);
4554                            }
4555                    }
4556    
4557                    return count.intValue();
4558            }
4559    
4560            private static final String _FINDER_COLUMN_N_P_NODEID_2 = "wikiPage.nodeId = ? AND ";
4561            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL";
4562            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ?";
4563            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '')";
4564            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4565                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4566                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_R",
4567                            new String[] {
4568                                    Long.class.getName(), String.class.getName(),
4569                                    
4570                            Integer.class.getName(), Integer.class.getName(),
4571                                    OrderByComparator.class.getName()
4572                            });
4573            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4574                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4575                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_R",
4576                            new String[] { Long.class.getName(), String.class.getName() },
4577                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
4578                            WikiPageModelImpl.REDIRECTTITLE_COLUMN_BITMASK |
4579                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
4580                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
4581            public static final FinderPath FINDER_PATH_COUNT_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4582                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4583                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_R",
4584                            new String[] { Long.class.getName(), String.class.getName() });
4585    
4586            /**
4587             * Returns all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
4588             *
4589             * @param nodeId the node ID
4590             * @param redirectTitle the redirect title
4591             * @return the matching wiki pages
4592             * @throws SystemException if a system exception occurred
4593             */
4594            public List<WikiPage> findByN_R(long nodeId, String redirectTitle)
4595                    throws SystemException {
4596                    return findByN_R(nodeId, redirectTitle, QueryUtil.ALL_POS,
4597                            QueryUtil.ALL_POS, null);
4598            }
4599    
4600            /**
4601             * Returns a range of all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
4602             *
4603             * <p>
4604             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4605             * </p>
4606             *
4607             * @param nodeId the node ID
4608             * @param redirectTitle the redirect title
4609             * @param start the lower bound of the range of wiki pages
4610             * @param end the upper bound of the range of wiki pages (not inclusive)
4611             * @return the range of matching wiki pages
4612             * @throws SystemException if a system exception occurred
4613             */
4614            public List<WikiPage> findByN_R(long nodeId, String redirectTitle,
4615                    int start, int end) throws SystemException {
4616                    return findByN_R(nodeId, redirectTitle, start, end, null);
4617            }
4618    
4619            /**
4620             * Returns an ordered range of all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
4621             *
4622             * <p>
4623             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4624             * </p>
4625             *
4626             * @param nodeId the node ID
4627             * @param redirectTitle the redirect title
4628             * @param start the lower bound of the range of wiki pages
4629             * @param end the upper bound of the range of wiki pages (not inclusive)
4630             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4631             * @return the ordered range of matching wiki pages
4632             * @throws SystemException if a system exception occurred
4633             */
4634            public List<WikiPage> findByN_R(long nodeId, String redirectTitle,
4635                    int start, int end, OrderByComparator orderByComparator)
4636                    throws SystemException {
4637                    boolean pagination = true;
4638                    FinderPath finderPath = null;
4639                    Object[] finderArgs = null;
4640    
4641                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4642                                    (orderByComparator == null)) {
4643                            pagination = false;
4644                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R;
4645                            finderArgs = new Object[] { nodeId, redirectTitle };
4646                    }
4647                    else {
4648                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_R;
4649                            finderArgs = new Object[] {
4650                                            nodeId, redirectTitle,
4651                                            
4652                                            start, end, orderByComparator
4653                                    };
4654                    }
4655    
4656                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
4657                                    finderArgs, this);
4658    
4659                    if ((list != null) && !list.isEmpty()) {
4660                            for (WikiPage wikiPage : list) {
4661                                    if ((nodeId != wikiPage.getNodeId()) ||
4662                                                    !Validator.equals(redirectTitle,
4663                                                            wikiPage.getRedirectTitle())) {
4664                                            list = null;
4665    
4666                                            break;
4667                                    }
4668                            }
4669                    }
4670    
4671                    if (list == null) {
4672                            StringBundler query = null;
4673    
4674                            if (orderByComparator != null) {
4675                                    query = new StringBundler(4 +
4676                                                    (orderByComparator.getOrderByFields().length * 3));
4677                            }
4678                            else {
4679                                    query = new StringBundler(4);
4680                            }
4681    
4682                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4683    
4684                            query.append(_FINDER_COLUMN_N_R_NODEID_2);
4685    
4686                            boolean bindRedirectTitle = false;
4687    
4688                            if (redirectTitle == null) {
4689                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
4690                            }
4691                            else if (redirectTitle.equals(StringPool.BLANK)) {
4692                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
4693                            }
4694                            else {
4695                                    bindRedirectTitle = true;
4696    
4697                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
4698                            }
4699    
4700                            if (orderByComparator != null) {
4701                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4702                                            orderByComparator);
4703                            }
4704                            else
4705                             if (pagination) {
4706                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4707                            }
4708    
4709                            String sql = query.toString();
4710    
4711                            Session session = null;
4712    
4713                            try {
4714                                    session = openSession();
4715    
4716                                    Query q = session.createQuery(sql);
4717    
4718                                    QueryPos qPos = QueryPos.getInstance(q);
4719    
4720                                    qPos.add(nodeId);
4721    
4722                                    if (bindRedirectTitle) {
4723                                            qPos.add(redirectTitle.toLowerCase());
4724                                    }
4725    
4726                                    if (!pagination) {
4727                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4728                                                            start, end, false);
4729    
4730                                            Collections.sort(list);
4731    
4732                                            list = new UnmodifiableList<WikiPage>(list);
4733                                    }
4734                                    else {
4735                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4736                                                            start, end);
4737                                    }
4738    
4739                                    cacheResult(list);
4740    
4741                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4742                            }
4743                            catch (Exception e) {
4744                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4745    
4746                                    throw processException(e);
4747                            }
4748                            finally {
4749                                    closeSession(session);
4750                            }
4751                    }
4752    
4753                    return list;
4754            }
4755    
4756            /**
4757             * Returns the first wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4758             *
4759             * @param nodeId the node ID
4760             * @param redirectTitle the redirect title
4761             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4762             * @return the first matching wiki page
4763             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4764             * @throws SystemException if a system exception occurred
4765             */
4766            public WikiPage findByN_R_First(long nodeId, String redirectTitle,
4767                    OrderByComparator orderByComparator)
4768                    throws NoSuchPageException, SystemException {
4769                    WikiPage wikiPage = fetchByN_R_First(nodeId, redirectTitle,
4770                                    orderByComparator);
4771    
4772                    if (wikiPage != null) {
4773                            return wikiPage;
4774                    }
4775    
4776                    StringBundler msg = new StringBundler(6);
4777    
4778                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4779    
4780                    msg.append("nodeId=");
4781                    msg.append(nodeId);
4782    
4783                    msg.append(", redirectTitle=");
4784                    msg.append(redirectTitle);
4785    
4786                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4787    
4788                    throw new NoSuchPageException(msg.toString());
4789            }
4790    
4791            /**
4792             * Returns the first wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4793             *
4794             * @param nodeId the node ID
4795             * @param redirectTitle the redirect title
4796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4797             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
4798             * @throws SystemException if a system exception occurred
4799             */
4800            public WikiPage fetchByN_R_First(long nodeId, String redirectTitle,
4801                    OrderByComparator orderByComparator) throws SystemException {
4802                    List<WikiPage> list = findByN_R(nodeId, redirectTitle, 0, 1,
4803                                    orderByComparator);
4804    
4805                    if (!list.isEmpty()) {
4806                            return list.get(0);
4807                    }
4808    
4809                    return null;
4810            }
4811    
4812            /**
4813             * Returns the last wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4814             *
4815             * @param nodeId the node ID
4816             * @param redirectTitle the redirect title
4817             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4818             * @return the last matching wiki page
4819             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4820             * @throws SystemException if a system exception occurred
4821             */
4822            public WikiPage findByN_R_Last(long nodeId, String redirectTitle,
4823                    OrderByComparator orderByComparator)
4824                    throws NoSuchPageException, SystemException {
4825                    WikiPage wikiPage = fetchByN_R_Last(nodeId, redirectTitle,
4826                                    orderByComparator);
4827    
4828                    if (wikiPage != null) {
4829                            return wikiPage;
4830                    }
4831    
4832                    StringBundler msg = new StringBundler(6);
4833    
4834                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4835    
4836                    msg.append("nodeId=");
4837                    msg.append(nodeId);
4838    
4839                    msg.append(", redirectTitle=");
4840                    msg.append(redirectTitle);
4841    
4842                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4843    
4844                    throw new NoSuchPageException(msg.toString());
4845            }
4846    
4847            /**
4848             * Returns the last wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4849             *
4850             * @param nodeId the node ID
4851             * @param redirectTitle the redirect title
4852             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4853             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
4854             * @throws SystemException if a system exception occurred
4855             */
4856            public WikiPage fetchByN_R_Last(long nodeId, String redirectTitle,
4857                    OrderByComparator orderByComparator) throws SystemException {
4858                    int count = countByN_R(nodeId, redirectTitle);
4859    
4860                    List<WikiPage> list = findByN_R(nodeId, redirectTitle, count - 1,
4861                                    count, orderByComparator);
4862    
4863                    if (!list.isEmpty()) {
4864                            return list.get(0);
4865                    }
4866    
4867                    return null;
4868            }
4869    
4870            /**
4871             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4872             *
4873             * @param pageId the primary key of the current wiki page
4874             * @param nodeId the node ID
4875             * @param redirectTitle the redirect title
4876             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4877             * @return the previous, current, and next wiki page
4878             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
4879             * @throws SystemException if a system exception occurred
4880             */
4881            public WikiPage[] findByN_R_PrevAndNext(long pageId, long nodeId,
4882                    String redirectTitle, OrderByComparator orderByComparator)
4883                    throws NoSuchPageException, SystemException {
4884                    WikiPage wikiPage = findByPrimaryKey(pageId);
4885    
4886                    Session session = null;
4887    
4888                    try {
4889                            session = openSession();
4890    
4891                            WikiPage[] array = new WikiPageImpl[3];
4892    
4893                            array[0] = getByN_R_PrevAndNext(session, wikiPage, nodeId,
4894                                            redirectTitle, orderByComparator, true);
4895    
4896                            array[1] = wikiPage;
4897    
4898                            array[2] = getByN_R_PrevAndNext(session, wikiPage, nodeId,
4899                                            redirectTitle, orderByComparator, false);
4900    
4901                            return array;
4902                    }
4903                    catch (Exception e) {
4904                            throw processException(e);
4905                    }
4906                    finally {
4907                            closeSession(session);
4908                    }
4909            }
4910    
4911            protected WikiPage getByN_R_PrevAndNext(Session session, WikiPage wikiPage,
4912                    long nodeId, String redirectTitle, OrderByComparator orderByComparator,
4913                    boolean previous) {
4914                    StringBundler query = null;
4915    
4916                    if (orderByComparator != null) {
4917                            query = new StringBundler(6 +
4918                                            (orderByComparator.getOrderByFields().length * 6));
4919                    }
4920                    else {
4921                            query = new StringBundler(3);
4922                    }
4923    
4924                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4925    
4926                    query.append(_FINDER_COLUMN_N_R_NODEID_2);
4927    
4928                    boolean bindRedirectTitle = false;
4929    
4930                    if (redirectTitle == null) {
4931                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
4932                    }
4933                    else if (redirectTitle.equals(StringPool.BLANK)) {
4934                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
4935                    }
4936                    else {
4937                            bindRedirectTitle = true;
4938    
4939                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
4940                    }
4941    
4942                    if (orderByComparator != null) {
4943                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4944    
4945                            if (orderByConditionFields.length > 0) {
4946                                    query.append(WHERE_AND);
4947                            }
4948    
4949                            for (int i = 0; i < orderByConditionFields.length; i++) {
4950                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4951                                    query.append(orderByConditionFields[i]);
4952    
4953                                    if ((i + 1) < orderByConditionFields.length) {
4954                                            if (orderByComparator.isAscending() ^ previous) {
4955                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4956                                            }
4957                                            else {
4958                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4959                                            }
4960                                    }
4961                                    else {
4962                                            if (orderByComparator.isAscending() ^ previous) {
4963                                                    query.append(WHERE_GREATER_THAN);
4964                                            }
4965                                            else {
4966                                                    query.append(WHERE_LESSER_THAN);
4967                                            }
4968                                    }
4969                            }
4970    
4971                            query.append(ORDER_BY_CLAUSE);
4972    
4973                            String[] orderByFields = orderByComparator.getOrderByFields();
4974    
4975                            for (int i = 0; i < orderByFields.length; i++) {
4976                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4977                                    query.append(orderByFields[i]);
4978    
4979                                    if ((i + 1) < orderByFields.length) {
4980                                            if (orderByComparator.isAscending() ^ previous) {
4981                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4982                                            }
4983                                            else {
4984                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4985                                            }
4986                                    }
4987                                    else {
4988                                            if (orderByComparator.isAscending() ^ previous) {
4989                                                    query.append(ORDER_BY_ASC);
4990                                            }
4991                                            else {
4992                                                    query.append(ORDER_BY_DESC);
4993                                            }
4994                                    }
4995                            }
4996                    }
4997                    else {
4998                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4999                    }
5000    
5001                    String sql = query.toString();
5002    
5003                    Query q = session.createQuery(sql);
5004    
5005                    q.setFirstResult(0);
5006                    q.setMaxResults(2);
5007    
5008                    QueryPos qPos = QueryPos.getInstance(q);
5009    
5010                    qPos.add(nodeId);
5011    
5012                    if (bindRedirectTitle) {
5013                            qPos.add(redirectTitle.toLowerCase());
5014                    }
5015    
5016                    if (orderByComparator != null) {
5017                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
5018    
5019                            for (Object value : values) {
5020                                    qPos.add(value);
5021                            }
5022                    }
5023    
5024                    List<WikiPage> list = q.list();
5025    
5026                    if (list.size() == 2) {
5027                            return list.get(1);
5028                    }
5029                    else {
5030                            return null;
5031                    }
5032            }
5033    
5034            /**
5035             * Removes all the wiki pages where nodeId = &#63; and redirectTitle = &#63; from the database.
5036             *
5037             * @param nodeId the node ID
5038             * @param redirectTitle the redirect title
5039             * @throws SystemException if a system exception occurred
5040             */
5041            public void removeByN_R(long nodeId, String redirectTitle)
5042                    throws SystemException {
5043                    for (WikiPage wikiPage : findByN_R(nodeId, redirectTitle,
5044                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5045                            remove(wikiPage);
5046                    }
5047            }
5048    
5049            /**
5050             * Returns the number of wiki pages where nodeId = &#63; and redirectTitle = &#63;.
5051             *
5052             * @param nodeId the node ID
5053             * @param redirectTitle the redirect title
5054             * @return the number of matching wiki pages
5055             * @throws SystemException if a system exception occurred
5056             */
5057            public int countByN_R(long nodeId, String redirectTitle)
5058                    throws SystemException {
5059                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_R;
5060    
5061                    Object[] finderArgs = new Object[] { nodeId, redirectTitle };
5062    
5063                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5064                                    this);
5065    
5066                    if (count == null) {
5067                            StringBundler query = new StringBundler(3);
5068    
5069                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
5070    
5071                            query.append(_FINDER_COLUMN_N_R_NODEID_2);
5072    
5073                            boolean bindRedirectTitle = false;
5074    
5075                            if (redirectTitle == null) {
5076                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
5077                            }
5078                            else if (redirectTitle.equals(StringPool.BLANK)) {
5079                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
5080                            }
5081                            else {
5082                                    bindRedirectTitle = true;
5083    
5084                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
5085                            }
5086    
5087                            String sql = query.toString();
5088    
5089                            Session session = null;
5090    
5091                            try {
5092                                    session = openSession();
5093    
5094                                    Query q = session.createQuery(sql);
5095    
5096                                    QueryPos qPos = QueryPos.getInstance(q);
5097    
5098                                    qPos.add(nodeId);
5099    
5100                                    if (bindRedirectTitle) {
5101                                            qPos.add(redirectTitle.toLowerCase());
5102                                    }
5103    
5104                                    count = (Long)q.uniqueResult();
5105    
5106                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5107                            }
5108                            catch (Exception e) {
5109                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5110    
5111                                    throw processException(e);
5112                            }
5113                            finally {
5114                                    closeSession(session);
5115                            }
5116                    }
5117    
5118                    return count.intValue();
5119            }
5120    
5121            private static final String _FINDER_COLUMN_N_R_NODEID_2 = "wikiPage.nodeId = ? AND ";
5122            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_1 = "wikiPage.redirectTitle IS NULL";
5123            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_2 = "lower(wikiPage.redirectTitle) = ?";
5124            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_3 = "(wikiPage.redirectTitle IS NULL OR wikiPage.redirectTitle = '')";
5125            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5126                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5127                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_S",
5128                            new String[] {
5129                                    Long.class.getName(), Integer.class.getName(),
5130                                    
5131                            Integer.class.getName(), Integer.class.getName(),
5132                                    OrderByComparator.class.getName()
5133                            });
5134            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5135                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5136                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_S",
5137                            new String[] { Long.class.getName(), Integer.class.getName() },
5138                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
5139                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
5140                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
5141                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
5142            public static final FinderPath FINDER_PATH_COUNT_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5143                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5144                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_S",
5145                            new String[] { Long.class.getName(), Integer.class.getName() });
5146    
5147            /**
5148             * Returns all the wiki pages where nodeId = &#63; and status = &#63;.
5149             *
5150             * @param nodeId the node ID
5151             * @param status the status
5152             * @return the matching wiki pages
5153             * @throws SystemException if a system exception occurred
5154             */
5155            public List<WikiPage> findByN_S(long nodeId, int status)
5156                    throws SystemException {
5157                    return findByN_S(nodeId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5158                            null);
5159            }
5160    
5161            /**
5162             * Returns a range of all the wiki pages where nodeId = &#63; and status = &#63;.
5163             *
5164             * <p>
5165             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5166             * </p>
5167             *
5168             * @param nodeId the node ID
5169             * @param status the status
5170             * @param start the lower bound of the range of wiki pages
5171             * @param end the upper bound of the range of wiki pages (not inclusive)
5172             * @return the range of matching wiki pages
5173             * @throws SystemException if a system exception occurred
5174             */
5175            public List<WikiPage> findByN_S(long nodeId, int status, int start, int end)
5176                    throws SystemException {
5177                    return findByN_S(nodeId, status, start, end, null);
5178            }
5179    
5180            /**
5181             * Returns an ordered range of all the wiki pages where nodeId = &#63; and status = &#63;.
5182             *
5183             * <p>
5184             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5185             * </p>
5186             *
5187             * @param nodeId the node ID
5188             * @param status the status
5189             * @param start the lower bound of the range of wiki pages
5190             * @param end the upper bound of the range of wiki pages (not inclusive)
5191             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5192             * @return the ordered range of matching wiki pages
5193             * @throws SystemException if a system exception occurred
5194             */
5195            public List<WikiPage> findByN_S(long nodeId, int status, int start,
5196                    int end, OrderByComparator orderByComparator) throws SystemException {
5197                    boolean pagination = true;
5198                    FinderPath finderPath = null;
5199                    Object[] finderArgs = null;
5200    
5201                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5202                                    (orderByComparator == null)) {
5203                            pagination = false;
5204                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S;
5205                            finderArgs = new Object[] { nodeId, status };
5206                    }
5207                    else {
5208                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_S;
5209                            finderArgs = new Object[] {
5210                                            nodeId, status,
5211                                            
5212                                            start, end, orderByComparator
5213                                    };
5214                    }
5215    
5216                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
5217                                    finderArgs, this);
5218    
5219                    if ((list != null) && !list.isEmpty()) {
5220                            for (WikiPage wikiPage : list) {
5221                                    if ((nodeId != wikiPage.getNodeId()) ||
5222                                                    (status != wikiPage.getStatus())) {
5223                                            list = null;
5224    
5225                                            break;
5226                                    }
5227                            }
5228                    }
5229    
5230                    if (list == null) {
5231                            StringBundler query = null;
5232    
5233                            if (orderByComparator != null) {
5234                                    query = new StringBundler(4 +
5235                                                    (orderByComparator.getOrderByFields().length * 3));
5236                            }
5237                            else {
5238                                    query = new StringBundler(4);
5239                            }
5240    
5241                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5242    
5243                            query.append(_FINDER_COLUMN_N_S_NODEID_2);
5244    
5245                            query.append(_FINDER_COLUMN_N_S_STATUS_2);
5246    
5247                            if (orderByComparator != null) {
5248                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5249                                            orderByComparator);
5250                            }
5251                            else
5252                             if (pagination) {
5253                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5254                            }
5255    
5256                            String sql = query.toString();
5257    
5258                            Session session = null;
5259    
5260                            try {
5261                                    session = openSession();
5262    
5263                                    Query q = session.createQuery(sql);
5264    
5265                                    QueryPos qPos = QueryPos.getInstance(q);
5266    
5267                                    qPos.add(nodeId);
5268    
5269                                    qPos.add(status);
5270    
5271                                    if (!pagination) {
5272                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
5273                                                            start, end, false);
5274    
5275                                            Collections.sort(list);
5276    
5277                                            list = new UnmodifiableList<WikiPage>(list);
5278                                    }
5279                                    else {
5280                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
5281                                                            start, end);
5282                                    }
5283    
5284                                    cacheResult(list);
5285    
5286                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5287                            }
5288                            catch (Exception e) {
5289                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5290    
5291                                    throw processException(e);
5292                            }
5293                            finally {
5294                                    closeSession(session);
5295                            }
5296                    }
5297    
5298                    return list;
5299            }
5300    
5301            /**
5302             * Returns the first wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5303             *
5304             * @param nodeId the node ID
5305             * @param status the status
5306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5307             * @return the first matching wiki page
5308             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5309             * @throws SystemException if a system exception occurred
5310             */
5311            public WikiPage findByN_S_First(long nodeId, int status,
5312                    OrderByComparator orderByComparator)
5313                    throws NoSuchPageException, SystemException {
5314                    WikiPage wikiPage = fetchByN_S_First(nodeId, status, orderByComparator);
5315    
5316                    if (wikiPage != null) {
5317                            return wikiPage;
5318                    }
5319    
5320                    StringBundler msg = new StringBundler(6);
5321    
5322                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5323    
5324                    msg.append("nodeId=");
5325                    msg.append(nodeId);
5326    
5327                    msg.append(", status=");
5328                    msg.append(status);
5329    
5330                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5331    
5332                    throw new NoSuchPageException(msg.toString());
5333            }
5334    
5335            /**
5336             * Returns the first wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5337             *
5338             * @param nodeId the node ID
5339             * @param status the status
5340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5341             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
5342             * @throws SystemException if a system exception occurred
5343             */
5344            public WikiPage fetchByN_S_First(long nodeId, int status,
5345                    OrderByComparator orderByComparator) throws SystemException {
5346                    List<WikiPage> list = findByN_S(nodeId, status, 0, 1, orderByComparator);
5347    
5348                    if (!list.isEmpty()) {
5349                            return list.get(0);
5350                    }
5351    
5352                    return null;
5353            }
5354    
5355            /**
5356             * Returns the last wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5357             *
5358             * @param nodeId the node ID
5359             * @param status the status
5360             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5361             * @return the last matching wiki page
5362             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5363             * @throws SystemException if a system exception occurred
5364             */
5365            public WikiPage findByN_S_Last(long nodeId, int status,
5366                    OrderByComparator orderByComparator)
5367                    throws NoSuchPageException, SystemException {
5368                    WikiPage wikiPage = fetchByN_S_Last(nodeId, status, orderByComparator);
5369    
5370                    if (wikiPage != null) {
5371                            return wikiPage;
5372                    }
5373    
5374                    StringBundler msg = new StringBundler(6);
5375    
5376                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5377    
5378                    msg.append("nodeId=");
5379                    msg.append(nodeId);
5380    
5381                    msg.append(", status=");
5382                    msg.append(status);
5383    
5384                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5385    
5386                    throw new NoSuchPageException(msg.toString());
5387            }
5388    
5389            /**
5390             * Returns the last wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5391             *
5392             * @param nodeId the node ID
5393             * @param status the status
5394             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5395             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
5396             * @throws SystemException if a system exception occurred
5397             */
5398            public WikiPage fetchByN_S_Last(long nodeId, int status,
5399                    OrderByComparator orderByComparator) throws SystemException {
5400                    int count = countByN_S(nodeId, status);
5401    
5402                    List<WikiPage> list = findByN_S(nodeId, status, count - 1, count,
5403                                    orderByComparator);
5404    
5405                    if (!list.isEmpty()) {
5406                            return list.get(0);
5407                    }
5408    
5409                    return null;
5410            }
5411    
5412            /**
5413             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5414             *
5415             * @param pageId the primary key of the current wiki page
5416             * @param nodeId the node ID
5417             * @param status the status
5418             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5419             * @return the previous, current, and next wiki page
5420             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
5421             * @throws SystemException if a system exception occurred
5422             */
5423            public WikiPage[] findByN_S_PrevAndNext(long pageId, long nodeId,
5424                    int status, OrderByComparator orderByComparator)
5425                    throws NoSuchPageException, SystemException {
5426                    WikiPage wikiPage = findByPrimaryKey(pageId);
5427    
5428                    Session session = null;
5429    
5430                    try {
5431                            session = openSession();
5432    
5433                            WikiPage[] array = new WikiPageImpl[3];
5434    
5435                            array[0] = getByN_S_PrevAndNext(session, wikiPage, nodeId, status,
5436                                            orderByComparator, true);
5437    
5438                            array[1] = wikiPage;
5439    
5440                            array[2] = getByN_S_PrevAndNext(session, wikiPage, nodeId, status,
5441                                            orderByComparator, false);
5442    
5443                            return array;
5444                    }
5445                    catch (Exception e) {
5446                            throw processException(e);
5447                    }
5448                    finally {
5449                            closeSession(session);
5450                    }
5451            }
5452    
5453            protected WikiPage getByN_S_PrevAndNext(Session session, WikiPage wikiPage,
5454                    long nodeId, int status, OrderByComparator orderByComparator,
5455                    boolean previous) {
5456                    StringBundler query = null;
5457    
5458                    if (orderByComparator != null) {
5459                            query = new StringBundler(6 +
5460                                            (orderByComparator.getOrderByFields().length * 6));
5461                    }
5462                    else {
5463                            query = new StringBundler(3);
5464                    }
5465    
5466                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5467    
5468                    query.append(_FINDER_COLUMN_N_S_NODEID_2);
5469    
5470                    query.append(_FINDER_COLUMN_N_S_STATUS_2);
5471    
5472                    if (orderByComparator != null) {
5473                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5474    
5475                            if (orderByConditionFields.length > 0) {
5476                                    query.append(WHERE_AND);
5477                            }
5478    
5479                            for (int i = 0; i < orderByConditionFields.length; i++) {
5480                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5481                                    query.append(orderByConditionFields[i]);
5482    
5483                                    if ((i + 1) < orderByConditionFields.length) {
5484                                            if (orderByComparator.isAscending() ^ previous) {
5485                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5486                                            }
5487                                            else {
5488                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5489                                            }
5490                                    }
5491                                    else {
5492                                            if (orderByComparator.isAscending() ^ previous) {
5493                                                    query.append(WHERE_GREATER_THAN);
5494                                            }
5495                                            else {
5496                                                    query.append(WHERE_LESSER_THAN);
5497                                            }
5498                                    }
5499                            }
5500    
5501                            query.append(ORDER_BY_CLAUSE);
5502    
5503                            String[] orderByFields = orderByComparator.getOrderByFields();
5504    
5505                            for (int i = 0; i < orderByFields.length; i++) {
5506                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5507                                    query.append(orderByFields[i]);
5508    
5509                                    if ((i + 1) < orderByFields.length) {
5510                                            if (orderByComparator.isAscending() ^ previous) {
5511                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5512                                            }
5513                                            else {
5514                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5515                                            }
5516                                    }
5517                                    else {
5518                                            if (orderByComparator.isAscending() ^ previous) {
5519                                                    query.append(ORDER_BY_ASC);
5520                                            }
5521                                            else {
5522                                                    query.append(ORDER_BY_DESC);
5523                                            }
5524                                    }
5525                            }
5526                    }
5527                    else {
5528                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5529                    }
5530    
5531                    String sql = query.toString();
5532    
5533                    Query q = session.createQuery(sql);
5534    
5535                    q.setFirstResult(0);
5536                    q.setMaxResults(2);
5537    
5538                    QueryPos qPos = QueryPos.getInstance(q);
5539    
5540                    qPos.add(nodeId);
5541    
5542                    qPos.add(status);
5543    
5544                    if (orderByComparator != null) {
5545                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
5546    
5547                            for (Object value : values) {
5548                                    qPos.add(value);
5549                            }
5550                    }
5551    
5552                    List<WikiPage> list = q.list();
5553    
5554                    if (list.size() == 2) {
5555                            return list.get(1);
5556                    }
5557                    else {
5558                            return null;
5559                    }
5560            }
5561    
5562            /**
5563             * Removes all the wiki pages where nodeId = &#63; and status = &#63; from the database.
5564             *
5565             * @param nodeId the node ID
5566             * @param status the status
5567             * @throws SystemException if a system exception occurred
5568             */
5569            public void removeByN_S(long nodeId, int status) throws SystemException {
5570                    for (WikiPage wikiPage : findByN_S(nodeId, status, QueryUtil.ALL_POS,
5571                                    QueryUtil.ALL_POS, null)) {
5572                            remove(wikiPage);
5573                    }
5574            }
5575    
5576            /**
5577             * Returns the number of wiki pages where nodeId = &#63; and status = &#63;.
5578             *
5579             * @param nodeId the node ID
5580             * @param status the status
5581             * @return the number of matching wiki pages
5582             * @throws SystemException if a system exception occurred
5583             */
5584            public int countByN_S(long nodeId, int status) throws SystemException {
5585                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_S;
5586    
5587                    Object[] finderArgs = new Object[] { nodeId, status };
5588    
5589                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5590                                    this);
5591    
5592                    if (count == null) {
5593                            StringBundler query = new StringBundler(3);
5594    
5595                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
5596    
5597                            query.append(_FINDER_COLUMN_N_S_NODEID_2);
5598    
5599                            query.append(_FINDER_COLUMN_N_S_STATUS_2);
5600    
5601                            String sql = query.toString();
5602    
5603                            Session session = null;
5604    
5605                            try {
5606                                    session = openSession();
5607    
5608                                    Query q = session.createQuery(sql);
5609    
5610                                    QueryPos qPos = QueryPos.getInstance(q);
5611    
5612                                    qPos.add(nodeId);
5613    
5614                                    qPos.add(status);
5615    
5616                                    count = (Long)q.uniqueResult();
5617    
5618                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5619                            }
5620                            catch (Exception e) {
5621                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5622    
5623                                    throw processException(e);
5624                            }
5625                            finally {
5626                                    closeSession(session);
5627                            }
5628                    }
5629    
5630                    return count.intValue();
5631            }
5632    
5633            private static final String _FINDER_COLUMN_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
5634            private static final String _FINDER_COLUMN_N_S_STATUS_2 = "wikiPage.status = ?";
5635            public static final FinderPath FINDER_PATH_FETCH_BY_R_N_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5636                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5637                            FINDER_CLASS_NAME_ENTITY, "fetchByR_N_V",
5638                            new String[] {
5639                                    Long.class.getName(), Long.class.getName(),
5640                                    Double.class.getName()
5641                            },
5642                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
5643                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
5644                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
5645            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5646                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5647                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N_V",
5648                            new String[] {
5649                                    Long.class.getName(), Long.class.getName(),
5650                                    Double.class.getName()
5651                            });
5652    
5653            /**
5654             * Returns 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.
5655             *
5656             * @param resourcePrimKey the resource prim key
5657             * @param nodeId the node ID
5658             * @param version the version
5659             * @return the matching wiki page
5660             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5661             * @throws SystemException if a system exception occurred
5662             */
5663            public WikiPage findByR_N_V(long resourcePrimKey, long nodeId,
5664                    double version) throws NoSuchPageException, SystemException {
5665                    WikiPage wikiPage = fetchByR_N_V(resourcePrimKey, nodeId, version);
5666    
5667                    if (wikiPage == null) {
5668                            StringBundler msg = new StringBundler(8);
5669    
5670                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5671    
5672                            msg.append("resourcePrimKey=");
5673                            msg.append(resourcePrimKey);
5674    
5675                            msg.append(", nodeId=");
5676                            msg.append(nodeId);
5677    
5678                            msg.append(", version=");
5679                            msg.append(version);
5680    
5681                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5682    
5683                            if (_log.isWarnEnabled()) {
5684                                    _log.warn(msg.toString());
5685                            }
5686    
5687                            throw new NoSuchPageException(msg.toString());
5688                    }
5689    
5690                    return wikiPage;
5691            }
5692    
5693            /**
5694             * Returns 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.
5695             *
5696             * @param resourcePrimKey the resource prim key
5697             * @param nodeId the node ID
5698             * @param version the version
5699             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
5700             * @throws SystemException if a system exception occurred
5701             */
5702            public WikiPage fetchByR_N_V(long resourcePrimKey, long nodeId,
5703                    double version) throws SystemException {
5704                    return fetchByR_N_V(resourcePrimKey, nodeId, version, true);
5705            }
5706    
5707            /**
5708             * Returns 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.
5709             *
5710             * @param resourcePrimKey the resource prim key
5711             * @param nodeId the node ID
5712             * @param version the version
5713             * @param retrieveFromCache whether to use the finder cache
5714             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
5715             * @throws SystemException if a system exception occurred
5716             */
5717            public WikiPage fetchByR_N_V(long resourcePrimKey, long nodeId,
5718                    double version, boolean retrieveFromCache) throws SystemException {
5719                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, version };
5720    
5721                    Object result = null;
5722    
5723                    if (retrieveFromCache) {
5724                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_R_N_V,
5725                                            finderArgs, this);
5726                    }
5727    
5728                    if (result instanceof WikiPage) {
5729                            WikiPage wikiPage = (WikiPage)result;
5730    
5731                            if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
5732                                            (nodeId != wikiPage.getNodeId()) ||
5733                                            (version != wikiPage.getVersion())) {
5734                                    result = null;
5735                            }
5736                    }
5737    
5738                    if (result == null) {
5739                            StringBundler query = new StringBundler(5);
5740    
5741                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5742    
5743                            query.append(_FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2);
5744    
5745                            query.append(_FINDER_COLUMN_R_N_V_NODEID_2);
5746    
5747                            query.append(_FINDER_COLUMN_R_N_V_VERSION_2);
5748    
5749                            String sql = query.toString();
5750    
5751                            Session session = null;
5752    
5753                            try {
5754                                    session = openSession();
5755    
5756                                    Query q = session.createQuery(sql);
5757    
5758                                    QueryPos qPos = QueryPos.getInstance(q);
5759    
5760                                    qPos.add(resourcePrimKey);
5761    
5762                                    qPos.add(nodeId);
5763    
5764                                    qPos.add(version);
5765    
5766                                    List<WikiPage> list = q.list();
5767    
5768                                    if (list.isEmpty()) {
5769                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
5770                                                    finderArgs, list);
5771                                    }
5772                                    else {
5773                                            WikiPage wikiPage = list.get(0);
5774    
5775                                            result = wikiPage;
5776    
5777                                            cacheResult(wikiPage);
5778    
5779                                            if ((wikiPage.getResourcePrimKey() != resourcePrimKey) ||
5780                                                            (wikiPage.getNodeId() != nodeId) ||
5781                                                            (wikiPage.getVersion() != version)) {
5782                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
5783                                                            finderArgs, wikiPage);
5784                                            }
5785                                    }
5786                            }
5787                            catch (Exception e) {
5788                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V,
5789                                            finderArgs);
5790    
5791                                    throw processException(e);
5792                            }
5793                            finally {
5794                                    closeSession(session);
5795                            }
5796                    }
5797    
5798                    if (result instanceof List<?>) {
5799                            return null;
5800                    }
5801                    else {
5802                            return (WikiPage)result;
5803                    }
5804            }
5805    
5806            /**
5807             * Removes the wiki page where resourcePrimKey = &#63; and nodeId = &#63; and version = &#63; from the database.
5808             *
5809             * @param resourcePrimKey the resource prim key
5810             * @param nodeId the node ID
5811             * @param version the version
5812             * @return the wiki page that was removed
5813             * @throws SystemException if a system exception occurred
5814             */
5815            public WikiPage removeByR_N_V(long resourcePrimKey, long nodeId,
5816                    double version) throws NoSuchPageException, SystemException {
5817                    WikiPage wikiPage = findByR_N_V(resourcePrimKey, nodeId, version);
5818    
5819                    return remove(wikiPage);
5820            }
5821    
5822            /**
5823             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and version = &#63;.
5824             *
5825             * @param resourcePrimKey the resource prim key
5826             * @param nodeId the node ID
5827             * @param version the version
5828             * @return the number of matching wiki pages
5829             * @throws SystemException if a system exception occurred
5830             */
5831            public int countByR_N_V(long resourcePrimKey, long nodeId, double version)
5832                    throws SystemException {
5833                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N_V;
5834    
5835                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, version };
5836    
5837                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5838                                    this);
5839    
5840                    if (count == null) {
5841                            StringBundler query = new StringBundler(4);
5842    
5843                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
5844    
5845                            query.append(_FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2);
5846    
5847                            query.append(_FINDER_COLUMN_R_N_V_NODEID_2);
5848    
5849                            query.append(_FINDER_COLUMN_R_N_V_VERSION_2);
5850    
5851                            String sql = query.toString();
5852    
5853                            Session session = null;
5854    
5855                            try {
5856                                    session = openSession();
5857    
5858                                    Query q = session.createQuery(sql);
5859    
5860                                    QueryPos qPos = QueryPos.getInstance(q);
5861    
5862                                    qPos.add(resourcePrimKey);
5863    
5864                                    qPos.add(nodeId);
5865    
5866                                    qPos.add(version);
5867    
5868                                    count = (Long)q.uniqueResult();
5869    
5870                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5871                            }
5872                            catch (Exception e) {
5873                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5874    
5875                                    throw processException(e);
5876                            }
5877                            finally {
5878                                    closeSession(session);
5879                            }
5880                    }
5881    
5882                    return count.intValue();
5883            }
5884    
5885            private static final String _FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
5886            private static final String _FINDER_COLUMN_R_N_V_NODEID_2 = "wikiPage.nodeId = ? AND ";
5887            private static final String _FINDER_COLUMN_R_N_V_VERSION_2 = "wikiPage.version = ?";
5888            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5889                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5890                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_N_H",
5891                            new String[] {
5892                                    Long.class.getName(), Long.class.getName(),
5893                                    Boolean.class.getName(),
5894                                    
5895                            Integer.class.getName(), Integer.class.getName(),
5896                                    OrderByComparator.class.getName()
5897                            });
5898            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5899                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5900                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_N_H",
5901                            new String[] {
5902                                    Long.class.getName(), Long.class.getName(),
5903                                    Boolean.class.getName()
5904                            },
5905                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
5906                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
5907                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
5908                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
5909                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
5910            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5911                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5912                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N_H",
5913                            new String[] {
5914                                    Long.class.getName(), Long.class.getName(),
5915                                    Boolean.class.getName()
5916                            });
5917    
5918            /**
5919             * Returns all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
5920             *
5921             * @param resourcePrimKey the resource prim key
5922             * @param nodeId the node ID
5923             * @param head the head
5924             * @return the matching wiki pages
5925             * @throws SystemException if a system exception occurred
5926             */
5927            public List<WikiPage> findByR_N_H(long resourcePrimKey, long nodeId,
5928                    boolean head) throws SystemException {
5929                    return findByR_N_H(resourcePrimKey, nodeId, head, QueryUtil.ALL_POS,
5930                            QueryUtil.ALL_POS, null);
5931            }
5932    
5933            /**
5934             * Returns a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
5935             *
5936             * <p>
5937             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5938             * </p>
5939             *
5940             * @param resourcePrimKey the resource prim key
5941             * @param nodeId the node ID
5942             * @param head the head
5943             * @param start the lower bound of the range of wiki pages
5944             * @param end the upper bound of the range of wiki pages (not inclusive)
5945             * @return the range of matching wiki pages
5946             * @throws SystemException if a system exception occurred
5947             */
5948            public List<WikiPage> findByR_N_H(long resourcePrimKey, long nodeId,
5949                    boolean head, int start, int end) throws SystemException {
5950                    return findByR_N_H(resourcePrimKey, nodeId, head, start, end, null);
5951            }
5952    
5953            /**
5954             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
5955             *
5956             * <p>
5957             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5958             * </p>
5959             *
5960             * @param resourcePrimKey the resource prim key
5961             * @param nodeId the node ID
5962             * @param head the head
5963             * @param start the lower bound of the range of wiki pages
5964             * @param end the upper bound of the range of wiki pages (not inclusive)
5965             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5966             * @return the ordered range of matching wiki pages
5967             * @throws SystemException if a system exception occurred
5968             */
5969            public List<WikiPage> findByR_N_H(long resourcePrimKey, long nodeId,
5970                    boolean head, int start, int end, OrderByComparator orderByComparator)
5971                    throws SystemException {
5972                    boolean pagination = true;
5973                    FinderPath finderPath = null;
5974                    Object[] finderArgs = null;
5975    
5976                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5977                                    (orderByComparator == null)) {
5978                            pagination = false;
5979                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H;
5980                            finderArgs = new Object[] { resourcePrimKey, nodeId, head };
5981                    }
5982                    else {
5983                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_H;
5984                            finderArgs = new Object[] {
5985                                            resourcePrimKey, nodeId, head,
5986                                            
5987                                            start, end, orderByComparator
5988                                    };
5989                    }
5990    
5991                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
5992                                    finderArgs, this);
5993    
5994                    if ((list != null) && !list.isEmpty()) {
5995                            for (WikiPage wikiPage : list) {
5996                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
5997                                                    (nodeId != wikiPage.getNodeId()) ||
5998                                                    (head != wikiPage.getHead())) {
5999                                            list = null;
6000    
6001                                            break;
6002                                    }
6003                            }
6004                    }
6005    
6006                    if (list == null) {
6007                            StringBundler query = null;
6008    
6009                            if (orderByComparator != null) {
6010                                    query = new StringBundler(5 +
6011                                                    (orderByComparator.getOrderByFields().length * 3));
6012                            }
6013                            else {
6014                                    query = new StringBundler(5);
6015                            }
6016    
6017                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6018    
6019                            query.append(_FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2);
6020    
6021                            query.append(_FINDER_COLUMN_R_N_H_NODEID_2);
6022    
6023                            query.append(_FINDER_COLUMN_R_N_H_HEAD_2);
6024    
6025                            if (orderByComparator != null) {
6026                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6027                                            orderByComparator);
6028                            }
6029                            else
6030                             if (pagination) {
6031                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6032                            }
6033    
6034                            String sql = query.toString();
6035    
6036                            Session session = null;
6037    
6038                            try {
6039                                    session = openSession();
6040    
6041                                    Query q = session.createQuery(sql);
6042    
6043                                    QueryPos qPos = QueryPos.getInstance(q);
6044    
6045                                    qPos.add(resourcePrimKey);
6046    
6047                                    qPos.add(nodeId);
6048    
6049                                    qPos.add(head);
6050    
6051                                    if (!pagination) {
6052                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6053                                                            start, end, false);
6054    
6055                                            Collections.sort(list);
6056    
6057                                            list = new UnmodifiableList<WikiPage>(list);
6058                                    }
6059                                    else {
6060                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6061                                                            start, end);
6062                                    }
6063    
6064                                    cacheResult(list);
6065    
6066                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6067                            }
6068                            catch (Exception e) {
6069                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6070    
6071                                    throw processException(e);
6072                            }
6073                            finally {
6074                                    closeSession(session);
6075                            }
6076                    }
6077    
6078                    return list;
6079            }
6080    
6081            /**
6082             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6083             *
6084             * @param resourcePrimKey the resource prim key
6085             * @param nodeId the node ID
6086             * @param head the head
6087             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6088             * @return the first matching wiki page
6089             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6090             * @throws SystemException if a system exception occurred
6091             */
6092            public WikiPage findByR_N_H_First(long resourcePrimKey, long nodeId,
6093                    boolean head, OrderByComparator orderByComparator)
6094                    throws NoSuchPageException, SystemException {
6095                    WikiPage wikiPage = fetchByR_N_H_First(resourcePrimKey, nodeId, head,
6096                                    orderByComparator);
6097    
6098                    if (wikiPage != null) {
6099                            return wikiPage;
6100                    }
6101    
6102                    StringBundler msg = new StringBundler(8);
6103    
6104                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6105    
6106                    msg.append("resourcePrimKey=");
6107                    msg.append(resourcePrimKey);
6108    
6109                    msg.append(", nodeId=");
6110                    msg.append(nodeId);
6111    
6112                    msg.append(", head=");
6113                    msg.append(head);
6114    
6115                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6116    
6117                    throw new NoSuchPageException(msg.toString());
6118            }
6119    
6120            /**
6121             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6122             *
6123             * @param resourcePrimKey the resource prim key
6124             * @param nodeId the node ID
6125             * @param head the head
6126             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6127             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
6128             * @throws SystemException if a system exception occurred
6129             */
6130            public WikiPage fetchByR_N_H_First(long resourcePrimKey, long nodeId,
6131                    boolean head, OrderByComparator orderByComparator)
6132                    throws SystemException {
6133                    List<WikiPage> list = findByR_N_H(resourcePrimKey, nodeId, head, 0, 1,
6134                                    orderByComparator);
6135    
6136                    if (!list.isEmpty()) {
6137                            return list.get(0);
6138                    }
6139    
6140                    return null;
6141            }
6142    
6143            /**
6144             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6145             *
6146             * @param resourcePrimKey the resource prim key
6147             * @param nodeId the node ID
6148             * @param head the head
6149             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6150             * @return the last matching wiki page
6151             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6152             * @throws SystemException if a system exception occurred
6153             */
6154            public WikiPage findByR_N_H_Last(long resourcePrimKey, long nodeId,
6155                    boolean head, OrderByComparator orderByComparator)
6156                    throws NoSuchPageException, SystemException {
6157                    WikiPage wikiPage = fetchByR_N_H_Last(resourcePrimKey, nodeId, head,
6158                                    orderByComparator);
6159    
6160                    if (wikiPage != null) {
6161                            return wikiPage;
6162                    }
6163    
6164                    StringBundler msg = new StringBundler(8);
6165    
6166                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6167    
6168                    msg.append("resourcePrimKey=");
6169                    msg.append(resourcePrimKey);
6170    
6171                    msg.append(", nodeId=");
6172                    msg.append(nodeId);
6173    
6174                    msg.append(", head=");
6175                    msg.append(head);
6176    
6177                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6178    
6179                    throw new NoSuchPageException(msg.toString());
6180            }
6181    
6182            /**
6183             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6184             *
6185             * @param resourcePrimKey the resource prim key
6186             * @param nodeId the node ID
6187             * @param head the head
6188             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6189             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
6190             * @throws SystemException if a system exception occurred
6191             */
6192            public WikiPage fetchByR_N_H_Last(long resourcePrimKey, long nodeId,
6193                    boolean head, OrderByComparator orderByComparator)
6194                    throws SystemException {
6195                    int count = countByR_N_H(resourcePrimKey, nodeId, head);
6196    
6197                    List<WikiPage> list = findByR_N_H(resourcePrimKey, nodeId, head,
6198                                    count - 1, count, orderByComparator);
6199    
6200                    if (!list.isEmpty()) {
6201                            return list.get(0);
6202                    }
6203    
6204                    return null;
6205            }
6206    
6207            /**
6208             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6209             *
6210             * @param pageId the primary key of the current wiki page
6211             * @param resourcePrimKey the resource prim key
6212             * @param nodeId the node ID
6213             * @param head the head
6214             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6215             * @return the previous, current, and next wiki page
6216             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
6217             * @throws SystemException if a system exception occurred
6218             */
6219            public WikiPage[] findByR_N_H_PrevAndNext(long pageId,
6220                    long resourcePrimKey, long nodeId, boolean head,
6221                    OrderByComparator orderByComparator)
6222                    throws NoSuchPageException, SystemException {
6223                    WikiPage wikiPage = findByPrimaryKey(pageId);
6224    
6225                    Session session = null;
6226    
6227                    try {
6228                            session = openSession();
6229    
6230                            WikiPage[] array = new WikiPageImpl[3];
6231    
6232                            array[0] = getByR_N_H_PrevAndNext(session, wikiPage,
6233                                            resourcePrimKey, nodeId, head, orderByComparator, true);
6234    
6235                            array[1] = wikiPage;
6236    
6237                            array[2] = getByR_N_H_PrevAndNext(session, wikiPage,
6238                                            resourcePrimKey, nodeId, head, orderByComparator, false);
6239    
6240                            return array;
6241                    }
6242                    catch (Exception e) {
6243                            throw processException(e);
6244                    }
6245                    finally {
6246                            closeSession(session);
6247                    }
6248            }
6249    
6250            protected WikiPage getByR_N_H_PrevAndNext(Session session,
6251                    WikiPage wikiPage, long resourcePrimKey, long nodeId, boolean head,
6252                    OrderByComparator orderByComparator, boolean previous) {
6253                    StringBundler query = null;
6254    
6255                    if (orderByComparator != null) {
6256                            query = new StringBundler(6 +
6257                                            (orderByComparator.getOrderByFields().length * 6));
6258                    }
6259                    else {
6260                            query = new StringBundler(3);
6261                    }
6262    
6263                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6264    
6265                    query.append(_FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2);
6266    
6267                    query.append(_FINDER_COLUMN_R_N_H_NODEID_2);
6268    
6269                    query.append(_FINDER_COLUMN_R_N_H_HEAD_2);
6270    
6271                    if (orderByComparator != null) {
6272                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6273    
6274                            if (orderByConditionFields.length > 0) {
6275                                    query.append(WHERE_AND);
6276                            }
6277    
6278                            for (int i = 0; i < orderByConditionFields.length; i++) {
6279                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6280                                    query.append(orderByConditionFields[i]);
6281    
6282                                    if ((i + 1) < orderByConditionFields.length) {
6283                                            if (orderByComparator.isAscending() ^ previous) {
6284                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6285                                            }
6286                                            else {
6287                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6288                                            }
6289                                    }
6290                                    else {
6291                                            if (orderByComparator.isAscending() ^ previous) {
6292                                                    query.append(WHERE_GREATER_THAN);
6293                                            }
6294                                            else {
6295                                                    query.append(WHERE_LESSER_THAN);
6296                                            }
6297                                    }
6298                            }
6299    
6300                            query.append(ORDER_BY_CLAUSE);
6301    
6302                            String[] orderByFields = orderByComparator.getOrderByFields();
6303    
6304                            for (int i = 0; i < orderByFields.length; i++) {
6305                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6306                                    query.append(orderByFields[i]);
6307    
6308                                    if ((i + 1) < orderByFields.length) {
6309                                            if (orderByComparator.isAscending() ^ previous) {
6310                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6311                                            }
6312                                            else {
6313                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6314                                            }
6315                                    }
6316                                    else {
6317                                            if (orderByComparator.isAscending() ^ previous) {
6318                                                    query.append(ORDER_BY_ASC);
6319                                            }
6320                                            else {
6321                                                    query.append(ORDER_BY_DESC);
6322                                            }
6323                                    }
6324                            }
6325                    }
6326                    else {
6327                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6328                    }
6329    
6330                    String sql = query.toString();
6331    
6332                    Query q = session.createQuery(sql);
6333    
6334                    q.setFirstResult(0);
6335                    q.setMaxResults(2);
6336    
6337                    QueryPos qPos = QueryPos.getInstance(q);
6338    
6339                    qPos.add(resourcePrimKey);
6340    
6341                    qPos.add(nodeId);
6342    
6343                    qPos.add(head);
6344    
6345                    if (orderByComparator != null) {
6346                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
6347    
6348                            for (Object value : values) {
6349                                    qPos.add(value);
6350                            }
6351                    }
6352    
6353                    List<WikiPage> list = q.list();
6354    
6355                    if (list.size() == 2) {
6356                            return list.get(1);
6357                    }
6358                    else {
6359                            return null;
6360                    }
6361            }
6362    
6363            /**
6364             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63; from the database.
6365             *
6366             * @param resourcePrimKey the resource prim key
6367             * @param nodeId the node ID
6368             * @param head the head
6369             * @throws SystemException if a system exception occurred
6370             */
6371            public void removeByR_N_H(long resourcePrimKey, long nodeId, boolean head)
6372                    throws SystemException {
6373                    for (WikiPage wikiPage : findByR_N_H(resourcePrimKey, nodeId, head,
6374                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6375                            remove(wikiPage);
6376                    }
6377            }
6378    
6379            /**
6380             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6381             *
6382             * @param resourcePrimKey the resource prim key
6383             * @param nodeId the node ID
6384             * @param head the head
6385             * @return the number of matching wiki pages
6386             * @throws SystemException if a system exception occurred
6387             */
6388            public int countByR_N_H(long resourcePrimKey, long nodeId, boolean head)
6389                    throws SystemException {
6390                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N_H;
6391    
6392                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, head };
6393    
6394                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6395                                    this);
6396    
6397                    if (count == null) {
6398                            StringBundler query = new StringBundler(4);
6399    
6400                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
6401    
6402                            query.append(_FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2);
6403    
6404                            query.append(_FINDER_COLUMN_R_N_H_NODEID_2);
6405    
6406                            query.append(_FINDER_COLUMN_R_N_H_HEAD_2);
6407    
6408                            String sql = query.toString();
6409    
6410                            Session session = null;
6411    
6412                            try {
6413                                    session = openSession();
6414    
6415                                    Query q = session.createQuery(sql);
6416    
6417                                    QueryPos qPos = QueryPos.getInstance(q);
6418    
6419                                    qPos.add(resourcePrimKey);
6420    
6421                                    qPos.add(nodeId);
6422    
6423                                    qPos.add(head);
6424    
6425                                    count = (Long)q.uniqueResult();
6426    
6427                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6428                            }
6429                            catch (Exception e) {
6430                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6431    
6432                                    throw processException(e);
6433                            }
6434                            finally {
6435                                    closeSession(session);
6436                            }
6437                    }
6438    
6439                    return count.intValue();
6440            }
6441    
6442            private static final String _FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
6443            private static final String _FINDER_COLUMN_R_N_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
6444            private static final String _FINDER_COLUMN_R_N_H_HEAD_2 = "wikiPage.head = ?";
6445            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6446                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
6447                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_N_S",
6448                            new String[] {
6449                                    Long.class.getName(), Long.class.getName(),
6450                                    Integer.class.getName(),
6451                                    
6452                            Integer.class.getName(), Integer.class.getName(),
6453                                    OrderByComparator.class.getName()
6454                            });
6455            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6456                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
6457                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_N_S",
6458                            new String[] {
6459                                    Long.class.getName(), Long.class.getName(),
6460                                    Integer.class.getName()
6461                            },
6462                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
6463                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
6464                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
6465                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
6466                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
6467            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6468                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6469                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N_S",
6470                            new String[] {
6471                                    Long.class.getName(), Long.class.getName(),
6472                                    Integer.class.getName()
6473                            });
6474    
6475            /**
6476             * Returns all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6477             *
6478             * @param resourcePrimKey the resource prim key
6479             * @param nodeId the node ID
6480             * @param status the status
6481             * @return the matching wiki pages
6482             * @throws SystemException if a system exception occurred
6483             */
6484            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
6485                    int status) throws SystemException {
6486                    return findByR_N_S(resourcePrimKey, nodeId, status, QueryUtil.ALL_POS,
6487                            QueryUtil.ALL_POS, null);
6488            }
6489    
6490            /**
6491             * Returns a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6492             *
6493             * <p>
6494             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6495             * </p>
6496             *
6497             * @param resourcePrimKey the resource prim key
6498             * @param nodeId the node ID
6499             * @param status the status
6500             * @param start the lower bound of the range of wiki pages
6501             * @param end the upper bound of the range of wiki pages (not inclusive)
6502             * @return the range of matching wiki pages
6503             * @throws SystemException if a system exception occurred
6504             */
6505            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
6506                    int status, int start, int end) throws SystemException {
6507                    return findByR_N_S(resourcePrimKey, nodeId, status, start, end, null);
6508            }
6509    
6510            /**
6511             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6512             *
6513             * <p>
6514             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6515             * </p>
6516             *
6517             * @param resourcePrimKey the resource prim key
6518             * @param nodeId the node ID
6519             * @param status the status
6520             * @param start the lower bound of the range of wiki pages
6521             * @param end the upper bound of the range of wiki pages (not inclusive)
6522             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6523             * @return the ordered range of matching wiki pages
6524             * @throws SystemException if a system exception occurred
6525             */
6526            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
6527                    int status, int start, int end, OrderByComparator orderByComparator)
6528                    throws SystemException {
6529                    boolean pagination = true;
6530                    FinderPath finderPath = null;
6531                    Object[] finderArgs = null;
6532    
6533                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6534                                    (orderByComparator == null)) {
6535                            pagination = false;
6536                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S;
6537                            finderArgs = new Object[] { resourcePrimKey, nodeId, status };
6538                    }
6539                    else {
6540                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_S;
6541                            finderArgs = new Object[] {
6542                                            resourcePrimKey, nodeId, status,
6543                                            
6544                                            start, end, orderByComparator
6545                                    };
6546                    }
6547    
6548                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
6549                                    finderArgs, this);
6550    
6551                    if ((list != null) && !list.isEmpty()) {
6552                            for (WikiPage wikiPage : list) {
6553                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
6554                                                    (nodeId != wikiPage.getNodeId()) ||
6555                                                    (status != wikiPage.getStatus())) {
6556                                            list = null;
6557    
6558                                            break;
6559                                    }
6560                            }
6561                    }
6562    
6563                    if (list == null) {
6564                            StringBundler query = null;
6565    
6566                            if (orderByComparator != null) {
6567                                    query = new StringBundler(5 +
6568                                                    (orderByComparator.getOrderByFields().length * 3));
6569                            }
6570                            else {
6571                                    query = new StringBundler(5);
6572                            }
6573    
6574                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6575    
6576                            query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
6577    
6578                            query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
6579    
6580                            query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
6581    
6582                            if (orderByComparator != null) {
6583                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6584                                            orderByComparator);
6585                            }
6586                            else
6587                             if (pagination) {
6588                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6589                            }
6590    
6591                            String sql = query.toString();
6592    
6593                            Session session = null;
6594    
6595                            try {
6596                                    session = openSession();
6597    
6598                                    Query q = session.createQuery(sql);
6599    
6600                                    QueryPos qPos = QueryPos.getInstance(q);
6601    
6602                                    qPos.add(resourcePrimKey);
6603    
6604                                    qPos.add(nodeId);
6605    
6606                                    qPos.add(status);
6607    
6608                                    if (!pagination) {
6609                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6610                                                            start, end, false);
6611    
6612                                            Collections.sort(list);
6613    
6614                                            list = new UnmodifiableList<WikiPage>(list);
6615                                    }
6616                                    else {
6617                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6618                                                            start, end);
6619                                    }
6620    
6621                                    cacheResult(list);
6622    
6623                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6624                            }
6625                            catch (Exception e) {
6626                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6627    
6628                                    throw processException(e);
6629                            }
6630                            finally {
6631                                    closeSession(session);
6632                            }
6633                    }
6634    
6635                    return list;
6636            }
6637    
6638            /**
6639             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6640             *
6641             * @param resourcePrimKey the resource prim key
6642             * @param nodeId the node ID
6643             * @param status the status
6644             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6645             * @return the first matching wiki page
6646             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6647             * @throws SystemException if a system exception occurred
6648             */
6649            public WikiPage findByR_N_S_First(long resourcePrimKey, long nodeId,
6650                    int status, OrderByComparator orderByComparator)
6651                    throws NoSuchPageException, SystemException {
6652                    WikiPage wikiPage = fetchByR_N_S_First(resourcePrimKey, nodeId, status,
6653                                    orderByComparator);
6654    
6655                    if (wikiPage != null) {
6656                            return wikiPage;
6657                    }
6658    
6659                    StringBundler msg = new StringBundler(8);
6660    
6661                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6662    
6663                    msg.append("resourcePrimKey=");
6664                    msg.append(resourcePrimKey);
6665    
6666                    msg.append(", nodeId=");
6667                    msg.append(nodeId);
6668    
6669                    msg.append(", status=");
6670                    msg.append(status);
6671    
6672                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6673    
6674                    throw new NoSuchPageException(msg.toString());
6675            }
6676    
6677            /**
6678             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6679             *
6680             * @param resourcePrimKey the resource prim key
6681             * @param nodeId the node ID
6682             * @param status the status
6683             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6684             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
6685             * @throws SystemException if a system exception occurred
6686             */
6687            public WikiPage fetchByR_N_S_First(long resourcePrimKey, long nodeId,
6688                    int status, OrderByComparator orderByComparator)
6689                    throws SystemException {
6690                    List<WikiPage> list = findByR_N_S(resourcePrimKey, nodeId, status, 0,
6691                                    1, orderByComparator);
6692    
6693                    if (!list.isEmpty()) {
6694                            return list.get(0);
6695                    }
6696    
6697                    return null;
6698            }
6699    
6700            /**
6701             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6702             *
6703             * @param resourcePrimKey the resource prim key
6704             * @param nodeId the node ID
6705             * @param status the status
6706             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6707             * @return the last matching wiki page
6708             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6709             * @throws SystemException if a system exception occurred
6710             */
6711            public WikiPage findByR_N_S_Last(long resourcePrimKey, long nodeId,
6712                    int status, OrderByComparator orderByComparator)
6713                    throws NoSuchPageException, SystemException {
6714                    WikiPage wikiPage = fetchByR_N_S_Last(resourcePrimKey, nodeId, status,
6715                                    orderByComparator);
6716    
6717                    if (wikiPage != null) {
6718                            return wikiPage;
6719                    }
6720    
6721                    StringBundler msg = new StringBundler(8);
6722    
6723                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6724    
6725                    msg.append("resourcePrimKey=");
6726                    msg.append(resourcePrimKey);
6727    
6728                    msg.append(", nodeId=");
6729                    msg.append(nodeId);
6730    
6731                    msg.append(", status=");
6732                    msg.append(status);
6733    
6734                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6735    
6736                    throw new NoSuchPageException(msg.toString());
6737            }
6738    
6739            /**
6740             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6741             *
6742             * @param resourcePrimKey the resource prim key
6743             * @param nodeId the node ID
6744             * @param status the status
6745             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6746             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
6747             * @throws SystemException if a system exception occurred
6748             */
6749            public WikiPage fetchByR_N_S_Last(long resourcePrimKey, long nodeId,
6750                    int status, OrderByComparator orderByComparator)
6751                    throws SystemException {
6752                    int count = countByR_N_S(resourcePrimKey, nodeId, status);
6753    
6754                    List<WikiPage> list = findByR_N_S(resourcePrimKey, nodeId, status,
6755                                    count - 1, count, orderByComparator);
6756    
6757                    if (!list.isEmpty()) {
6758                            return list.get(0);
6759                    }
6760    
6761                    return null;
6762            }
6763    
6764            /**
6765             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6766             *
6767             * @param pageId the primary key of the current wiki page
6768             * @param resourcePrimKey the resource prim key
6769             * @param nodeId the node ID
6770             * @param status the status
6771             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6772             * @return the previous, current, and next wiki page
6773             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
6774             * @throws SystemException if a system exception occurred
6775             */
6776            public WikiPage[] findByR_N_S_PrevAndNext(long pageId,
6777                    long resourcePrimKey, long nodeId, int status,
6778                    OrderByComparator orderByComparator)
6779                    throws NoSuchPageException, SystemException {
6780                    WikiPage wikiPage = findByPrimaryKey(pageId);
6781    
6782                    Session session = null;
6783    
6784                    try {
6785                            session = openSession();
6786    
6787                            WikiPage[] array = new WikiPageImpl[3];
6788    
6789                            array[0] = getByR_N_S_PrevAndNext(session, wikiPage,
6790                                            resourcePrimKey, nodeId, status, orderByComparator, true);
6791    
6792                            array[1] = wikiPage;
6793    
6794                            array[2] = getByR_N_S_PrevAndNext(session, wikiPage,
6795                                            resourcePrimKey, nodeId, status, orderByComparator, false);
6796    
6797                            return array;
6798                    }
6799                    catch (Exception e) {
6800                            throw processException(e);
6801                    }
6802                    finally {
6803                            closeSession(session);
6804                    }
6805            }
6806    
6807            protected WikiPage getByR_N_S_PrevAndNext(Session session,
6808                    WikiPage wikiPage, long resourcePrimKey, long nodeId, int status,
6809                    OrderByComparator orderByComparator, boolean previous) {
6810                    StringBundler query = null;
6811    
6812                    if (orderByComparator != null) {
6813                            query = new StringBundler(6 +
6814                                            (orderByComparator.getOrderByFields().length * 6));
6815                    }
6816                    else {
6817                            query = new StringBundler(3);
6818                    }
6819    
6820                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6821    
6822                    query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
6823    
6824                    query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
6825    
6826                    query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
6827    
6828                    if (orderByComparator != null) {
6829                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6830    
6831                            if (orderByConditionFields.length > 0) {
6832                                    query.append(WHERE_AND);
6833                            }
6834    
6835                            for (int i = 0; i < orderByConditionFields.length; i++) {
6836                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6837                                    query.append(orderByConditionFields[i]);
6838    
6839                                    if ((i + 1) < orderByConditionFields.length) {
6840                                            if (orderByComparator.isAscending() ^ previous) {
6841                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6842                                            }
6843                                            else {
6844                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6845                                            }
6846                                    }
6847                                    else {
6848                                            if (orderByComparator.isAscending() ^ previous) {
6849                                                    query.append(WHERE_GREATER_THAN);
6850                                            }
6851                                            else {
6852                                                    query.append(WHERE_LESSER_THAN);
6853                                            }
6854                                    }
6855                            }
6856    
6857                            query.append(ORDER_BY_CLAUSE);
6858    
6859                            String[] orderByFields = orderByComparator.getOrderByFields();
6860    
6861                            for (int i = 0; i < orderByFields.length; i++) {
6862                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6863                                    query.append(orderByFields[i]);
6864    
6865                                    if ((i + 1) < orderByFields.length) {
6866                                            if (orderByComparator.isAscending() ^ previous) {
6867                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6868                                            }
6869                                            else {
6870                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6871                                            }
6872                                    }
6873                                    else {
6874                                            if (orderByComparator.isAscending() ^ previous) {
6875                                                    query.append(ORDER_BY_ASC);
6876                                            }
6877                                            else {
6878                                                    query.append(ORDER_BY_DESC);
6879                                            }
6880                                    }
6881                            }
6882                    }
6883                    else {
6884                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6885                    }
6886    
6887                    String sql = query.toString();
6888    
6889                    Query q = session.createQuery(sql);
6890    
6891                    q.setFirstResult(0);
6892                    q.setMaxResults(2);
6893    
6894                    QueryPos qPos = QueryPos.getInstance(q);
6895    
6896                    qPos.add(resourcePrimKey);
6897    
6898                    qPos.add(nodeId);
6899    
6900                    qPos.add(status);
6901    
6902                    if (orderByComparator != null) {
6903                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
6904    
6905                            for (Object value : values) {
6906                                    qPos.add(value);
6907                            }
6908                    }
6909    
6910                    List<WikiPage> list = q.list();
6911    
6912                    if (list.size() == 2) {
6913                            return list.get(1);
6914                    }
6915                    else {
6916                            return null;
6917                    }
6918            }
6919    
6920            /**
6921             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63; from the database.
6922             *
6923             * @param resourcePrimKey the resource prim key
6924             * @param nodeId the node ID
6925             * @param status the status
6926             * @throws SystemException if a system exception occurred
6927             */
6928            public void removeByR_N_S(long resourcePrimKey, long nodeId, int status)
6929                    throws SystemException {
6930                    for (WikiPage wikiPage : findByR_N_S(resourcePrimKey, nodeId, status,
6931                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6932                            remove(wikiPage);
6933                    }
6934            }
6935    
6936            /**
6937             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6938             *
6939             * @param resourcePrimKey the resource prim key
6940             * @param nodeId the node ID
6941             * @param status the status
6942             * @return the number of matching wiki pages
6943             * @throws SystemException if a system exception occurred
6944             */
6945            public int countByR_N_S(long resourcePrimKey, long nodeId, int status)
6946                    throws SystemException {
6947                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N_S;
6948    
6949                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, status };
6950    
6951                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6952                                    this);
6953    
6954                    if (count == null) {
6955                            StringBundler query = new StringBundler(4);
6956    
6957                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
6958    
6959                            query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
6960    
6961                            query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
6962    
6963                            query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
6964    
6965                            String sql = query.toString();
6966    
6967                            Session session = null;
6968    
6969                            try {
6970                                    session = openSession();
6971    
6972                                    Query q = session.createQuery(sql);
6973    
6974                                    QueryPos qPos = QueryPos.getInstance(q);
6975    
6976                                    qPos.add(resourcePrimKey);
6977    
6978                                    qPos.add(nodeId);
6979    
6980                                    qPos.add(status);
6981    
6982                                    count = (Long)q.uniqueResult();
6983    
6984                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6985                            }
6986                            catch (Exception e) {
6987                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6988    
6989                                    throw processException(e);
6990                            }
6991                            finally {
6992                                    closeSession(session);
6993                            }
6994                    }
6995    
6996                    return count.intValue();
6997            }
6998    
6999            private static final String _FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
7000            private static final String _FINDER_COLUMN_R_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
7001            private static final String _FINDER_COLUMN_R_N_S_STATUS_2 = "wikiPage.status = ?";
7002            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7003                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
7004                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H",
7005                            new String[] {
7006                                    Long.class.getName(), Long.class.getName(),
7007                                    Boolean.class.getName(),
7008                                    
7009                            Integer.class.getName(), Integer.class.getName(),
7010                                    OrderByComparator.class.getName()
7011                            });
7012            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7013                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
7014                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H",
7015                            new String[] {
7016                                    Long.class.getName(), Long.class.getName(),
7017                                    Boolean.class.getName()
7018                            },
7019                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
7020                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
7021                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
7022                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
7023                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
7024            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7025                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7026                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H",
7027                            new String[] {
7028                                    Long.class.getName(), Long.class.getName(),
7029                                    Boolean.class.getName()
7030                            });
7031    
7032            /**
7033             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
7034             *
7035             * @param groupId the group ID
7036             * @param nodeId the node ID
7037             * @param head the head
7038             * @return the matching wiki pages
7039             * @throws SystemException if a system exception occurred
7040             */
7041            public List<WikiPage> findByG_N_H(long groupId, long nodeId, boolean head)
7042                    throws SystemException {
7043                    return findByG_N_H(groupId, nodeId, head, QueryUtil.ALL_POS,
7044                            QueryUtil.ALL_POS, null);
7045            }
7046    
7047            /**
7048             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
7049             *
7050             * <p>
7051             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7052             * </p>
7053             *
7054             * @param groupId the group ID
7055             * @param nodeId the node ID
7056             * @param head the head
7057             * @param start the lower bound of the range of wiki pages
7058             * @param end the upper bound of the range of wiki pages (not inclusive)
7059             * @return the range of matching wiki pages
7060             * @throws SystemException if a system exception occurred
7061             */
7062            public List<WikiPage> findByG_N_H(long groupId, long nodeId, boolean head,
7063                    int start, int end) throws SystemException {
7064                    return findByG_N_H(groupId, nodeId, head, start, end, null);
7065            }
7066    
7067            /**
7068             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
7069             *
7070             * <p>
7071             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7072             * </p>
7073             *
7074             * @param groupId the group ID
7075             * @param nodeId the node ID
7076             * @param head the head
7077             * @param start the lower bound of the range of wiki pages
7078             * @param end the upper bound of the range of wiki pages (not inclusive)
7079             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7080             * @return the ordered range of matching wiki pages
7081             * @throws SystemException if a system exception occurred
7082             */
7083            public List<WikiPage> findByG_N_H(long groupId, long nodeId, boolean head,
7084                    int start, int end, OrderByComparator orderByComparator)
7085                    throws SystemException {
7086                    boolean pagination = true;
7087                    FinderPath finderPath = null;
7088                    Object[] finderArgs = null;
7089    
7090                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7091                                    (orderByComparator == null)) {
7092                            pagination = false;
7093                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H;
7094                            finderArgs = new Object[] { groupId, nodeId, head };
7095                    }
7096                    else {
7097                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H;
7098                            finderArgs = new Object[] {
7099                                            groupId, nodeId, head,
7100                                            
7101                                            start, end, orderByComparator
7102                                    };
7103                    }
7104    
7105                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
7106                                    finderArgs, this);
7107    
7108                    if ((list != null) && !list.isEmpty()) {
7109                            for (WikiPage wikiPage : list) {
7110                                    if ((groupId != wikiPage.getGroupId()) ||
7111                                                    (nodeId != wikiPage.getNodeId()) ||
7112                                                    (head != wikiPage.getHead())) {
7113                                            list = null;
7114    
7115                                            break;
7116                                    }
7117                            }
7118                    }
7119    
7120                    if (list == null) {
7121                            StringBundler query = null;
7122    
7123                            if (orderByComparator != null) {
7124                                    query = new StringBundler(5 +
7125                                                    (orderByComparator.getOrderByFields().length * 3));
7126                            }
7127                            else {
7128                                    query = new StringBundler(5);
7129                            }
7130    
7131                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
7132    
7133                            query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7134    
7135                            query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7136    
7137                            query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7138    
7139                            if (orderByComparator != null) {
7140                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7141                                            orderByComparator);
7142                            }
7143                            else
7144                             if (pagination) {
7145                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7146                            }
7147    
7148                            String sql = query.toString();
7149    
7150                            Session session = null;
7151    
7152                            try {
7153                                    session = openSession();
7154    
7155                                    Query q = session.createQuery(sql);
7156    
7157                                    QueryPos qPos = QueryPos.getInstance(q);
7158    
7159                                    qPos.add(groupId);
7160    
7161                                    qPos.add(nodeId);
7162    
7163                                    qPos.add(head);
7164    
7165                                    if (!pagination) {
7166                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
7167                                                            start, end, false);
7168    
7169                                            Collections.sort(list);
7170    
7171                                            list = new UnmodifiableList<WikiPage>(list);
7172                                    }
7173                                    else {
7174                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
7175                                                            start, end);
7176                                    }
7177    
7178                                    cacheResult(list);
7179    
7180                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7181                            }
7182                            catch (Exception e) {
7183                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7184    
7185                                    throw processException(e);
7186                            }
7187                            finally {
7188                                    closeSession(session);
7189                            }
7190                    }
7191    
7192                    return list;
7193            }
7194    
7195            /**
7196             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7197             *
7198             * @param groupId the group ID
7199             * @param nodeId the node ID
7200             * @param head the head
7201             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7202             * @return the first matching wiki page
7203             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
7204             * @throws SystemException if a system exception occurred
7205             */
7206            public WikiPage findByG_N_H_First(long groupId, long nodeId, boolean head,
7207                    OrderByComparator orderByComparator)
7208                    throws NoSuchPageException, SystemException {
7209                    WikiPage wikiPage = fetchByG_N_H_First(groupId, nodeId, head,
7210                                    orderByComparator);
7211    
7212                    if (wikiPage != null) {
7213                            return wikiPage;
7214                    }
7215    
7216                    StringBundler msg = new StringBundler(8);
7217    
7218                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7219    
7220                    msg.append("groupId=");
7221                    msg.append(groupId);
7222    
7223                    msg.append(", nodeId=");
7224                    msg.append(nodeId);
7225    
7226                    msg.append(", head=");
7227                    msg.append(head);
7228    
7229                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7230    
7231                    throw new NoSuchPageException(msg.toString());
7232            }
7233    
7234            /**
7235             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7236             *
7237             * @param groupId the group ID
7238             * @param nodeId the node ID
7239             * @param head the head
7240             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7241             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
7242             * @throws SystemException if a system exception occurred
7243             */
7244            public WikiPage fetchByG_N_H_First(long groupId, long nodeId, boolean head,
7245                    OrderByComparator orderByComparator) throws SystemException {
7246                    List<WikiPage> list = findByG_N_H(groupId, nodeId, head, 0, 1,
7247                                    orderByComparator);
7248    
7249                    if (!list.isEmpty()) {
7250                            return list.get(0);
7251                    }
7252    
7253                    return null;
7254            }
7255    
7256            /**
7257             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7258             *
7259             * @param groupId the group ID
7260             * @param nodeId the node ID
7261             * @param head the head
7262             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7263             * @return the last matching wiki page
7264             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
7265             * @throws SystemException if a system exception occurred
7266             */
7267            public WikiPage findByG_N_H_Last(long groupId, long nodeId, boolean head,
7268                    OrderByComparator orderByComparator)
7269                    throws NoSuchPageException, SystemException {
7270                    WikiPage wikiPage = fetchByG_N_H_Last(groupId, nodeId, head,
7271                                    orderByComparator);
7272    
7273                    if (wikiPage != null) {
7274                            return wikiPage;
7275                    }
7276    
7277                    StringBundler msg = new StringBundler(8);
7278    
7279                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7280    
7281                    msg.append("groupId=");
7282                    msg.append(groupId);
7283    
7284                    msg.append(", nodeId=");
7285                    msg.append(nodeId);
7286    
7287                    msg.append(", head=");
7288                    msg.append(head);
7289    
7290                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7291    
7292                    throw new NoSuchPageException(msg.toString());
7293            }
7294    
7295            /**
7296             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7297             *
7298             * @param groupId the group ID
7299             * @param nodeId the node ID
7300             * @param head the head
7301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7302             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
7303             * @throws SystemException if a system exception occurred
7304             */
7305            public WikiPage fetchByG_N_H_Last(long groupId, long nodeId, boolean head,
7306                    OrderByComparator orderByComparator) throws SystemException {
7307                    int count = countByG_N_H(groupId, nodeId, head);
7308    
7309                    List<WikiPage> list = findByG_N_H(groupId, nodeId, head, count - 1,
7310                                    count, orderByComparator);
7311    
7312                    if (!list.isEmpty()) {
7313                            return list.get(0);
7314                    }
7315    
7316                    return null;
7317            }
7318    
7319            /**
7320             * Returns the wiki pages before and after the current wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7321             *
7322             * @param pageId the primary key of the current wiki page
7323             * @param groupId the group ID
7324             * @param nodeId the node ID
7325             * @param head the head
7326             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7327             * @return the previous, current, and next wiki page
7328             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
7329             * @throws SystemException if a system exception occurred
7330             */
7331            public WikiPage[] findByG_N_H_PrevAndNext(long pageId, long groupId,
7332                    long nodeId, boolean head, OrderByComparator orderByComparator)
7333                    throws NoSuchPageException, SystemException {
7334                    WikiPage wikiPage = findByPrimaryKey(pageId);
7335    
7336                    Session session = null;
7337    
7338                    try {
7339                            session = openSession();
7340    
7341                            WikiPage[] array = new WikiPageImpl[3];
7342    
7343                            array[0] = getByG_N_H_PrevAndNext(session, wikiPage, groupId,
7344                                            nodeId, head, orderByComparator, true);
7345    
7346                            array[1] = wikiPage;
7347    
7348                            array[2] = getByG_N_H_PrevAndNext(session, wikiPage, groupId,
7349                                            nodeId, head, orderByComparator, false);
7350    
7351                            return array;
7352                    }
7353                    catch (Exception e) {
7354                            throw processException(e);
7355                    }
7356                    finally {
7357                            closeSession(session);
7358                    }
7359            }
7360    
7361            protected WikiPage getByG_N_H_PrevAndNext(Session session,
7362                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
7363                    OrderByComparator orderByComparator, boolean previous) {
7364                    StringBundler query = null;
7365    
7366                    if (orderByComparator != null) {
7367                            query = new StringBundler(6 +
7368                                            (orderByComparator.getOrderByFields().length * 6));
7369                    }
7370                    else {
7371                            query = new StringBundler(3);
7372                    }
7373    
7374                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
7375    
7376                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7377    
7378                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7379    
7380                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7381    
7382                    if (orderByComparator != null) {
7383                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7384    
7385                            if (orderByConditionFields.length > 0) {
7386                                    query.append(WHERE_AND);
7387                            }
7388    
7389                            for (int i = 0; i < orderByConditionFields.length; i++) {
7390                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7391                                    query.append(orderByConditionFields[i]);
7392    
7393                                    if ((i + 1) < orderByConditionFields.length) {
7394                                            if (orderByComparator.isAscending() ^ previous) {
7395                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7396                                            }
7397                                            else {
7398                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7399                                            }
7400                                    }
7401                                    else {
7402                                            if (orderByComparator.isAscending() ^ previous) {
7403                                                    query.append(WHERE_GREATER_THAN);
7404                                            }
7405                                            else {
7406                                                    query.append(WHERE_LESSER_THAN);
7407                                            }
7408                                    }
7409                            }
7410    
7411                            query.append(ORDER_BY_CLAUSE);
7412    
7413                            String[] orderByFields = orderByComparator.getOrderByFields();
7414    
7415                            for (int i = 0; i < orderByFields.length; i++) {
7416                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7417                                    query.append(orderByFields[i]);
7418    
7419                                    if ((i + 1) < orderByFields.length) {
7420                                            if (orderByComparator.isAscending() ^ previous) {
7421                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7422                                            }
7423                                            else {
7424                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7425                                            }
7426                                    }
7427                                    else {
7428                                            if (orderByComparator.isAscending() ^ previous) {
7429                                                    query.append(ORDER_BY_ASC);
7430                                            }
7431                                            else {
7432                                                    query.append(ORDER_BY_DESC);
7433                                            }
7434                                    }
7435                            }
7436                    }
7437                    else {
7438                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7439                    }
7440    
7441                    String sql = query.toString();
7442    
7443                    Query q = session.createQuery(sql);
7444    
7445                    q.setFirstResult(0);
7446                    q.setMaxResults(2);
7447    
7448                    QueryPos qPos = QueryPos.getInstance(q);
7449    
7450                    qPos.add(groupId);
7451    
7452                    qPos.add(nodeId);
7453    
7454                    qPos.add(head);
7455    
7456                    if (orderByComparator != null) {
7457                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
7458    
7459                            for (Object value : values) {
7460                                    qPos.add(value);
7461                            }
7462                    }
7463    
7464                    List<WikiPage> list = q.list();
7465    
7466                    if (list.size() == 2) {
7467                            return list.get(1);
7468                    }
7469                    else {
7470                            return null;
7471                    }
7472            }
7473    
7474            /**
7475             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
7476             *
7477             * @param groupId the group ID
7478             * @param nodeId the node ID
7479             * @param head the head
7480             * @return the matching wiki pages that the user has permission to view
7481             * @throws SystemException if a system exception occurred
7482             */
7483            public List<WikiPage> filterFindByG_N_H(long groupId, long nodeId,
7484                    boolean head) throws SystemException {
7485                    return filterFindByG_N_H(groupId, nodeId, head, QueryUtil.ALL_POS,
7486                            QueryUtil.ALL_POS, null);
7487            }
7488    
7489            /**
7490             * Returns a range of all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
7491             *
7492             * <p>
7493             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7494             * </p>
7495             *
7496             * @param groupId the group ID
7497             * @param nodeId the node ID
7498             * @param head the head
7499             * @param start the lower bound of the range of wiki pages
7500             * @param end the upper bound of the range of wiki pages (not inclusive)
7501             * @return the range of matching wiki pages that the user has permission to view
7502             * @throws SystemException if a system exception occurred
7503             */
7504            public List<WikiPage> filterFindByG_N_H(long groupId, long nodeId,
7505                    boolean head, int start, int end) throws SystemException {
7506                    return filterFindByG_N_H(groupId, nodeId, head, start, end, null);
7507            }
7508    
7509            /**
7510             * Returns an ordered range of all the wiki pages that the user has permissions to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
7511             *
7512             * <p>
7513             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7514             * </p>
7515             *
7516             * @param groupId the group ID
7517             * @param nodeId the node ID
7518             * @param head the head
7519             * @param start the lower bound of the range of wiki pages
7520             * @param end the upper bound of the range of wiki pages (not inclusive)
7521             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7522             * @return the ordered range of matching wiki pages that the user has permission to view
7523             * @throws SystemException if a system exception occurred
7524             */
7525            public List<WikiPage> filterFindByG_N_H(long groupId, long nodeId,
7526                    boolean head, int start, int end, OrderByComparator orderByComparator)
7527                    throws SystemException {
7528                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7529                            return findByG_N_H(groupId, nodeId, head, start, end,
7530                                    orderByComparator);
7531                    }
7532    
7533                    StringBundler query = null;
7534    
7535                    if (orderByComparator != null) {
7536                            query = new StringBundler(5 +
7537                                            (orderByComparator.getOrderByFields().length * 3));
7538                    }
7539                    else {
7540                            query = new StringBundler(5);
7541                    }
7542    
7543                    if (getDB().isSupportsInlineDistinct()) {
7544                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
7545                    }
7546                    else {
7547                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
7548                    }
7549    
7550                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7551    
7552                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7553    
7554                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7555    
7556                    if (!getDB().isSupportsInlineDistinct()) {
7557                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
7558                    }
7559    
7560                    if (orderByComparator != null) {
7561                            if (getDB().isSupportsInlineDistinct()) {
7562                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7563                                            orderByComparator, true);
7564                            }
7565                            else {
7566                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7567                                            orderByComparator, true);
7568                            }
7569                    }
7570                    else {
7571                            if (getDB().isSupportsInlineDistinct()) {
7572                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7573                            }
7574                            else {
7575                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
7576                            }
7577                    }
7578    
7579                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7580                                    WikiPage.class.getName(),
7581                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7582    
7583                    Session session = null;
7584    
7585                    try {
7586                            session = openSession();
7587    
7588                            SQLQuery q = session.createSQLQuery(sql);
7589    
7590                            if (getDB().isSupportsInlineDistinct()) {
7591                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
7592                            }
7593                            else {
7594                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
7595                            }
7596    
7597                            QueryPos qPos = QueryPos.getInstance(q);
7598    
7599                            qPos.add(groupId);
7600    
7601                            qPos.add(nodeId);
7602    
7603                            qPos.add(head);
7604    
7605                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
7606                    }
7607                    catch (Exception e) {
7608                            throw processException(e);
7609                    }
7610                    finally {
7611                            closeSession(session);
7612                    }
7613            }
7614    
7615            /**
7616             * Returns the wiki pages before and after the current wiki page in the ordered set of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
7617             *
7618             * @param pageId the primary key of the current wiki page
7619             * @param groupId the group ID
7620             * @param nodeId the node ID
7621             * @param head the head
7622             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7623             * @return the previous, current, and next wiki page
7624             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
7625             * @throws SystemException if a system exception occurred
7626             */
7627            public WikiPage[] filterFindByG_N_H_PrevAndNext(long pageId, long groupId,
7628                    long nodeId, boolean head, OrderByComparator orderByComparator)
7629                    throws NoSuchPageException, SystemException {
7630                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7631                            return findByG_N_H_PrevAndNext(pageId, groupId, nodeId, head,
7632                                    orderByComparator);
7633                    }
7634    
7635                    WikiPage wikiPage = findByPrimaryKey(pageId);
7636    
7637                    Session session = null;
7638    
7639                    try {
7640                            session = openSession();
7641    
7642                            WikiPage[] array = new WikiPageImpl[3];
7643    
7644                            array[0] = filterGetByG_N_H_PrevAndNext(session, wikiPage, groupId,
7645                                            nodeId, head, orderByComparator, true);
7646    
7647                            array[1] = wikiPage;
7648    
7649                            array[2] = filterGetByG_N_H_PrevAndNext(session, wikiPage, groupId,
7650                                            nodeId, head, orderByComparator, false);
7651    
7652                            return array;
7653                    }
7654                    catch (Exception e) {
7655                            throw processException(e);
7656                    }
7657                    finally {
7658                            closeSession(session);
7659                    }
7660            }
7661    
7662            protected WikiPage filterGetByG_N_H_PrevAndNext(Session session,
7663                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
7664                    OrderByComparator orderByComparator, boolean previous) {
7665                    StringBundler query = null;
7666    
7667                    if (orderByComparator != null) {
7668                            query = new StringBundler(6 +
7669                                            (orderByComparator.getOrderByFields().length * 6));
7670                    }
7671                    else {
7672                            query = new StringBundler(3);
7673                    }
7674    
7675                    if (getDB().isSupportsInlineDistinct()) {
7676                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
7677                    }
7678                    else {
7679                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
7680                    }
7681    
7682                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7683    
7684                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7685    
7686                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7687    
7688                    if (!getDB().isSupportsInlineDistinct()) {
7689                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
7690                    }
7691    
7692                    if (orderByComparator != null) {
7693                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7694    
7695                            if (orderByConditionFields.length > 0) {
7696                                    query.append(WHERE_AND);
7697                            }
7698    
7699                            for (int i = 0; i < orderByConditionFields.length; i++) {
7700                                    if (getDB().isSupportsInlineDistinct()) {
7701                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7702                                    }
7703                                    else {
7704                                            query.append(_ORDER_BY_ENTITY_TABLE);
7705                                    }
7706    
7707                                    query.append(orderByConditionFields[i]);
7708    
7709                                    if ((i + 1) < orderByConditionFields.length) {
7710                                            if (orderByComparator.isAscending() ^ previous) {
7711                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7712                                            }
7713                                            else {
7714                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7715                                            }
7716                                    }
7717                                    else {
7718                                            if (orderByComparator.isAscending() ^ previous) {
7719                                                    query.append(WHERE_GREATER_THAN);
7720                                            }
7721                                            else {
7722                                                    query.append(WHERE_LESSER_THAN);
7723                                            }
7724                                    }
7725                            }
7726    
7727                            query.append(ORDER_BY_CLAUSE);
7728    
7729                            String[] orderByFields = orderByComparator.getOrderByFields();
7730    
7731                            for (int i = 0; i < orderByFields.length; i++) {
7732                                    if (getDB().isSupportsInlineDistinct()) {
7733                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7734                                    }
7735                                    else {
7736                                            query.append(_ORDER_BY_ENTITY_TABLE);
7737                                    }
7738    
7739                                    query.append(orderByFields[i]);
7740    
7741                                    if ((i + 1) < orderByFields.length) {
7742                                            if (orderByComparator.isAscending() ^ previous) {
7743                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7744                                            }
7745                                            else {
7746                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7747                                            }
7748                                    }
7749                                    else {
7750                                            if (orderByComparator.isAscending() ^ previous) {
7751                                                    query.append(ORDER_BY_ASC);
7752                                            }
7753                                            else {
7754                                                    query.append(ORDER_BY_DESC);
7755                                            }
7756                                    }
7757                            }
7758                    }
7759                    else {
7760                            if (getDB().isSupportsInlineDistinct()) {
7761                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7762                            }
7763                            else {
7764                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
7765                            }
7766                    }
7767    
7768                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7769                                    WikiPage.class.getName(),
7770                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7771    
7772                    SQLQuery q = session.createSQLQuery(sql);
7773    
7774                    q.setFirstResult(0);
7775                    q.setMaxResults(2);
7776    
7777                    if (getDB().isSupportsInlineDistinct()) {
7778                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
7779                    }
7780                    else {
7781                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
7782                    }
7783    
7784                    QueryPos qPos = QueryPos.getInstance(q);
7785    
7786                    qPos.add(groupId);
7787    
7788                    qPos.add(nodeId);
7789    
7790                    qPos.add(head);
7791    
7792                    if (orderByComparator != null) {
7793                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
7794    
7795                            for (Object value : values) {
7796                                    qPos.add(value);
7797                            }
7798                    }
7799    
7800                    List<WikiPage> list = q.list();
7801    
7802                    if (list.size() == 2) {
7803                            return list.get(1);
7804                    }
7805                    else {
7806                            return null;
7807                    }
7808            }
7809    
7810            /**
7811             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; from the database.
7812             *
7813             * @param groupId the group ID
7814             * @param nodeId the node ID
7815             * @param head the head
7816             * @throws SystemException if a system exception occurred
7817             */
7818            public void removeByG_N_H(long groupId, long nodeId, boolean head)
7819                    throws SystemException {
7820                    for (WikiPage wikiPage : findByG_N_H(groupId, nodeId, head,
7821                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7822                            remove(wikiPage);
7823                    }
7824            }
7825    
7826            /**
7827             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
7828             *
7829             * @param groupId the group ID
7830             * @param nodeId the node ID
7831             * @param head the head
7832             * @return the number of matching wiki pages
7833             * @throws SystemException if a system exception occurred
7834             */
7835            public int countByG_N_H(long groupId, long nodeId, boolean head)
7836                    throws SystemException {
7837                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H;
7838    
7839                    Object[] finderArgs = new Object[] { groupId, nodeId, head };
7840    
7841                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7842                                    this);
7843    
7844                    if (count == null) {
7845                            StringBundler query = new StringBundler(4);
7846    
7847                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
7848    
7849                            query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7850    
7851                            query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7852    
7853                            query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7854    
7855                            String sql = query.toString();
7856    
7857                            Session session = null;
7858    
7859                            try {
7860                                    session = openSession();
7861    
7862                                    Query q = session.createQuery(sql);
7863    
7864                                    QueryPos qPos = QueryPos.getInstance(q);
7865    
7866                                    qPos.add(groupId);
7867    
7868                                    qPos.add(nodeId);
7869    
7870                                    qPos.add(head);
7871    
7872                                    count = (Long)q.uniqueResult();
7873    
7874                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7875                            }
7876                            catch (Exception e) {
7877                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7878    
7879                                    throw processException(e);
7880                            }
7881                            finally {
7882                                    closeSession(session);
7883                            }
7884                    }
7885    
7886                    return count.intValue();
7887            }
7888    
7889            /**
7890             * Returns the number of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
7891             *
7892             * @param groupId the group ID
7893             * @param nodeId the node ID
7894             * @param head the head
7895             * @return the number of matching wiki pages that the user has permission to view
7896             * @throws SystemException if a system exception occurred
7897             */
7898            public int filterCountByG_N_H(long groupId, long nodeId, boolean head)
7899                    throws SystemException {
7900                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7901                            return countByG_N_H(groupId, nodeId, head);
7902                    }
7903    
7904                    StringBundler query = new StringBundler(4);
7905    
7906                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
7907    
7908                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7909    
7910                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7911    
7912                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7913    
7914                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7915                                    WikiPage.class.getName(),
7916                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7917    
7918                    Session session = null;
7919    
7920                    try {
7921                            session = openSession();
7922    
7923                            SQLQuery q = session.createSQLQuery(sql);
7924    
7925                            q.addScalar(COUNT_COLUMN_NAME,
7926                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7927    
7928                            QueryPos qPos = QueryPos.getInstance(q);
7929    
7930                            qPos.add(groupId);
7931    
7932                            qPos.add(nodeId);
7933    
7934                            qPos.add(head);
7935    
7936                            Long count = (Long)q.uniqueResult();
7937    
7938                            return count.intValue();
7939                    }
7940                    catch (Exception e) {
7941                            throw processException(e);
7942                    }
7943                    finally {
7944                            closeSession(session);
7945                    }
7946            }
7947    
7948            private static final String _FINDER_COLUMN_G_N_H_GROUPID_2 = "wikiPage.groupId = ? AND ";
7949            private static final String _FINDER_COLUMN_G_N_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
7950            private static final String _FINDER_COLUMN_G_N_H_HEAD_2 = "wikiPage.head = ?";
7951            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7952                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
7953                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_S",
7954                            new String[] {
7955                                    Long.class.getName(), Long.class.getName(),
7956                                    Integer.class.getName(),
7957                                    
7958                            Integer.class.getName(), Integer.class.getName(),
7959                                    OrderByComparator.class.getName()
7960                            });
7961            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7962                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
7963                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_S",
7964                            new String[] {
7965                                    Long.class.getName(), Long.class.getName(),
7966                                    Integer.class.getName()
7967                            },
7968                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
7969                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
7970                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
7971                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
7972                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
7973            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7974                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7975                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_S",
7976                            new String[] {
7977                                    Long.class.getName(), Long.class.getName(),
7978                                    Integer.class.getName()
7979                            });
7980    
7981            /**
7982             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
7983             *
7984             * @param groupId the group ID
7985             * @param nodeId the node ID
7986             * @param status the status
7987             * @return the matching wiki pages
7988             * @throws SystemException if a system exception occurred
7989             */
7990            public List<WikiPage> findByG_N_S(long groupId, long nodeId, int status)
7991                    throws SystemException {
7992                    return findByG_N_S(groupId, nodeId, status, QueryUtil.ALL_POS,
7993                            QueryUtil.ALL_POS, null);
7994            }
7995    
7996            /**
7997             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
7998             *
7999             * <p>
8000             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8001             * </p>
8002             *
8003             * @param groupId the group ID
8004             * @param nodeId the node ID
8005             * @param status the status
8006             * @param start the lower bound of the range of wiki pages
8007             * @param end the upper bound of the range of wiki pages (not inclusive)
8008             * @return the range of matching wiki pages
8009             * @throws SystemException if a system exception occurred
8010             */
8011            public List<WikiPage> findByG_N_S(long groupId, long nodeId, int status,
8012                    int start, int end) throws SystemException {
8013                    return findByG_N_S(groupId, nodeId, status, start, end, null);
8014            }
8015    
8016            /**
8017             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
8018             *
8019             * <p>
8020             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8021             * </p>
8022             *
8023             * @param groupId the group ID
8024             * @param nodeId the node ID
8025             * @param status the status
8026             * @param start the lower bound of the range of wiki pages
8027             * @param end the upper bound of the range of wiki pages (not inclusive)
8028             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8029             * @return the ordered range of matching wiki pages
8030             * @throws SystemException if a system exception occurred
8031             */
8032            public List<WikiPage> findByG_N_S(long groupId, long nodeId, int status,
8033                    int start, int end, OrderByComparator orderByComparator)
8034                    throws SystemException {
8035                    boolean pagination = true;
8036                    FinderPath finderPath = null;
8037                    Object[] finderArgs = null;
8038    
8039                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8040                                    (orderByComparator == null)) {
8041                            pagination = false;
8042                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S;
8043                            finderArgs = new Object[] { groupId, nodeId, status };
8044                    }
8045                    else {
8046                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_S;
8047                            finderArgs = new Object[] {
8048                                            groupId, nodeId, status,
8049                                            
8050                                            start, end, orderByComparator
8051                                    };
8052                    }
8053    
8054                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
8055                                    finderArgs, this);
8056    
8057                    if ((list != null) && !list.isEmpty()) {
8058                            for (WikiPage wikiPage : list) {
8059                                    if ((groupId != wikiPage.getGroupId()) ||
8060                                                    (nodeId != wikiPage.getNodeId()) ||
8061                                                    (status != wikiPage.getStatus())) {
8062                                            list = null;
8063    
8064                                            break;
8065                                    }
8066                            }
8067                    }
8068    
8069                    if (list == null) {
8070                            StringBundler query = null;
8071    
8072                            if (orderByComparator != null) {
8073                                    query = new StringBundler(5 +
8074                                                    (orderByComparator.getOrderByFields().length * 3));
8075                            }
8076                            else {
8077                                    query = new StringBundler(5);
8078                            }
8079    
8080                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
8081    
8082                            query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8083    
8084                            query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8085    
8086                            query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8087    
8088                            if (orderByComparator != null) {
8089                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8090                                            orderByComparator);
8091                            }
8092                            else
8093                             if (pagination) {
8094                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8095                            }
8096    
8097                            String sql = query.toString();
8098    
8099                            Session session = null;
8100    
8101                            try {
8102                                    session = openSession();
8103    
8104                                    Query q = session.createQuery(sql);
8105    
8106                                    QueryPos qPos = QueryPos.getInstance(q);
8107    
8108                                    qPos.add(groupId);
8109    
8110                                    qPos.add(nodeId);
8111    
8112                                    qPos.add(status);
8113    
8114                                    if (!pagination) {
8115                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
8116                                                            start, end, false);
8117    
8118                                            Collections.sort(list);
8119    
8120                                            list = new UnmodifiableList<WikiPage>(list);
8121                                    }
8122                                    else {
8123                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
8124                                                            start, end);
8125                                    }
8126    
8127                                    cacheResult(list);
8128    
8129                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8130                            }
8131                            catch (Exception e) {
8132                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8133    
8134                                    throw processException(e);
8135                            }
8136                            finally {
8137                                    closeSession(session);
8138                            }
8139                    }
8140    
8141                    return list;
8142            }
8143    
8144            /**
8145             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8146             *
8147             * @param groupId the group ID
8148             * @param nodeId the node ID
8149             * @param status the status
8150             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8151             * @return the first matching wiki page
8152             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
8153             * @throws SystemException if a system exception occurred
8154             */
8155            public WikiPage findByG_N_S_First(long groupId, long nodeId, int status,
8156                    OrderByComparator orderByComparator)
8157                    throws NoSuchPageException, SystemException {
8158                    WikiPage wikiPage = fetchByG_N_S_First(groupId, nodeId, status,
8159                                    orderByComparator);
8160    
8161                    if (wikiPage != null) {
8162                            return wikiPage;
8163                    }
8164    
8165                    StringBundler msg = new StringBundler(8);
8166    
8167                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8168    
8169                    msg.append("groupId=");
8170                    msg.append(groupId);
8171    
8172                    msg.append(", nodeId=");
8173                    msg.append(nodeId);
8174    
8175                    msg.append(", status=");
8176                    msg.append(status);
8177    
8178                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8179    
8180                    throw new NoSuchPageException(msg.toString());
8181            }
8182    
8183            /**
8184             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8185             *
8186             * @param groupId the group ID
8187             * @param nodeId the node ID
8188             * @param status the status
8189             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8190             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
8191             * @throws SystemException if a system exception occurred
8192             */
8193            public WikiPage fetchByG_N_S_First(long groupId, long nodeId, int status,
8194                    OrderByComparator orderByComparator) throws SystemException {
8195                    List<WikiPage> list = findByG_N_S(groupId, nodeId, status, 0, 1,
8196                                    orderByComparator);
8197    
8198                    if (!list.isEmpty()) {
8199                            return list.get(0);
8200                    }
8201    
8202                    return null;
8203            }
8204    
8205            /**
8206             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8207             *
8208             * @param groupId the group ID
8209             * @param nodeId the node ID
8210             * @param status the status
8211             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8212             * @return the last matching wiki page
8213             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
8214             * @throws SystemException if a system exception occurred
8215             */
8216            public WikiPage findByG_N_S_Last(long groupId, long nodeId, int status,
8217                    OrderByComparator orderByComparator)
8218                    throws NoSuchPageException, SystemException {
8219                    WikiPage wikiPage = fetchByG_N_S_Last(groupId, nodeId, status,
8220                                    orderByComparator);
8221    
8222                    if (wikiPage != null) {
8223                            return wikiPage;
8224                    }
8225    
8226                    StringBundler msg = new StringBundler(8);
8227    
8228                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8229    
8230                    msg.append("groupId=");
8231                    msg.append(groupId);
8232    
8233                    msg.append(", nodeId=");
8234                    msg.append(nodeId);
8235    
8236                    msg.append(", status=");
8237                    msg.append(status);
8238    
8239                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8240    
8241                    throw new NoSuchPageException(msg.toString());
8242            }
8243    
8244            /**
8245             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8246             *
8247             * @param groupId the group ID
8248             * @param nodeId the node ID
8249             * @param status the status
8250             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8251             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
8252             * @throws SystemException if a system exception occurred
8253             */
8254            public WikiPage fetchByG_N_S_Last(long groupId, long nodeId, int status,
8255                    OrderByComparator orderByComparator) throws SystemException {
8256                    int count = countByG_N_S(groupId, nodeId, status);
8257    
8258                    List<WikiPage> list = findByG_N_S(groupId, nodeId, status, count - 1,
8259                                    count, orderByComparator);
8260    
8261                    if (!list.isEmpty()) {
8262                            return list.get(0);
8263                    }
8264    
8265                    return null;
8266            }
8267    
8268            /**
8269             * Returns the wiki pages before and after the current wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8270             *
8271             * @param pageId the primary key of the current wiki page
8272             * @param groupId the group ID
8273             * @param nodeId the node ID
8274             * @param status the status
8275             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8276             * @return the previous, current, and next wiki page
8277             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
8278             * @throws SystemException if a system exception occurred
8279             */
8280            public WikiPage[] findByG_N_S_PrevAndNext(long pageId, long groupId,
8281                    long nodeId, int status, OrderByComparator orderByComparator)
8282                    throws NoSuchPageException, SystemException {
8283                    WikiPage wikiPage = findByPrimaryKey(pageId);
8284    
8285                    Session session = null;
8286    
8287                    try {
8288                            session = openSession();
8289    
8290                            WikiPage[] array = new WikiPageImpl[3];
8291    
8292                            array[0] = getByG_N_S_PrevAndNext(session, wikiPage, groupId,
8293                                            nodeId, status, orderByComparator, true);
8294    
8295                            array[1] = wikiPage;
8296    
8297                            array[2] = getByG_N_S_PrevAndNext(session, wikiPage, groupId,
8298                                            nodeId, status, orderByComparator, false);
8299    
8300                            return array;
8301                    }
8302                    catch (Exception e) {
8303                            throw processException(e);
8304                    }
8305                    finally {
8306                            closeSession(session);
8307                    }
8308            }
8309    
8310            protected WikiPage getByG_N_S_PrevAndNext(Session session,
8311                    WikiPage wikiPage, long groupId, long nodeId, int status,
8312                    OrderByComparator orderByComparator, boolean previous) {
8313                    StringBundler query = null;
8314    
8315                    if (orderByComparator != null) {
8316                            query = new StringBundler(6 +
8317                                            (orderByComparator.getOrderByFields().length * 6));
8318                    }
8319                    else {
8320                            query = new StringBundler(3);
8321                    }
8322    
8323                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
8324    
8325                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8326    
8327                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8328    
8329                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8330    
8331                    if (orderByComparator != null) {
8332                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8333    
8334                            if (orderByConditionFields.length > 0) {
8335                                    query.append(WHERE_AND);
8336                            }
8337    
8338                            for (int i = 0; i < orderByConditionFields.length; i++) {
8339                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8340                                    query.append(orderByConditionFields[i]);
8341    
8342                                    if ((i + 1) < orderByConditionFields.length) {
8343                                            if (orderByComparator.isAscending() ^ previous) {
8344                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8345                                            }
8346                                            else {
8347                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8348                                            }
8349                                    }
8350                                    else {
8351                                            if (orderByComparator.isAscending() ^ previous) {
8352                                                    query.append(WHERE_GREATER_THAN);
8353                                            }
8354                                            else {
8355                                                    query.append(WHERE_LESSER_THAN);
8356                                            }
8357                                    }
8358                            }
8359    
8360                            query.append(ORDER_BY_CLAUSE);
8361    
8362                            String[] orderByFields = orderByComparator.getOrderByFields();
8363    
8364                            for (int i = 0; i < orderByFields.length; i++) {
8365                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8366                                    query.append(orderByFields[i]);
8367    
8368                                    if ((i + 1) < orderByFields.length) {
8369                                            if (orderByComparator.isAscending() ^ previous) {
8370                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8371                                            }
8372                                            else {
8373                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8374                                            }
8375                                    }
8376                                    else {
8377                                            if (orderByComparator.isAscending() ^ previous) {
8378                                                    query.append(ORDER_BY_ASC);
8379                                            }
8380                                            else {
8381                                                    query.append(ORDER_BY_DESC);
8382                                            }
8383                                    }
8384                            }
8385                    }
8386                    else {
8387                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8388                    }
8389    
8390                    String sql = query.toString();
8391    
8392                    Query q = session.createQuery(sql);
8393    
8394                    q.setFirstResult(0);
8395                    q.setMaxResults(2);
8396    
8397                    QueryPos qPos = QueryPos.getInstance(q);
8398    
8399                    qPos.add(groupId);
8400    
8401                    qPos.add(nodeId);
8402    
8403                    qPos.add(status);
8404    
8405                    if (orderByComparator != null) {
8406                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
8407    
8408                            for (Object value : values) {
8409                                    qPos.add(value);
8410                            }
8411                    }
8412    
8413                    List<WikiPage> list = q.list();
8414    
8415                    if (list.size() == 2) {
8416                            return list.get(1);
8417                    }
8418                    else {
8419                            return null;
8420                    }
8421            }
8422    
8423            /**
8424             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
8425             *
8426             * @param groupId the group ID
8427             * @param nodeId the node ID
8428             * @param status the status
8429             * @return the matching wiki pages that the user has permission to view
8430             * @throws SystemException if a system exception occurred
8431             */
8432            public List<WikiPage> filterFindByG_N_S(long groupId, long nodeId,
8433                    int status) throws SystemException {
8434                    return filterFindByG_N_S(groupId, nodeId, status, QueryUtil.ALL_POS,
8435                            QueryUtil.ALL_POS, null);
8436            }
8437    
8438            /**
8439             * Returns a range of all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
8440             *
8441             * <p>
8442             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8443             * </p>
8444             *
8445             * @param groupId the group ID
8446             * @param nodeId the node ID
8447             * @param status the status
8448             * @param start the lower bound of the range of wiki pages
8449             * @param end the upper bound of the range of wiki pages (not inclusive)
8450             * @return the range of matching wiki pages that the user has permission to view
8451             * @throws SystemException if a system exception occurred
8452             */
8453            public List<WikiPage> filterFindByG_N_S(long groupId, long nodeId,
8454                    int status, int start, int end) throws SystemException {
8455                    return filterFindByG_N_S(groupId, nodeId, status, start, end, null);
8456            }
8457    
8458            /**
8459             * Returns an ordered range of all the wiki pages that the user has permissions to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
8460             *
8461             * <p>
8462             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8463             * </p>
8464             *
8465             * @param groupId the group ID
8466             * @param nodeId the node ID
8467             * @param status the status
8468             * @param start the lower bound of the range of wiki pages
8469             * @param end the upper bound of the range of wiki pages (not inclusive)
8470             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8471             * @return the ordered range of matching wiki pages that the user has permission to view
8472             * @throws SystemException if a system exception occurred
8473             */
8474            public List<WikiPage> filterFindByG_N_S(long groupId, long nodeId,
8475                    int status, int start, int end, OrderByComparator orderByComparator)
8476                    throws SystemException {
8477                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8478                            return findByG_N_S(groupId, nodeId, status, start, end,
8479                                    orderByComparator);
8480                    }
8481    
8482                    StringBundler query = null;
8483    
8484                    if (orderByComparator != null) {
8485                            query = new StringBundler(5 +
8486                                            (orderByComparator.getOrderByFields().length * 3));
8487                    }
8488                    else {
8489                            query = new StringBundler(5);
8490                    }
8491    
8492                    if (getDB().isSupportsInlineDistinct()) {
8493                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
8494                    }
8495                    else {
8496                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
8497                    }
8498    
8499                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8500    
8501                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8502    
8503                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8504    
8505                    if (!getDB().isSupportsInlineDistinct()) {
8506                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
8507                    }
8508    
8509                    if (orderByComparator != null) {
8510                            if (getDB().isSupportsInlineDistinct()) {
8511                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8512                                            orderByComparator, true);
8513                            }
8514                            else {
8515                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8516                                            orderByComparator, true);
8517                            }
8518                    }
8519                    else {
8520                            if (getDB().isSupportsInlineDistinct()) {
8521                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8522                            }
8523                            else {
8524                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
8525                            }
8526                    }
8527    
8528                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8529                                    WikiPage.class.getName(),
8530                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8531    
8532                    Session session = null;
8533    
8534                    try {
8535                            session = openSession();
8536    
8537                            SQLQuery q = session.createSQLQuery(sql);
8538    
8539                            if (getDB().isSupportsInlineDistinct()) {
8540                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
8541                            }
8542                            else {
8543                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
8544                            }
8545    
8546                            QueryPos qPos = QueryPos.getInstance(q);
8547    
8548                            qPos.add(groupId);
8549    
8550                            qPos.add(nodeId);
8551    
8552                            qPos.add(status);
8553    
8554                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
8555                    }
8556                    catch (Exception e) {
8557                            throw processException(e);
8558                    }
8559                    finally {
8560                            closeSession(session);
8561                    }
8562            }
8563    
8564            /**
8565             * Returns the wiki pages before and after the current wiki page in the ordered set of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
8566             *
8567             * @param pageId the primary key of the current wiki page
8568             * @param groupId the group ID
8569             * @param nodeId the node ID
8570             * @param status the status
8571             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8572             * @return the previous, current, and next wiki page
8573             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
8574             * @throws SystemException if a system exception occurred
8575             */
8576            public WikiPage[] filterFindByG_N_S_PrevAndNext(long pageId, long groupId,
8577                    long nodeId, int status, OrderByComparator orderByComparator)
8578                    throws NoSuchPageException, SystemException {
8579                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8580                            return findByG_N_S_PrevAndNext(pageId, groupId, nodeId, status,
8581                                    orderByComparator);
8582                    }
8583    
8584                    WikiPage wikiPage = findByPrimaryKey(pageId);
8585    
8586                    Session session = null;
8587    
8588                    try {
8589                            session = openSession();
8590    
8591                            WikiPage[] array = new WikiPageImpl[3];
8592    
8593                            array[0] = filterGetByG_N_S_PrevAndNext(session, wikiPage, groupId,
8594                                            nodeId, status, orderByComparator, true);
8595    
8596                            array[1] = wikiPage;
8597    
8598                            array[2] = filterGetByG_N_S_PrevAndNext(session, wikiPage, groupId,
8599                                            nodeId, status, orderByComparator, false);
8600    
8601                            return array;
8602                    }
8603                    catch (Exception e) {
8604                            throw processException(e);
8605                    }
8606                    finally {
8607                            closeSession(session);
8608                    }
8609            }
8610    
8611            protected WikiPage filterGetByG_N_S_PrevAndNext(Session session,
8612                    WikiPage wikiPage, long groupId, long nodeId, int status,
8613                    OrderByComparator orderByComparator, boolean previous) {
8614                    StringBundler query = null;
8615    
8616                    if (orderByComparator != null) {
8617                            query = new StringBundler(6 +
8618                                            (orderByComparator.getOrderByFields().length * 6));
8619                    }
8620                    else {
8621                            query = new StringBundler(3);
8622                    }
8623    
8624                    if (getDB().isSupportsInlineDistinct()) {
8625                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
8626                    }
8627                    else {
8628                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
8629                    }
8630    
8631                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8632    
8633                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8634    
8635                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8636    
8637                    if (!getDB().isSupportsInlineDistinct()) {
8638                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
8639                    }
8640    
8641                    if (orderByComparator != null) {
8642                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8643    
8644                            if (orderByConditionFields.length > 0) {
8645                                    query.append(WHERE_AND);
8646                            }
8647    
8648                            for (int i = 0; i < orderByConditionFields.length; i++) {
8649                                    if (getDB().isSupportsInlineDistinct()) {
8650                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8651                                    }
8652                                    else {
8653                                            query.append(_ORDER_BY_ENTITY_TABLE);
8654                                    }
8655    
8656                                    query.append(orderByConditionFields[i]);
8657    
8658                                    if ((i + 1) < orderByConditionFields.length) {
8659                                            if (orderByComparator.isAscending() ^ previous) {
8660                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8661                                            }
8662                                            else {
8663                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8664                                            }
8665                                    }
8666                                    else {
8667                                            if (orderByComparator.isAscending() ^ previous) {
8668                                                    query.append(WHERE_GREATER_THAN);
8669                                            }
8670                                            else {
8671                                                    query.append(WHERE_LESSER_THAN);
8672                                            }
8673                                    }
8674                            }
8675    
8676                            query.append(ORDER_BY_CLAUSE);
8677    
8678                            String[] orderByFields = orderByComparator.getOrderByFields();
8679    
8680                            for (int i = 0; i < orderByFields.length; i++) {
8681                                    if (getDB().isSupportsInlineDistinct()) {
8682                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8683                                    }
8684                                    else {
8685                                            query.append(_ORDER_BY_ENTITY_TABLE);
8686                                    }
8687    
8688                                    query.append(orderByFields[i]);
8689    
8690                                    if ((i + 1) < orderByFields.length) {
8691                                            if (orderByComparator.isAscending() ^ previous) {
8692                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8693                                            }
8694                                            else {
8695                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8696                                            }
8697                                    }
8698                                    else {
8699                                            if (orderByComparator.isAscending() ^ previous) {
8700                                                    query.append(ORDER_BY_ASC);
8701                                            }
8702                                            else {
8703                                                    query.append(ORDER_BY_DESC);
8704                                            }
8705                                    }
8706                            }
8707                    }
8708                    else {
8709                            if (getDB().isSupportsInlineDistinct()) {
8710                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8711                            }
8712                            else {
8713                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
8714                            }
8715                    }
8716    
8717                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8718                                    WikiPage.class.getName(),
8719                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8720    
8721                    SQLQuery q = session.createSQLQuery(sql);
8722    
8723                    q.setFirstResult(0);
8724                    q.setMaxResults(2);
8725    
8726                    if (getDB().isSupportsInlineDistinct()) {
8727                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
8728                    }
8729                    else {
8730                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
8731                    }
8732    
8733                    QueryPos qPos = QueryPos.getInstance(q);
8734    
8735                    qPos.add(groupId);
8736    
8737                    qPos.add(nodeId);
8738    
8739                    qPos.add(status);
8740    
8741                    if (orderByComparator != null) {
8742                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
8743    
8744                            for (Object value : values) {
8745                                    qPos.add(value);
8746                            }
8747                    }
8748    
8749                    List<WikiPage> list = q.list();
8750    
8751                    if (list.size() == 2) {
8752                            return list.get(1);
8753                    }
8754                    else {
8755                            return null;
8756                    }
8757            }
8758    
8759            /**
8760             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63; from the database.
8761             *
8762             * @param groupId the group ID
8763             * @param nodeId the node ID
8764             * @param status the status
8765             * @throws SystemException if a system exception occurred
8766             */
8767            public void removeByG_N_S(long groupId, long nodeId, int status)
8768                    throws SystemException {
8769                    for (WikiPage wikiPage : findByG_N_S(groupId, nodeId, status,
8770                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8771                            remove(wikiPage);
8772                    }
8773            }
8774    
8775            /**
8776             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
8777             *
8778             * @param groupId the group ID
8779             * @param nodeId the node ID
8780             * @param status the status
8781             * @return the number of matching wiki pages
8782             * @throws SystemException if a system exception occurred
8783             */
8784            public int countByG_N_S(long groupId, long nodeId, int status)
8785                    throws SystemException {
8786                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_S;
8787    
8788                    Object[] finderArgs = new Object[] { groupId, nodeId, status };
8789    
8790                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8791                                    this);
8792    
8793                    if (count == null) {
8794                            StringBundler query = new StringBundler(4);
8795    
8796                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8797    
8798                            query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8799    
8800                            query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8801    
8802                            query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8803    
8804                            String sql = query.toString();
8805    
8806                            Session session = null;
8807    
8808                            try {
8809                                    session = openSession();
8810    
8811                                    Query q = session.createQuery(sql);
8812    
8813                                    QueryPos qPos = QueryPos.getInstance(q);
8814    
8815                                    qPos.add(groupId);
8816    
8817                                    qPos.add(nodeId);
8818    
8819                                    qPos.add(status);
8820    
8821                                    count = (Long)q.uniqueResult();
8822    
8823                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8824                            }
8825                            catch (Exception e) {
8826                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8827    
8828                                    throw processException(e);
8829                            }
8830                            finally {
8831                                    closeSession(session);
8832                            }
8833                    }
8834    
8835                    return count.intValue();
8836            }
8837    
8838            /**
8839             * Returns the number of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
8840             *
8841             * @param groupId the group ID
8842             * @param nodeId the node ID
8843             * @param status the status
8844             * @return the number of matching wiki pages that the user has permission to view
8845             * @throws SystemException if a system exception occurred
8846             */
8847            public int filterCountByG_N_S(long groupId, long nodeId, int status)
8848                    throws SystemException {
8849                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8850                            return countByG_N_S(groupId, nodeId, status);
8851                    }
8852    
8853                    StringBundler query = new StringBundler(4);
8854    
8855                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
8856    
8857                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8858    
8859                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8860    
8861                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8862    
8863                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8864                                    WikiPage.class.getName(),
8865                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8866    
8867                    Session session = null;
8868    
8869                    try {
8870                            session = openSession();
8871    
8872                            SQLQuery q = session.createSQLQuery(sql);
8873    
8874                            q.addScalar(COUNT_COLUMN_NAME,
8875                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8876    
8877                            QueryPos qPos = QueryPos.getInstance(q);
8878    
8879                            qPos.add(groupId);
8880    
8881                            qPos.add(nodeId);
8882    
8883                            qPos.add(status);
8884    
8885                            Long count = (Long)q.uniqueResult();
8886    
8887                            return count.intValue();
8888                    }
8889                    catch (Exception e) {
8890                            throw processException(e);
8891                    }
8892                    finally {
8893                            closeSession(session);
8894                    }
8895            }
8896    
8897            private static final String _FINDER_COLUMN_G_N_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
8898            private static final String _FINDER_COLUMN_G_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
8899            private static final String _FINDER_COLUMN_G_N_S_STATUS_2 = "wikiPage.status = ?";
8900            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
8901                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
8902                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_N_S",
8903                            new String[] {
8904                                    Long.class.getName(), Long.class.getName(),
8905                                    Integer.class.getName(),
8906                                    
8907                            Integer.class.getName(), Integer.class.getName(),
8908                                    OrderByComparator.class.getName()
8909                            });
8910            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
8911                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
8912                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_N_S",
8913                            new String[] {
8914                                    Long.class.getName(), Long.class.getName(),
8915                                    Integer.class.getName()
8916                            },
8917                            WikiPageModelImpl.USERID_COLUMN_BITMASK |
8918                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
8919                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
8920                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
8921                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
8922            public static final FinderPath FINDER_PATH_COUNT_BY_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
8923                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8924                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_N_S",
8925                            new String[] {
8926                                    Long.class.getName(), Long.class.getName(),
8927                                    Integer.class.getName()
8928                            });
8929    
8930            /**
8931             * Returns all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
8932             *
8933             * @param userId the user ID
8934             * @param nodeId the node ID
8935             * @param status the status
8936             * @return the matching wiki pages
8937             * @throws SystemException if a system exception occurred
8938             */
8939            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status)
8940                    throws SystemException {
8941                    return findByU_N_S(userId, nodeId, status, QueryUtil.ALL_POS,
8942                            QueryUtil.ALL_POS, null);
8943            }
8944    
8945            /**
8946             * Returns a range of all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
8947             *
8948             * <p>
8949             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8950             * </p>
8951             *
8952             * @param userId the user ID
8953             * @param nodeId the node ID
8954             * @param status the status
8955             * @param start the lower bound of the range of wiki pages
8956             * @param end the upper bound of the range of wiki pages (not inclusive)
8957             * @return the range of matching wiki pages
8958             * @throws SystemException if a system exception occurred
8959             */
8960            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status,
8961                    int start, int end) throws SystemException {
8962                    return findByU_N_S(userId, nodeId, status, start, end, null);
8963            }
8964    
8965            /**
8966             * Returns an ordered range of all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
8967             *
8968             * <p>
8969             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8970             * </p>
8971             *
8972             * @param userId the user ID
8973             * @param nodeId the node ID
8974             * @param status the status
8975             * @param start the lower bound of the range of wiki pages
8976             * @param end the upper bound of the range of wiki pages (not inclusive)
8977             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8978             * @return the ordered range of matching wiki pages
8979             * @throws SystemException if a system exception occurred
8980             */
8981            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status,
8982                    int start, int end, OrderByComparator orderByComparator)
8983                    throws SystemException {
8984                    boolean pagination = true;
8985                    FinderPath finderPath = null;
8986                    Object[] finderArgs = null;
8987    
8988                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8989                                    (orderByComparator == null)) {
8990                            pagination = false;
8991                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S;
8992                            finderArgs = new Object[] { userId, nodeId, status };
8993                    }
8994                    else {
8995                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_N_S;
8996                            finderArgs = new Object[] {
8997                                            userId, nodeId, status,
8998                                            
8999                                            start, end, orderByComparator
9000                                    };
9001                    }
9002    
9003                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
9004                                    finderArgs, this);
9005    
9006                    if ((list != null) && !list.isEmpty()) {
9007                            for (WikiPage wikiPage : list) {
9008                                    if ((userId != wikiPage.getUserId()) ||
9009                                                    (nodeId != wikiPage.getNodeId()) ||
9010                                                    (status != wikiPage.getStatus())) {
9011                                            list = null;
9012    
9013                                            break;
9014                                    }
9015                            }
9016                    }
9017    
9018                    if (list == null) {
9019                            StringBundler query = null;
9020    
9021                            if (orderByComparator != null) {
9022                                    query = new StringBundler(5 +
9023                                                    (orderByComparator.getOrderByFields().length * 3));
9024                            }
9025                            else {
9026                                    query = new StringBundler(5);
9027                            }
9028    
9029                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
9030    
9031                            query.append(_FINDER_COLUMN_U_N_S_USERID_2);
9032    
9033                            query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
9034    
9035                            query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
9036    
9037                            if (orderByComparator != null) {
9038                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9039                                            orderByComparator);
9040                            }
9041                            else
9042                             if (pagination) {
9043                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
9044                            }
9045    
9046                            String sql = query.toString();
9047    
9048                            Session session = null;
9049    
9050                            try {
9051                                    session = openSession();
9052    
9053                                    Query q = session.createQuery(sql);
9054    
9055                                    QueryPos qPos = QueryPos.getInstance(q);
9056    
9057                                    qPos.add(userId);
9058    
9059                                    qPos.add(nodeId);
9060    
9061                                    qPos.add(status);
9062    
9063                                    if (!pagination) {
9064                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
9065                                                            start, end, false);
9066    
9067                                            Collections.sort(list);
9068    
9069                                            list = new UnmodifiableList<WikiPage>(list);
9070                                    }
9071                                    else {
9072                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
9073                                                            start, end);
9074                                    }
9075    
9076                                    cacheResult(list);
9077    
9078                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9079                            }
9080                            catch (Exception e) {
9081                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9082    
9083                                    throw processException(e);
9084                            }
9085                            finally {
9086                                    closeSession(session);
9087                            }
9088                    }
9089    
9090                    return list;
9091            }
9092    
9093            /**
9094             * Returns the first wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9095             *
9096             * @param userId the user ID
9097             * @param nodeId the node ID
9098             * @param status the status
9099             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9100             * @return the first matching wiki page
9101             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9102             * @throws SystemException if a system exception occurred
9103             */
9104            public WikiPage findByU_N_S_First(long userId, long nodeId, int status,
9105                    OrderByComparator orderByComparator)
9106                    throws NoSuchPageException, SystemException {
9107                    WikiPage wikiPage = fetchByU_N_S_First(userId, nodeId, status,
9108                                    orderByComparator);
9109    
9110                    if (wikiPage != null) {
9111                            return wikiPage;
9112                    }
9113    
9114                    StringBundler msg = new StringBundler(8);
9115    
9116                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9117    
9118                    msg.append("userId=");
9119                    msg.append(userId);
9120    
9121                    msg.append(", nodeId=");
9122                    msg.append(nodeId);
9123    
9124                    msg.append(", status=");
9125                    msg.append(status);
9126    
9127                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9128    
9129                    throw new NoSuchPageException(msg.toString());
9130            }
9131    
9132            /**
9133             * Returns the first wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9134             *
9135             * @param userId the user ID
9136             * @param nodeId the node ID
9137             * @param status the status
9138             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9139             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
9140             * @throws SystemException if a system exception occurred
9141             */
9142            public WikiPage fetchByU_N_S_First(long userId, long nodeId, int status,
9143                    OrderByComparator orderByComparator) throws SystemException {
9144                    List<WikiPage> list = findByU_N_S(userId, nodeId, status, 0, 1,
9145                                    orderByComparator);
9146    
9147                    if (!list.isEmpty()) {
9148                            return list.get(0);
9149                    }
9150    
9151                    return null;
9152            }
9153    
9154            /**
9155             * Returns the last wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9156             *
9157             * @param userId the user ID
9158             * @param nodeId the node ID
9159             * @param status the status
9160             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9161             * @return the last matching wiki page
9162             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9163             * @throws SystemException if a system exception occurred
9164             */
9165            public WikiPage findByU_N_S_Last(long userId, long nodeId, int status,
9166                    OrderByComparator orderByComparator)
9167                    throws NoSuchPageException, SystemException {
9168                    WikiPage wikiPage = fetchByU_N_S_Last(userId, nodeId, status,
9169                                    orderByComparator);
9170    
9171                    if (wikiPage != null) {
9172                            return wikiPage;
9173                    }
9174    
9175                    StringBundler msg = new StringBundler(8);
9176    
9177                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9178    
9179                    msg.append("userId=");
9180                    msg.append(userId);
9181    
9182                    msg.append(", nodeId=");
9183                    msg.append(nodeId);
9184    
9185                    msg.append(", status=");
9186                    msg.append(status);
9187    
9188                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9189    
9190                    throw new NoSuchPageException(msg.toString());
9191            }
9192    
9193            /**
9194             * Returns the last wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9195             *
9196             * @param userId the user ID
9197             * @param nodeId the node ID
9198             * @param status the status
9199             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9200             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
9201             * @throws SystemException if a system exception occurred
9202             */
9203            public WikiPage fetchByU_N_S_Last(long userId, long nodeId, int status,
9204                    OrderByComparator orderByComparator) throws SystemException {
9205                    int count = countByU_N_S(userId, nodeId, status);
9206    
9207                    List<WikiPage> list = findByU_N_S(userId, nodeId, status, count - 1,
9208                                    count, orderByComparator);
9209    
9210                    if (!list.isEmpty()) {
9211                            return list.get(0);
9212                    }
9213    
9214                    return null;
9215            }
9216    
9217            /**
9218             * Returns the wiki pages before and after the current wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9219             *
9220             * @param pageId the primary key of the current wiki page
9221             * @param userId the user ID
9222             * @param nodeId the node ID
9223             * @param status the status
9224             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9225             * @return the previous, current, and next wiki page
9226             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
9227             * @throws SystemException if a system exception occurred
9228             */
9229            public WikiPage[] findByU_N_S_PrevAndNext(long pageId, long userId,
9230                    long nodeId, int status, OrderByComparator orderByComparator)
9231                    throws NoSuchPageException, SystemException {
9232                    WikiPage wikiPage = findByPrimaryKey(pageId);
9233    
9234                    Session session = null;
9235    
9236                    try {
9237                            session = openSession();
9238    
9239                            WikiPage[] array = new WikiPageImpl[3];
9240    
9241                            array[0] = getByU_N_S_PrevAndNext(session, wikiPage, userId,
9242                                            nodeId, status, orderByComparator, true);
9243    
9244                            array[1] = wikiPage;
9245    
9246                            array[2] = getByU_N_S_PrevAndNext(session, wikiPage, userId,
9247                                            nodeId, status, orderByComparator, false);
9248    
9249                            return array;
9250                    }
9251                    catch (Exception e) {
9252                            throw processException(e);
9253                    }
9254                    finally {
9255                            closeSession(session);
9256                    }
9257            }
9258    
9259            protected WikiPage getByU_N_S_PrevAndNext(Session session,
9260                    WikiPage wikiPage, long userId, long nodeId, int status,
9261                    OrderByComparator orderByComparator, boolean previous) {
9262                    StringBundler query = null;
9263    
9264                    if (orderByComparator != null) {
9265                            query = new StringBundler(6 +
9266                                            (orderByComparator.getOrderByFields().length * 6));
9267                    }
9268                    else {
9269                            query = new StringBundler(3);
9270                    }
9271    
9272                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
9273    
9274                    query.append(_FINDER_COLUMN_U_N_S_USERID_2);
9275    
9276                    query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
9277    
9278                    query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
9279    
9280                    if (orderByComparator != null) {
9281                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9282    
9283                            if (orderByConditionFields.length > 0) {
9284                                    query.append(WHERE_AND);
9285                            }
9286    
9287                            for (int i = 0; i < orderByConditionFields.length; i++) {
9288                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9289                                    query.append(orderByConditionFields[i]);
9290    
9291                                    if ((i + 1) < orderByConditionFields.length) {
9292                                            if (orderByComparator.isAscending() ^ previous) {
9293                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9294                                            }
9295                                            else {
9296                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9297                                            }
9298                                    }
9299                                    else {
9300                                            if (orderByComparator.isAscending() ^ previous) {
9301                                                    query.append(WHERE_GREATER_THAN);
9302                                            }
9303                                            else {
9304                                                    query.append(WHERE_LESSER_THAN);
9305                                            }
9306                                    }
9307                            }
9308    
9309                            query.append(ORDER_BY_CLAUSE);
9310    
9311                            String[] orderByFields = orderByComparator.getOrderByFields();
9312    
9313                            for (int i = 0; i < orderByFields.length; i++) {
9314                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9315                                    query.append(orderByFields[i]);
9316    
9317                                    if ((i + 1) < orderByFields.length) {
9318                                            if (orderByComparator.isAscending() ^ previous) {
9319                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9320                                            }
9321                                            else {
9322                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9323                                            }
9324                                    }
9325                                    else {
9326                                            if (orderByComparator.isAscending() ^ previous) {
9327                                                    query.append(ORDER_BY_ASC);
9328                                            }
9329                                            else {
9330                                                    query.append(ORDER_BY_DESC);
9331                                            }
9332                                    }
9333                            }
9334                    }
9335                    else {
9336                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
9337                    }
9338    
9339                    String sql = query.toString();
9340    
9341                    Query q = session.createQuery(sql);
9342    
9343                    q.setFirstResult(0);
9344                    q.setMaxResults(2);
9345    
9346                    QueryPos qPos = QueryPos.getInstance(q);
9347    
9348                    qPos.add(userId);
9349    
9350                    qPos.add(nodeId);
9351    
9352                    qPos.add(status);
9353    
9354                    if (orderByComparator != null) {
9355                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
9356    
9357                            for (Object value : values) {
9358                                    qPos.add(value);
9359                            }
9360                    }
9361    
9362                    List<WikiPage> list = q.list();
9363    
9364                    if (list.size() == 2) {
9365                            return list.get(1);
9366                    }
9367                    else {
9368                            return null;
9369                    }
9370            }
9371    
9372            /**
9373             * Removes all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63; from the database.
9374             *
9375             * @param userId the user ID
9376             * @param nodeId the node ID
9377             * @param status the status
9378             * @throws SystemException if a system exception occurred
9379             */
9380            public void removeByU_N_S(long userId, long nodeId, int status)
9381                    throws SystemException {
9382                    for (WikiPage wikiPage : findByU_N_S(userId, nodeId, status,
9383                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9384                            remove(wikiPage);
9385                    }
9386            }
9387    
9388            /**
9389             * Returns the number of wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
9390             *
9391             * @param userId the user ID
9392             * @param nodeId the node ID
9393             * @param status the status
9394             * @return the number of matching wiki pages
9395             * @throws SystemException if a system exception occurred
9396             */
9397            public int countByU_N_S(long userId, long nodeId, int status)
9398                    throws SystemException {
9399                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_N_S;
9400    
9401                    Object[] finderArgs = new Object[] { userId, nodeId, status };
9402    
9403                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9404                                    this);
9405    
9406                    if (count == null) {
9407                            StringBundler query = new StringBundler(4);
9408    
9409                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
9410    
9411                            query.append(_FINDER_COLUMN_U_N_S_USERID_2);
9412    
9413                            query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
9414    
9415                            query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
9416    
9417                            String sql = query.toString();
9418    
9419                            Session session = null;
9420    
9421                            try {
9422                                    session = openSession();
9423    
9424                                    Query q = session.createQuery(sql);
9425    
9426                                    QueryPos qPos = QueryPos.getInstance(q);
9427    
9428                                    qPos.add(userId);
9429    
9430                                    qPos.add(nodeId);
9431    
9432                                    qPos.add(status);
9433    
9434                                    count = (Long)q.uniqueResult();
9435    
9436                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9437                            }
9438                            catch (Exception e) {
9439                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9440    
9441                                    throw processException(e);
9442                            }
9443                            finally {
9444                                    closeSession(session);
9445                            }
9446                    }
9447    
9448                    return count.intValue();
9449            }
9450    
9451            private static final String _FINDER_COLUMN_U_N_S_USERID_2 = "wikiPage.userId = ? AND ";
9452            private static final String _FINDER_COLUMN_U_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
9453            private static final String _FINDER_COLUMN_U_N_S_STATUS_2 = "wikiPage.status = ?";
9454            public static final FinderPath FINDER_PATH_FETCH_BY_N_T_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9455                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
9456                            FINDER_CLASS_NAME_ENTITY, "fetchByN_T_V",
9457                            new String[] {
9458                                    Long.class.getName(), String.class.getName(),
9459                                    Double.class.getName()
9460                            },
9461                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
9462                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
9463                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
9464            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9465                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9466                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T_V",
9467                            new String[] {
9468                                    Long.class.getName(), String.class.getName(),
9469                                    Double.class.getName()
9470                            });
9471    
9472            /**
9473             * Returns 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.
9474             *
9475             * @param nodeId the node ID
9476             * @param title the title
9477             * @param version the version
9478             * @return the matching wiki page
9479             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9480             * @throws SystemException if a system exception occurred
9481             */
9482            public WikiPage findByN_T_V(long nodeId, String title, double version)
9483                    throws NoSuchPageException, SystemException {
9484                    WikiPage wikiPage = fetchByN_T_V(nodeId, title, version);
9485    
9486                    if (wikiPage == null) {
9487                            StringBundler msg = new StringBundler(8);
9488    
9489                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9490    
9491                            msg.append("nodeId=");
9492                            msg.append(nodeId);
9493    
9494                            msg.append(", title=");
9495                            msg.append(title);
9496    
9497                            msg.append(", version=");
9498                            msg.append(version);
9499    
9500                            msg.append(StringPool.CLOSE_CURLY_BRACE);
9501    
9502                            if (_log.isWarnEnabled()) {
9503                                    _log.warn(msg.toString());
9504                            }
9505    
9506                            throw new NoSuchPageException(msg.toString());
9507                    }
9508    
9509                    return wikiPage;
9510            }
9511    
9512            /**
9513             * Returns 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.
9514             *
9515             * @param nodeId the node ID
9516             * @param title the title
9517             * @param version the version
9518             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
9519             * @throws SystemException if a system exception occurred
9520             */
9521            public WikiPage fetchByN_T_V(long nodeId, String title, double version)
9522                    throws SystemException {
9523                    return fetchByN_T_V(nodeId, title, version, true);
9524            }
9525    
9526            /**
9527             * Returns 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.
9528             *
9529             * @param nodeId the node ID
9530             * @param title the title
9531             * @param version the version
9532             * @param retrieveFromCache whether to use the finder cache
9533             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
9534             * @throws SystemException if a system exception occurred
9535             */
9536            public WikiPage fetchByN_T_V(long nodeId, String title, double version,
9537                    boolean retrieveFromCache) throws SystemException {
9538                    Object[] finderArgs = new Object[] { nodeId, title, version };
9539    
9540                    Object result = null;
9541    
9542                    if (retrieveFromCache) {
9543                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T_V,
9544                                            finderArgs, this);
9545                    }
9546    
9547                    if (result instanceof WikiPage) {
9548                            WikiPage wikiPage = (WikiPage)result;
9549    
9550                            if ((nodeId != wikiPage.getNodeId()) ||
9551                                            !Validator.equals(title, wikiPage.getTitle()) ||
9552                                            (version != wikiPage.getVersion())) {
9553                                    result = null;
9554                            }
9555                    }
9556    
9557                    if (result == null) {
9558                            StringBundler query = new StringBundler(5);
9559    
9560                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
9561    
9562                            query.append(_FINDER_COLUMN_N_T_V_NODEID_2);
9563    
9564                            boolean bindTitle = false;
9565    
9566                            if (title == null) {
9567                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_1);
9568                            }
9569                            else if (title.equals(StringPool.BLANK)) {
9570                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_3);
9571                            }
9572                            else {
9573                                    bindTitle = true;
9574    
9575                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_2);
9576                            }
9577    
9578                            query.append(_FINDER_COLUMN_N_T_V_VERSION_2);
9579    
9580                            String sql = query.toString();
9581    
9582                            Session session = null;
9583    
9584                            try {
9585                                    session = openSession();
9586    
9587                                    Query q = session.createQuery(sql);
9588    
9589                                    QueryPos qPos = QueryPos.getInstance(q);
9590    
9591                                    qPos.add(nodeId);
9592    
9593                                    if (bindTitle) {
9594                                            qPos.add(title.toLowerCase());
9595                                    }
9596    
9597                                    qPos.add(version);
9598    
9599                                    List<WikiPage> list = q.list();
9600    
9601                                    if (list.isEmpty()) {
9602                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
9603                                                    finderArgs, list);
9604                                    }
9605                                    else {
9606                                            WikiPage wikiPage = list.get(0);
9607    
9608                                            result = wikiPage;
9609    
9610                                            cacheResult(wikiPage);
9611    
9612                                            if ((wikiPage.getNodeId() != nodeId) ||
9613                                                            (wikiPage.getTitle() == null) ||
9614                                                            !wikiPage.getTitle().equals(title) ||
9615                                                            (wikiPage.getVersion() != version)) {
9616                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
9617                                                            finderArgs, wikiPage);
9618                                            }
9619                                    }
9620                            }
9621                            catch (Exception e) {
9622                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V,
9623                                            finderArgs);
9624    
9625                                    throw processException(e);
9626                            }
9627                            finally {
9628                                    closeSession(session);
9629                            }
9630                    }
9631    
9632                    if (result instanceof List<?>) {
9633                            return null;
9634                    }
9635                    else {
9636                            return (WikiPage)result;
9637                    }
9638            }
9639    
9640            /**
9641             * Removes the wiki page where nodeId = &#63; and title = &#63; and version = &#63; from the database.
9642             *
9643             * @param nodeId the node ID
9644             * @param title the title
9645             * @param version the version
9646             * @return the wiki page that was removed
9647             * @throws SystemException if a system exception occurred
9648             */
9649            public WikiPage removeByN_T_V(long nodeId, String title, double version)
9650                    throws NoSuchPageException, SystemException {
9651                    WikiPage wikiPage = findByN_T_V(nodeId, title, version);
9652    
9653                    return remove(wikiPage);
9654            }
9655    
9656            /**
9657             * Returns the number of wiki pages where nodeId = &#63; and title = &#63; and version = &#63;.
9658             *
9659             * @param nodeId the node ID
9660             * @param title the title
9661             * @param version the version
9662             * @return the number of matching wiki pages
9663             * @throws SystemException if a system exception occurred
9664             */
9665            public int countByN_T_V(long nodeId, String title, double version)
9666                    throws SystemException {
9667                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T_V;
9668    
9669                    Object[] finderArgs = new Object[] { nodeId, title, version };
9670    
9671                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9672                                    this);
9673    
9674                    if (count == null) {
9675                            StringBundler query = new StringBundler(4);
9676    
9677                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
9678    
9679                            query.append(_FINDER_COLUMN_N_T_V_NODEID_2);
9680    
9681                            boolean bindTitle = false;
9682    
9683                            if (title == null) {
9684                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_1);
9685                            }
9686                            else if (title.equals(StringPool.BLANK)) {
9687                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_3);
9688                            }
9689                            else {
9690                                    bindTitle = true;
9691    
9692                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_2);
9693                            }
9694    
9695                            query.append(_FINDER_COLUMN_N_T_V_VERSION_2);
9696    
9697                            String sql = query.toString();
9698    
9699                            Session session = null;
9700    
9701                            try {
9702                                    session = openSession();
9703    
9704                                    Query q = session.createQuery(sql);
9705    
9706                                    QueryPos qPos = QueryPos.getInstance(q);
9707    
9708                                    qPos.add(nodeId);
9709    
9710                                    if (bindTitle) {
9711                                            qPos.add(title.toLowerCase());
9712                                    }
9713    
9714                                    qPos.add(version);
9715    
9716                                    count = (Long)q.uniqueResult();
9717    
9718                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9719                            }
9720                            catch (Exception e) {
9721                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9722    
9723                                    throw processException(e);
9724                            }
9725                            finally {
9726                                    closeSession(session);
9727                            }
9728                    }
9729    
9730                    return count.intValue();
9731            }
9732    
9733            private static final String _FINDER_COLUMN_N_T_V_NODEID_2 = "wikiPage.nodeId = ? AND ";
9734            private static final String _FINDER_COLUMN_N_T_V_TITLE_1 = "wikiPage.title IS NULL AND ";
9735            private static final String _FINDER_COLUMN_N_T_V_TITLE_2 = "lower(wikiPage.title) = ? AND ";
9736            private static final String _FINDER_COLUMN_N_T_V_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
9737            private static final String _FINDER_COLUMN_N_T_V_VERSION_2 = "wikiPage.version = ?";
9738            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9739                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
9740                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_T_H",
9741                            new String[] {
9742                                    Long.class.getName(), String.class.getName(),
9743                                    Boolean.class.getName(),
9744                                    
9745                            Integer.class.getName(), Integer.class.getName(),
9746                                    OrderByComparator.class.getName()
9747                            });
9748            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9749                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
9750                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_T_H",
9751                            new String[] {
9752                                    Long.class.getName(), String.class.getName(),
9753                                    Boolean.class.getName()
9754                            },
9755                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
9756                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
9757                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
9758                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
9759            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9760                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9761                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T_H",
9762                            new String[] {
9763                                    Long.class.getName(), String.class.getName(),
9764                                    Boolean.class.getName()
9765                            });
9766    
9767            /**
9768             * Returns all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
9769             *
9770             * @param nodeId the node ID
9771             * @param title the title
9772             * @param head the head
9773             * @return the matching wiki pages
9774             * @throws SystemException if a system exception occurred
9775             */
9776            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head)
9777                    throws SystemException {
9778                    return findByN_T_H(nodeId, title, head, QueryUtil.ALL_POS,
9779                            QueryUtil.ALL_POS, null);
9780            }
9781    
9782            /**
9783             * Returns a range of all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
9784             *
9785             * <p>
9786             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9787             * </p>
9788             *
9789             * @param nodeId the node ID
9790             * @param title the title
9791             * @param head the head
9792             * @param start the lower bound of the range of wiki pages
9793             * @param end the upper bound of the range of wiki pages (not inclusive)
9794             * @return the range of matching wiki pages
9795             * @throws SystemException if a system exception occurred
9796             */
9797            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head,
9798                    int start, int end) throws SystemException {
9799                    return findByN_T_H(nodeId, title, head, start, end, null);
9800            }
9801    
9802            /**
9803             * Returns an ordered range of all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
9804             *
9805             * <p>
9806             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9807             * </p>
9808             *
9809             * @param nodeId the node ID
9810             * @param title the title
9811             * @param head the head
9812             * @param start the lower bound of the range of wiki pages
9813             * @param end the upper bound of the range of wiki pages (not inclusive)
9814             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9815             * @return the ordered range of matching wiki pages
9816             * @throws SystemException if a system exception occurred
9817             */
9818            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head,
9819                    int start, int end, OrderByComparator orderByComparator)
9820                    throws SystemException {
9821                    boolean pagination = true;
9822                    FinderPath finderPath = null;
9823                    Object[] finderArgs = null;
9824    
9825                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9826                                    (orderByComparator == null)) {
9827                            pagination = false;
9828                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H;
9829                            finderArgs = new Object[] { nodeId, title, head };
9830                    }
9831                    else {
9832                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_H;
9833                            finderArgs = new Object[] {
9834                                            nodeId, title, head,
9835                                            
9836                                            start, end, orderByComparator
9837                                    };
9838                    }
9839    
9840                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
9841                                    finderArgs, this);
9842    
9843                    if ((list != null) && !list.isEmpty()) {
9844                            for (WikiPage wikiPage : list) {
9845                                    if ((nodeId != wikiPage.getNodeId()) ||
9846                                                    !Validator.equals(title, wikiPage.getTitle()) ||
9847                                                    (head != wikiPage.getHead())) {
9848                                            list = null;
9849    
9850                                            break;
9851                                    }
9852                            }
9853                    }
9854    
9855                    if (list == null) {
9856                            StringBundler query = null;
9857    
9858                            if (orderByComparator != null) {
9859                                    query = new StringBundler(5 +
9860                                                    (orderByComparator.getOrderByFields().length * 3));
9861                            }
9862                            else {
9863                                    query = new StringBundler(5);
9864                            }
9865    
9866                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
9867    
9868                            query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
9869    
9870                            boolean bindTitle = false;
9871    
9872                            if (title == null) {
9873                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
9874                            }
9875                            else if (title.equals(StringPool.BLANK)) {
9876                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
9877                            }
9878                            else {
9879                                    bindTitle = true;
9880    
9881                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
9882                            }
9883    
9884                            query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
9885    
9886                            if (orderByComparator != null) {
9887                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9888                                            orderByComparator);
9889                            }
9890                            else
9891                             if (pagination) {
9892                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
9893                            }
9894    
9895                            String sql = query.toString();
9896    
9897                            Session session = null;
9898    
9899                            try {
9900                                    session = openSession();
9901    
9902                                    Query q = session.createQuery(sql);
9903    
9904                                    QueryPos qPos = QueryPos.getInstance(q);
9905    
9906                                    qPos.add(nodeId);
9907    
9908                                    if (bindTitle) {
9909                                            qPos.add(title.toLowerCase());
9910                                    }
9911    
9912                                    qPos.add(head);
9913    
9914                                    if (!pagination) {
9915                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
9916                                                            start, end, false);
9917    
9918                                            Collections.sort(list);
9919    
9920                                            list = new UnmodifiableList<WikiPage>(list);
9921                                    }
9922                                    else {
9923                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
9924                                                            start, end);
9925                                    }
9926    
9927                                    cacheResult(list);
9928    
9929                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9930                            }
9931                            catch (Exception e) {
9932                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9933    
9934                                    throw processException(e);
9935                            }
9936                            finally {
9937                                    closeSession(session);
9938                            }
9939                    }
9940    
9941                    return list;
9942            }
9943    
9944            /**
9945             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
9946             *
9947             * @param nodeId the node ID
9948             * @param title the title
9949             * @param head the head
9950             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9951             * @return the first matching wiki page
9952             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9953             * @throws SystemException if a system exception occurred
9954             */
9955            public WikiPage findByN_T_H_First(long nodeId, String title, boolean head,
9956                    OrderByComparator orderByComparator)
9957                    throws NoSuchPageException, SystemException {
9958                    WikiPage wikiPage = fetchByN_T_H_First(nodeId, title, head,
9959                                    orderByComparator);
9960    
9961                    if (wikiPage != null) {
9962                            return wikiPage;
9963                    }
9964    
9965                    StringBundler msg = new StringBundler(8);
9966    
9967                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9968    
9969                    msg.append("nodeId=");
9970                    msg.append(nodeId);
9971    
9972                    msg.append(", title=");
9973                    msg.append(title);
9974    
9975                    msg.append(", head=");
9976                    msg.append(head);
9977    
9978                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9979    
9980                    throw new NoSuchPageException(msg.toString());
9981            }
9982    
9983            /**
9984             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
9985             *
9986             * @param nodeId the node ID
9987             * @param title the title
9988             * @param head the head
9989             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9990             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
9991             * @throws SystemException if a system exception occurred
9992             */
9993            public WikiPage fetchByN_T_H_First(long nodeId, String title, boolean head,
9994                    OrderByComparator orderByComparator) throws SystemException {
9995                    List<WikiPage> list = findByN_T_H(nodeId, title, head, 0, 1,
9996                                    orderByComparator);
9997    
9998                    if (!list.isEmpty()) {
9999                            return list.get(0);
10000                    }
10001    
10002                    return null;
10003            }
10004    
10005            /**
10006             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
10007             *
10008             * @param nodeId the node ID
10009             * @param title the title
10010             * @param head the head
10011             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10012             * @return the last matching wiki page
10013             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
10014             * @throws SystemException if a system exception occurred
10015             */
10016            public WikiPage findByN_T_H_Last(long nodeId, String title, boolean head,
10017                    OrderByComparator orderByComparator)
10018                    throws NoSuchPageException, SystemException {
10019                    WikiPage wikiPage = fetchByN_T_H_Last(nodeId, title, head,
10020                                    orderByComparator);
10021    
10022                    if (wikiPage != null) {
10023                            return wikiPage;
10024                    }
10025    
10026                    StringBundler msg = new StringBundler(8);
10027    
10028                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10029    
10030                    msg.append("nodeId=");
10031                    msg.append(nodeId);
10032    
10033                    msg.append(", title=");
10034                    msg.append(title);
10035    
10036                    msg.append(", head=");
10037                    msg.append(head);
10038    
10039                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10040    
10041                    throw new NoSuchPageException(msg.toString());
10042            }
10043    
10044            /**
10045             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
10046             *
10047             * @param nodeId the node ID
10048             * @param title the title
10049             * @param head the head
10050             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10051             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
10052             * @throws SystemException if a system exception occurred
10053             */
10054            public WikiPage fetchByN_T_H_Last(long nodeId, String title, boolean head,
10055                    OrderByComparator orderByComparator) throws SystemException {
10056                    int count = countByN_T_H(nodeId, title, head);
10057    
10058                    List<WikiPage> list = findByN_T_H(nodeId, title, head, count - 1,
10059                                    count, orderByComparator);
10060    
10061                    if (!list.isEmpty()) {
10062                            return list.get(0);
10063                    }
10064    
10065                    return null;
10066            }
10067    
10068            /**
10069             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
10070             *
10071             * @param pageId the primary key of the current wiki page
10072             * @param nodeId the node ID
10073             * @param title the title
10074             * @param head the head
10075             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10076             * @return the previous, current, and next wiki page
10077             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
10078             * @throws SystemException if a system exception occurred
10079             */
10080            public WikiPage[] findByN_T_H_PrevAndNext(long pageId, long nodeId,
10081                    String title, boolean head, OrderByComparator orderByComparator)
10082                    throws NoSuchPageException, SystemException {
10083                    WikiPage wikiPage = findByPrimaryKey(pageId);
10084    
10085                    Session session = null;
10086    
10087                    try {
10088                            session = openSession();
10089    
10090                            WikiPage[] array = new WikiPageImpl[3];
10091    
10092                            array[0] = getByN_T_H_PrevAndNext(session, wikiPage, nodeId, title,
10093                                            head, orderByComparator, true);
10094    
10095                            array[1] = wikiPage;
10096    
10097                            array[2] = getByN_T_H_PrevAndNext(session, wikiPage, nodeId, title,
10098                                            head, orderByComparator, false);
10099    
10100                            return array;
10101                    }
10102                    catch (Exception e) {
10103                            throw processException(e);
10104                    }
10105                    finally {
10106                            closeSession(session);
10107                    }
10108            }
10109    
10110            protected WikiPage getByN_T_H_PrevAndNext(Session session,
10111                    WikiPage wikiPage, long nodeId, String title, boolean head,
10112                    OrderByComparator orderByComparator, boolean previous) {
10113                    StringBundler query = null;
10114    
10115                    if (orderByComparator != null) {
10116                            query = new StringBundler(6 +
10117                                            (orderByComparator.getOrderByFields().length * 6));
10118                    }
10119                    else {
10120                            query = new StringBundler(3);
10121                    }
10122    
10123                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
10124    
10125                    query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
10126    
10127                    boolean bindTitle = false;
10128    
10129                    if (title == null) {
10130                            query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
10131                    }
10132                    else if (title.equals(StringPool.BLANK)) {
10133                            query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
10134                    }
10135                    else {
10136                            bindTitle = true;
10137    
10138                            query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
10139                    }
10140    
10141                    query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
10142    
10143                    if (orderByComparator != null) {
10144                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10145    
10146                            if (orderByConditionFields.length > 0) {
10147                                    query.append(WHERE_AND);
10148                            }
10149    
10150                            for (int i = 0; i < orderByConditionFields.length; i++) {
10151                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10152                                    query.append(orderByConditionFields[i]);
10153    
10154                                    if ((i + 1) < orderByConditionFields.length) {
10155                                            if (orderByComparator.isAscending() ^ previous) {
10156                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10157                                            }
10158                                            else {
10159                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10160                                            }
10161                                    }
10162                                    else {
10163                                            if (orderByComparator.isAscending() ^ previous) {
10164                                                    query.append(WHERE_GREATER_THAN);
10165                                            }
10166                                            else {
10167                                                    query.append(WHERE_LESSER_THAN);
10168                                            }
10169                                    }
10170                            }
10171    
10172                            query.append(ORDER_BY_CLAUSE);
10173    
10174                            String[] orderByFields = orderByComparator.getOrderByFields();
10175    
10176                            for (int i = 0; i < orderByFields.length; i++) {
10177                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10178                                    query.append(orderByFields[i]);
10179    
10180                                    if ((i + 1) < orderByFields.length) {
10181                                            if (orderByComparator.isAscending() ^ previous) {
10182                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10183                                            }
10184                                            else {
10185                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10186                                            }
10187                                    }
10188                                    else {
10189                                            if (orderByComparator.isAscending() ^ previous) {
10190                                                    query.append(ORDER_BY_ASC);
10191                                            }
10192                                            else {
10193                                                    query.append(ORDER_BY_DESC);
10194                                            }
10195                                    }
10196                            }
10197                    }
10198                    else {
10199                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
10200                    }
10201    
10202                    String sql = query.toString();
10203    
10204                    Query q = session.createQuery(sql);
10205    
10206                    q.setFirstResult(0);
10207                    q.setMaxResults(2);
10208    
10209                    QueryPos qPos = QueryPos.getInstance(q);
10210    
10211                    qPos.add(nodeId);
10212    
10213                    if (bindTitle) {
10214                            qPos.add(title.toLowerCase());
10215                    }
10216    
10217                    qPos.add(head);
10218    
10219                    if (orderByComparator != null) {
10220                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
10221    
10222                            for (Object value : values) {
10223                                    qPos.add(value);
10224                            }
10225                    }
10226    
10227                    List<WikiPage> list = q.list();
10228    
10229                    if (list.size() == 2) {
10230                            return list.get(1);
10231                    }
10232                    else {
10233                            return null;
10234                    }
10235            }
10236    
10237            /**
10238             * Removes all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63; from the database.
10239             *
10240             * @param nodeId the node ID
10241             * @param title the title
10242             * @param head the head
10243             * @throws SystemException if a system exception occurred
10244             */
10245            public void removeByN_T_H(long nodeId, String title, boolean head)
10246                    throws SystemException {
10247                    for (WikiPage wikiPage : findByN_T_H(nodeId, title, head,
10248                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10249                            remove(wikiPage);
10250                    }
10251            }
10252    
10253            /**
10254             * Returns the number of wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
10255             *
10256             * @param nodeId the node ID
10257             * @param title the title
10258             * @param head the head
10259             * @return the number of matching wiki pages
10260             * @throws SystemException if a system exception occurred
10261             */
10262            public int countByN_T_H(long nodeId, String title, boolean head)
10263                    throws SystemException {
10264                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T_H;
10265    
10266                    Object[] finderArgs = new Object[] { nodeId, title, head };
10267    
10268                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10269                                    this);
10270    
10271                    if (count == null) {
10272                            StringBundler query = new StringBundler(4);
10273    
10274                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
10275    
10276                            query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
10277    
10278                            boolean bindTitle = false;
10279    
10280                            if (title == null) {
10281                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
10282                            }
10283                            else if (title.equals(StringPool.BLANK)) {
10284                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
10285                            }
10286                            else {
10287                                    bindTitle = true;
10288    
10289                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
10290                            }
10291    
10292                            query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
10293    
10294                            String sql = query.toString();
10295    
10296                            Session session = null;
10297    
10298                            try {
10299                                    session = openSession();
10300    
10301                                    Query q = session.createQuery(sql);
10302    
10303                                    QueryPos qPos = QueryPos.getInstance(q);
10304    
10305                                    qPos.add(nodeId);
10306    
10307                                    if (bindTitle) {
10308                                            qPos.add(title.toLowerCase());
10309                                    }
10310    
10311                                    qPos.add(head);
10312    
10313                                    count = (Long)q.uniqueResult();
10314    
10315                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10316                            }
10317                            catch (Exception e) {
10318                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10319    
10320                                    throw processException(e);
10321                            }
10322                            finally {
10323                                    closeSession(session);
10324                            }
10325                    }
10326    
10327                    return count.intValue();
10328            }
10329    
10330            private static final String _FINDER_COLUMN_N_T_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
10331            private static final String _FINDER_COLUMN_N_T_H_TITLE_1 = "wikiPage.title IS NULL AND ";
10332            private static final String _FINDER_COLUMN_N_T_H_TITLE_2 = "lower(wikiPage.title) = ? AND ";
10333            private static final String _FINDER_COLUMN_N_T_H_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
10334            private static final String _FINDER_COLUMN_N_T_H_HEAD_2 = "wikiPage.head = ?";
10335            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10336                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
10337                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_T_S",
10338                            new String[] {
10339                                    Long.class.getName(), String.class.getName(),
10340                                    Integer.class.getName(),
10341                                    
10342                            Integer.class.getName(), Integer.class.getName(),
10343                                    OrderByComparator.class.getName()
10344                            });
10345            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10346                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
10347                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_T_S",
10348                            new String[] {
10349                                    Long.class.getName(), String.class.getName(),
10350                                    Integer.class.getName()
10351                            },
10352                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
10353                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
10354                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
10355                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
10356            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10357                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10358                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T_S",
10359                            new String[] {
10360                                    Long.class.getName(), String.class.getName(),
10361                                    Integer.class.getName()
10362                            });
10363    
10364            /**
10365             * Returns all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
10366             *
10367             * @param nodeId the node ID
10368             * @param title the title
10369             * @param status the status
10370             * @return the matching wiki pages
10371             * @throws SystemException if a system exception occurred
10372             */
10373            public List<WikiPage> findByN_T_S(long nodeId, String title, int status)
10374                    throws SystemException {
10375                    return findByN_T_S(nodeId, title, status, QueryUtil.ALL_POS,
10376                            QueryUtil.ALL_POS, null);
10377            }
10378    
10379            /**
10380             * Returns a range of all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
10381             *
10382             * <p>
10383             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10384             * </p>
10385             *
10386             * @param nodeId the node ID
10387             * @param title the title
10388             * @param status the status
10389             * @param start the lower bound of the range of wiki pages
10390             * @param end the upper bound of the range of wiki pages (not inclusive)
10391             * @return the range of matching wiki pages
10392             * @throws SystemException if a system exception occurred
10393             */
10394            public List<WikiPage> findByN_T_S(long nodeId, String title, int status,
10395                    int start, int end) throws SystemException {
10396                    return findByN_T_S(nodeId, title, status, start, end, null);
10397            }
10398    
10399            /**
10400             * Returns an ordered range of all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
10401             *
10402             * <p>
10403             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10404             * </p>
10405             *
10406             * @param nodeId the node ID
10407             * @param title the title
10408             * @param status the status
10409             * @param start the lower bound of the range of wiki pages
10410             * @param end the upper bound of the range of wiki pages (not inclusive)
10411             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10412             * @return the ordered range of matching wiki pages
10413             * @throws SystemException if a system exception occurred
10414             */
10415            public List<WikiPage> findByN_T_S(long nodeId, String title, int status,
10416                    int start, int end, OrderByComparator orderByComparator)
10417                    throws SystemException {
10418                    boolean pagination = true;
10419                    FinderPath finderPath = null;
10420                    Object[] finderArgs = null;
10421    
10422                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10423                                    (orderByComparator == null)) {
10424                            pagination = false;
10425                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S;
10426                            finderArgs = new Object[] { nodeId, title, status };
10427                    }
10428                    else {
10429                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_S;
10430                            finderArgs = new Object[] {
10431                                            nodeId, title, status,
10432                                            
10433                                            start, end, orderByComparator
10434                                    };
10435                    }
10436    
10437                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
10438                                    finderArgs, this);
10439    
10440                    if ((list != null) && !list.isEmpty()) {
10441                            for (WikiPage wikiPage : list) {
10442                                    if ((nodeId != wikiPage.getNodeId()) ||
10443                                                    !Validator.equals(title, wikiPage.getTitle()) ||
10444                                                    (status != wikiPage.getStatus())) {
10445                                            list = null;
10446    
10447                                            break;
10448                                    }
10449                            }
10450                    }
10451    
10452                    if (list == null) {
10453                            StringBundler query = null;
10454    
10455                            if (orderByComparator != null) {
10456                                    query = new StringBundler(5 +
10457                                                    (orderByComparator.getOrderByFields().length * 3));
10458                            }
10459                            else {
10460                                    query = new StringBundler(5);
10461                            }
10462    
10463                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
10464    
10465                            query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
10466    
10467                            boolean bindTitle = false;
10468    
10469                            if (title == null) {
10470                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
10471                            }
10472                            else if (title.equals(StringPool.BLANK)) {
10473                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
10474                            }
10475                            else {
10476                                    bindTitle = true;
10477    
10478                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
10479                            }
10480    
10481                            query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
10482    
10483                            if (orderByComparator != null) {
10484                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10485                                            orderByComparator);
10486                            }
10487                            else
10488                             if (pagination) {
10489                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
10490                            }
10491    
10492                            String sql = query.toString();
10493    
10494                            Session session = null;
10495    
10496                            try {
10497                                    session = openSession();
10498    
10499                                    Query q = session.createQuery(sql);
10500    
10501                                    QueryPos qPos = QueryPos.getInstance(q);
10502    
10503                                    qPos.add(nodeId);
10504    
10505                                    if (bindTitle) {
10506                                            qPos.add(title.toLowerCase());
10507                                    }
10508    
10509                                    qPos.add(status);
10510    
10511                                    if (!pagination) {
10512                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
10513                                                            start, end, false);
10514    
10515                                            Collections.sort(list);
10516    
10517                                            list = new UnmodifiableList<WikiPage>(list);
10518                                    }
10519                                    else {
10520                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
10521                                                            start, end);
10522                                    }
10523    
10524                                    cacheResult(list);
10525    
10526                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10527                            }
10528                            catch (Exception e) {
10529                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10530    
10531                                    throw processException(e);
10532                            }
10533                            finally {
10534                                    closeSession(session);
10535                            }
10536                    }
10537    
10538                    return list;
10539            }
10540    
10541            /**
10542             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10543             *
10544             * @param nodeId the node ID
10545             * @param title the title
10546             * @param status the status
10547             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10548             * @return the first matching wiki page
10549             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
10550             * @throws SystemException if a system exception occurred
10551             */
10552            public WikiPage findByN_T_S_First(long nodeId, String title, int status,
10553                    OrderByComparator orderByComparator)
10554                    throws NoSuchPageException, SystemException {
10555                    WikiPage wikiPage = fetchByN_T_S_First(nodeId, title, status,
10556                                    orderByComparator);
10557    
10558                    if (wikiPage != null) {
10559                            return wikiPage;
10560                    }
10561    
10562                    StringBundler msg = new StringBundler(8);
10563    
10564                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10565    
10566                    msg.append("nodeId=");
10567                    msg.append(nodeId);
10568    
10569                    msg.append(", title=");
10570                    msg.append(title);
10571    
10572                    msg.append(", status=");
10573                    msg.append(status);
10574    
10575                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10576    
10577                    throw new NoSuchPageException(msg.toString());
10578            }
10579    
10580            /**
10581             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10582             *
10583             * @param nodeId the node ID
10584             * @param title the title
10585             * @param status the status
10586             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10587             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
10588             * @throws SystemException if a system exception occurred
10589             */
10590            public WikiPage fetchByN_T_S_First(long nodeId, String title, int status,
10591                    OrderByComparator orderByComparator) throws SystemException {
10592                    List<WikiPage> list = findByN_T_S(nodeId, title, status, 0, 1,
10593                                    orderByComparator);
10594    
10595                    if (!list.isEmpty()) {
10596                            return list.get(0);
10597                    }
10598    
10599                    return null;
10600            }
10601    
10602            /**
10603             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10604             *
10605             * @param nodeId the node ID
10606             * @param title the title
10607             * @param status the status
10608             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10609             * @return the last matching wiki page
10610             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
10611             * @throws SystemException if a system exception occurred
10612             */
10613            public WikiPage findByN_T_S_Last(long nodeId, String title, int status,
10614                    OrderByComparator orderByComparator)
10615                    throws NoSuchPageException, SystemException {
10616                    WikiPage wikiPage = fetchByN_T_S_Last(nodeId, title, status,
10617                                    orderByComparator);
10618    
10619                    if (wikiPage != null) {
10620                            return wikiPage;
10621                    }
10622    
10623                    StringBundler msg = new StringBundler(8);
10624    
10625                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10626    
10627                    msg.append("nodeId=");
10628                    msg.append(nodeId);
10629    
10630                    msg.append(", title=");
10631                    msg.append(title);
10632    
10633                    msg.append(", status=");
10634                    msg.append(status);
10635    
10636                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10637    
10638                    throw new NoSuchPageException(msg.toString());
10639            }
10640    
10641            /**
10642             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10643             *
10644             * @param nodeId the node ID
10645             * @param title the title
10646             * @param status the status
10647             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10648             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
10649             * @throws SystemException if a system exception occurred
10650             */
10651            public WikiPage fetchByN_T_S_Last(long nodeId, String title, int status,
10652                    OrderByComparator orderByComparator) throws SystemException {
10653                    int count = countByN_T_S(nodeId, title, status);
10654    
10655                    List<WikiPage> list = findByN_T_S(nodeId, title, status, count - 1,
10656                                    count, orderByComparator);
10657    
10658                    if (!list.isEmpty()) {
10659                            return list.get(0);
10660                    }
10661    
10662                    return null;
10663            }
10664    
10665            /**
10666             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10667             *
10668             * @param pageId the primary key of the current wiki page
10669             * @param nodeId the node ID
10670             * @param title the title
10671             * @param status the status
10672             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10673             * @return the previous, current, and next wiki page
10674             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
10675             * @throws SystemException if a system exception occurred
10676             */
10677            public WikiPage[] findByN_T_S_PrevAndNext(long pageId, long nodeId,
10678                    String title, int status, OrderByComparator orderByComparator)
10679                    throws NoSuchPageException, SystemException {
10680                    WikiPage wikiPage = findByPrimaryKey(pageId);
10681    
10682                    Session session = null;
10683    
10684                    try {
10685                            session = openSession();
10686    
10687                            WikiPage[] array = new WikiPageImpl[3];
10688    
10689                            array[0] = getByN_T_S_PrevAndNext(session, wikiPage, nodeId, title,
10690                                            status, orderByComparator, true);
10691    
10692                            array[1] = wikiPage;
10693    
10694                            array[2] = getByN_T_S_PrevAndNext(session, wikiPage, nodeId, title,
10695                                            status, orderByComparator, false);
10696    
10697                            return array;
10698                    }
10699                    catch (Exception e) {
10700                            throw processException(e);
10701                    }
10702                    finally {
10703                            closeSession(session);
10704                    }
10705            }
10706    
10707            protected WikiPage getByN_T_S_PrevAndNext(Session session,
10708                    WikiPage wikiPage, long nodeId, String title, int status,
10709                    OrderByComparator orderByComparator, boolean previous) {
10710                    StringBundler query = null;
10711    
10712                    if (orderByComparator != null) {
10713                            query = new StringBundler(6 +
10714                                            (orderByComparator.getOrderByFields().length * 6));
10715                    }
10716                    else {
10717                            query = new StringBundler(3);
10718                    }
10719    
10720                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
10721    
10722                    query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
10723    
10724                    boolean bindTitle = false;
10725    
10726                    if (title == null) {
10727                            query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
10728                    }
10729                    else if (title.equals(StringPool.BLANK)) {
10730                            query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
10731                    }
10732                    else {
10733                            bindTitle = true;
10734    
10735                            query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
10736                    }
10737    
10738                    query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
10739    
10740                    if (orderByComparator != null) {
10741                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10742    
10743                            if (orderByConditionFields.length > 0) {
10744                                    query.append(WHERE_AND);
10745                            }
10746    
10747                            for (int i = 0; i < orderByConditionFields.length; i++) {
10748                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10749                                    query.append(orderByConditionFields[i]);
10750    
10751                                    if ((i + 1) < orderByConditionFields.length) {
10752                                            if (orderByComparator.isAscending() ^ previous) {
10753                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10754                                            }
10755                                            else {
10756                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10757                                            }
10758                                    }
10759                                    else {
10760                                            if (orderByComparator.isAscending() ^ previous) {
10761                                                    query.append(WHERE_GREATER_THAN);
10762                                            }
10763                                            else {
10764                                                    query.append(WHERE_LESSER_THAN);
10765                                            }
10766                                    }
10767                            }
10768    
10769                            query.append(ORDER_BY_CLAUSE);
10770    
10771                            String[] orderByFields = orderByComparator.getOrderByFields();
10772    
10773                            for (int i = 0; i < orderByFields.length; i++) {
10774                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10775                                    query.append(orderByFields[i]);
10776    
10777                                    if ((i + 1) < orderByFields.length) {
10778                                            if (orderByComparator.isAscending() ^ previous) {
10779                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10780                                            }
10781                                            else {
10782                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10783                                            }
10784                                    }
10785                                    else {
10786                                            if (orderByComparator.isAscending() ^ previous) {
10787                                                    query.append(ORDER_BY_ASC);
10788                                            }
10789                                            else {
10790                                                    query.append(ORDER_BY_DESC);
10791                                            }
10792                                    }
10793                            }
10794                    }
10795                    else {
10796                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
10797                    }
10798    
10799                    String sql = query.toString();
10800    
10801                    Query q = session.createQuery(sql);
10802    
10803                    q.setFirstResult(0);
10804                    q.setMaxResults(2);
10805    
10806                    QueryPos qPos = QueryPos.getInstance(q);
10807    
10808                    qPos.add(nodeId);
10809    
10810                    if (bindTitle) {
10811                            qPos.add(title.toLowerCase());
10812                    }
10813    
10814                    qPos.add(status);
10815    
10816                    if (orderByComparator != null) {
10817                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
10818    
10819                            for (Object value : values) {
10820                                    qPos.add(value);
10821                            }
10822                    }
10823    
10824                    List<WikiPage> list = q.list();
10825    
10826                    if (list.size() == 2) {
10827                            return list.get(1);
10828                    }
10829                    else {
10830                            return null;
10831                    }
10832            }
10833    
10834            /**
10835             * Removes all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63; from the database.
10836             *
10837             * @param nodeId the node ID
10838             * @param title the title
10839             * @param status the status
10840             * @throws SystemException if a system exception occurred
10841             */
10842            public void removeByN_T_S(long nodeId, String title, int status)
10843                    throws SystemException {
10844                    for (WikiPage wikiPage : findByN_T_S(nodeId, title, status,
10845                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10846                            remove(wikiPage);
10847                    }
10848            }
10849    
10850            /**
10851             * Returns the number of wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
10852             *
10853             * @param nodeId the node ID
10854             * @param title the title
10855             * @param status the status
10856             * @return the number of matching wiki pages
10857             * @throws SystemException if a system exception occurred
10858             */
10859            public int countByN_T_S(long nodeId, String title, int status)
10860                    throws SystemException {
10861                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T_S;
10862    
10863                    Object[] finderArgs = new Object[] { nodeId, title, status };
10864    
10865                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10866                                    this);
10867    
10868                    if (count == null) {
10869                            StringBundler query = new StringBundler(4);
10870    
10871                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
10872    
10873                            query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
10874    
10875                            boolean bindTitle = false;
10876    
10877                            if (title == null) {
10878                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
10879                            }
10880                            else if (title.equals(StringPool.BLANK)) {
10881                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
10882                            }
10883                            else {
10884                                    bindTitle = true;
10885    
10886                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
10887                            }
10888    
10889                            query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
10890    
10891                            String sql = query.toString();
10892    
10893                            Session session = null;
10894    
10895                            try {
10896                                    session = openSession();
10897    
10898                                    Query q = session.createQuery(sql);
10899    
10900                                    QueryPos qPos = QueryPos.getInstance(q);
10901    
10902                                    qPos.add(nodeId);
10903    
10904                                    if (bindTitle) {
10905                                            qPos.add(title.toLowerCase());
10906                                    }
10907    
10908                                    qPos.add(status);
10909    
10910                                    count = (Long)q.uniqueResult();
10911    
10912                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10913                            }
10914                            catch (Exception e) {
10915                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10916    
10917                                    throw processException(e);
10918                            }
10919                            finally {
10920                                    closeSession(session);
10921                            }
10922                    }
10923    
10924                    return count.intValue();
10925            }
10926    
10927            private static final String _FINDER_COLUMN_N_T_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
10928            private static final String _FINDER_COLUMN_N_T_S_TITLE_1 = "wikiPage.title IS NULL AND ";
10929            private static final String _FINDER_COLUMN_N_T_S_TITLE_2 = "lower(wikiPage.title) = ? AND ";
10930            private static final String _FINDER_COLUMN_N_T_S_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
10931            private static final String _FINDER_COLUMN_N_T_S_STATUS_2 = "wikiPage.status = ?";
10932            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10933                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
10934                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_P",
10935                            new String[] {
10936                                    Long.class.getName(), Boolean.class.getName(),
10937                                    String.class.getName(),
10938                                    
10939                            Integer.class.getName(), Integer.class.getName(),
10940                                    OrderByComparator.class.getName()
10941                            });
10942            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10943                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
10944                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_P",
10945                            new String[] {
10946                                    Long.class.getName(), Boolean.class.getName(),
10947                                    String.class.getName()
10948                            },
10949                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
10950                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
10951                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
10952                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
10953                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
10954            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10955                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10956                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_P",
10957                            new String[] {
10958                                    Long.class.getName(), Boolean.class.getName(),
10959                                    String.class.getName()
10960                            });
10961    
10962            /**
10963             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
10964             *
10965             * @param nodeId the node ID
10966             * @param head the head
10967             * @param parentTitle the parent title
10968             * @return the matching wiki pages
10969             * @throws SystemException if a system exception occurred
10970             */
10971            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
10972                    String parentTitle) throws SystemException {
10973                    return findByN_H_P(nodeId, head, parentTitle, QueryUtil.ALL_POS,
10974                            QueryUtil.ALL_POS, null);
10975            }
10976    
10977            /**
10978             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
10979             *
10980             * <p>
10981             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10982             * </p>
10983             *
10984             * @param nodeId the node ID
10985             * @param head the head
10986             * @param parentTitle the parent title
10987             * @param start the lower bound of the range of wiki pages
10988             * @param end the upper bound of the range of wiki pages (not inclusive)
10989             * @return the range of matching wiki pages
10990             * @throws SystemException if a system exception occurred
10991             */
10992            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
10993                    String parentTitle, int start, int end) throws SystemException {
10994                    return findByN_H_P(nodeId, head, parentTitle, start, end, null);
10995            }
10996    
10997            /**
10998             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
10999             *
11000             * <p>
11001             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11002             * </p>
11003             *
11004             * @param nodeId the node ID
11005             * @param head the head
11006             * @param parentTitle the parent title
11007             * @param start the lower bound of the range of wiki pages
11008             * @param end the upper bound of the range of wiki pages (not inclusive)
11009             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11010             * @return the ordered range of matching wiki pages
11011             * @throws SystemException if a system exception occurred
11012             */
11013            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
11014                    String parentTitle, int start, int end,
11015                    OrderByComparator orderByComparator) throws SystemException {
11016                    boolean pagination = true;
11017                    FinderPath finderPath = null;
11018                    Object[] finderArgs = null;
11019    
11020                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11021                                    (orderByComparator == null)) {
11022                            pagination = false;
11023                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P;
11024                            finderArgs = new Object[] { nodeId, head, parentTitle };
11025                    }
11026                    else {
11027                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P;
11028                            finderArgs = new Object[] {
11029                                            nodeId, head, parentTitle,
11030                                            
11031                                            start, end, orderByComparator
11032                                    };
11033                    }
11034    
11035                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
11036                                    finderArgs, this);
11037    
11038                    if ((list != null) && !list.isEmpty()) {
11039                            for (WikiPage wikiPage : list) {
11040                                    if ((nodeId != wikiPage.getNodeId()) ||
11041                                                    (head != wikiPage.getHead()) ||
11042                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle())) {
11043                                            list = null;
11044    
11045                                            break;
11046                                    }
11047                            }
11048                    }
11049    
11050                    if (list == null) {
11051                            StringBundler query = null;
11052    
11053                            if (orderByComparator != null) {
11054                                    query = new StringBundler(5 +
11055                                                    (orderByComparator.getOrderByFields().length * 3));
11056                            }
11057                            else {
11058                                    query = new StringBundler(5);
11059                            }
11060    
11061                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11062    
11063                            query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
11064    
11065                            query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
11066    
11067                            boolean bindParentTitle = false;
11068    
11069                            if (parentTitle == null) {
11070                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
11071                            }
11072                            else if (parentTitle.equals(StringPool.BLANK)) {
11073                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
11074                            }
11075                            else {
11076                                    bindParentTitle = true;
11077    
11078                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
11079                            }
11080    
11081                            if (orderByComparator != null) {
11082                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11083                                            orderByComparator);
11084                            }
11085                            else
11086                             if (pagination) {
11087                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11088                            }
11089    
11090                            String sql = query.toString();
11091    
11092                            Session session = null;
11093    
11094                            try {
11095                                    session = openSession();
11096    
11097                                    Query q = session.createQuery(sql);
11098    
11099                                    QueryPos qPos = QueryPos.getInstance(q);
11100    
11101                                    qPos.add(nodeId);
11102    
11103                                    qPos.add(head);
11104    
11105                                    if (bindParentTitle) {
11106                                            qPos.add(parentTitle.toLowerCase());
11107                                    }
11108    
11109                                    if (!pagination) {
11110                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11111                                                            start, end, false);
11112    
11113                                            Collections.sort(list);
11114    
11115                                            list = new UnmodifiableList<WikiPage>(list);
11116                                    }
11117                                    else {
11118                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11119                                                            start, end);
11120                                    }
11121    
11122                                    cacheResult(list);
11123    
11124                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11125                            }
11126                            catch (Exception e) {
11127                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11128    
11129                                    throw processException(e);
11130                            }
11131                            finally {
11132                                    closeSession(session);
11133                            }
11134                    }
11135    
11136                    return list;
11137            }
11138    
11139            /**
11140             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11141             *
11142             * @param nodeId the node ID
11143             * @param head the head
11144             * @param parentTitle the parent title
11145             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11146             * @return the first matching wiki page
11147             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11148             * @throws SystemException if a system exception occurred
11149             */
11150            public WikiPage findByN_H_P_First(long nodeId, boolean head,
11151                    String parentTitle, OrderByComparator orderByComparator)
11152                    throws NoSuchPageException, SystemException {
11153                    WikiPage wikiPage = fetchByN_H_P_First(nodeId, head, parentTitle,
11154                                    orderByComparator);
11155    
11156                    if (wikiPage != null) {
11157                            return wikiPage;
11158                    }
11159    
11160                    StringBundler msg = new StringBundler(8);
11161    
11162                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11163    
11164                    msg.append("nodeId=");
11165                    msg.append(nodeId);
11166    
11167                    msg.append(", head=");
11168                    msg.append(head);
11169    
11170                    msg.append(", parentTitle=");
11171                    msg.append(parentTitle);
11172    
11173                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11174    
11175                    throw new NoSuchPageException(msg.toString());
11176            }
11177    
11178            /**
11179             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11180             *
11181             * @param nodeId the node ID
11182             * @param head the head
11183             * @param parentTitle the parent title
11184             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11185             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
11186             * @throws SystemException if a system exception occurred
11187             */
11188            public WikiPage fetchByN_H_P_First(long nodeId, boolean head,
11189                    String parentTitle, OrderByComparator orderByComparator)
11190                    throws SystemException {
11191                    List<WikiPage> list = findByN_H_P(nodeId, head, parentTitle, 0, 1,
11192                                    orderByComparator);
11193    
11194                    if (!list.isEmpty()) {
11195                            return list.get(0);
11196                    }
11197    
11198                    return null;
11199            }
11200    
11201            /**
11202             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11203             *
11204             * @param nodeId the node ID
11205             * @param head the head
11206             * @param parentTitle the parent title
11207             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11208             * @return the last matching wiki page
11209             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11210             * @throws SystemException if a system exception occurred
11211             */
11212            public WikiPage findByN_H_P_Last(long nodeId, boolean head,
11213                    String parentTitle, OrderByComparator orderByComparator)
11214                    throws NoSuchPageException, SystemException {
11215                    WikiPage wikiPage = fetchByN_H_P_Last(nodeId, head, parentTitle,
11216                                    orderByComparator);
11217    
11218                    if (wikiPage != null) {
11219                            return wikiPage;
11220                    }
11221    
11222                    StringBundler msg = new StringBundler(8);
11223    
11224                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11225    
11226                    msg.append("nodeId=");
11227                    msg.append(nodeId);
11228    
11229                    msg.append(", head=");
11230                    msg.append(head);
11231    
11232                    msg.append(", parentTitle=");
11233                    msg.append(parentTitle);
11234    
11235                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11236    
11237                    throw new NoSuchPageException(msg.toString());
11238            }
11239    
11240            /**
11241             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11242             *
11243             * @param nodeId the node ID
11244             * @param head the head
11245             * @param parentTitle the parent title
11246             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11247             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
11248             * @throws SystemException if a system exception occurred
11249             */
11250            public WikiPage fetchByN_H_P_Last(long nodeId, boolean head,
11251                    String parentTitle, OrderByComparator orderByComparator)
11252                    throws SystemException {
11253                    int count = countByN_H_P(nodeId, head, parentTitle);
11254    
11255                    List<WikiPage> list = findByN_H_P(nodeId, head, parentTitle, count - 1,
11256                                    count, orderByComparator);
11257    
11258                    if (!list.isEmpty()) {
11259                            return list.get(0);
11260                    }
11261    
11262                    return null;
11263            }
11264    
11265            /**
11266             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11267             *
11268             * @param pageId the primary key of the current wiki page
11269             * @param nodeId the node ID
11270             * @param head the head
11271             * @param parentTitle the parent title
11272             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11273             * @return the previous, current, and next wiki page
11274             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
11275             * @throws SystemException if a system exception occurred
11276             */
11277            public WikiPage[] findByN_H_P_PrevAndNext(long pageId, long nodeId,
11278                    boolean head, String parentTitle, OrderByComparator orderByComparator)
11279                    throws NoSuchPageException, SystemException {
11280                    WikiPage wikiPage = findByPrimaryKey(pageId);
11281    
11282                    Session session = null;
11283    
11284                    try {
11285                            session = openSession();
11286    
11287                            WikiPage[] array = new WikiPageImpl[3];
11288    
11289                            array[0] = getByN_H_P_PrevAndNext(session, wikiPage, nodeId, head,
11290                                            parentTitle, orderByComparator, true);
11291    
11292                            array[1] = wikiPage;
11293    
11294                            array[2] = getByN_H_P_PrevAndNext(session, wikiPage, nodeId, head,
11295                                            parentTitle, orderByComparator, false);
11296    
11297                            return array;
11298                    }
11299                    catch (Exception e) {
11300                            throw processException(e);
11301                    }
11302                    finally {
11303                            closeSession(session);
11304                    }
11305            }
11306    
11307            protected WikiPage getByN_H_P_PrevAndNext(Session session,
11308                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
11309                    OrderByComparator orderByComparator, boolean previous) {
11310                    StringBundler query = null;
11311    
11312                    if (orderByComparator != null) {
11313                            query = new StringBundler(6 +
11314                                            (orderByComparator.getOrderByFields().length * 6));
11315                    }
11316                    else {
11317                            query = new StringBundler(3);
11318                    }
11319    
11320                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11321    
11322                    query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
11323    
11324                    query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
11325    
11326                    boolean bindParentTitle = false;
11327    
11328                    if (parentTitle == null) {
11329                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
11330                    }
11331                    else if (parentTitle.equals(StringPool.BLANK)) {
11332                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
11333                    }
11334                    else {
11335                            bindParentTitle = true;
11336    
11337                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
11338                    }
11339    
11340                    if (orderByComparator != null) {
11341                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11342    
11343                            if (orderByConditionFields.length > 0) {
11344                                    query.append(WHERE_AND);
11345                            }
11346    
11347                            for (int i = 0; i < orderByConditionFields.length; i++) {
11348                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11349                                    query.append(orderByConditionFields[i]);
11350    
11351                                    if ((i + 1) < orderByConditionFields.length) {
11352                                            if (orderByComparator.isAscending() ^ previous) {
11353                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11354                                            }
11355                                            else {
11356                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11357                                            }
11358                                    }
11359                                    else {
11360                                            if (orderByComparator.isAscending() ^ previous) {
11361                                                    query.append(WHERE_GREATER_THAN);
11362                                            }
11363                                            else {
11364                                                    query.append(WHERE_LESSER_THAN);
11365                                            }
11366                                    }
11367                            }
11368    
11369                            query.append(ORDER_BY_CLAUSE);
11370    
11371                            String[] orderByFields = orderByComparator.getOrderByFields();
11372    
11373                            for (int i = 0; i < orderByFields.length; i++) {
11374                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11375                                    query.append(orderByFields[i]);
11376    
11377                                    if ((i + 1) < orderByFields.length) {
11378                                            if (orderByComparator.isAscending() ^ previous) {
11379                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11380                                            }
11381                                            else {
11382                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11383                                            }
11384                                    }
11385                                    else {
11386                                            if (orderByComparator.isAscending() ^ previous) {
11387                                                    query.append(ORDER_BY_ASC);
11388                                            }
11389                                            else {
11390                                                    query.append(ORDER_BY_DESC);
11391                                            }
11392                                    }
11393                            }
11394                    }
11395                    else {
11396                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11397                    }
11398    
11399                    String sql = query.toString();
11400    
11401                    Query q = session.createQuery(sql);
11402    
11403                    q.setFirstResult(0);
11404                    q.setMaxResults(2);
11405    
11406                    QueryPos qPos = QueryPos.getInstance(q);
11407    
11408                    qPos.add(nodeId);
11409    
11410                    qPos.add(head);
11411    
11412                    if (bindParentTitle) {
11413                            qPos.add(parentTitle.toLowerCase());
11414                    }
11415    
11416                    if (orderByComparator != null) {
11417                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
11418    
11419                            for (Object value : values) {
11420                                    qPos.add(value);
11421                            }
11422                    }
11423    
11424                    List<WikiPage> list = q.list();
11425    
11426                    if (list.size() == 2) {
11427                            return list.get(1);
11428                    }
11429                    else {
11430                            return null;
11431                    }
11432            }
11433    
11434            /**
11435             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; from the database.
11436             *
11437             * @param nodeId the node ID
11438             * @param head the head
11439             * @param parentTitle the parent title
11440             * @throws SystemException if a system exception occurred
11441             */
11442            public void removeByN_H_P(long nodeId, boolean head, String parentTitle)
11443                    throws SystemException {
11444                    for (WikiPage wikiPage : findByN_H_P(nodeId, head, parentTitle,
11445                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11446                            remove(wikiPage);
11447                    }
11448            }
11449    
11450            /**
11451             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11452             *
11453             * @param nodeId the node ID
11454             * @param head the head
11455             * @param parentTitle the parent title
11456             * @return the number of matching wiki pages
11457             * @throws SystemException if a system exception occurred
11458             */
11459            public int countByN_H_P(long nodeId, boolean head, String parentTitle)
11460                    throws SystemException {
11461                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_P;
11462    
11463                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle };
11464    
11465                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11466                                    this);
11467    
11468                    if (count == null) {
11469                            StringBundler query = new StringBundler(4);
11470    
11471                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
11472    
11473                            query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
11474    
11475                            query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
11476    
11477                            boolean bindParentTitle = false;
11478    
11479                            if (parentTitle == null) {
11480                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
11481                            }
11482                            else if (parentTitle.equals(StringPool.BLANK)) {
11483                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
11484                            }
11485                            else {
11486                                    bindParentTitle = true;
11487    
11488                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
11489                            }
11490    
11491                            String sql = query.toString();
11492    
11493                            Session session = null;
11494    
11495                            try {
11496                                    session = openSession();
11497    
11498                                    Query q = session.createQuery(sql);
11499    
11500                                    QueryPos qPos = QueryPos.getInstance(q);
11501    
11502                                    qPos.add(nodeId);
11503    
11504                                    qPos.add(head);
11505    
11506                                    if (bindParentTitle) {
11507                                            qPos.add(parentTitle.toLowerCase());
11508                                    }
11509    
11510                                    count = (Long)q.uniqueResult();
11511    
11512                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11513                            }
11514                            catch (Exception e) {
11515                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11516    
11517                                    throw processException(e);
11518                            }
11519                            finally {
11520                                    closeSession(session);
11521                            }
11522                    }
11523    
11524                    return count.intValue();
11525            }
11526    
11527            private static final String _FINDER_COLUMN_N_H_P_NODEID_2 = "wikiPage.nodeId = ? AND ";
11528            private static final String _FINDER_COLUMN_N_H_P_HEAD_2 = "wikiPage.head = ? AND ";
11529            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL";
11530            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ?";
11531            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '')";
11532            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11533                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
11534                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_S",
11535                            new String[] {
11536                                    Long.class.getName(), Boolean.class.getName(),
11537                                    Integer.class.getName(),
11538                                    
11539                            Integer.class.getName(), Integer.class.getName(),
11540                                    OrderByComparator.class.getName()
11541                            });
11542            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11543                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
11544                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_S",
11545                            new String[] {
11546                                    Long.class.getName(), Boolean.class.getName(),
11547                                    Integer.class.getName()
11548                            },
11549                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
11550                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
11551                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
11552                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
11553                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
11554            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11555                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11556                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_S",
11557                            new String[] {
11558                                    Long.class.getName(), Boolean.class.getName(),
11559                                    Integer.class.getName()
11560                            });
11561    
11562            /**
11563             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
11564             *
11565             * @param nodeId the node ID
11566             * @param head the head
11567             * @param status the status
11568             * @return the matching wiki pages
11569             * @throws SystemException if a system exception occurred
11570             */
11571            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status)
11572                    throws SystemException {
11573                    return findByN_H_S(nodeId, head, status, QueryUtil.ALL_POS,
11574                            QueryUtil.ALL_POS, null);
11575            }
11576    
11577            /**
11578             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
11579             *
11580             * <p>
11581             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11582             * </p>
11583             *
11584             * @param nodeId the node ID
11585             * @param head the head
11586             * @param status the status
11587             * @param start the lower bound of the range of wiki pages
11588             * @param end the upper bound of the range of wiki pages (not inclusive)
11589             * @return the range of matching wiki pages
11590             * @throws SystemException if a system exception occurred
11591             */
11592            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status,
11593                    int start, int end) throws SystemException {
11594                    return findByN_H_S(nodeId, head, status, start, end, null);
11595            }
11596    
11597            /**
11598             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
11599             *
11600             * <p>
11601             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11602             * </p>
11603             *
11604             * @param nodeId the node ID
11605             * @param head the head
11606             * @param status the status
11607             * @param start the lower bound of the range of wiki pages
11608             * @param end the upper bound of the range of wiki pages (not inclusive)
11609             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11610             * @return the ordered range of matching wiki pages
11611             * @throws SystemException if a system exception occurred
11612             */
11613            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status,
11614                    int start, int end, OrderByComparator orderByComparator)
11615                    throws SystemException {
11616                    boolean pagination = true;
11617                    FinderPath finderPath = null;
11618                    Object[] finderArgs = null;
11619    
11620                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11621                                    (orderByComparator == null)) {
11622                            pagination = false;
11623                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S;
11624                            finderArgs = new Object[] { nodeId, head, status };
11625                    }
11626                    else {
11627                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_S;
11628                            finderArgs = new Object[] {
11629                                            nodeId, head, status,
11630                                            
11631                                            start, end, orderByComparator
11632                                    };
11633                    }
11634    
11635                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
11636                                    finderArgs, this);
11637    
11638                    if ((list != null) && !list.isEmpty()) {
11639                            for (WikiPage wikiPage : list) {
11640                                    if ((nodeId != wikiPage.getNodeId()) ||
11641                                                    (head != wikiPage.getHead()) ||
11642                                                    (status != wikiPage.getStatus())) {
11643                                            list = null;
11644    
11645                                            break;
11646                                    }
11647                            }
11648                    }
11649    
11650                    if (list == null) {
11651                            StringBundler query = null;
11652    
11653                            if (orderByComparator != null) {
11654                                    query = new StringBundler(5 +
11655                                                    (orderByComparator.getOrderByFields().length * 3));
11656                            }
11657                            else {
11658                                    query = new StringBundler(5);
11659                            }
11660    
11661                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11662    
11663                            query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
11664    
11665                            query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
11666    
11667                            query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
11668    
11669                            if (orderByComparator != null) {
11670                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11671                                            orderByComparator);
11672                            }
11673                            else
11674                             if (pagination) {
11675                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11676                            }
11677    
11678                            String sql = query.toString();
11679    
11680                            Session session = null;
11681    
11682                            try {
11683                                    session = openSession();
11684    
11685                                    Query q = session.createQuery(sql);
11686    
11687                                    QueryPos qPos = QueryPos.getInstance(q);
11688    
11689                                    qPos.add(nodeId);
11690    
11691                                    qPos.add(head);
11692    
11693                                    qPos.add(status);
11694    
11695                                    if (!pagination) {
11696                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11697                                                            start, end, false);
11698    
11699                                            Collections.sort(list);
11700    
11701                                            list = new UnmodifiableList<WikiPage>(list);
11702                                    }
11703                                    else {
11704                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11705                                                            start, end);
11706                                    }
11707    
11708                                    cacheResult(list);
11709    
11710                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11711                            }
11712                            catch (Exception e) {
11713                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11714    
11715                                    throw processException(e);
11716                            }
11717                            finally {
11718                                    closeSession(session);
11719                            }
11720                    }
11721    
11722                    return list;
11723            }
11724    
11725            /**
11726             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
11727             *
11728             * @param nodeId the node ID
11729             * @param head the head
11730             * @param status the status
11731             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11732             * @return the first matching wiki page
11733             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11734             * @throws SystemException if a system exception occurred
11735             */
11736            public WikiPage findByN_H_S_First(long nodeId, boolean head, int status,
11737                    OrderByComparator orderByComparator)
11738                    throws NoSuchPageException, SystemException {
11739                    WikiPage wikiPage = fetchByN_H_S_First(nodeId, head, status,
11740                                    orderByComparator);
11741    
11742                    if (wikiPage != null) {
11743                            return wikiPage;
11744                    }
11745    
11746                    StringBundler msg = new StringBundler(8);
11747    
11748                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11749    
11750                    msg.append("nodeId=");
11751                    msg.append(nodeId);
11752    
11753                    msg.append(", head=");
11754                    msg.append(head);
11755    
11756                    msg.append(", status=");
11757                    msg.append(status);
11758    
11759                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11760    
11761                    throw new NoSuchPageException(msg.toString());
11762            }
11763    
11764            /**
11765             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
11766             *
11767             * @param nodeId the node ID
11768             * @param head the head
11769             * @param status the status
11770             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11771             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
11772             * @throws SystemException if a system exception occurred
11773             */
11774            public WikiPage fetchByN_H_S_First(long nodeId, boolean head, int status,
11775                    OrderByComparator orderByComparator) throws SystemException {
11776                    List<WikiPage> list = findByN_H_S(nodeId, head, status, 0, 1,
11777                                    orderByComparator);
11778    
11779                    if (!list.isEmpty()) {
11780                            return list.get(0);
11781                    }
11782    
11783                    return null;
11784            }
11785    
11786            /**
11787             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
11788             *
11789             * @param nodeId the node ID
11790             * @param head the head
11791             * @param status the status
11792             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11793             * @return the last matching wiki page
11794             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11795             * @throws SystemException if a system exception occurred
11796             */
11797            public WikiPage findByN_H_S_Last(long nodeId, boolean head, int status,
11798                    OrderByComparator orderByComparator)
11799                    throws NoSuchPageException, SystemException {
11800                    WikiPage wikiPage = fetchByN_H_S_Last(nodeId, head, status,
11801                                    orderByComparator);
11802    
11803                    if (wikiPage != null) {
11804                            return wikiPage;
11805                    }
11806    
11807                    StringBundler msg = new StringBundler(8);
11808    
11809                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11810    
11811                    msg.append("nodeId=");
11812                    msg.append(nodeId);
11813    
11814                    msg.append(", head=");
11815                    msg.append(head);
11816    
11817                    msg.append(", status=");
11818                    msg.append(status);
11819    
11820                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11821    
11822                    throw new NoSuchPageException(msg.toString());
11823            }
11824    
11825            /**
11826             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
11827             *
11828             * @param nodeId the node ID
11829             * @param head the head
11830             * @param status the status
11831             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11832             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
11833             * @throws SystemException if a system exception occurred
11834             */
11835            public WikiPage fetchByN_H_S_Last(long nodeId, boolean head, int status,
11836                    OrderByComparator orderByComparator) throws SystemException {
11837                    int count = countByN_H_S(nodeId, head, status);
11838    
11839                    List<WikiPage> list = findByN_H_S(nodeId, head, status, count - 1,
11840                                    count, orderByComparator);
11841    
11842                    if (!list.isEmpty()) {
11843                            return list.get(0);
11844                    }
11845    
11846                    return null;
11847            }
11848    
11849            /**
11850             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
11851             *
11852             * @param pageId the primary key of the current wiki page
11853             * @param nodeId the node ID
11854             * @param head the head
11855             * @param status the status
11856             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11857             * @return the previous, current, and next wiki page
11858             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
11859             * @throws SystemException if a system exception occurred
11860             */
11861            public WikiPage[] findByN_H_S_PrevAndNext(long pageId, long nodeId,
11862                    boolean head, int status, OrderByComparator orderByComparator)
11863                    throws NoSuchPageException, SystemException {
11864                    WikiPage wikiPage = findByPrimaryKey(pageId);
11865    
11866                    Session session = null;
11867    
11868                    try {
11869                            session = openSession();
11870    
11871                            WikiPage[] array = new WikiPageImpl[3];
11872    
11873                            array[0] = getByN_H_S_PrevAndNext(session, wikiPage, nodeId, head,
11874                                            status, orderByComparator, true);
11875    
11876                            array[1] = wikiPage;
11877    
11878                            array[2] = getByN_H_S_PrevAndNext(session, wikiPage, nodeId, head,
11879                                            status, orderByComparator, false);
11880    
11881                            return array;
11882                    }
11883                    catch (Exception e) {
11884                            throw processException(e);
11885                    }
11886                    finally {
11887                            closeSession(session);
11888                    }
11889            }
11890    
11891            protected WikiPage getByN_H_S_PrevAndNext(Session session,
11892                    WikiPage wikiPage, long nodeId, boolean head, int status,
11893                    OrderByComparator orderByComparator, boolean previous) {
11894                    StringBundler query = null;
11895    
11896                    if (orderByComparator != null) {
11897                            query = new StringBundler(6 +
11898                                            (orderByComparator.getOrderByFields().length * 6));
11899                    }
11900                    else {
11901                            query = new StringBundler(3);
11902                    }
11903    
11904                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11905    
11906                    query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
11907    
11908                    query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
11909    
11910                    query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
11911    
11912                    if (orderByComparator != null) {
11913                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11914    
11915                            if (orderByConditionFields.length > 0) {
11916                                    query.append(WHERE_AND);
11917                            }
11918    
11919                            for (int i = 0; i < orderByConditionFields.length; i++) {
11920                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11921                                    query.append(orderByConditionFields[i]);
11922    
11923                                    if ((i + 1) < orderByConditionFields.length) {
11924                                            if (orderByComparator.isAscending() ^ previous) {
11925                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11926                                            }
11927                                            else {
11928                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11929                                            }
11930                                    }
11931                                    else {
11932                                            if (orderByComparator.isAscending() ^ previous) {
11933                                                    query.append(WHERE_GREATER_THAN);
11934                                            }
11935                                            else {
11936                                                    query.append(WHERE_LESSER_THAN);
11937                                            }
11938                                    }
11939                            }
11940    
11941                            query.append(ORDER_BY_CLAUSE);
11942    
11943                            String[] orderByFields = orderByComparator.getOrderByFields();
11944    
11945                            for (int i = 0; i < orderByFields.length; i++) {
11946                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11947                                    query.append(orderByFields[i]);
11948    
11949                                    if ((i + 1) < orderByFields.length) {
11950                                            if (orderByComparator.isAscending() ^ previous) {
11951                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11952                                            }
11953                                            else {
11954                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11955                                            }
11956                                    }
11957                                    else {
11958                                            if (orderByComparator.isAscending() ^ previous) {
11959                                                    query.append(ORDER_BY_ASC);
11960                                            }
11961                                            else {
11962                                                    query.append(ORDER_BY_DESC);
11963                                            }
11964                                    }
11965                            }
11966                    }
11967                    else {
11968                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11969                    }
11970    
11971                    String sql = query.toString();
11972    
11973                    Query q = session.createQuery(sql);
11974    
11975                    q.setFirstResult(0);
11976                    q.setMaxResults(2);
11977    
11978                    QueryPos qPos = QueryPos.getInstance(q);
11979    
11980                    qPos.add(nodeId);
11981    
11982                    qPos.add(head);
11983    
11984                    qPos.add(status);
11985    
11986                    if (orderByComparator != null) {
11987                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
11988    
11989                            for (Object value : values) {
11990                                    qPos.add(value);
11991                            }
11992                    }
11993    
11994                    List<WikiPage> list = q.list();
11995    
11996                    if (list.size() == 2) {
11997                            return list.get(1);
11998                    }
11999                    else {
12000                            return null;
12001                    }
12002            }
12003    
12004            /**
12005             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63; from the database.
12006             *
12007             * @param nodeId the node ID
12008             * @param head the head
12009             * @param status the status
12010             * @throws SystemException if a system exception occurred
12011             */
12012            public void removeByN_H_S(long nodeId, boolean head, int status)
12013                    throws SystemException {
12014                    for (WikiPage wikiPage : findByN_H_S(nodeId, head, status,
12015                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12016                            remove(wikiPage);
12017                    }
12018            }
12019    
12020            /**
12021             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
12022             *
12023             * @param nodeId the node ID
12024             * @param head the head
12025             * @param status the status
12026             * @return the number of matching wiki pages
12027             * @throws SystemException if a system exception occurred
12028             */
12029            public int countByN_H_S(long nodeId, boolean head, int status)
12030                    throws SystemException {
12031                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_S;
12032    
12033                    Object[] finderArgs = new Object[] { nodeId, head, status };
12034    
12035                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12036                                    this);
12037    
12038                    if (count == null) {
12039                            StringBundler query = new StringBundler(4);
12040    
12041                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
12042    
12043                            query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
12044    
12045                            query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
12046    
12047                            query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
12048    
12049                            String sql = query.toString();
12050    
12051                            Session session = null;
12052    
12053                            try {
12054                                    session = openSession();
12055    
12056                                    Query q = session.createQuery(sql);
12057    
12058                                    QueryPos qPos = QueryPos.getInstance(q);
12059    
12060                                    qPos.add(nodeId);
12061    
12062                                    qPos.add(head);
12063    
12064                                    qPos.add(status);
12065    
12066                                    count = (Long)q.uniqueResult();
12067    
12068                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12069                            }
12070                            catch (Exception e) {
12071                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12072    
12073                                    throw processException(e);
12074                            }
12075                            finally {
12076                                    closeSession(session);
12077                            }
12078                    }
12079    
12080                    return count.intValue();
12081            }
12082    
12083            private static final String _FINDER_COLUMN_N_H_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
12084            private static final String _FINDER_COLUMN_N_H_S_HEAD_2 = "wikiPage.head = ? AND ";
12085            private static final String _FINDER_COLUMN_N_H_S_STATUS_2 = "wikiPage.status = ?";
12086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12087                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
12088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_N_S",
12089                            new String[] {
12090                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12091                                    Integer.class.getName(),
12092                                    
12093                            Integer.class.getName(), Integer.class.getName(),
12094                                    OrderByComparator.class.getName()
12095                            });
12096            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S =
12097                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12098                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
12099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_N_S",
12100                            new String[] {
12101                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12102                                    Integer.class.getName()
12103                            },
12104                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
12105                            WikiPageModelImpl.USERID_COLUMN_BITMASK |
12106                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
12107                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
12108                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
12109                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
12110            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12111                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12112                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_N_S",
12113                            new String[] {
12114                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12115                                    Integer.class.getName()
12116                            });
12117    
12118            /**
12119             * Returns all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12120             *
12121             * @param groupId the group ID
12122             * @param userId the user ID
12123             * @param nodeId the node ID
12124             * @param status the status
12125             * @return the matching wiki pages
12126             * @throws SystemException if a system exception occurred
12127             */
12128            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
12129                    int status) throws SystemException {
12130                    return findByG_U_N_S(groupId, userId, nodeId, status,
12131                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12132            }
12133    
12134            /**
12135             * Returns a range of all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12136             *
12137             * <p>
12138             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12139             * </p>
12140             *
12141             * @param groupId the group ID
12142             * @param userId the user ID
12143             * @param nodeId the node ID
12144             * @param status the status
12145             * @param start the lower bound of the range of wiki pages
12146             * @param end the upper bound of the range of wiki pages (not inclusive)
12147             * @return the range of matching wiki pages
12148             * @throws SystemException if a system exception occurred
12149             */
12150            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
12151                    int status, int start, int end) throws SystemException {
12152                    return findByG_U_N_S(groupId, userId, nodeId, status, start, end, null);
12153            }
12154    
12155            /**
12156             * Returns an ordered range of all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12157             *
12158             * <p>
12159             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12160             * </p>
12161             *
12162             * @param groupId the group ID
12163             * @param userId the user ID
12164             * @param nodeId the node ID
12165             * @param status the status
12166             * @param start the lower bound of the range of wiki pages
12167             * @param end the upper bound of the range of wiki pages (not inclusive)
12168             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12169             * @return the ordered range of matching wiki pages
12170             * @throws SystemException if a system exception occurred
12171             */
12172            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
12173                    int status, int start, int end, OrderByComparator orderByComparator)
12174                    throws SystemException {
12175                    boolean pagination = true;
12176                    FinderPath finderPath = null;
12177                    Object[] finderArgs = null;
12178    
12179                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12180                                    (orderByComparator == null)) {
12181                            pagination = false;
12182                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S;
12183                            finderArgs = new Object[] { groupId, userId, nodeId, status };
12184                    }
12185                    else {
12186                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_N_S;
12187                            finderArgs = new Object[] {
12188                                            groupId, userId, nodeId, status,
12189                                            
12190                                            start, end, orderByComparator
12191                                    };
12192                    }
12193    
12194                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
12195                                    finderArgs, this);
12196    
12197                    if ((list != null) && !list.isEmpty()) {
12198                            for (WikiPage wikiPage : list) {
12199                                    if ((groupId != wikiPage.getGroupId()) ||
12200                                                    (userId != wikiPage.getUserId()) ||
12201                                                    (nodeId != wikiPage.getNodeId()) ||
12202                                                    (status != wikiPage.getStatus())) {
12203                                            list = null;
12204    
12205                                            break;
12206                                    }
12207                            }
12208                    }
12209    
12210                    if (list == null) {
12211                            StringBundler query = null;
12212    
12213                            if (orderByComparator != null) {
12214                                    query = new StringBundler(6 +
12215                                                    (orderByComparator.getOrderByFields().length * 3));
12216                            }
12217                            else {
12218                                    query = new StringBundler(6);
12219                            }
12220    
12221                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
12222    
12223                            query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12224    
12225                            query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12226    
12227                            query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12228    
12229                            query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12230    
12231                            if (orderByComparator != null) {
12232                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12233                                            orderByComparator);
12234                            }
12235                            else
12236                             if (pagination) {
12237                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12238                            }
12239    
12240                            String sql = query.toString();
12241    
12242                            Session session = null;
12243    
12244                            try {
12245                                    session = openSession();
12246    
12247                                    Query q = session.createQuery(sql);
12248    
12249                                    QueryPos qPos = QueryPos.getInstance(q);
12250    
12251                                    qPos.add(groupId);
12252    
12253                                    qPos.add(userId);
12254    
12255                                    qPos.add(nodeId);
12256    
12257                                    qPos.add(status);
12258    
12259                                    if (!pagination) {
12260                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
12261                                                            start, end, false);
12262    
12263                                            Collections.sort(list);
12264    
12265                                            list = new UnmodifiableList<WikiPage>(list);
12266                                    }
12267                                    else {
12268                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
12269                                                            start, end);
12270                                    }
12271    
12272                                    cacheResult(list);
12273    
12274                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
12275                            }
12276                            catch (Exception e) {
12277                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12278    
12279                                    throw processException(e);
12280                            }
12281                            finally {
12282                                    closeSession(session);
12283                            }
12284                    }
12285    
12286                    return list;
12287            }
12288    
12289            /**
12290             * Returns the first wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12291             *
12292             * @param groupId the group ID
12293             * @param userId the user ID
12294             * @param nodeId the node ID
12295             * @param status the status
12296             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12297             * @return the first matching wiki page
12298             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
12299             * @throws SystemException if a system exception occurred
12300             */
12301            public WikiPage findByG_U_N_S_First(long groupId, long userId, long nodeId,
12302                    int status, OrderByComparator orderByComparator)
12303                    throws NoSuchPageException, SystemException {
12304                    WikiPage wikiPage = fetchByG_U_N_S_First(groupId, userId, nodeId,
12305                                    status, orderByComparator);
12306    
12307                    if (wikiPage != null) {
12308                            return wikiPage;
12309                    }
12310    
12311                    StringBundler msg = new StringBundler(10);
12312    
12313                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12314    
12315                    msg.append("groupId=");
12316                    msg.append(groupId);
12317    
12318                    msg.append(", userId=");
12319                    msg.append(userId);
12320    
12321                    msg.append(", nodeId=");
12322                    msg.append(nodeId);
12323    
12324                    msg.append(", status=");
12325                    msg.append(status);
12326    
12327                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12328    
12329                    throw new NoSuchPageException(msg.toString());
12330            }
12331    
12332            /**
12333             * Returns the first wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12334             *
12335             * @param groupId the group ID
12336             * @param userId the user ID
12337             * @param nodeId the node ID
12338             * @param status the status
12339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12340             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
12341             * @throws SystemException if a system exception occurred
12342             */
12343            public WikiPage fetchByG_U_N_S_First(long groupId, long userId,
12344                    long nodeId, int status, OrderByComparator orderByComparator)
12345                    throws SystemException {
12346                    List<WikiPage> list = findByG_U_N_S(groupId, userId, nodeId, status, 0,
12347                                    1, orderByComparator);
12348    
12349                    if (!list.isEmpty()) {
12350                            return list.get(0);
12351                    }
12352    
12353                    return null;
12354            }
12355    
12356            /**
12357             * Returns the last wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12358             *
12359             * @param groupId the group ID
12360             * @param userId the user ID
12361             * @param nodeId the node ID
12362             * @param status the status
12363             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12364             * @return the last matching wiki page
12365             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
12366             * @throws SystemException if a system exception occurred
12367             */
12368            public WikiPage findByG_U_N_S_Last(long groupId, long userId, long nodeId,
12369                    int status, OrderByComparator orderByComparator)
12370                    throws NoSuchPageException, SystemException {
12371                    WikiPage wikiPage = fetchByG_U_N_S_Last(groupId, userId, nodeId,
12372                                    status, orderByComparator);
12373    
12374                    if (wikiPage != null) {
12375                            return wikiPage;
12376                    }
12377    
12378                    StringBundler msg = new StringBundler(10);
12379    
12380                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12381    
12382                    msg.append("groupId=");
12383                    msg.append(groupId);
12384    
12385                    msg.append(", userId=");
12386                    msg.append(userId);
12387    
12388                    msg.append(", nodeId=");
12389                    msg.append(nodeId);
12390    
12391                    msg.append(", status=");
12392                    msg.append(status);
12393    
12394                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12395    
12396                    throw new NoSuchPageException(msg.toString());
12397            }
12398    
12399            /**
12400             * Returns the last wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12401             *
12402             * @param groupId the group ID
12403             * @param userId the user ID
12404             * @param nodeId the node ID
12405             * @param status the status
12406             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12407             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
12408             * @throws SystemException if a system exception occurred
12409             */
12410            public WikiPage fetchByG_U_N_S_Last(long groupId, long userId, long nodeId,
12411                    int status, OrderByComparator orderByComparator)
12412                    throws SystemException {
12413                    int count = countByG_U_N_S(groupId, userId, nodeId, status);
12414    
12415                    List<WikiPage> list = findByG_U_N_S(groupId, userId, nodeId, status,
12416                                    count - 1, count, orderByComparator);
12417    
12418                    if (!list.isEmpty()) {
12419                            return list.get(0);
12420                    }
12421    
12422                    return null;
12423            }
12424    
12425            /**
12426             * Returns the wiki pages before and after the current wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12427             *
12428             * @param pageId the primary key of the current wiki page
12429             * @param groupId the group ID
12430             * @param userId the user ID
12431             * @param nodeId the node ID
12432             * @param status the status
12433             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12434             * @return the previous, current, and next wiki page
12435             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
12436             * @throws SystemException if a system exception occurred
12437             */
12438            public WikiPage[] findByG_U_N_S_PrevAndNext(long pageId, long groupId,
12439                    long userId, long nodeId, int status,
12440                    OrderByComparator orderByComparator)
12441                    throws NoSuchPageException, SystemException {
12442                    WikiPage wikiPage = findByPrimaryKey(pageId);
12443    
12444                    Session session = null;
12445    
12446                    try {
12447                            session = openSession();
12448    
12449                            WikiPage[] array = new WikiPageImpl[3];
12450    
12451                            array[0] = getByG_U_N_S_PrevAndNext(session, wikiPage, groupId,
12452                                            userId, nodeId, status, orderByComparator, true);
12453    
12454                            array[1] = wikiPage;
12455    
12456                            array[2] = getByG_U_N_S_PrevAndNext(session, wikiPage, groupId,
12457                                            userId, nodeId, status, orderByComparator, false);
12458    
12459                            return array;
12460                    }
12461                    catch (Exception e) {
12462                            throw processException(e);
12463                    }
12464                    finally {
12465                            closeSession(session);
12466                    }
12467            }
12468    
12469            protected WikiPage getByG_U_N_S_PrevAndNext(Session session,
12470                    WikiPage wikiPage, long groupId, long userId, long nodeId, int status,
12471                    OrderByComparator orderByComparator, boolean previous) {
12472                    StringBundler query = null;
12473    
12474                    if (orderByComparator != null) {
12475                            query = new StringBundler(6 +
12476                                            (orderByComparator.getOrderByFields().length * 6));
12477                    }
12478                    else {
12479                            query = new StringBundler(3);
12480                    }
12481    
12482                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
12483    
12484                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12485    
12486                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12487    
12488                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12489    
12490                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12491    
12492                    if (orderByComparator != null) {
12493                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12494    
12495                            if (orderByConditionFields.length > 0) {
12496                                    query.append(WHERE_AND);
12497                            }
12498    
12499                            for (int i = 0; i < orderByConditionFields.length; i++) {
12500                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12501                                    query.append(orderByConditionFields[i]);
12502    
12503                                    if ((i + 1) < orderByConditionFields.length) {
12504                                            if (orderByComparator.isAscending() ^ previous) {
12505                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12506                                            }
12507                                            else {
12508                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12509                                            }
12510                                    }
12511                                    else {
12512                                            if (orderByComparator.isAscending() ^ previous) {
12513                                                    query.append(WHERE_GREATER_THAN);
12514                                            }
12515                                            else {
12516                                                    query.append(WHERE_LESSER_THAN);
12517                                            }
12518                                    }
12519                            }
12520    
12521                            query.append(ORDER_BY_CLAUSE);
12522    
12523                            String[] orderByFields = orderByComparator.getOrderByFields();
12524    
12525                            for (int i = 0; i < orderByFields.length; i++) {
12526                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12527                                    query.append(orderByFields[i]);
12528    
12529                                    if ((i + 1) < orderByFields.length) {
12530                                            if (orderByComparator.isAscending() ^ previous) {
12531                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12532                                            }
12533                                            else {
12534                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12535                                            }
12536                                    }
12537                                    else {
12538                                            if (orderByComparator.isAscending() ^ previous) {
12539                                                    query.append(ORDER_BY_ASC);
12540                                            }
12541                                            else {
12542                                                    query.append(ORDER_BY_DESC);
12543                                            }
12544                                    }
12545                            }
12546                    }
12547                    else {
12548                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12549                    }
12550    
12551                    String sql = query.toString();
12552    
12553                    Query q = session.createQuery(sql);
12554    
12555                    q.setFirstResult(0);
12556                    q.setMaxResults(2);
12557    
12558                    QueryPos qPos = QueryPos.getInstance(q);
12559    
12560                    qPos.add(groupId);
12561    
12562                    qPos.add(userId);
12563    
12564                    qPos.add(nodeId);
12565    
12566                    qPos.add(status);
12567    
12568                    if (orderByComparator != null) {
12569                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
12570    
12571                            for (Object value : values) {
12572                                    qPos.add(value);
12573                            }
12574                    }
12575    
12576                    List<WikiPage> list = q.list();
12577    
12578                    if (list.size() == 2) {
12579                            return list.get(1);
12580                    }
12581                    else {
12582                            return null;
12583                    }
12584            }
12585    
12586            /**
12587             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12588             *
12589             * @param groupId the group ID
12590             * @param userId the user ID
12591             * @param nodeId the node ID
12592             * @param status the status
12593             * @return the matching wiki pages that the user has permission to view
12594             * @throws SystemException if a system exception occurred
12595             */
12596            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
12597                    long nodeId, int status) throws SystemException {
12598                    return filterFindByG_U_N_S(groupId, userId, nodeId, status,
12599                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12600            }
12601    
12602            /**
12603             * Returns a range of all the wiki pages that the user has permission to view where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12604             *
12605             * <p>
12606             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12607             * </p>
12608             *
12609             * @param groupId the group ID
12610             * @param userId the user ID
12611             * @param nodeId the node ID
12612             * @param status the status
12613             * @param start the lower bound of the range of wiki pages
12614             * @param end the upper bound of the range of wiki pages (not inclusive)
12615             * @return the range of matching wiki pages that the user has permission to view
12616             * @throws SystemException if a system exception occurred
12617             */
12618            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
12619                    long nodeId, int status, int start, int end) throws SystemException {
12620                    return filterFindByG_U_N_S(groupId, userId, nodeId, status, start, end,
12621                            null);
12622            }
12623    
12624            /**
12625             * Returns an ordered range of all the wiki pages that the user has permissions to view where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12626             *
12627             * <p>
12628             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12629             * </p>
12630             *
12631             * @param groupId the group ID
12632             * @param userId the user ID
12633             * @param nodeId the node ID
12634             * @param status the status
12635             * @param start the lower bound of the range of wiki pages
12636             * @param end the upper bound of the range of wiki pages (not inclusive)
12637             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12638             * @return the ordered range of matching wiki pages that the user has permission to view
12639             * @throws SystemException if a system exception occurred
12640             */
12641            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
12642                    long nodeId, int status, int start, int end,
12643                    OrderByComparator orderByComparator) throws SystemException {
12644                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12645                            return findByG_U_N_S(groupId, userId, nodeId, status, start, end,
12646                                    orderByComparator);
12647                    }
12648    
12649                    StringBundler query = null;
12650    
12651                    if (orderByComparator != null) {
12652                            query = new StringBundler(6 +
12653                                            (orderByComparator.getOrderByFields().length * 3));
12654                    }
12655                    else {
12656                            query = new StringBundler(6);
12657                    }
12658    
12659                    if (getDB().isSupportsInlineDistinct()) {
12660                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
12661                    }
12662                    else {
12663                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
12664                    }
12665    
12666                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12667    
12668                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12669    
12670                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12671    
12672                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12673    
12674                    if (!getDB().isSupportsInlineDistinct()) {
12675                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
12676                    }
12677    
12678                    if (orderByComparator != null) {
12679                            if (getDB().isSupportsInlineDistinct()) {
12680                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12681                                            orderByComparator, true);
12682                            }
12683                            else {
12684                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12685                                            orderByComparator, true);
12686                            }
12687                    }
12688                    else {
12689                            if (getDB().isSupportsInlineDistinct()) {
12690                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12691                            }
12692                            else {
12693                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
12694                            }
12695                    }
12696    
12697                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12698                                    WikiPage.class.getName(),
12699                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12700    
12701                    Session session = null;
12702    
12703                    try {
12704                            session = openSession();
12705    
12706                            SQLQuery q = session.createSQLQuery(sql);
12707    
12708                            if (getDB().isSupportsInlineDistinct()) {
12709                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
12710                            }
12711                            else {
12712                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
12713                            }
12714    
12715                            QueryPos qPos = QueryPos.getInstance(q);
12716    
12717                            qPos.add(groupId);
12718    
12719                            qPos.add(userId);
12720    
12721                            qPos.add(nodeId);
12722    
12723                            qPos.add(status);
12724    
12725                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
12726                    }
12727                    catch (Exception e) {
12728                            throw processException(e);
12729                    }
12730                    finally {
12731                            closeSession(session);
12732                    }
12733            }
12734    
12735            /**
12736             * Returns the wiki pages before and after the current wiki page in the ordered set of wiki pages that the user has permission to view where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12737             *
12738             * @param pageId the primary key of the current wiki page
12739             * @param groupId the group ID
12740             * @param userId the user ID
12741             * @param nodeId the node ID
12742             * @param status the status
12743             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12744             * @return the previous, current, and next wiki page
12745             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
12746             * @throws SystemException if a system exception occurred
12747             */
12748            public WikiPage[] filterFindByG_U_N_S_PrevAndNext(long pageId,
12749                    long groupId, long userId, long nodeId, int status,
12750                    OrderByComparator orderByComparator)
12751                    throws NoSuchPageException, SystemException {
12752                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12753                            return findByG_U_N_S_PrevAndNext(pageId, groupId, userId, nodeId,
12754                                    status, orderByComparator);
12755                    }
12756    
12757                    WikiPage wikiPage = findByPrimaryKey(pageId);
12758    
12759                    Session session = null;
12760    
12761                    try {
12762                            session = openSession();
12763    
12764                            WikiPage[] array = new WikiPageImpl[3];
12765    
12766                            array[0] = filterGetByG_U_N_S_PrevAndNext(session, wikiPage,
12767                                            groupId, userId, nodeId, status, orderByComparator, true);
12768    
12769                            array[1] = wikiPage;
12770    
12771                            array[2] = filterGetByG_U_N_S_PrevAndNext(session, wikiPage,
12772                                            groupId, userId, nodeId, status, orderByComparator, false);
12773    
12774                            return array;
12775                    }
12776                    catch (Exception e) {
12777                            throw processException(e);
12778                    }
12779                    finally {
12780                            closeSession(session);
12781                    }
12782            }
12783    
12784            protected WikiPage filterGetByG_U_N_S_PrevAndNext(Session session,
12785                    WikiPage wikiPage, long groupId, long userId, long nodeId, int status,
12786                    OrderByComparator orderByComparator, boolean previous) {
12787                    StringBundler query = null;
12788    
12789                    if (orderByComparator != null) {
12790                            query = new StringBundler(6 +
12791                                            (orderByComparator.getOrderByFields().length * 6));
12792                    }
12793                    else {
12794                            query = new StringBundler(3);
12795                    }
12796    
12797                    if (getDB().isSupportsInlineDistinct()) {
12798                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
12799                    }
12800                    else {
12801                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
12802                    }
12803    
12804                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12805    
12806                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12807    
12808                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12809    
12810                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12811    
12812                    if (!getDB().isSupportsInlineDistinct()) {
12813                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
12814                    }
12815    
12816                    if (orderByComparator != null) {
12817                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12818    
12819                            if (orderByConditionFields.length > 0) {
12820                                    query.append(WHERE_AND);
12821                            }
12822    
12823                            for (int i = 0; i < orderByConditionFields.length; i++) {
12824                                    if (getDB().isSupportsInlineDistinct()) {
12825                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12826                                    }
12827                                    else {
12828                                            query.append(_ORDER_BY_ENTITY_TABLE);
12829                                    }
12830    
12831                                    query.append(orderByConditionFields[i]);
12832    
12833                                    if ((i + 1) < orderByConditionFields.length) {
12834                                            if (orderByComparator.isAscending() ^ previous) {
12835                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12836                                            }
12837                                            else {
12838                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12839                                            }
12840                                    }
12841                                    else {
12842                                            if (orderByComparator.isAscending() ^ previous) {
12843                                                    query.append(WHERE_GREATER_THAN);
12844                                            }
12845                                            else {
12846                                                    query.append(WHERE_LESSER_THAN);
12847                                            }
12848                                    }
12849                            }
12850    
12851                            query.append(ORDER_BY_CLAUSE);
12852    
12853                            String[] orderByFields = orderByComparator.getOrderByFields();
12854    
12855                            for (int i = 0; i < orderByFields.length; i++) {
12856                                    if (getDB().isSupportsInlineDistinct()) {
12857                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12858                                    }
12859                                    else {
12860                                            query.append(_ORDER_BY_ENTITY_TABLE);
12861                                    }
12862    
12863                                    query.append(orderByFields[i]);
12864    
12865                                    if ((i + 1) < orderByFields.length) {
12866                                            if (orderByComparator.isAscending() ^ previous) {
12867                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12868                                            }
12869                                            else {
12870                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12871                                            }
12872                                    }
12873                                    else {
12874                                            if (orderByComparator.isAscending() ^ previous) {
12875                                                    query.append(ORDER_BY_ASC);
12876                                            }
12877                                            else {
12878                                                    query.append(ORDER_BY_DESC);
12879                                            }
12880                                    }
12881                            }
12882                    }
12883                    else {
12884                            if (getDB().isSupportsInlineDistinct()) {
12885                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12886                            }
12887                            else {
12888                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
12889                            }
12890                    }
12891    
12892                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12893                                    WikiPage.class.getName(),
12894                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12895    
12896                    SQLQuery q = session.createSQLQuery(sql);
12897    
12898                    q.setFirstResult(0);
12899                    q.setMaxResults(2);
12900    
12901                    if (getDB().isSupportsInlineDistinct()) {
12902                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
12903                    }
12904                    else {
12905                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
12906                    }
12907    
12908                    QueryPos qPos = QueryPos.getInstance(q);
12909    
12910                    qPos.add(groupId);
12911    
12912                    qPos.add(userId);
12913    
12914                    qPos.add(nodeId);
12915    
12916                    qPos.add(status);
12917    
12918                    if (orderByComparator != null) {
12919                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
12920    
12921                            for (Object value : values) {
12922                                    qPos.add(value);
12923                            }
12924                    }
12925    
12926                    List<WikiPage> list = q.list();
12927    
12928                    if (list.size() == 2) {
12929                            return list.get(1);
12930                    }
12931                    else {
12932                            return null;
12933                    }
12934            }
12935    
12936            /**
12937             * Removes all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63; from the database.
12938             *
12939             * @param groupId the group ID
12940             * @param userId the user ID
12941             * @param nodeId the node ID
12942             * @param status the status
12943             * @throws SystemException if a system exception occurred
12944             */
12945            public void removeByG_U_N_S(long groupId, long userId, long nodeId,
12946                    int status) throws SystemException {
12947                    for (WikiPage wikiPage : findByG_U_N_S(groupId, userId, nodeId, status,
12948                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12949                            remove(wikiPage);
12950                    }
12951            }
12952    
12953            /**
12954             * Returns the number of wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12955             *
12956             * @param groupId the group ID
12957             * @param userId the user ID
12958             * @param nodeId the node ID
12959             * @param status the status
12960             * @return the number of matching wiki pages
12961             * @throws SystemException if a system exception occurred
12962             */
12963            public int countByG_U_N_S(long groupId, long userId, long nodeId, int status)
12964                    throws SystemException {
12965                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_N_S;
12966    
12967                    Object[] finderArgs = new Object[] { groupId, userId, nodeId, status };
12968    
12969                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12970                                    this);
12971    
12972                    if (count == null) {
12973                            StringBundler query = new StringBundler(5);
12974    
12975                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
12976    
12977                            query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12978    
12979                            query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12980    
12981                            query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12982    
12983                            query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12984    
12985                            String sql = query.toString();
12986    
12987                            Session session = null;
12988    
12989                            try {
12990                                    session = openSession();
12991    
12992                                    Query q = session.createQuery(sql);
12993    
12994                                    QueryPos qPos = QueryPos.getInstance(q);
12995    
12996                                    qPos.add(groupId);
12997    
12998                                    qPos.add(userId);
12999    
13000                                    qPos.add(nodeId);
13001    
13002                                    qPos.add(status);
13003    
13004                                    count = (Long)q.uniqueResult();
13005    
13006                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
13007                            }
13008                            catch (Exception e) {
13009                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13010    
13011                                    throw processException(e);
13012                            }
13013                            finally {
13014                                    closeSession(session);
13015                            }
13016                    }
13017    
13018                    return count.intValue();
13019            }
13020    
13021            /**
13022             * Returns the number of wiki pages that the user has permission to view where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
13023             *
13024             * @param groupId the group ID
13025             * @param userId the user ID
13026             * @param nodeId the node ID
13027             * @param status the status
13028             * @return the number of matching wiki pages that the user has permission to view
13029             * @throws SystemException if a system exception occurred
13030             */
13031            public int filterCountByG_U_N_S(long groupId, long userId, long nodeId,
13032                    int status) throws SystemException {
13033                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13034                            return countByG_U_N_S(groupId, userId, nodeId, status);
13035                    }
13036    
13037                    StringBundler query = new StringBundler(5);
13038    
13039                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
13040    
13041                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
13042    
13043                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
13044    
13045                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
13046    
13047                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
13048    
13049                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13050                                    WikiPage.class.getName(),
13051                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13052    
13053                    Session session = null;
13054    
13055                    try {
13056                            session = openSession();
13057    
13058                            SQLQuery q = session.createSQLQuery(sql);
13059    
13060                            q.addScalar(COUNT_COLUMN_NAME,
13061                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13062    
13063                            QueryPos qPos = QueryPos.getInstance(q);
13064    
13065                            qPos.add(groupId);
13066    
13067                            qPos.add(userId);
13068    
13069                            qPos.add(nodeId);
13070    
13071                            qPos.add(status);
13072    
13073                            Long count = (Long)q.uniqueResult();
13074    
13075                            return count.intValue();
13076                    }
13077                    catch (Exception e) {
13078                            throw processException(e);
13079                    }
13080                    finally {
13081                            closeSession(session);
13082                    }
13083            }
13084    
13085            private static final String _FINDER_COLUMN_G_U_N_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
13086            private static final String _FINDER_COLUMN_G_U_N_S_USERID_2 = "wikiPage.userId = ? AND ";
13087            private static final String _FINDER_COLUMN_G_U_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
13088            private static final String _FINDER_COLUMN_G_U_N_S_STATUS_2 = "wikiPage.status = ?";
13089            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13090                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
13091                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_T_H",
13092                            new String[] {
13093                                    Long.class.getName(), Long.class.getName(),
13094                                    String.class.getName(), Boolean.class.getName(),
13095                                    
13096                            Integer.class.getName(), Integer.class.getName(),
13097                                    OrderByComparator.class.getName()
13098                            });
13099            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H =
13100                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13101                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
13102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_T_H",
13103                            new String[] {
13104                                    Long.class.getName(), Long.class.getName(),
13105                                    String.class.getName(), Boolean.class.getName()
13106                            },
13107                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
13108                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
13109                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
13110                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
13111                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
13112            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13113                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_T_H",
13115                            new String[] {
13116                                    Long.class.getName(), Long.class.getName(),
13117                                    String.class.getName(), Boolean.class.getName()
13118                            });
13119    
13120            /**
13121             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13122             *
13123             * @param groupId the group ID
13124             * @param nodeId the node ID
13125             * @param title the title
13126             * @param head the head
13127             * @return the matching wiki pages
13128             * @throws SystemException if a system exception occurred
13129             */
13130            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
13131                    String title, boolean head) throws SystemException {
13132                    return findByG_N_T_H(groupId, nodeId, title, head, QueryUtil.ALL_POS,
13133                            QueryUtil.ALL_POS, null);
13134            }
13135    
13136            /**
13137             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13138             *
13139             * <p>
13140             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13141             * </p>
13142             *
13143             * @param groupId the group ID
13144             * @param nodeId the node ID
13145             * @param title the title
13146             * @param head the head
13147             * @param start the lower bound of the range of wiki pages
13148             * @param end the upper bound of the range of wiki pages (not inclusive)
13149             * @return the range of matching wiki pages
13150             * @throws SystemException if a system exception occurred
13151             */
13152            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
13153                    String title, boolean head, int start, int end)
13154                    throws SystemException {
13155                    return findByG_N_T_H(groupId, nodeId, title, head, start, end, null);
13156            }
13157    
13158            /**
13159             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13160             *
13161             * <p>
13162             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13163             * </p>
13164             *
13165             * @param groupId the group ID
13166             * @param nodeId the node ID
13167             * @param title the title
13168             * @param head the head
13169             * @param start the lower bound of the range of wiki pages
13170             * @param end the upper bound of the range of wiki pages (not inclusive)
13171             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13172             * @return the ordered range of matching wiki pages
13173             * @throws SystemException if a system exception occurred
13174             */
13175            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
13176                    String title, boolean head, int start, int end,
13177                    OrderByComparator orderByComparator) throws SystemException {
13178                    boolean pagination = true;
13179                    FinderPath finderPath = null;
13180                    Object[] finderArgs = null;
13181    
13182                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13183                                    (orderByComparator == null)) {
13184                            pagination = false;
13185                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H;
13186                            finderArgs = new Object[] { groupId, nodeId, title, head };
13187                    }
13188                    else {
13189                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_H;
13190                            finderArgs = new Object[] {
13191                                            groupId, nodeId, title, head,
13192                                            
13193                                            start, end, orderByComparator
13194                                    };
13195                    }
13196    
13197                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
13198                                    finderArgs, this);
13199    
13200                    if ((list != null) && !list.isEmpty()) {
13201                            for (WikiPage wikiPage : list) {
13202                                    if ((groupId != wikiPage.getGroupId()) ||
13203                                                    (nodeId != wikiPage.getNodeId()) ||
13204                                                    !Validator.equals(title, wikiPage.getTitle()) ||
13205                                                    (head != wikiPage.getHead())) {
13206                                            list = null;
13207    
13208                                            break;
13209                                    }
13210                            }
13211                    }
13212    
13213                    if (list == null) {
13214                            StringBundler query = null;
13215    
13216                            if (orderByComparator != null) {
13217                                    query = new StringBundler(6 +
13218                                                    (orderByComparator.getOrderByFields().length * 3));
13219                            }
13220                            else {
13221                                    query = new StringBundler(6);
13222                            }
13223    
13224                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13225    
13226                            query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
13227    
13228                            query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
13229    
13230                            boolean bindTitle = false;
13231    
13232                            if (title == null) {
13233                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
13234                            }
13235                            else if (title.equals(StringPool.BLANK)) {
13236                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
13237                            }
13238                            else {
13239                                    bindTitle = true;
13240    
13241                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
13242                            }
13243    
13244                            query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
13245    
13246                            if (orderByComparator != null) {
13247                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13248                                            orderByComparator);
13249                            }
13250                            else
13251                             if (pagination) {
13252                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13253                            }
13254    
13255                            String sql = query.toString();
13256    
13257                            Session session = null;
13258    
13259                            try {
13260                                    session = openSession();
13261    
13262                                    Query q = session.createQuery(sql);
13263    
13264                                    QueryPos qPos = QueryPos.getInstance(q);
13265    
13266                                    qPos.add(groupId);
13267    
13268                                    qPos.add(nodeId);
13269    
13270                                    if (bindTitle) {
13271                                            qPos.add(title.toLowerCase());
13272                                    }
13273    
13274                                    qPos.add(head);
13275    
13276                                    if (!pagination) {
13277                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13278                                                            start, end, false);
13279    
13280                                            Collections.sort(list);
13281    
13282                                            list = new UnmodifiableList<WikiPage>(list);
13283                                    }
13284                                    else {
13285                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13286                                                            start, end);
13287                                    }
13288    
13289                                    cacheResult(list);
13290    
13291                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13292                            }
13293                            catch (Exception e) {
13294                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13295    
13296                                    throw processException(e);
13297                            }
13298                            finally {
13299                                    closeSession(session);
13300                            }
13301                    }
13302    
13303                    return list;
13304            }
13305    
13306            /**
13307             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13308             *
13309             * @param groupId the group ID
13310             * @param nodeId the node ID
13311             * @param title the title
13312             * @param head the head
13313             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13314             * @return the first matching wiki page
13315             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13316             * @throws SystemException if a system exception occurred
13317             */
13318            public WikiPage findByG_N_T_H_First(long groupId, long nodeId,
13319                    String title, boolean head, OrderByComparator orderByComparator)
13320                    throws NoSuchPageException, SystemException {
13321                    WikiPage wikiPage = fetchByG_N_T_H_First(groupId, nodeId, title, head,
13322                                    orderByComparator);
13323    
13324                    if (wikiPage != null) {
13325                            return wikiPage;
13326                    }
13327    
13328                    StringBundler msg = new StringBundler(10);
13329    
13330                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13331    
13332                    msg.append("groupId=");
13333                    msg.append(groupId);
13334    
13335                    msg.append(", nodeId=");
13336                    msg.append(nodeId);
13337    
13338                    msg.append(", title=");
13339                    msg.append(title);
13340    
13341                    msg.append(", head=");
13342                    msg.append(head);
13343    
13344                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13345    
13346                    throw new NoSuchPageException(msg.toString());
13347            }
13348    
13349            /**
13350             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13351             *
13352             * @param groupId the group ID
13353             * @param nodeId the node ID
13354             * @param title the title
13355             * @param head the head
13356             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13357             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
13358             * @throws SystemException if a system exception occurred
13359             */
13360            public WikiPage fetchByG_N_T_H_First(long groupId, long nodeId,
13361                    String title, boolean head, OrderByComparator orderByComparator)
13362                    throws SystemException {
13363                    List<WikiPage> list = findByG_N_T_H(groupId, nodeId, title, head, 0, 1,
13364                                    orderByComparator);
13365    
13366                    if (!list.isEmpty()) {
13367                            return list.get(0);
13368                    }
13369    
13370                    return null;
13371            }
13372    
13373            /**
13374             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13375             *
13376             * @param groupId the group ID
13377             * @param nodeId the node ID
13378             * @param title the title
13379             * @param head the head
13380             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13381             * @return the last matching wiki page
13382             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13383             * @throws SystemException if a system exception occurred
13384             */
13385            public WikiPage findByG_N_T_H_Last(long groupId, long nodeId, String title,
13386                    boolean head, OrderByComparator orderByComparator)
13387                    throws NoSuchPageException, SystemException {
13388                    WikiPage wikiPage = fetchByG_N_T_H_Last(groupId, nodeId, title, head,
13389                                    orderByComparator);
13390    
13391                    if (wikiPage != null) {
13392                            return wikiPage;
13393                    }
13394    
13395                    StringBundler msg = new StringBundler(10);
13396    
13397                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13398    
13399                    msg.append("groupId=");
13400                    msg.append(groupId);
13401    
13402                    msg.append(", nodeId=");
13403                    msg.append(nodeId);
13404    
13405                    msg.append(", title=");
13406                    msg.append(title);
13407    
13408                    msg.append(", head=");
13409                    msg.append(head);
13410    
13411                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13412    
13413                    throw new NoSuchPageException(msg.toString());
13414            }
13415    
13416            /**
13417             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13418             *
13419             * @param groupId the group ID
13420             * @param nodeId the node ID
13421             * @param title the title
13422             * @param head the head
13423             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13424             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
13425             * @throws SystemException if a system exception occurred
13426             */
13427            public WikiPage fetchByG_N_T_H_Last(long groupId, long nodeId,
13428                    String title, boolean head, OrderByComparator orderByComparator)
13429                    throws SystemException {
13430                    int count = countByG_N_T_H(groupId, nodeId, title, head);
13431    
13432                    List<WikiPage> list = findByG_N_T_H(groupId, nodeId, title, head,
13433                                    count - 1, count, orderByComparator);
13434    
13435                    if (!list.isEmpty()) {
13436                            return list.get(0);
13437                    }
13438    
13439                    return null;
13440            }
13441    
13442            /**
13443             * Returns the wiki pages before and after the current wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13444             *
13445             * @param pageId the primary key of the current wiki page
13446             * @param groupId the group ID
13447             * @param nodeId the node ID
13448             * @param title the title
13449             * @param head the head
13450             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13451             * @return the previous, current, and next wiki page
13452             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
13453             * @throws SystemException if a system exception occurred
13454             */
13455            public WikiPage[] findByG_N_T_H_PrevAndNext(long pageId, long groupId,
13456                    long nodeId, String title, boolean head,
13457                    OrderByComparator orderByComparator)
13458                    throws NoSuchPageException, SystemException {
13459                    WikiPage wikiPage = findByPrimaryKey(pageId);
13460    
13461                    Session session = null;
13462    
13463                    try {
13464                            session = openSession();
13465    
13466                            WikiPage[] array = new WikiPageImpl[3];
13467    
13468                            array[0] = getByG_N_T_H_PrevAndNext(session, wikiPage, groupId,
13469                                            nodeId, title, head, orderByComparator, true);
13470    
13471                            array[1] = wikiPage;
13472    
13473                            array[2] = getByG_N_T_H_PrevAndNext(session, wikiPage, groupId,
13474                                            nodeId, title, head, orderByComparator, false);
13475    
13476                            return array;
13477                    }
13478                    catch (Exception e) {
13479                            throw processException(e);
13480                    }
13481                    finally {
13482                            closeSession(session);
13483                    }
13484            }
13485    
13486            protected WikiPage getByG_N_T_H_PrevAndNext(Session session,
13487                    WikiPage wikiPage, long groupId, long nodeId, String title,
13488                    boolean head, OrderByComparator orderByComparator, boolean previous) {
13489                    StringBundler query = null;
13490    
13491                    if (orderByComparator != null) {
13492                            query = new StringBundler(6 +
13493                                            (orderByComparator.getOrderByFields().length * 6));
13494                    }
13495                    else {
13496                            query = new StringBundler(3);
13497                    }
13498    
13499                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13500    
13501                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
13502    
13503                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
13504    
13505                    boolean bindTitle = false;
13506    
13507                    if (title == null) {
13508                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
13509                    }
13510                    else if (title.equals(StringPool.BLANK)) {
13511                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
13512                    }
13513                    else {
13514                            bindTitle = true;
13515    
13516                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
13517                    }
13518    
13519                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
13520    
13521                    if (orderByComparator != null) {
13522                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13523    
13524                            if (orderByConditionFields.length > 0) {
13525                                    query.append(WHERE_AND);
13526                            }
13527    
13528                            for (int i = 0; i < orderByConditionFields.length; i++) {
13529                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13530                                    query.append(orderByConditionFields[i]);
13531    
13532                                    if ((i + 1) < orderByConditionFields.length) {
13533                                            if (orderByComparator.isAscending() ^ previous) {
13534                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13535                                            }
13536                                            else {
13537                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13538                                            }
13539                                    }
13540                                    else {
13541                                            if (orderByComparator.isAscending() ^ previous) {
13542                                                    query.append(WHERE_GREATER_THAN);
13543                                            }
13544                                            else {
13545                                                    query.append(WHERE_LESSER_THAN);
13546                                            }
13547                                    }
13548                            }
13549    
13550                            query.append(ORDER_BY_CLAUSE);
13551    
13552                            String[] orderByFields = orderByComparator.getOrderByFields();
13553    
13554                            for (int i = 0; i < orderByFields.length; i++) {
13555                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13556                                    query.append(orderByFields[i]);
13557    
13558                                    if ((i + 1) < orderByFields.length) {
13559                                            if (orderByComparator.isAscending() ^ previous) {
13560                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13561                                            }
13562                                            else {
13563                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13564                                            }
13565                                    }
13566                                    else {
13567                                            if (orderByComparator.isAscending() ^ previous) {
13568                                                    query.append(ORDER_BY_ASC);
13569                                            }
13570                                            else {
13571                                                    query.append(ORDER_BY_DESC);
13572                                            }
13573                                    }
13574                            }
13575                    }
13576                    else {
13577                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13578                    }
13579    
13580                    String sql = query.toString();
13581    
13582                    Query q = session.createQuery(sql);
13583    
13584                    q.setFirstResult(0);
13585                    q.setMaxResults(2);
13586    
13587                    QueryPos qPos = QueryPos.getInstance(q);
13588    
13589                    qPos.add(groupId);
13590    
13591                    qPos.add(nodeId);
13592    
13593                    if (bindTitle) {
13594                            qPos.add(title.toLowerCase());
13595                    }
13596    
13597                    qPos.add(head);
13598    
13599                    if (orderByComparator != null) {
13600                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
13601    
13602                            for (Object value : values) {
13603                                    qPos.add(value);
13604                            }
13605                    }
13606    
13607                    List<WikiPage> list = q.list();
13608    
13609                    if (list.size() == 2) {
13610                            return list.get(1);
13611                    }
13612                    else {
13613                            return null;
13614                    }
13615            }
13616    
13617            /**
13618             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13619             *
13620             * @param groupId the group ID
13621             * @param nodeId the node ID
13622             * @param title the title
13623             * @param head the head
13624             * @return the matching wiki pages that the user has permission to view
13625             * @throws SystemException if a system exception occurred
13626             */
13627            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
13628                    String title, boolean head) throws SystemException {
13629                    return filterFindByG_N_T_H(groupId, nodeId, title, head,
13630                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13631            }
13632    
13633            /**
13634             * Returns a range of all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13635             *
13636             * <p>
13637             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13638             * </p>
13639             *
13640             * @param groupId the group ID
13641             * @param nodeId the node ID
13642             * @param title the title
13643             * @param head the head
13644             * @param start the lower bound of the range of wiki pages
13645             * @param end the upper bound of the range of wiki pages (not inclusive)
13646             * @return the range of matching wiki pages that the user has permission to view
13647             * @throws SystemException if a system exception occurred
13648             */
13649            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
13650                    String title, boolean head, int start, int end)
13651                    throws SystemException {
13652                    return filterFindByG_N_T_H(groupId, nodeId, title, head, start, end,
13653                            null);
13654            }
13655    
13656            /**
13657             * Returns an ordered range of all the wiki pages that the user has permissions to view where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13658             *
13659             * <p>
13660             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13661             * </p>
13662             *
13663             * @param groupId the group ID
13664             * @param nodeId the node ID
13665             * @param title the title
13666             * @param head the head
13667             * @param start the lower bound of the range of wiki pages
13668             * @param end the upper bound of the range of wiki pages (not inclusive)
13669             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13670             * @return the ordered range of matching wiki pages that the user has permission to view
13671             * @throws SystemException if a system exception occurred
13672             */
13673            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
13674                    String title, boolean head, int start, int end,
13675                    OrderByComparator orderByComparator) throws SystemException {
13676                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13677                            return findByG_N_T_H(groupId, nodeId, title, head, start, end,
13678                                    orderByComparator);
13679                    }
13680    
13681                    StringBundler query = null;
13682    
13683                    if (orderByComparator != null) {
13684                            query = new StringBundler(6 +
13685                                            (orderByComparator.getOrderByFields().length * 3));
13686                    }
13687                    else {
13688                            query = new StringBundler(6);
13689                    }
13690    
13691                    if (getDB().isSupportsInlineDistinct()) {
13692                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
13693                    }
13694                    else {
13695                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
13696                    }
13697    
13698                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
13699    
13700                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
13701    
13702                    boolean bindTitle = false;
13703    
13704                    if (title == null) {
13705                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
13706                    }
13707                    else if (title.equals(StringPool.BLANK)) {
13708                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
13709                    }
13710                    else {
13711                            bindTitle = true;
13712    
13713                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
13714                    }
13715    
13716                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
13717    
13718                    if (!getDB().isSupportsInlineDistinct()) {
13719                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
13720                    }
13721    
13722                    if (orderByComparator != null) {
13723                            if (getDB().isSupportsInlineDistinct()) {
13724                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13725                                            orderByComparator, true);
13726                            }
13727                            else {
13728                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13729                                            orderByComparator, true);
13730                            }
13731                    }
13732                    else {
13733                            if (getDB().isSupportsInlineDistinct()) {
13734                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13735                            }
13736                            else {
13737                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
13738                            }
13739                    }
13740    
13741                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13742                                    WikiPage.class.getName(),
13743                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13744    
13745                    Session session = null;
13746    
13747                    try {
13748                            session = openSession();
13749    
13750                            SQLQuery q = session.createSQLQuery(sql);
13751    
13752                            if (getDB().isSupportsInlineDistinct()) {
13753                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
13754                            }
13755                            else {
13756                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
13757                            }
13758    
13759                            QueryPos qPos = QueryPos.getInstance(q);
13760    
13761                            qPos.add(groupId);
13762    
13763                            qPos.add(nodeId);
13764    
13765                            if (bindTitle) {
13766                                    qPos.add(title.toLowerCase());
13767                            }
13768    
13769                            qPos.add(head);
13770    
13771                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
13772                    }
13773                    catch (Exception e) {
13774                            throw processException(e);
13775                    }
13776                    finally {
13777                            closeSession(session);
13778                    }
13779            }
13780    
13781            /**
13782             * Returns the wiki pages before and after the current wiki page in the ordered set of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13783             *
13784             * @param pageId the primary key of the current wiki page
13785             * @param groupId the group ID
13786             * @param nodeId the node ID
13787             * @param title the title
13788             * @param head the head
13789             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13790             * @return the previous, current, and next wiki page
13791             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
13792             * @throws SystemException if a system exception occurred
13793             */
13794            public WikiPage[] filterFindByG_N_T_H_PrevAndNext(long pageId,
13795                    long groupId, long nodeId, String title, boolean head,
13796                    OrderByComparator orderByComparator)
13797                    throws NoSuchPageException, SystemException {
13798                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13799                            return findByG_N_T_H_PrevAndNext(pageId, groupId, nodeId, title,
13800                                    head, orderByComparator);
13801                    }
13802    
13803                    WikiPage wikiPage = findByPrimaryKey(pageId);
13804    
13805                    Session session = null;
13806    
13807                    try {
13808                            session = openSession();
13809    
13810                            WikiPage[] array = new WikiPageImpl[3];
13811    
13812                            array[0] = filterGetByG_N_T_H_PrevAndNext(session, wikiPage,
13813                                            groupId, nodeId, title, head, orderByComparator, true);
13814    
13815                            array[1] = wikiPage;
13816    
13817                            array[2] = filterGetByG_N_T_H_PrevAndNext(session, wikiPage,
13818                                            groupId, nodeId, title, head, orderByComparator, false);
13819    
13820                            return array;
13821                    }
13822                    catch (Exception e) {
13823                            throw processException(e);
13824                    }
13825                    finally {
13826                            closeSession(session);
13827                    }
13828            }
13829    
13830            protected WikiPage filterGetByG_N_T_H_PrevAndNext(Session session,
13831                    WikiPage wikiPage, long groupId, long nodeId, String title,
13832                    boolean head, OrderByComparator orderByComparator, boolean previous) {
13833                    StringBundler query = null;
13834    
13835                    if (orderByComparator != null) {
13836                            query = new StringBundler(6 +
13837                                            (orderByComparator.getOrderByFields().length * 6));
13838                    }
13839                    else {
13840                            query = new StringBundler(3);
13841                    }
13842    
13843                    if (getDB().isSupportsInlineDistinct()) {
13844                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
13845                    }
13846                    else {
13847                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
13848                    }
13849    
13850                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
13851    
13852                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
13853    
13854                    boolean bindTitle = false;
13855    
13856                    if (title == null) {
13857                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
13858                    }
13859                    else if (title.equals(StringPool.BLANK)) {
13860                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
13861                    }
13862                    else {
13863                            bindTitle = true;
13864    
13865                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
13866                    }
13867    
13868                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
13869    
13870                    if (!getDB().isSupportsInlineDistinct()) {
13871                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
13872                    }
13873    
13874                    if (orderByComparator != null) {
13875                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13876    
13877                            if (orderByConditionFields.length > 0) {
13878                                    query.append(WHERE_AND);
13879                            }
13880    
13881                            for (int i = 0; i < orderByConditionFields.length; i++) {
13882                                    if (getDB().isSupportsInlineDistinct()) {
13883                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13884                                    }
13885                                    else {
13886                                            query.append(_ORDER_BY_ENTITY_TABLE);
13887                                    }
13888    
13889                                    query.append(orderByConditionFields[i]);
13890    
13891                                    if ((i + 1) < orderByConditionFields.length) {
13892                                            if (orderByComparator.isAscending() ^ previous) {
13893                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13894                                            }
13895                                            else {
13896                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13897                                            }
13898                                    }
13899                                    else {
13900                                            if (orderByComparator.isAscending() ^ previous) {
13901                                                    query.append(WHERE_GREATER_THAN);
13902                                            }
13903                                            else {
13904                                                    query.append(WHERE_LESSER_THAN);
13905                                            }
13906                                    }
13907                            }
13908    
13909                            query.append(ORDER_BY_CLAUSE);
13910    
13911                            String[] orderByFields = orderByComparator.getOrderByFields();
13912    
13913                            for (int i = 0; i < orderByFields.length; i++) {
13914                                    if (getDB().isSupportsInlineDistinct()) {
13915                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13916                                    }
13917                                    else {
13918                                            query.append(_ORDER_BY_ENTITY_TABLE);
13919                                    }
13920    
13921                                    query.append(orderByFields[i]);
13922    
13923                                    if ((i + 1) < orderByFields.length) {
13924                                            if (orderByComparator.isAscending() ^ previous) {
13925                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13926                                            }
13927                                            else {
13928                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13929                                            }
13930                                    }
13931                                    else {
13932                                            if (orderByComparator.isAscending() ^ previous) {
13933                                                    query.append(ORDER_BY_ASC);
13934                                            }
13935                                            else {
13936                                                    query.append(ORDER_BY_DESC);
13937                                            }
13938                                    }
13939                            }
13940                    }
13941                    else {
13942                            if (getDB().isSupportsInlineDistinct()) {
13943                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13944                            }
13945                            else {
13946                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
13947                            }
13948                    }
13949    
13950                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13951                                    WikiPage.class.getName(),
13952                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13953    
13954                    SQLQuery q = session.createSQLQuery(sql);
13955    
13956                    q.setFirstResult(0);
13957                    q.setMaxResults(2);
13958    
13959                    if (getDB().isSupportsInlineDistinct()) {
13960                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
13961                    }
13962                    else {
13963                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
13964                    }
13965    
13966                    QueryPos qPos = QueryPos.getInstance(q);
13967    
13968                    qPos.add(groupId);
13969    
13970                    qPos.add(nodeId);
13971    
13972                    if (bindTitle) {
13973                            qPos.add(title.toLowerCase());
13974                    }
13975    
13976                    qPos.add(head);
13977    
13978                    if (orderByComparator != null) {
13979                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
13980    
13981                            for (Object value : values) {
13982                                    qPos.add(value);
13983                            }
13984                    }
13985    
13986                    List<WikiPage> list = q.list();
13987    
13988                    if (list.size() == 2) {
13989                            return list.get(1);
13990                    }
13991                    else {
13992                            return null;
13993                    }
13994            }
13995    
13996            /**
13997             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63; from the database.
13998             *
13999             * @param groupId the group ID
14000             * @param nodeId the node ID
14001             * @param title the title
14002             * @param head the head
14003             * @throws SystemException if a system exception occurred
14004             */
14005            public void removeByG_N_T_H(long groupId, long nodeId, String title,
14006                    boolean head) throws SystemException {
14007                    for (WikiPage wikiPage : findByG_N_T_H(groupId, nodeId, title, head,
14008                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14009                            remove(wikiPage);
14010                    }
14011            }
14012    
14013            /**
14014             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
14015             *
14016             * @param groupId the group ID
14017             * @param nodeId the node ID
14018             * @param title the title
14019             * @param head the head
14020             * @return the number of matching wiki pages
14021             * @throws SystemException if a system exception occurred
14022             */
14023            public int countByG_N_T_H(long groupId, long nodeId, String title,
14024                    boolean head) throws SystemException {
14025                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_T_H;
14026    
14027                    Object[] finderArgs = new Object[] { groupId, nodeId, title, head };
14028    
14029                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14030                                    this);
14031    
14032                    if (count == null) {
14033                            StringBundler query = new StringBundler(5);
14034    
14035                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
14036    
14037                            query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
14038    
14039                            query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
14040    
14041                            boolean bindTitle = false;
14042    
14043                            if (title == null) {
14044                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
14045                            }
14046                            else if (title.equals(StringPool.BLANK)) {
14047                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
14048                            }
14049                            else {
14050                                    bindTitle = true;
14051    
14052                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
14053                            }
14054    
14055                            query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
14056    
14057                            String sql = query.toString();
14058    
14059                            Session session = null;
14060    
14061                            try {
14062                                    session = openSession();
14063    
14064                                    Query q = session.createQuery(sql);
14065    
14066                                    QueryPos qPos = QueryPos.getInstance(q);
14067    
14068                                    qPos.add(groupId);
14069    
14070                                    qPos.add(nodeId);
14071    
14072                                    if (bindTitle) {
14073                                            qPos.add(title.toLowerCase());
14074                                    }
14075    
14076                                    qPos.add(head);
14077    
14078                                    count = (Long)q.uniqueResult();
14079    
14080                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14081                            }
14082                            catch (Exception e) {
14083                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14084    
14085                                    throw processException(e);
14086                            }
14087                            finally {
14088                                    closeSession(session);
14089                            }
14090                    }
14091    
14092                    return count.intValue();
14093            }
14094    
14095            /**
14096             * Returns the number of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
14097             *
14098             * @param groupId the group ID
14099             * @param nodeId the node ID
14100             * @param title the title
14101             * @param head the head
14102             * @return the number of matching wiki pages that the user has permission to view
14103             * @throws SystemException if a system exception occurred
14104             */
14105            public int filterCountByG_N_T_H(long groupId, long nodeId, String title,
14106                    boolean head) throws SystemException {
14107                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14108                            return countByG_N_T_H(groupId, nodeId, title, head);
14109                    }
14110    
14111                    StringBundler query = new StringBundler(5);
14112    
14113                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
14114    
14115                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
14116    
14117                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
14118    
14119                    boolean bindTitle = false;
14120    
14121                    if (title == null) {
14122                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
14123                    }
14124                    else if (title.equals(StringPool.BLANK)) {
14125                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
14126                    }
14127                    else {
14128                            bindTitle = true;
14129    
14130                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
14131                    }
14132    
14133                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
14134    
14135                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14136                                    WikiPage.class.getName(),
14137                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14138    
14139                    Session session = null;
14140    
14141                    try {
14142                            session = openSession();
14143    
14144                            SQLQuery q = session.createSQLQuery(sql);
14145    
14146                            q.addScalar(COUNT_COLUMN_NAME,
14147                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
14148    
14149                            QueryPos qPos = QueryPos.getInstance(q);
14150    
14151                            qPos.add(groupId);
14152    
14153                            qPos.add(nodeId);
14154    
14155                            if (bindTitle) {
14156                                    qPos.add(title.toLowerCase());
14157                            }
14158    
14159                            qPos.add(head);
14160    
14161                            Long count = (Long)q.uniqueResult();
14162    
14163                            return count.intValue();
14164                    }
14165                    catch (Exception e) {
14166                            throw processException(e);
14167                    }
14168                    finally {
14169                            closeSession(session);
14170                    }
14171            }
14172    
14173            private static final String _FINDER_COLUMN_G_N_T_H_GROUPID_2 = "wikiPage.groupId = ? AND ";
14174            private static final String _FINDER_COLUMN_G_N_T_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
14175            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_1 = "wikiPage.title IS NULL AND ";
14176            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_2 = "lower(wikiPage.title) = ? AND ";
14177            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
14178            private static final String _FINDER_COLUMN_G_N_T_H_HEAD_2 = "wikiPage.head = ?";
14179            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14180                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
14181                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H_S",
14182                            new String[] {
14183                                    Long.class.getName(), Long.class.getName(),
14184                                    Boolean.class.getName(), Integer.class.getName(),
14185                                    
14186                            Integer.class.getName(), Integer.class.getName(),
14187                                    OrderByComparator.class.getName()
14188                            });
14189            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S =
14190                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14191                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
14192                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H_S",
14193                            new String[] {
14194                                    Long.class.getName(), Long.class.getName(),
14195                                    Boolean.class.getName(), Integer.class.getName()
14196                            },
14197                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
14198                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
14199                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
14200                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
14201                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
14202                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
14203            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14204                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14205                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H_S",
14206                            new String[] {
14207                                    Long.class.getName(), Long.class.getName(),
14208                                    Boolean.class.getName(), Integer.class.getName()
14209                            });
14210    
14211            /**
14212             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14213             *
14214             * @param groupId the group ID
14215             * @param nodeId the node ID
14216             * @param head the head
14217             * @param status the status
14218             * @return the matching wiki pages
14219             * @throws SystemException if a system exception occurred
14220             */
14221            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
14222                    boolean head, int status) throws SystemException {
14223                    return findByG_N_H_S(groupId, nodeId, head, status, QueryUtil.ALL_POS,
14224                            QueryUtil.ALL_POS, null);
14225            }
14226    
14227            /**
14228             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14229             *
14230             * <p>
14231             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14232             * </p>
14233             *
14234             * @param groupId the group ID
14235             * @param nodeId the node ID
14236             * @param head the head
14237             * @param status the status
14238             * @param start the lower bound of the range of wiki pages
14239             * @param end the upper bound of the range of wiki pages (not inclusive)
14240             * @return the range of matching wiki pages
14241             * @throws SystemException if a system exception occurred
14242             */
14243            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
14244                    boolean head, int status, int start, int end) throws SystemException {
14245                    return findByG_N_H_S(groupId, nodeId, head, status, start, end, null);
14246            }
14247    
14248            /**
14249             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14250             *
14251             * <p>
14252             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14253             * </p>
14254             *
14255             * @param groupId the group ID
14256             * @param nodeId the node ID
14257             * @param head the head
14258             * @param status the status
14259             * @param start the lower bound of the range of wiki pages
14260             * @param end the upper bound of the range of wiki pages (not inclusive)
14261             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14262             * @return the ordered range of matching wiki pages
14263             * @throws SystemException if a system exception occurred
14264             */
14265            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
14266                    boolean head, int status, int start, int end,
14267                    OrderByComparator orderByComparator) throws SystemException {
14268                    boolean pagination = true;
14269                    FinderPath finderPath = null;
14270                    Object[] finderArgs = null;
14271    
14272                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14273                                    (orderByComparator == null)) {
14274                            pagination = false;
14275                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S;
14276                            finderArgs = new Object[] { groupId, nodeId, head, status };
14277                    }
14278                    else {
14279                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_S;
14280                            finderArgs = new Object[] {
14281                                            groupId, nodeId, head, status,
14282                                            
14283                                            start, end, orderByComparator
14284                                    };
14285                    }
14286    
14287                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
14288                                    finderArgs, this);
14289    
14290                    if ((list != null) && !list.isEmpty()) {
14291                            for (WikiPage wikiPage : list) {
14292                                    if ((groupId != wikiPage.getGroupId()) ||
14293                                                    (nodeId != wikiPage.getNodeId()) ||
14294                                                    (head != wikiPage.getHead()) ||
14295                                                    (status != wikiPage.getStatus())) {
14296                                            list = null;
14297    
14298                                            break;
14299                                    }
14300                            }
14301                    }
14302    
14303                    if (list == null) {
14304                            StringBundler query = null;
14305    
14306                            if (orderByComparator != null) {
14307                                    query = new StringBundler(6 +
14308                                                    (orderByComparator.getOrderByFields().length * 3));
14309                            }
14310                            else {
14311                                    query = new StringBundler(6);
14312                            }
14313    
14314                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14315    
14316                            query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
14317    
14318                            query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
14319    
14320                            query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
14321    
14322                            query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
14323    
14324                            if (orderByComparator != null) {
14325                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14326                                            orderByComparator);
14327                            }
14328                            else
14329                             if (pagination) {
14330                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14331                            }
14332    
14333                            String sql = query.toString();
14334    
14335                            Session session = null;
14336    
14337                            try {
14338                                    session = openSession();
14339    
14340                                    Query q = session.createQuery(sql);
14341    
14342                                    QueryPos qPos = QueryPos.getInstance(q);
14343    
14344                                    qPos.add(groupId);
14345    
14346                                    qPos.add(nodeId);
14347    
14348                                    qPos.add(head);
14349    
14350                                    qPos.add(status);
14351    
14352                                    if (!pagination) {
14353                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14354                                                            start, end, false);
14355    
14356                                            Collections.sort(list);
14357    
14358                                            list = new UnmodifiableList<WikiPage>(list);
14359                                    }
14360                                    else {
14361                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14362                                                            start, end);
14363                                    }
14364    
14365                                    cacheResult(list);
14366    
14367                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14368                            }
14369                            catch (Exception e) {
14370                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14371    
14372                                    throw processException(e);
14373                            }
14374                            finally {
14375                                    closeSession(session);
14376                            }
14377                    }
14378    
14379                    return list;
14380            }
14381    
14382            /**
14383             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14384             *
14385             * @param groupId the group ID
14386             * @param nodeId the node ID
14387             * @param head the head
14388             * @param status the status
14389             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14390             * @return the first matching wiki page
14391             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14392             * @throws SystemException if a system exception occurred
14393             */
14394            public WikiPage findByG_N_H_S_First(long groupId, long nodeId,
14395                    boolean head, int status, OrderByComparator orderByComparator)
14396                    throws NoSuchPageException, SystemException {
14397                    WikiPage wikiPage = fetchByG_N_H_S_First(groupId, nodeId, head, status,
14398                                    orderByComparator);
14399    
14400                    if (wikiPage != null) {
14401                            return wikiPage;
14402                    }
14403    
14404                    StringBundler msg = new StringBundler(10);
14405    
14406                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14407    
14408                    msg.append("groupId=");
14409                    msg.append(groupId);
14410    
14411                    msg.append(", nodeId=");
14412                    msg.append(nodeId);
14413    
14414                    msg.append(", head=");
14415                    msg.append(head);
14416    
14417                    msg.append(", status=");
14418                    msg.append(status);
14419    
14420                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14421    
14422                    throw new NoSuchPageException(msg.toString());
14423            }
14424    
14425            /**
14426             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14427             *
14428             * @param groupId the group ID
14429             * @param nodeId the node ID
14430             * @param head the head
14431             * @param status the status
14432             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14433             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
14434             * @throws SystemException if a system exception occurred
14435             */
14436            public WikiPage fetchByG_N_H_S_First(long groupId, long nodeId,
14437                    boolean head, int status, OrderByComparator orderByComparator)
14438                    throws SystemException {
14439                    List<WikiPage> list = findByG_N_H_S(groupId, nodeId, head, status, 0,
14440                                    1, orderByComparator);
14441    
14442                    if (!list.isEmpty()) {
14443                            return list.get(0);
14444                    }
14445    
14446                    return null;
14447            }
14448    
14449            /**
14450             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14451             *
14452             * @param groupId the group ID
14453             * @param nodeId the node ID
14454             * @param head the head
14455             * @param status the status
14456             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14457             * @return the last matching wiki page
14458             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14459             * @throws SystemException if a system exception occurred
14460             */
14461            public WikiPage findByG_N_H_S_Last(long groupId, long nodeId, boolean head,
14462                    int status, OrderByComparator orderByComparator)
14463                    throws NoSuchPageException, SystemException {
14464                    WikiPage wikiPage = fetchByG_N_H_S_Last(groupId, nodeId, head, status,
14465                                    orderByComparator);
14466    
14467                    if (wikiPage != null) {
14468                            return wikiPage;
14469                    }
14470    
14471                    StringBundler msg = new StringBundler(10);
14472    
14473                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14474    
14475                    msg.append("groupId=");
14476                    msg.append(groupId);
14477    
14478                    msg.append(", nodeId=");
14479                    msg.append(nodeId);
14480    
14481                    msg.append(", head=");
14482                    msg.append(head);
14483    
14484                    msg.append(", status=");
14485                    msg.append(status);
14486    
14487                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14488    
14489                    throw new NoSuchPageException(msg.toString());
14490            }
14491    
14492            /**
14493             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14494             *
14495             * @param groupId the group ID
14496             * @param nodeId the node ID
14497             * @param head the head
14498             * @param status the status
14499             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14500             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
14501             * @throws SystemException if a system exception occurred
14502             */
14503            public WikiPage fetchByG_N_H_S_Last(long groupId, long nodeId,
14504                    boolean head, int status, OrderByComparator orderByComparator)
14505                    throws SystemException {
14506                    int count = countByG_N_H_S(groupId, nodeId, head, status);
14507    
14508                    List<WikiPage> list = findByG_N_H_S(groupId, nodeId, head, status,
14509                                    count - 1, count, orderByComparator);
14510    
14511                    if (!list.isEmpty()) {
14512                            return list.get(0);
14513                    }
14514    
14515                    return null;
14516            }
14517    
14518            /**
14519             * Returns the wiki pages before and after the current wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14520             *
14521             * @param pageId the primary key of the current wiki page
14522             * @param groupId the group ID
14523             * @param nodeId the node ID
14524             * @param head the head
14525             * @param status the status
14526             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14527             * @return the previous, current, and next wiki page
14528             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
14529             * @throws SystemException if a system exception occurred
14530             */
14531            public WikiPage[] findByG_N_H_S_PrevAndNext(long pageId, long groupId,
14532                    long nodeId, boolean head, int status,
14533                    OrderByComparator orderByComparator)
14534                    throws NoSuchPageException, SystemException {
14535                    WikiPage wikiPage = findByPrimaryKey(pageId);
14536    
14537                    Session session = null;
14538    
14539                    try {
14540                            session = openSession();
14541    
14542                            WikiPage[] array = new WikiPageImpl[3];
14543    
14544                            array[0] = getByG_N_H_S_PrevAndNext(session, wikiPage, groupId,
14545                                            nodeId, head, status, orderByComparator, true);
14546    
14547                            array[1] = wikiPage;
14548    
14549                            array[2] = getByG_N_H_S_PrevAndNext(session, wikiPage, groupId,
14550                                            nodeId, head, status, orderByComparator, false);
14551    
14552                            return array;
14553                    }
14554                    catch (Exception e) {
14555                            throw processException(e);
14556                    }
14557                    finally {
14558                            closeSession(session);
14559                    }
14560            }
14561    
14562            protected WikiPage getByG_N_H_S_PrevAndNext(Session session,
14563                    WikiPage wikiPage, long groupId, long nodeId, boolean head, int status,
14564                    OrderByComparator orderByComparator, boolean previous) {
14565                    StringBundler query = null;
14566    
14567                    if (orderByComparator != null) {
14568                            query = new StringBundler(6 +
14569                                            (orderByComparator.getOrderByFields().length * 6));
14570                    }
14571                    else {
14572                            query = new StringBundler(3);
14573                    }
14574    
14575                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14576    
14577                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
14578    
14579                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
14580    
14581                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
14582    
14583                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
14584    
14585                    if (orderByComparator != null) {
14586                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14587    
14588                            if (orderByConditionFields.length > 0) {
14589                                    query.append(WHERE_AND);
14590                            }
14591    
14592                            for (int i = 0; i < orderByConditionFields.length; i++) {
14593                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14594                                    query.append(orderByConditionFields[i]);
14595    
14596                                    if ((i + 1) < orderByConditionFields.length) {
14597                                            if (orderByComparator.isAscending() ^ previous) {
14598                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14599                                            }
14600                                            else {
14601                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14602                                            }
14603                                    }
14604                                    else {
14605                                            if (orderByComparator.isAscending() ^ previous) {
14606                                                    query.append(WHERE_GREATER_THAN);
14607                                            }
14608                                            else {
14609                                                    query.append(WHERE_LESSER_THAN);
14610                                            }
14611                                    }
14612                            }
14613    
14614                            query.append(ORDER_BY_CLAUSE);
14615    
14616                            String[] orderByFields = orderByComparator.getOrderByFields();
14617    
14618                            for (int i = 0; i < orderByFields.length; i++) {
14619                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14620                                    query.append(orderByFields[i]);
14621    
14622                                    if ((i + 1) < orderByFields.length) {
14623                                            if (orderByComparator.isAscending() ^ previous) {
14624                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14625                                            }
14626                                            else {
14627                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14628                                            }
14629                                    }
14630                                    else {
14631                                            if (orderByComparator.isAscending() ^ previous) {
14632                                                    query.append(ORDER_BY_ASC);
14633                                            }
14634                                            else {
14635                                                    query.append(ORDER_BY_DESC);
14636                                            }
14637                                    }
14638                            }
14639                    }
14640                    else {
14641                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14642                    }
14643    
14644                    String sql = query.toString();
14645    
14646                    Query q = session.createQuery(sql);
14647    
14648                    q.setFirstResult(0);
14649                    q.setMaxResults(2);
14650    
14651                    QueryPos qPos = QueryPos.getInstance(q);
14652    
14653                    qPos.add(groupId);
14654    
14655                    qPos.add(nodeId);
14656    
14657                    qPos.add(head);
14658    
14659                    qPos.add(status);
14660    
14661                    if (orderByComparator != null) {
14662                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
14663    
14664                            for (Object value : values) {
14665                                    qPos.add(value);
14666                            }
14667                    }
14668    
14669                    List<WikiPage> list = q.list();
14670    
14671                    if (list.size() == 2) {
14672                            return list.get(1);
14673                    }
14674                    else {
14675                            return null;
14676                    }
14677            }
14678    
14679            /**
14680             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14681             *
14682             * @param groupId the group ID
14683             * @param nodeId the node ID
14684             * @param head the head
14685             * @param status the status
14686             * @return the matching wiki pages that the user has permission to view
14687             * @throws SystemException if a system exception occurred
14688             */
14689            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
14690                    boolean head, int status) throws SystemException {
14691                    return filterFindByG_N_H_S(groupId, nodeId, head, status,
14692                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14693            }
14694    
14695            /**
14696             * Returns a range of all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14697             *
14698             * <p>
14699             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14700             * </p>
14701             *
14702             * @param groupId the group ID
14703             * @param nodeId the node ID
14704             * @param head the head
14705             * @param status the status
14706             * @param start the lower bound of the range of wiki pages
14707             * @param end the upper bound of the range of wiki pages (not inclusive)
14708             * @return the range of matching wiki pages that the user has permission to view
14709             * @throws SystemException if a system exception occurred
14710             */
14711            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
14712                    boolean head, int status, int start, int end) throws SystemException {
14713                    return filterFindByG_N_H_S(groupId, nodeId, head, status, start, end,
14714                            null);
14715            }
14716    
14717            /**
14718             * Returns an ordered range of all the wiki pages that the user has permissions to view where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14719             *
14720             * <p>
14721             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14722             * </p>
14723             *
14724             * @param groupId the group ID
14725             * @param nodeId the node ID
14726             * @param head the head
14727             * @param status the status
14728             * @param start the lower bound of the range of wiki pages
14729             * @param end the upper bound of the range of wiki pages (not inclusive)
14730             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14731             * @return the ordered range of matching wiki pages that the user has permission to view
14732             * @throws SystemException if a system exception occurred
14733             */
14734            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
14735                    boolean head, int status, int start, int end,
14736                    OrderByComparator orderByComparator) throws SystemException {
14737                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14738                            return findByG_N_H_S(groupId, nodeId, head, status, start, end,
14739                                    orderByComparator);
14740                    }
14741    
14742                    StringBundler query = null;
14743    
14744                    if (orderByComparator != null) {
14745                            query = new StringBundler(6 +
14746                                            (orderByComparator.getOrderByFields().length * 3));
14747                    }
14748                    else {
14749                            query = new StringBundler(6);
14750                    }
14751    
14752                    if (getDB().isSupportsInlineDistinct()) {
14753                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
14754                    }
14755                    else {
14756                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
14757                    }
14758    
14759                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
14760    
14761                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
14762    
14763                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
14764    
14765                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
14766    
14767                    if (!getDB().isSupportsInlineDistinct()) {
14768                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
14769                    }
14770    
14771                    if (orderByComparator != null) {
14772                            if (getDB().isSupportsInlineDistinct()) {
14773                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14774                                            orderByComparator, true);
14775                            }
14776                            else {
14777                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
14778                                            orderByComparator, true);
14779                            }
14780                    }
14781                    else {
14782                            if (getDB().isSupportsInlineDistinct()) {
14783                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14784                            }
14785                            else {
14786                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
14787                            }
14788                    }
14789    
14790                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14791                                    WikiPage.class.getName(),
14792                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14793    
14794                    Session session = null;
14795    
14796                    try {
14797                            session = openSession();
14798    
14799                            SQLQuery q = session.createSQLQuery(sql);
14800    
14801                            if (getDB().isSupportsInlineDistinct()) {
14802                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
14803                            }
14804                            else {
14805                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
14806                            }
14807    
14808                            QueryPos qPos = QueryPos.getInstance(q);
14809    
14810                            qPos.add(groupId);
14811    
14812                            qPos.add(nodeId);
14813    
14814                            qPos.add(head);
14815    
14816                            qPos.add(status);
14817    
14818                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
14819                    }
14820                    catch (Exception e) {
14821                            throw processException(e);
14822                    }
14823                    finally {
14824                            closeSession(session);
14825                    }
14826            }
14827    
14828            /**
14829             * Returns the wiki pages before and after the current wiki page in the ordered set of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14830             *
14831             * @param pageId the primary key of the current wiki page
14832             * @param groupId the group ID
14833             * @param nodeId the node ID
14834             * @param head the head
14835             * @param status the status
14836             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14837             * @return the previous, current, and next wiki page
14838             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
14839             * @throws SystemException if a system exception occurred
14840             */
14841            public WikiPage[] filterFindByG_N_H_S_PrevAndNext(long pageId,
14842                    long groupId, long nodeId, boolean head, int status,
14843                    OrderByComparator orderByComparator)
14844                    throws NoSuchPageException, SystemException {
14845                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14846                            return findByG_N_H_S_PrevAndNext(pageId, groupId, nodeId, head,
14847                                    status, orderByComparator);
14848                    }
14849    
14850                    WikiPage wikiPage = findByPrimaryKey(pageId);
14851    
14852                    Session session = null;
14853    
14854                    try {
14855                            session = openSession();
14856    
14857                            WikiPage[] array = new WikiPageImpl[3];
14858    
14859                            array[0] = filterGetByG_N_H_S_PrevAndNext(session, wikiPage,
14860                                            groupId, nodeId, head, status, orderByComparator, true);
14861    
14862                            array[1] = wikiPage;
14863    
14864                            array[2] = filterGetByG_N_H_S_PrevAndNext(session, wikiPage,
14865                                            groupId, nodeId, head, status, orderByComparator, false);
14866    
14867                            return array;
14868                    }
14869                    catch (Exception e) {
14870                            throw processException(e);
14871                    }
14872                    finally {
14873                            closeSession(session);
14874                    }
14875            }
14876    
14877            protected WikiPage filterGetByG_N_H_S_PrevAndNext(Session session,
14878                    WikiPage wikiPage, long groupId, long nodeId, boolean head, int status,
14879                    OrderByComparator orderByComparator, boolean previous) {
14880                    StringBundler query = null;
14881    
14882                    if (orderByComparator != null) {
14883                            query = new StringBundler(6 +
14884                                            (orderByComparator.getOrderByFields().length * 6));
14885                    }
14886                    else {
14887                            query = new StringBundler(3);
14888                    }
14889    
14890                    if (getDB().isSupportsInlineDistinct()) {
14891                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
14892                    }
14893                    else {
14894                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
14895                    }
14896    
14897                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
14898    
14899                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
14900    
14901                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
14902    
14903                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
14904    
14905                    if (!getDB().isSupportsInlineDistinct()) {
14906                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
14907                    }
14908    
14909                    if (orderByComparator != null) {
14910                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14911    
14912                            if (orderByConditionFields.length > 0) {
14913                                    query.append(WHERE_AND);
14914                            }
14915    
14916                            for (int i = 0; i < orderByConditionFields.length; i++) {
14917                                    if (getDB().isSupportsInlineDistinct()) {
14918                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14919                                    }
14920                                    else {
14921                                            query.append(_ORDER_BY_ENTITY_TABLE);
14922                                    }
14923    
14924                                    query.append(orderByConditionFields[i]);
14925    
14926                                    if ((i + 1) < orderByConditionFields.length) {
14927                                            if (orderByComparator.isAscending() ^ previous) {
14928                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14929                                            }
14930                                            else {
14931                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14932                                            }
14933                                    }
14934                                    else {
14935                                            if (orderByComparator.isAscending() ^ previous) {
14936                                                    query.append(WHERE_GREATER_THAN);
14937                                            }
14938                                            else {
14939                                                    query.append(WHERE_LESSER_THAN);
14940                                            }
14941                                    }
14942                            }
14943    
14944                            query.append(ORDER_BY_CLAUSE);
14945    
14946                            String[] orderByFields = orderByComparator.getOrderByFields();
14947    
14948                            for (int i = 0; i < orderByFields.length; i++) {
14949                                    if (getDB().isSupportsInlineDistinct()) {
14950                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14951                                    }
14952                                    else {
14953                                            query.append(_ORDER_BY_ENTITY_TABLE);
14954                                    }
14955    
14956                                    query.append(orderByFields[i]);
14957    
14958                                    if ((i + 1) < orderByFields.length) {
14959                                            if (orderByComparator.isAscending() ^ previous) {
14960                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14961                                            }
14962                                            else {
14963                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14964                                            }
14965                                    }
14966                                    else {
14967                                            if (orderByComparator.isAscending() ^ previous) {
14968                                                    query.append(ORDER_BY_ASC);
14969                                            }
14970                                            else {
14971                                                    query.append(ORDER_BY_DESC);
14972                                            }
14973                                    }
14974                            }
14975                    }
14976                    else {
14977                            if (getDB().isSupportsInlineDistinct()) {
14978                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14979                            }
14980                            else {
14981                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
14982                            }
14983                    }
14984    
14985                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14986                                    WikiPage.class.getName(),
14987                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14988    
14989                    SQLQuery q = session.createSQLQuery(sql);
14990    
14991                    q.setFirstResult(0);
14992                    q.setMaxResults(2);
14993    
14994                    if (getDB().isSupportsInlineDistinct()) {
14995                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
14996                    }
14997                    else {
14998                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
14999                    }
15000    
15001                    QueryPos qPos = QueryPos.getInstance(q);
15002    
15003                    qPos.add(groupId);
15004    
15005                    qPos.add(nodeId);
15006    
15007                    qPos.add(head);
15008    
15009                    qPos.add(status);
15010    
15011                    if (orderByComparator != null) {
15012                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
15013    
15014                            for (Object value : values) {
15015                                    qPos.add(value);
15016                            }
15017                    }
15018    
15019                    List<WikiPage> list = q.list();
15020    
15021                    if (list.size() == 2) {
15022                            return list.get(1);
15023                    }
15024                    else {
15025                            return null;
15026                    }
15027            }
15028    
15029            /**
15030             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63; from the database.
15031             *
15032             * @param groupId the group ID
15033             * @param nodeId the node ID
15034             * @param head the head
15035             * @param status the status
15036             * @throws SystemException if a system exception occurred
15037             */
15038            public void removeByG_N_H_S(long groupId, long nodeId, boolean head,
15039                    int status) throws SystemException {
15040                    for (WikiPage wikiPage : findByG_N_H_S(groupId, nodeId, head, status,
15041                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15042                            remove(wikiPage);
15043                    }
15044            }
15045    
15046            /**
15047             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
15048             *
15049             * @param groupId the group ID
15050             * @param nodeId the node ID
15051             * @param head the head
15052             * @param status the status
15053             * @return the number of matching wiki pages
15054             * @throws SystemException if a system exception occurred
15055             */
15056            public int countByG_N_H_S(long groupId, long nodeId, boolean head,
15057                    int status) throws SystemException {
15058                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H_S;
15059    
15060                    Object[] finderArgs = new Object[] { groupId, nodeId, head, status };
15061    
15062                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15063                                    this);
15064    
15065                    if (count == null) {
15066                            StringBundler query = new StringBundler(5);
15067    
15068                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
15069    
15070                            query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
15071    
15072                            query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
15073    
15074                            query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
15075    
15076                            query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
15077    
15078                            String sql = query.toString();
15079    
15080                            Session session = null;
15081    
15082                            try {
15083                                    session = openSession();
15084    
15085                                    Query q = session.createQuery(sql);
15086    
15087                                    QueryPos qPos = QueryPos.getInstance(q);
15088    
15089                                    qPos.add(groupId);
15090    
15091                                    qPos.add(nodeId);
15092    
15093                                    qPos.add(head);
15094    
15095                                    qPos.add(status);
15096    
15097                                    count = (Long)q.uniqueResult();
15098    
15099                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15100                            }
15101                            catch (Exception e) {
15102                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15103    
15104                                    throw processException(e);
15105                            }
15106                            finally {
15107                                    closeSession(session);
15108                            }
15109                    }
15110    
15111                    return count.intValue();
15112            }
15113    
15114            /**
15115             * Returns the number of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
15116             *
15117             * @param groupId the group ID
15118             * @param nodeId the node ID
15119             * @param head the head
15120             * @param status the status
15121             * @return the number of matching wiki pages that the user has permission to view
15122             * @throws SystemException if a system exception occurred
15123             */
15124            public int filterCountByG_N_H_S(long groupId, long nodeId, boolean head,
15125                    int status) throws SystemException {
15126                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15127                            return countByG_N_H_S(groupId, nodeId, head, status);
15128                    }
15129    
15130                    StringBundler query = new StringBundler(5);
15131    
15132                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
15133    
15134                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
15135    
15136                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
15137    
15138                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
15139    
15140                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
15141    
15142                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15143                                    WikiPage.class.getName(),
15144                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15145    
15146                    Session session = null;
15147    
15148                    try {
15149                            session = openSession();
15150    
15151                            SQLQuery q = session.createSQLQuery(sql);
15152    
15153                            q.addScalar(COUNT_COLUMN_NAME,
15154                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
15155    
15156                            QueryPos qPos = QueryPos.getInstance(q);
15157    
15158                            qPos.add(groupId);
15159    
15160                            qPos.add(nodeId);
15161    
15162                            qPos.add(head);
15163    
15164                            qPos.add(status);
15165    
15166                            Long count = (Long)q.uniqueResult();
15167    
15168                            return count.intValue();
15169                    }
15170                    catch (Exception e) {
15171                            throw processException(e);
15172                    }
15173                    finally {
15174                            closeSession(session);
15175                    }
15176            }
15177    
15178            private static final String _FINDER_COLUMN_G_N_H_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
15179            private static final String _FINDER_COLUMN_G_N_H_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
15180            private static final String _FINDER_COLUMN_G_N_H_S_HEAD_2 = "wikiPage.head = ? AND ";
15181            private static final String _FINDER_COLUMN_G_N_H_S_STATUS_2 = "wikiPage.status = ?";
15182            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15183                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15184                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_P_S",
15185                            new String[] {
15186                                    Long.class.getName(), Boolean.class.getName(),
15187                                    String.class.getName(), Integer.class.getName(),
15188                                    
15189                            Integer.class.getName(), Integer.class.getName(),
15190                                    OrderByComparator.class.getName()
15191                            });
15192            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S =
15193                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15194                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15195                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_P_S",
15196                            new String[] {
15197                                    Long.class.getName(), Boolean.class.getName(),
15198                                    String.class.getName(), Integer.class.getName()
15199                            },
15200                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
15201                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
15202                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
15203                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
15204                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
15205                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
15206            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15207                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15208                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_P_S",
15209                            new String[] {
15210                                    Long.class.getName(), Boolean.class.getName(),
15211                                    String.class.getName(), Integer.class.getName()
15212                            });
15213    
15214            /**
15215             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15216             *
15217             * @param nodeId the node ID
15218             * @param head the head
15219             * @param parentTitle the parent title
15220             * @param status the status
15221             * @return the matching wiki pages
15222             * @throws SystemException if a system exception occurred
15223             */
15224            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
15225                    String parentTitle, int status) throws SystemException {
15226                    return findByN_H_P_S(nodeId, head, parentTitle, status,
15227                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15228            }
15229    
15230            /**
15231             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15232             *
15233             * <p>
15234             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15235             * </p>
15236             *
15237             * @param nodeId the node ID
15238             * @param head the head
15239             * @param parentTitle the parent title
15240             * @param status the status
15241             * @param start the lower bound of the range of wiki pages
15242             * @param end the upper bound of the range of wiki pages (not inclusive)
15243             * @return the range of matching wiki pages
15244             * @throws SystemException if a system exception occurred
15245             */
15246            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
15247                    String parentTitle, int status, int start, int end)
15248                    throws SystemException {
15249                    return findByN_H_P_S(nodeId, head, parentTitle, status, start, end, null);
15250            }
15251    
15252            /**
15253             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15254             *
15255             * <p>
15256             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15257             * </p>
15258             *
15259             * @param nodeId the node ID
15260             * @param head the head
15261             * @param parentTitle the parent title
15262             * @param status the status
15263             * @param start the lower bound of the range of wiki pages
15264             * @param end the upper bound of the range of wiki pages (not inclusive)
15265             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15266             * @return the ordered range of matching wiki pages
15267             * @throws SystemException if a system exception occurred
15268             */
15269            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
15270                    String parentTitle, int status, int start, int end,
15271                    OrderByComparator orderByComparator) throws SystemException {
15272                    boolean pagination = true;
15273                    FinderPath finderPath = null;
15274                    Object[] finderArgs = null;
15275    
15276                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15277                                    (orderByComparator == null)) {
15278                            pagination = false;
15279                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S;
15280                            finderArgs = new Object[] { nodeId, head, parentTitle, status };
15281                    }
15282                    else {
15283                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_S;
15284                            finderArgs = new Object[] {
15285                                            nodeId, head, parentTitle, status,
15286                                            
15287                                            start, end, orderByComparator
15288                                    };
15289                    }
15290    
15291                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
15292                                    finderArgs, this);
15293    
15294                    if ((list != null) && !list.isEmpty()) {
15295                            for (WikiPage wikiPage : list) {
15296                                    if ((nodeId != wikiPage.getNodeId()) ||
15297                                                    (head != wikiPage.getHead()) ||
15298                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
15299                                                    (status != wikiPage.getStatus())) {
15300                                            list = null;
15301    
15302                                            break;
15303                                    }
15304                            }
15305                    }
15306    
15307                    if (list == null) {
15308                            StringBundler query = null;
15309    
15310                            if (orderByComparator != null) {
15311                                    query = new StringBundler(6 +
15312                                                    (orderByComparator.getOrderByFields().length * 3));
15313                            }
15314                            else {
15315                                    query = new StringBundler(6);
15316                            }
15317    
15318                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
15319    
15320                            query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
15321    
15322                            query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
15323    
15324                            boolean bindParentTitle = false;
15325    
15326                            if (parentTitle == null) {
15327                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
15328                            }
15329                            else if (parentTitle.equals(StringPool.BLANK)) {
15330                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
15331                            }
15332                            else {
15333                                    bindParentTitle = true;
15334    
15335                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
15336                            }
15337    
15338                            query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
15339    
15340                            if (orderByComparator != null) {
15341                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15342                                            orderByComparator);
15343                            }
15344                            else
15345                             if (pagination) {
15346                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15347                            }
15348    
15349                            String sql = query.toString();
15350    
15351                            Session session = null;
15352    
15353                            try {
15354                                    session = openSession();
15355    
15356                                    Query q = session.createQuery(sql);
15357    
15358                                    QueryPos qPos = QueryPos.getInstance(q);
15359    
15360                                    qPos.add(nodeId);
15361    
15362                                    qPos.add(head);
15363    
15364                                    if (bindParentTitle) {
15365                                            qPos.add(parentTitle.toLowerCase());
15366                                    }
15367    
15368                                    qPos.add(status);
15369    
15370                                    if (!pagination) {
15371                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15372                                                            start, end, false);
15373    
15374                                            Collections.sort(list);
15375    
15376                                            list = new UnmodifiableList<WikiPage>(list);
15377                                    }
15378                                    else {
15379                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15380                                                            start, end);
15381                                    }
15382    
15383                                    cacheResult(list);
15384    
15385                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15386                            }
15387                            catch (Exception e) {
15388                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15389    
15390                                    throw processException(e);
15391                            }
15392                            finally {
15393                                    closeSession(session);
15394                            }
15395                    }
15396    
15397                    return list;
15398            }
15399    
15400            /**
15401             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15402             *
15403             * @param nodeId the node ID
15404             * @param head the head
15405             * @param parentTitle the parent title
15406             * @param status the status
15407             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15408             * @return the first matching wiki page
15409             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
15410             * @throws SystemException if a system exception occurred
15411             */
15412            public WikiPage findByN_H_P_S_First(long nodeId, boolean head,
15413                    String parentTitle, int status, OrderByComparator orderByComparator)
15414                    throws NoSuchPageException, SystemException {
15415                    WikiPage wikiPage = fetchByN_H_P_S_First(nodeId, head, parentTitle,
15416                                    status, orderByComparator);
15417    
15418                    if (wikiPage != null) {
15419                            return wikiPage;
15420                    }
15421    
15422                    StringBundler msg = new StringBundler(10);
15423    
15424                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15425    
15426                    msg.append("nodeId=");
15427                    msg.append(nodeId);
15428    
15429                    msg.append(", head=");
15430                    msg.append(head);
15431    
15432                    msg.append(", parentTitle=");
15433                    msg.append(parentTitle);
15434    
15435                    msg.append(", status=");
15436                    msg.append(status);
15437    
15438                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15439    
15440                    throw new NoSuchPageException(msg.toString());
15441            }
15442    
15443            /**
15444             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15445             *
15446             * @param nodeId the node ID
15447             * @param head the head
15448             * @param parentTitle the parent title
15449             * @param status the status
15450             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15451             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
15452             * @throws SystemException if a system exception occurred
15453             */
15454            public WikiPage fetchByN_H_P_S_First(long nodeId, boolean head,
15455                    String parentTitle, int status, OrderByComparator orderByComparator)
15456                    throws SystemException {
15457                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
15458                                    0, 1, orderByComparator);
15459    
15460                    if (!list.isEmpty()) {
15461                            return list.get(0);
15462                    }
15463    
15464                    return null;
15465            }
15466    
15467            /**
15468             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15469             *
15470             * @param nodeId the node ID
15471             * @param head the head
15472             * @param parentTitle the parent title
15473             * @param status the status
15474             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15475             * @return the last matching wiki page
15476             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
15477             * @throws SystemException if a system exception occurred
15478             */
15479            public WikiPage findByN_H_P_S_Last(long nodeId, boolean head,
15480                    String parentTitle, int status, OrderByComparator orderByComparator)
15481                    throws NoSuchPageException, SystemException {
15482                    WikiPage wikiPage = fetchByN_H_P_S_Last(nodeId, head, parentTitle,
15483                                    status, orderByComparator);
15484    
15485                    if (wikiPage != null) {
15486                            return wikiPage;
15487                    }
15488    
15489                    StringBundler msg = new StringBundler(10);
15490    
15491                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15492    
15493                    msg.append("nodeId=");
15494                    msg.append(nodeId);
15495    
15496                    msg.append(", head=");
15497                    msg.append(head);
15498    
15499                    msg.append(", parentTitle=");
15500                    msg.append(parentTitle);
15501    
15502                    msg.append(", status=");
15503                    msg.append(status);
15504    
15505                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15506    
15507                    throw new NoSuchPageException(msg.toString());
15508            }
15509    
15510            /**
15511             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15512             *
15513             * @param nodeId the node ID
15514             * @param head the head
15515             * @param parentTitle the parent title
15516             * @param status the status
15517             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15518             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
15519             * @throws SystemException if a system exception occurred
15520             */
15521            public WikiPage fetchByN_H_P_S_Last(long nodeId, boolean head,
15522                    String parentTitle, int status, OrderByComparator orderByComparator)
15523                    throws SystemException {
15524                    int count = countByN_H_P_S(nodeId, head, parentTitle, status);
15525    
15526                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
15527                                    count - 1, count, orderByComparator);
15528    
15529                    if (!list.isEmpty()) {
15530                            return list.get(0);
15531                    }
15532    
15533                    return null;
15534            }
15535    
15536            /**
15537             * Returns 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;.
15538             *
15539             * @param pageId the primary key of the current wiki page
15540             * @param nodeId the node ID
15541             * @param head the head
15542             * @param parentTitle the parent title
15543             * @param status the status
15544             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15545             * @return the previous, current, and next wiki page
15546             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
15547             * @throws SystemException if a system exception occurred
15548             */
15549            public WikiPage[] findByN_H_P_S_PrevAndNext(long pageId, long nodeId,
15550                    boolean head, String parentTitle, int status,
15551                    OrderByComparator orderByComparator)
15552                    throws NoSuchPageException, SystemException {
15553                    WikiPage wikiPage = findByPrimaryKey(pageId);
15554    
15555                    Session session = null;
15556    
15557                    try {
15558                            session = openSession();
15559    
15560                            WikiPage[] array = new WikiPageImpl[3];
15561    
15562                            array[0] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
15563                                            head, parentTitle, status, orderByComparator, true);
15564    
15565                            array[1] = wikiPage;
15566    
15567                            array[2] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
15568                                            head, parentTitle, status, orderByComparator, false);
15569    
15570                            return array;
15571                    }
15572                    catch (Exception e) {
15573                            throw processException(e);
15574                    }
15575                    finally {
15576                            closeSession(session);
15577                    }
15578            }
15579    
15580            protected WikiPage getByN_H_P_S_PrevAndNext(Session session,
15581                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
15582                    int status, OrderByComparator orderByComparator, boolean previous) {
15583                    StringBundler query = null;
15584    
15585                    if (orderByComparator != null) {
15586                            query = new StringBundler(6 +
15587                                            (orderByComparator.getOrderByFields().length * 6));
15588                    }
15589                    else {
15590                            query = new StringBundler(3);
15591                    }
15592    
15593                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
15594    
15595                    query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
15596    
15597                    query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
15598    
15599                    boolean bindParentTitle = false;
15600    
15601                    if (parentTitle == null) {
15602                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
15603                    }
15604                    else if (parentTitle.equals(StringPool.BLANK)) {
15605                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
15606                    }
15607                    else {
15608                            bindParentTitle = true;
15609    
15610                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
15611                    }
15612    
15613                    query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
15614    
15615                    if (orderByComparator != null) {
15616                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15617    
15618                            if (orderByConditionFields.length > 0) {
15619                                    query.append(WHERE_AND);
15620                            }
15621    
15622                            for (int i = 0; i < orderByConditionFields.length; i++) {
15623                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15624                                    query.append(orderByConditionFields[i]);
15625    
15626                                    if ((i + 1) < orderByConditionFields.length) {
15627                                            if (orderByComparator.isAscending() ^ previous) {
15628                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15629                                            }
15630                                            else {
15631                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15632                                            }
15633                                    }
15634                                    else {
15635                                            if (orderByComparator.isAscending() ^ previous) {
15636                                                    query.append(WHERE_GREATER_THAN);
15637                                            }
15638                                            else {
15639                                                    query.append(WHERE_LESSER_THAN);
15640                                            }
15641                                    }
15642                            }
15643    
15644                            query.append(ORDER_BY_CLAUSE);
15645    
15646                            String[] orderByFields = orderByComparator.getOrderByFields();
15647    
15648                            for (int i = 0; i < orderByFields.length; i++) {
15649                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15650                                    query.append(orderByFields[i]);
15651    
15652                                    if ((i + 1) < orderByFields.length) {
15653                                            if (orderByComparator.isAscending() ^ previous) {
15654                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15655                                            }
15656                                            else {
15657                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15658                                            }
15659                                    }
15660                                    else {
15661                                            if (orderByComparator.isAscending() ^ previous) {
15662                                                    query.append(ORDER_BY_ASC);
15663                                            }
15664                                            else {
15665                                                    query.append(ORDER_BY_DESC);
15666                                            }
15667                                    }
15668                            }
15669                    }
15670                    else {
15671                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15672                    }
15673    
15674                    String sql = query.toString();
15675    
15676                    Query q = session.createQuery(sql);
15677    
15678                    q.setFirstResult(0);
15679                    q.setMaxResults(2);
15680    
15681                    QueryPos qPos = QueryPos.getInstance(q);
15682    
15683                    qPos.add(nodeId);
15684    
15685                    qPos.add(head);
15686    
15687                    if (bindParentTitle) {
15688                            qPos.add(parentTitle.toLowerCase());
15689                    }
15690    
15691                    qPos.add(status);
15692    
15693                    if (orderByComparator != null) {
15694                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
15695    
15696                            for (Object value : values) {
15697                                    qPos.add(value);
15698                            }
15699                    }
15700    
15701                    List<WikiPage> list = q.list();
15702    
15703                    if (list.size() == 2) {
15704                            return list.get(1);
15705                    }
15706                    else {
15707                            return null;
15708                    }
15709            }
15710    
15711            /**
15712             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63; from the database.
15713             *
15714             * @param nodeId the node ID
15715             * @param head the head
15716             * @param parentTitle the parent title
15717             * @param status the status
15718             * @throws SystemException if a system exception occurred
15719             */
15720            public void removeByN_H_P_S(long nodeId, boolean head, String parentTitle,
15721                    int status) throws SystemException {
15722                    for (WikiPage wikiPage : findByN_H_P_S(nodeId, head, parentTitle,
15723                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15724                            remove(wikiPage);
15725                    }
15726            }
15727    
15728            /**
15729             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15730             *
15731             * @param nodeId the node ID
15732             * @param head the head
15733             * @param parentTitle the parent title
15734             * @param status the status
15735             * @return the number of matching wiki pages
15736             * @throws SystemException if a system exception occurred
15737             */
15738            public int countByN_H_P_S(long nodeId, boolean head, String parentTitle,
15739                    int status) throws SystemException {
15740                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_P_S;
15741    
15742                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle, status };
15743    
15744                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15745                                    this);
15746    
15747                    if (count == null) {
15748                            StringBundler query = new StringBundler(5);
15749    
15750                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
15751    
15752                            query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
15753    
15754                            query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
15755    
15756                            boolean bindParentTitle = false;
15757    
15758                            if (parentTitle == null) {
15759                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
15760                            }
15761                            else if (parentTitle.equals(StringPool.BLANK)) {
15762                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
15763                            }
15764                            else {
15765                                    bindParentTitle = true;
15766    
15767                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
15768                            }
15769    
15770                            query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
15771    
15772                            String sql = query.toString();
15773    
15774                            Session session = null;
15775    
15776                            try {
15777                                    session = openSession();
15778    
15779                                    Query q = session.createQuery(sql);
15780    
15781                                    QueryPos qPos = QueryPos.getInstance(q);
15782    
15783                                    qPos.add(nodeId);
15784    
15785                                    qPos.add(head);
15786    
15787                                    if (bindParentTitle) {
15788                                            qPos.add(parentTitle.toLowerCase());
15789                                    }
15790    
15791                                    qPos.add(status);
15792    
15793                                    count = (Long)q.uniqueResult();
15794    
15795                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15796                            }
15797                            catch (Exception e) {
15798                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15799    
15800                                    throw processException(e);
15801                            }
15802                            finally {
15803                                    closeSession(session);
15804                            }
15805                    }
15806    
15807                    return count.intValue();
15808            }
15809    
15810            private static final String _FINDER_COLUMN_N_H_P_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
15811            private static final String _FINDER_COLUMN_N_H_P_S_HEAD_2 = "wikiPage.head = ? AND ";
15812            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
15813            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ? AND ";
15814            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '') AND ";
15815            private static final String _FINDER_COLUMN_N_H_P_S_STATUS_2 = "wikiPage.status = ?";
15816            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_P_S =
15817                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15818                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15819                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H_P_S",
15820                            new String[] {
15821                                    Long.class.getName(), Long.class.getName(),
15822                                    Boolean.class.getName(), String.class.getName(),
15823                                    Integer.class.getName(),
15824                                    
15825                            Integer.class.getName(), Integer.class.getName(),
15826                                    OrderByComparator.class.getName()
15827                            });
15828            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S =
15829                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15830                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15831                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H_P_S",
15832                            new String[] {
15833                                    Long.class.getName(), Long.class.getName(),
15834                                    Boolean.class.getName(), String.class.getName(),
15835                                    Integer.class.getName()
15836                            },
15837                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
15838                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
15839                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
15840                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
15841                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
15842                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
15843                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
15844            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15845                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15846                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H_P_S",
15847                            new String[] {
15848                                    Long.class.getName(), Long.class.getName(),
15849                                    Boolean.class.getName(), String.class.getName(),
15850                                    Integer.class.getName()
15851                            });
15852    
15853            /**
15854             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15855             *
15856             * @param groupId the group ID
15857             * @param nodeId the node ID
15858             * @param head the head
15859             * @param parentTitle the parent title
15860             * @param status the status
15861             * @return the matching wiki pages
15862             * @throws SystemException if a system exception occurred
15863             */
15864            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
15865                    boolean head, String parentTitle, int status) throws SystemException {
15866                    return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
15867                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15868            }
15869    
15870            /**
15871             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15872             *
15873             * <p>
15874             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15875             * </p>
15876             *
15877             * @param groupId the group ID
15878             * @param nodeId the node ID
15879             * @param head the head
15880             * @param parentTitle the parent title
15881             * @param status the status
15882             * @param start the lower bound of the range of wiki pages
15883             * @param end the upper bound of the range of wiki pages (not inclusive)
15884             * @return the range of matching wiki pages
15885             * @throws SystemException if a system exception occurred
15886             */
15887            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
15888                    boolean head, String parentTitle, int status, int start, int end)
15889                    throws SystemException {
15890                    return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
15891                            start, end, null);
15892            }
15893    
15894            /**
15895             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15896             *
15897             * <p>
15898             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15899             * </p>
15900             *
15901             * @param groupId the group ID
15902             * @param nodeId the node ID
15903             * @param head the head
15904             * @param parentTitle the parent title
15905             * @param status the status
15906             * @param start the lower bound of the range of wiki pages
15907             * @param end the upper bound of the range of wiki pages (not inclusive)
15908             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15909             * @return the ordered range of matching wiki pages
15910             * @throws SystemException if a system exception occurred
15911             */
15912            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
15913                    boolean head, String parentTitle, int status, int start, int end,
15914                    OrderByComparator orderByComparator) throws SystemException {
15915                    boolean pagination = true;
15916                    FinderPath finderPath = null;
15917                    Object[] finderArgs = null;
15918    
15919                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15920                                    (orderByComparator == null)) {
15921                            pagination = false;
15922                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S;
15923                            finderArgs = new Object[] { groupId, nodeId, head, parentTitle, status };
15924                    }
15925                    else {
15926                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_P_S;
15927                            finderArgs = new Object[] {
15928                                            groupId, nodeId, head, parentTitle, status,
15929                                            
15930                                            start, end, orderByComparator
15931                                    };
15932                    }
15933    
15934                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
15935                                    finderArgs, this);
15936    
15937                    if ((list != null) && !list.isEmpty()) {
15938                            for (WikiPage wikiPage : list) {
15939                                    if ((groupId != wikiPage.getGroupId()) ||
15940                                                    (nodeId != wikiPage.getNodeId()) ||
15941                                                    (head != wikiPage.getHead()) ||
15942                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
15943                                                    (status != wikiPage.getStatus())) {
15944                                            list = null;
15945    
15946                                            break;
15947                                    }
15948                            }
15949                    }
15950    
15951                    if (list == null) {
15952                            StringBundler query = null;
15953    
15954                            if (orderByComparator != null) {
15955                                    query = new StringBundler(7 +
15956                                                    (orderByComparator.getOrderByFields().length * 3));
15957                            }
15958                            else {
15959                                    query = new StringBundler(7);
15960                            }
15961    
15962                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
15963    
15964                            query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
15965    
15966                            query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
15967    
15968                            query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
15969    
15970                            boolean bindParentTitle = false;
15971    
15972                            if (parentTitle == null) {
15973                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
15974                            }
15975                            else if (parentTitle.equals(StringPool.BLANK)) {
15976                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
15977                            }
15978                            else {
15979                                    bindParentTitle = true;
15980    
15981                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
15982                            }
15983    
15984                            query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
15985    
15986                            if (orderByComparator != null) {
15987                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15988                                            orderByComparator);
15989                            }
15990                            else
15991                             if (pagination) {
15992                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15993                            }
15994    
15995                            String sql = query.toString();
15996    
15997                            Session session = null;
15998    
15999                            try {
16000                                    session = openSession();
16001    
16002                                    Query q = session.createQuery(sql);
16003    
16004                                    QueryPos qPos = QueryPos.getInstance(q);
16005    
16006                                    qPos.add(groupId);
16007    
16008                                    qPos.add(nodeId);
16009    
16010                                    qPos.add(head);
16011    
16012                                    if (bindParentTitle) {
16013                                            qPos.add(parentTitle.toLowerCase());
16014                                    }
16015    
16016                                    qPos.add(status);
16017    
16018                                    if (!pagination) {
16019                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
16020                                                            start, end, false);
16021    
16022                                            Collections.sort(list);
16023    
16024                                            list = new UnmodifiableList<WikiPage>(list);
16025                                    }
16026                                    else {
16027                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
16028                                                            start, end);
16029                                    }
16030    
16031                                    cacheResult(list);
16032    
16033                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
16034                            }
16035                            catch (Exception e) {
16036                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16037    
16038                                    throw processException(e);
16039                            }
16040                            finally {
16041                                    closeSession(session);
16042                            }
16043                    }
16044    
16045                    return list;
16046            }
16047    
16048            /**
16049             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16050             *
16051             * @param groupId the group ID
16052             * @param nodeId the node ID
16053             * @param head the head
16054             * @param parentTitle the parent title
16055             * @param status the status
16056             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16057             * @return the first matching wiki page
16058             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
16059             * @throws SystemException if a system exception occurred
16060             */
16061            public WikiPage findByG_N_H_P_S_First(long groupId, long nodeId,
16062                    boolean head, String parentTitle, int status,
16063                    OrderByComparator orderByComparator)
16064                    throws NoSuchPageException, SystemException {
16065                    WikiPage wikiPage = fetchByG_N_H_P_S_First(groupId, nodeId, head,
16066                                    parentTitle, status, orderByComparator);
16067    
16068                    if (wikiPage != null) {
16069                            return wikiPage;
16070                    }
16071    
16072                    StringBundler msg = new StringBundler(12);
16073    
16074                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16075    
16076                    msg.append("groupId=");
16077                    msg.append(groupId);
16078    
16079                    msg.append(", nodeId=");
16080                    msg.append(nodeId);
16081    
16082                    msg.append(", head=");
16083                    msg.append(head);
16084    
16085                    msg.append(", parentTitle=");
16086                    msg.append(parentTitle);
16087    
16088                    msg.append(", status=");
16089                    msg.append(status);
16090    
16091                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16092    
16093                    throw new NoSuchPageException(msg.toString());
16094            }
16095    
16096            /**
16097             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16098             *
16099             * @param groupId the group ID
16100             * @param nodeId the node ID
16101             * @param head the head
16102             * @param parentTitle the parent title
16103             * @param status the status
16104             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16105             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
16106             * @throws SystemException if a system exception occurred
16107             */
16108            public WikiPage fetchByG_N_H_P_S_First(long groupId, long nodeId,
16109                    boolean head, String parentTitle, int status,
16110                    OrderByComparator orderByComparator) throws SystemException {
16111                    List<WikiPage> list = findByG_N_H_P_S(groupId, nodeId, head,
16112                                    parentTitle, status, 0, 1, orderByComparator);
16113    
16114                    if (!list.isEmpty()) {
16115                            return list.get(0);
16116                    }
16117    
16118                    return null;
16119            }
16120    
16121            /**
16122             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16123             *
16124             * @param groupId the group ID
16125             * @param nodeId the node ID
16126             * @param head the head
16127             * @param parentTitle the parent title
16128             * @param status the status
16129             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16130             * @return the last matching wiki page
16131             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
16132             * @throws SystemException if a system exception occurred
16133             */
16134            public WikiPage findByG_N_H_P_S_Last(long groupId, long nodeId,
16135                    boolean head, String parentTitle, int status,
16136                    OrderByComparator orderByComparator)
16137                    throws NoSuchPageException, SystemException {
16138                    WikiPage wikiPage = fetchByG_N_H_P_S_Last(groupId, nodeId, head,
16139                                    parentTitle, status, orderByComparator);
16140    
16141                    if (wikiPage != null) {
16142                            return wikiPage;
16143                    }
16144    
16145                    StringBundler msg = new StringBundler(12);
16146    
16147                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16148    
16149                    msg.append("groupId=");
16150                    msg.append(groupId);
16151    
16152                    msg.append(", nodeId=");
16153                    msg.append(nodeId);
16154    
16155                    msg.append(", head=");
16156                    msg.append(head);
16157    
16158                    msg.append(", parentTitle=");
16159                    msg.append(parentTitle);
16160    
16161                    msg.append(", status=");
16162                    msg.append(status);
16163    
16164                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16165    
16166                    throw new NoSuchPageException(msg.toString());
16167            }
16168    
16169            /**
16170             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16171             *
16172             * @param groupId the group ID
16173             * @param nodeId the node ID
16174             * @param head the head
16175             * @param parentTitle the parent title
16176             * @param status the status
16177             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16178             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
16179             * @throws SystemException if a system exception occurred
16180             */
16181            public WikiPage fetchByG_N_H_P_S_Last(long groupId, long nodeId,
16182                    boolean head, String parentTitle, int status,
16183                    OrderByComparator orderByComparator) throws SystemException {
16184                    int count = countByG_N_H_P_S(groupId, nodeId, head, parentTitle, status);
16185    
16186                    List<WikiPage> list = findByG_N_H_P_S(groupId, nodeId, head,
16187                                    parentTitle, status, count - 1, count, orderByComparator);
16188    
16189                    if (!list.isEmpty()) {
16190                            return list.get(0);
16191                    }
16192    
16193                    return null;
16194            }
16195    
16196            /**
16197             * Returns the wiki pages before and after the current wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16198             *
16199             * @param pageId the primary key of the current wiki page
16200             * @param groupId the group ID
16201             * @param nodeId the node ID
16202             * @param head the head
16203             * @param parentTitle the parent title
16204             * @param status the status
16205             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16206             * @return the previous, current, and next wiki page
16207             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
16208             * @throws SystemException if a system exception occurred
16209             */
16210            public WikiPage[] findByG_N_H_P_S_PrevAndNext(long pageId, long groupId,
16211                    long nodeId, boolean head, String parentTitle, int status,
16212                    OrderByComparator orderByComparator)
16213                    throws NoSuchPageException, SystemException {
16214                    WikiPage wikiPage = findByPrimaryKey(pageId);
16215    
16216                    Session session = null;
16217    
16218                    try {
16219                            session = openSession();
16220    
16221                            WikiPage[] array = new WikiPageImpl[3];
16222    
16223                            array[0] = getByG_N_H_P_S_PrevAndNext(session, wikiPage, groupId,
16224                                            nodeId, head, parentTitle, status, orderByComparator, true);
16225    
16226                            array[1] = wikiPage;
16227    
16228                            array[2] = getByG_N_H_P_S_PrevAndNext(session, wikiPage, groupId,
16229                                            nodeId, head, parentTitle, status, orderByComparator, false);
16230    
16231                            return array;
16232                    }
16233                    catch (Exception e) {
16234                            throw processException(e);
16235                    }
16236                    finally {
16237                            closeSession(session);
16238                    }
16239            }
16240    
16241            protected WikiPage getByG_N_H_P_S_PrevAndNext(Session session,
16242                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
16243                    String parentTitle, int status, OrderByComparator orderByComparator,
16244                    boolean previous) {
16245                    StringBundler query = null;
16246    
16247                    if (orderByComparator != null) {
16248                            query = new StringBundler(6 +
16249                                            (orderByComparator.getOrderByFields().length * 6));
16250                    }
16251                    else {
16252                            query = new StringBundler(3);
16253                    }
16254    
16255                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
16256    
16257                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
16258    
16259                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
16260    
16261                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
16262    
16263                    boolean bindParentTitle = false;
16264    
16265                    if (parentTitle == null) {
16266                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
16267                    }
16268                    else if (parentTitle.equals(StringPool.BLANK)) {
16269                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
16270                    }
16271                    else {
16272                            bindParentTitle = true;
16273    
16274                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
16275                    }
16276    
16277                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
16278    
16279                    if (orderByComparator != null) {
16280                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16281    
16282                            if (orderByConditionFields.length > 0) {
16283                                    query.append(WHERE_AND);
16284                            }
16285    
16286                            for (int i = 0; i < orderByConditionFields.length; i++) {
16287                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16288                                    query.append(orderByConditionFields[i]);
16289    
16290                                    if ((i + 1) < orderByConditionFields.length) {
16291                                            if (orderByComparator.isAscending() ^ previous) {
16292                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16293                                            }
16294                                            else {
16295                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16296                                            }
16297                                    }
16298                                    else {
16299                                            if (orderByComparator.isAscending() ^ previous) {
16300                                                    query.append(WHERE_GREATER_THAN);
16301                                            }
16302                                            else {
16303                                                    query.append(WHERE_LESSER_THAN);
16304                                            }
16305                                    }
16306                            }
16307    
16308                            query.append(ORDER_BY_CLAUSE);
16309    
16310                            String[] orderByFields = orderByComparator.getOrderByFields();
16311    
16312                            for (int i = 0; i < orderByFields.length; i++) {
16313                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16314                                    query.append(orderByFields[i]);
16315    
16316                                    if ((i + 1) < orderByFields.length) {
16317                                            if (orderByComparator.isAscending() ^ previous) {
16318                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16319                                            }
16320                                            else {
16321                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16322                                            }
16323                                    }
16324                                    else {
16325                                            if (orderByComparator.isAscending() ^ previous) {
16326                                                    query.append(ORDER_BY_ASC);
16327                                            }
16328                                            else {
16329                                                    query.append(ORDER_BY_DESC);
16330                                            }
16331                                    }
16332                            }
16333                    }
16334                    else {
16335                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16336                    }
16337    
16338                    String sql = query.toString();
16339    
16340                    Query q = session.createQuery(sql);
16341    
16342                    q.setFirstResult(0);
16343                    q.setMaxResults(2);
16344    
16345                    QueryPos qPos = QueryPos.getInstance(q);
16346    
16347                    qPos.add(groupId);
16348    
16349                    qPos.add(nodeId);
16350    
16351                    qPos.add(head);
16352    
16353                    if (bindParentTitle) {
16354                            qPos.add(parentTitle.toLowerCase());
16355                    }
16356    
16357                    qPos.add(status);
16358    
16359                    if (orderByComparator != null) {
16360                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
16361    
16362                            for (Object value : values) {
16363                                    qPos.add(value);
16364                            }
16365                    }
16366    
16367                    List<WikiPage> list = q.list();
16368    
16369                    if (list.size() == 2) {
16370                            return list.get(1);
16371                    }
16372                    else {
16373                            return null;
16374                    }
16375            }
16376    
16377            /**
16378             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16379             *
16380             * @param groupId the group ID
16381             * @param nodeId the node ID
16382             * @param head the head
16383             * @param parentTitle the parent title
16384             * @param status the status
16385             * @return the matching wiki pages that the user has permission to view
16386             * @throws SystemException if a system exception occurred
16387             */
16388            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
16389                    boolean head, String parentTitle, int status) throws SystemException {
16390                    return filterFindByG_N_H_P_S(groupId, nodeId, head, parentTitle,
16391                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16392            }
16393    
16394            /**
16395             * Returns a range of all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16396             *
16397             * <p>
16398             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16399             * </p>
16400             *
16401             * @param groupId the group ID
16402             * @param nodeId the node ID
16403             * @param head the head
16404             * @param parentTitle the parent title
16405             * @param status the status
16406             * @param start the lower bound of the range of wiki pages
16407             * @param end the upper bound of the range of wiki pages (not inclusive)
16408             * @return the range of matching wiki pages that the user has permission to view
16409             * @throws SystemException if a system exception occurred
16410             */
16411            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
16412                    boolean head, String parentTitle, int status, int start, int end)
16413                    throws SystemException {
16414                    return filterFindByG_N_H_P_S(groupId, nodeId, head, parentTitle,
16415                            status, start, end, null);
16416            }
16417    
16418            /**
16419             * Returns an ordered range of all the wiki pages that the user has permissions to view where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16420             *
16421             * <p>
16422             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16423             * </p>
16424             *
16425             * @param groupId the group ID
16426             * @param nodeId the node ID
16427             * @param head the head
16428             * @param parentTitle the parent title
16429             * @param status the status
16430             * @param start the lower bound of the range of wiki pages
16431             * @param end the upper bound of the range of wiki pages (not inclusive)
16432             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16433             * @return the ordered range of matching wiki pages that the user has permission to view
16434             * @throws SystemException if a system exception occurred
16435             */
16436            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
16437                    boolean head, String parentTitle, int status, int start, int end,
16438                    OrderByComparator orderByComparator) throws SystemException {
16439                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16440                            return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
16441                                    start, end, orderByComparator);
16442                    }
16443    
16444                    StringBundler query = null;
16445    
16446                    if (orderByComparator != null) {
16447                            query = new StringBundler(7 +
16448                                            (orderByComparator.getOrderByFields().length * 3));
16449                    }
16450                    else {
16451                            query = new StringBundler(7);
16452                    }
16453    
16454                    if (getDB().isSupportsInlineDistinct()) {
16455                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
16456                    }
16457                    else {
16458                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
16459                    }
16460    
16461                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
16462    
16463                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
16464    
16465                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
16466    
16467                    boolean bindParentTitle = false;
16468    
16469                    if (parentTitle == null) {
16470                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
16471                    }
16472                    else if (parentTitle.equals(StringPool.BLANK)) {
16473                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
16474                    }
16475                    else {
16476                            bindParentTitle = true;
16477    
16478                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
16479                    }
16480    
16481                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
16482    
16483                    if (!getDB().isSupportsInlineDistinct()) {
16484                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
16485                    }
16486    
16487                    if (orderByComparator != null) {
16488                            if (getDB().isSupportsInlineDistinct()) {
16489                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16490                                            orderByComparator, true);
16491                            }
16492                            else {
16493                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16494                                            orderByComparator, true);
16495                            }
16496                    }
16497                    else {
16498                            if (getDB().isSupportsInlineDistinct()) {
16499                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16500                            }
16501                            else {
16502                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
16503                            }
16504                    }
16505    
16506                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16507                                    WikiPage.class.getName(),
16508                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16509    
16510                    Session session = null;
16511    
16512                    try {
16513                            session = openSession();
16514    
16515                            SQLQuery q = session.createSQLQuery(sql);
16516    
16517                            if (getDB().isSupportsInlineDistinct()) {
16518                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
16519                            }
16520                            else {
16521                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
16522                            }
16523    
16524                            QueryPos qPos = QueryPos.getInstance(q);
16525    
16526                            qPos.add(groupId);
16527    
16528                            qPos.add(nodeId);
16529    
16530                            qPos.add(head);
16531    
16532                            if (bindParentTitle) {
16533                                    qPos.add(parentTitle.toLowerCase());
16534                            }
16535    
16536                            qPos.add(status);
16537    
16538                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
16539                    }
16540                    catch (Exception e) {
16541                            throw processException(e);
16542                    }
16543                    finally {
16544                            closeSession(session);
16545                    }
16546            }
16547    
16548            /**
16549             * Returns the wiki pages before and after the current wiki page in the ordered set of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16550             *
16551             * @param pageId the primary key of the current wiki page
16552             * @param groupId the group ID
16553             * @param nodeId the node ID
16554             * @param head the head
16555             * @param parentTitle the parent title
16556             * @param status the status
16557             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16558             * @return the previous, current, and next wiki page
16559             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
16560             * @throws SystemException if a system exception occurred
16561             */
16562            public WikiPage[] filterFindByG_N_H_P_S_PrevAndNext(long pageId,
16563                    long groupId, long nodeId, boolean head, String parentTitle,
16564                    int status, OrderByComparator orderByComparator)
16565                    throws NoSuchPageException, SystemException {
16566                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16567                            return findByG_N_H_P_S_PrevAndNext(pageId, groupId, nodeId, head,
16568                                    parentTitle, status, orderByComparator);
16569                    }
16570    
16571                    WikiPage wikiPage = findByPrimaryKey(pageId);
16572    
16573                    Session session = null;
16574    
16575                    try {
16576                            session = openSession();
16577    
16578                            WikiPage[] array = new WikiPageImpl[3];
16579    
16580                            array[0] = filterGetByG_N_H_P_S_PrevAndNext(session, wikiPage,
16581                                            groupId, nodeId, head, parentTitle, status,
16582                                            orderByComparator, true);
16583    
16584                            array[1] = wikiPage;
16585    
16586                            array[2] = filterGetByG_N_H_P_S_PrevAndNext(session, wikiPage,
16587                                            groupId, nodeId, head, parentTitle, status,
16588                                            orderByComparator, false);
16589    
16590                            return array;
16591                    }
16592                    catch (Exception e) {
16593                            throw processException(e);
16594                    }
16595                    finally {
16596                            closeSession(session);
16597                    }
16598            }
16599    
16600            protected WikiPage filterGetByG_N_H_P_S_PrevAndNext(Session session,
16601                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
16602                    String parentTitle, int status, OrderByComparator orderByComparator,
16603                    boolean previous) {
16604                    StringBundler query = null;
16605    
16606                    if (orderByComparator != null) {
16607                            query = new StringBundler(6 +
16608                                            (orderByComparator.getOrderByFields().length * 6));
16609                    }
16610                    else {
16611                            query = new StringBundler(3);
16612                    }
16613    
16614                    if (getDB().isSupportsInlineDistinct()) {
16615                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
16616                    }
16617                    else {
16618                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
16619                    }
16620    
16621                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
16622    
16623                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
16624    
16625                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
16626    
16627                    boolean bindParentTitle = false;
16628    
16629                    if (parentTitle == null) {
16630                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
16631                    }
16632                    else if (parentTitle.equals(StringPool.BLANK)) {
16633                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
16634                    }
16635                    else {
16636                            bindParentTitle = true;
16637    
16638                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
16639                    }
16640    
16641                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
16642    
16643                    if (!getDB().isSupportsInlineDistinct()) {
16644                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
16645                    }
16646    
16647                    if (orderByComparator != null) {
16648                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16649    
16650                            if (orderByConditionFields.length > 0) {
16651                                    query.append(WHERE_AND);
16652                            }
16653    
16654                            for (int i = 0; i < orderByConditionFields.length; i++) {
16655                                    if (getDB().isSupportsInlineDistinct()) {
16656                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16657                                    }
16658                                    else {
16659                                            query.append(_ORDER_BY_ENTITY_TABLE);
16660                                    }
16661    
16662                                    query.append(orderByConditionFields[i]);
16663    
16664                                    if ((i + 1) < orderByConditionFields.length) {
16665                                            if (orderByComparator.isAscending() ^ previous) {
16666                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16667                                            }
16668                                            else {
16669                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16670                                            }
16671                                    }
16672                                    else {
16673                                            if (orderByComparator.isAscending() ^ previous) {
16674                                                    query.append(WHERE_GREATER_THAN);
16675                                            }
16676                                            else {
16677                                                    query.append(WHERE_LESSER_THAN);
16678                                            }
16679                                    }
16680                            }
16681    
16682                            query.append(ORDER_BY_CLAUSE);
16683    
16684                            String[] orderByFields = orderByComparator.getOrderByFields();
16685    
16686                            for (int i = 0; i < orderByFields.length; i++) {
16687                                    if (getDB().isSupportsInlineDistinct()) {
16688                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16689                                    }
16690                                    else {
16691                                            query.append(_ORDER_BY_ENTITY_TABLE);
16692                                    }
16693    
16694                                    query.append(orderByFields[i]);
16695    
16696                                    if ((i + 1) < orderByFields.length) {
16697                                            if (orderByComparator.isAscending() ^ previous) {
16698                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16699                                            }
16700                                            else {
16701                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16702                                            }
16703                                    }
16704                                    else {
16705                                            if (orderByComparator.isAscending() ^ previous) {
16706                                                    query.append(ORDER_BY_ASC);
16707                                            }
16708                                            else {
16709                                                    query.append(ORDER_BY_DESC);
16710                                            }
16711                                    }
16712                            }
16713                    }
16714                    else {
16715                            if (getDB().isSupportsInlineDistinct()) {
16716                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16717                            }
16718                            else {
16719                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
16720                            }
16721                    }
16722    
16723                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16724                                    WikiPage.class.getName(),
16725                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16726    
16727                    SQLQuery q = session.createSQLQuery(sql);
16728    
16729                    q.setFirstResult(0);
16730                    q.setMaxResults(2);
16731    
16732                    if (getDB().isSupportsInlineDistinct()) {
16733                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
16734                    }
16735                    else {
16736                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
16737                    }
16738    
16739                    QueryPos qPos = QueryPos.getInstance(q);
16740    
16741                    qPos.add(groupId);
16742    
16743                    qPos.add(nodeId);
16744    
16745                    qPos.add(head);
16746    
16747                    if (bindParentTitle) {
16748                            qPos.add(parentTitle.toLowerCase());
16749                    }
16750    
16751                    qPos.add(status);
16752    
16753                    if (orderByComparator != null) {
16754                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
16755    
16756                            for (Object value : values) {
16757                                    qPos.add(value);
16758                            }
16759                    }
16760    
16761                    List<WikiPage> list = q.list();
16762    
16763                    if (list.size() == 2) {
16764                            return list.get(1);
16765                    }
16766                    else {
16767                            return null;
16768                    }
16769            }
16770    
16771            /**
16772             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63; from the database.
16773             *
16774             * @param groupId the group ID
16775             * @param nodeId the node ID
16776             * @param head the head
16777             * @param parentTitle the parent title
16778             * @param status the status
16779             * @throws SystemException if a system exception occurred
16780             */
16781            public void removeByG_N_H_P_S(long groupId, long nodeId, boolean head,
16782                    String parentTitle, int status) throws SystemException {
16783                    for (WikiPage wikiPage : findByG_N_H_P_S(groupId, nodeId, head,
16784                                    parentTitle, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16785                            remove(wikiPage);
16786                    }
16787            }
16788    
16789            /**
16790             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16791             *
16792             * @param groupId the group ID
16793             * @param nodeId the node ID
16794             * @param head the head
16795             * @param parentTitle the parent title
16796             * @param status the status
16797             * @return the number of matching wiki pages
16798             * @throws SystemException if a system exception occurred
16799             */
16800            public int countByG_N_H_P_S(long groupId, long nodeId, boolean head,
16801                    String parentTitle, int status) throws SystemException {
16802                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H_P_S;
16803    
16804                    Object[] finderArgs = new Object[] {
16805                                    groupId, nodeId, head, parentTitle, status
16806                            };
16807    
16808                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16809                                    this);
16810    
16811                    if (count == null) {
16812                            StringBundler query = new StringBundler(6);
16813    
16814                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
16815    
16816                            query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
16817    
16818                            query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
16819    
16820                            query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
16821    
16822                            boolean bindParentTitle = false;
16823    
16824                            if (parentTitle == null) {
16825                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
16826                            }
16827                            else if (parentTitle.equals(StringPool.BLANK)) {
16828                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
16829                            }
16830                            else {
16831                                    bindParentTitle = true;
16832    
16833                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
16834                            }
16835    
16836                            query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
16837    
16838                            String sql = query.toString();
16839    
16840                            Session session = null;
16841    
16842                            try {
16843                                    session = openSession();
16844    
16845                                    Query q = session.createQuery(sql);
16846    
16847                                    QueryPos qPos = QueryPos.getInstance(q);
16848    
16849                                    qPos.add(groupId);
16850    
16851                                    qPos.add(nodeId);
16852    
16853                                    qPos.add(head);
16854    
16855                                    if (bindParentTitle) {
16856                                            qPos.add(parentTitle.toLowerCase());
16857                                    }
16858    
16859                                    qPos.add(status);
16860    
16861                                    count = (Long)q.uniqueResult();
16862    
16863                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
16864                            }
16865                            catch (Exception e) {
16866                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16867    
16868                                    throw processException(e);
16869                            }
16870                            finally {
16871                                    closeSession(session);
16872                            }
16873                    }
16874    
16875                    return count.intValue();
16876            }
16877    
16878            /**
16879             * Returns the number of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16880             *
16881             * @param groupId the group ID
16882             * @param nodeId the node ID
16883             * @param head the head
16884             * @param parentTitle the parent title
16885             * @param status the status
16886             * @return the number of matching wiki pages that the user has permission to view
16887             * @throws SystemException if a system exception occurred
16888             */
16889            public int filterCountByG_N_H_P_S(long groupId, long nodeId, boolean head,
16890                    String parentTitle, int status) throws SystemException {
16891                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16892                            return countByG_N_H_P_S(groupId, nodeId, head, parentTitle, status);
16893                    }
16894    
16895                    StringBundler query = new StringBundler(6);
16896    
16897                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
16898    
16899                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
16900    
16901                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
16902    
16903                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
16904    
16905                    boolean bindParentTitle = false;
16906    
16907                    if (parentTitle == null) {
16908                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
16909                    }
16910                    else if (parentTitle.equals(StringPool.BLANK)) {
16911                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
16912                    }
16913                    else {
16914                            bindParentTitle = true;
16915    
16916                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
16917                    }
16918    
16919                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
16920    
16921                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16922                                    WikiPage.class.getName(),
16923                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16924    
16925                    Session session = null;
16926    
16927                    try {
16928                            session = openSession();
16929    
16930                            SQLQuery q = session.createSQLQuery(sql);
16931    
16932                            q.addScalar(COUNT_COLUMN_NAME,
16933                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16934    
16935                            QueryPos qPos = QueryPos.getInstance(q);
16936    
16937                            qPos.add(groupId);
16938    
16939                            qPos.add(nodeId);
16940    
16941                            qPos.add(head);
16942    
16943                            if (bindParentTitle) {
16944                                    qPos.add(parentTitle.toLowerCase());
16945                            }
16946    
16947                            qPos.add(status);
16948    
16949                            Long count = (Long)q.uniqueResult();
16950    
16951                            return count.intValue();
16952                    }
16953                    catch (Exception e) {
16954                            throw processException(e);
16955                    }
16956                    finally {
16957                            closeSession(session);
16958                    }
16959            }
16960    
16961            private static final String _FINDER_COLUMN_G_N_H_P_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
16962            private static final String _FINDER_COLUMN_G_N_H_P_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
16963            private static final String _FINDER_COLUMN_G_N_H_P_S_HEAD_2 = "wikiPage.head = ? AND ";
16964            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
16965            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ? AND ";
16966            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '') AND ";
16967            private static final String _FINDER_COLUMN_G_N_H_P_S_STATUS_2 = "wikiPage.status = ?";
16968    
16969            /**
16970             * Caches the wiki page in the entity cache if it is enabled.
16971             *
16972             * @param wikiPage the wiki page
16973             */
16974            public void cacheResult(WikiPage wikiPage) {
16975                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16976                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
16977    
16978                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
16979                            new Object[] { wikiPage.getUuid(), wikiPage.getGroupId() }, wikiPage);
16980    
16981                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
16982                            new Object[] {
16983                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
16984                                    wikiPage.getVersion()
16985                            }, wikiPage);
16986    
16987                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
16988                            new Object[] {
16989                                    wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion()
16990                            }, wikiPage);
16991    
16992                    wikiPage.resetOriginalValues();
16993            }
16994    
16995            /**
16996             * Caches the wiki pages in the entity cache if it is enabled.
16997             *
16998             * @param wikiPages the wiki pages
16999             */
17000            public void cacheResult(List<WikiPage> wikiPages) {
17001                    for (WikiPage wikiPage : wikiPages) {
17002                            if (EntityCacheUtil.getResult(
17003                                                    WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17004                                                    WikiPageImpl.class, wikiPage.getPrimaryKey()) == null) {
17005                                    cacheResult(wikiPage);
17006                            }
17007                            else {
17008                                    wikiPage.resetOriginalValues();
17009                            }
17010                    }
17011            }
17012    
17013            /**
17014             * Clears the cache for all wiki pages.
17015             *
17016             * <p>
17017             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
17018             * </p>
17019             */
17020            @Override
17021            public void clearCache() {
17022                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
17023                            CacheRegistryUtil.clear(WikiPageImpl.class.getName());
17024                    }
17025    
17026                    EntityCacheUtil.clearCache(WikiPageImpl.class.getName());
17027    
17028                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
17029                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
17030                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
17031            }
17032    
17033            /**
17034             * Clears the cache for the wiki page.
17035             *
17036             * <p>
17037             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
17038             * </p>
17039             */
17040            @Override
17041            public void clearCache(WikiPage wikiPage) {
17042                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17043                            WikiPageImpl.class, wikiPage.getPrimaryKey());
17044    
17045                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
17046                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
17047    
17048                    clearUniqueFindersCache(wikiPage);
17049            }
17050    
17051            @Override
17052            public void clearCache(List<WikiPage> wikiPages) {
17053                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
17054                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
17055    
17056                    for (WikiPage wikiPage : wikiPages) {
17057                            EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17058                                    WikiPageImpl.class, wikiPage.getPrimaryKey());
17059    
17060                            clearUniqueFindersCache(wikiPage);
17061                    }
17062            }
17063    
17064            protected void cacheUniqueFindersCache(WikiPage wikiPage) {
17065                    if (wikiPage.isNew()) {
17066                            Object[] args = new Object[] {
17067                                            wikiPage.getUuid(), wikiPage.getGroupId()
17068                                    };
17069    
17070                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
17071                                    Long.valueOf(1));
17072                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
17073                                    wikiPage);
17074    
17075                            args = new Object[] {
17076                                            wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
17077                                            wikiPage.getVersion()
17078                                    };
17079    
17080                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_V, args,
17081                                    Long.valueOf(1));
17082                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V, args, wikiPage);
17083    
17084                            args = new Object[] {
17085                                            wikiPage.getNodeId(), wikiPage.getTitle(),
17086                                            wikiPage.getVersion()
17087                                    };
17088    
17089                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_V, args,
17090                                    Long.valueOf(1));
17091                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V, args, wikiPage);
17092                    }
17093                    else {
17094                            WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
17095    
17096                            if ((wikiPageModelImpl.getColumnBitmask() &
17097                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
17098                                    Object[] args = new Object[] {
17099                                                    wikiPage.getUuid(), wikiPage.getGroupId()
17100                                            };
17101    
17102                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
17103                                            Long.valueOf(1));
17104                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
17105                                            wikiPage);
17106                            }
17107    
17108                            if ((wikiPageModelImpl.getColumnBitmask() &
17109                                            FINDER_PATH_FETCH_BY_R_N_V.getColumnBitmask()) != 0) {
17110                                    Object[] args = new Object[] {
17111                                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
17112                                                    wikiPage.getVersion()
17113                                            };
17114    
17115                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_V, args,
17116                                            Long.valueOf(1));
17117                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V, args,
17118                                            wikiPage);
17119                            }
17120    
17121                            if ((wikiPageModelImpl.getColumnBitmask() &
17122                                            FINDER_PATH_FETCH_BY_N_T_V.getColumnBitmask()) != 0) {
17123                                    Object[] args = new Object[] {
17124                                                    wikiPage.getNodeId(), wikiPage.getTitle(),
17125                                                    wikiPage.getVersion()
17126                                            };
17127    
17128                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_V, args,
17129                                            Long.valueOf(1));
17130                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V, args,
17131                                            wikiPage);
17132                            }
17133                    }
17134            }
17135    
17136            protected void clearUniqueFindersCache(WikiPage wikiPage) {
17137                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
17138    
17139                    Object[] args = new Object[] { wikiPage.getUuid(), wikiPage.getGroupId() };
17140    
17141                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
17142                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
17143    
17144                    if ((wikiPageModelImpl.getColumnBitmask() &
17145                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
17146                            args = new Object[] {
17147                                            wikiPageModelImpl.getOriginalUuid(),
17148                                            wikiPageModelImpl.getOriginalGroupId()
17149                                    };
17150    
17151                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
17152                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
17153                    }
17154    
17155                    args = new Object[] {
17156                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
17157                                    wikiPage.getVersion()
17158                            };
17159    
17160                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_V, args);
17161                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V, args);
17162    
17163                    if ((wikiPageModelImpl.getColumnBitmask() &
17164                                    FINDER_PATH_FETCH_BY_R_N_V.getColumnBitmask()) != 0) {
17165                            args = new Object[] {
17166                                            wikiPageModelImpl.getOriginalResourcePrimKey(),
17167                                            wikiPageModelImpl.getOriginalNodeId(),
17168                                            wikiPageModelImpl.getOriginalVersion()
17169                                    };
17170    
17171                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_V, args);
17172                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V, args);
17173                    }
17174    
17175                    args = new Object[] {
17176                                    wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion()
17177                            };
17178    
17179                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_V, args);
17180                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V, args);
17181    
17182                    if ((wikiPageModelImpl.getColumnBitmask() &
17183                                    FINDER_PATH_FETCH_BY_N_T_V.getColumnBitmask()) != 0) {
17184                            args = new Object[] {
17185                                            wikiPageModelImpl.getOriginalNodeId(),
17186                                            wikiPageModelImpl.getOriginalTitle(),
17187                                            wikiPageModelImpl.getOriginalVersion()
17188                                    };
17189    
17190                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_V, args);
17191                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V, args);
17192                    }
17193            }
17194    
17195            /**
17196             * Creates a new wiki page with the primary key. Does not add the wiki page to the database.
17197             *
17198             * @param pageId the primary key for the new wiki page
17199             * @return the new wiki page
17200             */
17201            public WikiPage create(long pageId) {
17202                    WikiPage wikiPage = new WikiPageImpl();
17203    
17204                    wikiPage.setNew(true);
17205                    wikiPage.setPrimaryKey(pageId);
17206    
17207                    String uuid = PortalUUIDUtil.generate();
17208    
17209                    wikiPage.setUuid(uuid);
17210    
17211                    return wikiPage;
17212            }
17213    
17214            /**
17215             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
17216             *
17217             * @param pageId the primary key of the wiki page
17218             * @return the wiki page that was removed
17219             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17220             * @throws SystemException if a system exception occurred
17221             */
17222            public WikiPage remove(long pageId)
17223                    throws NoSuchPageException, SystemException {
17224                    return remove((Serializable)pageId);
17225            }
17226    
17227            /**
17228             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
17229             *
17230             * @param primaryKey the primary key of the wiki page
17231             * @return the wiki page that was removed
17232             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17233             * @throws SystemException if a system exception occurred
17234             */
17235            @Override
17236            public WikiPage remove(Serializable primaryKey)
17237                    throws NoSuchPageException, SystemException {
17238                    Session session = null;
17239    
17240                    try {
17241                            session = openSession();
17242    
17243                            WikiPage wikiPage = (WikiPage)session.get(WikiPageImpl.class,
17244                                            primaryKey);
17245    
17246                            if (wikiPage == null) {
17247                                    if (_log.isWarnEnabled()) {
17248                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
17249                                    }
17250    
17251                                    throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
17252                                            primaryKey);
17253                            }
17254    
17255                            return remove(wikiPage);
17256                    }
17257                    catch (NoSuchPageException nsee) {
17258                            throw nsee;
17259                    }
17260                    catch (Exception e) {
17261                            throw processException(e);
17262                    }
17263                    finally {
17264                            closeSession(session);
17265                    }
17266            }
17267    
17268            @Override
17269            protected WikiPage removeImpl(WikiPage wikiPage) throws SystemException {
17270                    wikiPage = toUnwrappedModel(wikiPage);
17271    
17272                    Session session = null;
17273    
17274                    try {
17275                            session = openSession();
17276    
17277                            if (!session.contains(wikiPage)) {
17278                                    wikiPage = (WikiPage)session.get(WikiPageImpl.class,
17279                                                    wikiPage.getPrimaryKeyObj());
17280                            }
17281    
17282                            if (wikiPage != null) {
17283                                    session.delete(wikiPage);
17284                            }
17285                    }
17286                    catch (Exception e) {
17287                            throw processException(e);
17288                    }
17289                    finally {
17290                            closeSession(session);
17291                    }
17292    
17293                    if (wikiPage != null) {
17294                            clearCache(wikiPage);
17295                    }
17296    
17297                    return wikiPage;
17298            }
17299    
17300            @Override
17301            public WikiPage updateImpl(com.liferay.portlet.wiki.model.WikiPage wikiPage)
17302                    throws SystemException {
17303                    wikiPage = toUnwrappedModel(wikiPage);
17304    
17305                    boolean isNew = wikiPage.isNew();
17306    
17307                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
17308    
17309                    if (Validator.isNull(wikiPage.getUuid())) {
17310                            String uuid = PortalUUIDUtil.generate();
17311    
17312                            wikiPage.setUuid(uuid);
17313                    }
17314    
17315                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
17316    
17317                    if (userId > 0) {
17318                            long companyId = wikiPage.getCompanyId();
17319    
17320                            long groupId = wikiPage.getGroupId();
17321    
17322                            long pageId = 0;
17323    
17324                            if (!isNew) {
17325                                    pageId = wikiPage.getPrimaryKey();
17326                            }
17327    
17328                            try {
17329                                    wikiPage.setTitle(SanitizerUtil.sanitize(companyId, groupId,
17330                                                    userId,
17331                                                    com.liferay.portlet.wiki.model.WikiPage.class.getName(),
17332                                                    pageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
17333                                                    wikiPage.getTitle(), null));
17334                            }
17335                            catch (SanitizerException se) {
17336                                    throw new SystemException(se);
17337                            }
17338                    }
17339    
17340                    Session session = null;
17341    
17342                    try {
17343                            session = openSession();
17344    
17345                            if (wikiPage.isNew()) {
17346                                    session.save(wikiPage);
17347    
17348                                    wikiPage.setNew(false);
17349                            }
17350                            else {
17351                                    session.merge(wikiPage);
17352                            }
17353                    }
17354                    catch (Exception e) {
17355                            throw processException(e);
17356                    }
17357                    finally {
17358                            closeSession(session);
17359                    }
17360    
17361                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
17362    
17363                    if (isNew || !WikiPageModelImpl.COLUMN_BITMASK_ENABLED) {
17364                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
17365                    }
17366    
17367                    else {
17368                            if ((wikiPageModelImpl.getColumnBitmask() &
17369                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
17370                                    Object[] args = new Object[] { wikiPageModelImpl.getOriginalUuid() };
17371    
17372                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
17373                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
17374                                            args);
17375    
17376                                    args = new Object[] { wikiPageModelImpl.getUuid() };
17377    
17378                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
17379                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
17380                                            args);
17381                            }
17382    
17383                            if ((wikiPageModelImpl.getColumnBitmask() &
17384                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
17385                                    Object[] args = new Object[] {
17386                                                    wikiPageModelImpl.getOriginalUuid(),
17387                                                    wikiPageModelImpl.getOriginalCompanyId()
17388                                            };
17389    
17390                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
17391                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
17392                                            args);
17393    
17394                                    args = new Object[] {
17395                                                    wikiPageModelImpl.getUuid(),
17396                                                    wikiPageModelImpl.getCompanyId()
17397                                            };
17398    
17399                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
17400                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
17401                                            args);
17402                            }
17403    
17404                            if ((wikiPageModelImpl.getColumnBitmask() &
17405                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID.getColumnBitmask()) != 0) {
17406                                    Object[] args = new Object[] {
17407                                                    wikiPageModelImpl.getOriginalNodeId()
17408                                            };
17409    
17410                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NODEID, args);
17411                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID,
17412                                            args);
17413    
17414                                    args = new Object[] { wikiPageModelImpl.getNodeId() };
17415    
17416                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NODEID, args);
17417                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID,
17418                                            args);
17419                            }
17420    
17421                            if ((wikiPageModelImpl.getColumnBitmask() &
17422                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT.getColumnBitmask()) != 0) {
17423                                    Object[] args = new Object[] {
17424                                                    wikiPageModelImpl.getOriginalFormat()
17425                                            };
17426    
17427                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FORMAT, args);
17428                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT,
17429                                            args);
17430    
17431                                    args = new Object[] { wikiPageModelImpl.getFormat() };
17432    
17433                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FORMAT, args);
17434                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT,
17435                                            args);
17436                            }
17437    
17438                            if ((wikiPageModelImpl.getColumnBitmask() &
17439                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N.getColumnBitmask()) != 0) {
17440                                    Object[] args = new Object[] {
17441                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
17442                                                    wikiPageModelImpl.getOriginalNodeId()
17443                                            };
17444    
17445                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N, args);
17446                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N,
17447                                            args);
17448    
17449                                    args = new Object[] {
17450                                                    wikiPageModelImpl.getResourcePrimKey(),
17451                                                    wikiPageModelImpl.getNodeId()
17452                                            };
17453    
17454                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N, args);
17455                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N,
17456                                            args);
17457                            }
17458    
17459                            if ((wikiPageModelImpl.getColumnBitmask() &
17460                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T.getColumnBitmask()) != 0) {
17461                                    Object[] args = new Object[] {
17462                                                    wikiPageModelImpl.getOriginalNodeId(),
17463                                                    wikiPageModelImpl.getOriginalTitle()
17464                                            };
17465    
17466                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
17467                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T,
17468                                            args);
17469    
17470                                    args = new Object[] {
17471                                                    wikiPageModelImpl.getNodeId(),
17472                                                    wikiPageModelImpl.getTitle()
17473                                            };
17474    
17475                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
17476                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T,
17477                                            args);
17478                            }
17479    
17480                            if ((wikiPageModelImpl.getColumnBitmask() &
17481                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H.getColumnBitmask()) != 0) {
17482                                    Object[] args = new Object[] {
17483                                                    wikiPageModelImpl.getOriginalNodeId(),
17484                                                    wikiPageModelImpl.getOriginalHead()
17485                                            };
17486    
17487                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H, args);
17488                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H,
17489                                            args);
17490    
17491                                    args = new Object[] {
17492                                                    wikiPageModelImpl.getNodeId(),
17493                                                    wikiPageModelImpl.getHead()
17494                                            };
17495    
17496                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H, args);
17497                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H,
17498                                            args);
17499                            }
17500    
17501                            if ((wikiPageModelImpl.getColumnBitmask() &
17502                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P.getColumnBitmask()) != 0) {
17503                                    Object[] args = new Object[] {
17504                                                    wikiPageModelImpl.getOriginalNodeId(),
17505                                                    wikiPageModelImpl.getOriginalParentTitle()
17506                                            };
17507    
17508                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_P, args);
17509                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P,
17510                                            args);
17511    
17512                                    args = new Object[] {
17513                                                    wikiPageModelImpl.getNodeId(),
17514                                                    wikiPageModelImpl.getParentTitle()
17515                                            };
17516    
17517                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_P, args);
17518                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P,
17519                                            args);
17520                            }
17521    
17522                            if ((wikiPageModelImpl.getColumnBitmask() &
17523                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R.getColumnBitmask()) != 0) {
17524                                    Object[] args = new Object[] {
17525                                                    wikiPageModelImpl.getOriginalNodeId(),
17526                                                    wikiPageModelImpl.getOriginalRedirectTitle()
17527                                            };
17528    
17529                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_R, args);
17530                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R,
17531                                            args);
17532    
17533                                    args = new Object[] {
17534                                                    wikiPageModelImpl.getNodeId(),
17535                                                    wikiPageModelImpl.getRedirectTitle()
17536                                            };
17537    
17538                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_R, args);
17539                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R,
17540                                            args);
17541                            }
17542    
17543                            if ((wikiPageModelImpl.getColumnBitmask() &
17544                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S.getColumnBitmask()) != 0) {
17545                                    Object[] args = new Object[] {
17546                                                    wikiPageModelImpl.getOriginalNodeId(),
17547                                                    wikiPageModelImpl.getOriginalStatus()
17548                                            };
17549    
17550                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_S, args);
17551                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S,
17552                                            args);
17553    
17554                                    args = new Object[] {
17555                                                    wikiPageModelImpl.getNodeId(),
17556                                                    wikiPageModelImpl.getStatus()
17557                                            };
17558    
17559                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_S, args);
17560                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S,
17561                                            args);
17562                            }
17563    
17564                            if ((wikiPageModelImpl.getColumnBitmask() &
17565                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H.getColumnBitmask()) != 0) {
17566                                    Object[] args = new Object[] {
17567                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
17568                                                    wikiPageModelImpl.getOriginalNodeId(),
17569                                                    wikiPageModelImpl.getOriginalHead()
17570                                            };
17571    
17572                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_H, args);
17573                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H,
17574                                            args);
17575    
17576                                    args = new Object[] {
17577                                                    wikiPageModelImpl.getResourcePrimKey(),
17578                                                    wikiPageModelImpl.getNodeId(),
17579                                                    wikiPageModelImpl.getHead()
17580                                            };
17581    
17582                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_H, args);
17583                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H,
17584                                            args);
17585                            }
17586    
17587                            if ((wikiPageModelImpl.getColumnBitmask() &
17588                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S.getColumnBitmask()) != 0) {
17589                                    Object[] args = new Object[] {
17590                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
17591                                                    wikiPageModelImpl.getOriginalNodeId(),
17592                                                    wikiPageModelImpl.getOriginalStatus()
17593                                            };
17594    
17595                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_S, args);
17596                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S,
17597                                            args);
17598    
17599                                    args = new Object[] {
17600                                                    wikiPageModelImpl.getResourcePrimKey(),
17601                                                    wikiPageModelImpl.getNodeId(),
17602                                                    wikiPageModelImpl.getStatus()
17603                                            };
17604    
17605                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_S, args);
17606                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S,
17607                                            args);
17608                            }
17609    
17610                            if ((wikiPageModelImpl.getColumnBitmask() &
17611                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H.getColumnBitmask()) != 0) {
17612                                    Object[] args = new Object[] {
17613                                                    wikiPageModelImpl.getOriginalGroupId(),
17614                                                    wikiPageModelImpl.getOriginalNodeId(),
17615                                                    wikiPageModelImpl.getOriginalHead()
17616                                            };
17617    
17618                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H, args);
17619                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H,
17620                                            args);
17621    
17622                                    args = new Object[] {
17623                                                    wikiPageModelImpl.getGroupId(),
17624                                                    wikiPageModelImpl.getNodeId(),
17625                                                    wikiPageModelImpl.getHead()
17626                                            };
17627    
17628                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H, args);
17629                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H,
17630                                            args);
17631                            }
17632    
17633                            if ((wikiPageModelImpl.getColumnBitmask() &
17634                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S.getColumnBitmask()) != 0) {
17635                                    Object[] args = new Object[] {
17636                                                    wikiPageModelImpl.getOriginalGroupId(),
17637                                                    wikiPageModelImpl.getOriginalNodeId(),
17638                                                    wikiPageModelImpl.getOriginalStatus()
17639                                            };
17640    
17641                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_S, args);
17642                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S,
17643                                            args);
17644    
17645                                    args = new Object[] {
17646                                                    wikiPageModelImpl.getGroupId(),
17647                                                    wikiPageModelImpl.getNodeId(),
17648                                                    wikiPageModelImpl.getStatus()
17649                                            };
17650    
17651                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_S, args);
17652                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S,
17653                                            args);
17654                            }
17655    
17656                            if ((wikiPageModelImpl.getColumnBitmask() &
17657                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S.getColumnBitmask()) != 0) {
17658                                    Object[] args = new Object[] {
17659                                                    wikiPageModelImpl.getOriginalUserId(),
17660                                                    wikiPageModelImpl.getOriginalNodeId(),
17661                                                    wikiPageModelImpl.getOriginalStatus()
17662                                            };
17663    
17664                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_N_S, args);
17665                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S,
17666                                            args);
17667    
17668                                    args = new Object[] {
17669                                                    wikiPageModelImpl.getUserId(),
17670                                                    wikiPageModelImpl.getNodeId(),
17671                                                    wikiPageModelImpl.getStatus()
17672                                            };
17673    
17674                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_N_S, args);
17675                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S,
17676                                            args);
17677                            }
17678    
17679                            if ((wikiPageModelImpl.getColumnBitmask() &
17680                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H.getColumnBitmask()) != 0) {
17681                                    Object[] args = new Object[] {
17682                                                    wikiPageModelImpl.getOriginalNodeId(),
17683                                                    wikiPageModelImpl.getOriginalTitle(),
17684                                                    wikiPageModelImpl.getOriginalHead()
17685                                            };
17686    
17687                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_H, args);
17688                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H,
17689                                            args);
17690    
17691                                    args = new Object[] {
17692                                                    wikiPageModelImpl.getNodeId(),
17693                                                    wikiPageModelImpl.getTitle(),
17694                                                    wikiPageModelImpl.getHead()
17695                                            };
17696    
17697                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_H, args);
17698                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H,
17699                                            args);
17700                            }
17701    
17702                            if ((wikiPageModelImpl.getColumnBitmask() &
17703                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S.getColumnBitmask()) != 0) {
17704                                    Object[] args = new Object[] {
17705                                                    wikiPageModelImpl.getOriginalNodeId(),
17706                                                    wikiPageModelImpl.getOriginalTitle(),
17707                                                    wikiPageModelImpl.getOriginalStatus()
17708                                            };
17709    
17710                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_S, args);
17711                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S,
17712                                            args);
17713    
17714                                    args = new Object[] {
17715                                                    wikiPageModelImpl.getNodeId(),
17716                                                    wikiPageModelImpl.getTitle(),
17717                                                    wikiPageModelImpl.getStatus()
17718                                            };
17719    
17720                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_S, args);
17721                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S,
17722                                            args);
17723                            }
17724    
17725                            if ((wikiPageModelImpl.getColumnBitmask() &
17726                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P.getColumnBitmask()) != 0) {
17727                                    Object[] args = new Object[] {
17728                                                    wikiPageModelImpl.getOriginalNodeId(),
17729                                                    wikiPageModelImpl.getOriginalHead(),
17730                                                    wikiPageModelImpl.getOriginalParentTitle()
17731                                            };
17732    
17733                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P, args);
17734                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P,
17735                                            args);
17736    
17737                                    args = new Object[] {
17738                                                    wikiPageModelImpl.getNodeId(),
17739                                                    wikiPageModelImpl.getHead(),
17740                                                    wikiPageModelImpl.getParentTitle()
17741                                            };
17742    
17743                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P, args);
17744                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P,
17745                                            args);
17746                            }
17747    
17748                            if ((wikiPageModelImpl.getColumnBitmask() &
17749                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S.getColumnBitmask()) != 0) {
17750                                    Object[] args = new Object[] {
17751                                                    wikiPageModelImpl.getOriginalNodeId(),
17752                                                    wikiPageModelImpl.getOriginalHead(),
17753                                                    wikiPageModelImpl.getOriginalStatus()
17754                                            };
17755    
17756                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_S, args);
17757                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S,
17758                                            args);
17759    
17760                                    args = new Object[] {
17761                                                    wikiPageModelImpl.getNodeId(),
17762                                                    wikiPageModelImpl.getHead(),
17763                                                    wikiPageModelImpl.getStatus()
17764                                            };
17765    
17766                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_S, args);
17767                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S,
17768                                            args);
17769                            }
17770    
17771                            if ((wikiPageModelImpl.getColumnBitmask() &
17772                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S.getColumnBitmask()) != 0) {
17773                                    Object[] args = new Object[] {
17774                                                    wikiPageModelImpl.getOriginalGroupId(),
17775                                                    wikiPageModelImpl.getOriginalUserId(),
17776                                                    wikiPageModelImpl.getOriginalNodeId(),
17777                                                    wikiPageModelImpl.getOriginalStatus()
17778                                            };
17779    
17780                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N_S, args);
17781                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S,
17782                                            args);
17783    
17784                                    args = new Object[] {
17785                                                    wikiPageModelImpl.getGroupId(),
17786                                                    wikiPageModelImpl.getUserId(),
17787                                                    wikiPageModelImpl.getNodeId(),
17788                                                    wikiPageModelImpl.getStatus()
17789                                            };
17790    
17791                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N_S, args);
17792                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S,
17793                                            args);
17794                            }
17795    
17796                            if ((wikiPageModelImpl.getColumnBitmask() &
17797                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H.getColumnBitmask()) != 0) {
17798                                    Object[] args = new Object[] {
17799                                                    wikiPageModelImpl.getOriginalGroupId(),
17800                                                    wikiPageModelImpl.getOriginalNodeId(),
17801                                                    wikiPageModelImpl.getOriginalTitle(),
17802                                                    wikiPageModelImpl.getOriginalHead()
17803                                            };
17804    
17805                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_H, args);
17806                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H,
17807                                            args);
17808    
17809                                    args = new Object[] {
17810                                                    wikiPageModelImpl.getGroupId(),
17811                                                    wikiPageModelImpl.getNodeId(),
17812                                                    wikiPageModelImpl.getTitle(),
17813                                                    wikiPageModelImpl.getHead()
17814                                            };
17815    
17816                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_H, args);
17817                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H,
17818                                            args);
17819                            }
17820    
17821                            if ((wikiPageModelImpl.getColumnBitmask() &
17822                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S.getColumnBitmask()) != 0) {
17823                                    Object[] args = new Object[] {
17824                                                    wikiPageModelImpl.getOriginalGroupId(),
17825                                                    wikiPageModelImpl.getOriginalNodeId(),
17826                                                    wikiPageModelImpl.getOriginalHead(),
17827                                                    wikiPageModelImpl.getOriginalStatus()
17828                                            };
17829    
17830                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_S, args);
17831                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S,
17832                                            args);
17833    
17834                                    args = new Object[] {
17835                                                    wikiPageModelImpl.getGroupId(),
17836                                                    wikiPageModelImpl.getNodeId(),
17837                                                    wikiPageModelImpl.getHead(),
17838                                                    wikiPageModelImpl.getStatus()
17839                                            };
17840    
17841                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_S, args);
17842                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S,
17843                                            args);
17844                            }
17845    
17846                            if ((wikiPageModelImpl.getColumnBitmask() &
17847                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S.getColumnBitmask()) != 0) {
17848                                    Object[] args = new Object[] {
17849                                                    wikiPageModelImpl.getOriginalNodeId(),
17850                                                    wikiPageModelImpl.getOriginalHead(),
17851                                                    wikiPageModelImpl.getOriginalParentTitle(),
17852                                                    wikiPageModelImpl.getOriginalStatus()
17853                                            };
17854    
17855                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P_S, args);
17856                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S,
17857                                            args);
17858    
17859                                    args = new Object[] {
17860                                                    wikiPageModelImpl.getNodeId(),
17861                                                    wikiPageModelImpl.getHead(),
17862                                                    wikiPageModelImpl.getParentTitle(),
17863                                                    wikiPageModelImpl.getStatus()
17864                                            };
17865    
17866                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P_S, args);
17867                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S,
17868                                            args);
17869                            }
17870    
17871                            if ((wikiPageModelImpl.getColumnBitmask() &
17872                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S.getColumnBitmask()) != 0) {
17873                                    Object[] args = new Object[] {
17874                                                    wikiPageModelImpl.getOriginalGroupId(),
17875                                                    wikiPageModelImpl.getOriginalNodeId(),
17876                                                    wikiPageModelImpl.getOriginalHead(),
17877                                                    wikiPageModelImpl.getOriginalParentTitle(),
17878                                                    wikiPageModelImpl.getOriginalStatus()
17879                                            };
17880    
17881                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_P_S,
17882                                            args);
17883                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S,
17884                                            args);
17885    
17886                                    args = new Object[] {
17887                                                    wikiPageModelImpl.getGroupId(),
17888                                                    wikiPageModelImpl.getNodeId(),
17889                                                    wikiPageModelImpl.getHead(),
17890                                                    wikiPageModelImpl.getParentTitle(),
17891                                                    wikiPageModelImpl.getStatus()
17892                                            };
17893    
17894                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_P_S,
17895                                            args);
17896                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S,
17897                                            args);
17898                            }
17899                    }
17900    
17901                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17902                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
17903    
17904                    clearUniqueFindersCache(wikiPage);
17905                    cacheUniqueFindersCache(wikiPage);
17906    
17907                    return wikiPage;
17908            }
17909    
17910            protected WikiPage toUnwrappedModel(WikiPage wikiPage) {
17911                    if (wikiPage instanceof WikiPageImpl) {
17912                            return wikiPage;
17913                    }
17914    
17915                    WikiPageImpl wikiPageImpl = new WikiPageImpl();
17916    
17917                    wikiPageImpl.setNew(wikiPage.isNew());
17918                    wikiPageImpl.setPrimaryKey(wikiPage.getPrimaryKey());
17919    
17920                    wikiPageImpl.setUuid(wikiPage.getUuid());
17921                    wikiPageImpl.setPageId(wikiPage.getPageId());
17922                    wikiPageImpl.setResourcePrimKey(wikiPage.getResourcePrimKey());
17923                    wikiPageImpl.setGroupId(wikiPage.getGroupId());
17924                    wikiPageImpl.setCompanyId(wikiPage.getCompanyId());
17925                    wikiPageImpl.setUserId(wikiPage.getUserId());
17926                    wikiPageImpl.setUserName(wikiPage.getUserName());
17927                    wikiPageImpl.setCreateDate(wikiPage.getCreateDate());
17928                    wikiPageImpl.setModifiedDate(wikiPage.getModifiedDate());
17929                    wikiPageImpl.setNodeId(wikiPage.getNodeId());
17930                    wikiPageImpl.setTitle(wikiPage.getTitle());
17931                    wikiPageImpl.setVersion(wikiPage.getVersion());
17932                    wikiPageImpl.setMinorEdit(wikiPage.isMinorEdit());
17933                    wikiPageImpl.setContent(wikiPage.getContent());
17934                    wikiPageImpl.setSummary(wikiPage.getSummary());
17935                    wikiPageImpl.setFormat(wikiPage.getFormat());
17936                    wikiPageImpl.setHead(wikiPage.isHead());
17937                    wikiPageImpl.setParentTitle(wikiPage.getParentTitle());
17938                    wikiPageImpl.setRedirectTitle(wikiPage.getRedirectTitle());
17939                    wikiPageImpl.setStatus(wikiPage.getStatus());
17940                    wikiPageImpl.setStatusByUserId(wikiPage.getStatusByUserId());
17941                    wikiPageImpl.setStatusByUserName(wikiPage.getStatusByUserName());
17942                    wikiPageImpl.setStatusDate(wikiPage.getStatusDate());
17943    
17944                    return wikiPageImpl;
17945            }
17946    
17947            /**
17948             * Returns the wiki page with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
17949             *
17950             * @param primaryKey the primary key of the wiki page
17951             * @return the wiki page
17952             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17953             * @throws SystemException if a system exception occurred
17954             */
17955            @Override
17956            public WikiPage findByPrimaryKey(Serializable primaryKey)
17957                    throws NoSuchPageException, SystemException {
17958                    WikiPage wikiPage = fetchByPrimaryKey(primaryKey);
17959    
17960                    if (wikiPage == null) {
17961                            if (_log.isWarnEnabled()) {
17962                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
17963                            }
17964    
17965                            throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
17966                                    primaryKey);
17967                    }
17968    
17969                    return wikiPage;
17970            }
17971    
17972            /**
17973             * Returns the wiki page with the primary key or throws a {@link com.liferay.portlet.wiki.NoSuchPageException} if it could not be found.
17974             *
17975             * @param pageId the primary key of the wiki page
17976             * @return the wiki page
17977             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17978             * @throws SystemException if a system exception occurred
17979             */
17980            public WikiPage findByPrimaryKey(long pageId)
17981                    throws NoSuchPageException, SystemException {
17982                    return findByPrimaryKey((Serializable)pageId);
17983            }
17984    
17985            /**
17986             * Returns the wiki page with the primary key or returns <code>null</code> if it could not be found.
17987             *
17988             * @param primaryKey the primary key of the wiki page
17989             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
17990             * @throws SystemException if a system exception occurred
17991             */
17992            @Override
17993            public WikiPage fetchByPrimaryKey(Serializable primaryKey)
17994                    throws SystemException {
17995                    WikiPage wikiPage = (WikiPage)EntityCacheUtil.getResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17996                                    WikiPageImpl.class, primaryKey);
17997    
17998                    if (wikiPage == _nullWikiPage) {
17999                            return null;
18000                    }
18001    
18002                    if (wikiPage == null) {
18003                            Session session = null;
18004    
18005                            try {
18006                                    session = openSession();
18007    
18008                                    wikiPage = (WikiPage)session.get(WikiPageImpl.class, primaryKey);
18009    
18010                                    if (wikiPage != null) {
18011                                            cacheResult(wikiPage);
18012                                    }
18013                                    else {
18014                                            EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18015                                                    WikiPageImpl.class, primaryKey, _nullWikiPage);
18016                                    }
18017                            }
18018                            catch (Exception e) {
18019                                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18020                                            WikiPageImpl.class, primaryKey);
18021    
18022                                    throw processException(e);
18023                            }
18024                            finally {
18025                                    closeSession(session);
18026                            }
18027                    }
18028    
18029                    return wikiPage;
18030            }
18031    
18032            /**
18033             * Returns the wiki page with the primary key or returns <code>null</code> if it could not be found.
18034             *
18035             * @param pageId the primary key of the wiki page
18036             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
18037             * @throws SystemException if a system exception occurred
18038             */
18039            public WikiPage fetchByPrimaryKey(long pageId) throws SystemException {
18040                    return fetchByPrimaryKey((Serializable)pageId);
18041            }
18042    
18043            /**
18044             * Returns all the wiki pages.
18045             *
18046             * @return the wiki pages
18047             * @throws SystemException if a system exception occurred
18048             */
18049            public List<WikiPage> findAll() throws SystemException {
18050                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18051            }
18052    
18053            /**
18054             * Returns a range of all the wiki pages.
18055             *
18056             * <p>
18057             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18058             * </p>
18059             *
18060             * @param start the lower bound of the range of wiki pages
18061             * @param end the upper bound of the range of wiki pages (not inclusive)
18062             * @return the range of wiki pages
18063             * @throws SystemException if a system exception occurred
18064             */
18065            public List<WikiPage> findAll(int start, int end) throws SystemException {
18066                    return findAll(start, end, null);
18067            }
18068    
18069            /**
18070             * Returns an ordered range of all the wiki pages.
18071             *
18072             * <p>
18073             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.wiki.model.impl.WikiPageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
18074             * </p>
18075             *
18076             * @param start the lower bound of the range of wiki pages
18077             * @param end the upper bound of the range of wiki pages (not inclusive)
18078             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18079             * @return the ordered range of wiki pages
18080             * @throws SystemException if a system exception occurred
18081             */
18082            public List<WikiPage> findAll(int start, int end,
18083                    OrderByComparator orderByComparator) throws SystemException {
18084                    boolean pagination = true;
18085                    FinderPath finderPath = null;
18086                    Object[] finderArgs = null;
18087    
18088                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18089                                    (orderByComparator == null)) {
18090                            pagination = false;
18091                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
18092                            finderArgs = FINDER_ARGS_EMPTY;
18093                    }
18094                    else {
18095                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
18096                            finderArgs = new Object[] { start, end, orderByComparator };
18097                    }
18098    
18099                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
18100                                    finderArgs, this);
18101    
18102                    if (list == null) {
18103                            StringBundler query = null;
18104                            String sql = null;
18105    
18106                            if (orderByComparator != null) {
18107                                    query = new StringBundler(2 +
18108                                                    (orderByComparator.getOrderByFields().length * 3));
18109    
18110                                    query.append(_SQL_SELECT_WIKIPAGE);
18111    
18112                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18113                                            orderByComparator);
18114    
18115                                    sql = query.toString();
18116                            }
18117                            else {
18118                                    sql = _SQL_SELECT_WIKIPAGE;
18119    
18120                                    if (pagination) {
18121                                            sql = sql.concat(WikiPageModelImpl.ORDER_BY_JPQL);
18122                                    }
18123                            }
18124    
18125                            Session session = null;
18126    
18127                            try {
18128                                    session = openSession();
18129    
18130                                    Query q = session.createQuery(sql);
18131    
18132                                    if (!pagination) {
18133                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
18134                                                            start, end, false);
18135    
18136                                            Collections.sort(list);
18137    
18138                                            list = new UnmodifiableList<WikiPage>(list);
18139                                    }
18140                                    else {
18141                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
18142                                                            start, end);
18143                                    }
18144    
18145                                    cacheResult(list);
18146    
18147                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
18148                            }
18149                            catch (Exception e) {
18150                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18151    
18152                                    throw processException(e);
18153                            }
18154                            finally {
18155                                    closeSession(session);
18156                            }
18157                    }
18158    
18159                    return list;
18160            }
18161    
18162            /**
18163             * Removes all the wiki pages from the database.
18164             *
18165             * @throws SystemException if a system exception occurred
18166             */
18167            public void removeAll() throws SystemException {
18168                    for (WikiPage wikiPage : findAll()) {
18169                            remove(wikiPage);
18170                    }
18171            }
18172    
18173            /**
18174             * Returns the number of wiki pages.
18175             *
18176             * @return the number of wiki pages
18177             * @throws SystemException if a system exception occurred
18178             */
18179            public int countAll() throws SystemException {
18180                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
18181                                    FINDER_ARGS_EMPTY, this);
18182    
18183                    if (count == null) {
18184                            Session session = null;
18185    
18186                            try {
18187                                    session = openSession();
18188    
18189                                    Query q = session.createQuery(_SQL_COUNT_WIKIPAGE);
18190    
18191                                    count = (Long)q.uniqueResult();
18192    
18193                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
18194                                            FINDER_ARGS_EMPTY, count);
18195                            }
18196                            catch (Exception e) {
18197                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
18198                                            FINDER_ARGS_EMPTY);
18199    
18200                                    throw processException(e);
18201                            }
18202                            finally {
18203                                    closeSession(session);
18204                            }
18205                    }
18206    
18207                    return count.intValue();
18208            }
18209    
18210            @Override
18211            protected Set<String> getBadColumnNames() {
18212                    return _badColumnNames;
18213            }
18214    
18215            /**
18216             * Initializes the wiki page persistence.
18217             */
18218            public void afterPropertiesSet() {
18219                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
18220                                            com.liferay.portal.util.PropsUtil.get(
18221                                                    "value.object.listener.com.liferay.portlet.wiki.model.WikiPage")));
18222    
18223                    if (listenerClassNames.length > 0) {
18224                            try {
18225                                    List<ModelListener<WikiPage>> listenersList = new ArrayList<ModelListener<WikiPage>>();
18226    
18227                                    for (String listenerClassName : listenerClassNames) {
18228                                            listenersList.add((ModelListener<WikiPage>)InstanceFactory.newInstance(
18229                                                            getClassLoader(), listenerClassName));
18230                                    }
18231    
18232                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
18233                            }
18234                            catch (Exception e) {
18235                                    _log.error(e);
18236                            }
18237                    }
18238            }
18239    
18240            public void destroy() {
18241                    EntityCacheUtil.removeCache(WikiPageImpl.class.getName());
18242                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
18243                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18244                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18245            }
18246    
18247            private static final String _SQL_SELECT_WIKIPAGE = "SELECT wikiPage FROM WikiPage wikiPage";
18248            private static final String _SQL_SELECT_WIKIPAGE_WHERE = "SELECT wikiPage FROM WikiPage wikiPage WHERE ";
18249            private static final String _SQL_COUNT_WIKIPAGE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage";
18250            private static final String _SQL_COUNT_WIKIPAGE_WHERE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage WHERE ";
18251            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "wikiPage.resourcePrimKey";
18252            private static final String _FILTER_SQL_SELECT_WIKIPAGE_WHERE = "SELECT DISTINCT {wikiPage.*} FROM WikiPage wikiPage WHERE ";
18253            private static final String _FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1 =
18254                    "SELECT {WikiPage.*} FROM (SELECT DISTINCT wikiPage.pageId FROM WikiPage wikiPage WHERE ";
18255            private static final String _FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2 =
18256                    ") TEMP_TABLE INNER JOIN WikiPage ON TEMP_TABLE.pageId = WikiPage.pageId";
18257            private static final String _FILTER_SQL_COUNT_WIKIPAGE_WHERE = "SELECT COUNT(DISTINCT wikiPage.pageId) AS COUNT_VALUE FROM WikiPage wikiPage WHERE ";
18258            private static final String _FILTER_ENTITY_ALIAS = "wikiPage";
18259            private static final String _FILTER_ENTITY_TABLE = "WikiPage";
18260            private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPage.";
18261            private static final String _ORDER_BY_ENTITY_TABLE = "WikiPage.";
18262            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPage exists with the primary key ";
18263            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPage exists with the key {";
18264            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
18265            private static Log _log = LogFactoryUtil.getLog(WikiPagePersistenceImpl.class);
18266            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
18267                                    "uuid"
18268                            });
18269            private static WikiPage _nullWikiPage = new WikiPageImpl() {
18270                            @Override
18271                            public Object clone() {
18272                                    return this;
18273                            }
18274    
18275                            @Override
18276                            public CacheModel<WikiPage> toCacheModel() {
18277                                    return _nullWikiPageCacheModel;
18278                            }
18279                    };
18280    
18281            private static CacheModel<WikiPage> _nullWikiPageCacheModel = new CacheModel<WikiPage>() {
18282                            public WikiPage toEntityModel() {
18283                                    return _nullWikiPage;
18284                            }
18285                    };
18286    }