001    /**
002     * Copyright (c) 2000-2012 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.NoSuchModelException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.SQLQuery;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.sanitizer.Sanitizer;
031    import com.liferay.portal.kernel.sanitizer.SanitizerException;
032    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
033    import com.liferay.portal.kernel.util.ContentTypes;
034    import com.liferay.portal.kernel.util.GetterUtil;
035    import com.liferay.portal.kernel.util.InstanceFactory;
036    import com.liferay.portal.kernel.util.OrderByComparator;
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    
060    /**
061     * The persistence implementation for the wiki page service.
062     *
063     * <p>
064     * Caching information and settings can be found in <code>portal.properties</code>
065     * </p>
066     *
067     * @author Brian Wing Shun Chan
068     * @see WikiPagePersistence
069     * @see WikiPageUtil
070     * @generated
071     */
072    public class WikiPagePersistenceImpl extends BasePersistenceImpl<WikiPage>
073            implements WikiPagePersistence {
074            /*
075             * NOTE FOR DEVELOPERS:
076             *
077             * 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.
078             */
079            public static final String FINDER_CLASS_NAME_ENTITY = WikiPageImpl.class.getName();
080            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List1";
082            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List2";
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
085                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
088                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
090            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
091                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
093            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
094                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
096                            new String[] {
097                                    String.class.getName(),
098                                    
099                            Integer.class.getName(), Integer.class.getName(),
100                                    OrderByComparator.class.getName()
101                            });
102            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
103                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
105                            new String[] { String.class.getName() },
106                            WikiPageModelImpl.UUID_COLUMN_BITMASK |
107                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
108                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
109                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
110            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
111                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
112                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
113                            new String[] { String.class.getName() });
114    
115            /**
116             * Returns all the wiki pages where uuid = &#63;.
117             *
118             * @param uuid the uuid
119             * @return the matching wiki pages
120             * @throws SystemException if a system exception occurred
121             */
122            public List<WikiPage> findByUuid(String uuid) throws SystemException {
123                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
124            }
125    
126            /**
127             * Returns a range of all the wiki pages where uuid = &#63;.
128             *
129             * <p>
130             * 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.
131             * </p>
132             *
133             * @param uuid the uuid
134             * @param start the lower bound of the range of wiki pages
135             * @param end the upper bound of the range of wiki pages (not inclusive)
136             * @return the range of matching wiki pages
137             * @throws SystemException if a system exception occurred
138             */
139            public List<WikiPage> findByUuid(String uuid, int start, int end)
140                    throws SystemException {
141                    return findByUuid(uuid, start, end, null);
142            }
143    
144            /**
145             * Returns an ordered range of all the wiki pages where uuid = &#63;.
146             *
147             * <p>
148             * 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.
149             * </p>
150             *
151             * @param uuid the uuid
152             * @param start the lower bound of the range of wiki pages
153             * @param end the upper bound of the range of wiki pages (not inclusive)
154             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
155             * @return the ordered range of matching wiki pages
156             * @throws SystemException if a system exception occurred
157             */
158            public List<WikiPage> findByUuid(String uuid, int start, int end,
159                    OrderByComparator orderByComparator) throws SystemException {
160                    boolean pagination = true;
161                    FinderPath finderPath = null;
162                    Object[] finderArgs = null;
163    
164                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
165                                    (orderByComparator == null)) {
166                            pagination = false;
167                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
168                            finderArgs = new Object[] { uuid };
169                    }
170                    else {
171                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
172                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
173                    }
174    
175                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
176                                    finderArgs, this);
177    
178                    if ((list != null) && !list.isEmpty()) {
179                            for (WikiPage wikiPage : list) {
180                                    if (!Validator.equals(uuid, wikiPage.getUuid())) {
181                                            list = null;
182    
183                                            break;
184                                    }
185                            }
186                    }
187    
188                    if (list == null) {
189                            StringBundler query = null;
190    
191                            if (orderByComparator != null) {
192                                    query = new StringBundler(3 +
193                                                    (orderByComparator.getOrderByFields().length * 3));
194                            }
195                            else {
196                                    query = new StringBundler(3);
197                            }
198    
199                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
200    
201                            if (uuid == null) {
202                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
203                            }
204                            else {
205                                    if (uuid.equals(StringPool.BLANK)) {
206                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
207                                    }
208                                    else {
209                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
210                                    }
211                            }
212    
213                            if (orderByComparator != null) {
214                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
215                                            orderByComparator);
216                            }
217                            else
218                             if (pagination) {
219                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
220                            }
221    
222                            String sql = query.toString();
223    
224                            Session session = null;
225    
226                            try {
227                                    session = openSession();
228    
229                                    Query q = session.createQuery(sql);
230    
231                                    QueryPos qPos = QueryPos.getInstance(q);
232    
233                                    if (uuid != null) {
234                                            qPos.add(uuid);
235                                    }
236    
237                                    if (!pagination) {
238                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
239                                                            start, end, false);
240    
241                                            Collections.sort(list);
242    
243                                            list = new UnmodifiableList<WikiPage>(list);
244                                    }
245                                    else {
246                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
247                                                            start, end);
248                                    }
249    
250                                    cacheResult(list);
251    
252                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
253                            }
254                            catch (Exception e) {
255                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
256    
257                                    throw processException(e);
258                            }
259                            finally {
260                                    closeSession(session);
261                            }
262                    }
263    
264                    return list;
265            }
266    
267            /**
268             * Returns the first wiki page in the ordered set where uuid = &#63;.
269             *
270             * @param uuid the uuid
271             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
272             * @return the first matching wiki page
273             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
274             * @throws SystemException if a system exception occurred
275             */
276            public WikiPage findByUuid_First(String uuid,
277                    OrderByComparator orderByComparator)
278                    throws NoSuchPageException, SystemException {
279                    WikiPage wikiPage = fetchByUuid_First(uuid, orderByComparator);
280    
281                    if (wikiPage != null) {
282                            return wikiPage;
283                    }
284    
285                    StringBundler msg = new StringBundler(4);
286    
287                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
288    
289                    msg.append("uuid=");
290                    msg.append(uuid);
291    
292                    msg.append(StringPool.CLOSE_CURLY_BRACE);
293    
294                    throw new NoSuchPageException(msg.toString());
295            }
296    
297            /**
298             * Returns the first wiki page in the ordered set where uuid = &#63;.
299             *
300             * @param uuid the uuid
301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
302             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
303             * @throws SystemException if a system exception occurred
304             */
305            public WikiPage fetchByUuid_First(String uuid,
306                    OrderByComparator orderByComparator) throws SystemException {
307                    List<WikiPage> list = findByUuid(uuid, 0, 1, orderByComparator);
308    
309                    if (!list.isEmpty()) {
310                            return list.get(0);
311                    }
312    
313                    return null;
314            }
315    
316            /**
317             * Returns the last wiki page in the ordered set where uuid = &#63;.
318             *
319             * @param uuid the uuid
320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
321             * @return the last matching wiki page
322             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
323             * @throws SystemException if a system exception occurred
324             */
325            public WikiPage findByUuid_Last(String uuid,
326                    OrderByComparator orderByComparator)
327                    throws NoSuchPageException, SystemException {
328                    WikiPage wikiPage = fetchByUuid_Last(uuid, orderByComparator);
329    
330                    if (wikiPage != null) {
331                            return wikiPage;
332                    }
333    
334                    StringBundler msg = new StringBundler(4);
335    
336                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
337    
338                    msg.append("uuid=");
339                    msg.append(uuid);
340    
341                    msg.append(StringPool.CLOSE_CURLY_BRACE);
342    
343                    throw new NoSuchPageException(msg.toString());
344            }
345    
346            /**
347             * Returns the last wiki page in the ordered set where uuid = &#63;.
348             *
349             * @param uuid the uuid
350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
351             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
352             * @throws SystemException if a system exception occurred
353             */
354            public WikiPage fetchByUuid_Last(String uuid,
355                    OrderByComparator orderByComparator) throws SystemException {
356                    int count = countByUuid(uuid);
357    
358                    List<WikiPage> list = findByUuid(uuid, count - 1, count,
359                                    orderByComparator);
360    
361                    if (!list.isEmpty()) {
362                            return list.get(0);
363                    }
364    
365                    return null;
366            }
367    
368            /**
369             * Returns the wiki pages before and after the current wiki page in the ordered set where uuid = &#63;.
370             *
371             * @param pageId the primary key of the current wiki page
372             * @param uuid the uuid
373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
374             * @return the previous, current, and next wiki page
375             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
376             * @throws SystemException if a system exception occurred
377             */
378            public WikiPage[] findByUuid_PrevAndNext(long pageId, String uuid,
379                    OrderByComparator orderByComparator)
380                    throws NoSuchPageException, SystemException {
381                    WikiPage wikiPage = findByPrimaryKey(pageId);
382    
383                    Session session = null;
384    
385                    try {
386                            session = openSession();
387    
388                            WikiPage[] array = new WikiPageImpl[3];
389    
390                            array[0] = getByUuid_PrevAndNext(session, wikiPage, uuid,
391                                            orderByComparator, true);
392    
393                            array[1] = wikiPage;
394    
395                            array[2] = getByUuid_PrevAndNext(session, wikiPage, uuid,
396                                            orderByComparator, false);
397    
398                            return array;
399                    }
400                    catch (Exception e) {
401                            throw processException(e);
402                    }
403                    finally {
404                            closeSession(session);
405                    }
406            }
407    
408            protected WikiPage getByUuid_PrevAndNext(Session session,
409                    WikiPage wikiPage, String uuid, OrderByComparator orderByComparator,
410                    boolean previous) {
411                    StringBundler query = null;
412    
413                    if (orderByComparator != null) {
414                            query = new StringBundler(6 +
415                                            (orderByComparator.getOrderByFields().length * 6));
416                    }
417                    else {
418                            query = new StringBundler(3);
419                    }
420    
421                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
422    
423                    if (uuid == null) {
424                            query.append(_FINDER_COLUMN_UUID_UUID_1);
425                    }
426                    else {
427                            if (uuid.equals(StringPool.BLANK)) {
428                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
429                            }
430                            else {
431                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
432                            }
433                    }
434    
435                    if (orderByComparator != null) {
436                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
437    
438                            if (orderByConditionFields.length > 0) {
439                                    query.append(WHERE_AND);
440                            }
441    
442                            for (int i = 0; i < orderByConditionFields.length; i++) {
443                                    query.append(_ORDER_BY_ENTITY_ALIAS);
444                                    query.append(orderByConditionFields[i]);
445    
446                                    if ((i + 1) < orderByConditionFields.length) {
447                                            if (orderByComparator.isAscending() ^ previous) {
448                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
449                                            }
450                                            else {
451                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
452                                            }
453                                    }
454                                    else {
455                                            if (orderByComparator.isAscending() ^ previous) {
456                                                    query.append(WHERE_GREATER_THAN);
457                                            }
458                                            else {
459                                                    query.append(WHERE_LESSER_THAN);
460                                            }
461                                    }
462                            }
463    
464                            query.append(ORDER_BY_CLAUSE);
465    
466                            String[] orderByFields = orderByComparator.getOrderByFields();
467    
468                            for (int i = 0; i < orderByFields.length; i++) {
469                                    query.append(_ORDER_BY_ENTITY_ALIAS);
470                                    query.append(orderByFields[i]);
471    
472                                    if ((i + 1) < orderByFields.length) {
473                                            if (orderByComparator.isAscending() ^ previous) {
474                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
475                                            }
476                                            else {
477                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
478                                            }
479                                    }
480                                    else {
481                                            if (orderByComparator.isAscending() ^ previous) {
482                                                    query.append(ORDER_BY_ASC);
483                                            }
484                                            else {
485                                                    query.append(ORDER_BY_DESC);
486                                            }
487                                    }
488                            }
489                    }
490                    else {
491                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
492                    }
493    
494                    String sql = query.toString();
495    
496                    Query q = session.createQuery(sql);
497    
498                    q.setFirstResult(0);
499                    q.setMaxResults(2);
500    
501                    QueryPos qPos = QueryPos.getInstance(q);
502    
503                    if (uuid != null) {
504                            qPos.add(uuid);
505                    }
506    
507                    if (orderByComparator != null) {
508                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
509    
510                            for (Object value : values) {
511                                    qPos.add(value);
512                            }
513                    }
514    
515                    List<WikiPage> list = q.list();
516    
517                    if (list.size() == 2) {
518                            return list.get(1);
519                    }
520                    else {
521                            return null;
522                    }
523            }
524    
525            /**
526             * Removes all the wiki pages where uuid = &#63; from the database.
527             *
528             * @param uuid the uuid
529             * @throws SystemException if a system exception occurred
530             */
531            public void removeByUuid(String uuid) throws SystemException {
532                    for (WikiPage wikiPage : findByUuid(uuid, QueryUtil.ALL_POS,
533                                    QueryUtil.ALL_POS, null)) {
534                            remove(wikiPage);
535                    }
536            }
537    
538            /**
539             * Returns the number of wiki pages where uuid = &#63;.
540             *
541             * @param uuid the uuid
542             * @return the number of matching wiki pages
543             * @throws SystemException if a system exception occurred
544             */
545            public int countByUuid(String uuid) throws SystemException {
546                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
547    
548                    Object[] finderArgs = new Object[] { uuid };
549    
550                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
551                                    this);
552    
553                    if (count == null) {
554                            StringBundler query = new StringBundler(2);
555    
556                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
557    
558                            if (uuid == null) {
559                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
560                            }
561                            else {
562                                    if (uuid.equals(StringPool.BLANK)) {
563                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
564                                    }
565                                    else {
566                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
567                                    }
568                            }
569    
570                            String sql = query.toString();
571    
572                            Session session = null;
573    
574                            try {
575                                    session = openSession();
576    
577                                    Query q = session.createQuery(sql);
578    
579                                    QueryPos qPos = QueryPos.getInstance(q);
580    
581                                    if (uuid != null) {
582                                            qPos.add(uuid);
583                                    }
584    
585                                    count = (Long)q.uniqueResult();
586    
587                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
588                            }
589                            catch (Exception e) {
590                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
591    
592                                    throw processException(e);
593                            }
594                            finally {
595                                    closeSession(session);
596                            }
597                    }
598    
599                    return count.intValue();
600            }
601    
602            private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiPage.uuid IS NULL";
603            private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiPage.uuid = ?";
604            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiPage.uuid IS NULL OR wikiPage.uuid = ?)";
605            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
606                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
607                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
608                            new String[] { String.class.getName(), Long.class.getName() },
609                            WikiPageModelImpl.UUID_COLUMN_BITMASK |
610                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK);
611            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
612                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
613                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
614                            new String[] { String.class.getName(), Long.class.getName() });
615    
616            /**
617             * 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.
618             *
619             * @param uuid the uuid
620             * @param groupId the group ID
621             * @return the matching wiki page
622             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
623             * @throws SystemException if a system exception occurred
624             */
625            public WikiPage findByUUID_G(String uuid, long groupId)
626                    throws NoSuchPageException, SystemException {
627                    WikiPage wikiPage = fetchByUUID_G(uuid, groupId);
628    
629                    if (wikiPage == null) {
630                            StringBundler msg = new StringBundler(6);
631    
632                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
633    
634                            msg.append("uuid=");
635                            msg.append(uuid);
636    
637                            msg.append(", groupId=");
638                            msg.append(groupId);
639    
640                            msg.append(StringPool.CLOSE_CURLY_BRACE);
641    
642                            if (_log.isWarnEnabled()) {
643                                    _log.warn(msg.toString());
644                            }
645    
646                            throw new NoSuchPageException(msg.toString());
647                    }
648    
649                    return wikiPage;
650            }
651    
652            /**
653             * 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.
654             *
655             * @param uuid the uuid
656             * @param groupId the group ID
657             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
658             * @throws SystemException if a system exception occurred
659             */
660            public WikiPage fetchByUUID_G(String uuid, long groupId)
661                    throws SystemException {
662                    return fetchByUUID_G(uuid, groupId, true);
663            }
664    
665            /**
666             * 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.
667             *
668             * @param uuid the uuid
669             * @param groupId the group ID
670             * @param retrieveFromCache whether to use the finder cache
671             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
672             * @throws SystemException if a system exception occurred
673             */
674            public WikiPage fetchByUUID_G(String uuid, long groupId,
675                    boolean retrieveFromCache) throws SystemException {
676                    Object[] finderArgs = new Object[] { uuid, groupId };
677    
678                    Object result = null;
679    
680                    if (retrieveFromCache) {
681                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
682                                            finderArgs, this);
683                    }
684    
685                    if (result instanceof WikiPage) {
686                            WikiPage wikiPage = (WikiPage)result;
687    
688                            if (!Validator.equals(uuid, wikiPage.getUuid()) ||
689                                            (groupId != wikiPage.getGroupId())) {
690                                    result = null;
691                            }
692                    }
693    
694                    if (result == null) {
695                            StringBundler query = new StringBundler(4);
696    
697                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
698    
699                            if (uuid == null) {
700                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
701                            }
702                            else {
703                                    if (uuid.equals(StringPool.BLANK)) {
704                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
705                                    }
706                                    else {
707                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
708                                    }
709                            }
710    
711                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
712    
713                            String sql = query.toString();
714    
715                            Session session = null;
716    
717                            try {
718                                    session = openSession();
719    
720                                    Query q = session.createQuery(sql);
721    
722                                    QueryPos qPos = QueryPos.getInstance(q);
723    
724                                    if (uuid != null) {
725                                            qPos.add(uuid);
726                                    }
727    
728                                    qPos.add(groupId);
729    
730                                    List<WikiPage> list = q.list();
731    
732                                    if (list.isEmpty()) {
733                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
734                                                    finderArgs, list);
735                                    }
736                                    else {
737                                            WikiPage wikiPage = list.get(0);
738    
739                                            result = wikiPage;
740    
741                                            cacheResult(wikiPage);
742    
743                                            if ((wikiPage.getUuid() == null) ||
744                                                            !wikiPage.getUuid().equals(uuid) ||
745                                                            (wikiPage.getGroupId() != groupId)) {
746                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
747                                                            finderArgs, wikiPage);
748                                            }
749                                    }
750                            }
751                            catch (Exception e) {
752                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
753                                            finderArgs);
754    
755                                    throw processException(e);
756                            }
757                            finally {
758                                    closeSession(session);
759                            }
760                    }
761    
762                    if (result instanceof List<?>) {
763                            return null;
764                    }
765                    else {
766                            return (WikiPage)result;
767                    }
768            }
769    
770            /**
771             * Removes the wiki page where uuid = &#63; and groupId = &#63; from the database.
772             *
773             * @param uuid the uuid
774             * @param groupId the group ID
775             * @return the wiki page that was removed
776             * @throws SystemException if a system exception occurred
777             */
778            public WikiPage removeByUUID_G(String uuid, long groupId)
779                    throws NoSuchPageException, SystemException {
780                    WikiPage wikiPage = findByUUID_G(uuid, groupId);
781    
782                    return remove(wikiPage);
783            }
784    
785            /**
786             * Returns the number of wiki pages where uuid = &#63; and groupId = &#63;.
787             *
788             * @param uuid the uuid
789             * @param groupId the group ID
790             * @return the number of matching wiki pages
791             * @throws SystemException if a system exception occurred
792             */
793            public int countByUUID_G(String uuid, long groupId)
794                    throws SystemException {
795                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
796    
797                    Object[] finderArgs = new Object[] { uuid, groupId };
798    
799                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
800                                    this);
801    
802                    if (count == null) {
803                            StringBundler query = new StringBundler(3);
804    
805                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
806    
807                            if (uuid == null) {
808                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
809                            }
810                            else {
811                                    if (uuid.equals(StringPool.BLANK)) {
812                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
813                                    }
814                                    else {
815                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
816                                    }
817                            }
818    
819                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
820    
821                            String sql = query.toString();
822    
823                            Session session = null;
824    
825                            try {
826                                    session = openSession();
827    
828                                    Query q = session.createQuery(sql);
829    
830                                    QueryPos qPos = QueryPos.getInstance(q);
831    
832                                    if (uuid != null) {
833                                            qPos.add(uuid);
834                                    }
835    
836                                    qPos.add(groupId);
837    
838                                    count = (Long)q.uniqueResult();
839    
840                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
841                            }
842                            catch (Exception e) {
843                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
844    
845                                    throw processException(e);
846                            }
847                            finally {
848                                    closeSession(session);
849                            }
850                    }
851    
852                    return count.intValue();
853            }
854    
855            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "wikiPage.uuid IS NULL AND ";
856            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "wikiPage.uuid = ? AND ";
857            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(wikiPage.uuid IS NULL OR wikiPage.uuid = ?) AND ";
858            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "wikiPage.groupId = ?";
859            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
860                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
861                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
862                            new String[] {
863                                    String.class.getName(), Long.class.getName(),
864                                    
865                            Integer.class.getName(), Integer.class.getName(),
866                                    OrderByComparator.class.getName()
867                            });
868            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
869                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
870                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
871                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
872                            new String[] { String.class.getName(), Long.class.getName() },
873                            WikiPageModelImpl.UUID_COLUMN_BITMASK |
874                            WikiPageModelImpl.COMPANYID_COLUMN_BITMASK |
875                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
876                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
877                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
878            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
879                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
880                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
881                            new String[] { String.class.getName(), Long.class.getName() });
882    
883            /**
884             * Returns all the wiki pages where uuid = &#63; and companyId = &#63;.
885             *
886             * @param uuid the uuid
887             * @param companyId the company ID
888             * @return the matching wiki pages
889             * @throws SystemException if a system exception occurred
890             */
891            public List<WikiPage> findByUuid_C(String uuid, long companyId)
892                    throws SystemException {
893                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
894                            QueryUtil.ALL_POS, null);
895            }
896    
897            /**
898             * Returns a range of all the wiki pages where uuid = &#63; and companyId = &#63;.
899             *
900             * <p>
901             * 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.
902             * </p>
903             *
904             * @param uuid the uuid
905             * @param companyId the company ID
906             * @param start the lower bound of the range of wiki pages
907             * @param end the upper bound of the range of wiki pages (not inclusive)
908             * @return the range of matching wiki pages
909             * @throws SystemException if a system exception occurred
910             */
911            public List<WikiPage> findByUuid_C(String uuid, long companyId, int start,
912                    int end) throws SystemException {
913                    return findByUuid_C(uuid, companyId, start, end, null);
914            }
915    
916            /**
917             * Returns an ordered range of all the wiki pages where uuid = &#63; and companyId = &#63;.
918             *
919             * <p>
920             * 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.
921             * </p>
922             *
923             * @param uuid the uuid
924             * @param companyId the company ID
925             * @param start the lower bound of the range of wiki pages
926             * @param end the upper bound of the range of wiki pages (not inclusive)
927             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
928             * @return the ordered range of matching wiki pages
929             * @throws SystemException if a system exception occurred
930             */
931            public List<WikiPage> findByUuid_C(String uuid, long companyId, int start,
932                    int end, OrderByComparator orderByComparator) throws SystemException {
933                    boolean pagination = true;
934                    FinderPath finderPath = null;
935                    Object[] finderArgs = null;
936    
937                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
938                                    (orderByComparator == null)) {
939                            pagination = false;
940                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
941                            finderArgs = new Object[] { uuid, companyId };
942                    }
943                    else {
944                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
945                            finderArgs = new Object[] {
946                                            uuid, companyId,
947                                            
948                                            start, end, orderByComparator
949                                    };
950                    }
951    
952                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
953                                    finderArgs, this);
954    
955                    if ((list != null) && !list.isEmpty()) {
956                            for (WikiPage wikiPage : list) {
957                                    if (!Validator.equals(uuid, wikiPage.getUuid()) ||
958                                                    (companyId != wikiPage.getCompanyId())) {
959                                            list = null;
960    
961                                            break;
962                                    }
963                            }
964                    }
965    
966                    if (list == null) {
967                            StringBundler query = null;
968    
969                            if (orderByComparator != null) {
970                                    query = new StringBundler(4 +
971                                                    (orderByComparator.getOrderByFields().length * 3));
972                            }
973                            else {
974                                    query = new StringBundler(4);
975                            }
976    
977                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
978    
979                            if (uuid == null) {
980                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
981                            }
982                            else {
983                                    if (uuid.equals(StringPool.BLANK)) {
984                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
985                                    }
986                                    else {
987                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
988                                    }
989                            }
990    
991                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
992    
993                            if (orderByComparator != null) {
994                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
995                                            orderByComparator);
996                            }
997                            else
998                             if (pagination) {
999                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1000                            }
1001    
1002                            String sql = query.toString();
1003    
1004                            Session session = null;
1005    
1006                            try {
1007                                    session = openSession();
1008    
1009                                    Query q = session.createQuery(sql);
1010    
1011                                    QueryPos qPos = QueryPos.getInstance(q);
1012    
1013                                    if (uuid != null) {
1014                                            qPos.add(uuid);
1015                                    }
1016    
1017                                    qPos.add(companyId);
1018    
1019                                    if (!pagination) {
1020                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1021                                                            start, end, false);
1022    
1023                                            Collections.sort(list);
1024    
1025                                            list = new UnmodifiableList<WikiPage>(list);
1026                                    }
1027                                    else {
1028                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1029                                                            start, end);
1030                                    }
1031    
1032                                    cacheResult(list);
1033    
1034                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1035                            }
1036                            catch (Exception e) {
1037                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1038    
1039                                    throw processException(e);
1040                            }
1041                            finally {
1042                                    closeSession(session);
1043                            }
1044                    }
1045    
1046                    return list;
1047            }
1048    
1049            /**
1050             * Returns the first wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1051             *
1052             * @param uuid the uuid
1053             * @param companyId the company ID
1054             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1055             * @return the first matching wiki page
1056             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1057             * @throws SystemException if a system exception occurred
1058             */
1059            public WikiPage findByUuid_C_First(String uuid, long companyId,
1060                    OrderByComparator orderByComparator)
1061                    throws NoSuchPageException, SystemException {
1062                    WikiPage wikiPage = fetchByUuid_C_First(uuid, companyId,
1063                                    orderByComparator);
1064    
1065                    if (wikiPage != null) {
1066                            return wikiPage;
1067                    }
1068    
1069                    StringBundler msg = new StringBundler(6);
1070    
1071                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1072    
1073                    msg.append("uuid=");
1074                    msg.append(uuid);
1075    
1076                    msg.append(", companyId=");
1077                    msg.append(companyId);
1078    
1079                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1080    
1081                    throw new NoSuchPageException(msg.toString());
1082            }
1083    
1084            /**
1085             * Returns the first wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1086             *
1087             * @param uuid the uuid
1088             * @param companyId the company ID
1089             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1090             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
1091             * @throws SystemException if a system exception occurred
1092             */
1093            public WikiPage fetchByUuid_C_First(String uuid, long companyId,
1094                    OrderByComparator orderByComparator) throws SystemException {
1095                    List<WikiPage> list = findByUuid_C(uuid, companyId, 0, 1,
1096                                    orderByComparator);
1097    
1098                    if (!list.isEmpty()) {
1099                            return list.get(0);
1100                    }
1101    
1102                    return null;
1103            }
1104    
1105            /**
1106             * Returns the last wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1107             *
1108             * @param uuid the uuid
1109             * @param companyId the company ID
1110             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1111             * @return the last matching wiki page
1112             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1113             * @throws SystemException if a system exception occurred
1114             */
1115            public WikiPage findByUuid_C_Last(String uuid, long companyId,
1116                    OrderByComparator orderByComparator)
1117                    throws NoSuchPageException, SystemException {
1118                    WikiPage wikiPage = fetchByUuid_C_Last(uuid, companyId,
1119                                    orderByComparator);
1120    
1121                    if (wikiPage != null) {
1122                            return wikiPage;
1123                    }
1124    
1125                    StringBundler msg = new StringBundler(6);
1126    
1127                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1128    
1129                    msg.append("uuid=");
1130                    msg.append(uuid);
1131    
1132                    msg.append(", companyId=");
1133                    msg.append(companyId);
1134    
1135                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1136    
1137                    throw new NoSuchPageException(msg.toString());
1138            }
1139    
1140            /**
1141             * Returns the last wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1142             *
1143             * @param uuid the uuid
1144             * @param companyId the company ID
1145             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1146             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
1147             * @throws SystemException if a system exception occurred
1148             */
1149            public WikiPage fetchByUuid_C_Last(String uuid, long companyId,
1150                    OrderByComparator orderByComparator) throws SystemException {
1151                    int count = countByUuid_C(uuid, companyId);
1152    
1153                    List<WikiPage> list = findByUuid_C(uuid, companyId, count - 1, count,
1154                                    orderByComparator);
1155    
1156                    if (!list.isEmpty()) {
1157                            return list.get(0);
1158                    }
1159    
1160                    return null;
1161            }
1162    
1163            /**
1164             * Returns the wiki pages before and after the current wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1165             *
1166             * @param pageId the primary key of the current wiki page
1167             * @param uuid the uuid
1168             * @param companyId the company ID
1169             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1170             * @return the previous, current, and next wiki page
1171             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
1172             * @throws SystemException if a system exception occurred
1173             */
1174            public WikiPage[] findByUuid_C_PrevAndNext(long pageId, String uuid,
1175                    long companyId, OrderByComparator orderByComparator)
1176                    throws NoSuchPageException, SystemException {
1177                    WikiPage wikiPage = findByPrimaryKey(pageId);
1178    
1179                    Session session = null;
1180    
1181                    try {
1182                            session = openSession();
1183    
1184                            WikiPage[] array = new WikiPageImpl[3];
1185    
1186                            array[0] = getByUuid_C_PrevAndNext(session, wikiPage, uuid,
1187                                            companyId, orderByComparator, true);
1188    
1189                            array[1] = wikiPage;
1190    
1191                            array[2] = getByUuid_C_PrevAndNext(session, wikiPage, uuid,
1192                                            companyId, orderByComparator, false);
1193    
1194                            return array;
1195                    }
1196                    catch (Exception e) {
1197                            throw processException(e);
1198                    }
1199                    finally {
1200                            closeSession(session);
1201                    }
1202            }
1203    
1204            protected WikiPage getByUuid_C_PrevAndNext(Session session,
1205                    WikiPage wikiPage, String uuid, long companyId,
1206                    OrderByComparator orderByComparator, boolean previous) {
1207                    StringBundler query = null;
1208    
1209                    if (orderByComparator != null) {
1210                            query = new StringBundler(6 +
1211                                            (orderByComparator.getOrderByFields().length * 6));
1212                    }
1213                    else {
1214                            query = new StringBundler(3);
1215                    }
1216    
1217                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1218    
1219                    if (uuid == null) {
1220                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1221                    }
1222                    else {
1223                            if (uuid.equals(StringPool.BLANK)) {
1224                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1225                            }
1226                            else {
1227                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1228                            }
1229                    }
1230    
1231                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1232    
1233                    if (orderByComparator != null) {
1234                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1235    
1236                            if (orderByConditionFields.length > 0) {
1237                                    query.append(WHERE_AND);
1238                            }
1239    
1240                            for (int i = 0; i < orderByConditionFields.length; i++) {
1241                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1242                                    query.append(orderByConditionFields[i]);
1243    
1244                                    if ((i + 1) < orderByConditionFields.length) {
1245                                            if (orderByComparator.isAscending() ^ previous) {
1246                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1247                                            }
1248                                            else {
1249                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1250                                            }
1251                                    }
1252                                    else {
1253                                            if (orderByComparator.isAscending() ^ previous) {
1254                                                    query.append(WHERE_GREATER_THAN);
1255                                            }
1256                                            else {
1257                                                    query.append(WHERE_LESSER_THAN);
1258                                            }
1259                                    }
1260                            }
1261    
1262                            query.append(ORDER_BY_CLAUSE);
1263    
1264                            String[] orderByFields = orderByComparator.getOrderByFields();
1265    
1266                            for (int i = 0; i < orderByFields.length; i++) {
1267                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1268                                    query.append(orderByFields[i]);
1269    
1270                                    if ((i + 1) < orderByFields.length) {
1271                                            if (orderByComparator.isAscending() ^ previous) {
1272                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1273                                            }
1274                                            else {
1275                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1276                                            }
1277                                    }
1278                                    else {
1279                                            if (orderByComparator.isAscending() ^ previous) {
1280                                                    query.append(ORDER_BY_ASC);
1281                                            }
1282                                            else {
1283                                                    query.append(ORDER_BY_DESC);
1284                                            }
1285                                    }
1286                            }
1287                    }
1288                    else {
1289                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1290                    }
1291    
1292                    String sql = query.toString();
1293    
1294                    Query q = session.createQuery(sql);
1295    
1296                    q.setFirstResult(0);
1297                    q.setMaxResults(2);
1298    
1299                    QueryPos qPos = QueryPos.getInstance(q);
1300    
1301                    if (uuid != null) {
1302                            qPos.add(uuid);
1303                    }
1304    
1305                    qPos.add(companyId);
1306    
1307                    if (orderByComparator != null) {
1308                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
1309    
1310                            for (Object value : values) {
1311                                    qPos.add(value);
1312                            }
1313                    }
1314    
1315                    List<WikiPage> list = q.list();
1316    
1317                    if (list.size() == 2) {
1318                            return list.get(1);
1319                    }
1320                    else {
1321                            return null;
1322                    }
1323            }
1324    
1325            /**
1326             * Removes all the wiki pages where uuid = &#63; and companyId = &#63; from the database.
1327             *
1328             * @param uuid the uuid
1329             * @param companyId the company ID
1330             * @throws SystemException if a system exception occurred
1331             */
1332            public void removeByUuid_C(String uuid, long companyId)
1333                    throws SystemException {
1334                    for (WikiPage wikiPage : findByUuid_C(uuid, companyId,
1335                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1336                            remove(wikiPage);
1337                    }
1338            }
1339    
1340            /**
1341             * Returns the number of wiki pages where uuid = &#63; and companyId = &#63;.
1342             *
1343             * @param uuid the uuid
1344             * @param companyId the company ID
1345             * @return the number of matching wiki pages
1346             * @throws SystemException if a system exception occurred
1347             */
1348            public int countByUuid_C(String uuid, long companyId)
1349                    throws SystemException {
1350                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1351    
1352                    Object[] finderArgs = new Object[] { uuid, companyId };
1353    
1354                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1355                                    this);
1356    
1357                    if (count == null) {
1358                            StringBundler query = new StringBundler(3);
1359    
1360                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
1361    
1362                            if (uuid == null) {
1363                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1364                            }
1365                            else {
1366                                    if (uuid.equals(StringPool.BLANK)) {
1367                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1368                                    }
1369                                    else {
1370                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1371                                    }
1372                            }
1373    
1374                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1375    
1376                            String sql = query.toString();
1377    
1378                            Session session = null;
1379    
1380                            try {
1381                                    session = openSession();
1382    
1383                                    Query q = session.createQuery(sql);
1384    
1385                                    QueryPos qPos = QueryPos.getInstance(q);
1386    
1387                                    if (uuid != null) {
1388                                            qPos.add(uuid);
1389                                    }
1390    
1391                                    qPos.add(companyId);
1392    
1393                                    count = (Long)q.uniqueResult();
1394    
1395                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1396                            }
1397                            catch (Exception e) {
1398                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1399    
1400                                    throw processException(e);
1401                            }
1402                            finally {
1403                                    closeSession(session);
1404                            }
1405                    }
1406    
1407                    return count.intValue();
1408            }
1409    
1410            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "wikiPage.uuid IS NULL AND ";
1411            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "wikiPage.uuid = ? AND ";
1412            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(wikiPage.uuid IS NULL OR wikiPage.uuid = ?) AND ";
1413            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "wikiPage.companyId = ?";
1414            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NODEID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1415                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1416                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByNodeId",
1417                            new String[] {
1418                                    Long.class.getName(),
1419                                    
1420                            Integer.class.getName(), Integer.class.getName(),
1421                                    OrderByComparator.class.getName()
1422                            });
1423            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID =
1424                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1425                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1426                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByNodeId",
1427                            new String[] { Long.class.getName() },
1428                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
1429                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
1430                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
1431            public static final FinderPath FINDER_PATH_COUNT_BY_NODEID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1432                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1433                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByNodeId",
1434                            new String[] { Long.class.getName() });
1435    
1436            /**
1437             * Returns all the wiki pages where nodeId = &#63;.
1438             *
1439             * @param nodeId the node ID
1440             * @return the matching wiki pages
1441             * @throws SystemException if a system exception occurred
1442             */
1443            public List<WikiPage> findByNodeId(long nodeId) throws SystemException {
1444                    return findByNodeId(nodeId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1445            }
1446    
1447            /**
1448             * Returns a range of all the wiki pages where nodeId = &#63;.
1449             *
1450             * <p>
1451             * 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.
1452             * </p>
1453             *
1454             * @param nodeId the node ID
1455             * @param start the lower bound of the range of wiki pages
1456             * @param end the upper bound of the range of wiki pages (not inclusive)
1457             * @return the range of matching wiki pages
1458             * @throws SystemException if a system exception occurred
1459             */
1460            public List<WikiPage> findByNodeId(long nodeId, int start, int end)
1461                    throws SystemException {
1462                    return findByNodeId(nodeId, start, end, null);
1463            }
1464    
1465            /**
1466             * Returns an ordered range of all the wiki pages where nodeId = &#63;.
1467             *
1468             * <p>
1469             * 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.
1470             * </p>
1471             *
1472             * @param nodeId the node ID
1473             * @param start the lower bound of the range of wiki pages
1474             * @param end the upper bound of the range of wiki pages (not inclusive)
1475             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1476             * @return the ordered range of matching wiki pages
1477             * @throws SystemException if a system exception occurred
1478             */
1479            public List<WikiPage> findByNodeId(long nodeId, int start, int end,
1480                    OrderByComparator orderByComparator) throws SystemException {
1481                    boolean pagination = true;
1482                    FinderPath finderPath = null;
1483                    Object[] finderArgs = null;
1484    
1485                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1486                                    (orderByComparator == null)) {
1487                            pagination = false;
1488                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID;
1489                            finderArgs = new Object[] { nodeId };
1490                    }
1491                    else {
1492                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NODEID;
1493                            finderArgs = new Object[] { nodeId, start, end, orderByComparator };
1494                    }
1495    
1496                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
1497                                    finderArgs, this);
1498    
1499                    if ((list != null) && !list.isEmpty()) {
1500                            for (WikiPage wikiPage : list) {
1501                                    if ((nodeId != wikiPage.getNodeId())) {
1502                                            list = null;
1503    
1504                                            break;
1505                                    }
1506                            }
1507                    }
1508    
1509                    if (list == null) {
1510                            StringBundler query = null;
1511    
1512                            if (orderByComparator != null) {
1513                                    query = new StringBundler(3 +
1514                                                    (orderByComparator.getOrderByFields().length * 3));
1515                            }
1516                            else {
1517                                    query = new StringBundler(3);
1518                            }
1519    
1520                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1521    
1522                            query.append(_FINDER_COLUMN_NODEID_NODEID_2);
1523    
1524                            if (orderByComparator != null) {
1525                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1526                                            orderByComparator);
1527                            }
1528                            else
1529                             if (pagination) {
1530                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1531                            }
1532    
1533                            String sql = query.toString();
1534    
1535                            Session session = null;
1536    
1537                            try {
1538                                    session = openSession();
1539    
1540                                    Query q = session.createQuery(sql);
1541    
1542                                    QueryPos qPos = QueryPos.getInstance(q);
1543    
1544                                    qPos.add(nodeId);
1545    
1546                                    if (!pagination) {
1547                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1548                                                            start, end, false);
1549    
1550                                            Collections.sort(list);
1551    
1552                                            list = new UnmodifiableList<WikiPage>(list);
1553                                    }
1554                                    else {
1555                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1556                                                            start, end);
1557                                    }
1558    
1559                                    cacheResult(list);
1560    
1561                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1562                            }
1563                            catch (Exception e) {
1564                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1565    
1566                                    throw processException(e);
1567                            }
1568                            finally {
1569                                    closeSession(session);
1570                            }
1571                    }
1572    
1573                    return list;
1574            }
1575    
1576            /**
1577             * Returns the first wiki page in the ordered set where nodeId = &#63;.
1578             *
1579             * @param nodeId the node ID
1580             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1581             * @return the first matching wiki page
1582             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1583             * @throws SystemException if a system exception occurred
1584             */
1585            public WikiPage findByNodeId_First(long nodeId,
1586                    OrderByComparator orderByComparator)
1587                    throws NoSuchPageException, SystemException {
1588                    WikiPage wikiPage = fetchByNodeId_First(nodeId, orderByComparator);
1589    
1590                    if (wikiPage != null) {
1591                            return wikiPage;
1592                    }
1593    
1594                    StringBundler msg = new StringBundler(4);
1595    
1596                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1597    
1598                    msg.append("nodeId=");
1599                    msg.append(nodeId);
1600    
1601                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1602    
1603                    throw new NoSuchPageException(msg.toString());
1604            }
1605    
1606            /**
1607             * Returns the first wiki page in the ordered set where nodeId = &#63;.
1608             *
1609             * @param nodeId the node ID
1610             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1611             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
1612             * @throws SystemException if a system exception occurred
1613             */
1614            public WikiPage fetchByNodeId_First(long nodeId,
1615                    OrderByComparator orderByComparator) throws SystemException {
1616                    List<WikiPage> list = findByNodeId(nodeId, 0, 1, orderByComparator);
1617    
1618                    if (!list.isEmpty()) {
1619                            return list.get(0);
1620                    }
1621    
1622                    return null;
1623            }
1624    
1625            /**
1626             * Returns the last wiki page in the ordered set where nodeId = &#63;.
1627             *
1628             * @param nodeId the node ID
1629             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1630             * @return the last matching wiki page
1631             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1632             * @throws SystemException if a system exception occurred
1633             */
1634            public WikiPage findByNodeId_Last(long nodeId,
1635                    OrderByComparator orderByComparator)
1636                    throws NoSuchPageException, SystemException {
1637                    WikiPage wikiPage = fetchByNodeId_Last(nodeId, orderByComparator);
1638    
1639                    if (wikiPage != null) {
1640                            return wikiPage;
1641                    }
1642    
1643                    StringBundler msg = new StringBundler(4);
1644    
1645                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1646    
1647                    msg.append("nodeId=");
1648                    msg.append(nodeId);
1649    
1650                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1651    
1652                    throw new NoSuchPageException(msg.toString());
1653            }
1654    
1655            /**
1656             * Returns the last wiki page in the ordered set where nodeId = &#63;.
1657             *
1658             * @param nodeId the node ID
1659             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1660             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
1661             * @throws SystemException if a system exception occurred
1662             */
1663            public WikiPage fetchByNodeId_Last(long nodeId,
1664                    OrderByComparator orderByComparator) throws SystemException {
1665                    int count = countByNodeId(nodeId);
1666    
1667                    List<WikiPage> list = findByNodeId(nodeId, count - 1, count,
1668                                    orderByComparator);
1669    
1670                    if (!list.isEmpty()) {
1671                            return list.get(0);
1672                    }
1673    
1674                    return null;
1675            }
1676    
1677            /**
1678             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63;.
1679             *
1680             * @param pageId the primary key of the current wiki page
1681             * @param nodeId the node ID
1682             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1683             * @return the previous, current, and next wiki page
1684             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
1685             * @throws SystemException if a system exception occurred
1686             */
1687            public WikiPage[] findByNodeId_PrevAndNext(long pageId, long nodeId,
1688                    OrderByComparator orderByComparator)
1689                    throws NoSuchPageException, SystemException {
1690                    WikiPage wikiPage = findByPrimaryKey(pageId);
1691    
1692                    Session session = null;
1693    
1694                    try {
1695                            session = openSession();
1696    
1697                            WikiPage[] array = new WikiPageImpl[3];
1698    
1699                            array[0] = getByNodeId_PrevAndNext(session, wikiPage, nodeId,
1700                                            orderByComparator, true);
1701    
1702                            array[1] = wikiPage;
1703    
1704                            array[2] = getByNodeId_PrevAndNext(session, wikiPage, nodeId,
1705                                            orderByComparator, false);
1706    
1707                            return array;
1708                    }
1709                    catch (Exception e) {
1710                            throw processException(e);
1711                    }
1712                    finally {
1713                            closeSession(session);
1714                    }
1715            }
1716    
1717            protected WikiPage getByNodeId_PrevAndNext(Session session,
1718                    WikiPage wikiPage, long nodeId, OrderByComparator orderByComparator,
1719                    boolean previous) {
1720                    StringBundler query = null;
1721    
1722                    if (orderByComparator != null) {
1723                            query = new StringBundler(6 +
1724                                            (orderByComparator.getOrderByFields().length * 6));
1725                    }
1726                    else {
1727                            query = new StringBundler(3);
1728                    }
1729    
1730                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1731    
1732                    query.append(_FINDER_COLUMN_NODEID_NODEID_2);
1733    
1734                    if (orderByComparator != null) {
1735                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1736    
1737                            if (orderByConditionFields.length > 0) {
1738                                    query.append(WHERE_AND);
1739                            }
1740    
1741                            for (int i = 0; i < orderByConditionFields.length; i++) {
1742                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1743                                    query.append(orderByConditionFields[i]);
1744    
1745                                    if ((i + 1) < orderByConditionFields.length) {
1746                                            if (orderByComparator.isAscending() ^ previous) {
1747                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1748                                            }
1749                                            else {
1750                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1751                                            }
1752                                    }
1753                                    else {
1754                                            if (orderByComparator.isAscending() ^ previous) {
1755                                                    query.append(WHERE_GREATER_THAN);
1756                                            }
1757                                            else {
1758                                                    query.append(WHERE_LESSER_THAN);
1759                                            }
1760                                    }
1761                            }
1762    
1763                            query.append(ORDER_BY_CLAUSE);
1764    
1765                            String[] orderByFields = orderByComparator.getOrderByFields();
1766    
1767                            for (int i = 0; i < orderByFields.length; i++) {
1768                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1769                                    query.append(orderByFields[i]);
1770    
1771                                    if ((i + 1) < orderByFields.length) {
1772                                            if (orderByComparator.isAscending() ^ previous) {
1773                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1774                                            }
1775                                            else {
1776                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1777                                            }
1778                                    }
1779                                    else {
1780                                            if (orderByComparator.isAscending() ^ previous) {
1781                                                    query.append(ORDER_BY_ASC);
1782                                            }
1783                                            else {
1784                                                    query.append(ORDER_BY_DESC);
1785                                            }
1786                                    }
1787                            }
1788                    }
1789                    else {
1790                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1791                    }
1792    
1793                    String sql = query.toString();
1794    
1795                    Query q = session.createQuery(sql);
1796    
1797                    q.setFirstResult(0);
1798                    q.setMaxResults(2);
1799    
1800                    QueryPos qPos = QueryPos.getInstance(q);
1801    
1802                    qPos.add(nodeId);
1803    
1804                    if (orderByComparator != null) {
1805                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
1806    
1807                            for (Object value : values) {
1808                                    qPos.add(value);
1809                            }
1810                    }
1811    
1812                    List<WikiPage> list = q.list();
1813    
1814                    if (list.size() == 2) {
1815                            return list.get(1);
1816                    }
1817                    else {
1818                            return null;
1819                    }
1820            }
1821    
1822            /**
1823             * Removes all the wiki pages where nodeId = &#63; from the database.
1824             *
1825             * @param nodeId the node ID
1826             * @throws SystemException if a system exception occurred
1827             */
1828            public void removeByNodeId(long nodeId) throws SystemException {
1829                    for (WikiPage wikiPage : findByNodeId(nodeId, QueryUtil.ALL_POS,
1830                                    QueryUtil.ALL_POS, null)) {
1831                            remove(wikiPage);
1832                    }
1833            }
1834    
1835            /**
1836             * Returns the number of wiki pages where nodeId = &#63;.
1837             *
1838             * @param nodeId the node ID
1839             * @return the number of matching wiki pages
1840             * @throws SystemException if a system exception occurred
1841             */
1842            public int countByNodeId(long nodeId) throws SystemException {
1843                    FinderPath finderPath = FINDER_PATH_COUNT_BY_NODEID;
1844    
1845                    Object[] finderArgs = new Object[] { nodeId };
1846    
1847                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1848                                    this);
1849    
1850                    if (count == null) {
1851                            StringBundler query = new StringBundler(2);
1852    
1853                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
1854    
1855                            query.append(_FINDER_COLUMN_NODEID_NODEID_2);
1856    
1857                            String sql = query.toString();
1858    
1859                            Session session = null;
1860    
1861                            try {
1862                                    session = openSession();
1863    
1864                                    Query q = session.createQuery(sql);
1865    
1866                                    QueryPos qPos = QueryPos.getInstance(q);
1867    
1868                                    qPos.add(nodeId);
1869    
1870                                    count = (Long)q.uniqueResult();
1871    
1872                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1873                            }
1874                            catch (Exception e) {
1875                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1876    
1877                                    throw processException(e);
1878                            }
1879                            finally {
1880                                    closeSession(session);
1881                            }
1882                    }
1883    
1884                    return count.intValue();
1885            }
1886    
1887            private static final String _FINDER_COLUMN_NODEID_NODEID_2 = "wikiPage.nodeId = ?";
1888            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FORMAT = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1889                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1890                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByFormat",
1891                            new String[] {
1892                                    String.class.getName(),
1893                                    
1894                            Integer.class.getName(), Integer.class.getName(),
1895                                    OrderByComparator.class.getName()
1896                            });
1897            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT =
1898                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1899                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1900                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByFormat",
1901                            new String[] { String.class.getName() },
1902                            WikiPageModelImpl.FORMAT_COLUMN_BITMASK |
1903                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
1904                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
1905                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
1906            public static final FinderPath FINDER_PATH_COUNT_BY_FORMAT = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1907                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1908                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFormat",
1909                            new String[] { String.class.getName() });
1910    
1911            /**
1912             * Returns all the wiki pages where format = &#63;.
1913             *
1914             * @param format the format
1915             * @return the matching wiki pages
1916             * @throws SystemException if a system exception occurred
1917             */
1918            public List<WikiPage> findByFormat(String format) throws SystemException {
1919                    return findByFormat(format, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1920            }
1921    
1922            /**
1923             * Returns a range of all the wiki pages where format = &#63;.
1924             *
1925             * <p>
1926             * 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.
1927             * </p>
1928             *
1929             * @param format the format
1930             * @param start the lower bound of the range of wiki pages
1931             * @param end the upper bound of the range of wiki pages (not inclusive)
1932             * @return the range of matching wiki pages
1933             * @throws SystemException if a system exception occurred
1934             */
1935            public List<WikiPage> findByFormat(String format, int start, int end)
1936                    throws SystemException {
1937                    return findByFormat(format, start, end, null);
1938            }
1939    
1940            /**
1941             * Returns an ordered range of all the wiki pages where format = &#63;.
1942             *
1943             * <p>
1944             * 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.
1945             * </p>
1946             *
1947             * @param format the format
1948             * @param start the lower bound of the range of wiki pages
1949             * @param end the upper bound of the range of wiki pages (not inclusive)
1950             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1951             * @return the ordered range of matching wiki pages
1952             * @throws SystemException if a system exception occurred
1953             */
1954            public List<WikiPage> findByFormat(String format, int start, int end,
1955                    OrderByComparator orderByComparator) throws SystemException {
1956                    boolean pagination = true;
1957                    FinderPath finderPath = null;
1958                    Object[] finderArgs = null;
1959    
1960                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1961                                    (orderByComparator == null)) {
1962                            pagination = false;
1963                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT;
1964                            finderArgs = new Object[] { format };
1965                    }
1966                    else {
1967                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FORMAT;
1968                            finderArgs = new Object[] { format, start, end, orderByComparator };
1969                    }
1970    
1971                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
1972                                    finderArgs, this);
1973    
1974                    if ((list != null) && !list.isEmpty()) {
1975                            for (WikiPage wikiPage : list) {
1976                                    if (!Validator.equals(format, wikiPage.getFormat())) {
1977                                            list = null;
1978    
1979                                            break;
1980                                    }
1981                            }
1982                    }
1983    
1984                    if (list == null) {
1985                            StringBundler query = null;
1986    
1987                            if (orderByComparator != null) {
1988                                    query = new StringBundler(3 +
1989                                                    (orderByComparator.getOrderByFields().length * 3));
1990                            }
1991                            else {
1992                                    query = new StringBundler(3);
1993                            }
1994    
1995                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1996    
1997                            if (format == null) {
1998                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
1999                            }
2000                            else {
2001                                    if (format.equals(StringPool.BLANK)) {
2002                                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
2003                                    }
2004                                    else {
2005                                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
2006                                    }
2007                            }
2008    
2009                            if (orderByComparator != null) {
2010                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2011                                            orderByComparator);
2012                            }
2013                            else
2014                             if (pagination) {
2015                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2016                            }
2017    
2018                            String sql = query.toString();
2019    
2020                            Session session = null;
2021    
2022                            try {
2023                                    session = openSession();
2024    
2025                                    Query q = session.createQuery(sql);
2026    
2027                                    QueryPos qPos = QueryPos.getInstance(q);
2028    
2029                                    if (format != null) {
2030                                            qPos.add(format);
2031                                    }
2032    
2033                                    if (!pagination) {
2034                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2035                                                            start, end, false);
2036    
2037                                            Collections.sort(list);
2038    
2039                                            list = new UnmodifiableList<WikiPage>(list);
2040                                    }
2041                                    else {
2042                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2043                                                            start, end);
2044                                    }
2045    
2046                                    cacheResult(list);
2047    
2048                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2049                            }
2050                            catch (Exception e) {
2051                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2052    
2053                                    throw processException(e);
2054                            }
2055                            finally {
2056                                    closeSession(session);
2057                            }
2058                    }
2059    
2060                    return list;
2061            }
2062    
2063            /**
2064             * Returns the first wiki page in the ordered set where format = &#63;.
2065             *
2066             * @param format the format
2067             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2068             * @return the first matching wiki page
2069             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2070             * @throws SystemException if a system exception occurred
2071             */
2072            public WikiPage findByFormat_First(String format,
2073                    OrderByComparator orderByComparator)
2074                    throws NoSuchPageException, SystemException {
2075                    WikiPage wikiPage = fetchByFormat_First(format, orderByComparator);
2076    
2077                    if (wikiPage != null) {
2078                            return wikiPage;
2079                    }
2080    
2081                    StringBundler msg = new StringBundler(4);
2082    
2083                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2084    
2085                    msg.append("format=");
2086                    msg.append(format);
2087    
2088                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2089    
2090                    throw new NoSuchPageException(msg.toString());
2091            }
2092    
2093            /**
2094             * Returns the first wiki page in the ordered set where format = &#63;.
2095             *
2096             * @param format the format
2097             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2098             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
2099             * @throws SystemException if a system exception occurred
2100             */
2101            public WikiPage fetchByFormat_First(String format,
2102                    OrderByComparator orderByComparator) throws SystemException {
2103                    List<WikiPage> list = findByFormat(format, 0, 1, orderByComparator);
2104    
2105                    if (!list.isEmpty()) {
2106                            return list.get(0);
2107                    }
2108    
2109                    return null;
2110            }
2111    
2112            /**
2113             * Returns the last 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 last matching wiki page
2118             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2119             * @throws SystemException if a system exception occurred
2120             */
2121            public WikiPage findByFormat_Last(String format,
2122                    OrderByComparator orderByComparator)
2123                    throws NoSuchPageException, SystemException {
2124                    WikiPage wikiPage = fetchByFormat_Last(format, orderByComparator);
2125    
2126                    if (wikiPage != null) {
2127                            return wikiPage;
2128                    }
2129    
2130                    StringBundler msg = new StringBundler(4);
2131    
2132                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2133    
2134                    msg.append("format=");
2135                    msg.append(format);
2136    
2137                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2138    
2139                    throw new NoSuchPageException(msg.toString());
2140            }
2141    
2142            /**
2143             * Returns the last wiki page in the ordered set where format = &#63;.
2144             *
2145             * @param format the format
2146             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2147             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
2148             * @throws SystemException if a system exception occurred
2149             */
2150            public WikiPage fetchByFormat_Last(String format,
2151                    OrderByComparator orderByComparator) throws SystemException {
2152                    int count = countByFormat(format);
2153    
2154                    List<WikiPage> list = findByFormat(format, count - 1, count,
2155                                    orderByComparator);
2156    
2157                    if (!list.isEmpty()) {
2158                            return list.get(0);
2159                    }
2160    
2161                    return null;
2162            }
2163    
2164            /**
2165             * Returns the wiki pages before and after the current wiki page in the ordered set where format = &#63;.
2166             *
2167             * @param pageId the primary key of the current wiki page
2168             * @param format the format
2169             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2170             * @return the previous, current, and next wiki page
2171             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
2172             * @throws SystemException if a system exception occurred
2173             */
2174            public WikiPage[] findByFormat_PrevAndNext(long pageId, String format,
2175                    OrderByComparator orderByComparator)
2176                    throws NoSuchPageException, SystemException {
2177                    WikiPage wikiPage = findByPrimaryKey(pageId);
2178    
2179                    Session session = null;
2180    
2181                    try {
2182                            session = openSession();
2183    
2184                            WikiPage[] array = new WikiPageImpl[3];
2185    
2186                            array[0] = getByFormat_PrevAndNext(session, wikiPage, format,
2187                                            orderByComparator, true);
2188    
2189                            array[1] = wikiPage;
2190    
2191                            array[2] = getByFormat_PrevAndNext(session, wikiPage, format,
2192                                            orderByComparator, false);
2193    
2194                            return array;
2195                    }
2196                    catch (Exception e) {
2197                            throw processException(e);
2198                    }
2199                    finally {
2200                            closeSession(session);
2201                    }
2202            }
2203    
2204            protected WikiPage getByFormat_PrevAndNext(Session session,
2205                    WikiPage wikiPage, String format, OrderByComparator orderByComparator,
2206                    boolean previous) {
2207                    StringBundler query = null;
2208    
2209                    if (orderByComparator != null) {
2210                            query = new StringBundler(6 +
2211                                            (orderByComparator.getOrderByFields().length * 6));
2212                    }
2213                    else {
2214                            query = new StringBundler(3);
2215                    }
2216    
2217                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2218    
2219                    if (format == null) {
2220                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
2221                    }
2222                    else {
2223                            if (format.equals(StringPool.BLANK)) {
2224                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
2225                            }
2226                            else {
2227                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
2228                            }
2229                    }
2230    
2231                    if (orderByComparator != null) {
2232                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2233    
2234                            if (orderByConditionFields.length > 0) {
2235                                    query.append(WHERE_AND);
2236                            }
2237    
2238                            for (int i = 0; i < orderByConditionFields.length; i++) {
2239                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2240                                    query.append(orderByConditionFields[i]);
2241    
2242                                    if ((i + 1) < orderByConditionFields.length) {
2243                                            if (orderByComparator.isAscending() ^ previous) {
2244                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2245                                            }
2246                                            else {
2247                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2248                                            }
2249                                    }
2250                                    else {
2251                                            if (orderByComparator.isAscending() ^ previous) {
2252                                                    query.append(WHERE_GREATER_THAN);
2253                                            }
2254                                            else {
2255                                                    query.append(WHERE_LESSER_THAN);
2256                                            }
2257                                    }
2258                            }
2259    
2260                            query.append(ORDER_BY_CLAUSE);
2261    
2262                            String[] orderByFields = orderByComparator.getOrderByFields();
2263    
2264                            for (int i = 0; i < orderByFields.length; i++) {
2265                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2266                                    query.append(orderByFields[i]);
2267    
2268                                    if ((i + 1) < orderByFields.length) {
2269                                            if (orderByComparator.isAscending() ^ previous) {
2270                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2271                                            }
2272                                            else {
2273                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2274                                            }
2275                                    }
2276                                    else {
2277                                            if (orderByComparator.isAscending() ^ previous) {
2278                                                    query.append(ORDER_BY_ASC);
2279                                            }
2280                                            else {
2281                                                    query.append(ORDER_BY_DESC);
2282                                            }
2283                                    }
2284                            }
2285                    }
2286                    else {
2287                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2288                    }
2289    
2290                    String sql = query.toString();
2291    
2292                    Query q = session.createQuery(sql);
2293    
2294                    q.setFirstResult(0);
2295                    q.setMaxResults(2);
2296    
2297                    QueryPos qPos = QueryPos.getInstance(q);
2298    
2299                    if (format != null) {
2300                            qPos.add(format);
2301                    }
2302    
2303                    if (orderByComparator != null) {
2304                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
2305    
2306                            for (Object value : values) {
2307                                    qPos.add(value);
2308                            }
2309                    }
2310    
2311                    List<WikiPage> list = q.list();
2312    
2313                    if (list.size() == 2) {
2314                            return list.get(1);
2315                    }
2316                    else {
2317                            return null;
2318                    }
2319            }
2320    
2321            /**
2322             * Removes all the wiki pages where format = &#63; from the database.
2323             *
2324             * @param format the format
2325             * @throws SystemException if a system exception occurred
2326             */
2327            public void removeByFormat(String format) throws SystemException {
2328                    for (WikiPage wikiPage : findByFormat(format, QueryUtil.ALL_POS,
2329                                    QueryUtil.ALL_POS, null)) {
2330                            remove(wikiPage);
2331                    }
2332            }
2333    
2334            /**
2335             * Returns the number of wiki pages where format = &#63;.
2336             *
2337             * @param format the format
2338             * @return the number of matching wiki pages
2339             * @throws SystemException if a system exception occurred
2340             */
2341            public int countByFormat(String format) throws SystemException {
2342                    FinderPath finderPath = FINDER_PATH_COUNT_BY_FORMAT;
2343    
2344                    Object[] finderArgs = new Object[] { format };
2345    
2346                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2347                                    this);
2348    
2349                    if (count == null) {
2350                            StringBundler query = new StringBundler(2);
2351    
2352                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
2353    
2354                            if (format == null) {
2355                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
2356                            }
2357                            else {
2358                                    if (format.equals(StringPool.BLANK)) {
2359                                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
2360                                    }
2361                                    else {
2362                                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
2363                                    }
2364                            }
2365    
2366                            String sql = query.toString();
2367    
2368                            Session session = null;
2369    
2370                            try {
2371                                    session = openSession();
2372    
2373                                    Query q = session.createQuery(sql);
2374    
2375                                    QueryPos qPos = QueryPos.getInstance(q);
2376    
2377                                    if (format != null) {
2378                                            qPos.add(format);
2379                                    }
2380    
2381                                    count = (Long)q.uniqueResult();
2382    
2383                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2384                            }
2385                            catch (Exception e) {
2386                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2387    
2388                                    throw processException(e);
2389                            }
2390                            finally {
2391                                    closeSession(session);
2392                            }
2393                    }
2394    
2395                    return count.intValue();
2396            }
2397    
2398            private static final String _FINDER_COLUMN_FORMAT_FORMAT_1 = "wikiPage.format IS NULL";
2399            private static final String _FINDER_COLUMN_FORMAT_FORMAT_2 = "wikiPage.format = ?";
2400            private static final String _FINDER_COLUMN_FORMAT_FORMAT_3 = "(wikiPage.format IS NULL OR wikiPage.format = ?)";
2401            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2402                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2403                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_N",
2404                            new String[] {
2405                                    Long.class.getName(), Long.class.getName(),
2406                                    
2407                            Integer.class.getName(), Integer.class.getName(),
2408                                    OrderByComparator.class.getName()
2409                            });
2410            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2411                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2412                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_N",
2413                            new String[] { Long.class.getName(), Long.class.getName() },
2414                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
2415                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
2416                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
2417                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
2418            public static final FinderPath FINDER_PATH_COUNT_BY_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2419                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2420                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N",
2421                            new String[] { Long.class.getName(), Long.class.getName() });
2422    
2423            /**
2424             * Returns all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2425             *
2426             * @param resourcePrimKey the resource prim key
2427             * @param nodeId the node ID
2428             * @return the matching wiki pages
2429             * @throws SystemException if a system exception occurred
2430             */
2431            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId)
2432                    throws SystemException {
2433                    return findByR_N(resourcePrimKey, nodeId, QueryUtil.ALL_POS,
2434                            QueryUtil.ALL_POS, null);
2435            }
2436    
2437            /**
2438             * Returns a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2439             *
2440             * <p>
2441             * 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.
2442             * </p>
2443             *
2444             * @param resourcePrimKey the resource prim key
2445             * @param nodeId the node ID
2446             * @param start the lower bound of the range of wiki pages
2447             * @param end the upper bound of the range of wiki pages (not inclusive)
2448             * @return the range of matching wiki pages
2449             * @throws SystemException if a system exception occurred
2450             */
2451            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId,
2452                    int start, int end) throws SystemException {
2453                    return findByR_N(resourcePrimKey, nodeId, start, end, null);
2454            }
2455    
2456            /**
2457             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2458             *
2459             * <p>
2460             * 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.
2461             * </p>
2462             *
2463             * @param resourcePrimKey the resource prim key
2464             * @param nodeId the node ID
2465             * @param start the lower bound of the range of wiki pages
2466             * @param end the upper bound of the range of wiki pages (not inclusive)
2467             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2468             * @return the ordered range of matching wiki pages
2469             * @throws SystemException if a system exception occurred
2470             */
2471            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId,
2472                    int start, int end, OrderByComparator orderByComparator)
2473                    throws SystemException {
2474                    boolean pagination = true;
2475                    FinderPath finderPath = null;
2476                    Object[] finderArgs = null;
2477    
2478                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2479                                    (orderByComparator == null)) {
2480                            pagination = false;
2481                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N;
2482                            finderArgs = new Object[] { resourcePrimKey, nodeId };
2483                    }
2484                    else {
2485                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N;
2486                            finderArgs = new Object[] {
2487                                            resourcePrimKey, nodeId,
2488                                            
2489                                            start, end, orderByComparator
2490                                    };
2491                    }
2492    
2493                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
2494                                    finderArgs, this);
2495    
2496                    if ((list != null) && !list.isEmpty()) {
2497                            for (WikiPage wikiPage : list) {
2498                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
2499                                                    (nodeId != wikiPage.getNodeId())) {
2500                                            list = null;
2501    
2502                                            break;
2503                                    }
2504                            }
2505                    }
2506    
2507                    if (list == null) {
2508                            StringBundler query = null;
2509    
2510                            if (orderByComparator != null) {
2511                                    query = new StringBundler(4 +
2512                                                    (orderByComparator.getOrderByFields().length * 3));
2513                            }
2514                            else {
2515                                    query = new StringBundler(4);
2516                            }
2517    
2518                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2519    
2520                            query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
2521    
2522                            query.append(_FINDER_COLUMN_R_N_NODEID_2);
2523    
2524                            if (orderByComparator != null) {
2525                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2526                                            orderByComparator);
2527                            }
2528                            else
2529                             if (pagination) {
2530                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2531                            }
2532    
2533                            String sql = query.toString();
2534    
2535                            Session session = null;
2536    
2537                            try {
2538                                    session = openSession();
2539    
2540                                    Query q = session.createQuery(sql);
2541    
2542                                    QueryPos qPos = QueryPos.getInstance(q);
2543    
2544                                    qPos.add(resourcePrimKey);
2545    
2546                                    qPos.add(nodeId);
2547    
2548                                    if (!pagination) {
2549                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2550                                                            start, end, false);
2551    
2552                                            Collections.sort(list);
2553    
2554                                            list = new UnmodifiableList<WikiPage>(list);
2555                                    }
2556                                    else {
2557                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2558                                                            start, end);
2559                                    }
2560    
2561                                    cacheResult(list);
2562    
2563                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2564                            }
2565                            catch (Exception e) {
2566                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2567    
2568                                    throw processException(e);
2569                            }
2570                            finally {
2571                                    closeSession(session);
2572                            }
2573                    }
2574    
2575                    return list;
2576            }
2577    
2578            /**
2579             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2580             *
2581             * @param resourcePrimKey the resource prim key
2582             * @param nodeId the node ID
2583             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2584             * @return the first matching wiki page
2585             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2586             * @throws SystemException if a system exception occurred
2587             */
2588            public WikiPage findByR_N_First(long resourcePrimKey, long nodeId,
2589                    OrderByComparator orderByComparator)
2590                    throws NoSuchPageException, SystemException {
2591                    WikiPage wikiPage = fetchByR_N_First(resourcePrimKey, nodeId,
2592                                    orderByComparator);
2593    
2594                    if (wikiPage != null) {
2595                            return wikiPage;
2596                    }
2597    
2598                    StringBundler msg = new StringBundler(6);
2599    
2600                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2601    
2602                    msg.append("resourcePrimKey=");
2603                    msg.append(resourcePrimKey);
2604    
2605                    msg.append(", nodeId=");
2606                    msg.append(nodeId);
2607    
2608                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2609    
2610                    throw new NoSuchPageException(msg.toString());
2611            }
2612    
2613            /**
2614             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2615             *
2616             * @param resourcePrimKey the resource prim key
2617             * @param nodeId the node ID
2618             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2619             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
2620             * @throws SystemException if a system exception occurred
2621             */
2622            public WikiPage fetchByR_N_First(long resourcePrimKey, long nodeId,
2623                    OrderByComparator orderByComparator) throws SystemException {
2624                    List<WikiPage> list = findByR_N(resourcePrimKey, nodeId, 0, 1,
2625                                    orderByComparator);
2626    
2627                    if (!list.isEmpty()) {
2628                            return list.get(0);
2629                    }
2630    
2631                    return null;
2632            }
2633    
2634            /**
2635             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2636             *
2637             * @param resourcePrimKey the resource prim key
2638             * @param nodeId the node ID
2639             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2640             * @return the last matching wiki page
2641             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2642             * @throws SystemException if a system exception occurred
2643             */
2644            public WikiPage findByR_N_Last(long resourcePrimKey, long nodeId,
2645                    OrderByComparator orderByComparator)
2646                    throws NoSuchPageException, SystemException {
2647                    WikiPage wikiPage = fetchByR_N_Last(resourcePrimKey, nodeId,
2648                                    orderByComparator);
2649    
2650                    if (wikiPage != null) {
2651                            return wikiPage;
2652                    }
2653    
2654                    StringBundler msg = new StringBundler(6);
2655    
2656                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2657    
2658                    msg.append("resourcePrimKey=");
2659                    msg.append(resourcePrimKey);
2660    
2661                    msg.append(", nodeId=");
2662                    msg.append(nodeId);
2663    
2664                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2665    
2666                    throw new NoSuchPageException(msg.toString());
2667            }
2668    
2669            /**
2670             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2671             *
2672             * @param resourcePrimKey the resource prim key
2673             * @param nodeId the node ID
2674             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2675             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
2676             * @throws SystemException if a system exception occurred
2677             */
2678            public WikiPage fetchByR_N_Last(long resourcePrimKey, long nodeId,
2679                    OrderByComparator orderByComparator) throws SystemException {
2680                    int count = countByR_N(resourcePrimKey, nodeId);
2681    
2682                    List<WikiPage> list = findByR_N(resourcePrimKey, nodeId, count - 1,
2683                                    count, orderByComparator);
2684    
2685                    if (!list.isEmpty()) {
2686                            return list.get(0);
2687                    }
2688    
2689                    return null;
2690            }
2691    
2692            /**
2693             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
2694             *
2695             * @param pageId the primary key of the current wiki page
2696             * @param resourcePrimKey the resource prim key
2697             * @param nodeId the node ID
2698             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2699             * @return the previous, current, and next wiki page
2700             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
2701             * @throws SystemException if a system exception occurred
2702             */
2703            public WikiPage[] findByR_N_PrevAndNext(long pageId, long resourcePrimKey,
2704                    long nodeId, OrderByComparator orderByComparator)
2705                    throws NoSuchPageException, SystemException {
2706                    WikiPage wikiPage = findByPrimaryKey(pageId);
2707    
2708                    Session session = null;
2709    
2710                    try {
2711                            session = openSession();
2712    
2713                            WikiPage[] array = new WikiPageImpl[3];
2714    
2715                            array[0] = getByR_N_PrevAndNext(session, wikiPage, resourcePrimKey,
2716                                            nodeId, orderByComparator, true);
2717    
2718                            array[1] = wikiPage;
2719    
2720                            array[2] = getByR_N_PrevAndNext(session, wikiPage, resourcePrimKey,
2721                                            nodeId, orderByComparator, false);
2722    
2723                            return array;
2724                    }
2725                    catch (Exception e) {
2726                            throw processException(e);
2727                    }
2728                    finally {
2729                            closeSession(session);
2730                    }
2731            }
2732    
2733            protected WikiPage getByR_N_PrevAndNext(Session session, WikiPage wikiPage,
2734                    long resourcePrimKey, long nodeId, OrderByComparator orderByComparator,
2735                    boolean previous) {
2736                    StringBundler query = null;
2737    
2738                    if (orderByComparator != null) {
2739                            query = new StringBundler(6 +
2740                                            (orderByComparator.getOrderByFields().length * 6));
2741                    }
2742                    else {
2743                            query = new StringBundler(3);
2744                    }
2745    
2746                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2747    
2748                    query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
2749    
2750                    query.append(_FINDER_COLUMN_R_N_NODEID_2);
2751    
2752                    if (orderByComparator != null) {
2753                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2754    
2755                            if (orderByConditionFields.length > 0) {
2756                                    query.append(WHERE_AND);
2757                            }
2758    
2759                            for (int i = 0; i < orderByConditionFields.length; i++) {
2760                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2761                                    query.append(orderByConditionFields[i]);
2762    
2763                                    if ((i + 1) < orderByConditionFields.length) {
2764                                            if (orderByComparator.isAscending() ^ previous) {
2765                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2766                                            }
2767                                            else {
2768                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2769                                            }
2770                                    }
2771                                    else {
2772                                            if (orderByComparator.isAscending() ^ previous) {
2773                                                    query.append(WHERE_GREATER_THAN);
2774                                            }
2775                                            else {
2776                                                    query.append(WHERE_LESSER_THAN);
2777                                            }
2778                                    }
2779                            }
2780    
2781                            query.append(ORDER_BY_CLAUSE);
2782    
2783                            String[] orderByFields = orderByComparator.getOrderByFields();
2784    
2785                            for (int i = 0; i < orderByFields.length; i++) {
2786                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2787                                    query.append(orderByFields[i]);
2788    
2789                                    if ((i + 1) < orderByFields.length) {
2790                                            if (orderByComparator.isAscending() ^ previous) {
2791                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2792                                            }
2793                                            else {
2794                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2795                                            }
2796                                    }
2797                                    else {
2798                                            if (orderByComparator.isAscending() ^ previous) {
2799                                                    query.append(ORDER_BY_ASC);
2800                                            }
2801                                            else {
2802                                                    query.append(ORDER_BY_DESC);
2803                                            }
2804                                    }
2805                            }
2806                    }
2807                    else {
2808                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2809                    }
2810    
2811                    String sql = query.toString();
2812    
2813                    Query q = session.createQuery(sql);
2814    
2815                    q.setFirstResult(0);
2816                    q.setMaxResults(2);
2817    
2818                    QueryPos qPos = QueryPos.getInstance(q);
2819    
2820                    qPos.add(resourcePrimKey);
2821    
2822                    qPos.add(nodeId);
2823    
2824                    if (orderByComparator != null) {
2825                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
2826    
2827                            for (Object value : values) {
2828                                    qPos.add(value);
2829                            }
2830                    }
2831    
2832                    List<WikiPage> list = q.list();
2833    
2834                    if (list.size() == 2) {
2835                            return list.get(1);
2836                    }
2837                    else {
2838                            return null;
2839                    }
2840            }
2841    
2842            /**
2843             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; from the database.
2844             *
2845             * @param resourcePrimKey the resource prim key
2846             * @param nodeId the node ID
2847             * @throws SystemException if a system exception occurred
2848             */
2849            public void removeByR_N(long resourcePrimKey, long nodeId)
2850                    throws SystemException {
2851                    for (WikiPage wikiPage : findByR_N(resourcePrimKey, nodeId,
2852                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2853                            remove(wikiPage);
2854                    }
2855            }
2856    
2857            /**
2858             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
2859             *
2860             * @param resourcePrimKey the resource prim key
2861             * @param nodeId the node ID
2862             * @return the number of matching wiki pages
2863             * @throws SystemException if a system exception occurred
2864             */
2865            public int countByR_N(long resourcePrimKey, long nodeId)
2866                    throws SystemException {
2867                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N;
2868    
2869                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId };
2870    
2871                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2872                                    this);
2873    
2874                    if (count == null) {
2875                            StringBundler query = new StringBundler(3);
2876    
2877                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
2878    
2879                            query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
2880    
2881                            query.append(_FINDER_COLUMN_R_N_NODEID_2);
2882    
2883                            String sql = query.toString();
2884    
2885                            Session session = null;
2886    
2887                            try {
2888                                    session = openSession();
2889    
2890                                    Query q = session.createQuery(sql);
2891    
2892                                    QueryPos qPos = QueryPos.getInstance(q);
2893    
2894                                    qPos.add(resourcePrimKey);
2895    
2896                                    qPos.add(nodeId);
2897    
2898                                    count = (Long)q.uniqueResult();
2899    
2900                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2901                            }
2902                            catch (Exception e) {
2903                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2904    
2905                                    throw processException(e);
2906                            }
2907                            finally {
2908                                    closeSession(session);
2909                            }
2910                    }
2911    
2912                    return count.intValue();
2913            }
2914    
2915            private static final String _FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
2916            private static final String _FINDER_COLUMN_R_N_NODEID_2 = "wikiPage.nodeId = ?";
2917            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2918                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2919                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_T",
2920                            new String[] {
2921                                    Long.class.getName(), String.class.getName(),
2922                                    
2923                            Integer.class.getName(), Integer.class.getName(),
2924                                    OrderByComparator.class.getName()
2925                            });
2926            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2927                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2928                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_T",
2929                            new String[] { Long.class.getName(), String.class.getName() },
2930                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
2931                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
2932                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
2933            public static final FinderPath FINDER_PATH_COUNT_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2934                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2935                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T",
2936                            new String[] { Long.class.getName(), String.class.getName() });
2937    
2938            /**
2939             * Returns all the wiki pages where nodeId = &#63; and title = &#63;.
2940             *
2941             * @param nodeId the node ID
2942             * @param title the title
2943             * @return the matching wiki pages
2944             * @throws SystemException if a system exception occurred
2945             */
2946            public List<WikiPage> findByN_T(long nodeId, String title)
2947                    throws SystemException {
2948                    return findByN_T(nodeId, title, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2949                            null);
2950            }
2951    
2952            /**
2953             * Returns a range of all the wiki pages where nodeId = &#63; and title = &#63;.
2954             *
2955             * <p>
2956             * 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.
2957             * </p>
2958             *
2959             * @param nodeId the node ID
2960             * @param title the title
2961             * @param start the lower bound of the range of wiki pages
2962             * @param end the upper bound of the range of wiki pages (not inclusive)
2963             * @return the range of matching wiki pages
2964             * @throws SystemException if a system exception occurred
2965             */
2966            public List<WikiPage> findByN_T(long nodeId, String title, int start,
2967                    int end) throws SystemException {
2968                    return findByN_T(nodeId, title, start, end, null);
2969            }
2970    
2971            /**
2972             * Returns an ordered range of all the wiki pages where nodeId = &#63; and title = &#63;.
2973             *
2974             * <p>
2975             * 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.
2976             * </p>
2977             *
2978             * @param nodeId the node ID
2979             * @param title the title
2980             * @param start the lower bound of the range of wiki pages
2981             * @param end the upper bound of the range of wiki pages (not inclusive)
2982             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2983             * @return the ordered range of matching wiki pages
2984             * @throws SystemException if a system exception occurred
2985             */
2986            public List<WikiPage> findByN_T(long nodeId, String title, int start,
2987                    int end, OrderByComparator orderByComparator) throws SystemException {
2988                    boolean pagination = true;
2989                    FinderPath finderPath = null;
2990                    Object[] finderArgs = null;
2991    
2992                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2993                                    (orderByComparator == null)) {
2994                            pagination = false;
2995                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T;
2996                            finderArgs = new Object[] { nodeId, title };
2997                    }
2998                    else {
2999                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T;
3000                            finderArgs = new Object[] {
3001                                            nodeId, title,
3002                                            
3003                                            start, end, orderByComparator
3004                                    };
3005                    }
3006    
3007                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
3008                                    finderArgs, this);
3009    
3010                    if ((list != null) && !list.isEmpty()) {
3011                            for (WikiPage wikiPage : list) {
3012                                    if ((nodeId != wikiPage.getNodeId()) ||
3013                                                    !Validator.equals(title, wikiPage.getTitle())) {
3014                                            list = null;
3015    
3016                                            break;
3017                                    }
3018                            }
3019                    }
3020    
3021                    if (list == null) {
3022                            StringBundler query = null;
3023    
3024                            if (orderByComparator != null) {
3025                                    query = new StringBundler(4 +
3026                                                    (orderByComparator.getOrderByFields().length * 3));
3027                            }
3028                            else {
3029                                    query = new StringBundler(4);
3030                            }
3031    
3032                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3033    
3034                            query.append(_FINDER_COLUMN_N_T_NODEID_2);
3035    
3036                            if (title == null) {
3037                                    query.append(_FINDER_COLUMN_N_T_TITLE_1);
3038                            }
3039                            else {
3040                                    if (title.equals(StringPool.BLANK)) {
3041                                            query.append(_FINDER_COLUMN_N_T_TITLE_3);
3042                                    }
3043                                    else {
3044                                            query.append(_FINDER_COLUMN_N_T_TITLE_2);
3045                                    }
3046                            }
3047    
3048                            if (orderByComparator != null) {
3049                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3050                                            orderByComparator);
3051                            }
3052                            else
3053                             if (pagination) {
3054                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3055                            }
3056    
3057                            String sql = query.toString();
3058    
3059                            Session session = null;
3060    
3061                            try {
3062                                    session = openSession();
3063    
3064                                    Query q = session.createQuery(sql);
3065    
3066                                    QueryPos qPos = QueryPos.getInstance(q);
3067    
3068                                    qPos.add(nodeId);
3069    
3070                                    if (title != null) {
3071                                            qPos.add(title);
3072                                    }
3073    
3074                                    if (!pagination) {
3075                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3076                                                            start, end, false);
3077    
3078                                            Collections.sort(list);
3079    
3080                                            list = new UnmodifiableList<WikiPage>(list);
3081                                    }
3082                                    else {
3083                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3084                                                            start, end);
3085                                    }
3086    
3087                                    cacheResult(list);
3088    
3089                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3090                            }
3091                            catch (Exception e) {
3092                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3093    
3094                                    throw processException(e);
3095                            }
3096                            finally {
3097                                    closeSession(session);
3098                            }
3099                    }
3100    
3101                    return list;
3102            }
3103    
3104            /**
3105             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3106             *
3107             * @param nodeId the node ID
3108             * @param title the title
3109             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3110             * @return the first matching wiki page
3111             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3112             * @throws SystemException if a system exception occurred
3113             */
3114            public WikiPage findByN_T_First(long nodeId, String title,
3115                    OrderByComparator orderByComparator)
3116                    throws NoSuchPageException, SystemException {
3117                    WikiPage wikiPage = fetchByN_T_First(nodeId, title, orderByComparator);
3118    
3119                    if (wikiPage != null) {
3120                            return wikiPage;
3121                    }
3122    
3123                    StringBundler msg = new StringBundler(6);
3124    
3125                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3126    
3127                    msg.append("nodeId=");
3128                    msg.append(nodeId);
3129    
3130                    msg.append(", title=");
3131                    msg.append(title);
3132    
3133                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3134    
3135                    throw new NoSuchPageException(msg.toString());
3136            }
3137    
3138            /**
3139             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3140             *
3141             * @param nodeId the node ID
3142             * @param title the title
3143             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3144             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
3145             * @throws SystemException if a system exception occurred
3146             */
3147            public WikiPage fetchByN_T_First(long nodeId, String title,
3148                    OrderByComparator orderByComparator) throws SystemException {
3149                    List<WikiPage> list = findByN_T(nodeId, title, 0, 1, orderByComparator);
3150    
3151                    if (!list.isEmpty()) {
3152                            return list.get(0);
3153                    }
3154    
3155                    return null;
3156            }
3157    
3158            /**
3159             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3160             *
3161             * @param nodeId the node ID
3162             * @param title the title
3163             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3164             * @return the last matching wiki page
3165             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3166             * @throws SystemException if a system exception occurred
3167             */
3168            public WikiPage findByN_T_Last(long nodeId, String title,
3169                    OrderByComparator orderByComparator)
3170                    throws NoSuchPageException, SystemException {
3171                    WikiPage wikiPage = fetchByN_T_Last(nodeId, title, orderByComparator);
3172    
3173                    if (wikiPage != null) {
3174                            return wikiPage;
3175                    }
3176    
3177                    StringBundler msg = new StringBundler(6);
3178    
3179                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3180    
3181                    msg.append("nodeId=");
3182                    msg.append(nodeId);
3183    
3184                    msg.append(", title=");
3185                    msg.append(title);
3186    
3187                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3188    
3189                    throw new NoSuchPageException(msg.toString());
3190            }
3191    
3192            /**
3193             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3194             *
3195             * @param nodeId the node ID
3196             * @param title the title
3197             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3198             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
3199             * @throws SystemException if a system exception occurred
3200             */
3201            public WikiPage fetchByN_T_Last(long nodeId, String title,
3202                    OrderByComparator orderByComparator) throws SystemException {
3203                    int count = countByN_T(nodeId, title);
3204    
3205                    List<WikiPage> list = findByN_T(nodeId, title, count - 1, count,
3206                                    orderByComparator);
3207    
3208                    if (!list.isEmpty()) {
3209                            return list.get(0);
3210                    }
3211    
3212                    return null;
3213            }
3214    
3215            /**
3216             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63;.
3217             *
3218             * @param pageId the primary key of the current wiki page
3219             * @param nodeId the node ID
3220             * @param title the title
3221             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3222             * @return the previous, current, and next wiki page
3223             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
3224             * @throws SystemException if a system exception occurred
3225             */
3226            public WikiPage[] findByN_T_PrevAndNext(long pageId, long nodeId,
3227                    String title, OrderByComparator orderByComparator)
3228                    throws NoSuchPageException, SystemException {
3229                    WikiPage wikiPage = findByPrimaryKey(pageId);
3230    
3231                    Session session = null;
3232    
3233                    try {
3234                            session = openSession();
3235    
3236                            WikiPage[] array = new WikiPageImpl[3];
3237    
3238                            array[0] = getByN_T_PrevAndNext(session, wikiPage, nodeId, title,
3239                                            orderByComparator, true);
3240    
3241                            array[1] = wikiPage;
3242    
3243                            array[2] = getByN_T_PrevAndNext(session, wikiPage, nodeId, title,
3244                                            orderByComparator, false);
3245    
3246                            return array;
3247                    }
3248                    catch (Exception e) {
3249                            throw processException(e);
3250                    }
3251                    finally {
3252                            closeSession(session);
3253                    }
3254            }
3255    
3256            protected WikiPage getByN_T_PrevAndNext(Session session, WikiPage wikiPage,
3257                    long nodeId, String title, OrderByComparator orderByComparator,
3258                    boolean previous) {
3259                    StringBundler query = null;
3260    
3261                    if (orderByComparator != null) {
3262                            query = new StringBundler(6 +
3263                                            (orderByComparator.getOrderByFields().length * 6));
3264                    }
3265                    else {
3266                            query = new StringBundler(3);
3267                    }
3268    
3269                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3270    
3271                    query.append(_FINDER_COLUMN_N_T_NODEID_2);
3272    
3273                    if (title == null) {
3274                            query.append(_FINDER_COLUMN_N_T_TITLE_1);
3275                    }
3276                    else {
3277                            if (title.equals(StringPool.BLANK)) {
3278                                    query.append(_FINDER_COLUMN_N_T_TITLE_3);
3279                            }
3280                            else {
3281                                    query.append(_FINDER_COLUMN_N_T_TITLE_2);
3282                            }
3283                    }
3284    
3285                    if (orderByComparator != null) {
3286                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3287    
3288                            if (orderByConditionFields.length > 0) {
3289                                    query.append(WHERE_AND);
3290                            }
3291    
3292                            for (int i = 0; i < orderByConditionFields.length; i++) {
3293                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3294                                    query.append(orderByConditionFields[i]);
3295    
3296                                    if ((i + 1) < orderByConditionFields.length) {
3297                                            if (orderByComparator.isAscending() ^ previous) {
3298                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3299                                            }
3300                                            else {
3301                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3302                                            }
3303                                    }
3304                                    else {
3305                                            if (orderByComparator.isAscending() ^ previous) {
3306                                                    query.append(WHERE_GREATER_THAN);
3307                                            }
3308                                            else {
3309                                                    query.append(WHERE_LESSER_THAN);
3310                                            }
3311                                    }
3312                            }
3313    
3314                            query.append(ORDER_BY_CLAUSE);
3315    
3316                            String[] orderByFields = orderByComparator.getOrderByFields();
3317    
3318                            for (int i = 0; i < orderByFields.length; i++) {
3319                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3320                                    query.append(orderByFields[i]);
3321    
3322                                    if ((i + 1) < orderByFields.length) {
3323                                            if (orderByComparator.isAscending() ^ previous) {
3324                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3325                                            }
3326                                            else {
3327                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3328                                            }
3329                                    }
3330                                    else {
3331                                            if (orderByComparator.isAscending() ^ previous) {
3332                                                    query.append(ORDER_BY_ASC);
3333                                            }
3334                                            else {
3335                                                    query.append(ORDER_BY_DESC);
3336                                            }
3337                                    }
3338                            }
3339                    }
3340                    else {
3341                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3342                    }
3343    
3344                    String sql = query.toString();
3345    
3346                    Query q = session.createQuery(sql);
3347    
3348                    q.setFirstResult(0);
3349                    q.setMaxResults(2);
3350    
3351                    QueryPos qPos = QueryPos.getInstance(q);
3352    
3353                    qPos.add(nodeId);
3354    
3355                    if (title != null) {
3356                            qPos.add(title);
3357                    }
3358    
3359                    if (orderByComparator != null) {
3360                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
3361    
3362                            for (Object value : values) {
3363                                    qPos.add(value);
3364                            }
3365                    }
3366    
3367                    List<WikiPage> list = q.list();
3368    
3369                    if (list.size() == 2) {
3370                            return list.get(1);
3371                    }
3372                    else {
3373                            return null;
3374                    }
3375            }
3376    
3377            /**
3378             * Removes all the wiki pages where nodeId = &#63; and title = &#63; from the database.
3379             *
3380             * @param nodeId the node ID
3381             * @param title the title
3382             * @throws SystemException if a system exception occurred
3383             */
3384            public void removeByN_T(long nodeId, String title)
3385                    throws SystemException {
3386                    for (WikiPage wikiPage : findByN_T(nodeId, title, QueryUtil.ALL_POS,
3387                                    QueryUtil.ALL_POS, null)) {
3388                            remove(wikiPage);
3389                    }
3390            }
3391    
3392            /**
3393             * Returns the number of wiki pages where nodeId = &#63; and title = &#63;.
3394             *
3395             * @param nodeId the node ID
3396             * @param title the title
3397             * @return the number of matching wiki pages
3398             * @throws SystemException if a system exception occurred
3399             */
3400            public int countByN_T(long nodeId, String title) throws SystemException {
3401                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T;
3402    
3403                    Object[] finderArgs = new Object[] { nodeId, title };
3404    
3405                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3406                                    this);
3407    
3408                    if (count == null) {
3409                            StringBundler query = new StringBundler(3);
3410    
3411                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
3412    
3413                            query.append(_FINDER_COLUMN_N_T_NODEID_2);
3414    
3415                            if (title == null) {
3416                                    query.append(_FINDER_COLUMN_N_T_TITLE_1);
3417                            }
3418                            else {
3419                                    if (title.equals(StringPool.BLANK)) {
3420                                            query.append(_FINDER_COLUMN_N_T_TITLE_3);
3421                                    }
3422                                    else {
3423                                            query.append(_FINDER_COLUMN_N_T_TITLE_2);
3424                                    }
3425                            }
3426    
3427                            String sql = query.toString();
3428    
3429                            Session session = null;
3430    
3431                            try {
3432                                    session = openSession();
3433    
3434                                    Query q = session.createQuery(sql);
3435    
3436                                    QueryPos qPos = QueryPos.getInstance(q);
3437    
3438                                    qPos.add(nodeId);
3439    
3440                                    if (title != null) {
3441                                            qPos.add(title);
3442                                    }
3443    
3444                                    count = (Long)q.uniqueResult();
3445    
3446                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3447                            }
3448                            catch (Exception e) {
3449                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3450    
3451                                    throw processException(e);
3452                            }
3453                            finally {
3454                                    closeSession(session);
3455                            }
3456                    }
3457    
3458                    return count.intValue();
3459            }
3460    
3461            private static final String _FINDER_COLUMN_N_T_NODEID_2 = "wikiPage.nodeId = ? AND ";
3462            private static final String _FINDER_COLUMN_N_T_TITLE_1 = "wikiPage.title IS NULL";
3463            private static final String _FINDER_COLUMN_N_T_TITLE_2 = "lower(wikiPage.title) = lower(CAST_TEXT(?))";
3464            private static final String _FINDER_COLUMN_N_T_TITLE_3 = "(wikiPage.title IS NULL OR lower(wikiPage.title) = lower(CAST_TEXT(?)))";
3465            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3466                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
3467                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H",
3468                            new String[] {
3469                                    Long.class.getName(), Boolean.class.getName(),
3470                                    
3471                            Integer.class.getName(), Integer.class.getName(),
3472                                    OrderByComparator.class.getName()
3473                            });
3474            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3475                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
3476                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H",
3477                            new String[] { Long.class.getName(), Boolean.class.getName() },
3478                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
3479                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
3480                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
3481                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
3482            public static final FinderPath FINDER_PATH_COUNT_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3483                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3484                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H",
3485                            new String[] { Long.class.getName(), Boolean.class.getName() });
3486    
3487            /**
3488             * Returns all the wiki pages where nodeId = &#63; and head = &#63;.
3489             *
3490             * @param nodeId the node ID
3491             * @param head the head
3492             * @return the matching wiki pages
3493             * @throws SystemException if a system exception occurred
3494             */
3495            public List<WikiPage> findByN_H(long nodeId, boolean head)
3496                    throws SystemException {
3497                    return findByN_H(nodeId, head, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3498                            null);
3499            }
3500    
3501            /**
3502             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63;.
3503             *
3504             * <p>
3505             * 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.
3506             * </p>
3507             *
3508             * @param nodeId the node ID
3509             * @param head the head
3510             * @param start the lower bound of the range of wiki pages
3511             * @param end the upper bound of the range of wiki pages (not inclusive)
3512             * @return the range of matching wiki pages
3513             * @throws SystemException if a system exception occurred
3514             */
3515            public List<WikiPage> findByN_H(long nodeId, boolean head, int start,
3516                    int end) throws SystemException {
3517                    return findByN_H(nodeId, head, start, end, null);
3518            }
3519    
3520            /**
3521             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63;.
3522             *
3523             * <p>
3524             * 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.
3525             * </p>
3526             *
3527             * @param nodeId the node ID
3528             * @param head the head
3529             * @param start the lower bound of the range of wiki pages
3530             * @param end the upper bound of the range of wiki pages (not inclusive)
3531             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3532             * @return the ordered range of matching wiki pages
3533             * @throws SystemException if a system exception occurred
3534             */
3535            public List<WikiPage> findByN_H(long nodeId, boolean head, int start,
3536                    int end, OrderByComparator orderByComparator) throws SystemException {
3537                    boolean pagination = true;
3538                    FinderPath finderPath = null;
3539                    Object[] finderArgs = null;
3540    
3541                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3542                                    (orderByComparator == null)) {
3543                            pagination = false;
3544                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H;
3545                            finderArgs = new Object[] { nodeId, head };
3546                    }
3547                    else {
3548                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H;
3549                            finderArgs = new Object[] {
3550                                            nodeId, head,
3551                                            
3552                                            start, end, orderByComparator
3553                                    };
3554                    }
3555    
3556                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
3557                                    finderArgs, this);
3558    
3559                    if ((list != null) && !list.isEmpty()) {
3560                            for (WikiPage wikiPage : list) {
3561                                    if ((nodeId != wikiPage.getNodeId()) ||
3562                                                    (head != wikiPage.getHead())) {
3563                                            list = null;
3564    
3565                                            break;
3566                                    }
3567                            }
3568                    }
3569    
3570                    if (list == null) {
3571                            StringBundler query = null;
3572    
3573                            if (orderByComparator != null) {
3574                                    query = new StringBundler(4 +
3575                                                    (orderByComparator.getOrderByFields().length * 3));
3576                            }
3577                            else {
3578                                    query = new StringBundler(4);
3579                            }
3580    
3581                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3582    
3583                            query.append(_FINDER_COLUMN_N_H_NODEID_2);
3584    
3585                            query.append(_FINDER_COLUMN_N_H_HEAD_2);
3586    
3587                            if (orderByComparator != null) {
3588                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3589                                            orderByComparator);
3590                            }
3591                            else
3592                             if (pagination) {
3593                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3594                            }
3595    
3596                            String sql = query.toString();
3597    
3598                            Session session = null;
3599    
3600                            try {
3601                                    session = openSession();
3602    
3603                                    Query q = session.createQuery(sql);
3604    
3605                                    QueryPos qPos = QueryPos.getInstance(q);
3606    
3607                                    qPos.add(nodeId);
3608    
3609                                    qPos.add(head);
3610    
3611                                    if (!pagination) {
3612                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3613                                                            start, end, false);
3614    
3615                                            Collections.sort(list);
3616    
3617                                            list = new UnmodifiableList<WikiPage>(list);
3618                                    }
3619                                    else {
3620                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3621                                                            start, end);
3622                                    }
3623    
3624                                    cacheResult(list);
3625    
3626                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3627                            }
3628                            catch (Exception e) {
3629                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3630    
3631                                    throw processException(e);
3632                            }
3633                            finally {
3634                                    closeSession(session);
3635                            }
3636                    }
3637    
3638                    return list;
3639            }
3640    
3641            /**
3642             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3643             *
3644             * @param nodeId the node ID
3645             * @param head the head
3646             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3647             * @return the first matching wiki page
3648             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3649             * @throws SystemException if a system exception occurred
3650             */
3651            public WikiPage findByN_H_First(long nodeId, boolean head,
3652                    OrderByComparator orderByComparator)
3653                    throws NoSuchPageException, SystemException {
3654                    WikiPage wikiPage = fetchByN_H_First(nodeId, head, orderByComparator);
3655    
3656                    if (wikiPage != null) {
3657                            return wikiPage;
3658                    }
3659    
3660                    StringBundler msg = new StringBundler(6);
3661    
3662                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3663    
3664                    msg.append("nodeId=");
3665                    msg.append(nodeId);
3666    
3667                    msg.append(", head=");
3668                    msg.append(head);
3669    
3670                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3671    
3672                    throw new NoSuchPageException(msg.toString());
3673            }
3674    
3675            /**
3676             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3677             *
3678             * @param nodeId the node ID
3679             * @param head the head
3680             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3681             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
3682             * @throws SystemException if a system exception occurred
3683             */
3684            public WikiPage fetchByN_H_First(long nodeId, boolean head,
3685                    OrderByComparator orderByComparator) throws SystemException {
3686                    List<WikiPage> list = findByN_H(nodeId, head, 0, 1, orderByComparator);
3687    
3688                    if (!list.isEmpty()) {
3689                            return list.get(0);
3690                    }
3691    
3692                    return null;
3693            }
3694    
3695            /**
3696             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3697             *
3698             * @param nodeId the node ID
3699             * @param head the head
3700             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3701             * @return the last matching wiki page
3702             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3703             * @throws SystemException if a system exception occurred
3704             */
3705            public WikiPage findByN_H_Last(long nodeId, boolean head,
3706                    OrderByComparator orderByComparator)
3707                    throws NoSuchPageException, SystemException {
3708                    WikiPage wikiPage = fetchByN_H_Last(nodeId, head, orderByComparator);
3709    
3710                    if (wikiPage != null) {
3711                            return wikiPage;
3712                    }
3713    
3714                    StringBundler msg = new StringBundler(6);
3715    
3716                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3717    
3718                    msg.append("nodeId=");
3719                    msg.append(nodeId);
3720    
3721                    msg.append(", head=");
3722                    msg.append(head);
3723    
3724                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3725    
3726                    throw new NoSuchPageException(msg.toString());
3727            }
3728    
3729            /**
3730             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3731             *
3732             * @param nodeId the node ID
3733             * @param head the head
3734             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3735             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
3736             * @throws SystemException if a system exception occurred
3737             */
3738            public WikiPage fetchByN_H_Last(long nodeId, boolean head,
3739                    OrderByComparator orderByComparator) throws SystemException {
3740                    int count = countByN_H(nodeId, head);
3741    
3742                    List<WikiPage> list = findByN_H(nodeId, head, count - 1, count,
3743                                    orderByComparator);
3744    
3745                    if (!list.isEmpty()) {
3746                            return list.get(0);
3747                    }
3748    
3749                    return null;
3750            }
3751    
3752            /**
3753             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63;.
3754             *
3755             * @param pageId the primary key of the current wiki page
3756             * @param nodeId the node ID
3757             * @param head the head
3758             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3759             * @return the previous, current, and next wiki page
3760             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
3761             * @throws SystemException if a system exception occurred
3762             */
3763            public WikiPage[] findByN_H_PrevAndNext(long pageId, long nodeId,
3764                    boolean head, OrderByComparator orderByComparator)
3765                    throws NoSuchPageException, SystemException {
3766                    WikiPage wikiPage = findByPrimaryKey(pageId);
3767    
3768                    Session session = null;
3769    
3770                    try {
3771                            session = openSession();
3772    
3773                            WikiPage[] array = new WikiPageImpl[3];
3774    
3775                            array[0] = getByN_H_PrevAndNext(session, wikiPage, nodeId, head,
3776                                            orderByComparator, true);
3777    
3778                            array[1] = wikiPage;
3779    
3780                            array[2] = getByN_H_PrevAndNext(session, wikiPage, nodeId, head,
3781                                            orderByComparator, false);
3782    
3783                            return array;
3784                    }
3785                    catch (Exception e) {
3786                            throw processException(e);
3787                    }
3788                    finally {
3789                            closeSession(session);
3790                    }
3791            }
3792    
3793            protected WikiPage getByN_H_PrevAndNext(Session session, WikiPage wikiPage,
3794                    long nodeId, boolean head, OrderByComparator orderByComparator,
3795                    boolean previous) {
3796                    StringBundler query = null;
3797    
3798                    if (orderByComparator != null) {
3799                            query = new StringBundler(6 +
3800                                            (orderByComparator.getOrderByFields().length * 6));
3801                    }
3802                    else {
3803                            query = new StringBundler(3);
3804                    }
3805    
3806                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3807    
3808                    query.append(_FINDER_COLUMN_N_H_NODEID_2);
3809    
3810                    query.append(_FINDER_COLUMN_N_H_HEAD_2);
3811    
3812                    if (orderByComparator != null) {
3813                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3814    
3815                            if (orderByConditionFields.length > 0) {
3816                                    query.append(WHERE_AND);
3817                            }
3818    
3819                            for (int i = 0; i < orderByConditionFields.length; i++) {
3820                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3821                                    query.append(orderByConditionFields[i]);
3822    
3823                                    if ((i + 1) < orderByConditionFields.length) {
3824                                            if (orderByComparator.isAscending() ^ previous) {
3825                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3826                                            }
3827                                            else {
3828                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3829                                            }
3830                                    }
3831                                    else {
3832                                            if (orderByComparator.isAscending() ^ previous) {
3833                                                    query.append(WHERE_GREATER_THAN);
3834                                            }
3835                                            else {
3836                                                    query.append(WHERE_LESSER_THAN);
3837                                            }
3838                                    }
3839                            }
3840    
3841                            query.append(ORDER_BY_CLAUSE);
3842    
3843                            String[] orderByFields = orderByComparator.getOrderByFields();
3844    
3845                            for (int i = 0; i < orderByFields.length; i++) {
3846                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3847                                    query.append(orderByFields[i]);
3848    
3849                                    if ((i + 1) < orderByFields.length) {
3850                                            if (orderByComparator.isAscending() ^ previous) {
3851                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3852                                            }
3853                                            else {
3854                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3855                                            }
3856                                    }
3857                                    else {
3858                                            if (orderByComparator.isAscending() ^ previous) {
3859                                                    query.append(ORDER_BY_ASC);
3860                                            }
3861                                            else {
3862                                                    query.append(ORDER_BY_DESC);
3863                                            }
3864                                    }
3865                            }
3866                    }
3867                    else {
3868                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3869                    }
3870    
3871                    String sql = query.toString();
3872    
3873                    Query q = session.createQuery(sql);
3874    
3875                    q.setFirstResult(0);
3876                    q.setMaxResults(2);
3877    
3878                    QueryPos qPos = QueryPos.getInstance(q);
3879    
3880                    qPos.add(nodeId);
3881    
3882                    qPos.add(head);
3883    
3884                    if (orderByComparator != null) {
3885                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
3886    
3887                            for (Object value : values) {
3888                                    qPos.add(value);
3889                            }
3890                    }
3891    
3892                    List<WikiPage> list = q.list();
3893    
3894                    if (list.size() == 2) {
3895                            return list.get(1);
3896                    }
3897                    else {
3898                            return null;
3899                    }
3900            }
3901    
3902            /**
3903             * Removes all the wiki pages where nodeId = &#63; and head = &#63; from the database.
3904             *
3905             * @param nodeId the node ID
3906             * @param head the head
3907             * @throws SystemException if a system exception occurred
3908             */
3909            public void removeByN_H(long nodeId, boolean head)
3910                    throws SystemException {
3911                    for (WikiPage wikiPage : findByN_H(nodeId, head, QueryUtil.ALL_POS,
3912                                    QueryUtil.ALL_POS, null)) {
3913                            remove(wikiPage);
3914                    }
3915            }
3916    
3917            /**
3918             * Returns the number of wiki pages where nodeId = &#63; and head = &#63;.
3919             *
3920             * @param nodeId the node ID
3921             * @param head the head
3922             * @return the number of matching wiki pages
3923             * @throws SystemException if a system exception occurred
3924             */
3925            public int countByN_H(long nodeId, boolean head) throws SystemException {
3926                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H;
3927    
3928                    Object[] finderArgs = new Object[] { nodeId, head };
3929    
3930                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3931                                    this);
3932    
3933                    if (count == null) {
3934                            StringBundler query = new StringBundler(3);
3935    
3936                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
3937    
3938                            query.append(_FINDER_COLUMN_N_H_NODEID_2);
3939    
3940                            query.append(_FINDER_COLUMN_N_H_HEAD_2);
3941    
3942                            String sql = query.toString();
3943    
3944                            Session session = null;
3945    
3946                            try {
3947                                    session = openSession();
3948    
3949                                    Query q = session.createQuery(sql);
3950    
3951                                    QueryPos qPos = QueryPos.getInstance(q);
3952    
3953                                    qPos.add(nodeId);
3954    
3955                                    qPos.add(head);
3956    
3957                                    count = (Long)q.uniqueResult();
3958    
3959                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3960                            }
3961                            catch (Exception e) {
3962                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3963    
3964                                    throw processException(e);
3965                            }
3966                            finally {
3967                                    closeSession(session);
3968                            }
3969                    }
3970    
3971                    return count.intValue();
3972            }
3973    
3974            private static final String _FINDER_COLUMN_N_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
3975            private static final String _FINDER_COLUMN_N_H_HEAD_2 = "wikiPage.head = ?";
3976            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3977                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
3978                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_P",
3979                            new String[] {
3980                                    Long.class.getName(), String.class.getName(),
3981                                    
3982                            Integer.class.getName(), Integer.class.getName(),
3983                                    OrderByComparator.class.getName()
3984                            });
3985            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3986                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
3987                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_P",
3988                            new String[] { Long.class.getName(), String.class.getName() },
3989                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
3990                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
3991                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
3992                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
3993            public static final FinderPath FINDER_PATH_COUNT_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3994                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3995                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_P",
3996                            new String[] { Long.class.getName(), String.class.getName() });
3997    
3998            /**
3999             * Returns all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
4000             *
4001             * @param nodeId the node ID
4002             * @param parentTitle the parent title
4003             * @return the matching wiki pages
4004             * @throws SystemException if a system exception occurred
4005             */
4006            public List<WikiPage> findByN_P(long nodeId, String parentTitle)
4007                    throws SystemException {
4008                    return findByN_P(nodeId, parentTitle, QueryUtil.ALL_POS,
4009                            QueryUtil.ALL_POS, null);
4010            }
4011    
4012            /**
4013             * Returns a range of all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
4014             *
4015             * <p>
4016             * 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.
4017             * </p>
4018             *
4019             * @param nodeId the node ID
4020             * @param parentTitle the parent title
4021             * @param start the lower bound of the range of wiki pages
4022             * @param end the upper bound of the range of wiki pages (not inclusive)
4023             * @return the range of matching wiki pages
4024             * @throws SystemException if a system exception occurred
4025             */
4026            public List<WikiPage> findByN_P(long nodeId, String parentTitle, int start,
4027                    int end) throws SystemException {
4028                    return findByN_P(nodeId, parentTitle, start, end, null);
4029            }
4030    
4031            /**
4032             * Returns an ordered range of all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
4033             *
4034             * <p>
4035             * 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.
4036             * </p>
4037             *
4038             * @param nodeId the node ID
4039             * @param parentTitle the parent title
4040             * @param start the lower bound of the range of wiki pages
4041             * @param end the upper bound of the range of wiki pages (not inclusive)
4042             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4043             * @return the ordered range of matching wiki pages
4044             * @throws SystemException if a system exception occurred
4045             */
4046            public List<WikiPage> findByN_P(long nodeId, String parentTitle, int start,
4047                    int end, OrderByComparator orderByComparator) throws SystemException {
4048                    boolean pagination = true;
4049                    FinderPath finderPath = null;
4050                    Object[] finderArgs = null;
4051    
4052                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4053                                    (orderByComparator == null)) {
4054                            pagination = false;
4055                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P;
4056                            finderArgs = new Object[] { nodeId, parentTitle };
4057                    }
4058                    else {
4059                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_P;
4060                            finderArgs = new Object[] {
4061                                            nodeId, parentTitle,
4062                                            
4063                                            start, end, orderByComparator
4064                                    };
4065                    }
4066    
4067                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
4068                                    finderArgs, this);
4069    
4070                    if ((list != null) && !list.isEmpty()) {
4071                            for (WikiPage wikiPage : list) {
4072                                    if ((nodeId != wikiPage.getNodeId()) ||
4073                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle())) {
4074                                            list = null;
4075    
4076                                            break;
4077                                    }
4078                            }
4079                    }
4080    
4081                    if (list == null) {
4082                            StringBundler query = null;
4083    
4084                            if (orderByComparator != null) {
4085                                    query = new StringBundler(4 +
4086                                                    (orderByComparator.getOrderByFields().length * 3));
4087                            }
4088                            else {
4089                                    query = new StringBundler(4);
4090                            }
4091    
4092                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4093    
4094                            query.append(_FINDER_COLUMN_N_P_NODEID_2);
4095    
4096                            if (parentTitle == null) {
4097                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
4098                            }
4099                            else {
4100                                    if (parentTitle.equals(StringPool.BLANK)) {
4101                                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
4102                                    }
4103                                    else {
4104                                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
4105                                    }
4106                            }
4107    
4108                            if (orderByComparator != null) {
4109                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4110                                            orderByComparator);
4111                            }
4112                            else
4113                             if (pagination) {
4114                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4115                            }
4116    
4117                            String sql = query.toString();
4118    
4119                            Session session = null;
4120    
4121                            try {
4122                                    session = openSession();
4123    
4124                                    Query q = session.createQuery(sql);
4125    
4126                                    QueryPos qPos = QueryPos.getInstance(q);
4127    
4128                                    qPos.add(nodeId);
4129    
4130                                    if (parentTitle != null) {
4131                                            qPos.add(parentTitle);
4132                                    }
4133    
4134                                    if (!pagination) {
4135                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4136                                                            start, end, false);
4137    
4138                                            Collections.sort(list);
4139    
4140                                            list = new UnmodifiableList<WikiPage>(list);
4141                                    }
4142                                    else {
4143                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4144                                                            start, end);
4145                                    }
4146    
4147                                    cacheResult(list);
4148    
4149                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4150                            }
4151                            catch (Exception e) {
4152                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4153    
4154                                    throw processException(e);
4155                            }
4156                            finally {
4157                                    closeSession(session);
4158                            }
4159                    }
4160    
4161                    return list;
4162            }
4163    
4164            /**
4165             * Returns the first wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4166             *
4167             * @param nodeId the node ID
4168             * @param parentTitle the parent title
4169             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4170             * @return the first matching wiki page
4171             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4172             * @throws SystemException if a system exception occurred
4173             */
4174            public WikiPage findByN_P_First(long nodeId, String parentTitle,
4175                    OrderByComparator orderByComparator)
4176                    throws NoSuchPageException, SystemException {
4177                    WikiPage wikiPage = fetchByN_P_First(nodeId, parentTitle,
4178                                    orderByComparator);
4179    
4180                    if (wikiPage != null) {
4181                            return wikiPage;
4182                    }
4183    
4184                    StringBundler msg = new StringBundler(6);
4185    
4186                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4187    
4188                    msg.append("nodeId=");
4189                    msg.append(nodeId);
4190    
4191                    msg.append(", parentTitle=");
4192                    msg.append(parentTitle);
4193    
4194                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4195    
4196                    throw new NoSuchPageException(msg.toString());
4197            }
4198    
4199            /**
4200             * Returns the first wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4201             *
4202             * @param nodeId the node ID
4203             * @param parentTitle the parent title
4204             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4205             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
4206             * @throws SystemException if a system exception occurred
4207             */
4208            public WikiPage fetchByN_P_First(long nodeId, String parentTitle,
4209                    OrderByComparator orderByComparator) throws SystemException {
4210                    List<WikiPage> list = findByN_P(nodeId, parentTitle, 0, 1,
4211                                    orderByComparator);
4212    
4213                    if (!list.isEmpty()) {
4214                            return list.get(0);
4215                    }
4216    
4217                    return null;
4218            }
4219    
4220            /**
4221             * Returns the last wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4222             *
4223             * @param nodeId the node ID
4224             * @param parentTitle the parent title
4225             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4226             * @return the last matching wiki page
4227             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4228             * @throws SystemException if a system exception occurred
4229             */
4230            public WikiPage findByN_P_Last(long nodeId, String parentTitle,
4231                    OrderByComparator orderByComparator)
4232                    throws NoSuchPageException, SystemException {
4233                    WikiPage wikiPage = fetchByN_P_Last(nodeId, parentTitle,
4234                                    orderByComparator);
4235    
4236                    if (wikiPage != null) {
4237                            return wikiPage;
4238                    }
4239    
4240                    StringBundler msg = new StringBundler(6);
4241    
4242                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4243    
4244                    msg.append("nodeId=");
4245                    msg.append(nodeId);
4246    
4247                    msg.append(", parentTitle=");
4248                    msg.append(parentTitle);
4249    
4250                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4251    
4252                    throw new NoSuchPageException(msg.toString());
4253            }
4254    
4255            /**
4256             * Returns the last wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4257             *
4258             * @param nodeId the node ID
4259             * @param parentTitle the parent title
4260             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4261             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
4262             * @throws SystemException if a system exception occurred
4263             */
4264            public WikiPage fetchByN_P_Last(long nodeId, String parentTitle,
4265                    OrderByComparator orderByComparator) throws SystemException {
4266                    int count = countByN_P(nodeId, parentTitle);
4267    
4268                    List<WikiPage> list = findByN_P(nodeId, parentTitle, count - 1, count,
4269                                    orderByComparator);
4270    
4271                    if (!list.isEmpty()) {
4272                            return list.get(0);
4273                    }
4274    
4275                    return null;
4276            }
4277    
4278            /**
4279             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
4280             *
4281             * @param pageId the primary key of the current wiki page
4282             * @param nodeId the node ID
4283             * @param parentTitle the parent title
4284             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4285             * @return the previous, current, and next wiki page
4286             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
4287             * @throws SystemException if a system exception occurred
4288             */
4289            public WikiPage[] findByN_P_PrevAndNext(long pageId, long nodeId,
4290                    String parentTitle, OrderByComparator orderByComparator)
4291                    throws NoSuchPageException, SystemException {
4292                    WikiPage wikiPage = findByPrimaryKey(pageId);
4293    
4294                    Session session = null;
4295    
4296                    try {
4297                            session = openSession();
4298    
4299                            WikiPage[] array = new WikiPageImpl[3];
4300    
4301                            array[0] = getByN_P_PrevAndNext(session, wikiPage, nodeId,
4302                                            parentTitle, orderByComparator, true);
4303    
4304                            array[1] = wikiPage;
4305    
4306                            array[2] = getByN_P_PrevAndNext(session, wikiPage, nodeId,
4307                                            parentTitle, orderByComparator, false);
4308    
4309                            return array;
4310                    }
4311                    catch (Exception e) {
4312                            throw processException(e);
4313                    }
4314                    finally {
4315                            closeSession(session);
4316                    }
4317            }
4318    
4319            protected WikiPage getByN_P_PrevAndNext(Session session, WikiPage wikiPage,
4320                    long nodeId, String parentTitle, OrderByComparator orderByComparator,
4321                    boolean previous) {
4322                    StringBundler query = null;
4323    
4324                    if (orderByComparator != null) {
4325                            query = new StringBundler(6 +
4326                                            (orderByComparator.getOrderByFields().length * 6));
4327                    }
4328                    else {
4329                            query = new StringBundler(3);
4330                    }
4331    
4332                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4333    
4334                    query.append(_FINDER_COLUMN_N_P_NODEID_2);
4335    
4336                    if (parentTitle == null) {
4337                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
4338                    }
4339                    else {
4340                            if (parentTitle.equals(StringPool.BLANK)) {
4341                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
4342                            }
4343                            else {
4344                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
4345                            }
4346                    }
4347    
4348                    if (orderByComparator != null) {
4349                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4350    
4351                            if (orderByConditionFields.length > 0) {
4352                                    query.append(WHERE_AND);
4353                            }
4354    
4355                            for (int i = 0; i < orderByConditionFields.length; i++) {
4356                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4357                                    query.append(orderByConditionFields[i]);
4358    
4359                                    if ((i + 1) < orderByConditionFields.length) {
4360                                            if (orderByComparator.isAscending() ^ previous) {
4361                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4362                                            }
4363                                            else {
4364                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4365                                            }
4366                                    }
4367                                    else {
4368                                            if (orderByComparator.isAscending() ^ previous) {
4369                                                    query.append(WHERE_GREATER_THAN);
4370                                            }
4371                                            else {
4372                                                    query.append(WHERE_LESSER_THAN);
4373                                            }
4374                                    }
4375                            }
4376    
4377                            query.append(ORDER_BY_CLAUSE);
4378    
4379                            String[] orderByFields = orderByComparator.getOrderByFields();
4380    
4381                            for (int i = 0; i < orderByFields.length; i++) {
4382                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4383                                    query.append(orderByFields[i]);
4384    
4385                                    if ((i + 1) < orderByFields.length) {
4386                                            if (orderByComparator.isAscending() ^ previous) {
4387                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4388                                            }
4389                                            else {
4390                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4391                                            }
4392                                    }
4393                                    else {
4394                                            if (orderByComparator.isAscending() ^ previous) {
4395                                                    query.append(ORDER_BY_ASC);
4396                                            }
4397                                            else {
4398                                                    query.append(ORDER_BY_DESC);
4399                                            }
4400                                    }
4401                            }
4402                    }
4403                    else {
4404                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4405                    }
4406    
4407                    String sql = query.toString();
4408    
4409                    Query q = session.createQuery(sql);
4410    
4411                    q.setFirstResult(0);
4412                    q.setMaxResults(2);
4413    
4414                    QueryPos qPos = QueryPos.getInstance(q);
4415    
4416                    qPos.add(nodeId);
4417    
4418                    if (parentTitle != null) {
4419                            qPos.add(parentTitle);
4420                    }
4421    
4422                    if (orderByComparator != null) {
4423                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
4424    
4425                            for (Object value : values) {
4426                                    qPos.add(value);
4427                            }
4428                    }
4429    
4430                    List<WikiPage> list = q.list();
4431    
4432                    if (list.size() == 2) {
4433                            return list.get(1);
4434                    }
4435                    else {
4436                            return null;
4437                    }
4438            }
4439    
4440            /**
4441             * Removes all the wiki pages where nodeId = &#63; and parentTitle = &#63; from the database.
4442             *
4443             * @param nodeId the node ID
4444             * @param parentTitle the parent title
4445             * @throws SystemException if a system exception occurred
4446             */
4447            public void removeByN_P(long nodeId, String parentTitle)
4448                    throws SystemException {
4449                    for (WikiPage wikiPage : findByN_P(nodeId, parentTitle,
4450                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4451                            remove(wikiPage);
4452                    }
4453            }
4454    
4455            /**
4456             * Returns the number of wiki pages where nodeId = &#63; and parentTitle = &#63;.
4457             *
4458             * @param nodeId the node ID
4459             * @param parentTitle the parent title
4460             * @return the number of matching wiki pages
4461             * @throws SystemException if a system exception occurred
4462             */
4463            public int countByN_P(long nodeId, String parentTitle)
4464                    throws SystemException {
4465                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_P;
4466    
4467                    Object[] finderArgs = new Object[] { nodeId, parentTitle };
4468    
4469                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4470                                    this);
4471    
4472                    if (count == null) {
4473                            StringBundler query = new StringBundler(3);
4474    
4475                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
4476    
4477                            query.append(_FINDER_COLUMN_N_P_NODEID_2);
4478    
4479                            if (parentTitle == null) {
4480                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
4481                            }
4482                            else {
4483                                    if (parentTitle.equals(StringPool.BLANK)) {
4484                                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
4485                                    }
4486                                    else {
4487                                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
4488                                    }
4489                            }
4490    
4491                            String sql = query.toString();
4492    
4493                            Session session = null;
4494    
4495                            try {
4496                                    session = openSession();
4497    
4498                                    Query q = session.createQuery(sql);
4499    
4500                                    QueryPos qPos = QueryPos.getInstance(q);
4501    
4502                                    qPos.add(nodeId);
4503    
4504                                    if (parentTitle != null) {
4505                                            qPos.add(parentTitle);
4506                                    }
4507    
4508                                    count = (Long)q.uniqueResult();
4509    
4510                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4511                            }
4512                            catch (Exception e) {
4513                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4514    
4515                                    throw processException(e);
4516                            }
4517                            finally {
4518                                    closeSession(session);
4519                            }
4520                    }
4521    
4522                    return count.intValue();
4523            }
4524    
4525            private static final String _FINDER_COLUMN_N_P_NODEID_2 = "wikiPage.nodeId = ? AND ";
4526            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL";
4527            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = lower(CAST_TEXT(?))";
4528            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR lower(wikiPage.parentTitle) = lower(CAST_TEXT(?)))";
4529            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4530                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4531                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_R",
4532                            new String[] {
4533                                    Long.class.getName(), String.class.getName(),
4534                                    
4535                            Integer.class.getName(), Integer.class.getName(),
4536                                    OrderByComparator.class.getName()
4537                            });
4538            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4539                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4540                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_R",
4541                            new String[] { Long.class.getName(), String.class.getName() },
4542                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
4543                            WikiPageModelImpl.REDIRECTTITLE_COLUMN_BITMASK |
4544                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
4545                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
4546            public static final FinderPath FINDER_PATH_COUNT_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4547                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4548                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_R",
4549                            new String[] { Long.class.getName(), String.class.getName() });
4550    
4551            /**
4552             * Returns all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
4553             *
4554             * @param nodeId the node ID
4555             * @param redirectTitle the redirect title
4556             * @return the matching wiki pages
4557             * @throws SystemException if a system exception occurred
4558             */
4559            public List<WikiPage> findByN_R(long nodeId, String redirectTitle)
4560                    throws SystemException {
4561                    return findByN_R(nodeId, redirectTitle, QueryUtil.ALL_POS,
4562                            QueryUtil.ALL_POS, null);
4563            }
4564    
4565            /**
4566             * Returns a range of all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
4567             *
4568             * <p>
4569             * 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.
4570             * </p>
4571             *
4572             * @param nodeId the node ID
4573             * @param redirectTitle the redirect title
4574             * @param start the lower bound of the range of wiki pages
4575             * @param end the upper bound of the range of wiki pages (not inclusive)
4576             * @return the range of matching wiki pages
4577             * @throws SystemException if a system exception occurred
4578             */
4579            public List<WikiPage> findByN_R(long nodeId, String redirectTitle,
4580                    int start, int end) throws SystemException {
4581                    return findByN_R(nodeId, redirectTitle, start, end, null);
4582            }
4583    
4584            /**
4585             * Returns an ordered range of all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
4586             *
4587             * <p>
4588             * 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.
4589             * </p>
4590             *
4591             * @param nodeId the node ID
4592             * @param redirectTitle the redirect title
4593             * @param start the lower bound of the range of wiki pages
4594             * @param end the upper bound of the range of wiki pages (not inclusive)
4595             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4596             * @return the ordered range of matching wiki pages
4597             * @throws SystemException if a system exception occurred
4598             */
4599            public List<WikiPage> findByN_R(long nodeId, String redirectTitle,
4600                    int start, int end, OrderByComparator orderByComparator)
4601                    throws SystemException {
4602                    boolean pagination = true;
4603                    FinderPath finderPath = null;
4604                    Object[] finderArgs = null;
4605    
4606                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4607                                    (orderByComparator == null)) {
4608                            pagination = false;
4609                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R;
4610                            finderArgs = new Object[] { nodeId, redirectTitle };
4611                    }
4612                    else {
4613                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_R;
4614                            finderArgs = new Object[] {
4615                                            nodeId, redirectTitle,
4616                                            
4617                                            start, end, orderByComparator
4618                                    };
4619                    }
4620    
4621                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
4622                                    finderArgs, this);
4623    
4624                    if ((list != null) && !list.isEmpty()) {
4625                            for (WikiPage wikiPage : list) {
4626                                    if ((nodeId != wikiPage.getNodeId()) ||
4627                                                    !Validator.equals(redirectTitle,
4628                                                            wikiPage.getRedirectTitle())) {
4629                                            list = null;
4630    
4631                                            break;
4632                                    }
4633                            }
4634                    }
4635    
4636                    if (list == null) {
4637                            StringBundler query = null;
4638    
4639                            if (orderByComparator != null) {
4640                                    query = new StringBundler(4 +
4641                                                    (orderByComparator.getOrderByFields().length * 3));
4642                            }
4643                            else {
4644                                    query = new StringBundler(4);
4645                            }
4646    
4647                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4648    
4649                            query.append(_FINDER_COLUMN_N_R_NODEID_2);
4650    
4651                            if (redirectTitle == null) {
4652                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
4653                            }
4654                            else {
4655                                    if (redirectTitle.equals(StringPool.BLANK)) {
4656                                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
4657                                    }
4658                                    else {
4659                                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
4660                                    }
4661                            }
4662    
4663                            if (orderByComparator != null) {
4664                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4665                                            orderByComparator);
4666                            }
4667                            else
4668                             if (pagination) {
4669                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4670                            }
4671    
4672                            String sql = query.toString();
4673    
4674                            Session session = null;
4675    
4676                            try {
4677                                    session = openSession();
4678    
4679                                    Query q = session.createQuery(sql);
4680    
4681                                    QueryPos qPos = QueryPos.getInstance(q);
4682    
4683                                    qPos.add(nodeId);
4684    
4685                                    if (redirectTitle != null) {
4686                                            qPos.add(redirectTitle);
4687                                    }
4688    
4689                                    if (!pagination) {
4690                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4691                                                            start, end, false);
4692    
4693                                            Collections.sort(list);
4694    
4695                                            list = new UnmodifiableList<WikiPage>(list);
4696                                    }
4697                                    else {
4698                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4699                                                            start, end);
4700                                    }
4701    
4702                                    cacheResult(list);
4703    
4704                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4705                            }
4706                            catch (Exception e) {
4707                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4708    
4709                                    throw processException(e);
4710                            }
4711                            finally {
4712                                    closeSession(session);
4713                            }
4714                    }
4715    
4716                    return list;
4717            }
4718    
4719            /**
4720             * Returns the first wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4721             *
4722             * @param nodeId the node ID
4723             * @param redirectTitle the redirect title
4724             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4725             * @return the first matching wiki page
4726             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4727             * @throws SystemException if a system exception occurred
4728             */
4729            public WikiPage findByN_R_First(long nodeId, String redirectTitle,
4730                    OrderByComparator orderByComparator)
4731                    throws NoSuchPageException, SystemException {
4732                    WikiPage wikiPage = fetchByN_R_First(nodeId, redirectTitle,
4733                                    orderByComparator);
4734    
4735                    if (wikiPage != null) {
4736                            return wikiPage;
4737                    }
4738    
4739                    StringBundler msg = new StringBundler(6);
4740    
4741                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4742    
4743                    msg.append("nodeId=");
4744                    msg.append(nodeId);
4745    
4746                    msg.append(", redirectTitle=");
4747                    msg.append(redirectTitle);
4748    
4749                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4750    
4751                    throw new NoSuchPageException(msg.toString());
4752            }
4753    
4754            /**
4755             * Returns the first wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4756             *
4757             * @param nodeId the node ID
4758             * @param redirectTitle the redirect title
4759             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4760             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
4761             * @throws SystemException if a system exception occurred
4762             */
4763            public WikiPage fetchByN_R_First(long nodeId, String redirectTitle,
4764                    OrderByComparator orderByComparator) throws SystemException {
4765                    List<WikiPage> list = findByN_R(nodeId, redirectTitle, 0, 1,
4766                                    orderByComparator);
4767    
4768                    if (!list.isEmpty()) {
4769                            return list.get(0);
4770                    }
4771    
4772                    return null;
4773            }
4774    
4775            /**
4776             * Returns the last wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4777             *
4778             * @param nodeId the node ID
4779             * @param redirectTitle the redirect title
4780             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4781             * @return the last matching wiki page
4782             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4783             * @throws SystemException if a system exception occurred
4784             */
4785            public WikiPage findByN_R_Last(long nodeId, String redirectTitle,
4786                    OrderByComparator orderByComparator)
4787                    throws NoSuchPageException, SystemException {
4788                    WikiPage wikiPage = fetchByN_R_Last(nodeId, redirectTitle,
4789                                    orderByComparator);
4790    
4791                    if (wikiPage != null) {
4792                            return wikiPage;
4793                    }
4794    
4795                    StringBundler msg = new StringBundler(6);
4796    
4797                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4798    
4799                    msg.append("nodeId=");
4800                    msg.append(nodeId);
4801    
4802                    msg.append(", redirectTitle=");
4803                    msg.append(redirectTitle);
4804    
4805                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4806    
4807                    throw new NoSuchPageException(msg.toString());
4808            }
4809    
4810            /**
4811             * Returns the last wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4812             *
4813             * @param nodeId the node ID
4814             * @param redirectTitle the redirect title
4815             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4816             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
4817             * @throws SystemException if a system exception occurred
4818             */
4819            public WikiPage fetchByN_R_Last(long nodeId, String redirectTitle,
4820                    OrderByComparator orderByComparator) throws SystemException {
4821                    int count = countByN_R(nodeId, redirectTitle);
4822    
4823                    List<WikiPage> list = findByN_R(nodeId, redirectTitle, count - 1,
4824                                    count, orderByComparator);
4825    
4826                    if (!list.isEmpty()) {
4827                            return list.get(0);
4828                    }
4829    
4830                    return null;
4831            }
4832    
4833            /**
4834             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
4835             *
4836             * @param pageId the primary key of the current wiki page
4837             * @param nodeId the node ID
4838             * @param redirectTitle the redirect title
4839             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4840             * @return the previous, current, and next wiki page
4841             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
4842             * @throws SystemException if a system exception occurred
4843             */
4844            public WikiPage[] findByN_R_PrevAndNext(long pageId, long nodeId,
4845                    String redirectTitle, OrderByComparator orderByComparator)
4846                    throws NoSuchPageException, SystemException {
4847                    WikiPage wikiPage = findByPrimaryKey(pageId);
4848    
4849                    Session session = null;
4850    
4851                    try {
4852                            session = openSession();
4853    
4854                            WikiPage[] array = new WikiPageImpl[3];
4855    
4856                            array[0] = getByN_R_PrevAndNext(session, wikiPage, nodeId,
4857                                            redirectTitle, orderByComparator, true);
4858    
4859                            array[1] = wikiPage;
4860    
4861                            array[2] = getByN_R_PrevAndNext(session, wikiPage, nodeId,
4862                                            redirectTitle, orderByComparator, false);
4863    
4864                            return array;
4865                    }
4866                    catch (Exception e) {
4867                            throw processException(e);
4868                    }
4869                    finally {
4870                            closeSession(session);
4871                    }
4872            }
4873    
4874            protected WikiPage getByN_R_PrevAndNext(Session session, WikiPage wikiPage,
4875                    long nodeId, String redirectTitle, OrderByComparator orderByComparator,
4876                    boolean previous) {
4877                    StringBundler query = null;
4878    
4879                    if (orderByComparator != null) {
4880                            query = new StringBundler(6 +
4881                                            (orderByComparator.getOrderByFields().length * 6));
4882                    }
4883                    else {
4884                            query = new StringBundler(3);
4885                    }
4886    
4887                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4888    
4889                    query.append(_FINDER_COLUMN_N_R_NODEID_2);
4890    
4891                    if (redirectTitle == null) {
4892                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
4893                    }
4894                    else {
4895                            if (redirectTitle.equals(StringPool.BLANK)) {
4896                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
4897                            }
4898                            else {
4899                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
4900                            }
4901                    }
4902    
4903                    if (orderByComparator != null) {
4904                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4905    
4906                            if (orderByConditionFields.length > 0) {
4907                                    query.append(WHERE_AND);
4908                            }
4909    
4910                            for (int i = 0; i < orderByConditionFields.length; i++) {
4911                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4912                                    query.append(orderByConditionFields[i]);
4913    
4914                                    if ((i + 1) < orderByConditionFields.length) {
4915                                            if (orderByComparator.isAscending() ^ previous) {
4916                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4917                                            }
4918                                            else {
4919                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4920                                            }
4921                                    }
4922                                    else {
4923                                            if (orderByComparator.isAscending() ^ previous) {
4924                                                    query.append(WHERE_GREATER_THAN);
4925                                            }
4926                                            else {
4927                                                    query.append(WHERE_LESSER_THAN);
4928                                            }
4929                                    }
4930                            }
4931    
4932                            query.append(ORDER_BY_CLAUSE);
4933    
4934                            String[] orderByFields = orderByComparator.getOrderByFields();
4935    
4936                            for (int i = 0; i < orderByFields.length; i++) {
4937                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4938                                    query.append(orderByFields[i]);
4939    
4940                                    if ((i + 1) < orderByFields.length) {
4941                                            if (orderByComparator.isAscending() ^ previous) {
4942                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4943                                            }
4944                                            else {
4945                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4946                                            }
4947                                    }
4948                                    else {
4949                                            if (orderByComparator.isAscending() ^ previous) {
4950                                                    query.append(ORDER_BY_ASC);
4951                                            }
4952                                            else {
4953                                                    query.append(ORDER_BY_DESC);
4954                                            }
4955                                    }
4956                            }
4957                    }
4958                    else {
4959                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4960                    }
4961    
4962                    String sql = query.toString();
4963    
4964                    Query q = session.createQuery(sql);
4965    
4966                    q.setFirstResult(0);
4967                    q.setMaxResults(2);
4968    
4969                    QueryPos qPos = QueryPos.getInstance(q);
4970    
4971                    qPos.add(nodeId);
4972    
4973                    if (redirectTitle != null) {
4974                            qPos.add(redirectTitle);
4975                    }
4976    
4977                    if (orderByComparator != null) {
4978                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
4979    
4980                            for (Object value : values) {
4981                                    qPos.add(value);
4982                            }
4983                    }
4984    
4985                    List<WikiPage> list = q.list();
4986    
4987                    if (list.size() == 2) {
4988                            return list.get(1);
4989                    }
4990                    else {
4991                            return null;
4992                    }
4993            }
4994    
4995            /**
4996             * Removes all the wiki pages where nodeId = &#63; and redirectTitle = &#63; from the database.
4997             *
4998             * @param nodeId the node ID
4999             * @param redirectTitle the redirect title
5000             * @throws SystemException if a system exception occurred
5001             */
5002            public void removeByN_R(long nodeId, String redirectTitle)
5003                    throws SystemException {
5004                    for (WikiPage wikiPage : findByN_R(nodeId, redirectTitle,
5005                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5006                            remove(wikiPage);
5007                    }
5008            }
5009    
5010            /**
5011             * Returns the number of wiki pages where nodeId = &#63; and redirectTitle = &#63;.
5012             *
5013             * @param nodeId the node ID
5014             * @param redirectTitle the redirect title
5015             * @return the number of matching wiki pages
5016             * @throws SystemException if a system exception occurred
5017             */
5018            public int countByN_R(long nodeId, String redirectTitle)
5019                    throws SystemException {
5020                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_R;
5021    
5022                    Object[] finderArgs = new Object[] { nodeId, redirectTitle };
5023    
5024                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5025                                    this);
5026    
5027                    if (count == null) {
5028                            StringBundler query = new StringBundler(3);
5029    
5030                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
5031    
5032                            query.append(_FINDER_COLUMN_N_R_NODEID_2);
5033    
5034                            if (redirectTitle == null) {
5035                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
5036                            }
5037                            else {
5038                                    if (redirectTitle.equals(StringPool.BLANK)) {
5039                                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
5040                                    }
5041                                    else {
5042                                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
5043                                    }
5044                            }
5045    
5046                            String sql = query.toString();
5047    
5048                            Session session = null;
5049    
5050                            try {
5051                                    session = openSession();
5052    
5053                                    Query q = session.createQuery(sql);
5054    
5055                                    QueryPos qPos = QueryPos.getInstance(q);
5056    
5057                                    qPos.add(nodeId);
5058    
5059                                    if (redirectTitle != null) {
5060                                            qPos.add(redirectTitle);
5061                                    }
5062    
5063                                    count = (Long)q.uniqueResult();
5064    
5065                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5066                            }
5067                            catch (Exception e) {
5068                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5069    
5070                                    throw processException(e);
5071                            }
5072                            finally {
5073                                    closeSession(session);
5074                            }
5075                    }
5076    
5077                    return count.intValue();
5078            }
5079    
5080            private static final String _FINDER_COLUMN_N_R_NODEID_2 = "wikiPage.nodeId = ? AND ";
5081            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_1 = "wikiPage.redirectTitle IS NULL";
5082            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_2 = "lower(wikiPage.redirectTitle) = lower(CAST_TEXT(?))";
5083            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_3 = "(wikiPage.redirectTitle IS NULL OR lower(wikiPage.redirectTitle) = lower(CAST_TEXT(?)))";
5084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5085                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5086                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_S",
5087                            new String[] {
5088                                    Long.class.getName(), Integer.class.getName(),
5089                                    
5090                            Integer.class.getName(), Integer.class.getName(),
5091                                    OrderByComparator.class.getName()
5092                            });
5093            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5094                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_S",
5096                            new String[] { Long.class.getName(), Integer.class.getName() },
5097                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
5098                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
5099                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
5100                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
5101            public static final FinderPath FINDER_PATH_COUNT_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5102                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_S",
5104                            new String[] { Long.class.getName(), Integer.class.getName() });
5105    
5106            /**
5107             * Returns all the wiki pages where nodeId = &#63; and status = &#63;.
5108             *
5109             * @param nodeId the node ID
5110             * @param status the status
5111             * @return the matching wiki pages
5112             * @throws SystemException if a system exception occurred
5113             */
5114            public List<WikiPage> findByN_S(long nodeId, int status)
5115                    throws SystemException {
5116                    return findByN_S(nodeId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5117                            null);
5118            }
5119    
5120            /**
5121             * Returns a range of all the wiki pages where nodeId = &#63; and status = &#63;.
5122             *
5123             * <p>
5124             * 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.
5125             * </p>
5126             *
5127             * @param nodeId the node ID
5128             * @param status the status
5129             * @param start the lower bound of the range of wiki pages
5130             * @param end the upper bound of the range of wiki pages (not inclusive)
5131             * @return the range of matching wiki pages
5132             * @throws SystemException if a system exception occurred
5133             */
5134            public List<WikiPage> findByN_S(long nodeId, int status, int start, int end)
5135                    throws SystemException {
5136                    return findByN_S(nodeId, status, start, end, null);
5137            }
5138    
5139            /**
5140             * Returns an ordered range of all the wiki pages where nodeId = &#63; and status = &#63;.
5141             *
5142             * <p>
5143             * 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.
5144             * </p>
5145             *
5146             * @param nodeId the node ID
5147             * @param status the status
5148             * @param start the lower bound of the range of wiki pages
5149             * @param end the upper bound of the range of wiki pages (not inclusive)
5150             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5151             * @return the ordered range of matching wiki pages
5152             * @throws SystemException if a system exception occurred
5153             */
5154            public List<WikiPage> findByN_S(long nodeId, int status, int start,
5155                    int end, OrderByComparator orderByComparator) throws SystemException {
5156                    boolean pagination = true;
5157                    FinderPath finderPath = null;
5158                    Object[] finderArgs = null;
5159    
5160                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5161                                    (orderByComparator == null)) {
5162                            pagination = false;
5163                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S;
5164                            finderArgs = new Object[] { nodeId, status };
5165                    }
5166                    else {
5167                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_S;
5168                            finderArgs = new Object[] {
5169                                            nodeId, status,
5170                                            
5171                                            start, end, orderByComparator
5172                                    };
5173                    }
5174    
5175                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
5176                                    finderArgs, this);
5177    
5178                    if ((list != null) && !list.isEmpty()) {
5179                            for (WikiPage wikiPage : list) {
5180                                    if ((nodeId != wikiPage.getNodeId()) ||
5181                                                    (status != wikiPage.getStatus())) {
5182                                            list = null;
5183    
5184                                            break;
5185                                    }
5186                            }
5187                    }
5188    
5189                    if (list == null) {
5190                            StringBundler query = null;
5191    
5192                            if (orderByComparator != null) {
5193                                    query = new StringBundler(4 +
5194                                                    (orderByComparator.getOrderByFields().length * 3));
5195                            }
5196                            else {
5197                                    query = new StringBundler(4);
5198                            }
5199    
5200                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5201    
5202                            query.append(_FINDER_COLUMN_N_S_NODEID_2);
5203    
5204                            query.append(_FINDER_COLUMN_N_S_STATUS_2);
5205    
5206                            if (orderByComparator != null) {
5207                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5208                                            orderByComparator);
5209                            }
5210                            else
5211                             if (pagination) {
5212                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5213                            }
5214    
5215                            String sql = query.toString();
5216    
5217                            Session session = null;
5218    
5219                            try {
5220                                    session = openSession();
5221    
5222                                    Query q = session.createQuery(sql);
5223    
5224                                    QueryPos qPos = QueryPos.getInstance(q);
5225    
5226                                    qPos.add(nodeId);
5227    
5228                                    qPos.add(status);
5229    
5230                                    if (!pagination) {
5231                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
5232                                                            start, end, false);
5233    
5234                                            Collections.sort(list);
5235    
5236                                            list = new UnmodifiableList<WikiPage>(list);
5237                                    }
5238                                    else {
5239                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
5240                                                            start, end);
5241                                    }
5242    
5243                                    cacheResult(list);
5244    
5245                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5246                            }
5247                            catch (Exception e) {
5248                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5249    
5250                                    throw processException(e);
5251                            }
5252                            finally {
5253                                    closeSession(session);
5254                            }
5255                    }
5256    
5257                    return list;
5258            }
5259    
5260            /**
5261             * Returns the first wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5262             *
5263             * @param nodeId the node ID
5264             * @param status the status
5265             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5266             * @return the first matching wiki page
5267             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5268             * @throws SystemException if a system exception occurred
5269             */
5270            public WikiPage findByN_S_First(long nodeId, int status,
5271                    OrderByComparator orderByComparator)
5272                    throws NoSuchPageException, SystemException {
5273                    WikiPage wikiPage = fetchByN_S_First(nodeId, status, orderByComparator);
5274    
5275                    if (wikiPage != null) {
5276                            return wikiPage;
5277                    }
5278    
5279                    StringBundler msg = new StringBundler(6);
5280    
5281                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5282    
5283                    msg.append("nodeId=");
5284                    msg.append(nodeId);
5285    
5286                    msg.append(", status=");
5287                    msg.append(status);
5288    
5289                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5290    
5291                    throw new NoSuchPageException(msg.toString());
5292            }
5293    
5294            /**
5295             * Returns the first wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5296             *
5297             * @param nodeId the node ID
5298             * @param status the status
5299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5300             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
5301             * @throws SystemException if a system exception occurred
5302             */
5303            public WikiPage fetchByN_S_First(long nodeId, int status,
5304                    OrderByComparator orderByComparator) throws SystemException {
5305                    List<WikiPage> list = findByN_S(nodeId, status, 0, 1, orderByComparator);
5306    
5307                    if (!list.isEmpty()) {
5308                            return list.get(0);
5309                    }
5310    
5311                    return null;
5312            }
5313    
5314            /**
5315             * Returns the last wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5316             *
5317             * @param nodeId the node ID
5318             * @param status the status
5319             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5320             * @return the last matching wiki page
5321             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5322             * @throws SystemException if a system exception occurred
5323             */
5324            public WikiPage findByN_S_Last(long nodeId, int status,
5325                    OrderByComparator orderByComparator)
5326                    throws NoSuchPageException, SystemException {
5327                    WikiPage wikiPage = fetchByN_S_Last(nodeId, status, orderByComparator);
5328    
5329                    if (wikiPage != null) {
5330                            return wikiPage;
5331                    }
5332    
5333                    StringBundler msg = new StringBundler(6);
5334    
5335                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5336    
5337                    msg.append("nodeId=");
5338                    msg.append(nodeId);
5339    
5340                    msg.append(", status=");
5341                    msg.append(status);
5342    
5343                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5344    
5345                    throw new NoSuchPageException(msg.toString());
5346            }
5347    
5348            /**
5349             * Returns the last wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5350             *
5351             * @param nodeId the node ID
5352             * @param status the status
5353             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5354             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
5355             * @throws SystemException if a system exception occurred
5356             */
5357            public WikiPage fetchByN_S_Last(long nodeId, int status,
5358                    OrderByComparator orderByComparator) throws SystemException {
5359                    int count = countByN_S(nodeId, status);
5360    
5361                    List<WikiPage> list = findByN_S(nodeId, status, count - 1, count,
5362                                    orderByComparator);
5363    
5364                    if (!list.isEmpty()) {
5365                            return list.get(0);
5366                    }
5367    
5368                    return null;
5369            }
5370    
5371            /**
5372             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and status = &#63;.
5373             *
5374             * @param pageId the primary key of the current wiki page
5375             * @param nodeId the node ID
5376             * @param status the status
5377             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5378             * @return the previous, current, and next wiki page
5379             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
5380             * @throws SystemException if a system exception occurred
5381             */
5382            public WikiPage[] findByN_S_PrevAndNext(long pageId, long nodeId,
5383                    int status, OrderByComparator orderByComparator)
5384                    throws NoSuchPageException, SystemException {
5385                    WikiPage wikiPage = findByPrimaryKey(pageId);
5386    
5387                    Session session = null;
5388    
5389                    try {
5390                            session = openSession();
5391    
5392                            WikiPage[] array = new WikiPageImpl[3];
5393    
5394                            array[0] = getByN_S_PrevAndNext(session, wikiPage, nodeId, status,
5395                                            orderByComparator, true);
5396    
5397                            array[1] = wikiPage;
5398    
5399                            array[2] = getByN_S_PrevAndNext(session, wikiPage, nodeId, status,
5400                                            orderByComparator, false);
5401    
5402                            return array;
5403                    }
5404                    catch (Exception e) {
5405                            throw processException(e);
5406                    }
5407                    finally {
5408                            closeSession(session);
5409                    }
5410            }
5411    
5412            protected WikiPage getByN_S_PrevAndNext(Session session, WikiPage wikiPage,
5413                    long nodeId, int status, OrderByComparator orderByComparator,
5414                    boolean previous) {
5415                    StringBundler query = null;
5416    
5417                    if (orderByComparator != null) {
5418                            query = new StringBundler(6 +
5419                                            (orderByComparator.getOrderByFields().length * 6));
5420                    }
5421                    else {
5422                            query = new StringBundler(3);
5423                    }
5424    
5425                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5426    
5427                    query.append(_FINDER_COLUMN_N_S_NODEID_2);
5428    
5429                    query.append(_FINDER_COLUMN_N_S_STATUS_2);
5430    
5431                    if (orderByComparator != null) {
5432                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5433    
5434                            if (orderByConditionFields.length > 0) {
5435                                    query.append(WHERE_AND);
5436                            }
5437    
5438                            for (int i = 0; i < orderByConditionFields.length; i++) {
5439                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5440                                    query.append(orderByConditionFields[i]);
5441    
5442                                    if ((i + 1) < orderByConditionFields.length) {
5443                                            if (orderByComparator.isAscending() ^ previous) {
5444                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5445                                            }
5446                                            else {
5447                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5448                                            }
5449                                    }
5450                                    else {
5451                                            if (orderByComparator.isAscending() ^ previous) {
5452                                                    query.append(WHERE_GREATER_THAN);
5453                                            }
5454                                            else {
5455                                                    query.append(WHERE_LESSER_THAN);
5456                                            }
5457                                    }
5458                            }
5459    
5460                            query.append(ORDER_BY_CLAUSE);
5461    
5462                            String[] orderByFields = orderByComparator.getOrderByFields();
5463    
5464                            for (int i = 0; i < orderByFields.length; i++) {
5465                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5466                                    query.append(orderByFields[i]);
5467    
5468                                    if ((i + 1) < orderByFields.length) {
5469                                            if (orderByComparator.isAscending() ^ previous) {
5470                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5471                                            }
5472                                            else {
5473                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5474                                            }
5475                                    }
5476                                    else {
5477                                            if (orderByComparator.isAscending() ^ previous) {
5478                                                    query.append(ORDER_BY_ASC);
5479                                            }
5480                                            else {
5481                                                    query.append(ORDER_BY_DESC);
5482                                            }
5483                                    }
5484                            }
5485                    }
5486                    else {
5487                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5488                    }
5489    
5490                    String sql = query.toString();
5491    
5492                    Query q = session.createQuery(sql);
5493    
5494                    q.setFirstResult(0);
5495                    q.setMaxResults(2);
5496    
5497                    QueryPos qPos = QueryPos.getInstance(q);
5498    
5499                    qPos.add(nodeId);
5500    
5501                    qPos.add(status);
5502    
5503                    if (orderByComparator != null) {
5504                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
5505    
5506                            for (Object value : values) {
5507                                    qPos.add(value);
5508                            }
5509                    }
5510    
5511                    List<WikiPage> list = q.list();
5512    
5513                    if (list.size() == 2) {
5514                            return list.get(1);
5515                    }
5516                    else {
5517                            return null;
5518                    }
5519            }
5520    
5521            /**
5522             * Removes all the wiki pages where nodeId = &#63; and status = &#63; from the database.
5523             *
5524             * @param nodeId the node ID
5525             * @param status the status
5526             * @throws SystemException if a system exception occurred
5527             */
5528            public void removeByN_S(long nodeId, int status) throws SystemException {
5529                    for (WikiPage wikiPage : findByN_S(nodeId, status, QueryUtil.ALL_POS,
5530                                    QueryUtil.ALL_POS, null)) {
5531                            remove(wikiPage);
5532                    }
5533            }
5534    
5535            /**
5536             * Returns the number of wiki pages where nodeId = &#63; and status = &#63;.
5537             *
5538             * @param nodeId the node ID
5539             * @param status the status
5540             * @return the number of matching wiki pages
5541             * @throws SystemException if a system exception occurred
5542             */
5543            public int countByN_S(long nodeId, int status) throws SystemException {
5544                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_S;
5545    
5546                    Object[] finderArgs = new Object[] { nodeId, status };
5547    
5548                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5549                                    this);
5550    
5551                    if (count == null) {
5552                            StringBundler query = new StringBundler(3);
5553    
5554                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
5555    
5556                            query.append(_FINDER_COLUMN_N_S_NODEID_2);
5557    
5558                            query.append(_FINDER_COLUMN_N_S_STATUS_2);
5559    
5560                            String sql = query.toString();
5561    
5562                            Session session = null;
5563    
5564                            try {
5565                                    session = openSession();
5566    
5567                                    Query q = session.createQuery(sql);
5568    
5569                                    QueryPos qPos = QueryPos.getInstance(q);
5570    
5571                                    qPos.add(nodeId);
5572    
5573                                    qPos.add(status);
5574    
5575                                    count = (Long)q.uniqueResult();
5576    
5577                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5578                            }
5579                            catch (Exception e) {
5580                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5581    
5582                                    throw processException(e);
5583                            }
5584                            finally {
5585                                    closeSession(session);
5586                            }
5587                    }
5588    
5589                    return count.intValue();
5590            }
5591    
5592            private static final String _FINDER_COLUMN_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
5593            private static final String _FINDER_COLUMN_N_S_STATUS_2 = "wikiPage.status = ?";
5594            public static final FinderPath FINDER_PATH_FETCH_BY_R_N_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5595                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5596                            FINDER_CLASS_NAME_ENTITY, "fetchByR_N_V",
5597                            new String[] {
5598                                    Long.class.getName(), Long.class.getName(),
5599                                    Double.class.getName()
5600                            },
5601                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
5602                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
5603                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
5604            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5605                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5606                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N_V",
5607                            new String[] {
5608                                    Long.class.getName(), Long.class.getName(),
5609                                    Double.class.getName()
5610                            });
5611    
5612            /**
5613             * 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.
5614             *
5615             * @param resourcePrimKey the resource prim key
5616             * @param nodeId the node ID
5617             * @param version the version
5618             * @return the matching wiki page
5619             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5620             * @throws SystemException if a system exception occurred
5621             */
5622            public WikiPage findByR_N_V(long resourcePrimKey, long nodeId,
5623                    double version) throws NoSuchPageException, SystemException {
5624                    WikiPage wikiPage = fetchByR_N_V(resourcePrimKey, nodeId, version);
5625    
5626                    if (wikiPage == null) {
5627                            StringBundler msg = new StringBundler(8);
5628    
5629                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5630    
5631                            msg.append("resourcePrimKey=");
5632                            msg.append(resourcePrimKey);
5633    
5634                            msg.append(", nodeId=");
5635                            msg.append(nodeId);
5636    
5637                            msg.append(", version=");
5638                            msg.append(version);
5639    
5640                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5641    
5642                            if (_log.isWarnEnabled()) {
5643                                    _log.warn(msg.toString());
5644                            }
5645    
5646                            throw new NoSuchPageException(msg.toString());
5647                    }
5648    
5649                    return wikiPage;
5650            }
5651    
5652            /**
5653             * 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.
5654             *
5655             * @param resourcePrimKey the resource prim key
5656             * @param nodeId the node ID
5657             * @param version the version
5658             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
5659             * @throws SystemException if a system exception occurred
5660             */
5661            public WikiPage fetchByR_N_V(long resourcePrimKey, long nodeId,
5662                    double version) throws SystemException {
5663                    return fetchByR_N_V(resourcePrimKey, nodeId, version, true);
5664            }
5665    
5666            /**
5667             * 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.
5668             *
5669             * @param resourcePrimKey the resource prim key
5670             * @param nodeId the node ID
5671             * @param version the version
5672             * @param retrieveFromCache whether to use the finder cache
5673             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
5674             * @throws SystemException if a system exception occurred
5675             */
5676            public WikiPage fetchByR_N_V(long resourcePrimKey, long nodeId,
5677                    double version, boolean retrieveFromCache) throws SystemException {
5678                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, version };
5679    
5680                    Object result = null;
5681    
5682                    if (retrieveFromCache) {
5683                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_R_N_V,
5684                                            finderArgs, this);
5685                    }
5686    
5687                    if (result instanceof WikiPage) {
5688                            WikiPage wikiPage = (WikiPage)result;
5689    
5690                            if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
5691                                            (nodeId != wikiPage.getNodeId()) ||
5692                                            (version != wikiPage.getVersion())) {
5693                                    result = null;
5694                            }
5695                    }
5696    
5697                    if (result == null) {
5698                            StringBundler query = new StringBundler(5);
5699    
5700                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5701    
5702                            query.append(_FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2);
5703    
5704                            query.append(_FINDER_COLUMN_R_N_V_NODEID_2);
5705    
5706                            query.append(_FINDER_COLUMN_R_N_V_VERSION_2);
5707    
5708                            String sql = query.toString();
5709    
5710                            Session session = null;
5711    
5712                            try {
5713                                    session = openSession();
5714    
5715                                    Query q = session.createQuery(sql);
5716    
5717                                    QueryPos qPos = QueryPos.getInstance(q);
5718    
5719                                    qPos.add(resourcePrimKey);
5720    
5721                                    qPos.add(nodeId);
5722    
5723                                    qPos.add(version);
5724    
5725                                    List<WikiPage> list = q.list();
5726    
5727                                    if (list.isEmpty()) {
5728                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
5729                                                    finderArgs, list);
5730                                    }
5731                                    else {
5732                                            WikiPage wikiPage = list.get(0);
5733    
5734                                            result = wikiPage;
5735    
5736                                            cacheResult(wikiPage);
5737    
5738                                            if ((wikiPage.getResourcePrimKey() != resourcePrimKey) ||
5739                                                            (wikiPage.getNodeId() != nodeId) ||
5740                                                            (wikiPage.getVersion() != version)) {
5741                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
5742                                                            finderArgs, wikiPage);
5743                                            }
5744                                    }
5745                            }
5746                            catch (Exception e) {
5747                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V,
5748                                            finderArgs);
5749    
5750                                    throw processException(e);
5751                            }
5752                            finally {
5753                                    closeSession(session);
5754                            }
5755                    }
5756    
5757                    if (result instanceof List<?>) {
5758                            return null;
5759                    }
5760                    else {
5761                            return (WikiPage)result;
5762                    }
5763            }
5764    
5765            /**
5766             * Removes the wiki page where resourcePrimKey = &#63; and nodeId = &#63; and version = &#63; from the database.
5767             *
5768             * @param resourcePrimKey the resource prim key
5769             * @param nodeId the node ID
5770             * @param version the version
5771             * @return the wiki page that was removed
5772             * @throws SystemException if a system exception occurred
5773             */
5774            public WikiPage removeByR_N_V(long resourcePrimKey, long nodeId,
5775                    double version) throws NoSuchPageException, SystemException {
5776                    WikiPage wikiPage = findByR_N_V(resourcePrimKey, nodeId, version);
5777    
5778                    return remove(wikiPage);
5779            }
5780    
5781            /**
5782             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and version = &#63;.
5783             *
5784             * @param resourcePrimKey the resource prim key
5785             * @param nodeId the node ID
5786             * @param version the version
5787             * @return the number of matching wiki pages
5788             * @throws SystemException if a system exception occurred
5789             */
5790            public int countByR_N_V(long resourcePrimKey, long nodeId, double version)
5791                    throws SystemException {
5792                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N_V;
5793    
5794                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, version };
5795    
5796                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5797                                    this);
5798    
5799                    if (count == null) {
5800                            StringBundler query = new StringBundler(4);
5801    
5802                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
5803    
5804                            query.append(_FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2);
5805    
5806                            query.append(_FINDER_COLUMN_R_N_V_NODEID_2);
5807    
5808                            query.append(_FINDER_COLUMN_R_N_V_VERSION_2);
5809    
5810                            String sql = query.toString();
5811    
5812                            Session session = null;
5813    
5814                            try {
5815                                    session = openSession();
5816    
5817                                    Query q = session.createQuery(sql);
5818    
5819                                    QueryPos qPos = QueryPos.getInstance(q);
5820    
5821                                    qPos.add(resourcePrimKey);
5822    
5823                                    qPos.add(nodeId);
5824    
5825                                    qPos.add(version);
5826    
5827                                    count = (Long)q.uniqueResult();
5828    
5829                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5830                            }
5831                            catch (Exception e) {
5832                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5833    
5834                                    throw processException(e);
5835                            }
5836                            finally {
5837                                    closeSession(session);
5838                            }
5839                    }
5840    
5841                    return count.intValue();
5842            }
5843    
5844            private static final String _FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
5845            private static final String _FINDER_COLUMN_R_N_V_NODEID_2 = "wikiPage.nodeId = ? AND ";
5846            private static final String _FINDER_COLUMN_R_N_V_VERSION_2 = "wikiPage.version = ?";
5847            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5848                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5849                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_N_H",
5850                            new String[] {
5851                                    Long.class.getName(), Long.class.getName(),
5852                                    Boolean.class.getName(),
5853                                    
5854                            Integer.class.getName(), Integer.class.getName(),
5855                                    OrderByComparator.class.getName()
5856                            });
5857            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5858                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5859                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_N_H",
5860                            new String[] {
5861                                    Long.class.getName(), Long.class.getName(),
5862                                    Boolean.class.getName()
5863                            },
5864                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
5865                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
5866                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
5867                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
5868                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
5869            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5870                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5871                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N_H",
5872                            new String[] {
5873                                    Long.class.getName(), Long.class.getName(),
5874                                    Boolean.class.getName()
5875                            });
5876    
5877            /**
5878             * Returns all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
5879             *
5880             * @param resourcePrimKey the resource prim key
5881             * @param nodeId the node ID
5882             * @param head the head
5883             * @return the matching wiki pages
5884             * @throws SystemException if a system exception occurred
5885             */
5886            public List<WikiPage> findByR_N_H(long resourcePrimKey, long nodeId,
5887                    boolean head) throws SystemException {
5888                    return findByR_N_H(resourcePrimKey, nodeId, head, QueryUtil.ALL_POS,
5889                            QueryUtil.ALL_POS, null);
5890            }
5891    
5892            /**
5893             * Returns a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
5894             *
5895             * <p>
5896             * 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.
5897             * </p>
5898             *
5899             * @param resourcePrimKey the resource prim key
5900             * @param nodeId the node ID
5901             * @param head the head
5902             * @param start the lower bound of the range of wiki pages
5903             * @param end the upper bound of the range of wiki pages (not inclusive)
5904             * @return the range of matching wiki pages
5905             * @throws SystemException if a system exception occurred
5906             */
5907            public List<WikiPage> findByR_N_H(long resourcePrimKey, long nodeId,
5908                    boolean head, int start, int end) throws SystemException {
5909                    return findByR_N_H(resourcePrimKey, nodeId, head, start, end, null);
5910            }
5911    
5912            /**
5913             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
5914             *
5915             * <p>
5916             * 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.
5917             * </p>
5918             *
5919             * @param resourcePrimKey the resource prim key
5920             * @param nodeId the node ID
5921             * @param head the head
5922             * @param start the lower bound of the range of wiki pages
5923             * @param end the upper bound of the range of wiki pages (not inclusive)
5924             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5925             * @return the ordered range of matching wiki pages
5926             * @throws SystemException if a system exception occurred
5927             */
5928            public List<WikiPage> findByR_N_H(long resourcePrimKey, long nodeId,
5929                    boolean head, int start, int end, OrderByComparator orderByComparator)
5930                    throws SystemException {
5931                    boolean pagination = true;
5932                    FinderPath finderPath = null;
5933                    Object[] finderArgs = null;
5934    
5935                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5936                                    (orderByComparator == null)) {
5937                            pagination = false;
5938                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H;
5939                            finderArgs = new Object[] { resourcePrimKey, nodeId, head };
5940                    }
5941                    else {
5942                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_H;
5943                            finderArgs = new Object[] {
5944                                            resourcePrimKey, nodeId, head,
5945                                            
5946                                            start, end, orderByComparator
5947                                    };
5948                    }
5949    
5950                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
5951                                    finderArgs, this);
5952    
5953                    if ((list != null) && !list.isEmpty()) {
5954                            for (WikiPage wikiPage : list) {
5955                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
5956                                                    (nodeId != wikiPage.getNodeId()) ||
5957                                                    (head != wikiPage.getHead())) {
5958                                            list = null;
5959    
5960                                            break;
5961                                    }
5962                            }
5963                    }
5964    
5965                    if (list == null) {
5966                            StringBundler query = null;
5967    
5968                            if (orderByComparator != null) {
5969                                    query = new StringBundler(5 +
5970                                                    (orderByComparator.getOrderByFields().length * 3));
5971                            }
5972                            else {
5973                                    query = new StringBundler(5);
5974                            }
5975    
5976                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5977    
5978                            query.append(_FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2);
5979    
5980                            query.append(_FINDER_COLUMN_R_N_H_NODEID_2);
5981    
5982                            query.append(_FINDER_COLUMN_R_N_H_HEAD_2);
5983    
5984                            if (orderByComparator != null) {
5985                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5986                                            orderByComparator);
5987                            }
5988                            else
5989                             if (pagination) {
5990                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5991                            }
5992    
5993                            String sql = query.toString();
5994    
5995                            Session session = null;
5996    
5997                            try {
5998                                    session = openSession();
5999    
6000                                    Query q = session.createQuery(sql);
6001    
6002                                    QueryPos qPos = QueryPos.getInstance(q);
6003    
6004                                    qPos.add(resourcePrimKey);
6005    
6006                                    qPos.add(nodeId);
6007    
6008                                    qPos.add(head);
6009    
6010                                    if (!pagination) {
6011                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6012                                                            start, end, false);
6013    
6014                                            Collections.sort(list);
6015    
6016                                            list = new UnmodifiableList<WikiPage>(list);
6017                                    }
6018                                    else {
6019                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6020                                                            start, end);
6021                                    }
6022    
6023                                    cacheResult(list);
6024    
6025                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6026                            }
6027                            catch (Exception e) {
6028                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6029    
6030                                    throw processException(e);
6031                            }
6032                            finally {
6033                                    closeSession(session);
6034                            }
6035                    }
6036    
6037                    return list;
6038            }
6039    
6040            /**
6041             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6042             *
6043             * @param resourcePrimKey the resource prim key
6044             * @param nodeId the node ID
6045             * @param head the head
6046             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6047             * @return the first matching wiki page
6048             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6049             * @throws SystemException if a system exception occurred
6050             */
6051            public WikiPage findByR_N_H_First(long resourcePrimKey, long nodeId,
6052                    boolean head, OrderByComparator orderByComparator)
6053                    throws NoSuchPageException, SystemException {
6054                    WikiPage wikiPage = fetchByR_N_H_First(resourcePrimKey, nodeId, head,
6055                                    orderByComparator);
6056    
6057                    if (wikiPage != null) {
6058                            return wikiPage;
6059                    }
6060    
6061                    StringBundler msg = new StringBundler(8);
6062    
6063                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6064    
6065                    msg.append("resourcePrimKey=");
6066                    msg.append(resourcePrimKey);
6067    
6068                    msg.append(", nodeId=");
6069                    msg.append(nodeId);
6070    
6071                    msg.append(", head=");
6072                    msg.append(head);
6073    
6074                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6075    
6076                    throw new NoSuchPageException(msg.toString());
6077            }
6078    
6079            /**
6080             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6081             *
6082             * @param resourcePrimKey the resource prim key
6083             * @param nodeId the node ID
6084             * @param head the head
6085             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6086             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
6087             * @throws SystemException if a system exception occurred
6088             */
6089            public WikiPage fetchByR_N_H_First(long resourcePrimKey, long nodeId,
6090                    boolean head, OrderByComparator orderByComparator)
6091                    throws SystemException {
6092                    List<WikiPage> list = findByR_N_H(resourcePrimKey, nodeId, head, 0, 1,
6093                                    orderByComparator);
6094    
6095                    if (!list.isEmpty()) {
6096                            return list.get(0);
6097                    }
6098    
6099                    return null;
6100            }
6101    
6102            /**
6103             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6104             *
6105             * @param resourcePrimKey the resource prim key
6106             * @param nodeId the node ID
6107             * @param head the head
6108             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6109             * @return the last matching wiki page
6110             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6111             * @throws SystemException if a system exception occurred
6112             */
6113            public WikiPage findByR_N_H_Last(long resourcePrimKey, long nodeId,
6114                    boolean head, OrderByComparator orderByComparator)
6115                    throws NoSuchPageException, SystemException {
6116                    WikiPage wikiPage = fetchByR_N_H_Last(resourcePrimKey, nodeId, head,
6117                                    orderByComparator);
6118    
6119                    if (wikiPage != null) {
6120                            return wikiPage;
6121                    }
6122    
6123                    StringBundler msg = new StringBundler(8);
6124    
6125                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6126    
6127                    msg.append("resourcePrimKey=");
6128                    msg.append(resourcePrimKey);
6129    
6130                    msg.append(", nodeId=");
6131                    msg.append(nodeId);
6132    
6133                    msg.append(", head=");
6134                    msg.append(head);
6135    
6136                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6137    
6138                    throw new NoSuchPageException(msg.toString());
6139            }
6140    
6141            /**
6142             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6143             *
6144             * @param resourcePrimKey the resource prim key
6145             * @param nodeId the node ID
6146             * @param head the head
6147             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6148             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
6149             * @throws SystemException if a system exception occurred
6150             */
6151            public WikiPage fetchByR_N_H_Last(long resourcePrimKey, long nodeId,
6152                    boolean head, OrderByComparator orderByComparator)
6153                    throws SystemException {
6154                    int count = countByR_N_H(resourcePrimKey, nodeId, head);
6155    
6156                    List<WikiPage> list = findByR_N_H(resourcePrimKey, nodeId, head,
6157                                    count - 1, count, orderByComparator);
6158    
6159                    if (!list.isEmpty()) {
6160                            return list.get(0);
6161                    }
6162    
6163                    return null;
6164            }
6165    
6166            /**
6167             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6168             *
6169             * @param pageId the primary key of the current wiki page
6170             * @param resourcePrimKey the resource prim key
6171             * @param nodeId the node ID
6172             * @param head the head
6173             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6174             * @return the previous, current, and next wiki page
6175             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
6176             * @throws SystemException if a system exception occurred
6177             */
6178            public WikiPage[] findByR_N_H_PrevAndNext(long pageId,
6179                    long resourcePrimKey, long nodeId, boolean head,
6180                    OrderByComparator orderByComparator)
6181                    throws NoSuchPageException, SystemException {
6182                    WikiPage wikiPage = findByPrimaryKey(pageId);
6183    
6184                    Session session = null;
6185    
6186                    try {
6187                            session = openSession();
6188    
6189                            WikiPage[] array = new WikiPageImpl[3];
6190    
6191                            array[0] = getByR_N_H_PrevAndNext(session, wikiPage,
6192                                            resourcePrimKey, nodeId, head, orderByComparator, true);
6193    
6194                            array[1] = wikiPage;
6195    
6196                            array[2] = getByR_N_H_PrevAndNext(session, wikiPage,
6197                                            resourcePrimKey, nodeId, head, orderByComparator, false);
6198    
6199                            return array;
6200                    }
6201                    catch (Exception e) {
6202                            throw processException(e);
6203                    }
6204                    finally {
6205                            closeSession(session);
6206                    }
6207            }
6208    
6209            protected WikiPage getByR_N_H_PrevAndNext(Session session,
6210                    WikiPage wikiPage, long resourcePrimKey, long nodeId, boolean head,
6211                    OrderByComparator orderByComparator, boolean previous) {
6212                    StringBundler query = null;
6213    
6214                    if (orderByComparator != null) {
6215                            query = new StringBundler(6 +
6216                                            (orderByComparator.getOrderByFields().length * 6));
6217                    }
6218                    else {
6219                            query = new StringBundler(3);
6220                    }
6221    
6222                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6223    
6224                    query.append(_FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2);
6225    
6226                    query.append(_FINDER_COLUMN_R_N_H_NODEID_2);
6227    
6228                    query.append(_FINDER_COLUMN_R_N_H_HEAD_2);
6229    
6230                    if (orderByComparator != null) {
6231                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6232    
6233                            if (orderByConditionFields.length > 0) {
6234                                    query.append(WHERE_AND);
6235                            }
6236    
6237                            for (int i = 0; i < orderByConditionFields.length; i++) {
6238                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6239                                    query.append(orderByConditionFields[i]);
6240    
6241                                    if ((i + 1) < orderByConditionFields.length) {
6242                                            if (orderByComparator.isAscending() ^ previous) {
6243                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6244                                            }
6245                                            else {
6246                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6247                                            }
6248                                    }
6249                                    else {
6250                                            if (orderByComparator.isAscending() ^ previous) {
6251                                                    query.append(WHERE_GREATER_THAN);
6252                                            }
6253                                            else {
6254                                                    query.append(WHERE_LESSER_THAN);
6255                                            }
6256                                    }
6257                            }
6258    
6259                            query.append(ORDER_BY_CLAUSE);
6260    
6261                            String[] orderByFields = orderByComparator.getOrderByFields();
6262    
6263                            for (int i = 0; i < orderByFields.length; i++) {
6264                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6265                                    query.append(orderByFields[i]);
6266    
6267                                    if ((i + 1) < orderByFields.length) {
6268                                            if (orderByComparator.isAscending() ^ previous) {
6269                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6270                                            }
6271                                            else {
6272                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6273                                            }
6274                                    }
6275                                    else {
6276                                            if (orderByComparator.isAscending() ^ previous) {
6277                                                    query.append(ORDER_BY_ASC);
6278                                            }
6279                                            else {
6280                                                    query.append(ORDER_BY_DESC);
6281                                            }
6282                                    }
6283                            }
6284                    }
6285                    else {
6286                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6287                    }
6288    
6289                    String sql = query.toString();
6290    
6291                    Query q = session.createQuery(sql);
6292    
6293                    q.setFirstResult(0);
6294                    q.setMaxResults(2);
6295    
6296                    QueryPos qPos = QueryPos.getInstance(q);
6297    
6298                    qPos.add(resourcePrimKey);
6299    
6300                    qPos.add(nodeId);
6301    
6302                    qPos.add(head);
6303    
6304                    if (orderByComparator != null) {
6305                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
6306    
6307                            for (Object value : values) {
6308                                    qPos.add(value);
6309                            }
6310                    }
6311    
6312                    List<WikiPage> list = q.list();
6313    
6314                    if (list.size() == 2) {
6315                            return list.get(1);
6316                    }
6317                    else {
6318                            return null;
6319                    }
6320            }
6321    
6322            /**
6323             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63; from the database.
6324             *
6325             * @param resourcePrimKey the resource prim key
6326             * @param nodeId the node ID
6327             * @param head the head
6328             * @throws SystemException if a system exception occurred
6329             */
6330            public void removeByR_N_H(long resourcePrimKey, long nodeId, boolean head)
6331                    throws SystemException {
6332                    for (WikiPage wikiPage : findByR_N_H(resourcePrimKey, nodeId, head,
6333                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6334                            remove(wikiPage);
6335                    }
6336            }
6337    
6338            /**
6339             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
6340             *
6341             * @param resourcePrimKey the resource prim key
6342             * @param nodeId the node ID
6343             * @param head the head
6344             * @return the number of matching wiki pages
6345             * @throws SystemException if a system exception occurred
6346             */
6347            public int countByR_N_H(long resourcePrimKey, long nodeId, boolean head)
6348                    throws SystemException {
6349                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N_H;
6350    
6351                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, head };
6352    
6353                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6354                                    this);
6355    
6356                    if (count == null) {
6357                            StringBundler query = new StringBundler(4);
6358    
6359                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
6360    
6361                            query.append(_FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2);
6362    
6363                            query.append(_FINDER_COLUMN_R_N_H_NODEID_2);
6364    
6365                            query.append(_FINDER_COLUMN_R_N_H_HEAD_2);
6366    
6367                            String sql = query.toString();
6368    
6369                            Session session = null;
6370    
6371                            try {
6372                                    session = openSession();
6373    
6374                                    Query q = session.createQuery(sql);
6375    
6376                                    QueryPos qPos = QueryPos.getInstance(q);
6377    
6378                                    qPos.add(resourcePrimKey);
6379    
6380                                    qPos.add(nodeId);
6381    
6382                                    qPos.add(head);
6383    
6384                                    count = (Long)q.uniqueResult();
6385    
6386                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6387                            }
6388                            catch (Exception e) {
6389                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6390    
6391                                    throw processException(e);
6392                            }
6393                            finally {
6394                                    closeSession(session);
6395                            }
6396                    }
6397    
6398                    return count.intValue();
6399            }
6400    
6401            private static final String _FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
6402            private static final String _FINDER_COLUMN_R_N_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
6403            private static final String _FINDER_COLUMN_R_N_H_HEAD_2 = "wikiPage.head = ?";
6404            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6405                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
6406                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_N_S",
6407                            new String[] {
6408                                    Long.class.getName(), Long.class.getName(),
6409                                    Integer.class.getName(),
6410                                    
6411                            Integer.class.getName(), Integer.class.getName(),
6412                                    OrderByComparator.class.getName()
6413                            });
6414            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6415                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
6416                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_N_S",
6417                            new String[] {
6418                                    Long.class.getName(), Long.class.getName(),
6419                                    Integer.class.getName()
6420                            },
6421                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
6422                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
6423                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
6424                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
6425                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
6426            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6427                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6428                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N_S",
6429                            new String[] {
6430                                    Long.class.getName(), Long.class.getName(),
6431                                    Integer.class.getName()
6432                            });
6433    
6434            /**
6435             * Returns all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6436             *
6437             * @param resourcePrimKey the resource prim key
6438             * @param nodeId the node ID
6439             * @param status the status
6440             * @return the matching wiki pages
6441             * @throws SystemException if a system exception occurred
6442             */
6443            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
6444                    int status) throws SystemException {
6445                    return findByR_N_S(resourcePrimKey, nodeId, status, QueryUtil.ALL_POS,
6446                            QueryUtil.ALL_POS, null);
6447            }
6448    
6449            /**
6450             * Returns a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6451             *
6452             * <p>
6453             * 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.
6454             * </p>
6455             *
6456             * @param resourcePrimKey the resource prim key
6457             * @param nodeId the node ID
6458             * @param status the status
6459             * @param start the lower bound of the range of wiki pages
6460             * @param end the upper bound of the range of wiki pages (not inclusive)
6461             * @return the range of matching wiki pages
6462             * @throws SystemException if a system exception occurred
6463             */
6464            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
6465                    int status, int start, int end) throws SystemException {
6466                    return findByR_N_S(resourcePrimKey, nodeId, status, start, end, null);
6467            }
6468    
6469            /**
6470             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6471             *
6472             * <p>
6473             * 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.
6474             * </p>
6475             *
6476             * @param resourcePrimKey the resource prim key
6477             * @param nodeId the node ID
6478             * @param status the status
6479             * @param start the lower bound of the range of wiki pages
6480             * @param end the upper bound of the range of wiki pages (not inclusive)
6481             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6482             * @return the ordered range of matching wiki pages
6483             * @throws SystemException if a system exception occurred
6484             */
6485            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
6486                    int status, int start, int end, OrderByComparator orderByComparator)
6487                    throws SystemException {
6488                    boolean pagination = true;
6489                    FinderPath finderPath = null;
6490                    Object[] finderArgs = null;
6491    
6492                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6493                                    (orderByComparator == null)) {
6494                            pagination = false;
6495                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S;
6496                            finderArgs = new Object[] { resourcePrimKey, nodeId, status };
6497                    }
6498                    else {
6499                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_S;
6500                            finderArgs = new Object[] {
6501                                            resourcePrimKey, nodeId, status,
6502                                            
6503                                            start, end, orderByComparator
6504                                    };
6505                    }
6506    
6507                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
6508                                    finderArgs, this);
6509    
6510                    if ((list != null) && !list.isEmpty()) {
6511                            for (WikiPage wikiPage : list) {
6512                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
6513                                                    (nodeId != wikiPage.getNodeId()) ||
6514                                                    (status != wikiPage.getStatus())) {
6515                                            list = null;
6516    
6517                                            break;
6518                                    }
6519                            }
6520                    }
6521    
6522                    if (list == null) {
6523                            StringBundler query = null;
6524    
6525                            if (orderByComparator != null) {
6526                                    query = new StringBundler(5 +
6527                                                    (orderByComparator.getOrderByFields().length * 3));
6528                            }
6529                            else {
6530                                    query = new StringBundler(5);
6531                            }
6532    
6533                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6534    
6535                            query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
6536    
6537                            query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
6538    
6539                            query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
6540    
6541                            if (orderByComparator != null) {
6542                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6543                                            orderByComparator);
6544                            }
6545                            else
6546                             if (pagination) {
6547                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6548                            }
6549    
6550                            String sql = query.toString();
6551    
6552                            Session session = null;
6553    
6554                            try {
6555                                    session = openSession();
6556    
6557                                    Query q = session.createQuery(sql);
6558    
6559                                    QueryPos qPos = QueryPos.getInstance(q);
6560    
6561                                    qPos.add(resourcePrimKey);
6562    
6563                                    qPos.add(nodeId);
6564    
6565                                    qPos.add(status);
6566    
6567                                    if (!pagination) {
6568                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6569                                                            start, end, false);
6570    
6571                                            Collections.sort(list);
6572    
6573                                            list = new UnmodifiableList<WikiPage>(list);
6574                                    }
6575                                    else {
6576                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6577                                                            start, end);
6578                                    }
6579    
6580                                    cacheResult(list);
6581    
6582                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6583                            }
6584                            catch (Exception e) {
6585                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6586    
6587                                    throw processException(e);
6588                            }
6589                            finally {
6590                                    closeSession(session);
6591                            }
6592                    }
6593    
6594                    return list;
6595            }
6596    
6597            /**
6598             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6599             *
6600             * @param resourcePrimKey the resource prim key
6601             * @param nodeId the node ID
6602             * @param status the status
6603             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6604             * @return the first matching wiki page
6605             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6606             * @throws SystemException if a system exception occurred
6607             */
6608            public WikiPage findByR_N_S_First(long resourcePrimKey, long nodeId,
6609                    int status, OrderByComparator orderByComparator)
6610                    throws NoSuchPageException, SystemException {
6611                    WikiPage wikiPage = fetchByR_N_S_First(resourcePrimKey, nodeId, status,
6612                                    orderByComparator);
6613    
6614                    if (wikiPage != null) {
6615                            return wikiPage;
6616                    }
6617    
6618                    StringBundler msg = new StringBundler(8);
6619    
6620                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6621    
6622                    msg.append("resourcePrimKey=");
6623                    msg.append(resourcePrimKey);
6624    
6625                    msg.append(", nodeId=");
6626                    msg.append(nodeId);
6627    
6628                    msg.append(", status=");
6629                    msg.append(status);
6630    
6631                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6632    
6633                    throw new NoSuchPageException(msg.toString());
6634            }
6635    
6636            /**
6637             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6638             *
6639             * @param resourcePrimKey the resource prim key
6640             * @param nodeId the node ID
6641             * @param status the status
6642             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6643             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
6644             * @throws SystemException if a system exception occurred
6645             */
6646            public WikiPage fetchByR_N_S_First(long resourcePrimKey, long nodeId,
6647                    int status, OrderByComparator orderByComparator)
6648                    throws SystemException {
6649                    List<WikiPage> list = findByR_N_S(resourcePrimKey, nodeId, status, 0,
6650                                    1, orderByComparator);
6651    
6652                    if (!list.isEmpty()) {
6653                            return list.get(0);
6654                    }
6655    
6656                    return null;
6657            }
6658    
6659            /**
6660             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6661             *
6662             * @param resourcePrimKey the resource prim key
6663             * @param nodeId the node ID
6664             * @param status the status
6665             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6666             * @return the last matching wiki page
6667             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6668             * @throws SystemException if a system exception occurred
6669             */
6670            public WikiPage findByR_N_S_Last(long resourcePrimKey, long nodeId,
6671                    int status, OrderByComparator orderByComparator)
6672                    throws NoSuchPageException, SystemException {
6673                    WikiPage wikiPage = fetchByR_N_S_Last(resourcePrimKey, nodeId, status,
6674                                    orderByComparator);
6675    
6676                    if (wikiPage != null) {
6677                            return wikiPage;
6678                    }
6679    
6680                    StringBundler msg = new StringBundler(8);
6681    
6682                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6683    
6684                    msg.append("resourcePrimKey=");
6685                    msg.append(resourcePrimKey);
6686    
6687                    msg.append(", nodeId=");
6688                    msg.append(nodeId);
6689    
6690                    msg.append(", status=");
6691                    msg.append(status);
6692    
6693                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6694    
6695                    throw new NoSuchPageException(msg.toString());
6696            }
6697    
6698            /**
6699             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6700             *
6701             * @param resourcePrimKey the resource prim key
6702             * @param nodeId the node ID
6703             * @param status the status
6704             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6705             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
6706             * @throws SystemException if a system exception occurred
6707             */
6708            public WikiPage fetchByR_N_S_Last(long resourcePrimKey, long nodeId,
6709                    int status, OrderByComparator orderByComparator)
6710                    throws SystemException {
6711                    int count = countByR_N_S(resourcePrimKey, nodeId, status);
6712    
6713                    List<WikiPage> list = findByR_N_S(resourcePrimKey, nodeId, status,
6714                                    count - 1, count, orderByComparator);
6715    
6716                    if (!list.isEmpty()) {
6717                            return list.get(0);
6718                    }
6719    
6720                    return null;
6721            }
6722    
6723            /**
6724             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6725             *
6726             * @param pageId the primary key of the current wiki page
6727             * @param resourcePrimKey the resource prim key
6728             * @param nodeId the node ID
6729             * @param status the status
6730             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6731             * @return the previous, current, and next wiki page
6732             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
6733             * @throws SystemException if a system exception occurred
6734             */
6735            public WikiPage[] findByR_N_S_PrevAndNext(long pageId,
6736                    long resourcePrimKey, long nodeId, int status,
6737                    OrderByComparator orderByComparator)
6738                    throws NoSuchPageException, SystemException {
6739                    WikiPage wikiPage = findByPrimaryKey(pageId);
6740    
6741                    Session session = null;
6742    
6743                    try {
6744                            session = openSession();
6745    
6746                            WikiPage[] array = new WikiPageImpl[3];
6747    
6748                            array[0] = getByR_N_S_PrevAndNext(session, wikiPage,
6749                                            resourcePrimKey, nodeId, status, orderByComparator, true);
6750    
6751                            array[1] = wikiPage;
6752    
6753                            array[2] = getByR_N_S_PrevAndNext(session, wikiPage,
6754                                            resourcePrimKey, nodeId, status, orderByComparator, false);
6755    
6756                            return array;
6757                    }
6758                    catch (Exception e) {
6759                            throw processException(e);
6760                    }
6761                    finally {
6762                            closeSession(session);
6763                    }
6764            }
6765    
6766            protected WikiPage getByR_N_S_PrevAndNext(Session session,
6767                    WikiPage wikiPage, long resourcePrimKey, long nodeId, int status,
6768                    OrderByComparator orderByComparator, boolean previous) {
6769                    StringBundler query = null;
6770    
6771                    if (orderByComparator != null) {
6772                            query = new StringBundler(6 +
6773                                            (orderByComparator.getOrderByFields().length * 6));
6774                    }
6775                    else {
6776                            query = new StringBundler(3);
6777                    }
6778    
6779                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6780    
6781                    query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
6782    
6783                    query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
6784    
6785                    query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
6786    
6787                    if (orderByComparator != null) {
6788                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6789    
6790                            if (orderByConditionFields.length > 0) {
6791                                    query.append(WHERE_AND);
6792                            }
6793    
6794                            for (int i = 0; i < orderByConditionFields.length; i++) {
6795                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6796                                    query.append(orderByConditionFields[i]);
6797    
6798                                    if ((i + 1) < orderByConditionFields.length) {
6799                                            if (orderByComparator.isAscending() ^ previous) {
6800                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6801                                            }
6802                                            else {
6803                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6804                                            }
6805                                    }
6806                                    else {
6807                                            if (orderByComparator.isAscending() ^ previous) {
6808                                                    query.append(WHERE_GREATER_THAN);
6809                                            }
6810                                            else {
6811                                                    query.append(WHERE_LESSER_THAN);
6812                                            }
6813                                    }
6814                            }
6815    
6816                            query.append(ORDER_BY_CLAUSE);
6817    
6818                            String[] orderByFields = orderByComparator.getOrderByFields();
6819    
6820                            for (int i = 0; i < orderByFields.length; i++) {
6821                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6822                                    query.append(orderByFields[i]);
6823    
6824                                    if ((i + 1) < orderByFields.length) {
6825                                            if (orderByComparator.isAscending() ^ previous) {
6826                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6827                                            }
6828                                            else {
6829                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6830                                            }
6831                                    }
6832                                    else {
6833                                            if (orderByComparator.isAscending() ^ previous) {
6834                                                    query.append(ORDER_BY_ASC);
6835                                            }
6836                                            else {
6837                                                    query.append(ORDER_BY_DESC);
6838                                            }
6839                                    }
6840                            }
6841                    }
6842                    else {
6843                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6844                    }
6845    
6846                    String sql = query.toString();
6847    
6848                    Query q = session.createQuery(sql);
6849    
6850                    q.setFirstResult(0);
6851                    q.setMaxResults(2);
6852    
6853                    QueryPos qPos = QueryPos.getInstance(q);
6854    
6855                    qPos.add(resourcePrimKey);
6856    
6857                    qPos.add(nodeId);
6858    
6859                    qPos.add(status);
6860    
6861                    if (orderByComparator != null) {
6862                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
6863    
6864                            for (Object value : values) {
6865                                    qPos.add(value);
6866                            }
6867                    }
6868    
6869                    List<WikiPage> list = q.list();
6870    
6871                    if (list.size() == 2) {
6872                            return list.get(1);
6873                    }
6874                    else {
6875                            return null;
6876                    }
6877            }
6878    
6879            /**
6880             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63; from the database.
6881             *
6882             * @param resourcePrimKey the resource prim key
6883             * @param nodeId the node ID
6884             * @param status the status
6885             * @throws SystemException if a system exception occurred
6886             */
6887            public void removeByR_N_S(long resourcePrimKey, long nodeId, int status)
6888                    throws SystemException {
6889                    for (WikiPage wikiPage : findByR_N_S(resourcePrimKey, nodeId, status,
6890                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6891                            remove(wikiPage);
6892                    }
6893            }
6894    
6895            /**
6896             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
6897             *
6898             * @param resourcePrimKey the resource prim key
6899             * @param nodeId the node ID
6900             * @param status the status
6901             * @return the number of matching wiki pages
6902             * @throws SystemException if a system exception occurred
6903             */
6904            public int countByR_N_S(long resourcePrimKey, long nodeId, int status)
6905                    throws SystemException {
6906                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N_S;
6907    
6908                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, status };
6909    
6910                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6911                                    this);
6912    
6913                    if (count == null) {
6914                            StringBundler query = new StringBundler(4);
6915    
6916                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
6917    
6918                            query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
6919    
6920                            query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
6921    
6922                            query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
6923    
6924                            String sql = query.toString();
6925    
6926                            Session session = null;
6927    
6928                            try {
6929                                    session = openSession();
6930    
6931                                    Query q = session.createQuery(sql);
6932    
6933                                    QueryPos qPos = QueryPos.getInstance(q);
6934    
6935                                    qPos.add(resourcePrimKey);
6936    
6937                                    qPos.add(nodeId);
6938    
6939                                    qPos.add(status);
6940    
6941                                    count = (Long)q.uniqueResult();
6942    
6943                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6944                            }
6945                            catch (Exception e) {
6946                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6947    
6948                                    throw processException(e);
6949                            }
6950                            finally {
6951                                    closeSession(session);
6952                            }
6953                    }
6954    
6955                    return count.intValue();
6956            }
6957    
6958            private static final String _FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
6959            private static final String _FINDER_COLUMN_R_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
6960            private static final String _FINDER_COLUMN_R_N_S_STATUS_2 = "wikiPage.status = ?";
6961            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6962                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
6963                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H",
6964                            new String[] {
6965                                    Long.class.getName(), Long.class.getName(),
6966                                    Boolean.class.getName(),
6967                                    
6968                            Integer.class.getName(), Integer.class.getName(),
6969                                    OrderByComparator.class.getName()
6970                            });
6971            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6972                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
6973                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H",
6974                            new String[] {
6975                                    Long.class.getName(), Long.class.getName(),
6976                                    Boolean.class.getName()
6977                            },
6978                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
6979                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
6980                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
6981                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
6982                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
6983            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6984                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6985                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H",
6986                            new String[] {
6987                                    Long.class.getName(), Long.class.getName(),
6988                                    Boolean.class.getName()
6989                            });
6990    
6991            /**
6992             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
6993             *
6994             * @param groupId the group ID
6995             * @param nodeId the node ID
6996             * @param head the head
6997             * @return the matching wiki pages
6998             * @throws SystemException if a system exception occurred
6999             */
7000            public List<WikiPage> findByG_N_H(long groupId, long nodeId, boolean head)
7001                    throws SystemException {
7002                    return findByG_N_H(groupId, nodeId, head, QueryUtil.ALL_POS,
7003                            QueryUtil.ALL_POS, null);
7004            }
7005    
7006            /**
7007             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
7008             *
7009             * <p>
7010             * 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.
7011             * </p>
7012             *
7013             * @param groupId the group ID
7014             * @param nodeId the node ID
7015             * @param head the head
7016             * @param start the lower bound of the range of wiki pages
7017             * @param end the upper bound of the range of wiki pages (not inclusive)
7018             * @return the range of matching wiki pages
7019             * @throws SystemException if a system exception occurred
7020             */
7021            public List<WikiPage> findByG_N_H(long groupId, long nodeId, boolean head,
7022                    int start, int end) throws SystemException {
7023                    return findByG_N_H(groupId, nodeId, head, start, end, null);
7024            }
7025    
7026            /**
7027             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
7028             *
7029             * <p>
7030             * 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.
7031             * </p>
7032             *
7033             * @param groupId the group ID
7034             * @param nodeId the node ID
7035             * @param head the head
7036             * @param start the lower bound of the range of wiki pages
7037             * @param end the upper bound of the range of wiki pages (not inclusive)
7038             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7039             * @return the ordered range of matching wiki pages
7040             * @throws SystemException if a system exception occurred
7041             */
7042            public List<WikiPage> findByG_N_H(long groupId, long nodeId, boolean head,
7043                    int start, int end, OrderByComparator orderByComparator)
7044                    throws SystemException {
7045                    boolean pagination = true;
7046                    FinderPath finderPath = null;
7047                    Object[] finderArgs = null;
7048    
7049                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7050                                    (orderByComparator == null)) {
7051                            pagination = false;
7052                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H;
7053                            finderArgs = new Object[] { groupId, nodeId, head };
7054                    }
7055                    else {
7056                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H;
7057                            finderArgs = new Object[] {
7058                                            groupId, nodeId, head,
7059                                            
7060                                            start, end, orderByComparator
7061                                    };
7062                    }
7063    
7064                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
7065                                    finderArgs, this);
7066    
7067                    if ((list != null) && !list.isEmpty()) {
7068                            for (WikiPage wikiPage : list) {
7069                                    if ((groupId != wikiPage.getGroupId()) ||
7070                                                    (nodeId != wikiPage.getNodeId()) ||
7071                                                    (head != wikiPage.getHead())) {
7072                                            list = null;
7073    
7074                                            break;
7075                                    }
7076                            }
7077                    }
7078    
7079                    if (list == null) {
7080                            StringBundler query = null;
7081    
7082                            if (orderByComparator != null) {
7083                                    query = new StringBundler(5 +
7084                                                    (orderByComparator.getOrderByFields().length * 3));
7085                            }
7086                            else {
7087                                    query = new StringBundler(5);
7088                            }
7089    
7090                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
7091    
7092                            query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7093    
7094                            query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7095    
7096                            query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7097    
7098                            if (orderByComparator != null) {
7099                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7100                                            orderByComparator);
7101                            }
7102                            else
7103                             if (pagination) {
7104                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7105                            }
7106    
7107                            String sql = query.toString();
7108    
7109                            Session session = null;
7110    
7111                            try {
7112                                    session = openSession();
7113    
7114                                    Query q = session.createQuery(sql);
7115    
7116                                    QueryPos qPos = QueryPos.getInstance(q);
7117    
7118                                    qPos.add(groupId);
7119    
7120                                    qPos.add(nodeId);
7121    
7122                                    qPos.add(head);
7123    
7124                                    if (!pagination) {
7125                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
7126                                                            start, end, false);
7127    
7128                                            Collections.sort(list);
7129    
7130                                            list = new UnmodifiableList<WikiPage>(list);
7131                                    }
7132                                    else {
7133                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
7134                                                            start, end);
7135                                    }
7136    
7137                                    cacheResult(list);
7138    
7139                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7140                            }
7141                            catch (Exception e) {
7142                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7143    
7144                                    throw processException(e);
7145                            }
7146                            finally {
7147                                    closeSession(session);
7148                            }
7149                    }
7150    
7151                    return list;
7152            }
7153    
7154            /**
7155             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7156             *
7157             * @param groupId the group ID
7158             * @param nodeId the node ID
7159             * @param head the head
7160             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7161             * @return the first matching wiki page
7162             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
7163             * @throws SystemException if a system exception occurred
7164             */
7165            public WikiPage findByG_N_H_First(long groupId, long nodeId, boolean head,
7166                    OrderByComparator orderByComparator)
7167                    throws NoSuchPageException, SystemException {
7168                    WikiPage wikiPage = fetchByG_N_H_First(groupId, nodeId, head,
7169                                    orderByComparator);
7170    
7171                    if (wikiPage != null) {
7172                            return wikiPage;
7173                    }
7174    
7175                    StringBundler msg = new StringBundler(8);
7176    
7177                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7178    
7179                    msg.append("groupId=");
7180                    msg.append(groupId);
7181    
7182                    msg.append(", nodeId=");
7183                    msg.append(nodeId);
7184    
7185                    msg.append(", head=");
7186                    msg.append(head);
7187    
7188                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7189    
7190                    throw new NoSuchPageException(msg.toString());
7191            }
7192    
7193            /**
7194             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7195             *
7196             * @param groupId the group ID
7197             * @param nodeId the node ID
7198             * @param head the head
7199             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7200             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
7201             * @throws SystemException if a system exception occurred
7202             */
7203            public WikiPage fetchByG_N_H_First(long groupId, long nodeId, boolean head,
7204                    OrderByComparator orderByComparator) throws SystemException {
7205                    List<WikiPage> list = findByG_N_H(groupId, nodeId, head, 0, 1,
7206                                    orderByComparator);
7207    
7208                    if (!list.isEmpty()) {
7209                            return list.get(0);
7210                    }
7211    
7212                    return null;
7213            }
7214    
7215            /**
7216             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7217             *
7218             * @param groupId the group ID
7219             * @param nodeId the node ID
7220             * @param head the head
7221             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7222             * @return the last matching wiki page
7223             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
7224             * @throws SystemException if a system exception occurred
7225             */
7226            public WikiPage findByG_N_H_Last(long groupId, long nodeId, boolean head,
7227                    OrderByComparator orderByComparator)
7228                    throws NoSuchPageException, SystemException {
7229                    WikiPage wikiPage = fetchByG_N_H_Last(groupId, nodeId, head,
7230                                    orderByComparator);
7231    
7232                    if (wikiPage != null) {
7233                            return wikiPage;
7234                    }
7235    
7236                    StringBundler msg = new StringBundler(8);
7237    
7238                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7239    
7240                    msg.append("groupId=");
7241                    msg.append(groupId);
7242    
7243                    msg.append(", nodeId=");
7244                    msg.append(nodeId);
7245    
7246                    msg.append(", head=");
7247                    msg.append(head);
7248    
7249                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7250    
7251                    throw new NoSuchPageException(msg.toString());
7252            }
7253    
7254            /**
7255             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7256             *
7257             * @param groupId the group ID
7258             * @param nodeId the node ID
7259             * @param head the head
7260             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7261             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
7262             * @throws SystemException if a system exception occurred
7263             */
7264            public WikiPage fetchByG_N_H_Last(long groupId, long nodeId, boolean head,
7265                    OrderByComparator orderByComparator) throws SystemException {
7266                    int count = countByG_N_H(groupId, nodeId, head);
7267    
7268                    List<WikiPage> list = findByG_N_H(groupId, nodeId, head, count - 1,
7269                                    count, orderByComparator);
7270    
7271                    if (!list.isEmpty()) {
7272                            return list.get(0);
7273                    }
7274    
7275                    return null;
7276            }
7277    
7278            /**
7279             * Returns the wiki pages before and after the current wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
7280             *
7281             * @param pageId the primary key of the current wiki page
7282             * @param groupId the group ID
7283             * @param nodeId the node ID
7284             * @param head the head
7285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7286             * @return the previous, current, and next wiki page
7287             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
7288             * @throws SystemException if a system exception occurred
7289             */
7290            public WikiPage[] findByG_N_H_PrevAndNext(long pageId, long groupId,
7291                    long nodeId, boolean head, OrderByComparator orderByComparator)
7292                    throws NoSuchPageException, SystemException {
7293                    WikiPage wikiPage = findByPrimaryKey(pageId);
7294    
7295                    Session session = null;
7296    
7297                    try {
7298                            session = openSession();
7299    
7300                            WikiPage[] array = new WikiPageImpl[3];
7301    
7302                            array[0] = getByG_N_H_PrevAndNext(session, wikiPage, groupId,
7303                                            nodeId, head, orderByComparator, true);
7304    
7305                            array[1] = wikiPage;
7306    
7307                            array[2] = getByG_N_H_PrevAndNext(session, wikiPage, groupId,
7308                                            nodeId, head, orderByComparator, false);
7309    
7310                            return array;
7311                    }
7312                    catch (Exception e) {
7313                            throw processException(e);
7314                    }
7315                    finally {
7316                            closeSession(session);
7317                    }
7318            }
7319    
7320            protected WikiPage getByG_N_H_PrevAndNext(Session session,
7321                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
7322                    OrderByComparator orderByComparator, boolean previous) {
7323                    StringBundler query = null;
7324    
7325                    if (orderByComparator != null) {
7326                            query = new StringBundler(6 +
7327                                            (orderByComparator.getOrderByFields().length * 6));
7328                    }
7329                    else {
7330                            query = new StringBundler(3);
7331                    }
7332    
7333                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
7334    
7335                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7336    
7337                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7338    
7339                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7340    
7341                    if (orderByComparator != null) {
7342                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7343    
7344                            if (orderByConditionFields.length > 0) {
7345                                    query.append(WHERE_AND);
7346                            }
7347    
7348                            for (int i = 0; i < orderByConditionFields.length; i++) {
7349                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7350                                    query.append(orderByConditionFields[i]);
7351    
7352                                    if ((i + 1) < orderByConditionFields.length) {
7353                                            if (orderByComparator.isAscending() ^ previous) {
7354                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7355                                            }
7356                                            else {
7357                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7358                                            }
7359                                    }
7360                                    else {
7361                                            if (orderByComparator.isAscending() ^ previous) {
7362                                                    query.append(WHERE_GREATER_THAN);
7363                                            }
7364                                            else {
7365                                                    query.append(WHERE_LESSER_THAN);
7366                                            }
7367                                    }
7368                            }
7369    
7370                            query.append(ORDER_BY_CLAUSE);
7371    
7372                            String[] orderByFields = orderByComparator.getOrderByFields();
7373    
7374                            for (int i = 0; i < orderByFields.length; i++) {
7375                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7376                                    query.append(orderByFields[i]);
7377    
7378                                    if ((i + 1) < orderByFields.length) {
7379                                            if (orderByComparator.isAscending() ^ previous) {
7380                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7381                                            }
7382                                            else {
7383                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7384                                            }
7385                                    }
7386                                    else {
7387                                            if (orderByComparator.isAscending() ^ previous) {
7388                                                    query.append(ORDER_BY_ASC);
7389                                            }
7390                                            else {
7391                                                    query.append(ORDER_BY_DESC);
7392                                            }
7393                                    }
7394                            }
7395                    }
7396                    else {
7397                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7398                    }
7399    
7400                    String sql = query.toString();
7401    
7402                    Query q = session.createQuery(sql);
7403    
7404                    q.setFirstResult(0);
7405                    q.setMaxResults(2);
7406    
7407                    QueryPos qPos = QueryPos.getInstance(q);
7408    
7409                    qPos.add(groupId);
7410    
7411                    qPos.add(nodeId);
7412    
7413                    qPos.add(head);
7414    
7415                    if (orderByComparator != null) {
7416                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
7417    
7418                            for (Object value : values) {
7419                                    qPos.add(value);
7420                            }
7421                    }
7422    
7423                    List<WikiPage> list = q.list();
7424    
7425                    if (list.size() == 2) {
7426                            return list.get(1);
7427                    }
7428                    else {
7429                            return null;
7430                    }
7431            }
7432    
7433            /**
7434             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
7435             *
7436             * @param groupId the group ID
7437             * @param nodeId the node ID
7438             * @param head the head
7439             * @return the matching wiki pages that the user has permission to view
7440             * @throws SystemException if a system exception occurred
7441             */
7442            public List<WikiPage> filterFindByG_N_H(long groupId, long nodeId,
7443                    boolean head) throws SystemException {
7444                    return filterFindByG_N_H(groupId, nodeId, head, QueryUtil.ALL_POS,
7445                            QueryUtil.ALL_POS, null);
7446            }
7447    
7448            /**
7449             * Returns a range of all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
7450             *
7451             * <p>
7452             * 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.
7453             * </p>
7454             *
7455             * @param groupId the group ID
7456             * @param nodeId the node ID
7457             * @param head the head
7458             * @param start the lower bound of the range of wiki pages
7459             * @param end the upper bound of the range of wiki pages (not inclusive)
7460             * @return the range of matching wiki pages that the user has permission to view
7461             * @throws SystemException if a system exception occurred
7462             */
7463            public List<WikiPage> filterFindByG_N_H(long groupId, long nodeId,
7464                    boolean head, int start, int end) throws SystemException {
7465                    return filterFindByG_N_H(groupId, nodeId, head, start, end, null);
7466            }
7467    
7468            /**
7469             * 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;.
7470             *
7471             * <p>
7472             * 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.
7473             * </p>
7474             *
7475             * @param groupId the group ID
7476             * @param nodeId the node ID
7477             * @param head the head
7478             * @param start the lower bound of the range of wiki pages
7479             * @param end the upper bound of the range of wiki pages (not inclusive)
7480             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7481             * @return the ordered range of matching wiki pages that the user has permission to view
7482             * @throws SystemException if a system exception occurred
7483             */
7484            public List<WikiPage> filterFindByG_N_H(long groupId, long nodeId,
7485                    boolean head, int start, int end, OrderByComparator orderByComparator)
7486                    throws SystemException {
7487                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7488                            return findByG_N_H(groupId, nodeId, head, start, end,
7489                                    orderByComparator);
7490                    }
7491    
7492                    StringBundler query = null;
7493    
7494                    if (orderByComparator != null) {
7495                            query = new StringBundler(5 +
7496                                            (orderByComparator.getOrderByFields().length * 3));
7497                    }
7498                    else {
7499                            query = new StringBundler(5);
7500                    }
7501    
7502                    if (getDB().isSupportsInlineDistinct()) {
7503                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
7504                    }
7505                    else {
7506                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
7507                    }
7508    
7509                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7510    
7511                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7512    
7513                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7514    
7515                    if (!getDB().isSupportsInlineDistinct()) {
7516                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
7517                    }
7518    
7519                    if (orderByComparator != null) {
7520                            if (getDB().isSupportsInlineDistinct()) {
7521                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7522                                            orderByComparator);
7523                            }
7524                            else {
7525                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7526                                            orderByComparator);
7527                            }
7528                    }
7529                    else {
7530                            if (getDB().isSupportsInlineDistinct()) {
7531                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7532                            }
7533                            else {
7534                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
7535                            }
7536                    }
7537    
7538                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7539                                    WikiPage.class.getName(),
7540                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7541    
7542                    Session session = null;
7543    
7544                    try {
7545                            session = openSession();
7546    
7547                            SQLQuery q = session.createSQLQuery(sql);
7548    
7549                            if (getDB().isSupportsInlineDistinct()) {
7550                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
7551                            }
7552                            else {
7553                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
7554                            }
7555    
7556                            QueryPos qPos = QueryPos.getInstance(q);
7557    
7558                            qPos.add(groupId);
7559    
7560                            qPos.add(nodeId);
7561    
7562                            qPos.add(head);
7563    
7564                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
7565                    }
7566                    catch (Exception e) {
7567                            throw processException(e);
7568                    }
7569                    finally {
7570                            closeSession(session);
7571                    }
7572            }
7573    
7574            /**
7575             * 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;.
7576             *
7577             * @param pageId the primary key of the current wiki page
7578             * @param groupId the group ID
7579             * @param nodeId the node ID
7580             * @param head the head
7581             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7582             * @return the previous, current, and next wiki page
7583             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
7584             * @throws SystemException if a system exception occurred
7585             */
7586            public WikiPage[] filterFindByG_N_H_PrevAndNext(long pageId, long groupId,
7587                    long nodeId, boolean head, OrderByComparator orderByComparator)
7588                    throws NoSuchPageException, SystemException {
7589                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7590                            return findByG_N_H_PrevAndNext(pageId, groupId, nodeId, head,
7591                                    orderByComparator);
7592                    }
7593    
7594                    WikiPage wikiPage = findByPrimaryKey(pageId);
7595    
7596                    Session session = null;
7597    
7598                    try {
7599                            session = openSession();
7600    
7601                            WikiPage[] array = new WikiPageImpl[3];
7602    
7603                            array[0] = filterGetByG_N_H_PrevAndNext(session, wikiPage, groupId,
7604                                            nodeId, head, orderByComparator, true);
7605    
7606                            array[1] = wikiPage;
7607    
7608                            array[2] = filterGetByG_N_H_PrevAndNext(session, wikiPage, groupId,
7609                                            nodeId, head, orderByComparator, false);
7610    
7611                            return array;
7612                    }
7613                    catch (Exception e) {
7614                            throw processException(e);
7615                    }
7616                    finally {
7617                            closeSession(session);
7618                    }
7619            }
7620    
7621            protected WikiPage filterGetByG_N_H_PrevAndNext(Session session,
7622                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
7623                    OrderByComparator orderByComparator, boolean previous) {
7624                    StringBundler query = null;
7625    
7626                    if (orderByComparator != null) {
7627                            query = new StringBundler(6 +
7628                                            (orderByComparator.getOrderByFields().length * 6));
7629                    }
7630                    else {
7631                            query = new StringBundler(3);
7632                    }
7633    
7634                    if (getDB().isSupportsInlineDistinct()) {
7635                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
7636                    }
7637                    else {
7638                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
7639                    }
7640    
7641                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7642    
7643                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7644    
7645                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7646    
7647                    if (!getDB().isSupportsInlineDistinct()) {
7648                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
7649                    }
7650    
7651                    if (orderByComparator != null) {
7652                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7653    
7654                            if (orderByConditionFields.length > 0) {
7655                                    query.append(WHERE_AND);
7656                            }
7657    
7658                            for (int i = 0; i < orderByConditionFields.length; i++) {
7659                                    if (getDB().isSupportsInlineDistinct()) {
7660                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7661                                    }
7662                                    else {
7663                                            query.append(_ORDER_BY_ENTITY_TABLE);
7664                                    }
7665    
7666                                    query.append(orderByConditionFields[i]);
7667    
7668                                    if ((i + 1) < orderByConditionFields.length) {
7669                                            if (orderByComparator.isAscending() ^ previous) {
7670                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7671                                            }
7672                                            else {
7673                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7674                                            }
7675                                    }
7676                                    else {
7677                                            if (orderByComparator.isAscending() ^ previous) {
7678                                                    query.append(WHERE_GREATER_THAN);
7679                                            }
7680                                            else {
7681                                                    query.append(WHERE_LESSER_THAN);
7682                                            }
7683                                    }
7684                            }
7685    
7686                            query.append(ORDER_BY_CLAUSE);
7687    
7688                            String[] orderByFields = orderByComparator.getOrderByFields();
7689    
7690                            for (int i = 0; i < orderByFields.length; i++) {
7691                                    if (getDB().isSupportsInlineDistinct()) {
7692                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7693                                    }
7694                                    else {
7695                                            query.append(_ORDER_BY_ENTITY_TABLE);
7696                                    }
7697    
7698                                    query.append(orderByFields[i]);
7699    
7700                                    if ((i + 1) < orderByFields.length) {
7701                                            if (orderByComparator.isAscending() ^ previous) {
7702                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7703                                            }
7704                                            else {
7705                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7706                                            }
7707                                    }
7708                                    else {
7709                                            if (orderByComparator.isAscending() ^ previous) {
7710                                                    query.append(ORDER_BY_ASC);
7711                                            }
7712                                            else {
7713                                                    query.append(ORDER_BY_DESC);
7714                                            }
7715                                    }
7716                            }
7717                    }
7718                    else {
7719                            if (getDB().isSupportsInlineDistinct()) {
7720                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7721                            }
7722                            else {
7723                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
7724                            }
7725                    }
7726    
7727                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7728                                    WikiPage.class.getName(),
7729                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7730    
7731                    SQLQuery q = session.createSQLQuery(sql);
7732    
7733                    q.setFirstResult(0);
7734                    q.setMaxResults(2);
7735    
7736                    if (getDB().isSupportsInlineDistinct()) {
7737                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
7738                    }
7739                    else {
7740                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
7741                    }
7742    
7743                    QueryPos qPos = QueryPos.getInstance(q);
7744    
7745                    qPos.add(groupId);
7746    
7747                    qPos.add(nodeId);
7748    
7749                    qPos.add(head);
7750    
7751                    if (orderByComparator != null) {
7752                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
7753    
7754                            for (Object value : values) {
7755                                    qPos.add(value);
7756                            }
7757                    }
7758    
7759                    List<WikiPage> list = q.list();
7760    
7761                    if (list.size() == 2) {
7762                            return list.get(1);
7763                    }
7764                    else {
7765                            return null;
7766                    }
7767            }
7768    
7769            /**
7770             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; from the database.
7771             *
7772             * @param groupId the group ID
7773             * @param nodeId the node ID
7774             * @param head the head
7775             * @throws SystemException if a system exception occurred
7776             */
7777            public void removeByG_N_H(long groupId, long nodeId, boolean head)
7778                    throws SystemException {
7779                    for (WikiPage wikiPage : findByG_N_H(groupId, nodeId, head,
7780                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7781                            remove(wikiPage);
7782                    }
7783            }
7784    
7785            /**
7786             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
7787             *
7788             * @param groupId the group ID
7789             * @param nodeId the node ID
7790             * @param head the head
7791             * @return the number of matching wiki pages
7792             * @throws SystemException if a system exception occurred
7793             */
7794            public int countByG_N_H(long groupId, long nodeId, boolean head)
7795                    throws SystemException {
7796                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H;
7797    
7798                    Object[] finderArgs = new Object[] { groupId, nodeId, head };
7799    
7800                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7801                                    this);
7802    
7803                    if (count == null) {
7804                            StringBundler query = new StringBundler(4);
7805    
7806                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
7807    
7808                            query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7809    
7810                            query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7811    
7812                            query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7813    
7814                            String sql = query.toString();
7815    
7816                            Session session = null;
7817    
7818                            try {
7819                                    session = openSession();
7820    
7821                                    Query q = session.createQuery(sql);
7822    
7823                                    QueryPos qPos = QueryPos.getInstance(q);
7824    
7825                                    qPos.add(groupId);
7826    
7827                                    qPos.add(nodeId);
7828    
7829                                    qPos.add(head);
7830    
7831                                    count = (Long)q.uniqueResult();
7832    
7833                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7834                            }
7835                            catch (Exception e) {
7836                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7837    
7838                                    throw processException(e);
7839                            }
7840                            finally {
7841                                    closeSession(session);
7842                            }
7843                    }
7844    
7845                    return count.intValue();
7846            }
7847    
7848            /**
7849             * Returns the number of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
7850             *
7851             * @param groupId the group ID
7852             * @param nodeId the node ID
7853             * @param head the head
7854             * @return the number of matching wiki pages that the user has permission to view
7855             * @throws SystemException if a system exception occurred
7856             */
7857            public int filterCountByG_N_H(long groupId, long nodeId, boolean head)
7858                    throws SystemException {
7859                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7860                            return countByG_N_H(groupId, nodeId, head);
7861                    }
7862    
7863                    StringBundler query = new StringBundler(4);
7864    
7865                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
7866    
7867                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
7868    
7869                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
7870    
7871                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
7872    
7873                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7874                                    WikiPage.class.getName(),
7875                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7876    
7877                    Session session = null;
7878    
7879                    try {
7880                            session = openSession();
7881    
7882                            SQLQuery q = session.createSQLQuery(sql);
7883    
7884                            q.addScalar(COUNT_COLUMN_NAME,
7885                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7886    
7887                            QueryPos qPos = QueryPos.getInstance(q);
7888    
7889                            qPos.add(groupId);
7890    
7891                            qPos.add(nodeId);
7892    
7893                            qPos.add(head);
7894    
7895                            Long count = (Long)q.uniqueResult();
7896    
7897                            return count.intValue();
7898                    }
7899                    catch (Exception e) {
7900                            throw processException(e);
7901                    }
7902                    finally {
7903                            closeSession(session);
7904                    }
7905            }
7906    
7907            private static final String _FINDER_COLUMN_G_N_H_GROUPID_2 = "wikiPage.groupId = ? AND ";
7908            private static final String _FINDER_COLUMN_G_N_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
7909            private static final String _FINDER_COLUMN_G_N_H_HEAD_2 = "wikiPage.head = ?";
7910            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7911                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
7912                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_S",
7913                            new String[] {
7914                                    Long.class.getName(), Long.class.getName(),
7915                                    Integer.class.getName(),
7916                                    
7917                            Integer.class.getName(), Integer.class.getName(),
7918                                    OrderByComparator.class.getName()
7919                            });
7920            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7921                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
7922                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_S",
7923                            new String[] {
7924                                    Long.class.getName(), Long.class.getName(),
7925                                    Integer.class.getName()
7926                            },
7927                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
7928                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
7929                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
7930                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
7931                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
7932            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7933                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7934                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_S",
7935                            new String[] {
7936                                    Long.class.getName(), Long.class.getName(),
7937                                    Integer.class.getName()
7938                            });
7939    
7940            /**
7941             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
7942             *
7943             * @param groupId the group ID
7944             * @param nodeId the node ID
7945             * @param status the status
7946             * @return the matching wiki pages
7947             * @throws SystemException if a system exception occurred
7948             */
7949            public List<WikiPage> findByG_N_S(long groupId, long nodeId, int status)
7950                    throws SystemException {
7951                    return findByG_N_S(groupId, nodeId, status, QueryUtil.ALL_POS,
7952                            QueryUtil.ALL_POS, null);
7953            }
7954    
7955            /**
7956             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
7957             *
7958             * <p>
7959             * 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.
7960             * </p>
7961             *
7962             * @param groupId the group ID
7963             * @param nodeId the node ID
7964             * @param status the status
7965             * @param start the lower bound of the range of wiki pages
7966             * @param end the upper bound of the range of wiki pages (not inclusive)
7967             * @return the range of matching wiki pages
7968             * @throws SystemException if a system exception occurred
7969             */
7970            public List<WikiPage> findByG_N_S(long groupId, long nodeId, int status,
7971                    int start, int end) throws SystemException {
7972                    return findByG_N_S(groupId, nodeId, status, start, end, null);
7973            }
7974    
7975            /**
7976             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
7977             *
7978             * <p>
7979             * 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.
7980             * </p>
7981             *
7982             * @param groupId the group ID
7983             * @param nodeId the node ID
7984             * @param status the status
7985             * @param start the lower bound of the range of wiki pages
7986             * @param end the upper bound of the range of wiki pages (not inclusive)
7987             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7988             * @return the ordered range of matching wiki pages
7989             * @throws SystemException if a system exception occurred
7990             */
7991            public List<WikiPage> findByG_N_S(long groupId, long nodeId, int status,
7992                    int start, int end, OrderByComparator orderByComparator)
7993                    throws SystemException {
7994                    boolean pagination = true;
7995                    FinderPath finderPath = null;
7996                    Object[] finderArgs = null;
7997    
7998                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7999                                    (orderByComparator == null)) {
8000                            pagination = false;
8001                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S;
8002                            finderArgs = new Object[] { groupId, nodeId, status };
8003                    }
8004                    else {
8005                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_S;
8006                            finderArgs = new Object[] {
8007                                            groupId, nodeId, status,
8008                                            
8009                                            start, end, orderByComparator
8010                                    };
8011                    }
8012    
8013                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
8014                                    finderArgs, this);
8015    
8016                    if ((list != null) && !list.isEmpty()) {
8017                            for (WikiPage wikiPage : list) {
8018                                    if ((groupId != wikiPage.getGroupId()) ||
8019                                                    (nodeId != wikiPage.getNodeId()) ||
8020                                                    (status != wikiPage.getStatus())) {
8021                                            list = null;
8022    
8023                                            break;
8024                                    }
8025                            }
8026                    }
8027    
8028                    if (list == null) {
8029                            StringBundler query = null;
8030    
8031                            if (orderByComparator != null) {
8032                                    query = new StringBundler(5 +
8033                                                    (orderByComparator.getOrderByFields().length * 3));
8034                            }
8035                            else {
8036                                    query = new StringBundler(5);
8037                            }
8038    
8039                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
8040    
8041                            query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8042    
8043                            query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8044    
8045                            query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8046    
8047                            if (orderByComparator != null) {
8048                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8049                                            orderByComparator);
8050                            }
8051                            else
8052                             if (pagination) {
8053                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8054                            }
8055    
8056                            String sql = query.toString();
8057    
8058                            Session session = null;
8059    
8060                            try {
8061                                    session = openSession();
8062    
8063                                    Query q = session.createQuery(sql);
8064    
8065                                    QueryPos qPos = QueryPos.getInstance(q);
8066    
8067                                    qPos.add(groupId);
8068    
8069                                    qPos.add(nodeId);
8070    
8071                                    qPos.add(status);
8072    
8073                                    if (!pagination) {
8074                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
8075                                                            start, end, false);
8076    
8077                                            Collections.sort(list);
8078    
8079                                            list = new UnmodifiableList<WikiPage>(list);
8080                                    }
8081                                    else {
8082                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
8083                                                            start, end);
8084                                    }
8085    
8086                                    cacheResult(list);
8087    
8088                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8089                            }
8090                            catch (Exception e) {
8091                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8092    
8093                                    throw processException(e);
8094                            }
8095                            finally {
8096                                    closeSession(session);
8097                            }
8098                    }
8099    
8100                    return list;
8101            }
8102    
8103            /**
8104             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8105             *
8106             * @param groupId the group ID
8107             * @param nodeId the node ID
8108             * @param status the status
8109             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8110             * @return the first matching wiki page
8111             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
8112             * @throws SystemException if a system exception occurred
8113             */
8114            public WikiPage findByG_N_S_First(long groupId, long nodeId, int status,
8115                    OrderByComparator orderByComparator)
8116                    throws NoSuchPageException, SystemException {
8117                    WikiPage wikiPage = fetchByG_N_S_First(groupId, nodeId, status,
8118                                    orderByComparator);
8119    
8120                    if (wikiPage != null) {
8121                            return wikiPage;
8122                    }
8123    
8124                    StringBundler msg = new StringBundler(8);
8125    
8126                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8127    
8128                    msg.append("groupId=");
8129                    msg.append(groupId);
8130    
8131                    msg.append(", nodeId=");
8132                    msg.append(nodeId);
8133    
8134                    msg.append(", status=");
8135                    msg.append(status);
8136    
8137                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8138    
8139                    throw new NoSuchPageException(msg.toString());
8140            }
8141    
8142            /**
8143             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8144             *
8145             * @param groupId the group ID
8146             * @param nodeId the node ID
8147             * @param status the status
8148             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8149             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
8150             * @throws SystemException if a system exception occurred
8151             */
8152            public WikiPage fetchByG_N_S_First(long groupId, long nodeId, int status,
8153                    OrderByComparator orderByComparator) throws SystemException {
8154                    List<WikiPage> list = findByG_N_S(groupId, nodeId, status, 0, 1,
8155                                    orderByComparator);
8156    
8157                    if (!list.isEmpty()) {
8158                            return list.get(0);
8159                    }
8160    
8161                    return null;
8162            }
8163    
8164            /**
8165             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8166             *
8167             * @param groupId the group ID
8168             * @param nodeId the node ID
8169             * @param status the status
8170             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8171             * @return the last matching wiki page
8172             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
8173             * @throws SystemException if a system exception occurred
8174             */
8175            public WikiPage findByG_N_S_Last(long groupId, long nodeId, int status,
8176                    OrderByComparator orderByComparator)
8177                    throws NoSuchPageException, SystemException {
8178                    WikiPage wikiPage = fetchByG_N_S_Last(groupId, nodeId, status,
8179                                    orderByComparator);
8180    
8181                    if (wikiPage != null) {
8182                            return wikiPage;
8183                    }
8184    
8185                    StringBundler msg = new StringBundler(8);
8186    
8187                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8188    
8189                    msg.append("groupId=");
8190                    msg.append(groupId);
8191    
8192                    msg.append(", nodeId=");
8193                    msg.append(nodeId);
8194    
8195                    msg.append(", status=");
8196                    msg.append(status);
8197    
8198                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8199    
8200                    throw new NoSuchPageException(msg.toString());
8201            }
8202    
8203            /**
8204             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8205             *
8206             * @param groupId the group ID
8207             * @param nodeId the node ID
8208             * @param status the status
8209             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8210             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
8211             * @throws SystemException if a system exception occurred
8212             */
8213            public WikiPage fetchByG_N_S_Last(long groupId, long nodeId, int status,
8214                    OrderByComparator orderByComparator) throws SystemException {
8215                    int count = countByG_N_S(groupId, nodeId, status);
8216    
8217                    List<WikiPage> list = findByG_N_S(groupId, nodeId, status, count - 1,
8218                                    count, orderByComparator);
8219    
8220                    if (!list.isEmpty()) {
8221                            return list.get(0);
8222                    }
8223    
8224                    return null;
8225            }
8226    
8227            /**
8228             * Returns the wiki pages before and after the current wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
8229             *
8230             * @param pageId the primary key of the current wiki page
8231             * @param groupId the group ID
8232             * @param nodeId the node ID
8233             * @param status the status
8234             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8235             * @return the previous, current, and next wiki page
8236             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
8237             * @throws SystemException if a system exception occurred
8238             */
8239            public WikiPage[] findByG_N_S_PrevAndNext(long pageId, long groupId,
8240                    long nodeId, int status, OrderByComparator orderByComparator)
8241                    throws NoSuchPageException, SystemException {
8242                    WikiPage wikiPage = findByPrimaryKey(pageId);
8243    
8244                    Session session = null;
8245    
8246                    try {
8247                            session = openSession();
8248    
8249                            WikiPage[] array = new WikiPageImpl[3];
8250    
8251                            array[0] = getByG_N_S_PrevAndNext(session, wikiPage, groupId,
8252                                            nodeId, status, orderByComparator, true);
8253    
8254                            array[1] = wikiPage;
8255    
8256                            array[2] = getByG_N_S_PrevAndNext(session, wikiPage, groupId,
8257                                            nodeId, status, orderByComparator, false);
8258    
8259                            return array;
8260                    }
8261                    catch (Exception e) {
8262                            throw processException(e);
8263                    }
8264                    finally {
8265                            closeSession(session);
8266                    }
8267            }
8268    
8269            protected WikiPage getByG_N_S_PrevAndNext(Session session,
8270                    WikiPage wikiPage, long groupId, long nodeId, int status,
8271                    OrderByComparator orderByComparator, boolean previous) {
8272                    StringBundler query = null;
8273    
8274                    if (orderByComparator != null) {
8275                            query = new StringBundler(6 +
8276                                            (orderByComparator.getOrderByFields().length * 6));
8277                    }
8278                    else {
8279                            query = new StringBundler(3);
8280                    }
8281    
8282                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
8283    
8284                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8285    
8286                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8287    
8288                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8289    
8290                    if (orderByComparator != null) {
8291                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8292    
8293                            if (orderByConditionFields.length > 0) {
8294                                    query.append(WHERE_AND);
8295                            }
8296    
8297                            for (int i = 0; i < orderByConditionFields.length; i++) {
8298                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8299                                    query.append(orderByConditionFields[i]);
8300    
8301                                    if ((i + 1) < orderByConditionFields.length) {
8302                                            if (orderByComparator.isAscending() ^ previous) {
8303                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8304                                            }
8305                                            else {
8306                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8307                                            }
8308                                    }
8309                                    else {
8310                                            if (orderByComparator.isAscending() ^ previous) {
8311                                                    query.append(WHERE_GREATER_THAN);
8312                                            }
8313                                            else {
8314                                                    query.append(WHERE_LESSER_THAN);
8315                                            }
8316                                    }
8317                            }
8318    
8319                            query.append(ORDER_BY_CLAUSE);
8320    
8321                            String[] orderByFields = orderByComparator.getOrderByFields();
8322    
8323                            for (int i = 0; i < orderByFields.length; i++) {
8324                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8325                                    query.append(orderByFields[i]);
8326    
8327                                    if ((i + 1) < orderByFields.length) {
8328                                            if (orderByComparator.isAscending() ^ previous) {
8329                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8330                                            }
8331                                            else {
8332                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8333                                            }
8334                                    }
8335                                    else {
8336                                            if (orderByComparator.isAscending() ^ previous) {
8337                                                    query.append(ORDER_BY_ASC);
8338                                            }
8339                                            else {
8340                                                    query.append(ORDER_BY_DESC);
8341                                            }
8342                                    }
8343                            }
8344                    }
8345                    else {
8346                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8347                    }
8348    
8349                    String sql = query.toString();
8350    
8351                    Query q = session.createQuery(sql);
8352    
8353                    q.setFirstResult(0);
8354                    q.setMaxResults(2);
8355    
8356                    QueryPos qPos = QueryPos.getInstance(q);
8357    
8358                    qPos.add(groupId);
8359    
8360                    qPos.add(nodeId);
8361    
8362                    qPos.add(status);
8363    
8364                    if (orderByComparator != null) {
8365                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
8366    
8367                            for (Object value : values) {
8368                                    qPos.add(value);
8369                            }
8370                    }
8371    
8372                    List<WikiPage> list = q.list();
8373    
8374                    if (list.size() == 2) {
8375                            return list.get(1);
8376                    }
8377                    else {
8378                            return null;
8379                    }
8380            }
8381    
8382            /**
8383             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
8384             *
8385             * @param groupId the group ID
8386             * @param nodeId the node ID
8387             * @param status the status
8388             * @return the matching wiki pages that the user has permission to view
8389             * @throws SystemException if a system exception occurred
8390             */
8391            public List<WikiPage> filterFindByG_N_S(long groupId, long nodeId,
8392                    int status) throws SystemException {
8393                    return filterFindByG_N_S(groupId, nodeId, status, QueryUtil.ALL_POS,
8394                            QueryUtil.ALL_POS, null);
8395            }
8396    
8397            /**
8398             * Returns a range of all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
8399             *
8400             * <p>
8401             * 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.
8402             * </p>
8403             *
8404             * @param groupId the group ID
8405             * @param nodeId the node ID
8406             * @param status the status
8407             * @param start the lower bound of the range of wiki pages
8408             * @param end the upper bound of the range of wiki pages (not inclusive)
8409             * @return the range of matching wiki pages that the user has permission to view
8410             * @throws SystemException if a system exception occurred
8411             */
8412            public List<WikiPage> filterFindByG_N_S(long groupId, long nodeId,
8413                    int status, int start, int end) throws SystemException {
8414                    return filterFindByG_N_S(groupId, nodeId, status, start, end, null);
8415            }
8416    
8417            /**
8418             * 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;.
8419             *
8420             * <p>
8421             * 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.
8422             * </p>
8423             *
8424             * @param groupId the group ID
8425             * @param nodeId the node ID
8426             * @param status the status
8427             * @param start the lower bound of the range of wiki pages
8428             * @param end the upper bound of the range of wiki pages (not inclusive)
8429             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8430             * @return the ordered range of matching wiki pages that the user has permission to view
8431             * @throws SystemException if a system exception occurred
8432             */
8433            public List<WikiPage> filterFindByG_N_S(long groupId, long nodeId,
8434                    int status, int start, int end, OrderByComparator orderByComparator)
8435                    throws SystemException {
8436                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8437                            return findByG_N_S(groupId, nodeId, status, start, end,
8438                                    orderByComparator);
8439                    }
8440    
8441                    StringBundler query = null;
8442    
8443                    if (orderByComparator != null) {
8444                            query = new StringBundler(5 +
8445                                            (orderByComparator.getOrderByFields().length * 3));
8446                    }
8447                    else {
8448                            query = new StringBundler(5);
8449                    }
8450    
8451                    if (getDB().isSupportsInlineDistinct()) {
8452                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
8453                    }
8454                    else {
8455                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
8456                    }
8457    
8458                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8459    
8460                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8461    
8462                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8463    
8464                    if (!getDB().isSupportsInlineDistinct()) {
8465                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
8466                    }
8467    
8468                    if (orderByComparator != null) {
8469                            if (getDB().isSupportsInlineDistinct()) {
8470                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8471                                            orderByComparator);
8472                            }
8473                            else {
8474                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8475                                            orderByComparator);
8476                            }
8477                    }
8478                    else {
8479                            if (getDB().isSupportsInlineDistinct()) {
8480                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8481                            }
8482                            else {
8483                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
8484                            }
8485                    }
8486    
8487                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8488                                    WikiPage.class.getName(),
8489                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8490    
8491                    Session session = null;
8492    
8493                    try {
8494                            session = openSession();
8495    
8496                            SQLQuery q = session.createSQLQuery(sql);
8497    
8498                            if (getDB().isSupportsInlineDistinct()) {
8499                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
8500                            }
8501                            else {
8502                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
8503                            }
8504    
8505                            QueryPos qPos = QueryPos.getInstance(q);
8506    
8507                            qPos.add(groupId);
8508    
8509                            qPos.add(nodeId);
8510    
8511                            qPos.add(status);
8512    
8513                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
8514                    }
8515                    catch (Exception e) {
8516                            throw processException(e);
8517                    }
8518                    finally {
8519                            closeSession(session);
8520                    }
8521            }
8522    
8523            /**
8524             * 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;.
8525             *
8526             * @param pageId the primary key of the current wiki page
8527             * @param groupId the group ID
8528             * @param nodeId the node ID
8529             * @param status the status
8530             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8531             * @return the previous, current, and next wiki page
8532             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
8533             * @throws SystemException if a system exception occurred
8534             */
8535            public WikiPage[] filterFindByG_N_S_PrevAndNext(long pageId, long groupId,
8536                    long nodeId, int status, OrderByComparator orderByComparator)
8537                    throws NoSuchPageException, SystemException {
8538                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8539                            return findByG_N_S_PrevAndNext(pageId, groupId, nodeId, status,
8540                                    orderByComparator);
8541                    }
8542    
8543                    WikiPage wikiPage = findByPrimaryKey(pageId);
8544    
8545                    Session session = null;
8546    
8547                    try {
8548                            session = openSession();
8549    
8550                            WikiPage[] array = new WikiPageImpl[3];
8551    
8552                            array[0] = filterGetByG_N_S_PrevAndNext(session, wikiPage, groupId,
8553                                            nodeId, status, orderByComparator, true);
8554    
8555                            array[1] = wikiPage;
8556    
8557                            array[2] = filterGetByG_N_S_PrevAndNext(session, wikiPage, groupId,
8558                                            nodeId, status, orderByComparator, false);
8559    
8560                            return array;
8561                    }
8562                    catch (Exception e) {
8563                            throw processException(e);
8564                    }
8565                    finally {
8566                            closeSession(session);
8567                    }
8568            }
8569    
8570            protected WikiPage filterGetByG_N_S_PrevAndNext(Session session,
8571                    WikiPage wikiPage, long groupId, long nodeId, int status,
8572                    OrderByComparator orderByComparator, boolean previous) {
8573                    StringBundler query = null;
8574    
8575                    if (orderByComparator != null) {
8576                            query = new StringBundler(6 +
8577                                            (orderByComparator.getOrderByFields().length * 6));
8578                    }
8579                    else {
8580                            query = new StringBundler(3);
8581                    }
8582    
8583                    if (getDB().isSupportsInlineDistinct()) {
8584                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
8585                    }
8586                    else {
8587                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
8588                    }
8589    
8590                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8591    
8592                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8593    
8594                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8595    
8596                    if (!getDB().isSupportsInlineDistinct()) {
8597                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
8598                    }
8599    
8600                    if (orderByComparator != null) {
8601                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8602    
8603                            if (orderByConditionFields.length > 0) {
8604                                    query.append(WHERE_AND);
8605                            }
8606    
8607                            for (int i = 0; i < orderByConditionFields.length; i++) {
8608                                    if (getDB().isSupportsInlineDistinct()) {
8609                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8610                                    }
8611                                    else {
8612                                            query.append(_ORDER_BY_ENTITY_TABLE);
8613                                    }
8614    
8615                                    query.append(orderByConditionFields[i]);
8616    
8617                                    if ((i + 1) < orderByConditionFields.length) {
8618                                            if (orderByComparator.isAscending() ^ previous) {
8619                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8620                                            }
8621                                            else {
8622                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8623                                            }
8624                                    }
8625                                    else {
8626                                            if (orderByComparator.isAscending() ^ previous) {
8627                                                    query.append(WHERE_GREATER_THAN);
8628                                            }
8629                                            else {
8630                                                    query.append(WHERE_LESSER_THAN);
8631                                            }
8632                                    }
8633                            }
8634    
8635                            query.append(ORDER_BY_CLAUSE);
8636    
8637                            String[] orderByFields = orderByComparator.getOrderByFields();
8638    
8639                            for (int i = 0; i < orderByFields.length; i++) {
8640                                    if (getDB().isSupportsInlineDistinct()) {
8641                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8642                                    }
8643                                    else {
8644                                            query.append(_ORDER_BY_ENTITY_TABLE);
8645                                    }
8646    
8647                                    query.append(orderByFields[i]);
8648    
8649                                    if ((i + 1) < orderByFields.length) {
8650                                            if (orderByComparator.isAscending() ^ previous) {
8651                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8652                                            }
8653                                            else {
8654                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8655                                            }
8656                                    }
8657                                    else {
8658                                            if (orderByComparator.isAscending() ^ previous) {
8659                                                    query.append(ORDER_BY_ASC);
8660                                            }
8661                                            else {
8662                                                    query.append(ORDER_BY_DESC);
8663                                            }
8664                                    }
8665                            }
8666                    }
8667                    else {
8668                            if (getDB().isSupportsInlineDistinct()) {
8669                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8670                            }
8671                            else {
8672                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
8673                            }
8674                    }
8675    
8676                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8677                                    WikiPage.class.getName(),
8678                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8679    
8680                    SQLQuery q = session.createSQLQuery(sql);
8681    
8682                    q.setFirstResult(0);
8683                    q.setMaxResults(2);
8684    
8685                    if (getDB().isSupportsInlineDistinct()) {
8686                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
8687                    }
8688                    else {
8689                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
8690                    }
8691    
8692                    QueryPos qPos = QueryPos.getInstance(q);
8693    
8694                    qPos.add(groupId);
8695    
8696                    qPos.add(nodeId);
8697    
8698                    qPos.add(status);
8699    
8700                    if (orderByComparator != null) {
8701                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
8702    
8703                            for (Object value : values) {
8704                                    qPos.add(value);
8705                            }
8706                    }
8707    
8708                    List<WikiPage> list = q.list();
8709    
8710                    if (list.size() == 2) {
8711                            return list.get(1);
8712                    }
8713                    else {
8714                            return null;
8715                    }
8716            }
8717    
8718            /**
8719             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63; from the database.
8720             *
8721             * @param groupId the group ID
8722             * @param nodeId the node ID
8723             * @param status the status
8724             * @throws SystemException if a system exception occurred
8725             */
8726            public void removeByG_N_S(long groupId, long nodeId, int status)
8727                    throws SystemException {
8728                    for (WikiPage wikiPage : findByG_N_S(groupId, nodeId, status,
8729                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8730                            remove(wikiPage);
8731                    }
8732            }
8733    
8734            /**
8735             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
8736             *
8737             * @param groupId the group ID
8738             * @param nodeId the node ID
8739             * @param status the status
8740             * @return the number of matching wiki pages
8741             * @throws SystemException if a system exception occurred
8742             */
8743            public int countByG_N_S(long groupId, long nodeId, int status)
8744                    throws SystemException {
8745                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_S;
8746    
8747                    Object[] finderArgs = new Object[] { groupId, nodeId, status };
8748    
8749                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8750                                    this);
8751    
8752                    if (count == null) {
8753                            StringBundler query = new StringBundler(4);
8754    
8755                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8756    
8757                            query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8758    
8759                            query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8760    
8761                            query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8762    
8763                            String sql = query.toString();
8764    
8765                            Session session = null;
8766    
8767                            try {
8768                                    session = openSession();
8769    
8770                                    Query q = session.createQuery(sql);
8771    
8772                                    QueryPos qPos = QueryPos.getInstance(q);
8773    
8774                                    qPos.add(groupId);
8775    
8776                                    qPos.add(nodeId);
8777    
8778                                    qPos.add(status);
8779    
8780                                    count = (Long)q.uniqueResult();
8781    
8782                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8783                            }
8784                            catch (Exception e) {
8785                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8786    
8787                                    throw processException(e);
8788                            }
8789                            finally {
8790                                    closeSession(session);
8791                            }
8792                    }
8793    
8794                    return count.intValue();
8795            }
8796    
8797            /**
8798             * Returns the number of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
8799             *
8800             * @param groupId the group ID
8801             * @param nodeId the node ID
8802             * @param status the status
8803             * @return the number of matching wiki pages that the user has permission to view
8804             * @throws SystemException if a system exception occurred
8805             */
8806            public int filterCountByG_N_S(long groupId, long nodeId, int status)
8807                    throws SystemException {
8808                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8809                            return countByG_N_S(groupId, nodeId, status);
8810                    }
8811    
8812                    StringBundler query = new StringBundler(4);
8813    
8814                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
8815    
8816                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
8817    
8818                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
8819    
8820                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
8821    
8822                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8823                                    WikiPage.class.getName(),
8824                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8825    
8826                    Session session = null;
8827    
8828                    try {
8829                            session = openSession();
8830    
8831                            SQLQuery q = session.createSQLQuery(sql);
8832    
8833                            q.addScalar(COUNT_COLUMN_NAME,
8834                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8835    
8836                            QueryPos qPos = QueryPos.getInstance(q);
8837    
8838                            qPos.add(groupId);
8839    
8840                            qPos.add(nodeId);
8841    
8842                            qPos.add(status);
8843    
8844                            Long count = (Long)q.uniqueResult();
8845    
8846                            return count.intValue();
8847                    }
8848                    catch (Exception e) {
8849                            throw processException(e);
8850                    }
8851                    finally {
8852                            closeSession(session);
8853                    }
8854            }
8855    
8856            private static final String _FINDER_COLUMN_G_N_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
8857            private static final String _FINDER_COLUMN_G_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
8858            private static final String _FINDER_COLUMN_G_N_S_STATUS_2 = "wikiPage.status = ?";
8859            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
8860                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
8861                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_N_S",
8862                            new String[] {
8863                                    Long.class.getName(), Long.class.getName(),
8864                                    Integer.class.getName(),
8865                                    
8866                            Integer.class.getName(), Integer.class.getName(),
8867                                    OrderByComparator.class.getName()
8868                            });
8869            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
8870                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
8871                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_N_S",
8872                            new String[] {
8873                                    Long.class.getName(), Long.class.getName(),
8874                                    Integer.class.getName()
8875                            },
8876                            WikiPageModelImpl.USERID_COLUMN_BITMASK |
8877                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
8878                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
8879                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
8880                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
8881            public static final FinderPath FINDER_PATH_COUNT_BY_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
8882                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8883                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_N_S",
8884                            new String[] {
8885                                    Long.class.getName(), Long.class.getName(),
8886                                    Integer.class.getName()
8887                            });
8888    
8889            /**
8890             * Returns all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
8891             *
8892             * @param userId the user ID
8893             * @param nodeId the node ID
8894             * @param status the status
8895             * @return the matching wiki pages
8896             * @throws SystemException if a system exception occurred
8897             */
8898            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status)
8899                    throws SystemException {
8900                    return findByU_N_S(userId, nodeId, status, QueryUtil.ALL_POS,
8901                            QueryUtil.ALL_POS, null);
8902            }
8903    
8904            /**
8905             * Returns a range of all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
8906             *
8907             * <p>
8908             * 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.
8909             * </p>
8910             *
8911             * @param userId the user ID
8912             * @param nodeId the node ID
8913             * @param status the status
8914             * @param start the lower bound of the range of wiki pages
8915             * @param end the upper bound of the range of wiki pages (not inclusive)
8916             * @return the range of matching wiki pages
8917             * @throws SystemException if a system exception occurred
8918             */
8919            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status,
8920                    int start, int end) throws SystemException {
8921                    return findByU_N_S(userId, nodeId, status, start, end, null);
8922            }
8923    
8924            /**
8925             * Returns an ordered range of all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
8926             *
8927             * <p>
8928             * 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.
8929             * </p>
8930             *
8931             * @param userId the user ID
8932             * @param nodeId the node ID
8933             * @param status the status
8934             * @param start the lower bound of the range of wiki pages
8935             * @param end the upper bound of the range of wiki pages (not inclusive)
8936             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8937             * @return the ordered range of matching wiki pages
8938             * @throws SystemException if a system exception occurred
8939             */
8940            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status,
8941                    int start, int end, OrderByComparator orderByComparator)
8942                    throws SystemException {
8943                    boolean pagination = true;
8944                    FinderPath finderPath = null;
8945                    Object[] finderArgs = null;
8946    
8947                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8948                                    (orderByComparator == null)) {
8949                            pagination = false;
8950                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S;
8951                            finderArgs = new Object[] { userId, nodeId, status };
8952                    }
8953                    else {
8954                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_N_S;
8955                            finderArgs = new Object[] {
8956                                            userId, nodeId, status,
8957                                            
8958                                            start, end, orderByComparator
8959                                    };
8960                    }
8961    
8962                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
8963                                    finderArgs, this);
8964    
8965                    if ((list != null) && !list.isEmpty()) {
8966                            for (WikiPage wikiPage : list) {
8967                                    if ((userId != wikiPage.getUserId()) ||
8968                                                    (nodeId != wikiPage.getNodeId()) ||
8969                                                    (status != wikiPage.getStatus())) {
8970                                            list = null;
8971    
8972                                            break;
8973                                    }
8974                            }
8975                    }
8976    
8977                    if (list == null) {
8978                            StringBundler query = null;
8979    
8980                            if (orderByComparator != null) {
8981                                    query = new StringBundler(5 +
8982                                                    (orderByComparator.getOrderByFields().length * 3));
8983                            }
8984                            else {
8985                                    query = new StringBundler(5);
8986                            }
8987    
8988                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
8989    
8990                            query.append(_FINDER_COLUMN_U_N_S_USERID_2);
8991    
8992                            query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
8993    
8994                            query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
8995    
8996                            if (orderByComparator != null) {
8997                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8998                                            orderByComparator);
8999                            }
9000                            else
9001                             if (pagination) {
9002                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
9003                            }
9004    
9005                            String sql = query.toString();
9006    
9007                            Session session = null;
9008    
9009                            try {
9010                                    session = openSession();
9011    
9012                                    Query q = session.createQuery(sql);
9013    
9014                                    QueryPos qPos = QueryPos.getInstance(q);
9015    
9016                                    qPos.add(userId);
9017    
9018                                    qPos.add(nodeId);
9019    
9020                                    qPos.add(status);
9021    
9022                                    if (!pagination) {
9023                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
9024                                                            start, end, false);
9025    
9026                                            Collections.sort(list);
9027    
9028                                            list = new UnmodifiableList<WikiPage>(list);
9029                                    }
9030                                    else {
9031                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
9032                                                            start, end);
9033                                    }
9034    
9035                                    cacheResult(list);
9036    
9037                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9038                            }
9039                            catch (Exception e) {
9040                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9041    
9042                                    throw processException(e);
9043                            }
9044                            finally {
9045                                    closeSession(session);
9046                            }
9047                    }
9048    
9049                    return list;
9050            }
9051    
9052            /**
9053             * Returns the first wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9054             *
9055             * @param userId the user ID
9056             * @param nodeId the node ID
9057             * @param status the status
9058             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9059             * @return the first matching wiki page
9060             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9061             * @throws SystemException if a system exception occurred
9062             */
9063            public WikiPage findByU_N_S_First(long userId, long nodeId, int status,
9064                    OrderByComparator orderByComparator)
9065                    throws NoSuchPageException, SystemException {
9066                    WikiPage wikiPage = fetchByU_N_S_First(userId, nodeId, status,
9067                                    orderByComparator);
9068    
9069                    if (wikiPage != null) {
9070                            return wikiPage;
9071                    }
9072    
9073                    StringBundler msg = new StringBundler(8);
9074    
9075                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9076    
9077                    msg.append("userId=");
9078                    msg.append(userId);
9079    
9080                    msg.append(", nodeId=");
9081                    msg.append(nodeId);
9082    
9083                    msg.append(", status=");
9084                    msg.append(status);
9085    
9086                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9087    
9088                    throw new NoSuchPageException(msg.toString());
9089            }
9090    
9091            /**
9092             * Returns the first wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9093             *
9094             * @param userId the user ID
9095             * @param nodeId the node ID
9096             * @param status the status
9097             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9098             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
9099             * @throws SystemException if a system exception occurred
9100             */
9101            public WikiPage fetchByU_N_S_First(long userId, long nodeId, int status,
9102                    OrderByComparator orderByComparator) throws SystemException {
9103                    List<WikiPage> list = findByU_N_S(userId, nodeId, status, 0, 1,
9104                                    orderByComparator);
9105    
9106                    if (!list.isEmpty()) {
9107                            return list.get(0);
9108                    }
9109    
9110                    return null;
9111            }
9112    
9113            /**
9114             * Returns the last wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9115             *
9116             * @param userId the user ID
9117             * @param nodeId the node ID
9118             * @param status the status
9119             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9120             * @return the last matching wiki page
9121             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9122             * @throws SystemException if a system exception occurred
9123             */
9124            public WikiPage findByU_N_S_Last(long userId, long nodeId, int status,
9125                    OrderByComparator orderByComparator)
9126                    throws NoSuchPageException, SystemException {
9127                    WikiPage wikiPage = fetchByU_N_S_Last(userId, nodeId, status,
9128                                    orderByComparator);
9129    
9130                    if (wikiPage != null) {
9131                            return wikiPage;
9132                    }
9133    
9134                    StringBundler msg = new StringBundler(8);
9135    
9136                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9137    
9138                    msg.append("userId=");
9139                    msg.append(userId);
9140    
9141                    msg.append(", nodeId=");
9142                    msg.append(nodeId);
9143    
9144                    msg.append(", status=");
9145                    msg.append(status);
9146    
9147                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9148    
9149                    throw new NoSuchPageException(msg.toString());
9150            }
9151    
9152            /**
9153             * Returns the last wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9154             *
9155             * @param userId the user ID
9156             * @param nodeId the node ID
9157             * @param status the status
9158             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9159             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
9160             * @throws SystemException if a system exception occurred
9161             */
9162            public WikiPage fetchByU_N_S_Last(long userId, long nodeId, int status,
9163                    OrderByComparator orderByComparator) throws SystemException {
9164                    int count = countByU_N_S(userId, nodeId, status);
9165    
9166                    List<WikiPage> list = findByU_N_S(userId, nodeId, status, count - 1,
9167                                    count, orderByComparator);
9168    
9169                    if (!list.isEmpty()) {
9170                            return list.get(0);
9171                    }
9172    
9173                    return null;
9174            }
9175    
9176            /**
9177             * Returns the wiki pages before and after the current wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
9178             *
9179             * @param pageId the primary key of the current wiki page
9180             * @param userId the user ID
9181             * @param nodeId the node ID
9182             * @param status the status
9183             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9184             * @return the previous, current, and next wiki page
9185             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
9186             * @throws SystemException if a system exception occurred
9187             */
9188            public WikiPage[] findByU_N_S_PrevAndNext(long pageId, long userId,
9189                    long nodeId, int status, OrderByComparator orderByComparator)
9190                    throws NoSuchPageException, SystemException {
9191                    WikiPage wikiPage = findByPrimaryKey(pageId);
9192    
9193                    Session session = null;
9194    
9195                    try {
9196                            session = openSession();
9197    
9198                            WikiPage[] array = new WikiPageImpl[3];
9199    
9200                            array[0] = getByU_N_S_PrevAndNext(session, wikiPage, userId,
9201                                            nodeId, status, orderByComparator, true);
9202    
9203                            array[1] = wikiPage;
9204    
9205                            array[2] = getByU_N_S_PrevAndNext(session, wikiPage, userId,
9206                                            nodeId, status, orderByComparator, false);
9207    
9208                            return array;
9209                    }
9210                    catch (Exception e) {
9211                            throw processException(e);
9212                    }
9213                    finally {
9214                            closeSession(session);
9215                    }
9216            }
9217    
9218            protected WikiPage getByU_N_S_PrevAndNext(Session session,
9219                    WikiPage wikiPage, long userId, long nodeId, int status,
9220                    OrderByComparator orderByComparator, boolean previous) {
9221                    StringBundler query = null;
9222    
9223                    if (orderByComparator != null) {
9224                            query = new StringBundler(6 +
9225                                            (orderByComparator.getOrderByFields().length * 6));
9226                    }
9227                    else {
9228                            query = new StringBundler(3);
9229                    }
9230    
9231                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
9232    
9233                    query.append(_FINDER_COLUMN_U_N_S_USERID_2);
9234    
9235                    query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
9236    
9237                    query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
9238    
9239                    if (orderByComparator != null) {
9240                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9241    
9242                            if (orderByConditionFields.length > 0) {
9243                                    query.append(WHERE_AND);
9244                            }
9245    
9246                            for (int i = 0; i < orderByConditionFields.length; i++) {
9247                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9248                                    query.append(orderByConditionFields[i]);
9249    
9250                                    if ((i + 1) < orderByConditionFields.length) {
9251                                            if (orderByComparator.isAscending() ^ previous) {
9252                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9253                                            }
9254                                            else {
9255                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9256                                            }
9257                                    }
9258                                    else {
9259                                            if (orderByComparator.isAscending() ^ previous) {
9260                                                    query.append(WHERE_GREATER_THAN);
9261                                            }
9262                                            else {
9263                                                    query.append(WHERE_LESSER_THAN);
9264                                            }
9265                                    }
9266                            }
9267    
9268                            query.append(ORDER_BY_CLAUSE);
9269    
9270                            String[] orderByFields = orderByComparator.getOrderByFields();
9271    
9272                            for (int i = 0; i < orderByFields.length; i++) {
9273                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9274                                    query.append(orderByFields[i]);
9275    
9276                                    if ((i + 1) < orderByFields.length) {
9277                                            if (orderByComparator.isAscending() ^ previous) {
9278                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9279                                            }
9280                                            else {
9281                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9282                                            }
9283                                    }
9284                                    else {
9285                                            if (orderByComparator.isAscending() ^ previous) {
9286                                                    query.append(ORDER_BY_ASC);
9287                                            }
9288                                            else {
9289                                                    query.append(ORDER_BY_DESC);
9290                                            }
9291                                    }
9292                            }
9293                    }
9294                    else {
9295                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
9296                    }
9297    
9298                    String sql = query.toString();
9299    
9300                    Query q = session.createQuery(sql);
9301    
9302                    q.setFirstResult(0);
9303                    q.setMaxResults(2);
9304    
9305                    QueryPos qPos = QueryPos.getInstance(q);
9306    
9307                    qPos.add(userId);
9308    
9309                    qPos.add(nodeId);
9310    
9311                    qPos.add(status);
9312    
9313                    if (orderByComparator != null) {
9314                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
9315    
9316                            for (Object value : values) {
9317                                    qPos.add(value);
9318                            }
9319                    }
9320    
9321                    List<WikiPage> list = q.list();
9322    
9323                    if (list.size() == 2) {
9324                            return list.get(1);
9325                    }
9326                    else {
9327                            return null;
9328                    }
9329            }
9330    
9331            /**
9332             * Removes all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63; from the database.
9333             *
9334             * @param userId the user ID
9335             * @param nodeId the node ID
9336             * @param status the status
9337             * @throws SystemException if a system exception occurred
9338             */
9339            public void removeByU_N_S(long userId, long nodeId, int status)
9340                    throws SystemException {
9341                    for (WikiPage wikiPage : findByU_N_S(userId, nodeId, status,
9342                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9343                            remove(wikiPage);
9344                    }
9345            }
9346    
9347            /**
9348             * Returns the number of wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
9349             *
9350             * @param userId the user ID
9351             * @param nodeId the node ID
9352             * @param status the status
9353             * @return the number of matching wiki pages
9354             * @throws SystemException if a system exception occurred
9355             */
9356            public int countByU_N_S(long userId, long nodeId, int status)
9357                    throws SystemException {
9358                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_N_S;
9359    
9360                    Object[] finderArgs = new Object[] { userId, nodeId, status };
9361    
9362                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9363                                    this);
9364    
9365                    if (count == null) {
9366                            StringBundler query = new StringBundler(4);
9367    
9368                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
9369    
9370                            query.append(_FINDER_COLUMN_U_N_S_USERID_2);
9371    
9372                            query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
9373    
9374                            query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
9375    
9376                            String sql = query.toString();
9377    
9378                            Session session = null;
9379    
9380                            try {
9381                                    session = openSession();
9382    
9383                                    Query q = session.createQuery(sql);
9384    
9385                                    QueryPos qPos = QueryPos.getInstance(q);
9386    
9387                                    qPos.add(userId);
9388    
9389                                    qPos.add(nodeId);
9390    
9391                                    qPos.add(status);
9392    
9393                                    count = (Long)q.uniqueResult();
9394    
9395                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9396                            }
9397                            catch (Exception e) {
9398                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9399    
9400                                    throw processException(e);
9401                            }
9402                            finally {
9403                                    closeSession(session);
9404                            }
9405                    }
9406    
9407                    return count.intValue();
9408            }
9409    
9410            private static final String _FINDER_COLUMN_U_N_S_USERID_2 = "wikiPage.userId = ? AND ";
9411            private static final String _FINDER_COLUMN_U_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
9412            private static final String _FINDER_COLUMN_U_N_S_STATUS_2 = "wikiPage.status = ?";
9413            public static final FinderPath FINDER_PATH_FETCH_BY_N_T_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9414                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
9415                            FINDER_CLASS_NAME_ENTITY, "fetchByN_T_V",
9416                            new String[] {
9417                                    Long.class.getName(), String.class.getName(),
9418                                    Double.class.getName()
9419                            },
9420                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
9421                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
9422                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
9423            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9424                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9425                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T_V",
9426                            new String[] {
9427                                    Long.class.getName(), String.class.getName(),
9428                                    Double.class.getName()
9429                            });
9430    
9431            /**
9432             * 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.
9433             *
9434             * @param nodeId the node ID
9435             * @param title the title
9436             * @param version the version
9437             * @return the matching wiki page
9438             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9439             * @throws SystemException if a system exception occurred
9440             */
9441            public WikiPage findByN_T_V(long nodeId, String title, double version)
9442                    throws NoSuchPageException, SystemException {
9443                    WikiPage wikiPage = fetchByN_T_V(nodeId, title, version);
9444    
9445                    if (wikiPage == null) {
9446                            StringBundler msg = new StringBundler(8);
9447    
9448                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9449    
9450                            msg.append("nodeId=");
9451                            msg.append(nodeId);
9452    
9453                            msg.append(", title=");
9454                            msg.append(title);
9455    
9456                            msg.append(", version=");
9457                            msg.append(version);
9458    
9459                            msg.append(StringPool.CLOSE_CURLY_BRACE);
9460    
9461                            if (_log.isWarnEnabled()) {
9462                                    _log.warn(msg.toString());
9463                            }
9464    
9465                            throw new NoSuchPageException(msg.toString());
9466                    }
9467    
9468                    return wikiPage;
9469            }
9470    
9471            /**
9472             * 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.
9473             *
9474             * @param nodeId the node ID
9475             * @param title the title
9476             * @param version the version
9477             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
9478             * @throws SystemException if a system exception occurred
9479             */
9480            public WikiPage fetchByN_T_V(long nodeId, String title, double version)
9481                    throws SystemException {
9482                    return fetchByN_T_V(nodeId, title, version, true);
9483            }
9484    
9485            /**
9486             * 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.
9487             *
9488             * @param nodeId the node ID
9489             * @param title the title
9490             * @param version the version
9491             * @param retrieveFromCache whether to use the finder cache
9492             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
9493             * @throws SystemException if a system exception occurred
9494             */
9495            public WikiPage fetchByN_T_V(long nodeId, String title, double version,
9496                    boolean retrieveFromCache) throws SystemException {
9497                    Object[] finderArgs = new Object[] { nodeId, title, version };
9498    
9499                    Object result = null;
9500    
9501                    if (retrieveFromCache) {
9502                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T_V,
9503                                            finderArgs, this);
9504                    }
9505    
9506                    if (result instanceof WikiPage) {
9507                            WikiPage wikiPage = (WikiPage)result;
9508    
9509                            if ((nodeId != wikiPage.getNodeId()) ||
9510                                            !Validator.equals(title, wikiPage.getTitle()) ||
9511                                            (version != wikiPage.getVersion())) {
9512                                    result = null;
9513                            }
9514                    }
9515    
9516                    if (result == null) {
9517                            StringBundler query = new StringBundler(5);
9518    
9519                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
9520    
9521                            query.append(_FINDER_COLUMN_N_T_V_NODEID_2);
9522    
9523                            if (title == null) {
9524                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_1);
9525                            }
9526                            else {
9527                                    if (title.equals(StringPool.BLANK)) {
9528                                            query.append(_FINDER_COLUMN_N_T_V_TITLE_3);
9529                                    }
9530                                    else {
9531                                            query.append(_FINDER_COLUMN_N_T_V_TITLE_2);
9532                                    }
9533                            }
9534    
9535                            query.append(_FINDER_COLUMN_N_T_V_VERSION_2);
9536    
9537                            String sql = query.toString();
9538    
9539                            Session session = null;
9540    
9541                            try {
9542                                    session = openSession();
9543    
9544                                    Query q = session.createQuery(sql);
9545    
9546                                    QueryPos qPos = QueryPos.getInstance(q);
9547    
9548                                    qPos.add(nodeId);
9549    
9550                                    if (title != null) {
9551                                            qPos.add(title);
9552                                    }
9553    
9554                                    qPos.add(version);
9555    
9556                                    List<WikiPage> list = q.list();
9557    
9558                                    if (list.isEmpty()) {
9559                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
9560                                                    finderArgs, list);
9561                                    }
9562                                    else {
9563                                            WikiPage wikiPage = list.get(0);
9564    
9565                                            result = wikiPage;
9566    
9567                                            cacheResult(wikiPage);
9568    
9569                                            if ((wikiPage.getNodeId() != nodeId) ||
9570                                                            (wikiPage.getTitle() == null) ||
9571                                                            !wikiPage.getTitle().equals(title) ||
9572                                                            (wikiPage.getVersion() != version)) {
9573                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
9574                                                            finderArgs, wikiPage);
9575                                            }
9576                                    }
9577                            }
9578                            catch (Exception e) {
9579                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V,
9580                                            finderArgs);
9581    
9582                                    throw processException(e);
9583                            }
9584                            finally {
9585                                    closeSession(session);
9586                            }
9587                    }
9588    
9589                    if (result instanceof List<?>) {
9590                            return null;
9591                    }
9592                    else {
9593                            return (WikiPage)result;
9594                    }
9595            }
9596    
9597            /**
9598             * Removes the wiki page where nodeId = &#63; and title = &#63; and version = &#63; from the database.
9599             *
9600             * @param nodeId the node ID
9601             * @param title the title
9602             * @param version the version
9603             * @return the wiki page that was removed
9604             * @throws SystemException if a system exception occurred
9605             */
9606            public WikiPage removeByN_T_V(long nodeId, String title, double version)
9607                    throws NoSuchPageException, SystemException {
9608                    WikiPage wikiPage = findByN_T_V(nodeId, title, version);
9609    
9610                    return remove(wikiPage);
9611            }
9612    
9613            /**
9614             * Returns the number of wiki pages where nodeId = &#63; and title = &#63; and version = &#63;.
9615             *
9616             * @param nodeId the node ID
9617             * @param title the title
9618             * @param version the version
9619             * @return the number of matching wiki pages
9620             * @throws SystemException if a system exception occurred
9621             */
9622            public int countByN_T_V(long nodeId, String title, double version)
9623                    throws SystemException {
9624                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T_V;
9625    
9626                    Object[] finderArgs = new Object[] { nodeId, title, version };
9627    
9628                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9629                                    this);
9630    
9631                    if (count == null) {
9632                            StringBundler query = new StringBundler(4);
9633    
9634                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
9635    
9636                            query.append(_FINDER_COLUMN_N_T_V_NODEID_2);
9637    
9638                            if (title == null) {
9639                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_1);
9640                            }
9641                            else {
9642                                    if (title.equals(StringPool.BLANK)) {
9643                                            query.append(_FINDER_COLUMN_N_T_V_TITLE_3);
9644                                    }
9645                                    else {
9646                                            query.append(_FINDER_COLUMN_N_T_V_TITLE_2);
9647                                    }
9648                            }
9649    
9650                            query.append(_FINDER_COLUMN_N_T_V_VERSION_2);
9651    
9652                            String sql = query.toString();
9653    
9654                            Session session = null;
9655    
9656                            try {
9657                                    session = openSession();
9658    
9659                                    Query q = session.createQuery(sql);
9660    
9661                                    QueryPos qPos = QueryPos.getInstance(q);
9662    
9663                                    qPos.add(nodeId);
9664    
9665                                    if (title != null) {
9666                                            qPos.add(title);
9667                                    }
9668    
9669                                    qPos.add(version);
9670    
9671                                    count = (Long)q.uniqueResult();
9672    
9673                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9674                            }
9675                            catch (Exception e) {
9676                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9677    
9678                                    throw processException(e);
9679                            }
9680                            finally {
9681                                    closeSession(session);
9682                            }
9683                    }
9684    
9685                    return count.intValue();
9686            }
9687    
9688            private static final String _FINDER_COLUMN_N_T_V_NODEID_2 = "wikiPage.nodeId = ? AND ";
9689            private static final String _FINDER_COLUMN_N_T_V_TITLE_1 = "wikiPage.title IS NULL AND ";
9690            private static final String _FINDER_COLUMN_N_T_V_TITLE_2 = "lower(wikiPage.title) = lower(CAST_TEXT(?)) AND ";
9691            private static final String _FINDER_COLUMN_N_T_V_TITLE_3 = "(wikiPage.title IS NULL OR lower(wikiPage.title) = lower(CAST_TEXT(?))) AND ";
9692            private static final String _FINDER_COLUMN_N_T_V_VERSION_2 = "wikiPage.version = ?";
9693            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9694                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
9695                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_T_H",
9696                            new String[] {
9697                                    Long.class.getName(), String.class.getName(),
9698                                    Boolean.class.getName(),
9699                                    
9700                            Integer.class.getName(), Integer.class.getName(),
9701                                    OrderByComparator.class.getName()
9702                            });
9703            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9704                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
9705                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_T_H",
9706                            new String[] {
9707                                    Long.class.getName(), String.class.getName(),
9708                                    Boolean.class.getName()
9709                            },
9710                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
9711                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
9712                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
9713                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
9714            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9715                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9716                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T_H",
9717                            new String[] {
9718                                    Long.class.getName(), String.class.getName(),
9719                                    Boolean.class.getName()
9720                            });
9721    
9722            /**
9723             * Returns all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
9724             *
9725             * @param nodeId the node ID
9726             * @param title the title
9727             * @param head the head
9728             * @return the matching wiki pages
9729             * @throws SystemException if a system exception occurred
9730             */
9731            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head)
9732                    throws SystemException {
9733                    return findByN_T_H(nodeId, title, head, QueryUtil.ALL_POS,
9734                            QueryUtil.ALL_POS, null);
9735            }
9736    
9737            /**
9738             * Returns a range of all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
9739             *
9740             * <p>
9741             * 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.
9742             * </p>
9743             *
9744             * @param nodeId the node ID
9745             * @param title the title
9746             * @param head the head
9747             * @param start the lower bound of the range of wiki pages
9748             * @param end the upper bound of the range of wiki pages (not inclusive)
9749             * @return the range of matching wiki pages
9750             * @throws SystemException if a system exception occurred
9751             */
9752            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head,
9753                    int start, int end) throws SystemException {
9754                    return findByN_T_H(nodeId, title, head, start, end, null);
9755            }
9756    
9757            /**
9758             * Returns an ordered range of all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
9759             *
9760             * <p>
9761             * 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.
9762             * </p>
9763             *
9764             * @param nodeId the node ID
9765             * @param title the title
9766             * @param head the head
9767             * @param start the lower bound of the range of wiki pages
9768             * @param end the upper bound of the range of wiki pages (not inclusive)
9769             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9770             * @return the ordered range of matching wiki pages
9771             * @throws SystemException if a system exception occurred
9772             */
9773            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head,
9774                    int start, int end, OrderByComparator orderByComparator)
9775                    throws SystemException {
9776                    boolean pagination = true;
9777                    FinderPath finderPath = null;
9778                    Object[] finderArgs = null;
9779    
9780                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9781                                    (orderByComparator == null)) {
9782                            pagination = false;
9783                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H;
9784                            finderArgs = new Object[] { nodeId, title, head };
9785                    }
9786                    else {
9787                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_H;
9788                            finderArgs = new Object[] {
9789                                            nodeId, title, head,
9790                                            
9791                                            start, end, orderByComparator
9792                                    };
9793                    }
9794    
9795                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
9796                                    finderArgs, this);
9797    
9798                    if ((list != null) && !list.isEmpty()) {
9799                            for (WikiPage wikiPage : list) {
9800                                    if ((nodeId != wikiPage.getNodeId()) ||
9801                                                    !Validator.equals(title, wikiPage.getTitle()) ||
9802                                                    (head != wikiPage.getHead())) {
9803                                            list = null;
9804    
9805                                            break;
9806                                    }
9807                            }
9808                    }
9809    
9810                    if (list == null) {
9811                            StringBundler query = null;
9812    
9813                            if (orderByComparator != null) {
9814                                    query = new StringBundler(5 +
9815                                                    (orderByComparator.getOrderByFields().length * 3));
9816                            }
9817                            else {
9818                                    query = new StringBundler(5);
9819                            }
9820    
9821                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
9822    
9823                            query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
9824    
9825                            if (title == null) {
9826                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
9827                            }
9828                            else {
9829                                    if (title.equals(StringPool.BLANK)) {
9830                                            query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
9831                                    }
9832                                    else {
9833                                            query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
9834                                    }
9835                            }
9836    
9837                            query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
9838    
9839                            if (orderByComparator != null) {
9840                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9841                                            orderByComparator);
9842                            }
9843                            else
9844                             if (pagination) {
9845                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
9846                            }
9847    
9848                            String sql = query.toString();
9849    
9850                            Session session = null;
9851    
9852                            try {
9853                                    session = openSession();
9854    
9855                                    Query q = session.createQuery(sql);
9856    
9857                                    QueryPos qPos = QueryPos.getInstance(q);
9858    
9859                                    qPos.add(nodeId);
9860    
9861                                    if (title != null) {
9862                                            qPos.add(title);
9863                                    }
9864    
9865                                    qPos.add(head);
9866    
9867                                    if (!pagination) {
9868                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
9869                                                            start, end, false);
9870    
9871                                            Collections.sort(list);
9872    
9873                                            list = new UnmodifiableList<WikiPage>(list);
9874                                    }
9875                                    else {
9876                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
9877                                                            start, end);
9878                                    }
9879    
9880                                    cacheResult(list);
9881    
9882                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9883                            }
9884                            catch (Exception e) {
9885                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9886    
9887                                    throw processException(e);
9888                            }
9889                            finally {
9890                                    closeSession(session);
9891                            }
9892                    }
9893    
9894                    return list;
9895            }
9896    
9897            /**
9898             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
9899             *
9900             * @param nodeId the node ID
9901             * @param title the title
9902             * @param head the head
9903             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9904             * @return the first matching wiki page
9905             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9906             * @throws SystemException if a system exception occurred
9907             */
9908            public WikiPage findByN_T_H_First(long nodeId, String title, boolean head,
9909                    OrderByComparator orderByComparator)
9910                    throws NoSuchPageException, SystemException {
9911                    WikiPage wikiPage = fetchByN_T_H_First(nodeId, title, head,
9912                                    orderByComparator);
9913    
9914                    if (wikiPage != null) {
9915                            return wikiPage;
9916                    }
9917    
9918                    StringBundler msg = new StringBundler(8);
9919    
9920                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9921    
9922                    msg.append("nodeId=");
9923                    msg.append(nodeId);
9924    
9925                    msg.append(", title=");
9926                    msg.append(title);
9927    
9928                    msg.append(", head=");
9929                    msg.append(head);
9930    
9931                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9932    
9933                    throw new NoSuchPageException(msg.toString());
9934            }
9935    
9936            /**
9937             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
9938             *
9939             * @param nodeId the node ID
9940             * @param title the title
9941             * @param head the head
9942             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9943             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
9944             * @throws SystemException if a system exception occurred
9945             */
9946            public WikiPage fetchByN_T_H_First(long nodeId, String title, boolean head,
9947                    OrderByComparator orderByComparator) throws SystemException {
9948                    List<WikiPage> list = findByN_T_H(nodeId, title, head, 0, 1,
9949                                    orderByComparator);
9950    
9951                    if (!list.isEmpty()) {
9952                            return list.get(0);
9953                    }
9954    
9955                    return null;
9956            }
9957    
9958            /**
9959             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
9960             *
9961             * @param nodeId the node ID
9962             * @param title the title
9963             * @param head the head
9964             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9965             * @return the last matching wiki page
9966             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9967             * @throws SystemException if a system exception occurred
9968             */
9969            public WikiPage findByN_T_H_Last(long nodeId, String title, boolean head,
9970                    OrderByComparator orderByComparator)
9971                    throws NoSuchPageException, SystemException {
9972                    WikiPage wikiPage = fetchByN_T_H_Last(nodeId, title, head,
9973                                    orderByComparator);
9974    
9975                    if (wikiPage != null) {
9976                            return wikiPage;
9977                    }
9978    
9979                    StringBundler msg = new StringBundler(8);
9980    
9981                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9982    
9983                    msg.append("nodeId=");
9984                    msg.append(nodeId);
9985    
9986                    msg.append(", title=");
9987                    msg.append(title);
9988    
9989                    msg.append(", head=");
9990                    msg.append(head);
9991    
9992                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9993    
9994                    throw new NoSuchPageException(msg.toString());
9995            }
9996    
9997            /**
9998             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
9999             *
10000             * @param nodeId the node ID
10001             * @param title the title
10002             * @param head the head
10003             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10004             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
10005             * @throws SystemException if a system exception occurred
10006             */
10007            public WikiPage fetchByN_T_H_Last(long nodeId, String title, boolean head,
10008                    OrderByComparator orderByComparator) throws SystemException {
10009                    int count = countByN_T_H(nodeId, title, head);
10010    
10011                    List<WikiPage> list = findByN_T_H(nodeId, title, head, count - 1,
10012                                    count, orderByComparator);
10013    
10014                    if (!list.isEmpty()) {
10015                            return list.get(0);
10016                    }
10017    
10018                    return null;
10019            }
10020    
10021            /**
10022             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
10023             *
10024             * @param pageId the primary key of the current wiki page
10025             * @param nodeId the node ID
10026             * @param title the title
10027             * @param head the head
10028             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10029             * @return the previous, current, and next wiki page
10030             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
10031             * @throws SystemException if a system exception occurred
10032             */
10033            public WikiPage[] findByN_T_H_PrevAndNext(long pageId, long nodeId,
10034                    String title, boolean head, OrderByComparator orderByComparator)
10035                    throws NoSuchPageException, SystemException {
10036                    WikiPage wikiPage = findByPrimaryKey(pageId);
10037    
10038                    Session session = null;
10039    
10040                    try {
10041                            session = openSession();
10042    
10043                            WikiPage[] array = new WikiPageImpl[3];
10044    
10045                            array[0] = getByN_T_H_PrevAndNext(session, wikiPage, nodeId, title,
10046                                            head, orderByComparator, true);
10047    
10048                            array[1] = wikiPage;
10049    
10050                            array[2] = getByN_T_H_PrevAndNext(session, wikiPage, nodeId, title,
10051                                            head, orderByComparator, false);
10052    
10053                            return array;
10054                    }
10055                    catch (Exception e) {
10056                            throw processException(e);
10057                    }
10058                    finally {
10059                            closeSession(session);
10060                    }
10061            }
10062    
10063            protected WikiPage getByN_T_H_PrevAndNext(Session session,
10064                    WikiPage wikiPage, long nodeId, String title, boolean head,
10065                    OrderByComparator orderByComparator, boolean previous) {
10066                    StringBundler query = null;
10067    
10068                    if (orderByComparator != null) {
10069                            query = new StringBundler(6 +
10070                                            (orderByComparator.getOrderByFields().length * 6));
10071                    }
10072                    else {
10073                            query = new StringBundler(3);
10074                    }
10075    
10076                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
10077    
10078                    query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
10079    
10080                    if (title == null) {
10081                            query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
10082                    }
10083                    else {
10084                            if (title.equals(StringPool.BLANK)) {
10085                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
10086                            }
10087                            else {
10088                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
10089                            }
10090                    }
10091    
10092                    query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
10093    
10094                    if (orderByComparator != null) {
10095                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10096    
10097                            if (orderByConditionFields.length > 0) {
10098                                    query.append(WHERE_AND);
10099                            }
10100    
10101                            for (int i = 0; i < orderByConditionFields.length; i++) {
10102                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10103                                    query.append(orderByConditionFields[i]);
10104    
10105                                    if ((i + 1) < orderByConditionFields.length) {
10106                                            if (orderByComparator.isAscending() ^ previous) {
10107                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10108                                            }
10109                                            else {
10110                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10111                                            }
10112                                    }
10113                                    else {
10114                                            if (orderByComparator.isAscending() ^ previous) {
10115                                                    query.append(WHERE_GREATER_THAN);
10116                                            }
10117                                            else {
10118                                                    query.append(WHERE_LESSER_THAN);
10119                                            }
10120                                    }
10121                            }
10122    
10123                            query.append(ORDER_BY_CLAUSE);
10124    
10125                            String[] orderByFields = orderByComparator.getOrderByFields();
10126    
10127                            for (int i = 0; i < orderByFields.length; i++) {
10128                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10129                                    query.append(orderByFields[i]);
10130    
10131                                    if ((i + 1) < orderByFields.length) {
10132                                            if (orderByComparator.isAscending() ^ previous) {
10133                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10134                                            }
10135                                            else {
10136                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10137                                            }
10138                                    }
10139                                    else {
10140                                            if (orderByComparator.isAscending() ^ previous) {
10141                                                    query.append(ORDER_BY_ASC);
10142                                            }
10143                                            else {
10144                                                    query.append(ORDER_BY_DESC);
10145                                            }
10146                                    }
10147                            }
10148                    }
10149                    else {
10150                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
10151                    }
10152    
10153                    String sql = query.toString();
10154    
10155                    Query q = session.createQuery(sql);
10156    
10157                    q.setFirstResult(0);
10158                    q.setMaxResults(2);
10159    
10160                    QueryPos qPos = QueryPos.getInstance(q);
10161    
10162                    qPos.add(nodeId);
10163    
10164                    if (title != null) {
10165                            qPos.add(title);
10166                    }
10167    
10168                    qPos.add(head);
10169    
10170                    if (orderByComparator != null) {
10171                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
10172    
10173                            for (Object value : values) {
10174                                    qPos.add(value);
10175                            }
10176                    }
10177    
10178                    List<WikiPage> list = q.list();
10179    
10180                    if (list.size() == 2) {
10181                            return list.get(1);
10182                    }
10183                    else {
10184                            return null;
10185                    }
10186            }
10187    
10188            /**
10189             * Removes all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63; from the database.
10190             *
10191             * @param nodeId the node ID
10192             * @param title the title
10193             * @param head the head
10194             * @throws SystemException if a system exception occurred
10195             */
10196            public void removeByN_T_H(long nodeId, String title, boolean head)
10197                    throws SystemException {
10198                    for (WikiPage wikiPage : findByN_T_H(nodeId, title, head,
10199                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10200                            remove(wikiPage);
10201                    }
10202            }
10203    
10204            /**
10205             * Returns the number of wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
10206             *
10207             * @param nodeId the node ID
10208             * @param title the title
10209             * @param head the head
10210             * @return the number of matching wiki pages
10211             * @throws SystemException if a system exception occurred
10212             */
10213            public int countByN_T_H(long nodeId, String title, boolean head)
10214                    throws SystemException {
10215                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T_H;
10216    
10217                    Object[] finderArgs = new Object[] { nodeId, title, head };
10218    
10219                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10220                                    this);
10221    
10222                    if (count == null) {
10223                            StringBundler query = new StringBundler(4);
10224    
10225                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
10226    
10227                            query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
10228    
10229                            if (title == null) {
10230                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
10231                            }
10232                            else {
10233                                    if (title.equals(StringPool.BLANK)) {
10234                                            query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
10235                                    }
10236                                    else {
10237                                            query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
10238                                    }
10239                            }
10240    
10241                            query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
10242    
10243                            String sql = query.toString();
10244    
10245                            Session session = null;
10246    
10247                            try {
10248                                    session = openSession();
10249    
10250                                    Query q = session.createQuery(sql);
10251    
10252                                    QueryPos qPos = QueryPos.getInstance(q);
10253    
10254                                    qPos.add(nodeId);
10255    
10256                                    if (title != null) {
10257                                            qPos.add(title);
10258                                    }
10259    
10260                                    qPos.add(head);
10261    
10262                                    count = (Long)q.uniqueResult();
10263    
10264                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10265                            }
10266                            catch (Exception e) {
10267                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10268    
10269                                    throw processException(e);
10270                            }
10271                            finally {
10272                                    closeSession(session);
10273                            }
10274                    }
10275    
10276                    return count.intValue();
10277            }
10278    
10279            private static final String _FINDER_COLUMN_N_T_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
10280            private static final String _FINDER_COLUMN_N_T_H_TITLE_1 = "wikiPage.title IS NULL AND ";
10281            private static final String _FINDER_COLUMN_N_T_H_TITLE_2 = "lower(wikiPage.title) = lower(CAST_TEXT(?)) AND ";
10282            private static final String _FINDER_COLUMN_N_T_H_TITLE_3 = "(wikiPage.title IS NULL OR lower(wikiPage.title) = lower(CAST_TEXT(?))) AND ";
10283            private static final String _FINDER_COLUMN_N_T_H_HEAD_2 = "wikiPage.head = ?";
10284            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10285                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
10286                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_T_S",
10287                            new String[] {
10288                                    Long.class.getName(), String.class.getName(),
10289                                    Integer.class.getName(),
10290                                    
10291                            Integer.class.getName(), Integer.class.getName(),
10292                                    OrderByComparator.class.getName()
10293                            });
10294            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10295                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
10296                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_T_S",
10297                            new String[] {
10298                                    Long.class.getName(), String.class.getName(),
10299                                    Integer.class.getName()
10300                            },
10301                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
10302                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
10303                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
10304                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
10305            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10306                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10307                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T_S",
10308                            new String[] {
10309                                    Long.class.getName(), String.class.getName(),
10310                                    Integer.class.getName()
10311                            });
10312    
10313            /**
10314             * Returns all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
10315             *
10316             * @param nodeId the node ID
10317             * @param title the title
10318             * @param status the status
10319             * @return the matching wiki pages
10320             * @throws SystemException if a system exception occurred
10321             */
10322            public List<WikiPage> findByN_T_S(long nodeId, String title, int status)
10323                    throws SystemException {
10324                    return findByN_T_S(nodeId, title, status, QueryUtil.ALL_POS,
10325                            QueryUtil.ALL_POS, null);
10326            }
10327    
10328            /**
10329             * Returns a range of all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
10330             *
10331             * <p>
10332             * 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.
10333             * </p>
10334             *
10335             * @param nodeId the node ID
10336             * @param title the title
10337             * @param status the status
10338             * @param start the lower bound of the range of wiki pages
10339             * @param end the upper bound of the range of wiki pages (not inclusive)
10340             * @return the range of matching wiki pages
10341             * @throws SystemException if a system exception occurred
10342             */
10343            public List<WikiPage> findByN_T_S(long nodeId, String title, int status,
10344                    int start, int end) throws SystemException {
10345                    return findByN_T_S(nodeId, title, status, start, end, null);
10346            }
10347    
10348            /**
10349             * Returns an ordered range of all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
10350             *
10351             * <p>
10352             * 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.
10353             * </p>
10354             *
10355             * @param nodeId the node ID
10356             * @param title the title
10357             * @param status the status
10358             * @param start the lower bound of the range of wiki pages
10359             * @param end the upper bound of the range of wiki pages (not inclusive)
10360             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10361             * @return the ordered range of matching wiki pages
10362             * @throws SystemException if a system exception occurred
10363             */
10364            public List<WikiPage> findByN_T_S(long nodeId, String title, int status,
10365                    int start, int end, OrderByComparator orderByComparator)
10366                    throws SystemException {
10367                    boolean pagination = true;
10368                    FinderPath finderPath = null;
10369                    Object[] finderArgs = null;
10370    
10371                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10372                                    (orderByComparator == null)) {
10373                            pagination = false;
10374                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S;
10375                            finderArgs = new Object[] { nodeId, title, status };
10376                    }
10377                    else {
10378                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_S;
10379                            finderArgs = new Object[] {
10380                                            nodeId, title, status,
10381                                            
10382                                            start, end, orderByComparator
10383                                    };
10384                    }
10385    
10386                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
10387                                    finderArgs, this);
10388    
10389                    if ((list != null) && !list.isEmpty()) {
10390                            for (WikiPage wikiPage : list) {
10391                                    if ((nodeId != wikiPage.getNodeId()) ||
10392                                                    !Validator.equals(title, wikiPage.getTitle()) ||
10393                                                    (status != wikiPage.getStatus())) {
10394                                            list = null;
10395    
10396                                            break;
10397                                    }
10398                            }
10399                    }
10400    
10401                    if (list == null) {
10402                            StringBundler query = null;
10403    
10404                            if (orderByComparator != null) {
10405                                    query = new StringBundler(5 +
10406                                                    (orderByComparator.getOrderByFields().length * 3));
10407                            }
10408                            else {
10409                                    query = new StringBundler(5);
10410                            }
10411    
10412                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
10413    
10414                            query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
10415    
10416                            if (title == null) {
10417                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
10418                            }
10419                            else {
10420                                    if (title.equals(StringPool.BLANK)) {
10421                                            query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
10422                                    }
10423                                    else {
10424                                            query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
10425                                    }
10426                            }
10427    
10428                            query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
10429    
10430                            if (orderByComparator != null) {
10431                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10432                                            orderByComparator);
10433                            }
10434                            else
10435                             if (pagination) {
10436                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
10437                            }
10438    
10439                            String sql = query.toString();
10440    
10441                            Session session = null;
10442    
10443                            try {
10444                                    session = openSession();
10445    
10446                                    Query q = session.createQuery(sql);
10447    
10448                                    QueryPos qPos = QueryPos.getInstance(q);
10449    
10450                                    qPos.add(nodeId);
10451    
10452                                    if (title != null) {
10453                                            qPos.add(title);
10454                                    }
10455    
10456                                    qPos.add(status);
10457    
10458                                    if (!pagination) {
10459                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
10460                                                            start, end, false);
10461    
10462                                            Collections.sort(list);
10463    
10464                                            list = new UnmodifiableList<WikiPage>(list);
10465                                    }
10466                                    else {
10467                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
10468                                                            start, end);
10469                                    }
10470    
10471                                    cacheResult(list);
10472    
10473                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10474                            }
10475                            catch (Exception e) {
10476                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10477    
10478                                    throw processException(e);
10479                            }
10480                            finally {
10481                                    closeSession(session);
10482                            }
10483                    }
10484    
10485                    return list;
10486            }
10487    
10488            /**
10489             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10490             *
10491             * @param nodeId the node ID
10492             * @param title the title
10493             * @param status the status
10494             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10495             * @return the first matching wiki page
10496             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
10497             * @throws SystemException if a system exception occurred
10498             */
10499            public WikiPage findByN_T_S_First(long nodeId, String title, int status,
10500                    OrderByComparator orderByComparator)
10501                    throws NoSuchPageException, SystemException {
10502                    WikiPage wikiPage = fetchByN_T_S_First(nodeId, title, status,
10503                                    orderByComparator);
10504    
10505                    if (wikiPage != null) {
10506                            return wikiPage;
10507                    }
10508    
10509                    StringBundler msg = new StringBundler(8);
10510    
10511                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10512    
10513                    msg.append("nodeId=");
10514                    msg.append(nodeId);
10515    
10516                    msg.append(", title=");
10517                    msg.append(title);
10518    
10519                    msg.append(", status=");
10520                    msg.append(status);
10521    
10522                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10523    
10524                    throw new NoSuchPageException(msg.toString());
10525            }
10526    
10527            /**
10528             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10529             *
10530             * @param nodeId the node ID
10531             * @param title the title
10532             * @param status the status
10533             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10534             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
10535             * @throws SystemException if a system exception occurred
10536             */
10537            public WikiPage fetchByN_T_S_First(long nodeId, String title, int status,
10538                    OrderByComparator orderByComparator) throws SystemException {
10539                    List<WikiPage> list = findByN_T_S(nodeId, title, status, 0, 1,
10540                                    orderByComparator);
10541    
10542                    if (!list.isEmpty()) {
10543                            return list.get(0);
10544                    }
10545    
10546                    return null;
10547            }
10548    
10549            /**
10550             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10551             *
10552             * @param nodeId the node ID
10553             * @param title the title
10554             * @param status the status
10555             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10556             * @return the last matching wiki page
10557             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
10558             * @throws SystemException if a system exception occurred
10559             */
10560            public WikiPage findByN_T_S_Last(long nodeId, String title, int status,
10561                    OrderByComparator orderByComparator)
10562                    throws NoSuchPageException, SystemException {
10563                    WikiPage wikiPage = fetchByN_T_S_Last(nodeId, title, status,
10564                                    orderByComparator);
10565    
10566                    if (wikiPage != null) {
10567                            return wikiPage;
10568                    }
10569    
10570                    StringBundler msg = new StringBundler(8);
10571    
10572                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10573    
10574                    msg.append("nodeId=");
10575                    msg.append(nodeId);
10576    
10577                    msg.append(", title=");
10578                    msg.append(title);
10579    
10580                    msg.append(", status=");
10581                    msg.append(status);
10582    
10583                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10584    
10585                    throw new NoSuchPageException(msg.toString());
10586            }
10587    
10588            /**
10589             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10590             *
10591             * @param nodeId the node ID
10592             * @param title the title
10593             * @param status the status
10594             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10595             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
10596             * @throws SystemException if a system exception occurred
10597             */
10598            public WikiPage fetchByN_T_S_Last(long nodeId, String title, int status,
10599                    OrderByComparator orderByComparator) throws SystemException {
10600                    int count = countByN_T_S(nodeId, title, status);
10601    
10602                    List<WikiPage> list = findByN_T_S(nodeId, title, status, count - 1,
10603                                    count, orderByComparator);
10604    
10605                    if (!list.isEmpty()) {
10606                            return list.get(0);
10607                    }
10608    
10609                    return null;
10610            }
10611    
10612            /**
10613             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
10614             *
10615             * @param pageId the primary key of the current wiki page
10616             * @param nodeId the node ID
10617             * @param title the title
10618             * @param status the status
10619             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10620             * @return the previous, current, and next wiki page
10621             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
10622             * @throws SystemException if a system exception occurred
10623             */
10624            public WikiPage[] findByN_T_S_PrevAndNext(long pageId, long nodeId,
10625                    String title, int status, OrderByComparator orderByComparator)
10626                    throws NoSuchPageException, SystemException {
10627                    WikiPage wikiPage = findByPrimaryKey(pageId);
10628    
10629                    Session session = null;
10630    
10631                    try {
10632                            session = openSession();
10633    
10634                            WikiPage[] array = new WikiPageImpl[3];
10635    
10636                            array[0] = getByN_T_S_PrevAndNext(session, wikiPage, nodeId, title,
10637                                            status, orderByComparator, true);
10638    
10639                            array[1] = wikiPage;
10640    
10641                            array[2] = getByN_T_S_PrevAndNext(session, wikiPage, nodeId, title,
10642                                            status, orderByComparator, false);
10643    
10644                            return array;
10645                    }
10646                    catch (Exception e) {
10647                            throw processException(e);
10648                    }
10649                    finally {
10650                            closeSession(session);
10651                    }
10652            }
10653    
10654            protected WikiPage getByN_T_S_PrevAndNext(Session session,
10655                    WikiPage wikiPage, long nodeId, String title, int status,
10656                    OrderByComparator orderByComparator, boolean previous) {
10657                    StringBundler query = null;
10658    
10659                    if (orderByComparator != null) {
10660                            query = new StringBundler(6 +
10661                                            (orderByComparator.getOrderByFields().length * 6));
10662                    }
10663                    else {
10664                            query = new StringBundler(3);
10665                    }
10666    
10667                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
10668    
10669                    query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
10670    
10671                    if (title == null) {
10672                            query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
10673                    }
10674                    else {
10675                            if (title.equals(StringPool.BLANK)) {
10676                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
10677                            }
10678                            else {
10679                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
10680                            }
10681                    }
10682    
10683                    query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
10684    
10685                    if (orderByComparator != null) {
10686                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10687    
10688                            if (orderByConditionFields.length > 0) {
10689                                    query.append(WHERE_AND);
10690                            }
10691    
10692                            for (int i = 0; i < orderByConditionFields.length; i++) {
10693                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10694                                    query.append(orderByConditionFields[i]);
10695    
10696                                    if ((i + 1) < orderByConditionFields.length) {
10697                                            if (orderByComparator.isAscending() ^ previous) {
10698                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10699                                            }
10700                                            else {
10701                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10702                                            }
10703                                    }
10704                                    else {
10705                                            if (orderByComparator.isAscending() ^ previous) {
10706                                                    query.append(WHERE_GREATER_THAN);
10707                                            }
10708                                            else {
10709                                                    query.append(WHERE_LESSER_THAN);
10710                                            }
10711                                    }
10712                            }
10713    
10714                            query.append(ORDER_BY_CLAUSE);
10715    
10716                            String[] orderByFields = orderByComparator.getOrderByFields();
10717    
10718                            for (int i = 0; i < orderByFields.length; i++) {
10719                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10720                                    query.append(orderByFields[i]);
10721    
10722                                    if ((i + 1) < orderByFields.length) {
10723                                            if (orderByComparator.isAscending() ^ previous) {
10724                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10725                                            }
10726                                            else {
10727                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10728                                            }
10729                                    }
10730                                    else {
10731                                            if (orderByComparator.isAscending() ^ previous) {
10732                                                    query.append(ORDER_BY_ASC);
10733                                            }
10734                                            else {
10735                                                    query.append(ORDER_BY_DESC);
10736                                            }
10737                                    }
10738                            }
10739                    }
10740                    else {
10741                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
10742                    }
10743    
10744                    String sql = query.toString();
10745    
10746                    Query q = session.createQuery(sql);
10747    
10748                    q.setFirstResult(0);
10749                    q.setMaxResults(2);
10750    
10751                    QueryPos qPos = QueryPos.getInstance(q);
10752    
10753                    qPos.add(nodeId);
10754    
10755                    if (title != null) {
10756                            qPos.add(title);
10757                    }
10758    
10759                    qPos.add(status);
10760    
10761                    if (orderByComparator != null) {
10762                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
10763    
10764                            for (Object value : values) {
10765                                    qPos.add(value);
10766                            }
10767                    }
10768    
10769                    List<WikiPage> list = q.list();
10770    
10771                    if (list.size() == 2) {
10772                            return list.get(1);
10773                    }
10774                    else {
10775                            return null;
10776                    }
10777            }
10778    
10779            /**
10780             * Removes all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63; from the database.
10781             *
10782             * @param nodeId the node ID
10783             * @param title the title
10784             * @param status the status
10785             * @throws SystemException if a system exception occurred
10786             */
10787            public void removeByN_T_S(long nodeId, String title, int status)
10788                    throws SystemException {
10789                    for (WikiPage wikiPage : findByN_T_S(nodeId, title, status,
10790                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10791                            remove(wikiPage);
10792                    }
10793            }
10794    
10795            /**
10796             * Returns the number of wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
10797             *
10798             * @param nodeId the node ID
10799             * @param title the title
10800             * @param status the status
10801             * @return the number of matching wiki pages
10802             * @throws SystemException if a system exception occurred
10803             */
10804            public int countByN_T_S(long nodeId, String title, int status)
10805                    throws SystemException {
10806                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T_S;
10807    
10808                    Object[] finderArgs = new Object[] { nodeId, title, status };
10809    
10810                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10811                                    this);
10812    
10813                    if (count == null) {
10814                            StringBundler query = new StringBundler(4);
10815    
10816                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
10817    
10818                            query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
10819    
10820                            if (title == null) {
10821                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
10822                            }
10823                            else {
10824                                    if (title.equals(StringPool.BLANK)) {
10825                                            query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
10826                                    }
10827                                    else {
10828                                            query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
10829                                    }
10830                            }
10831    
10832                            query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
10833    
10834                            String sql = query.toString();
10835    
10836                            Session session = null;
10837    
10838                            try {
10839                                    session = openSession();
10840    
10841                                    Query q = session.createQuery(sql);
10842    
10843                                    QueryPos qPos = QueryPos.getInstance(q);
10844    
10845                                    qPos.add(nodeId);
10846    
10847                                    if (title != null) {
10848                                            qPos.add(title);
10849                                    }
10850    
10851                                    qPos.add(status);
10852    
10853                                    count = (Long)q.uniqueResult();
10854    
10855                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10856                            }
10857                            catch (Exception e) {
10858                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10859    
10860                                    throw processException(e);
10861                            }
10862                            finally {
10863                                    closeSession(session);
10864                            }
10865                    }
10866    
10867                    return count.intValue();
10868            }
10869    
10870            private static final String _FINDER_COLUMN_N_T_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
10871            private static final String _FINDER_COLUMN_N_T_S_TITLE_1 = "wikiPage.title IS NULL AND ";
10872            private static final String _FINDER_COLUMN_N_T_S_TITLE_2 = "lower(wikiPage.title) = lower(CAST_TEXT(?)) AND ";
10873            private static final String _FINDER_COLUMN_N_T_S_TITLE_3 = "(wikiPage.title IS NULL OR lower(wikiPage.title) = lower(CAST_TEXT(?))) AND ";
10874            private static final String _FINDER_COLUMN_N_T_S_STATUS_2 = "wikiPage.status = ?";
10875            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10876                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
10877                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_P",
10878                            new String[] {
10879                                    Long.class.getName(), Boolean.class.getName(),
10880                                    String.class.getName(),
10881                                    
10882                            Integer.class.getName(), Integer.class.getName(),
10883                                    OrderByComparator.class.getName()
10884                            });
10885            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10886                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
10887                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_P",
10888                            new String[] {
10889                                    Long.class.getName(), Boolean.class.getName(),
10890                                    String.class.getName()
10891                            },
10892                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
10893                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
10894                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
10895                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
10896                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
10897            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10898                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10899                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_P",
10900                            new String[] {
10901                                    Long.class.getName(), Boolean.class.getName(),
10902                                    String.class.getName()
10903                            });
10904    
10905            /**
10906             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
10907             *
10908             * @param nodeId the node ID
10909             * @param head the head
10910             * @param parentTitle the parent title
10911             * @return the matching wiki pages
10912             * @throws SystemException if a system exception occurred
10913             */
10914            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
10915                    String parentTitle) throws SystemException {
10916                    return findByN_H_P(nodeId, head, parentTitle, QueryUtil.ALL_POS,
10917                            QueryUtil.ALL_POS, null);
10918            }
10919    
10920            /**
10921             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
10922             *
10923             * <p>
10924             * 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.
10925             * </p>
10926             *
10927             * @param nodeId the node ID
10928             * @param head the head
10929             * @param parentTitle the parent title
10930             * @param start the lower bound of the range of wiki pages
10931             * @param end the upper bound of the range of wiki pages (not inclusive)
10932             * @return the range of matching wiki pages
10933             * @throws SystemException if a system exception occurred
10934             */
10935            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
10936                    String parentTitle, int start, int end) throws SystemException {
10937                    return findByN_H_P(nodeId, head, parentTitle, start, end, null);
10938            }
10939    
10940            /**
10941             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
10942             *
10943             * <p>
10944             * 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.
10945             * </p>
10946             *
10947             * @param nodeId the node ID
10948             * @param head the head
10949             * @param parentTitle the parent title
10950             * @param start the lower bound of the range of wiki pages
10951             * @param end the upper bound of the range of wiki pages (not inclusive)
10952             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10953             * @return the ordered range of matching wiki pages
10954             * @throws SystemException if a system exception occurred
10955             */
10956            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
10957                    String parentTitle, int start, int end,
10958                    OrderByComparator orderByComparator) throws SystemException {
10959                    boolean pagination = true;
10960                    FinderPath finderPath = null;
10961                    Object[] finderArgs = null;
10962    
10963                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10964                                    (orderByComparator == null)) {
10965                            pagination = false;
10966                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P;
10967                            finderArgs = new Object[] { nodeId, head, parentTitle };
10968                    }
10969                    else {
10970                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P;
10971                            finderArgs = new Object[] {
10972                                            nodeId, head, parentTitle,
10973                                            
10974                                            start, end, orderByComparator
10975                                    };
10976                    }
10977    
10978                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
10979                                    finderArgs, this);
10980    
10981                    if ((list != null) && !list.isEmpty()) {
10982                            for (WikiPage wikiPage : list) {
10983                                    if ((nodeId != wikiPage.getNodeId()) ||
10984                                                    (head != wikiPage.getHead()) ||
10985                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle())) {
10986                                            list = null;
10987    
10988                                            break;
10989                                    }
10990                            }
10991                    }
10992    
10993                    if (list == null) {
10994                            StringBundler query = null;
10995    
10996                            if (orderByComparator != null) {
10997                                    query = new StringBundler(5 +
10998                                                    (orderByComparator.getOrderByFields().length * 3));
10999                            }
11000                            else {
11001                                    query = new StringBundler(5);
11002                            }
11003    
11004                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11005    
11006                            query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
11007    
11008                            query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
11009    
11010                            if (parentTitle == null) {
11011                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
11012                            }
11013                            else {
11014                                    if (parentTitle.equals(StringPool.BLANK)) {
11015                                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
11016                                    }
11017                                    else {
11018                                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
11019                                    }
11020                            }
11021    
11022                            if (orderByComparator != null) {
11023                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11024                                            orderByComparator);
11025                            }
11026                            else
11027                             if (pagination) {
11028                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11029                            }
11030    
11031                            String sql = query.toString();
11032    
11033                            Session session = null;
11034    
11035                            try {
11036                                    session = openSession();
11037    
11038                                    Query q = session.createQuery(sql);
11039    
11040                                    QueryPos qPos = QueryPos.getInstance(q);
11041    
11042                                    qPos.add(nodeId);
11043    
11044                                    qPos.add(head);
11045    
11046                                    if (parentTitle != null) {
11047                                            qPos.add(parentTitle);
11048                                    }
11049    
11050                                    if (!pagination) {
11051                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11052                                                            start, end, false);
11053    
11054                                            Collections.sort(list);
11055    
11056                                            list = new UnmodifiableList<WikiPage>(list);
11057                                    }
11058                                    else {
11059                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11060                                                            start, end);
11061                                    }
11062    
11063                                    cacheResult(list);
11064    
11065                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11066                            }
11067                            catch (Exception e) {
11068                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11069    
11070                                    throw processException(e);
11071                            }
11072                            finally {
11073                                    closeSession(session);
11074                            }
11075                    }
11076    
11077                    return list;
11078            }
11079    
11080            /**
11081             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11082             *
11083             * @param nodeId the node ID
11084             * @param head the head
11085             * @param parentTitle the parent title
11086             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11087             * @return the first matching wiki page
11088             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11089             * @throws SystemException if a system exception occurred
11090             */
11091            public WikiPage findByN_H_P_First(long nodeId, boolean head,
11092                    String parentTitle, OrderByComparator orderByComparator)
11093                    throws NoSuchPageException, SystemException {
11094                    WikiPage wikiPage = fetchByN_H_P_First(nodeId, head, parentTitle,
11095                                    orderByComparator);
11096    
11097                    if (wikiPage != null) {
11098                            return wikiPage;
11099                    }
11100    
11101                    StringBundler msg = new StringBundler(8);
11102    
11103                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11104    
11105                    msg.append("nodeId=");
11106                    msg.append(nodeId);
11107    
11108                    msg.append(", head=");
11109                    msg.append(head);
11110    
11111                    msg.append(", parentTitle=");
11112                    msg.append(parentTitle);
11113    
11114                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11115    
11116                    throw new NoSuchPageException(msg.toString());
11117            }
11118    
11119            /**
11120             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11121             *
11122             * @param nodeId the node ID
11123             * @param head the head
11124             * @param parentTitle the parent title
11125             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11126             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
11127             * @throws SystemException if a system exception occurred
11128             */
11129            public WikiPage fetchByN_H_P_First(long nodeId, boolean head,
11130                    String parentTitle, OrderByComparator orderByComparator)
11131                    throws SystemException {
11132                    List<WikiPage> list = findByN_H_P(nodeId, head, parentTitle, 0, 1,
11133                                    orderByComparator);
11134    
11135                    if (!list.isEmpty()) {
11136                            return list.get(0);
11137                    }
11138    
11139                    return null;
11140            }
11141    
11142            /**
11143             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11144             *
11145             * @param nodeId the node ID
11146             * @param head the head
11147             * @param parentTitle the parent title
11148             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11149             * @return the last matching wiki page
11150             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11151             * @throws SystemException if a system exception occurred
11152             */
11153            public WikiPage findByN_H_P_Last(long nodeId, boolean head,
11154                    String parentTitle, OrderByComparator orderByComparator)
11155                    throws NoSuchPageException, SystemException {
11156                    WikiPage wikiPage = fetchByN_H_P_Last(nodeId, head, parentTitle,
11157                                    orderByComparator);
11158    
11159                    if (wikiPage != null) {
11160                            return wikiPage;
11161                    }
11162    
11163                    StringBundler msg = new StringBundler(8);
11164    
11165                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11166    
11167                    msg.append("nodeId=");
11168                    msg.append(nodeId);
11169    
11170                    msg.append(", head=");
11171                    msg.append(head);
11172    
11173                    msg.append(", parentTitle=");
11174                    msg.append(parentTitle);
11175    
11176                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11177    
11178                    throw new NoSuchPageException(msg.toString());
11179            }
11180    
11181            /**
11182             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11183             *
11184             * @param nodeId the node ID
11185             * @param head the head
11186             * @param parentTitle the parent title
11187             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11188             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
11189             * @throws SystemException if a system exception occurred
11190             */
11191            public WikiPage fetchByN_H_P_Last(long nodeId, boolean head,
11192                    String parentTitle, OrderByComparator orderByComparator)
11193                    throws SystemException {
11194                    int count = countByN_H_P(nodeId, head, parentTitle);
11195    
11196                    List<WikiPage> list = findByN_H_P(nodeId, head, parentTitle, count - 1,
11197                                    count, orderByComparator);
11198    
11199                    if (!list.isEmpty()) {
11200                            return list.get(0);
11201                    }
11202    
11203                    return null;
11204            }
11205    
11206            /**
11207             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11208             *
11209             * @param pageId the primary key of the current wiki page
11210             * @param nodeId the node ID
11211             * @param head the head
11212             * @param parentTitle the parent title
11213             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11214             * @return the previous, current, and next wiki page
11215             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
11216             * @throws SystemException if a system exception occurred
11217             */
11218            public WikiPage[] findByN_H_P_PrevAndNext(long pageId, long nodeId,
11219                    boolean head, String parentTitle, OrderByComparator orderByComparator)
11220                    throws NoSuchPageException, SystemException {
11221                    WikiPage wikiPage = findByPrimaryKey(pageId);
11222    
11223                    Session session = null;
11224    
11225                    try {
11226                            session = openSession();
11227    
11228                            WikiPage[] array = new WikiPageImpl[3];
11229    
11230                            array[0] = getByN_H_P_PrevAndNext(session, wikiPage, nodeId, head,
11231                                            parentTitle, orderByComparator, true);
11232    
11233                            array[1] = wikiPage;
11234    
11235                            array[2] = getByN_H_P_PrevAndNext(session, wikiPage, nodeId, head,
11236                                            parentTitle, orderByComparator, false);
11237    
11238                            return array;
11239                    }
11240                    catch (Exception e) {
11241                            throw processException(e);
11242                    }
11243                    finally {
11244                            closeSession(session);
11245                    }
11246            }
11247    
11248            protected WikiPage getByN_H_P_PrevAndNext(Session session,
11249                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
11250                    OrderByComparator orderByComparator, boolean previous) {
11251                    StringBundler query = null;
11252    
11253                    if (orderByComparator != null) {
11254                            query = new StringBundler(6 +
11255                                            (orderByComparator.getOrderByFields().length * 6));
11256                    }
11257                    else {
11258                            query = new StringBundler(3);
11259                    }
11260    
11261                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11262    
11263                    query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
11264    
11265                    query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
11266    
11267                    if (parentTitle == null) {
11268                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
11269                    }
11270                    else {
11271                            if (parentTitle.equals(StringPool.BLANK)) {
11272                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
11273                            }
11274                            else {
11275                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
11276                            }
11277                    }
11278    
11279                    if (orderByComparator != null) {
11280                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11281    
11282                            if (orderByConditionFields.length > 0) {
11283                                    query.append(WHERE_AND);
11284                            }
11285    
11286                            for (int i = 0; i < orderByConditionFields.length; i++) {
11287                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11288                                    query.append(orderByConditionFields[i]);
11289    
11290                                    if ((i + 1) < orderByConditionFields.length) {
11291                                            if (orderByComparator.isAscending() ^ previous) {
11292                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11293                                            }
11294                                            else {
11295                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11296                                            }
11297                                    }
11298                                    else {
11299                                            if (orderByComparator.isAscending() ^ previous) {
11300                                                    query.append(WHERE_GREATER_THAN);
11301                                            }
11302                                            else {
11303                                                    query.append(WHERE_LESSER_THAN);
11304                                            }
11305                                    }
11306                            }
11307    
11308                            query.append(ORDER_BY_CLAUSE);
11309    
11310                            String[] orderByFields = orderByComparator.getOrderByFields();
11311    
11312                            for (int i = 0; i < orderByFields.length; i++) {
11313                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11314                                    query.append(orderByFields[i]);
11315    
11316                                    if ((i + 1) < orderByFields.length) {
11317                                            if (orderByComparator.isAscending() ^ previous) {
11318                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11319                                            }
11320                                            else {
11321                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11322                                            }
11323                                    }
11324                                    else {
11325                                            if (orderByComparator.isAscending() ^ previous) {
11326                                                    query.append(ORDER_BY_ASC);
11327                                            }
11328                                            else {
11329                                                    query.append(ORDER_BY_DESC);
11330                                            }
11331                                    }
11332                            }
11333                    }
11334                    else {
11335                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11336                    }
11337    
11338                    String sql = query.toString();
11339    
11340                    Query q = session.createQuery(sql);
11341    
11342                    q.setFirstResult(0);
11343                    q.setMaxResults(2);
11344    
11345                    QueryPos qPos = QueryPos.getInstance(q);
11346    
11347                    qPos.add(nodeId);
11348    
11349                    qPos.add(head);
11350    
11351                    if (parentTitle != null) {
11352                            qPos.add(parentTitle);
11353                    }
11354    
11355                    if (orderByComparator != null) {
11356                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
11357    
11358                            for (Object value : values) {
11359                                    qPos.add(value);
11360                            }
11361                    }
11362    
11363                    List<WikiPage> list = q.list();
11364    
11365                    if (list.size() == 2) {
11366                            return list.get(1);
11367                    }
11368                    else {
11369                            return null;
11370                    }
11371            }
11372    
11373            /**
11374             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; from the database.
11375             *
11376             * @param nodeId the node ID
11377             * @param head the head
11378             * @param parentTitle the parent title
11379             * @throws SystemException if a system exception occurred
11380             */
11381            public void removeByN_H_P(long nodeId, boolean head, String parentTitle)
11382                    throws SystemException {
11383                    for (WikiPage wikiPage : findByN_H_P(nodeId, head, parentTitle,
11384                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11385                            remove(wikiPage);
11386                    }
11387            }
11388    
11389            /**
11390             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
11391             *
11392             * @param nodeId the node ID
11393             * @param head the head
11394             * @param parentTitle the parent title
11395             * @return the number of matching wiki pages
11396             * @throws SystemException if a system exception occurred
11397             */
11398            public int countByN_H_P(long nodeId, boolean head, String parentTitle)
11399                    throws SystemException {
11400                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_P;
11401    
11402                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle };
11403    
11404                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11405                                    this);
11406    
11407                    if (count == null) {
11408                            StringBundler query = new StringBundler(4);
11409    
11410                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
11411    
11412                            query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
11413    
11414                            query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
11415    
11416                            if (parentTitle == null) {
11417                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
11418                            }
11419                            else {
11420                                    if (parentTitle.equals(StringPool.BLANK)) {
11421                                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
11422                                    }
11423                                    else {
11424                                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
11425                                    }
11426                            }
11427    
11428                            String sql = query.toString();
11429    
11430                            Session session = null;
11431    
11432                            try {
11433                                    session = openSession();
11434    
11435                                    Query q = session.createQuery(sql);
11436    
11437                                    QueryPos qPos = QueryPos.getInstance(q);
11438    
11439                                    qPos.add(nodeId);
11440    
11441                                    qPos.add(head);
11442    
11443                                    if (parentTitle != null) {
11444                                            qPos.add(parentTitle);
11445                                    }
11446    
11447                                    count = (Long)q.uniqueResult();
11448    
11449                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11450                            }
11451                            catch (Exception e) {
11452                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11453    
11454                                    throw processException(e);
11455                            }
11456                            finally {
11457                                    closeSession(session);
11458                            }
11459                    }
11460    
11461                    return count.intValue();
11462            }
11463    
11464            private static final String _FINDER_COLUMN_N_H_P_NODEID_2 = "wikiPage.nodeId = ? AND ";
11465            private static final String _FINDER_COLUMN_N_H_P_HEAD_2 = "wikiPage.head = ? AND ";
11466            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL";
11467            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = lower(CAST_TEXT(?))";
11468            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR lower(wikiPage.parentTitle) = lower(CAST_TEXT(?)))";
11469            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11470                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
11471                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_S",
11472                            new String[] {
11473                                    Long.class.getName(), Boolean.class.getName(),
11474                                    Integer.class.getName(),
11475                                    
11476                            Integer.class.getName(), Integer.class.getName(),
11477                                    OrderByComparator.class.getName()
11478                            });
11479            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11480                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
11481                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_S",
11482                            new String[] {
11483                                    Long.class.getName(), Boolean.class.getName(),
11484                                    Integer.class.getName()
11485                            },
11486                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
11487                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
11488                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
11489                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
11490                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
11491            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11492                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11493                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_S",
11494                            new String[] {
11495                                    Long.class.getName(), Boolean.class.getName(),
11496                                    Integer.class.getName()
11497                            });
11498    
11499            /**
11500             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
11501             *
11502             * @param nodeId the node ID
11503             * @param head the head
11504             * @param status the status
11505             * @return the matching wiki pages
11506             * @throws SystemException if a system exception occurred
11507             */
11508            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status)
11509                    throws SystemException {
11510                    return findByN_H_S(nodeId, head, status, QueryUtil.ALL_POS,
11511                            QueryUtil.ALL_POS, null);
11512            }
11513    
11514            /**
11515             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
11516             *
11517             * <p>
11518             * 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.
11519             * </p>
11520             *
11521             * @param nodeId the node ID
11522             * @param head the head
11523             * @param status the status
11524             * @param start the lower bound of the range of wiki pages
11525             * @param end the upper bound of the range of wiki pages (not inclusive)
11526             * @return the range of matching wiki pages
11527             * @throws SystemException if a system exception occurred
11528             */
11529            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status,
11530                    int start, int end) throws SystemException {
11531                    return findByN_H_S(nodeId, head, status, start, end, null);
11532            }
11533    
11534            /**
11535             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
11536             *
11537             * <p>
11538             * 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.
11539             * </p>
11540             *
11541             * @param nodeId the node ID
11542             * @param head the head
11543             * @param status the status
11544             * @param start the lower bound of the range of wiki pages
11545             * @param end the upper bound of the range of wiki pages (not inclusive)
11546             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11547             * @return the ordered range of matching wiki pages
11548             * @throws SystemException if a system exception occurred
11549             */
11550            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status,
11551                    int start, int end, OrderByComparator orderByComparator)
11552                    throws SystemException {
11553                    boolean pagination = true;
11554                    FinderPath finderPath = null;
11555                    Object[] finderArgs = null;
11556    
11557                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11558                                    (orderByComparator == null)) {
11559                            pagination = false;
11560                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S;
11561                            finderArgs = new Object[] { nodeId, head, status };
11562                    }
11563                    else {
11564                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_S;
11565                            finderArgs = new Object[] {
11566                                            nodeId, head, status,
11567                                            
11568                                            start, end, orderByComparator
11569                                    };
11570                    }
11571    
11572                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
11573                                    finderArgs, this);
11574    
11575                    if ((list != null) && !list.isEmpty()) {
11576                            for (WikiPage wikiPage : list) {
11577                                    if ((nodeId != wikiPage.getNodeId()) ||
11578                                                    (head != wikiPage.getHead()) ||
11579                                                    (status != wikiPage.getStatus())) {
11580                                            list = null;
11581    
11582                                            break;
11583                                    }
11584                            }
11585                    }
11586    
11587                    if (list == null) {
11588                            StringBundler query = null;
11589    
11590                            if (orderByComparator != null) {
11591                                    query = new StringBundler(5 +
11592                                                    (orderByComparator.getOrderByFields().length * 3));
11593                            }
11594                            else {
11595                                    query = new StringBundler(5);
11596                            }
11597    
11598                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11599    
11600                            query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
11601    
11602                            query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
11603    
11604                            query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
11605    
11606                            if (orderByComparator != null) {
11607                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11608                                            orderByComparator);
11609                            }
11610                            else
11611                             if (pagination) {
11612                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11613                            }
11614    
11615                            String sql = query.toString();
11616    
11617                            Session session = null;
11618    
11619                            try {
11620                                    session = openSession();
11621    
11622                                    Query q = session.createQuery(sql);
11623    
11624                                    QueryPos qPos = QueryPos.getInstance(q);
11625    
11626                                    qPos.add(nodeId);
11627    
11628                                    qPos.add(head);
11629    
11630                                    qPos.add(status);
11631    
11632                                    if (!pagination) {
11633                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11634                                                            start, end, false);
11635    
11636                                            Collections.sort(list);
11637    
11638                                            list = new UnmodifiableList<WikiPage>(list);
11639                                    }
11640                                    else {
11641                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11642                                                            start, end);
11643                                    }
11644    
11645                                    cacheResult(list);
11646    
11647                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11648                            }
11649                            catch (Exception e) {
11650                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11651    
11652                                    throw processException(e);
11653                            }
11654                            finally {
11655                                    closeSession(session);
11656                            }
11657                    }
11658    
11659                    return list;
11660            }
11661    
11662            /**
11663             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
11664             *
11665             * @param nodeId the node ID
11666             * @param head the head
11667             * @param status the status
11668             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11669             * @return the first matching wiki page
11670             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11671             * @throws SystemException if a system exception occurred
11672             */
11673            public WikiPage findByN_H_S_First(long nodeId, boolean head, int status,
11674                    OrderByComparator orderByComparator)
11675                    throws NoSuchPageException, SystemException {
11676                    WikiPage wikiPage = fetchByN_H_S_First(nodeId, head, status,
11677                                    orderByComparator);
11678    
11679                    if (wikiPage != null) {
11680                            return wikiPage;
11681                    }
11682    
11683                    StringBundler msg = new StringBundler(8);
11684    
11685                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11686    
11687                    msg.append("nodeId=");
11688                    msg.append(nodeId);
11689    
11690                    msg.append(", head=");
11691                    msg.append(head);
11692    
11693                    msg.append(", status=");
11694                    msg.append(status);
11695    
11696                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11697    
11698                    throw new NoSuchPageException(msg.toString());
11699            }
11700    
11701            /**
11702             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
11703             *
11704             * @param nodeId the node ID
11705             * @param head the head
11706             * @param status the status
11707             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11708             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
11709             * @throws SystemException if a system exception occurred
11710             */
11711            public WikiPage fetchByN_H_S_First(long nodeId, boolean head, int status,
11712                    OrderByComparator orderByComparator) throws SystemException {
11713                    List<WikiPage> list = findByN_H_S(nodeId, head, status, 0, 1,
11714                                    orderByComparator);
11715    
11716                    if (!list.isEmpty()) {
11717                            return list.get(0);
11718                    }
11719    
11720                    return null;
11721            }
11722    
11723            /**
11724             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
11725             *
11726             * @param nodeId the node ID
11727             * @param head the head
11728             * @param status the status
11729             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11730             * @return the last matching wiki page
11731             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11732             * @throws SystemException if a system exception occurred
11733             */
11734            public WikiPage findByN_H_S_Last(long nodeId, boolean head, int status,
11735                    OrderByComparator orderByComparator)
11736                    throws NoSuchPageException, SystemException {
11737                    WikiPage wikiPage = fetchByN_H_S_Last(nodeId, head, status,
11738                                    orderByComparator);
11739    
11740                    if (wikiPage != null) {
11741                            return wikiPage;
11742                    }
11743    
11744                    StringBundler msg = new StringBundler(8);
11745    
11746                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11747    
11748                    msg.append("nodeId=");
11749                    msg.append(nodeId);
11750    
11751                    msg.append(", head=");
11752                    msg.append(head);
11753    
11754                    msg.append(", status=");
11755                    msg.append(status);
11756    
11757                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11758    
11759                    throw new NoSuchPageException(msg.toString());
11760            }
11761    
11762            /**
11763             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
11764             *
11765             * @param nodeId the node ID
11766             * @param head the head
11767             * @param status the status
11768             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11769             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
11770             * @throws SystemException if a system exception occurred
11771             */
11772            public WikiPage fetchByN_H_S_Last(long nodeId, boolean head, int status,
11773                    OrderByComparator orderByComparator) throws SystemException {
11774                    int count = countByN_H_S(nodeId, head, status);
11775    
11776                    List<WikiPage> list = findByN_H_S(nodeId, head, status, count - 1,
11777                                    count, orderByComparator);
11778    
11779                    if (!list.isEmpty()) {
11780                            return list.get(0);
11781                    }
11782    
11783                    return null;
11784            }
11785    
11786            /**
11787             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
11788             *
11789             * @param pageId the primary key of the current wiki page
11790             * @param nodeId the node ID
11791             * @param head the head
11792             * @param status the status
11793             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11794             * @return the previous, current, and next wiki page
11795             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
11796             * @throws SystemException if a system exception occurred
11797             */
11798            public WikiPage[] findByN_H_S_PrevAndNext(long pageId, long nodeId,
11799                    boolean head, int status, OrderByComparator orderByComparator)
11800                    throws NoSuchPageException, SystemException {
11801                    WikiPage wikiPage = findByPrimaryKey(pageId);
11802    
11803                    Session session = null;
11804    
11805                    try {
11806                            session = openSession();
11807    
11808                            WikiPage[] array = new WikiPageImpl[3];
11809    
11810                            array[0] = getByN_H_S_PrevAndNext(session, wikiPage, nodeId, head,
11811                                            status, orderByComparator, true);
11812    
11813                            array[1] = wikiPage;
11814    
11815                            array[2] = getByN_H_S_PrevAndNext(session, wikiPage, nodeId, head,
11816                                            status, orderByComparator, false);
11817    
11818                            return array;
11819                    }
11820                    catch (Exception e) {
11821                            throw processException(e);
11822                    }
11823                    finally {
11824                            closeSession(session);
11825                    }
11826            }
11827    
11828            protected WikiPage getByN_H_S_PrevAndNext(Session session,
11829                    WikiPage wikiPage, long nodeId, boolean head, int status,
11830                    OrderByComparator orderByComparator, boolean previous) {
11831                    StringBundler query = null;
11832    
11833                    if (orderByComparator != null) {
11834                            query = new StringBundler(6 +
11835                                            (orderByComparator.getOrderByFields().length * 6));
11836                    }
11837                    else {
11838                            query = new StringBundler(3);
11839                    }
11840    
11841                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11842    
11843                    query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
11844    
11845                    query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
11846    
11847                    query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
11848    
11849                    if (orderByComparator != null) {
11850                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11851    
11852                            if (orderByConditionFields.length > 0) {
11853                                    query.append(WHERE_AND);
11854                            }
11855    
11856                            for (int i = 0; i < orderByConditionFields.length; i++) {
11857                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11858                                    query.append(orderByConditionFields[i]);
11859    
11860                                    if ((i + 1) < orderByConditionFields.length) {
11861                                            if (orderByComparator.isAscending() ^ previous) {
11862                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11863                                            }
11864                                            else {
11865                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11866                                            }
11867                                    }
11868                                    else {
11869                                            if (orderByComparator.isAscending() ^ previous) {
11870                                                    query.append(WHERE_GREATER_THAN);
11871                                            }
11872                                            else {
11873                                                    query.append(WHERE_LESSER_THAN);
11874                                            }
11875                                    }
11876                            }
11877    
11878                            query.append(ORDER_BY_CLAUSE);
11879    
11880                            String[] orderByFields = orderByComparator.getOrderByFields();
11881    
11882                            for (int i = 0; i < orderByFields.length; i++) {
11883                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11884                                    query.append(orderByFields[i]);
11885    
11886                                    if ((i + 1) < orderByFields.length) {
11887                                            if (orderByComparator.isAscending() ^ previous) {
11888                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11889                                            }
11890                                            else {
11891                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11892                                            }
11893                                    }
11894                                    else {
11895                                            if (orderByComparator.isAscending() ^ previous) {
11896                                                    query.append(ORDER_BY_ASC);
11897                                            }
11898                                            else {
11899                                                    query.append(ORDER_BY_DESC);
11900                                            }
11901                                    }
11902                            }
11903                    }
11904                    else {
11905                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11906                    }
11907    
11908                    String sql = query.toString();
11909    
11910                    Query q = session.createQuery(sql);
11911    
11912                    q.setFirstResult(0);
11913                    q.setMaxResults(2);
11914    
11915                    QueryPos qPos = QueryPos.getInstance(q);
11916    
11917                    qPos.add(nodeId);
11918    
11919                    qPos.add(head);
11920    
11921                    qPos.add(status);
11922    
11923                    if (orderByComparator != null) {
11924                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
11925    
11926                            for (Object value : values) {
11927                                    qPos.add(value);
11928                            }
11929                    }
11930    
11931                    List<WikiPage> list = q.list();
11932    
11933                    if (list.size() == 2) {
11934                            return list.get(1);
11935                    }
11936                    else {
11937                            return null;
11938                    }
11939            }
11940    
11941            /**
11942             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63; from the database.
11943             *
11944             * @param nodeId the node ID
11945             * @param head the head
11946             * @param status the status
11947             * @throws SystemException if a system exception occurred
11948             */
11949            public void removeByN_H_S(long nodeId, boolean head, int status)
11950                    throws SystemException {
11951                    for (WikiPage wikiPage : findByN_H_S(nodeId, head, status,
11952                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11953                            remove(wikiPage);
11954                    }
11955            }
11956    
11957            /**
11958             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
11959             *
11960             * @param nodeId the node ID
11961             * @param head the head
11962             * @param status the status
11963             * @return the number of matching wiki pages
11964             * @throws SystemException if a system exception occurred
11965             */
11966            public int countByN_H_S(long nodeId, boolean head, int status)
11967                    throws SystemException {
11968                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_S;
11969    
11970                    Object[] finderArgs = new Object[] { nodeId, head, status };
11971    
11972                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11973                                    this);
11974    
11975                    if (count == null) {
11976                            StringBundler query = new StringBundler(4);
11977    
11978                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
11979    
11980                            query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
11981    
11982                            query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
11983    
11984                            query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
11985    
11986                            String sql = query.toString();
11987    
11988                            Session session = null;
11989    
11990                            try {
11991                                    session = openSession();
11992    
11993                                    Query q = session.createQuery(sql);
11994    
11995                                    QueryPos qPos = QueryPos.getInstance(q);
11996    
11997                                    qPos.add(nodeId);
11998    
11999                                    qPos.add(head);
12000    
12001                                    qPos.add(status);
12002    
12003                                    count = (Long)q.uniqueResult();
12004    
12005                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12006                            }
12007                            catch (Exception e) {
12008                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12009    
12010                                    throw processException(e);
12011                            }
12012                            finally {
12013                                    closeSession(session);
12014                            }
12015                    }
12016    
12017                    return count.intValue();
12018            }
12019    
12020            private static final String _FINDER_COLUMN_N_H_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
12021            private static final String _FINDER_COLUMN_N_H_S_HEAD_2 = "wikiPage.head = ? AND ";
12022            private static final String _FINDER_COLUMN_N_H_S_STATUS_2 = "wikiPage.status = ?";
12023            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12024                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
12025                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_N_S",
12026                            new String[] {
12027                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12028                                    Integer.class.getName(),
12029                                    
12030                            Integer.class.getName(), Integer.class.getName(),
12031                                    OrderByComparator.class.getName()
12032                            });
12033            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S =
12034                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12035                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
12036                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_N_S",
12037                            new String[] {
12038                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12039                                    Integer.class.getName()
12040                            },
12041                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
12042                            WikiPageModelImpl.USERID_COLUMN_BITMASK |
12043                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
12044                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
12045                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
12046                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
12047            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12048                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12049                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_N_S",
12050                            new String[] {
12051                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
12052                                    Integer.class.getName()
12053                            });
12054    
12055            /**
12056             * Returns all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12057             *
12058             * @param groupId the group ID
12059             * @param userId the user ID
12060             * @param nodeId the node ID
12061             * @param status the status
12062             * @return the matching wiki pages
12063             * @throws SystemException if a system exception occurred
12064             */
12065            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
12066                    int status) throws SystemException {
12067                    return findByG_U_N_S(groupId, userId, nodeId, status,
12068                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12069            }
12070    
12071            /**
12072             * Returns a range of all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12073             *
12074             * <p>
12075             * 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.
12076             * </p>
12077             *
12078             * @param groupId the group ID
12079             * @param userId the user ID
12080             * @param nodeId the node ID
12081             * @param status the status
12082             * @param start the lower bound of the range of wiki pages
12083             * @param end the upper bound of the range of wiki pages (not inclusive)
12084             * @return the range of matching wiki pages
12085             * @throws SystemException if a system exception occurred
12086             */
12087            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
12088                    int status, int start, int end) throws SystemException {
12089                    return findByG_U_N_S(groupId, userId, nodeId, status, start, end, null);
12090            }
12091    
12092            /**
12093             * Returns an ordered range of all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12094             *
12095             * <p>
12096             * 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.
12097             * </p>
12098             *
12099             * @param groupId the group ID
12100             * @param userId the user ID
12101             * @param nodeId the node ID
12102             * @param status the status
12103             * @param start the lower bound of the range of wiki pages
12104             * @param end the upper bound of the range of wiki pages (not inclusive)
12105             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12106             * @return the ordered range of matching wiki pages
12107             * @throws SystemException if a system exception occurred
12108             */
12109            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
12110                    int status, int start, int end, OrderByComparator orderByComparator)
12111                    throws SystemException {
12112                    boolean pagination = true;
12113                    FinderPath finderPath = null;
12114                    Object[] finderArgs = null;
12115    
12116                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12117                                    (orderByComparator == null)) {
12118                            pagination = false;
12119                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S;
12120                            finderArgs = new Object[] { groupId, userId, nodeId, status };
12121                    }
12122                    else {
12123                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_N_S;
12124                            finderArgs = new Object[] {
12125                                            groupId, userId, nodeId, status,
12126                                            
12127                                            start, end, orderByComparator
12128                                    };
12129                    }
12130    
12131                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
12132                                    finderArgs, this);
12133    
12134                    if ((list != null) && !list.isEmpty()) {
12135                            for (WikiPage wikiPage : list) {
12136                                    if ((groupId != wikiPage.getGroupId()) ||
12137                                                    (userId != wikiPage.getUserId()) ||
12138                                                    (nodeId != wikiPage.getNodeId()) ||
12139                                                    (status != wikiPage.getStatus())) {
12140                                            list = null;
12141    
12142                                            break;
12143                                    }
12144                            }
12145                    }
12146    
12147                    if (list == null) {
12148                            StringBundler query = null;
12149    
12150                            if (orderByComparator != null) {
12151                                    query = new StringBundler(6 +
12152                                                    (orderByComparator.getOrderByFields().length * 3));
12153                            }
12154                            else {
12155                                    query = new StringBundler(6);
12156                            }
12157    
12158                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
12159    
12160                            query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12161    
12162                            query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12163    
12164                            query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12165    
12166                            query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12167    
12168                            if (orderByComparator != null) {
12169                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12170                                            orderByComparator);
12171                            }
12172                            else
12173                             if (pagination) {
12174                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12175                            }
12176    
12177                            String sql = query.toString();
12178    
12179                            Session session = null;
12180    
12181                            try {
12182                                    session = openSession();
12183    
12184                                    Query q = session.createQuery(sql);
12185    
12186                                    QueryPos qPos = QueryPos.getInstance(q);
12187    
12188                                    qPos.add(groupId);
12189    
12190                                    qPos.add(userId);
12191    
12192                                    qPos.add(nodeId);
12193    
12194                                    qPos.add(status);
12195    
12196                                    if (!pagination) {
12197                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
12198                                                            start, end, false);
12199    
12200                                            Collections.sort(list);
12201    
12202                                            list = new UnmodifiableList<WikiPage>(list);
12203                                    }
12204                                    else {
12205                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
12206                                                            start, end);
12207                                    }
12208    
12209                                    cacheResult(list);
12210    
12211                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
12212                            }
12213                            catch (Exception e) {
12214                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12215    
12216                                    throw processException(e);
12217                            }
12218                            finally {
12219                                    closeSession(session);
12220                            }
12221                    }
12222    
12223                    return list;
12224            }
12225    
12226            /**
12227             * Returns the first wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12228             *
12229             * @param groupId the group ID
12230             * @param userId the user ID
12231             * @param nodeId the node ID
12232             * @param status the status
12233             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12234             * @return the first matching wiki page
12235             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
12236             * @throws SystemException if a system exception occurred
12237             */
12238            public WikiPage findByG_U_N_S_First(long groupId, long userId, long nodeId,
12239                    int status, OrderByComparator orderByComparator)
12240                    throws NoSuchPageException, SystemException {
12241                    WikiPage wikiPage = fetchByG_U_N_S_First(groupId, userId, nodeId,
12242                                    status, orderByComparator);
12243    
12244                    if (wikiPage != null) {
12245                            return wikiPage;
12246                    }
12247    
12248                    StringBundler msg = new StringBundler(10);
12249    
12250                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12251    
12252                    msg.append("groupId=");
12253                    msg.append(groupId);
12254    
12255                    msg.append(", userId=");
12256                    msg.append(userId);
12257    
12258                    msg.append(", nodeId=");
12259                    msg.append(nodeId);
12260    
12261                    msg.append(", status=");
12262                    msg.append(status);
12263    
12264                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12265    
12266                    throw new NoSuchPageException(msg.toString());
12267            }
12268    
12269            /**
12270             * Returns the first wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12271             *
12272             * @param groupId the group ID
12273             * @param userId the user ID
12274             * @param nodeId the node ID
12275             * @param status the status
12276             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12277             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
12278             * @throws SystemException if a system exception occurred
12279             */
12280            public WikiPage fetchByG_U_N_S_First(long groupId, long userId,
12281                    long nodeId, int status, OrderByComparator orderByComparator)
12282                    throws SystemException {
12283                    List<WikiPage> list = findByG_U_N_S(groupId, userId, nodeId, status, 0,
12284                                    1, orderByComparator);
12285    
12286                    if (!list.isEmpty()) {
12287                            return list.get(0);
12288                    }
12289    
12290                    return null;
12291            }
12292    
12293            /**
12294             * Returns the last wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12295             *
12296             * @param groupId the group ID
12297             * @param userId the user ID
12298             * @param nodeId the node ID
12299             * @param status the status
12300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12301             * @return the last matching wiki page
12302             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
12303             * @throws SystemException if a system exception occurred
12304             */
12305            public WikiPage findByG_U_N_S_Last(long groupId, long userId, long nodeId,
12306                    int status, OrderByComparator orderByComparator)
12307                    throws NoSuchPageException, SystemException {
12308                    WikiPage wikiPage = fetchByG_U_N_S_Last(groupId, userId, nodeId,
12309                                    status, orderByComparator);
12310    
12311                    if (wikiPage != null) {
12312                            return wikiPage;
12313                    }
12314    
12315                    StringBundler msg = new StringBundler(10);
12316    
12317                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12318    
12319                    msg.append("groupId=");
12320                    msg.append(groupId);
12321    
12322                    msg.append(", userId=");
12323                    msg.append(userId);
12324    
12325                    msg.append(", nodeId=");
12326                    msg.append(nodeId);
12327    
12328                    msg.append(", status=");
12329                    msg.append(status);
12330    
12331                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12332    
12333                    throw new NoSuchPageException(msg.toString());
12334            }
12335    
12336            /**
12337             * Returns the last wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12338             *
12339             * @param groupId the group ID
12340             * @param userId the user ID
12341             * @param nodeId the node ID
12342             * @param status the status
12343             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12344             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
12345             * @throws SystemException if a system exception occurred
12346             */
12347            public WikiPage fetchByG_U_N_S_Last(long groupId, long userId, long nodeId,
12348                    int status, OrderByComparator orderByComparator)
12349                    throws SystemException {
12350                    int count = countByG_U_N_S(groupId, userId, nodeId, status);
12351    
12352                    List<WikiPage> list = findByG_U_N_S(groupId, userId, nodeId, status,
12353                                    count - 1, count, orderByComparator);
12354    
12355                    if (!list.isEmpty()) {
12356                            return list.get(0);
12357                    }
12358    
12359                    return null;
12360            }
12361    
12362            /**
12363             * 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;.
12364             *
12365             * @param pageId the primary key of the current wiki page
12366             * @param groupId the group ID
12367             * @param userId the user ID
12368             * @param nodeId the node ID
12369             * @param status the status
12370             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12371             * @return the previous, current, and next wiki page
12372             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
12373             * @throws SystemException if a system exception occurred
12374             */
12375            public WikiPage[] findByG_U_N_S_PrevAndNext(long pageId, long groupId,
12376                    long userId, long nodeId, int status,
12377                    OrderByComparator orderByComparator)
12378                    throws NoSuchPageException, SystemException {
12379                    WikiPage wikiPage = findByPrimaryKey(pageId);
12380    
12381                    Session session = null;
12382    
12383                    try {
12384                            session = openSession();
12385    
12386                            WikiPage[] array = new WikiPageImpl[3];
12387    
12388                            array[0] = getByG_U_N_S_PrevAndNext(session, wikiPage, groupId,
12389                                            userId, nodeId, status, orderByComparator, true);
12390    
12391                            array[1] = wikiPage;
12392    
12393                            array[2] = getByG_U_N_S_PrevAndNext(session, wikiPage, groupId,
12394                                            userId, nodeId, status, orderByComparator, false);
12395    
12396                            return array;
12397                    }
12398                    catch (Exception e) {
12399                            throw processException(e);
12400                    }
12401                    finally {
12402                            closeSession(session);
12403                    }
12404            }
12405    
12406            protected WikiPage getByG_U_N_S_PrevAndNext(Session session,
12407                    WikiPage wikiPage, long groupId, long userId, long nodeId, int status,
12408                    OrderByComparator orderByComparator, boolean previous) {
12409                    StringBundler query = null;
12410    
12411                    if (orderByComparator != null) {
12412                            query = new StringBundler(6 +
12413                                            (orderByComparator.getOrderByFields().length * 6));
12414                    }
12415                    else {
12416                            query = new StringBundler(3);
12417                    }
12418    
12419                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
12420    
12421                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12422    
12423                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12424    
12425                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12426    
12427                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12428    
12429                    if (orderByComparator != null) {
12430                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12431    
12432                            if (orderByConditionFields.length > 0) {
12433                                    query.append(WHERE_AND);
12434                            }
12435    
12436                            for (int i = 0; i < orderByConditionFields.length; i++) {
12437                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12438                                    query.append(orderByConditionFields[i]);
12439    
12440                                    if ((i + 1) < orderByConditionFields.length) {
12441                                            if (orderByComparator.isAscending() ^ previous) {
12442                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12443                                            }
12444                                            else {
12445                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12446                                            }
12447                                    }
12448                                    else {
12449                                            if (orderByComparator.isAscending() ^ previous) {
12450                                                    query.append(WHERE_GREATER_THAN);
12451                                            }
12452                                            else {
12453                                                    query.append(WHERE_LESSER_THAN);
12454                                            }
12455                                    }
12456                            }
12457    
12458                            query.append(ORDER_BY_CLAUSE);
12459    
12460                            String[] orderByFields = orderByComparator.getOrderByFields();
12461    
12462                            for (int i = 0; i < orderByFields.length; i++) {
12463                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12464                                    query.append(orderByFields[i]);
12465    
12466                                    if ((i + 1) < orderByFields.length) {
12467                                            if (orderByComparator.isAscending() ^ previous) {
12468                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12469                                            }
12470                                            else {
12471                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12472                                            }
12473                                    }
12474                                    else {
12475                                            if (orderByComparator.isAscending() ^ previous) {
12476                                                    query.append(ORDER_BY_ASC);
12477                                            }
12478                                            else {
12479                                                    query.append(ORDER_BY_DESC);
12480                                            }
12481                                    }
12482                            }
12483                    }
12484                    else {
12485                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12486                    }
12487    
12488                    String sql = query.toString();
12489    
12490                    Query q = session.createQuery(sql);
12491    
12492                    q.setFirstResult(0);
12493                    q.setMaxResults(2);
12494    
12495                    QueryPos qPos = QueryPos.getInstance(q);
12496    
12497                    qPos.add(groupId);
12498    
12499                    qPos.add(userId);
12500    
12501                    qPos.add(nodeId);
12502    
12503                    qPos.add(status);
12504    
12505                    if (orderByComparator != null) {
12506                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
12507    
12508                            for (Object value : values) {
12509                                    qPos.add(value);
12510                            }
12511                    }
12512    
12513                    List<WikiPage> list = q.list();
12514    
12515                    if (list.size() == 2) {
12516                            return list.get(1);
12517                    }
12518                    else {
12519                            return null;
12520                    }
12521            }
12522    
12523            /**
12524             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12525             *
12526             * @param groupId the group ID
12527             * @param userId the user ID
12528             * @param nodeId the node ID
12529             * @param status the status
12530             * @return the matching wiki pages that the user has permission to view
12531             * @throws SystemException if a system exception occurred
12532             */
12533            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
12534                    long nodeId, int status) throws SystemException {
12535                    return filterFindByG_U_N_S(groupId, userId, nodeId, status,
12536                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12537            }
12538    
12539            /**
12540             * 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;.
12541             *
12542             * <p>
12543             * 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.
12544             * </p>
12545             *
12546             * @param groupId the group ID
12547             * @param userId the user ID
12548             * @param nodeId the node ID
12549             * @param status the status
12550             * @param start the lower bound of the range of wiki pages
12551             * @param end the upper bound of the range of wiki pages (not inclusive)
12552             * @return the range of matching wiki pages that the user has permission to view
12553             * @throws SystemException if a system exception occurred
12554             */
12555            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
12556                    long nodeId, int status, int start, int end) throws SystemException {
12557                    return filterFindByG_U_N_S(groupId, userId, nodeId, status, start, end,
12558                            null);
12559            }
12560    
12561            /**
12562             * 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;.
12563             *
12564             * <p>
12565             * 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.
12566             * </p>
12567             *
12568             * @param groupId the group ID
12569             * @param userId the user ID
12570             * @param nodeId the node ID
12571             * @param status the status
12572             * @param start the lower bound of the range of wiki pages
12573             * @param end the upper bound of the range of wiki pages (not inclusive)
12574             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12575             * @return the ordered range of matching wiki pages that the user has permission to view
12576             * @throws SystemException if a system exception occurred
12577             */
12578            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
12579                    long nodeId, int status, int start, int end,
12580                    OrderByComparator orderByComparator) throws SystemException {
12581                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12582                            return findByG_U_N_S(groupId, userId, nodeId, status, start, end,
12583                                    orderByComparator);
12584                    }
12585    
12586                    StringBundler query = null;
12587    
12588                    if (orderByComparator != null) {
12589                            query = new StringBundler(6 +
12590                                            (orderByComparator.getOrderByFields().length * 3));
12591                    }
12592                    else {
12593                            query = new StringBundler(6);
12594                    }
12595    
12596                    if (getDB().isSupportsInlineDistinct()) {
12597                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
12598                    }
12599                    else {
12600                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
12601                    }
12602    
12603                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12604    
12605                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12606    
12607                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12608    
12609                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12610    
12611                    if (!getDB().isSupportsInlineDistinct()) {
12612                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
12613                    }
12614    
12615                    if (orderByComparator != null) {
12616                            if (getDB().isSupportsInlineDistinct()) {
12617                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12618                                            orderByComparator);
12619                            }
12620                            else {
12621                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12622                                            orderByComparator);
12623                            }
12624                    }
12625                    else {
12626                            if (getDB().isSupportsInlineDistinct()) {
12627                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12628                            }
12629                            else {
12630                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
12631                            }
12632                    }
12633    
12634                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12635                                    WikiPage.class.getName(),
12636                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12637    
12638                    Session session = null;
12639    
12640                    try {
12641                            session = openSession();
12642    
12643                            SQLQuery q = session.createSQLQuery(sql);
12644    
12645                            if (getDB().isSupportsInlineDistinct()) {
12646                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
12647                            }
12648                            else {
12649                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
12650                            }
12651    
12652                            QueryPos qPos = QueryPos.getInstance(q);
12653    
12654                            qPos.add(groupId);
12655    
12656                            qPos.add(userId);
12657    
12658                            qPos.add(nodeId);
12659    
12660                            qPos.add(status);
12661    
12662                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
12663                    }
12664                    catch (Exception e) {
12665                            throw processException(e);
12666                    }
12667                    finally {
12668                            closeSession(session);
12669                    }
12670            }
12671    
12672            /**
12673             * 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;.
12674             *
12675             * @param pageId the primary key of the current wiki page
12676             * @param groupId the group ID
12677             * @param userId the user ID
12678             * @param nodeId the node ID
12679             * @param status the status
12680             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12681             * @return the previous, current, and next wiki page
12682             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
12683             * @throws SystemException if a system exception occurred
12684             */
12685            public WikiPage[] filterFindByG_U_N_S_PrevAndNext(long pageId,
12686                    long groupId, long userId, long nodeId, int status,
12687                    OrderByComparator orderByComparator)
12688                    throws NoSuchPageException, SystemException {
12689                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12690                            return findByG_U_N_S_PrevAndNext(pageId, groupId, userId, nodeId,
12691                                    status, orderByComparator);
12692                    }
12693    
12694                    WikiPage wikiPage = findByPrimaryKey(pageId);
12695    
12696                    Session session = null;
12697    
12698                    try {
12699                            session = openSession();
12700    
12701                            WikiPage[] array = new WikiPageImpl[3];
12702    
12703                            array[0] = filterGetByG_U_N_S_PrevAndNext(session, wikiPage,
12704                                            groupId, userId, nodeId, status, orderByComparator, true);
12705    
12706                            array[1] = wikiPage;
12707    
12708                            array[2] = filterGetByG_U_N_S_PrevAndNext(session, wikiPage,
12709                                            groupId, userId, nodeId, status, orderByComparator, false);
12710    
12711                            return array;
12712                    }
12713                    catch (Exception e) {
12714                            throw processException(e);
12715                    }
12716                    finally {
12717                            closeSession(session);
12718                    }
12719            }
12720    
12721            protected WikiPage filterGetByG_U_N_S_PrevAndNext(Session session,
12722                    WikiPage wikiPage, long groupId, long userId, long nodeId, int status,
12723                    OrderByComparator orderByComparator, boolean previous) {
12724                    StringBundler query = null;
12725    
12726                    if (orderByComparator != null) {
12727                            query = new StringBundler(6 +
12728                                            (orderByComparator.getOrderByFields().length * 6));
12729                    }
12730                    else {
12731                            query = new StringBundler(3);
12732                    }
12733    
12734                    if (getDB().isSupportsInlineDistinct()) {
12735                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
12736                    }
12737                    else {
12738                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
12739                    }
12740    
12741                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12742    
12743                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12744    
12745                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12746    
12747                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12748    
12749                    if (!getDB().isSupportsInlineDistinct()) {
12750                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
12751                    }
12752    
12753                    if (orderByComparator != null) {
12754                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12755    
12756                            if (orderByConditionFields.length > 0) {
12757                                    query.append(WHERE_AND);
12758                            }
12759    
12760                            for (int i = 0; i < orderByConditionFields.length; i++) {
12761                                    if (getDB().isSupportsInlineDistinct()) {
12762                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12763                                    }
12764                                    else {
12765                                            query.append(_ORDER_BY_ENTITY_TABLE);
12766                                    }
12767    
12768                                    query.append(orderByConditionFields[i]);
12769    
12770                                    if ((i + 1) < orderByConditionFields.length) {
12771                                            if (orderByComparator.isAscending() ^ previous) {
12772                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12773                                            }
12774                                            else {
12775                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12776                                            }
12777                                    }
12778                                    else {
12779                                            if (orderByComparator.isAscending() ^ previous) {
12780                                                    query.append(WHERE_GREATER_THAN);
12781                                            }
12782                                            else {
12783                                                    query.append(WHERE_LESSER_THAN);
12784                                            }
12785                                    }
12786                            }
12787    
12788                            query.append(ORDER_BY_CLAUSE);
12789    
12790                            String[] orderByFields = orderByComparator.getOrderByFields();
12791    
12792                            for (int i = 0; i < orderByFields.length; i++) {
12793                                    if (getDB().isSupportsInlineDistinct()) {
12794                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12795                                    }
12796                                    else {
12797                                            query.append(_ORDER_BY_ENTITY_TABLE);
12798                                    }
12799    
12800                                    query.append(orderByFields[i]);
12801    
12802                                    if ((i + 1) < orderByFields.length) {
12803                                            if (orderByComparator.isAscending() ^ previous) {
12804                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12805                                            }
12806                                            else {
12807                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12808                                            }
12809                                    }
12810                                    else {
12811                                            if (orderByComparator.isAscending() ^ previous) {
12812                                                    query.append(ORDER_BY_ASC);
12813                                            }
12814                                            else {
12815                                                    query.append(ORDER_BY_DESC);
12816                                            }
12817                                    }
12818                            }
12819                    }
12820                    else {
12821                            if (getDB().isSupportsInlineDistinct()) {
12822                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12823                            }
12824                            else {
12825                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
12826                            }
12827                    }
12828    
12829                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12830                                    WikiPage.class.getName(),
12831                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12832    
12833                    SQLQuery q = session.createSQLQuery(sql);
12834    
12835                    q.setFirstResult(0);
12836                    q.setMaxResults(2);
12837    
12838                    if (getDB().isSupportsInlineDistinct()) {
12839                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
12840                    }
12841                    else {
12842                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
12843                    }
12844    
12845                    QueryPos qPos = QueryPos.getInstance(q);
12846    
12847                    qPos.add(groupId);
12848    
12849                    qPos.add(userId);
12850    
12851                    qPos.add(nodeId);
12852    
12853                    qPos.add(status);
12854    
12855                    if (orderByComparator != null) {
12856                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
12857    
12858                            for (Object value : values) {
12859                                    qPos.add(value);
12860                            }
12861                    }
12862    
12863                    List<WikiPage> list = q.list();
12864    
12865                    if (list.size() == 2) {
12866                            return list.get(1);
12867                    }
12868                    else {
12869                            return null;
12870                    }
12871            }
12872    
12873            /**
12874             * Removes all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63; from the database.
12875             *
12876             * @param groupId the group ID
12877             * @param userId the user ID
12878             * @param nodeId the node ID
12879             * @param status the status
12880             * @throws SystemException if a system exception occurred
12881             */
12882            public void removeByG_U_N_S(long groupId, long userId, long nodeId,
12883                    int status) throws SystemException {
12884                    for (WikiPage wikiPage : findByG_U_N_S(groupId, userId, nodeId, status,
12885                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12886                            remove(wikiPage);
12887                    }
12888            }
12889    
12890            /**
12891             * Returns the number of wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
12892             *
12893             * @param groupId the group ID
12894             * @param userId the user ID
12895             * @param nodeId the node ID
12896             * @param status the status
12897             * @return the number of matching wiki pages
12898             * @throws SystemException if a system exception occurred
12899             */
12900            public int countByG_U_N_S(long groupId, long userId, long nodeId, int status)
12901                    throws SystemException {
12902                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_N_S;
12903    
12904                    Object[] finderArgs = new Object[] { groupId, userId, nodeId, status };
12905    
12906                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12907                                    this);
12908    
12909                    if (count == null) {
12910                            StringBundler query = new StringBundler(5);
12911    
12912                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
12913    
12914                            query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12915    
12916                            query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12917    
12918                            query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12919    
12920                            query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12921    
12922                            String sql = query.toString();
12923    
12924                            Session session = null;
12925    
12926                            try {
12927                                    session = openSession();
12928    
12929                                    Query q = session.createQuery(sql);
12930    
12931                                    QueryPos qPos = QueryPos.getInstance(q);
12932    
12933                                    qPos.add(groupId);
12934    
12935                                    qPos.add(userId);
12936    
12937                                    qPos.add(nodeId);
12938    
12939                                    qPos.add(status);
12940    
12941                                    count = (Long)q.uniqueResult();
12942    
12943                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12944                            }
12945                            catch (Exception e) {
12946                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12947    
12948                                    throw processException(e);
12949                            }
12950                            finally {
12951                                    closeSession(session);
12952                            }
12953                    }
12954    
12955                    return count.intValue();
12956            }
12957    
12958            /**
12959             * 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;.
12960             *
12961             * @param groupId the group ID
12962             * @param userId the user ID
12963             * @param nodeId the node ID
12964             * @param status the status
12965             * @return the number of matching wiki pages that the user has permission to view
12966             * @throws SystemException if a system exception occurred
12967             */
12968            public int filterCountByG_U_N_S(long groupId, long userId, long nodeId,
12969                    int status) throws SystemException {
12970                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12971                            return countByG_U_N_S(groupId, userId, nodeId, status);
12972                    }
12973    
12974                    StringBundler query = new StringBundler(5);
12975    
12976                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
12977    
12978                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
12979    
12980                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
12981    
12982                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
12983    
12984                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
12985    
12986                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12987                                    WikiPage.class.getName(),
12988                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12989    
12990                    Session session = null;
12991    
12992                    try {
12993                            session = openSession();
12994    
12995                            SQLQuery q = session.createSQLQuery(sql);
12996    
12997                            q.addScalar(COUNT_COLUMN_NAME,
12998                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12999    
13000                            QueryPos qPos = QueryPos.getInstance(q);
13001    
13002                            qPos.add(groupId);
13003    
13004                            qPos.add(userId);
13005    
13006                            qPos.add(nodeId);
13007    
13008                            qPos.add(status);
13009    
13010                            Long count = (Long)q.uniqueResult();
13011    
13012                            return count.intValue();
13013                    }
13014                    catch (Exception e) {
13015                            throw processException(e);
13016                    }
13017                    finally {
13018                            closeSession(session);
13019                    }
13020            }
13021    
13022            private static final String _FINDER_COLUMN_G_U_N_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
13023            private static final String _FINDER_COLUMN_G_U_N_S_USERID_2 = "wikiPage.userId = ? AND ";
13024            private static final String _FINDER_COLUMN_G_U_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
13025            private static final String _FINDER_COLUMN_G_U_N_S_STATUS_2 = "wikiPage.status = ?";
13026            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13027                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
13028                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_T_H",
13029                            new String[] {
13030                                    Long.class.getName(), Long.class.getName(),
13031                                    String.class.getName(), Boolean.class.getName(),
13032                                    
13033                            Integer.class.getName(), Integer.class.getName(),
13034                                    OrderByComparator.class.getName()
13035                            });
13036            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H =
13037                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13038                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
13039                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_T_H",
13040                            new String[] {
13041                                    Long.class.getName(), Long.class.getName(),
13042                                    String.class.getName(), Boolean.class.getName()
13043                            },
13044                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
13045                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
13046                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
13047                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
13048                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
13049            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13050                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13051                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_T_H",
13052                            new String[] {
13053                                    Long.class.getName(), Long.class.getName(),
13054                                    String.class.getName(), Boolean.class.getName()
13055                            });
13056    
13057            /**
13058             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13059             *
13060             * @param groupId the group ID
13061             * @param nodeId the node ID
13062             * @param title the title
13063             * @param head the head
13064             * @return the matching wiki pages
13065             * @throws SystemException if a system exception occurred
13066             */
13067            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
13068                    String title, boolean head) throws SystemException {
13069                    return findByG_N_T_H(groupId, nodeId, title, head, QueryUtil.ALL_POS,
13070                            QueryUtil.ALL_POS, null);
13071            }
13072    
13073            /**
13074             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13075             *
13076             * <p>
13077             * 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.
13078             * </p>
13079             *
13080             * @param groupId the group ID
13081             * @param nodeId the node ID
13082             * @param title the title
13083             * @param head the head
13084             * @param start the lower bound of the range of wiki pages
13085             * @param end the upper bound of the range of wiki pages (not inclusive)
13086             * @return the range of matching wiki pages
13087             * @throws SystemException if a system exception occurred
13088             */
13089            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
13090                    String title, boolean head, int start, int end)
13091                    throws SystemException {
13092                    return findByG_N_T_H(groupId, nodeId, title, head, start, end, null);
13093            }
13094    
13095            /**
13096             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13097             *
13098             * <p>
13099             * 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.
13100             * </p>
13101             *
13102             * @param groupId the group ID
13103             * @param nodeId the node ID
13104             * @param title the title
13105             * @param head the head
13106             * @param start the lower bound of the range of wiki pages
13107             * @param end the upper bound of the range of wiki pages (not inclusive)
13108             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13109             * @return the ordered range of matching wiki pages
13110             * @throws SystemException if a system exception occurred
13111             */
13112            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
13113                    String title, boolean head, int start, int end,
13114                    OrderByComparator orderByComparator) throws SystemException {
13115                    boolean pagination = true;
13116                    FinderPath finderPath = null;
13117                    Object[] finderArgs = null;
13118    
13119                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13120                                    (orderByComparator == null)) {
13121                            pagination = false;
13122                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H;
13123                            finderArgs = new Object[] { groupId, nodeId, title, head };
13124                    }
13125                    else {
13126                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_H;
13127                            finderArgs = new Object[] {
13128                                            groupId, nodeId, title, head,
13129                                            
13130                                            start, end, orderByComparator
13131                                    };
13132                    }
13133    
13134                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
13135                                    finderArgs, this);
13136    
13137                    if ((list != null) && !list.isEmpty()) {
13138                            for (WikiPage wikiPage : list) {
13139                                    if ((groupId != wikiPage.getGroupId()) ||
13140                                                    (nodeId != wikiPage.getNodeId()) ||
13141                                                    !Validator.equals(title, wikiPage.getTitle()) ||
13142                                                    (head != wikiPage.getHead())) {
13143                                            list = null;
13144    
13145                                            break;
13146                                    }
13147                            }
13148                    }
13149    
13150                    if (list == null) {
13151                            StringBundler query = null;
13152    
13153                            if (orderByComparator != null) {
13154                                    query = new StringBundler(6 +
13155                                                    (orderByComparator.getOrderByFields().length * 3));
13156                            }
13157                            else {
13158                                    query = new StringBundler(6);
13159                            }
13160    
13161                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13162    
13163                            query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
13164    
13165                            query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
13166    
13167                            if (title == null) {
13168                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
13169                            }
13170                            else {
13171                                    if (title.equals(StringPool.BLANK)) {
13172                                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
13173                                    }
13174                                    else {
13175                                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
13176                                    }
13177                            }
13178    
13179                            query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
13180    
13181                            if (orderByComparator != null) {
13182                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13183                                            orderByComparator);
13184                            }
13185                            else
13186                             if (pagination) {
13187                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13188                            }
13189    
13190                            String sql = query.toString();
13191    
13192                            Session session = null;
13193    
13194                            try {
13195                                    session = openSession();
13196    
13197                                    Query q = session.createQuery(sql);
13198    
13199                                    QueryPos qPos = QueryPos.getInstance(q);
13200    
13201                                    qPos.add(groupId);
13202    
13203                                    qPos.add(nodeId);
13204    
13205                                    if (title != null) {
13206                                            qPos.add(title);
13207                                    }
13208    
13209                                    qPos.add(head);
13210    
13211                                    if (!pagination) {
13212                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13213                                                            start, end, false);
13214    
13215                                            Collections.sort(list);
13216    
13217                                            list = new UnmodifiableList<WikiPage>(list);
13218                                    }
13219                                    else {
13220                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13221                                                            start, end);
13222                                    }
13223    
13224                                    cacheResult(list);
13225    
13226                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13227                            }
13228                            catch (Exception e) {
13229                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13230    
13231                                    throw processException(e);
13232                            }
13233                            finally {
13234                                    closeSession(session);
13235                            }
13236                    }
13237    
13238                    return list;
13239            }
13240    
13241            /**
13242             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13243             *
13244             * @param groupId the group ID
13245             * @param nodeId the node ID
13246             * @param title the title
13247             * @param head the head
13248             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13249             * @return the first matching wiki page
13250             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13251             * @throws SystemException if a system exception occurred
13252             */
13253            public WikiPage findByG_N_T_H_First(long groupId, long nodeId,
13254                    String title, boolean head, OrderByComparator orderByComparator)
13255                    throws NoSuchPageException, SystemException {
13256                    WikiPage wikiPage = fetchByG_N_T_H_First(groupId, nodeId, title, head,
13257                                    orderByComparator);
13258    
13259                    if (wikiPage != null) {
13260                            return wikiPage;
13261                    }
13262    
13263                    StringBundler msg = new StringBundler(10);
13264    
13265                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13266    
13267                    msg.append("groupId=");
13268                    msg.append(groupId);
13269    
13270                    msg.append(", nodeId=");
13271                    msg.append(nodeId);
13272    
13273                    msg.append(", title=");
13274                    msg.append(title);
13275    
13276                    msg.append(", head=");
13277                    msg.append(head);
13278    
13279                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13280    
13281                    throw new NoSuchPageException(msg.toString());
13282            }
13283    
13284            /**
13285             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13286             *
13287             * @param groupId the group ID
13288             * @param nodeId the node ID
13289             * @param title the title
13290             * @param head the head
13291             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13292             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
13293             * @throws SystemException if a system exception occurred
13294             */
13295            public WikiPage fetchByG_N_T_H_First(long groupId, long nodeId,
13296                    String title, boolean head, OrderByComparator orderByComparator)
13297                    throws SystemException {
13298                    List<WikiPage> list = findByG_N_T_H(groupId, nodeId, title, head, 0, 1,
13299                                    orderByComparator);
13300    
13301                    if (!list.isEmpty()) {
13302                            return list.get(0);
13303                    }
13304    
13305                    return null;
13306            }
13307    
13308            /**
13309             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13310             *
13311             * @param groupId the group ID
13312             * @param nodeId the node ID
13313             * @param title the title
13314             * @param head the head
13315             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13316             * @return the last matching wiki page
13317             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13318             * @throws SystemException if a system exception occurred
13319             */
13320            public WikiPage findByG_N_T_H_Last(long groupId, long nodeId, String title,
13321                    boolean head, OrderByComparator orderByComparator)
13322                    throws NoSuchPageException, SystemException {
13323                    WikiPage wikiPage = fetchByG_N_T_H_Last(groupId, nodeId, title, head,
13324                                    orderByComparator);
13325    
13326                    if (wikiPage != null) {
13327                            return wikiPage;
13328                    }
13329    
13330                    StringBundler msg = new StringBundler(10);
13331    
13332                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13333    
13334                    msg.append("groupId=");
13335                    msg.append(groupId);
13336    
13337                    msg.append(", nodeId=");
13338                    msg.append(nodeId);
13339    
13340                    msg.append(", title=");
13341                    msg.append(title);
13342    
13343                    msg.append(", head=");
13344                    msg.append(head);
13345    
13346                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13347    
13348                    throw new NoSuchPageException(msg.toString());
13349            }
13350    
13351            /**
13352             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13353             *
13354             * @param groupId the group ID
13355             * @param nodeId the node ID
13356             * @param title the title
13357             * @param head the head
13358             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13359             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
13360             * @throws SystemException if a system exception occurred
13361             */
13362            public WikiPage fetchByG_N_T_H_Last(long groupId, long nodeId,
13363                    String title, boolean head, OrderByComparator orderByComparator)
13364                    throws SystemException {
13365                    int count = countByG_N_T_H(groupId, nodeId, title, head);
13366    
13367                    List<WikiPage> list = findByG_N_T_H(groupId, nodeId, title, head,
13368                                    count - 1, count, orderByComparator);
13369    
13370                    if (!list.isEmpty()) {
13371                            return list.get(0);
13372                    }
13373    
13374                    return null;
13375            }
13376    
13377            /**
13378             * 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;.
13379             *
13380             * @param pageId the primary key of the current wiki page
13381             * @param groupId the group ID
13382             * @param nodeId the node ID
13383             * @param title the title
13384             * @param head the head
13385             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13386             * @return the previous, current, and next wiki page
13387             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
13388             * @throws SystemException if a system exception occurred
13389             */
13390            public WikiPage[] findByG_N_T_H_PrevAndNext(long pageId, long groupId,
13391                    long nodeId, String title, boolean head,
13392                    OrderByComparator orderByComparator)
13393                    throws NoSuchPageException, SystemException {
13394                    WikiPage wikiPage = findByPrimaryKey(pageId);
13395    
13396                    Session session = null;
13397    
13398                    try {
13399                            session = openSession();
13400    
13401                            WikiPage[] array = new WikiPageImpl[3];
13402    
13403                            array[0] = getByG_N_T_H_PrevAndNext(session, wikiPage, groupId,
13404                                            nodeId, title, head, orderByComparator, true);
13405    
13406                            array[1] = wikiPage;
13407    
13408                            array[2] = getByG_N_T_H_PrevAndNext(session, wikiPage, groupId,
13409                                            nodeId, title, head, orderByComparator, false);
13410    
13411                            return array;
13412                    }
13413                    catch (Exception e) {
13414                            throw processException(e);
13415                    }
13416                    finally {
13417                            closeSession(session);
13418                    }
13419            }
13420    
13421            protected WikiPage getByG_N_T_H_PrevAndNext(Session session,
13422                    WikiPage wikiPage, long groupId, long nodeId, String title,
13423                    boolean head, OrderByComparator orderByComparator, boolean previous) {
13424                    StringBundler query = null;
13425    
13426                    if (orderByComparator != null) {
13427                            query = new StringBundler(6 +
13428                                            (orderByComparator.getOrderByFields().length * 6));
13429                    }
13430                    else {
13431                            query = new StringBundler(3);
13432                    }
13433    
13434                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13435    
13436                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
13437    
13438                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
13439    
13440                    if (title == null) {
13441                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
13442                    }
13443                    else {
13444                            if (title.equals(StringPool.BLANK)) {
13445                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
13446                            }
13447                            else {
13448                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
13449                            }
13450                    }
13451    
13452                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
13453    
13454                    if (orderByComparator != null) {
13455                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13456    
13457                            if (orderByConditionFields.length > 0) {
13458                                    query.append(WHERE_AND);
13459                            }
13460    
13461                            for (int i = 0; i < orderByConditionFields.length; i++) {
13462                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13463                                    query.append(orderByConditionFields[i]);
13464    
13465                                    if ((i + 1) < orderByConditionFields.length) {
13466                                            if (orderByComparator.isAscending() ^ previous) {
13467                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13468                                            }
13469                                            else {
13470                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13471                                            }
13472                                    }
13473                                    else {
13474                                            if (orderByComparator.isAscending() ^ previous) {
13475                                                    query.append(WHERE_GREATER_THAN);
13476                                            }
13477                                            else {
13478                                                    query.append(WHERE_LESSER_THAN);
13479                                            }
13480                                    }
13481                            }
13482    
13483                            query.append(ORDER_BY_CLAUSE);
13484    
13485                            String[] orderByFields = orderByComparator.getOrderByFields();
13486    
13487                            for (int i = 0; i < orderByFields.length; i++) {
13488                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13489                                    query.append(orderByFields[i]);
13490    
13491                                    if ((i + 1) < orderByFields.length) {
13492                                            if (orderByComparator.isAscending() ^ previous) {
13493                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13494                                            }
13495                                            else {
13496                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13497                                            }
13498                                    }
13499                                    else {
13500                                            if (orderByComparator.isAscending() ^ previous) {
13501                                                    query.append(ORDER_BY_ASC);
13502                                            }
13503                                            else {
13504                                                    query.append(ORDER_BY_DESC);
13505                                            }
13506                                    }
13507                            }
13508                    }
13509                    else {
13510                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13511                    }
13512    
13513                    String sql = query.toString();
13514    
13515                    Query q = session.createQuery(sql);
13516    
13517                    q.setFirstResult(0);
13518                    q.setMaxResults(2);
13519    
13520                    QueryPos qPos = QueryPos.getInstance(q);
13521    
13522                    qPos.add(groupId);
13523    
13524                    qPos.add(nodeId);
13525    
13526                    if (title != null) {
13527                            qPos.add(title);
13528                    }
13529    
13530                    qPos.add(head);
13531    
13532                    if (orderByComparator != null) {
13533                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
13534    
13535                            for (Object value : values) {
13536                                    qPos.add(value);
13537                            }
13538                    }
13539    
13540                    List<WikiPage> list = q.list();
13541    
13542                    if (list.size() == 2) {
13543                            return list.get(1);
13544                    }
13545                    else {
13546                            return null;
13547                    }
13548            }
13549    
13550            /**
13551             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13552             *
13553             * @param groupId the group ID
13554             * @param nodeId the node ID
13555             * @param title the title
13556             * @param head the head
13557             * @return the matching wiki pages that the user has permission to view
13558             * @throws SystemException if a system exception occurred
13559             */
13560            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
13561                    String title, boolean head) throws SystemException {
13562                    return filterFindByG_N_T_H(groupId, nodeId, title, head,
13563                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13564            }
13565    
13566            /**
13567             * 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;.
13568             *
13569             * <p>
13570             * 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.
13571             * </p>
13572             *
13573             * @param groupId the group ID
13574             * @param nodeId the node ID
13575             * @param title the title
13576             * @param head the head
13577             * @param start the lower bound of the range of wiki pages
13578             * @param end the upper bound of the range of wiki pages (not inclusive)
13579             * @return the range of matching wiki pages that the user has permission to view
13580             * @throws SystemException if a system exception occurred
13581             */
13582            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
13583                    String title, boolean head, int start, int end)
13584                    throws SystemException {
13585                    return filterFindByG_N_T_H(groupId, nodeId, title, head, start, end,
13586                            null);
13587            }
13588    
13589            /**
13590             * 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;.
13591             *
13592             * <p>
13593             * 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.
13594             * </p>
13595             *
13596             * @param groupId the group ID
13597             * @param nodeId the node ID
13598             * @param title the title
13599             * @param head the head
13600             * @param start the lower bound of the range of wiki pages
13601             * @param end the upper bound of the range of wiki pages (not inclusive)
13602             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13603             * @return the ordered range of matching wiki pages that the user has permission to view
13604             * @throws SystemException if a system exception occurred
13605             */
13606            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
13607                    String title, boolean head, int start, int end,
13608                    OrderByComparator orderByComparator) throws SystemException {
13609                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13610                            return findByG_N_T_H(groupId, nodeId, title, head, start, end,
13611                                    orderByComparator);
13612                    }
13613    
13614                    StringBundler query = null;
13615    
13616                    if (orderByComparator != null) {
13617                            query = new StringBundler(6 +
13618                                            (orderByComparator.getOrderByFields().length * 3));
13619                    }
13620                    else {
13621                            query = new StringBundler(6);
13622                    }
13623    
13624                    if (getDB().isSupportsInlineDistinct()) {
13625                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
13626                    }
13627                    else {
13628                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
13629                    }
13630    
13631                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
13632    
13633                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
13634    
13635                    if (title == null) {
13636                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
13637                    }
13638                    else {
13639                            if (title.equals(StringPool.BLANK)) {
13640                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
13641                            }
13642                            else {
13643                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
13644                            }
13645                    }
13646    
13647                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
13648    
13649                    if (!getDB().isSupportsInlineDistinct()) {
13650                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
13651                    }
13652    
13653                    if (orderByComparator != null) {
13654                            if (getDB().isSupportsInlineDistinct()) {
13655                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13656                                            orderByComparator);
13657                            }
13658                            else {
13659                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13660                                            orderByComparator);
13661                            }
13662                    }
13663                    else {
13664                            if (getDB().isSupportsInlineDistinct()) {
13665                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13666                            }
13667                            else {
13668                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
13669                            }
13670                    }
13671    
13672                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13673                                    WikiPage.class.getName(),
13674                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13675    
13676                    Session session = null;
13677    
13678                    try {
13679                            session = openSession();
13680    
13681                            SQLQuery q = session.createSQLQuery(sql);
13682    
13683                            if (getDB().isSupportsInlineDistinct()) {
13684                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
13685                            }
13686                            else {
13687                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
13688                            }
13689    
13690                            QueryPos qPos = QueryPos.getInstance(q);
13691    
13692                            qPos.add(groupId);
13693    
13694                            qPos.add(nodeId);
13695    
13696                            if (title != null) {
13697                                    qPos.add(title);
13698                            }
13699    
13700                            qPos.add(head);
13701    
13702                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
13703                    }
13704                    catch (Exception e) {
13705                            throw processException(e);
13706                    }
13707                    finally {
13708                            closeSession(session);
13709                    }
13710            }
13711    
13712            /**
13713             * 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;.
13714             *
13715             * @param pageId the primary key of the current wiki page
13716             * @param groupId the group ID
13717             * @param nodeId the node ID
13718             * @param title the title
13719             * @param head the head
13720             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13721             * @return the previous, current, and next wiki page
13722             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
13723             * @throws SystemException if a system exception occurred
13724             */
13725            public WikiPage[] filterFindByG_N_T_H_PrevAndNext(long pageId,
13726                    long groupId, long nodeId, String title, boolean head,
13727                    OrderByComparator orderByComparator)
13728                    throws NoSuchPageException, SystemException {
13729                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13730                            return findByG_N_T_H_PrevAndNext(pageId, groupId, nodeId, title,
13731                                    head, orderByComparator);
13732                    }
13733    
13734                    WikiPage wikiPage = findByPrimaryKey(pageId);
13735    
13736                    Session session = null;
13737    
13738                    try {
13739                            session = openSession();
13740    
13741                            WikiPage[] array = new WikiPageImpl[3];
13742    
13743                            array[0] = filterGetByG_N_T_H_PrevAndNext(session, wikiPage,
13744                                            groupId, nodeId, title, head, orderByComparator, true);
13745    
13746                            array[1] = wikiPage;
13747    
13748                            array[2] = filterGetByG_N_T_H_PrevAndNext(session, wikiPage,
13749                                            groupId, nodeId, title, head, orderByComparator, false);
13750    
13751                            return array;
13752                    }
13753                    catch (Exception e) {
13754                            throw processException(e);
13755                    }
13756                    finally {
13757                            closeSession(session);
13758                    }
13759            }
13760    
13761            protected WikiPage filterGetByG_N_T_H_PrevAndNext(Session session,
13762                    WikiPage wikiPage, long groupId, long nodeId, String title,
13763                    boolean head, OrderByComparator orderByComparator, boolean previous) {
13764                    StringBundler query = null;
13765    
13766                    if (orderByComparator != null) {
13767                            query = new StringBundler(6 +
13768                                            (orderByComparator.getOrderByFields().length * 6));
13769                    }
13770                    else {
13771                            query = new StringBundler(3);
13772                    }
13773    
13774                    if (getDB().isSupportsInlineDistinct()) {
13775                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
13776                    }
13777                    else {
13778                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
13779                    }
13780    
13781                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
13782    
13783                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
13784    
13785                    if (title == null) {
13786                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
13787                    }
13788                    else {
13789                            if (title.equals(StringPool.BLANK)) {
13790                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
13791                            }
13792                            else {
13793                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
13794                            }
13795                    }
13796    
13797                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
13798    
13799                    if (!getDB().isSupportsInlineDistinct()) {
13800                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
13801                    }
13802    
13803                    if (orderByComparator != null) {
13804                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13805    
13806                            if (orderByConditionFields.length > 0) {
13807                                    query.append(WHERE_AND);
13808                            }
13809    
13810                            for (int i = 0; i < orderByConditionFields.length; i++) {
13811                                    if (getDB().isSupportsInlineDistinct()) {
13812                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13813                                    }
13814                                    else {
13815                                            query.append(_ORDER_BY_ENTITY_TABLE);
13816                                    }
13817    
13818                                    query.append(orderByConditionFields[i]);
13819    
13820                                    if ((i + 1) < orderByConditionFields.length) {
13821                                            if (orderByComparator.isAscending() ^ previous) {
13822                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13823                                            }
13824                                            else {
13825                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13826                                            }
13827                                    }
13828                                    else {
13829                                            if (orderByComparator.isAscending() ^ previous) {
13830                                                    query.append(WHERE_GREATER_THAN);
13831                                            }
13832                                            else {
13833                                                    query.append(WHERE_LESSER_THAN);
13834                                            }
13835                                    }
13836                            }
13837    
13838                            query.append(ORDER_BY_CLAUSE);
13839    
13840                            String[] orderByFields = orderByComparator.getOrderByFields();
13841    
13842                            for (int i = 0; i < orderByFields.length; i++) {
13843                                    if (getDB().isSupportsInlineDistinct()) {
13844                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13845                                    }
13846                                    else {
13847                                            query.append(_ORDER_BY_ENTITY_TABLE);
13848                                    }
13849    
13850                                    query.append(orderByFields[i]);
13851    
13852                                    if ((i + 1) < orderByFields.length) {
13853                                            if (orderByComparator.isAscending() ^ previous) {
13854                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13855                                            }
13856                                            else {
13857                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13858                                            }
13859                                    }
13860                                    else {
13861                                            if (orderByComparator.isAscending() ^ previous) {
13862                                                    query.append(ORDER_BY_ASC);
13863                                            }
13864                                            else {
13865                                                    query.append(ORDER_BY_DESC);
13866                                            }
13867                                    }
13868                            }
13869                    }
13870                    else {
13871                            if (getDB().isSupportsInlineDistinct()) {
13872                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13873                            }
13874                            else {
13875                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
13876                            }
13877                    }
13878    
13879                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13880                                    WikiPage.class.getName(),
13881                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13882    
13883                    SQLQuery q = session.createSQLQuery(sql);
13884    
13885                    q.setFirstResult(0);
13886                    q.setMaxResults(2);
13887    
13888                    if (getDB().isSupportsInlineDistinct()) {
13889                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
13890                    }
13891                    else {
13892                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
13893                    }
13894    
13895                    QueryPos qPos = QueryPos.getInstance(q);
13896    
13897                    qPos.add(groupId);
13898    
13899                    qPos.add(nodeId);
13900    
13901                    if (title != null) {
13902                            qPos.add(title);
13903                    }
13904    
13905                    qPos.add(head);
13906    
13907                    if (orderByComparator != null) {
13908                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
13909    
13910                            for (Object value : values) {
13911                                    qPos.add(value);
13912                            }
13913                    }
13914    
13915                    List<WikiPage> list = q.list();
13916    
13917                    if (list.size() == 2) {
13918                            return list.get(1);
13919                    }
13920                    else {
13921                            return null;
13922                    }
13923            }
13924    
13925            /**
13926             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63; from the database.
13927             *
13928             * @param groupId the group ID
13929             * @param nodeId the node ID
13930             * @param title the title
13931             * @param head the head
13932             * @throws SystemException if a system exception occurred
13933             */
13934            public void removeByG_N_T_H(long groupId, long nodeId, String title,
13935                    boolean head) throws SystemException {
13936                    for (WikiPage wikiPage : findByG_N_T_H(groupId, nodeId, title, head,
13937                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13938                            remove(wikiPage);
13939                    }
13940            }
13941    
13942            /**
13943             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
13944             *
13945             * @param groupId the group ID
13946             * @param nodeId the node ID
13947             * @param title the title
13948             * @param head the head
13949             * @return the number of matching wiki pages
13950             * @throws SystemException if a system exception occurred
13951             */
13952            public int countByG_N_T_H(long groupId, long nodeId, String title,
13953                    boolean head) throws SystemException {
13954                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_T_H;
13955    
13956                    Object[] finderArgs = new Object[] { groupId, nodeId, title, head };
13957    
13958                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13959                                    this);
13960    
13961                    if (count == null) {
13962                            StringBundler query = new StringBundler(5);
13963    
13964                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
13965    
13966                            query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
13967    
13968                            query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
13969    
13970                            if (title == null) {
13971                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
13972                            }
13973                            else {
13974                                    if (title.equals(StringPool.BLANK)) {
13975                                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
13976                                    }
13977                                    else {
13978                                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
13979                                    }
13980                            }
13981    
13982                            query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
13983    
13984                            String sql = query.toString();
13985    
13986                            Session session = null;
13987    
13988                            try {
13989                                    session = openSession();
13990    
13991                                    Query q = session.createQuery(sql);
13992    
13993                                    QueryPos qPos = QueryPos.getInstance(q);
13994    
13995                                    qPos.add(groupId);
13996    
13997                                    qPos.add(nodeId);
13998    
13999                                    if (title != null) {
14000                                            qPos.add(title);
14001                                    }
14002    
14003                                    qPos.add(head);
14004    
14005                                    count = (Long)q.uniqueResult();
14006    
14007                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14008                            }
14009                            catch (Exception e) {
14010                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14011    
14012                                    throw processException(e);
14013                            }
14014                            finally {
14015                                    closeSession(session);
14016                            }
14017                    }
14018    
14019                    return count.intValue();
14020            }
14021    
14022            /**
14023             * 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;.
14024             *
14025             * @param groupId the group ID
14026             * @param nodeId the node ID
14027             * @param title the title
14028             * @param head the head
14029             * @return the number of matching wiki pages that the user has permission to view
14030             * @throws SystemException if a system exception occurred
14031             */
14032            public int filterCountByG_N_T_H(long groupId, long nodeId, String title,
14033                    boolean head) throws SystemException {
14034                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14035                            return countByG_N_T_H(groupId, nodeId, title, head);
14036                    }
14037    
14038                    StringBundler query = new StringBundler(5);
14039    
14040                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
14041    
14042                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
14043    
14044                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
14045    
14046                    if (title == null) {
14047                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
14048                    }
14049                    else {
14050                            if (title.equals(StringPool.BLANK)) {
14051                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
14052                            }
14053                            else {
14054                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
14055                            }
14056                    }
14057    
14058                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
14059    
14060                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14061                                    WikiPage.class.getName(),
14062                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14063    
14064                    Session session = null;
14065    
14066                    try {
14067                            session = openSession();
14068    
14069                            SQLQuery q = session.createSQLQuery(sql);
14070    
14071                            q.addScalar(COUNT_COLUMN_NAME,
14072                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
14073    
14074                            QueryPos qPos = QueryPos.getInstance(q);
14075    
14076                            qPos.add(groupId);
14077    
14078                            qPos.add(nodeId);
14079    
14080                            if (title != null) {
14081                                    qPos.add(title);
14082                            }
14083    
14084                            qPos.add(head);
14085    
14086                            Long count = (Long)q.uniqueResult();
14087    
14088                            return count.intValue();
14089                    }
14090                    catch (Exception e) {
14091                            throw processException(e);
14092                    }
14093                    finally {
14094                            closeSession(session);
14095                    }
14096            }
14097    
14098            private static final String _FINDER_COLUMN_G_N_T_H_GROUPID_2 = "wikiPage.groupId = ? AND ";
14099            private static final String _FINDER_COLUMN_G_N_T_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
14100            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_1 = "wikiPage.title IS NULL AND ";
14101            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_2 = "lower(wikiPage.title) = lower(CAST_TEXT(?)) AND ";
14102            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_3 = "(wikiPage.title IS NULL OR lower(wikiPage.title) = lower(CAST_TEXT(?))) AND ";
14103            private static final String _FINDER_COLUMN_G_N_T_H_HEAD_2 = "wikiPage.head = ?";
14104            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14105                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
14106                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H_S",
14107                            new String[] {
14108                                    Long.class.getName(), Long.class.getName(),
14109                                    Boolean.class.getName(), Integer.class.getName(),
14110                                    
14111                            Integer.class.getName(), Integer.class.getName(),
14112                                    OrderByComparator.class.getName()
14113                            });
14114            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S =
14115                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14116                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
14117                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H_S",
14118                            new String[] {
14119                                    Long.class.getName(), Long.class.getName(),
14120                                    Boolean.class.getName(), Integer.class.getName()
14121                            },
14122                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
14123                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
14124                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
14125                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
14126                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
14127                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
14128            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14129                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14130                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H_S",
14131                            new String[] {
14132                                    Long.class.getName(), Long.class.getName(),
14133                                    Boolean.class.getName(), Integer.class.getName()
14134                            });
14135    
14136            /**
14137             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14138             *
14139             * @param groupId the group ID
14140             * @param nodeId the node ID
14141             * @param head the head
14142             * @param status the status
14143             * @return the matching wiki pages
14144             * @throws SystemException if a system exception occurred
14145             */
14146            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
14147                    boolean head, int status) throws SystemException {
14148                    return findByG_N_H_S(groupId, nodeId, head, status, QueryUtil.ALL_POS,
14149                            QueryUtil.ALL_POS, null);
14150            }
14151    
14152            /**
14153             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14154             *
14155             * <p>
14156             * 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.
14157             * </p>
14158             *
14159             * @param groupId the group ID
14160             * @param nodeId the node ID
14161             * @param head the head
14162             * @param status the status
14163             * @param start the lower bound of the range of wiki pages
14164             * @param end the upper bound of the range of wiki pages (not inclusive)
14165             * @return the range of matching wiki pages
14166             * @throws SystemException if a system exception occurred
14167             */
14168            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
14169                    boolean head, int status, int start, int end) throws SystemException {
14170                    return findByG_N_H_S(groupId, nodeId, head, status, start, end, null);
14171            }
14172    
14173            /**
14174             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14175             *
14176             * <p>
14177             * 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.
14178             * </p>
14179             *
14180             * @param groupId the group ID
14181             * @param nodeId the node ID
14182             * @param head the head
14183             * @param status the status
14184             * @param start the lower bound of the range of wiki pages
14185             * @param end the upper bound of the range of wiki pages (not inclusive)
14186             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14187             * @return the ordered range of matching wiki pages
14188             * @throws SystemException if a system exception occurred
14189             */
14190            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
14191                    boolean head, int status, int start, int end,
14192                    OrderByComparator orderByComparator) throws SystemException {
14193                    boolean pagination = true;
14194                    FinderPath finderPath = null;
14195                    Object[] finderArgs = null;
14196    
14197                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14198                                    (orderByComparator == null)) {
14199                            pagination = false;
14200                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S;
14201                            finderArgs = new Object[] { groupId, nodeId, head, status };
14202                    }
14203                    else {
14204                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_S;
14205                            finderArgs = new Object[] {
14206                                            groupId, nodeId, head, status,
14207                                            
14208                                            start, end, orderByComparator
14209                                    };
14210                    }
14211    
14212                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
14213                                    finderArgs, this);
14214    
14215                    if ((list != null) && !list.isEmpty()) {
14216                            for (WikiPage wikiPage : list) {
14217                                    if ((groupId != wikiPage.getGroupId()) ||
14218                                                    (nodeId != wikiPage.getNodeId()) ||
14219                                                    (head != wikiPage.getHead()) ||
14220                                                    (status != wikiPage.getStatus())) {
14221                                            list = null;
14222    
14223                                            break;
14224                                    }
14225                            }
14226                    }
14227    
14228                    if (list == null) {
14229                            StringBundler query = null;
14230    
14231                            if (orderByComparator != null) {
14232                                    query = new StringBundler(6 +
14233                                                    (orderByComparator.getOrderByFields().length * 3));
14234                            }
14235                            else {
14236                                    query = new StringBundler(6);
14237                            }
14238    
14239                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14240    
14241                            query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
14242    
14243                            query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
14244    
14245                            query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
14246    
14247                            query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
14248    
14249                            if (orderByComparator != null) {
14250                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14251                                            orderByComparator);
14252                            }
14253                            else
14254                             if (pagination) {
14255                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14256                            }
14257    
14258                            String sql = query.toString();
14259    
14260                            Session session = null;
14261    
14262                            try {
14263                                    session = openSession();
14264    
14265                                    Query q = session.createQuery(sql);
14266    
14267                                    QueryPos qPos = QueryPos.getInstance(q);
14268    
14269                                    qPos.add(groupId);
14270    
14271                                    qPos.add(nodeId);
14272    
14273                                    qPos.add(head);
14274    
14275                                    qPos.add(status);
14276    
14277                                    if (!pagination) {
14278                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14279                                                            start, end, false);
14280    
14281                                            Collections.sort(list);
14282    
14283                                            list = new UnmodifiableList<WikiPage>(list);
14284                                    }
14285                                    else {
14286                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14287                                                            start, end);
14288                                    }
14289    
14290                                    cacheResult(list);
14291    
14292                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14293                            }
14294                            catch (Exception e) {
14295                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14296    
14297                                    throw processException(e);
14298                            }
14299                            finally {
14300                                    closeSession(session);
14301                            }
14302                    }
14303    
14304                    return list;
14305            }
14306    
14307            /**
14308             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14309             *
14310             * @param groupId the group ID
14311             * @param nodeId the node ID
14312             * @param head the head
14313             * @param status the status
14314             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14315             * @return the first matching wiki page
14316             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14317             * @throws SystemException if a system exception occurred
14318             */
14319            public WikiPage findByG_N_H_S_First(long groupId, long nodeId,
14320                    boolean head, int status, OrderByComparator orderByComparator)
14321                    throws NoSuchPageException, SystemException {
14322                    WikiPage wikiPage = fetchByG_N_H_S_First(groupId, nodeId, head, status,
14323                                    orderByComparator);
14324    
14325                    if (wikiPage != null) {
14326                            return wikiPage;
14327                    }
14328    
14329                    StringBundler msg = new StringBundler(10);
14330    
14331                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14332    
14333                    msg.append("groupId=");
14334                    msg.append(groupId);
14335    
14336                    msg.append(", nodeId=");
14337                    msg.append(nodeId);
14338    
14339                    msg.append(", head=");
14340                    msg.append(head);
14341    
14342                    msg.append(", status=");
14343                    msg.append(status);
14344    
14345                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14346    
14347                    throw new NoSuchPageException(msg.toString());
14348            }
14349    
14350            /**
14351             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14352             *
14353             * @param groupId the group ID
14354             * @param nodeId the node ID
14355             * @param head the head
14356             * @param status the status
14357             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14358             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
14359             * @throws SystemException if a system exception occurred
14360             */
14361            public WikiPage fetchByG_N_H_S_First(long groupId, long nodeId,
14362                    boolean head, int status, OrderByComparator orderByComparator)
14363                    throws SystemException {
14364                    List<WikiPage> list = findByG_N_H_S(groupId, nodeId, head, status, 0,
14365                                    1, orderByComparator);
14366    
14367                    if (!list.isEmpty()) {
14368                            return list.get(0);
14369                    }
14370    
14371                    return null;
14372            }
14373    
14374            /**
14375             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14376             *
14377             * @param groupId the group ID
14378             * @param nodeId the node ID
14379             * @param head the head
14380             * @param status the status
14381             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14382             * @return the last matching wiki page
14383             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14384             * @throws SystemException if a system exception occurred
14385             */
14386            public WikiPage findByG_N_H_S_Last(long groupId, long nodeId, boolean head,
14387                    int status, OrderByComparator orderByComparator)
14388                    throws NoSuchPageException, SystemException {
14389                    WikiPage wikiPage = fetchByG_N_H_S_Last(groupId, nodeId, head, status,
14390                                    orderByComparator);
14391    
14392                    if (wikiPage != null) {
14393                            return wikiPage;
14394                    }
14395    
14396                    StringBundler msg = new StringBundler(10);
14397    
14398                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14399    
14400                    msg.append("groupId=");
14401                    msg.append(groupId);
14402    
14403                    msg.append(", nodeId=");
14404                    msg.append(nodeId);
14405    
14406                    msg.append(", head=");
14407                    msg.append(head);
14408    
14409                    msg.append(", status=");
14410                    msg.append(status);
14411    
14412                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14413    
14414                    throw new NoSuchPageException(msg.toString());
14415            }
14416    
14417            /**
14418             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14419             *
14420             * @param groupId the group ID
14421             * @param nodeId the node ID
14422             * @param head the head
14423             * @param status the status
14424             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14425             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
14426             * @throws SystemException if a system exception occurred
14427             */
14428            public WikiPage fetchByG_N_H_S_Last(long groupId, long nodeId,
14429                    boolean head, int status, OrderByComparator orderByComparator)
14430                    throws SystemException {
14431                    int count = countByG_N_H_S(groupId, nodeId, head, status);
14432    
14433                    List<WikiPage> list = findByG_N_H_S(groupId, nodeId, head, status,
14434                                    count - 1, count, orderByComparator);
14435    
14436                    if (!list.isEmpty()) {
14437                            return list.get(0);
14438                    }
14439    
14440                    return null;
14441            }
14442    
14443            /**
14444             * 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;.
14445             *
14446             * @param pageId the primary key of the current wiki page
14447             * @param groupId the group ID
14448             * @param nodeId the node ID
14449             * @param head the head
14450             * @param status the status
14451             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14452             * @return the previous, current, and next wiki page
14453             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
14454             * @throws SystemException if a system exception occurred
14455             */
14456            public WikiPage[] findByG_N_H_S_PrevAndNext(long pageId, long groupId,
14457                    long nodeId, boolean head, int status,
14458                    OrderByComparator orderByComparator)
14459                    throws NoSuchPageException, SystemException {
14460                    WikiPage wikiPage = findByPrimaryKey(pageId);
14461    
14462                    Session session = null;
14463    
14464                    try {
14465                            session = openSession();
14466    
14467                            WikiPage[] array = new WikiPageImpl[3];
14468    
14469                            array[0] = getByG_N_H_S_PrevAndNext(session, wikiPage, groupId,
14470                                            nodeId, head, status, orderByComparator, true);
14471    
14472                            array[1] = wikiPage;
14473    
14474                            array[2] = getByG_N_H_S_PrevAndNext(session, wikiPage, groupId,
14475                                            nodeId, head, status, orderByComparator, false);
14476    
14477                            return array;
14478                    }
14479                    catch (Exception e) {
14480                            throw processException(e);
14481                    }
14482                    finally {
14483                            closeSession(session);
14484                    }
14485            }
14486    
14487            protected WikiPage getByG_N_H_S_PrevAndNext(Session session,
14488                    WikiPage wikiPage, long groupId, long nodeId, boolean head, int status,
14489                    OrderByComparator orderByComparator, boolean previous) {
14490                    StringBundler query = null;
14491    
14492                    if (orderByComparator != null) {
14493                            query = new StringBundler(6 +
14494                                            (orderByComparator.getOrderByFields().length * 6));
14495                    }
14496                    else {
14497                            query = new StringBundler(3);
14498                    }
14499    
14500                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14501    
14502                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
14503    
14504                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
14505    
14506                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
14507    
14508                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
14509    
14510                    if (orderByComparator != null) {
14511                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14512    
14513                            if (orderByConditionFields.length > 0) {
14514                                    query.append(WHERE_AND);
14515                            }
14516    
14517                            for (int i = 0; i < orderByConditionFields.length; i++) {
14518                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14519                                    query.append(orderByConditionFields[i]);
14520    
14521                                    if ((i + 1) < orderByConditionFields.length) {
14522                                            if (orderByComparator.isAscending() ^ previous) {
14523                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14524                                            }
14525                                            else {
14526                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14527                                            }
14528                                    }
14529                                    else {
14530                                            if (orderByComparator.isAscending() ^ previous) {
14531                                                    query.append(WHERE_GREATER_THAN);
14532                                            }
14533                                            else {
14534                                                    query.append(WHERE_LESSER_THAN);
14535                                            }
14536                                    }
14537                            }
14538    
14539                            query.append(ORDER_BY_CLAUSE);
14540    
14541                            String[] orderByFields = orderByComparator.getOrderByFields();
14542    
14543                            for (int i = 0; i < orderByFields.length; i++) {
14544                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14545                                    query.append(orderByFields[i]);
14546    
14547                                    if ((i + 1) < orderByFields.length) {
14548                                            if (orderByComparator.isAscending() ^ previous) {
14549                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14550                                            }
14551                                            else {
14552                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14553                                            }
14554                                    }
14555                                    else {
14556                                            if (orderByComparator.isAscending() ^ previous) {
14557                                                    query.append(ORDER_BY_ASC);
14558                                            }
14559                                            else {
14560                                                    query.append(ORDER_BY_DESC);
14561                                            }
14562                                    }
14563                            }
14564                    }
14565                    else {
14566                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14567                    }
14568    
14569                    String sql = query.toString();
14570    
14571                    Query q = session.createQuery(sql);
14572    
14573                    q.setFirstResult(0);
14574                    q.setMaxResults(2);
14575    
14576                    QueryPos qPos = QueryPos.getInstance(q);
14577    
14578                    qPos.add(groupId);
14579    
14580                    qPos.add(nodeId);
14581    
14582                    qPos.add(head);
14583    
14584                    qPos.add(status);
14585    
14586                    if (orderByComparator != null) {
14587                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
14588    
14589                            for (Object value : values) {
14590                                    qPos.add(value);
14591                            }
14592                    }
14593    
14594                    List<WikiPage> list = q.list();
14595    
14596                    if (list.size() == 2) {
14597                            return list.get(1);
14598                    }
14599                    else {
14600                            return null;
14601                    }
14602            }
14603    
14604            /**
14605             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14606             *
14607             * @param groupId the group ID
14608             * @param nodeId the node ID
14609             * @param head the head
14610             * @param status the status
14611             * @return the matching wiki pages that the user has permission to view
14612             * @throws SystemException if a system exception occurred
14613             */
14614            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
14615                    boolean head, int status) throws SystemException {
14616                    return filterFindByG_N_H_S(groupId, nodeId, head, status,
14617                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14618            }
14619    
14620            /**
14621             * 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;.
14622             *
14623             * <p>
14624             * 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.
14625             * </p>
14626             *
14627             * @param groupId the group ID
14628             * @param nodeId the node ID
14629             * @param head the head
14630             * @param status the status
14631             * @param start the lower bound of the range of wiki pages
14632             * @param end the upper bound of the range of wiki pages (not inclusive)
14633             * @return the range of matching wiki pages that the user has permission to view
14634             * @throws SystemException if a system exception occurred
14635             */
14636            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
14637                    boolean head, int status, int start, int end) throws SystemException {
14638                    return filterFindByG_N_H_S(groupId, nodeId, head, status, start, end,
14639                            null);
14640            }
14641    
14642            /**
14643             * 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;.
14644             *
14645             * <p>
14646             * 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.
14647             * </p>
14648             *
14649             * @param groupId the group ID
14650             * @param nodeId the node ID
14651             * @param head the head
14652             * @param status the status
14653             * @param start the lower bound of the range of wiki pages
14654             * @param end the upper bound of the range of wiki pages (not inclusive)
14655             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14656             * @return the ordered range of matching wiki pages that the user has permission to view
14657             * @throws SystemException if a system exception occurred
14658             */
14659            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
14660                    boolean head, int status, int start, int end,
14661                    OrderByComparator orderByComparator) throws SystemException {
14662                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14663                            return findByG_N_H_S(groupId, nodeId, head, status, start, end,
14664                                    orderByComparator);
14665                    }
14666    
14667                    StringBundler query = null;
14668    
14669                    if (orderByComparator != null) {
14670                            query = new StringBundler(6 +
14671                                            (orderByComparator.getOrderByFields().length * 3));
14672                    }
14673                    else {
14674                            query = new StringBundler(6);
14675                    }
14676    
14677                    if (getDB().isSupportsInlineDistinct()) {
14678                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
14679                    }
14680                    else {
14681                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
14682                    }
14683    
14684                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
14685    
14686                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
14687    
14688                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
14689    
14690                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
14691    
14692                    if (!getDB().isSupportsInlineDistinct()) {
14693                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
14694                    }
14695    
14696                    if (orderByComparator != null) {
14697                            if (getDB().isSupportsInlineDistinct()) {
14698                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14699                                            orderByComparator);
14700                            }
14701                            else {
14702                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
14703                                            orderByComparator);
14704                            }
14705                    }
14706                    else {
14707                            if (getDB().isSupportsInlineDistinct()) {
14708                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14709                            }
14710                            else {
14711                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
14712                            }
14713                    }
14714    
14715                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14716                                    WikiPage.class.getName(),
14717                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14718    
14719                    Session session = null;
14720    
14721                    try {
14722                            session = openSession();
14723    
14724                            SQLQuery q = session.createSQLQuery(sql);
14725    
14726                            if (getDB().isSupportsInlineDistinct()) {
14727                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
14728                            }
14729                            else {
14730                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
14731                            }
14732    
14733                            QueryPos qPos = QueryPos.getInstance(q);
14734    
14735                            qPos.add(groupId);
14736    
14737                            qPos.add(nodeId);
14738    
14739                            qPos.add(head);
14740    
14741                            qPos.add(status);
14742    
14743                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
14744                    }
14745                    catch (Exception e) {
14746                            throw processException(e);
14747                    }
14748                    finally {
14749                            closeSession(session);
14750                    }
14751            }
14752    
14753            /**
14754             * 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;.
14755             *
14756             * @param pageId the primary key of the current wiki page
14757             * @param groupId the group ID
14758             * @param nodeId the node ID
14759             * @param head the head
14760             * @param status the status
14761             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14762             * @return the previous, current, and next wiki page
14763             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
14764             * @throws SystemException if a system exception occurred
14765             */
14766            public WikiPage[] filterFindByG_N_H_S_PrevAndNext(long pageId,
14767                    long groupId, long nodeId, boolean head, int status,
14768                    OrderByComparator orderByComparator)
14769                    throws NoSuchPageException, SystemException {
14770                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14771                            return findByG_N_H_S_PrevAndNext(pageId, groupId, nodeId, head,
14772                                    status, orderByComparator);
14773                    }
14774    
14775                    WikiPage wikiPage = findByPrimaryKey(pageId);
14776    
14777                    Session session = null;
14778    
14779                    try {
14780                            session = openSession();
14781    
14782                            WikiPage[] array = new WikiPageImpl[3];
14783    
14784                            array[0] = filterGetByG_N_H_S_PrevAndNext(session, wikiPage,
14785                                            groupId, nodeId, head, status, orderByComparator, true);
14786    
14787                            array[1] = wikiPage;
14788    
14789                            array[2] = filterGetByG_N_H_S_PrevAndNext(session, wikiPage,
14790                                            groupId, nodeId, head, status, orderByComparator, false);
14791    
14792                            return array;
14793                    }
14794                    catch (Exception e) {
14795                            throw processException(e);
14796                    }
14797                    finally {
14798                            closeSession(session);
14799                    }
14800            }
14801    
14802            protected WikiPage filterGetByG_N_H_S_PrevAndNext(Session session,
14803                    WikiPage wikiPage, long groupId, long nodeId, boolean head, int status,
14804                    OrderByComparator orderByComparator, boolean previous) {
14805                    StringBundler query = null;
14806    
14807                    if (orderByComparator != null) {
14808                            query = new StringBundler(6 +
14809                                            (orderByComparator.getOrderByFields().length * 6));
14810                    }
14811                    else {
14812                            query = new StringBundler(3);
14813                    }
14814    
14815                    if (getDB().isSupportsInlineDistinct()) {
14816                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
14817                    }
14818                    else {
14819                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
14820                    }
14821    
14822                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
14823    
14824                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
14825    
14826                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
14827    
14828                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
14829    
14830                    if (!getDB().isSupportsInlineDistinct()) {
14831                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
14832                    }
14833    
14834                    if (orderByComparator != null) {
14835                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14836    
14837                            if (orderByConditionFields.length > 0) {
14838                                    query.append(WHERE_AND);
14839                            }
14840    
14841                            for (int i = 0; i < orderByConditionFields.length; i++) {
14842                                    if (getDB().isSupportsInlineDistinct()) {
14843                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14844                                    }
14845                                    else {
14846                                            query.append(_ORDER_BY_ENTITY_TABLE);
14847                                    }
14848    
14849                                    query.append(orderByConditionFields[i]);
14850    
14851                                    if ((i + 1) < orderByConditionFields.length) {
14852                                            if (orderByComparator.isAscending() ^ previous) {
14853                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14854                                            }
14855                                            else {
14856                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14857                                            }
14858                                    }
14859                                    else {
14860                                            if (orderByComparator.isAscending() ^ previous) {
14861                                                    query.append(WHERE_GREATER_THAN);
14862                                            }
14863                                            else {
14864                                                    query.append(WHERE_LESSER_THAN);
14865                                            }
14866                                    }
14867                            }
14868    
14869                            query.append(ORDER_BY_CLAUSE);
14870    
14871                            String[] orderByFields = orderByComparator.getOrderByFields();
14872    
14873                            for (int i = 0; i < orderByFields.length; i++) {
14874                                    if (getDB().isSupportsInlineDistinct()) {
14875                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14876                                    }
14877                                    else {
14878                                            query.append(_ORDER_BY_ENTITY_TABLE);
14879                                    }
14880    
14881                                    query.append(orderByFields[i]);
14882    
14883                                    if ((i + 1) < orderByFields.length) {
14884                                            if (orderByComparator.isAscending() ^ previous) {
14885                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14886                                            }
14887                                            else {
14888                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14889                                            }
14890                                    }
14891                                    else {
14892                                            if (orderByComparator.isAscending() ^ previous) {
14893                                                    query.append(ORDER_BY_ASC);
14894                                            }
14895                                            else {
14896                                                    query.append(ORDER_BY_DESC);
14897                                            }
14898                                    }
14899                            }
14900                    }
14901                    else {
14902                            if (getDB().isSupportsInlineDistinct()) {
14903                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14904                            }
14905                            else {
14906                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
14907                            }
14908                    }
14909    
14910                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14911                                    WikiPage.class.getName(),
14912                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14913    
14914                    SQLQuery q = session.createSQLQuery(sql);
14915    
14916                    q.setFirstResult(0);
14917                    q.setMaxResults(2);
14918    
14919                    if (getDB().isSupportsInlineDistinct()) {
14920                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
14921                    }
14922                    else {
14923                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
14924                    }
14925    
14926                    QueryPos qPos = QueryPos.getInstance(q);
14927    
14928                    qPos.add(groupId);
14929    
14930                    qPos.add(nodeId);
14931    
14932                    qPos.add(head);
14933    
14934                    qPos.add(status);
14935    
14936                    if (orderByComparator != null) {
14937                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
14938    
14939                            for (Object value : values) {
14940                                    qPos.add(value);
14941                            }
14942                    }
14943    
14944                    List<WikiPage> list = q.list();
14945    
14946                    if (list.size() == 2) {
14947                            return list.get(1);
14948                    }
14949                    else {
14950                            return null;
14951                    }
14952            }
14953    
14954            /**
14955             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63; from the database.
14956             *
14957             * @param groupId the group ID
14958             * @param nodeId the node ID
14959             * @param head the head
14960             * @param status the status
14961             * @throws SystemException if a system exception occurred
14962             */
14963            public void removeByG_N_H_S(long groupId, long nodeId, boolean head,
14964                    int status) throws SystemException {
14965                    for (WikiPage wikiPage : findByG_N_H_S(groupId, nodeId, head, status,
14966                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14967                            remove(wikiPage);
14968                    }
14969            }
14970    
14971            /**
14972             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
14973             *
14974             * @param groupId the group ID
14975             * @param nodeId the node ID
14976             * @param head the head
14977             * @param status the status
14978             * @return the number of matching wiki pages
14979             * @throws SystemException if a system exception occurred
14980             */
14981            public int countByG_N_H_S(long groupId, long nodeId, boolean head,
14982                    int status) throws SystemException {
14983                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H_S;
14984    
14985                    Object[] finderArgs = new Object[] { groupId, nodeId, head, status };
14986    
14987                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14988                                    this);
14989    
14990                    if (count == null) {
14991                            StringBundler query = new StringBundler(5);
14992    
14993                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
14994    
14995                            query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
14996    
14997                            query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
14998    
14999                            query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
15000    
15001                            query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
15002    
15003                            String sql = query.toString();
15004    
15005                            Session session = null;
15006    
15007                            try {
15008                                    session = openSession();
15009    
15010                                    Query q = session.createQuery(sql);
15011    
15012                                    QueryPos qPos = QueryPos.getInstance(q);
15013    
15014                                    qPos.add(groupId);
15015    
15016                                    qPos.add(nodeId);
15017    
15018                                    qPos.add(head);
15019    
15020                                    qPos.add(status);
15021    
15022                                    count = (Long)q.uniqueResult();
15023    
15024                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15025                            }
15026                            catch (Exception e) {
15027                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15028    
15029                                    throw processException(e);
15030                            }
15031                            finally {
15032                                    closeSession(session);
15033                            }
15034                    }
15035    
15036                    return count.intValue();
15037            }
15038    
15039            /**
15040             * 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;.
15041             *
15042             * @param groupId the group ID
15043             * @param nodeId the node ID
15044             * @param head the head
15045             * @param status the status
15046             * @return the number of matching wiki pages that the user has permission to view
15047             * @throws SystemException if a system exception occurred
15048             */
15049            public int filterCountByG_N_H_S(long groupId, long nodeId, boolean head,
15050                    int status) throws SystemException {
15051                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15052                            return countByG_N_H_S(groupId, nodeId, head, status);
15053                    }
15054    
15055                    StringBundler query = new StringBundler(5);
15056    
15057                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
15058    
15059                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
15060    
15061                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
15062    
15063                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
15064    
15065                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
15066    
15067                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15068                                    WikiPage.class.getName(),
15069                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15070    
15071                    Session session = null;
15072    
15073                    try {
15074                            session = openSession();
15075    
15076                            SQLQuery q = session.createSQLQuery(sql);
15077    
15078                            q.addScalar(COUNT_COLUMN_NAME,
15079                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
15080    
15081                            QueryPos qPos = QueryPos.getInstance(q);
15082    
15083                            qPos.add(groupId);
15084    
15085                            qPos.add(nodeId);
15086    
15087                            qPos.add(head);
15088    
15089                            qPos.add(status);
15090    
15091                            Long count = (Long)q.uniqueResult();
15092    
15093                            return count.intValue();
15094                    }
15095                    catch (Exception e) {
15096                            throw processException(e);
15097                    }
15098                    finally {
15099                            closeSession(session);
15100                    }
15101            }
15102    
15103            private static final String _FINDER_COLUMN_G_N_H_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
15104            private static final String _FINDER_COLUMN_G_N_H_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
15105            private static final String _FINDER_COLUMN_G_N_H_S_HEAD_2 = "wikiPage.head = ? AND ";
15106            private static final String _FINDER_COLUMN_G_N_H_S_STATUS_2 = "wikiPage.status = ?";
15107            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15108                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15109                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_P_S",
15110                            new String[] {
15111                                    Long.class.getName(), Boolean.class.getName(),
15112                                    String.class.getName(), Integer.class.getName(),
15113                                    
15114                            Integer.class.getName(), Integer.class.getName(),
15115                                    OrderByComparator.class.getName()
15116                            });
15117            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S =
15118                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15119                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15120                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_P_S",
15121                            new String[] {
15122                                    Long.class.getName(), Boolean.class.getName(),
15123                                    String.class.getName(), Integer.class.getName()
15124                            },
15125                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
15126                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
15127                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
15128                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
15129                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
15130                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
15131            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15132                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15133                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_P_S",
15134                            new String[] {
15135                                    Long.class.getName(), Boolean.class.getName(),
15136                                    String.class.getName(), Integer.class.getName()
15137                            });
15138    
15139            /**
15140             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15141             *
15142             * @param nodeId the node ID
15143             * @param head the head
15144             * @param parentTitle the parent title
15145             * @param status the status
15146             * @return the matching wiki pages
15147             * @throws SystemException if a system exception occurred
15148             */
15149            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
15150                    String parentTitle, int status) throws SystemException {
15151                    return findByN_H_P_S(nodeId, head, parentTitle, status,
15152                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15153            }
15154    
15155            /**
15156             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15157             *
15158             * <p>
15159             * 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.
15160             * </p>
15161             *
15162             * @param nodeId the node ID
15163             * @param head the head
15164             * @param parentTitle the parent title
15165             * @param status the status
15166             * @param start the lower bound of the range of wiki pages
15167             * @param end the upper bound of the range of wiki pages (not inclusive)
15168             * @return the range of matching wiki pages
15169             * @throws SystemException if a system exception occurred
15170             */
15171            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
15172                    String parentTitle, int status, int start, int end)
15173                    throws SystemException {
15174                    return findByN_H_P_S(nodeId, head, parentTitle, status, start, end, null);
15175            }
15176    
15177            /**
15178             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15179             *
15180             * <p>
15181             * 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.
15182             * </p>
15183             *
15184             * @param nodeId the node ID
15185             * @param head the head
15186             * @param parentTitle the parent title
15187             * @param status the status
15188             * @param start the lower bound of the range of wiki pages
15189             * @param end the upper bound of the range of wiki pages (not inclusive)
15190             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15191             * @return the ordered range of matching wiki pages
15192             * @throws SystemException if a system exception occurred
15193             */
15194            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
15195                    String parentTitle, int status, int start, int end,
15196                    OrderByComparator orderByComparator) throws SystemException {
15197                    boolean pagination = true;
15198                    FinderPath finderPath = null;
15199                    Object[] finderArgs = null;
15200    
15201                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15202                                    (orderByComparator == null)) {
15203                            pagination = false;
15204                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S;
15205                            finderArgs = new Object[] { nodeId, head, parentTitle, status };
15206                    }
15207                    else {
15208                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_S;
15209                            finderArgs = new Object[] {
15210                                            nodeId, head, parentTitle, status,
15211                                            
15212                                            start, end, orderByComparator
15213                                    };
15214                    }
15215    
15216                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
15217                                    finderArgs, this);
15218    
15219                    if ((list != null) && !list.isEmpty()) {
15220                            for (WikiPage wikiPage : list) {
15221                                    if ((nodeId != wikiPage.getNodeId()) ||
15222                                                    (head != wikiPage.getHead()) ||
15223                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
15224                                                    (status != wikiPage.getStatus())) {
15225                                            list = null;
15226    
15227                                            break;
15228                                    }
15229                            }
15230                    }
15231    
15232                    if (list == null) {
15233                            StringBundler query = null;
15234    
15235                            if (orderByComparator != null) {
15236                                    query = new StringBundler(6 +
15237                                                    (orderByComparator.getOrderByFields().length * 3));
15238                            }
15239                            else {
15240                                    query = new StringBundler(6);
15241                            }
15242    
15243                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
15244    
15245                            query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
15246    
15247                            query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
15248    
15249                            if (parentTitle == null) {
15250                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
15251                            }
15252                            else {
15253                                    if (parentTitle.equals(StringPool.BLANK)) {
15254                                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
15255                                    }
15256                                    else {
15257                                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
15258                                    }
15259                            }
15260    
15261                            query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
15262    
15263                            if (orderByComparator != null) {
15264                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15265                                            orderByComparator);
15266                            }
15267                            else
15268                             if (pagination) {
15269                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15270                            }
15271    
15272                            String sql = query.toString();
15273    
15274                            Session session = null;
15275    
15276                            try {
15277                                    session = openSession();
15278    
15279                                    Query q = session.createQuery(sql);
15280    
15281                                    QueryPos qPos = QueryPos.getInstance(q);
15282    
15283                                    qPos.add(nodeId);
15284    
15285                                    qPos.add(head);
15286    
15287                                    if (parentTitle != null) {
15288                                            qPos.add(parentTitle);
15289                                    }
15290    
15291                                    qPos.add(status);
15292    
15293                                    if (!pagination) {
15294                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15295                                                            start, end, false);
15296    
15297                                            Collections.sort(list);
15298    
15299                                            list = new UnmodifiableList<WikiPage>(list);
15300                                    }
15301                                    else {
15302                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15303                                                            start, end);
15304                                    }
15305    
15306                                    cacheResult(list);
15307    
15308                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15309                            }
15310                            catch (Exception e) {
15311                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15312    
15313                                    throw processException(e);
15314                            }
15315                            finally {
15316                                    closeSession(session);
15317                            }
15318                    }
15319    
15320                    return list;
15321            }
15322    
15323            /**
15324             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15325             *
15326             * @param nodeId the node ID
15327             * @param head the head
15328             * @param parentTitle the parent title
15329             * @param status the status
15330             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15331             * @return the first matching wiki page
15332             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
15333             * @throws SystemException if a system exception occurred
15334             */
15335            public WikiPage findByN_H_P_S_First(long nodeId, boolean head,
15336                    String parentTitle, int status, OrderByComparator orderByComparator)
15337                    throws NoSuchPageException, SystemException {
15338                    WikiPage wikiPage = fetchByN_H_P_S_First(nodeId, head, parentTitle,
15339                                    status, orderByComparator);
15340    
15341                    if (wikiPage != null) {
15342                            return wikiPage;
15343                    }
15344    
15345                    StringBundler msg = new StringBundler(10);
15346    
15347                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15348    
15349                    msg.append("nodeId=");
15350                    msg.append(nodeId);
15351    
15352                    msg.append(", head=");
15353                    msg.append(head);
15354    
15355                    msg.append(", parentTitle=");
15356                    msg.append(parentTitle);
15357    
15358                    msg.append(", status=");
15359                    msg.append(status);
15360    
15361                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15362    
15363                    throw new NoSuchPageException(msg.toString());
15364            }
15365    
15366            /**
15367             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15368             *
15369             * @param nodeId the node ID
15370             * @param head the head
15371             * @param parentTitle the parent title
15372             * @param status the status
15373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15374             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
15375             * @throws SystemException if a system exception occurred
15376             */
15377            public WikiPage fetchByN_H_P_S_First(long nodeId, boolean head,
15378                    String parentTitle, int status, OrderByComparator orderByComparator)
15379                    throws SystemException {
15380                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
15381                                    0, 1, orderByComparator);
15382    
15383                    if (!list.isEmpty()) {
15384                            return list.get(0);
15385                    }
15386    
15387                    return null;
15388            }
15389    
15390            /**
15391             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15392             *
15393             * @param nodeId the node ID
15394             * @param head the head
15395             * @param parentTitle the parent title
15396             * @param status the status
15397             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15398             * @return the last matching wiki page
15399             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
15400             * @throws SystemException if a system exception occurred
15401             */
15402            public WikiPage findByN_H_P_S_Last(long nodeId, boolean head,
15403                    String parentTitle, int status, OrderByComparator orderByComparator)
15404                    throws NoSuchPageException, SystemException {
15405                    WikiPage wikiPage = fetchByN_H_P_S_Last(nodeId, head, parentTitle,
15406                                    status, orderByComparator);
15407    
15408                    if (wikiPage != null) {
15409                            return wikiPage;
15410                    }
15411    
15412                    StringBundler msg = new StringBundler(10);
15413    
15414                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15415    
15416                    msg.append("nodeId=");
15417                    msg.append(nodeId);
15418    
15419                    msg.append(", head=");
15420                    msg.append(head);
15421    
15422                    msg.append(", parentTitle=");
15423                    msg.append(parentTitle);
15424    
15425                    msg.append(", status=");
15426                    msg.append(status);
15427    
15428                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15429    
15430                    throw new NoSuchPageException(msg.toString());
15431            }
15432    
15433            /**
15434             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15435             *
15436             * @param nodeId the node ID
15437             * @param head the head
15438             * @param parentTitle the parent title
15439             * @param status the status
15440             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15441             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
15442             * @throws SystemException if a system exception occurred
15443             */
15444            public WikiPage fetchByN_H_P_S_Last(long nodeId, boolean head,
15445                    String parentTitle, int status, OrderByComparator orderByComparator)
15446                    throws SystemException {
15447                    int count = countByN_H_P_S(nodeId, head, parentTitle, status);
15448    
15449                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
15450                                    count - 1, count, orderByComparator);
15451    
15452                    if (!list.isEmpty()) {
15453                            return list.get(0);
15454                    }
15455    
15456                    return null;
15457            }
15458    
15459            /**
15460             * 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;.
15461             *
15462             * @param pageId the primary key of the current wiki page
15463             * @param nodeId the node ID
15464             * @param head the head
15465             * @param parentTitle the parent title
15466             * @param status the status
15467             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15468             * @return the previous, current, and next wiki page
15469             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
15470             * @throws SystemException if a system exception occurred
15471             */
15472            public WikiPage[] findByN_H_P_S_PrevAndNext(long pageId, long nodeId,
15473                    boolean head, String parentTitle, int status,
15474                    OrderByComparator orderByComparator)
15475                    throws NoSuchPageException, SystemException {
15476                    WikiPage wikiPage = findByPrimaryKey(pageId);
15477    
15478                    Session session = null;
15479    
15480                    try {
15481                            session = openSession();
15482    
15483                            WikiPage[] array = new WikiPageImpl[3];
15484    
15485                            array[0] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
15486                                            head, parentTitle, status, orderByComparator, true);
15487    
15488                            array[1] = wikiPage;
15489    
15490                            array[2] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
15491                                            head, parentTitle, status, orderByComparator, false);
15492    
15493                            return array;
15494                    }
15495                    catch (Exception e) {
15496                            throw processException(e);
15497                    }
15498                    finally {
15499                            closeSession(session);
15500                    }
15501            }
15502    
15503            protected WikiPage getByN_H_P_S_PrevAndNext(Session session,
15504                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
15505                    int status, OrderByComparator orderByComparator, boolean previous) {
15506                    StringBundler query = null;
15507    
15508                    if (orderByComparator != null) {
15509                            query = new StringBundler(6 +
15510                                            (orderByComparator.getOrderByFields().length * 6));
15511                    }
15512                    else {
15513                            query = new StringBundler(3);
15514                    }
15515    
15516                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
15517    
15518                    query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
15519    
15520                    query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
15521    
15522                    if (parentTitle == null) {
15523                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
15524                    }
15525                    else {
15526                            if (parentTitle.equals(StringPool.BLANK)) {
15527                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
15528                            }
15529                            else {
15530                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
15531                            }
15532                    }
15533    
15534                    query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
15535    
15536                    if (orderByComparator != null) {
15537                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15538    
15539                            if (orderByConditionFields.length > 0) {
15540                                    query.append(WHERE_AND);
15541                            }
15542    
15543                            for (int i = 0; i < orderByConditionFields.length; i++) {
15544                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15545                                    query.append(orderByConditionFields[i]);
15546    
15547                                    if ((i + 1) < orderByConditionFields.length) {
15548                                            if (orderByComparator.isAscending() ^ previous) {
15549                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15550                                            }
15551                                            else {
15552                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15553                                            }
15554                                    }
15555                                    else {
15556                                            if (orderByComparator.isAscending() ^ previous) {
15557                                                    query.append(WHERE_GREATER_THAN);
15558                                            }
15559                                            else {
15560                                                    query.append(WHERE_LESSER_THAN);
15561                                            }
15562                                    }
15563                            }
15564    
15565                            query.append(ORDER_BY_CLAUSE);
15566    
15567                            String[] orderByFields = orderByComparator.getOrderByFields();
15568    
15569                            for (int i = 0; i < orderByFields.length; i++) {
15570                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15571                                    query.append(orderByFields[i]);
15572    
15573                                    if ((i + 1) < orderByFields.length) {
15574                                            if (orderByComparator.isAscending() ^ previous) {
15575                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15576                                            }
15577                                            else {
15578                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15579                                            }
15580                                    }
15581                                    else {
15582                                            if (orderByComparator.isAscending() ^ previous) {
15583                                                    query.append(ORDER_BY_ASC);
15584                                            }
15585                                            else {
15586                                                    query.append(ORDER_BY_DESC);
15587                                            }
15588                                    }
15589                            }
15590                    }
15591                    else {
15592                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15593                    }
15594    
15595                    String sql = query.toString();
15596    
15597                    Query q = session.createQuery(sql);
15598    
15599                    q.setFirstResult(0);
15600                    q.setMaxResults(2);
15601    
15602                    QueryPos qPos = QueryPos.getInstance(q);
15603    
15604                    qPos.add(nodeId);
15605    
15606                    qPos.add(head);
15607    
15608                    if (parentTitle != null) {
15609                            qPos.add(parentTitle);
15610                    }
15611    
15612                    qPos.add(status);
15613    
15614                    if (orderByComparator != null) {
15615                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
15616    
15617                            for (Object value : values) {
15618                                    qPos.add(value);
15619                            }
15620                    }
15621    
15622                    List<WikiPage> list = q.list();
15623    
15624                    if (list.size() == 2) {
15625                            return list.get(1);
15626                    }
15627                    else {
15628                            return null;
15629                    }
15630            }
15631    
15632            /**
15633             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63; from the database.
15634             *
15635             * @param nodeId the node ID
15636             * @param head the head
15637             * @param parentTitle the parent title
15638             * @param status the status
15639             * @throws SystemException if a system exception occurred
15640             */
15641            public void removeByN_H_P_S(long nodeId, boolean head, String parentTitle,
15642                    int status) throws SystemException {
15643                    for (WikiPage wikiPage : findByN_H_P_S(nodeId, head, parentTitle,
15644                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15645                            remove(wikiPage);
15646                    }
15647            }
15648    
15649            /**
15650             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15651             *
15652             * @param nodeId the node ID
15653             * @param head the head
15654             * @param parentTitle the parent title
15655             * @param status the status
15656             * @return the number of matching wiki pages
15657             * @throws SystemException if a system exception occurred
15658             */
15659            public int countByN_H_P_S(long nodeId, boolean head, String parentTitle,
15660                    int status) throws SystemException {
15661                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_P_S;
15662    
15663                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle, status };
15664    
15665                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15666                                    this);
15667    
15668                    if (count == null) {
15669                            StringBundler query = new StringBundler(5);
15670    
15671                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
15672    
15673                            query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
15674    
15675                            query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
15676    
15677                            if (parentTitle == null) {
15678                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
15679                            }
15680                            else {
15681                                    if (parentTitle.equals(StringPool.BLANK)) {
15682                                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
15683                                    }
15684                                    else {
15685                                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
15686                                    }
15687                            }
15688    
15689                            query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
15690    
15691                            String sql = query.toString();
15692    
15693                            Session session = null;
15694    
15695                            try {
15696                                    session = openSession();
15697    
15698                                    Query q = session.createQuery(sql);
15699    
15700                                    QueryPos qPos = QueryPos.getInstance(q);
15701    
15702                                    qPos.add(nodeId);
15703    
15704                                    qPos.add(head);
15705    
15706                                    if (parentTitle != null) {
15707                                            qPos.add(parentTitle);
15708                                    }
15709    
15710                                    qPos.add(status);
15711    
15712                                    count = (Long)q.uniqueResult();
15713    
15714                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15715                            }
15716                            catch (Exception e) {
15717                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15718    
15719                                    throw processException(e);
15720                            }
15721                            finally {
15722                                    closeSession(session);
15723                            }
15724                    }
15725    
15726                    return count.intValue();
15727            }
15728    
15729            private static final String _FINDER_COLUMN_N_H_P_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
15730            private static final String _FINDER_COLUMN_N_H_P_S_HEAD_2 = "wikiPage.head = ? AND ";
15731            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
15732            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = lower(CAST_TEXT(?)) AND ";
15733            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR lower(wikiPage.parentTitle) = lower(CAST_TEXT(?))) AND ";
15734            private static final String _FINDER_COLUMN_N_H_P_S_STATUS_2 = "wikiPage.status = ?";
15735            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_P_S =
15736                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15737                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15738                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H_P_S",
15739                            new String[] {
15740                                    Long.class.getName(), Long.class.getName(),
15741                                    Boolean.class.getName(), String.class.getName(),
15742                                    Integer.class.getName(),
15743                                    
15744                            Integer.class.getName(), Integer.class.getName(),
15745                                    OrderByComparator.class.getName()
15746                            });
15747            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S =
15748                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15749                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15750                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H_P_S",
15751                            new String[] {
15752                                    Long.class.getName(), Long.class.getName(),
15753                                    Boolean.class.getName(), String.class.getName(),
15754                                    Integer.class.getName()
15755                            },
15756                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
15757                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
15758                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
15759                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
15760                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
15761                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
15762                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
15763            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15764                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15765                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H_P_S",
15766                            new String[] {
15767                                    Long.class.getName(), Long.class.getName(),
15768                                    Boolean.class.getName(), String.class.getName(),
15769                                    Integer.class.getName()
15770                            });
15771    
15772            /**
15773             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15774             *
15775             * @param groupId the group ID
15776             * @param nodeId the node ID
15777             * @param head the head
15778             * @param parentTitle the parent title
15779             * @param status the status
15780             * @return the matching wiki pages
15781             * @throws SystemException if a system exception occurred
15782             */
15783            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
15784                    boolean head, String parentTitle, int status) throws SystemException {
15785                    return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
15786                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15787            }
15788    
15789            /**
15790             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15791             *
15792             * <p>
15793             * 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.
15794             * </p>
15795             *
15796             * @param groupId the group ID
15797             * @param nodeId the node ID
15798             * @param head the head
15799             * @param parentTitle the parent title
15800             * @param status the status
15801             * @param start the lower bound of the range of wiki pages
15802             * @param end the upper bound of the range of wiki pages (not inclusive)
15803             * @return the range of matching wiki pages
15804             * @throws SystemException if a system exception occurred
15805             */
15806            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
15807                    boolean head, String parentTitle, int status, int start, int end)
15808                    throws SystemException {
15809                    return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
15810                            start, end, null);
15811            }
15812    
15813            /**
15814             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15815             *
15816             * <p>
15817             * 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.
15818             * </p>
15819             *
15820             * @param groupId the group ID
15821             * @param nodeId the node ID
15822             * @param head the head
15823             * @param parentTitle the parent title
15824             * @param status the status
15825             * @param start the lower bound of the range of wiki pages
15826             * @param end the upper bound of the range of wiki pages (not inclusive)
15827             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15828             * @return the ordered range of matching wiki pages
15829             * @throws SystemException if a system exception occurred
15830             */
15831            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
15832                    boolean head, String parentTitle, int status, int start, int end,
15833                    OrderByComparator orderByComparator) throws SystemException {
15834                    boolean pagination = true;
15835                    FinderPath finderPath = null;
15836                    Object[] finderArgs = null;
15837    
15838                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15839                                    (orderByComparator == null)) {
15840                            pagination = false;
15841                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S;
15842                            finderArgs = new Object[] { groupId, nodeId, head, parentTitle, status };
15843                    }
15844                    else {
15845                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_P_S;
15846                            finderArgs = new Object[] {
15847                                            groupId, nodeId, head, parentTitle, status,
15848                                            
15849                                            start, end, orderByComparator
15850                                    };
15851                    }
15852    
15853                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
15854                                    finderArgs, this);
15855    
15856                    if ((list != null) && !list.isEmpty()) {
15857                            for (WikiPage wikiPage : list) {
15858                                    if ((groupId != wikiPage.getGroupId()) ||
15859                                                    (nodeId != wikiPage.getNodeId()) ||
15860                                                    (head != wikiPage.getHead()) ||
15861                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
15862                                                    (status != wikiPage.getStatus())) {
15863                                            list = null;
15864    
15865                                            break;
15866                                    }
15867                            }
15868                    }
15869    
15870                    if (list == null) {
15871                            StringBundler query = null;
15872    
15873                            if (orderByComparator != null) {
15874                                    query = new StringBundler(7 +
15875                                                    (orderByComparator.getOrderByFields().length * 3));
15876                            }
15877                            else {
15878                                    query = new StringBundler(7);
15879                            }
15880    
15881                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
15882    
15883                            query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
15884    
15885                            query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
15886    
15887                            query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
15888    
15889                            if (parentTitle == null) {
15890                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
15891                            }
15892                            else {
15893                                    if (parentTitle.equals(StringPool.BLANK)) {
15894                                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
15895                                    }
15896                                    else {
15897                                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
15898                                    }
15899                            }
15900    
15901                            query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
15902    
15903                            if (orderByComparator != null) {
15904                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15905                                            orderByComparator);
15906                            }
15907                            else
15908                             if (pagination) {
15909                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15910                            }
15911    
15912                            String sql = query.toString();
15913    
15914                            Session session = null;
15915    
15916                            try {
15917                                    session = openSession();
15918    
15919                                    Query q = session.createQuery(sql);
15920    
15921                                    QueryPos qPos = QueryPos.getInstance(q);
15922    
15923                                    qPos.add(groupId);
15924    
15925                                    qPos.add(nodeId);
15926    
15927                                    qPos.add(head);
15928    
15929                                    if (parentTitle != null) {
15930                                            qPos.add(parentTitle);
15931                                    }
15932    
15933                                    qPos.add(status);
15934    
15935                                    if (!pagination) {
15936                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15937                                                            start, end, false);
15938    
15939                                            Collections.sort(list);
15940    
15941                                            list = new UnmodifiableList<WikiPage>(list);
15942                                    }
15943                                    else {
15944                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15945                                                            start, end);
15946                                    }
15947    
15948                                    cacheResult(list);
15949    
15950                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15951                            }
15952                            catch (Exception e) {
15953                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15954    
15955                                    throw processException(e);
15956                            }
15957                            finally {
15958                                    closeSession(session);
15959                            }
15960                    }
15961    
15962                    return list;
15963            }
15964    
15965            /**
15966             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
15967             *
15968             * @param groupId the group ID
15969             * @param nodeId the node ID
15970             * @param head the head
15971             * @param parentTitle the parent title
15972             * @param status the status
15973             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15974             * @return the first matching wiki page
15975             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
15976             * @throws SystemException if a system exception occurred
15977             */
15978            public WikiPage findByG_N_H_P_S_First(long groupId, long nodeId,
15979                    boolean head, String parentTitle, int status,
15980                    OrderByComparator orderByComparator)
15981                    throws NoSuchPageException, SystemException {
15982                    WikiPage wikiPage = fetchByG_N_H_P_S_First(groupId, nodeId, head,
15983                                    parentTitle, status, orderByComparator);
15984    
15985                    if (wikiPage != null) {
15986                            return wikiPage;
15987                    }
15988    
15989                    StringBundler msg = new StringBundler(12);
15990    
15991                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15992    
15993                    msg.append("groupId=");
15994                    msg.append(groupId);
15995    
15996                    msg.append(", nodeId=");
15997                    msg.append(nodeId);
15998    
15999                    msg.append(", head=");
16000                    msg.append(head);
16001    
16002                    msg.append(", parentTitle=");
16003                    msg.append(parentTitle);
16004    
16005                    msg.append(", status=");
16006                    msg.append(status);
16007    
16008                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16009    
16010                    throw new NoSuchPageException(msg.toString());
16011            }
16012    
16013            /**
16014             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16015             *
16016             * @param groupId the group ID
16017             * @param nodeId the node ID
16018             * @param head the head
16019             * @param parentTitle the parent title
16020             * @param status the status
16021             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16022             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
16023             * @throws SystemException if a system exception occurred
16024             */
16025            public WikiPage fetchByG_N_H_P_S_First(long groupId, long nodeId,
16026                    boolean head, String parentTitle, int status,
16027                    OrderByComparator orderByComparator) throws SystemException {
16028                    List<WikiPage> list = findByG_N_H_P_S(groupId, nodeId, head,
16029                                    parentTitle, status, 0, 1, orderByComparator);
16030    
16031                    if (!list.isEmpty()) {
16032                            return list.get(0);
16033                    }
16034    
16035                    return null;
16036            }
16037    
16038            /**
16039             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16040             *
16041             * @param groupId the group ID
16042             * @param nodeId the node ID
16043             * @param head the head
16044             * @param parentTitle the parent title
16045             * @param status the status
16046             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16047             * @return the last matching wiki page
16048             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
16049             * @throws SystemException if a system exception occurred
16050             */
16051            public WikiPage findByG_N_H_P_S_Last(long groupId, long nodeId,
16052                    boolean head, String parentTitle, int status,
16053                    OrderByComparator orderByComparator)
16054                    throws NoSuchPageException, SystemException {
16055                    WikiPage wikiPage = fetchByG_N_H_P_S_Last(groupId, nodeId, head,
16056                                    parentTitle, status, orderByComparator);
16057    
16058                    if (wikiPage != null) {
16059                            return wikiPage;
16060                    }
16061    
16062                    StringBundler msg = new StringBundler(12);
16063    
16064                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16065    
16066                    msg.append("groupId=");
16067                    msg.append(groupId);
16068    
16069                    msg.append(", nodeId=");
16070                    msg.append(nodeId);
16071    
16072                    msg.append(", head=");
16073                    msg.append(head);
16074    
16075                    msg.append(", parentTitle=");
16076                    msg.append(parentTitle);
16077    
16078                    msg.append(", status=");
16079                    msg.append(status);
16080    
16081                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16082    
16083                    throw new NoSuchPageException(msg.toString());
16084            }
16085    
16086            /**
16087             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16088             *
16089             * @param groupId the group ID
16090             * @param nodeId the node ID
16091             * @param head the head
16092             * @param parentTitle the parent title
16093             * @param status the status
16094             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16095             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
16096             * @throws SystemException if a system exception occurred
16097             */
16098            public WikiPage fetchByG_N_H_P_S_Last(long groupId, long nodeId,
16099                    boolean head, String parentTitle, int status,
16100                    OrderByComparator orderByComparator) throws SystemException {
16101                    int count = countByG_N_H_P_S(groupId, nodeId, head, parentTitle, status);
16102    
16103                    List<WikiPage> list = findByG_N_H_P_S(groupId, nodeId, head,
16104                                    parentTitle, status, count - 1, count, orderByComparator);
16105    
16106                    if (!list.isEmpty()) {
16107                            return list.get(0);
16108                    }
16109    
16110                    return null;
16111            }
16112    
16113            /**
16114             * 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;.
16115             *
16116             * @param pageId the primary key of the current wiki page
16117             * @param groupId the group ID
16118             * @param nodeId the node ID
16119             * @param head the head
16120             * @param parentTitle the parent title
16121             * @param status the status
16122             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16123             * @return the previous, current, and next wiki page
16124             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
16125             * @throws SystemException if a system exception occurred
16126             */
16127            public WikiPage[] findByG_N_H_P_S_PrevAndNext(long pageId, long groupId,
16128                    long nodeId, boolean head, String parentTitle, int status,
16129                    OrderByComparator orderByComparator)
16130                    throws NoSuchPageException, SystemException {
16131                    WikiPage wikiPage = findByPrimaryKey(pageId);
16132    
16133                    Session session = null;
16134    
16135                    try {
16136                            session = openSession();
16137    
16138                            WikiPage[] array = new WikiPageImpl[3];
16139    
16140                            array[0] = getByG_N_H_P_S_PrevAndNext(session, wikiPage, groupId,
16141                                            nodeId, head, parentTitle, status, orderByComparator, true);
16142    
16143                            array[1] = wikiPage;
16144    
16145                            array[2] = getByG_N_H_P_S_PrevAndNext(session, wikiPage, groupId,
16146                                            nodeId, head, parentTitle, status, orderByComparator, false);
16147    
16148                            return array;
16149                    }
16150                    catch (Exception e) {
16151                            throw processException(e);
16152                    }
16153                    finally {
16154                            closeSession(session);
16155                    }
16156            }
16157    
16158            protected WikiPage getByG_N_H_P_S_PrevAndNext(Session session,
16159                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
16160                    String parentTitle, int status, OrderByComparator orderByComparator,
16161                    boolean previous) {
16162                    StringBundler query = null;
16163    
16164                    if (orderByComparator != null) {
16165                            query = new StringBundler(6 +
16166                                            (orderByComparator.getOrderByFields().length * 6));
16167                    }
16168                    else {
16169                            query = new StringBundler(3);
16170                    }
16171    
16172                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
16173    
16174                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
16175    
16176                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
16177    
16178                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
16179    
16180                    if (parentTitle == null) {
16181                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
16182                    }
16183                    else {
16184                            if (parentTitle.equals(StringPool.BLANK)) {
16185                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
16186                            }
16187                            else {
16188                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
16189                            }
16190                    }
16191    
16192                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
16193    
16194                    if (orderByComparator != null) {
16195                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16196    
16197                            if (orderByConditionFields.length > 0) {
16198                                    query.append(WHERE_AND);
16199                            }
16200    
16201                            for (int i = 0; i < orderByConditionFields.length; i++) {
16202                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16203                                    query.append(orderByConditionFields[i]);
16204    
16205                                    if ((i + 1) < orderByConditionFields.length) {
16206                                            if (orderByComparator.isAscending() ^ previous) {
16207                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16208                                            }
16209                                            else {
16210                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16211                                            }
16212                                    }
16213                                    else {
16214                                            if (orderByComparator.isAscending() ^ previous) {
16215                                                    query.append(WHERE_GREATER_THAN);
16216                                            }
16217                                            else {
16218                                                    query.append(WHERE_LESSER_THAN);
16219                                            }
16220                                    }
16221                            }
16222    
16223                            query.append(ORDER_BY_CLAUSE);
16224    
16225                            String[] orderByFields = orderByComparator.getOrderByFields();
16226    
16227                            for (int i = 0; i < orderByFields.length; i++) {
16228                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16229                                    query.append(orderByFields[i]);
16230    
16231                                    if ((i + 1) < orderByFields.length) {
16232                                            if (orderByComparator.isAscending() ^ previous) {
16233                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16234                                            }
16235                                            else {
16236                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16237                                            }
16238                                    }
16239                                    else {
16240                                            if (orderByComparator.isAscending() ^ previous) {
16241                                                    query.append(ORDER_BY_ASC);
16242                                            }
16243                                            else {
16244                                                    query.append(ORDER_BY_DESC);
16245                                            }
16246                                    }
16247                            }
16248                    }
16249                    else {
16250                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16251                    }
16252    
16253                    String sql = query.toString();
16254    
16255                    Query q = session.createQuery(sql);
16256    
16257                    q.setFirstResult(0);
16258                    q.setMaxResults(2);
16259    
16260                    QueryPos qPos = QueryPos.getInstance(q);
16261    
16262                    qPos.add(groupId);
16263    
16264                    qPos.add(nodeId);
16265    
16266                    qPos.add(head);
16267    
16268                    if (parentTitle != null) {
16269                            qPos.add(parentTitle);
16270                    }
16271    
16272                    qPos.add(status);
16273    
16274                    if (orderByComparator != null) {
16275                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
16276    
16277                            for (Object value : values) {
16278                                    qPos.add(value);
16279                            }
16280                    }
16281    
16282                    List<WikiPage> list = q.list();
16283    
16284                    if (list.size() == 2) {
16285                            return list.get(1);
16286                    }
16287                    else {
16288                            return null;
16289                    }
16290            }
16291    
16292            /**
16293             * 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;.
16294             *
16295             * @param groupId the group ID
16296             * @param nodeId the node ID
16297             * @param head the head
16298             * @param parentTitle the parent title
16299             * @param status the status
16300             * @return the matching wiki pages that the user has permission to view
16301             * @throws SystemException if a system exception occurred
16302             */
16303            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
16304                    boolean head, String parentTitle, int status) throws SystemException {
16305                    return filterFindByG_N_H_P_S(groupId, nodeId, head, parentTitle,
16306                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16307            }
16308    
16309            /**
16310             * 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;.
16311             *
16312             * <p>
16313             * 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.
16314             * </p>
16315             *
16316             * @param groupId the group ID
16317             * @param nodeId the node ID
16318             * @param head the head
16319             * @param parentTitle the parent title
16320             * @param status the status
16321             * @param start the lower bound of the range of wiki pages
16322             * @param end the upper bound of the range of wiki pages (not inclusive)
16323             * @return the range of matching wiki pages that the user has permission to view
16324             * @throws SystemException if a system exception occurred
16325             */
16326            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
16327                    boolean head, String parentTitle, int status, int start, int end)
16328                    throws SystemException {
16329                    return filterFindByG_N_H_P_S(groupId, nodeId, head, parentTitle,
16330                            status, start, end, null);
16331            }
16332    
16333            /**
16334             * 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;.
16335             *
16336             * <p>
16337             * 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.
16338             * </p>
16339             *
16340             * @param groupId the group ID
16341             * @param nodeId the node ID
16342             * @param head the head
16343             * @param parentTitle the parent title
16344             * @param status the status
16345             * @param start the lower bound of the range of wiki pages
16346             * @param end the upper bound of the range of wiki pages (not inclusive)
16347             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16348             * @return the ordered range of matching wiki pages that the user has permission to view
16349             * @throws SystemException if a system exception occurred
16350             */
16351            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
16352                    boolean head, String parentTitle, int status, int start, int end,
16353                    OrderByComparator orderByComparator) throws SystemException {
16354                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16355                            return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
16356                                    start, end, orderByComparator);
16357                    }
16358    
16359                    StringBundler query = null;
16360    
16361                    if (orderByComparator != null) {
16362                            query = new StringBundler(7 +
16363                                            (orderByComparator.getOrderByFields().length * 3));
16364                    }
16365                    else {
16366                            query = new StringBundler(7);
16367                    }
16368    
16369                    if (getDB().isSupportsInlineDistinct()) {
16370                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
16371                    }
16372                    else {
16373                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
16374                    }
16375    
16376                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
16377    
16378                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
16379    
16380                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
16381    
16382                    if (parentTitle == null) {
16383                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
16384                    }
16385                    else {
16386                            if (parentTitle.equals(StringPool.BLANK)) {
16387                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
16388                            }
16389                            else {
16390                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
16391                            }
16392                    }
16393    
16394                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
16395    
16396                    if (!getDB().isSupportsInlineDistinct()) {
16397                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
16398                    }
16399    
16400                    if (orderByComparator != null) {
16401                            if (getDB().isSupportsInlineDistinct()) {
16402                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16403                                            orderByComparator);
16404                            }
16405                            else {
16406                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16407                                            orderByComparator);
16408                            }
16409                    }
16410                    else {
16411                            if (getDB().isSupportsInlineDistinct()) {
16412                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16413                            }
16414                            else {
16415                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
16416                            }
16417                    }
16418    
16419                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16420                                    WikiPage.class.getName(),
16421                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16422    
16423                    Session session = null;
16424    
16425                    try {
16426                            session = openSession();
16427    
16428                            SQLQuery q = session.createSQLQuery(sql);
16429    
16430                            if (getDB().isSupportsInlineDistinct()) {
16431                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
16432                            }
16433                            else {
16434                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
16435                            }
16436    
16437                            QueryPos qPos = QueryPos.getInstance(q);
16438    
16439                            qPos.add(groupId);
16440    
16441                            qPos.add(nodeId);
16442    
16443                            qPos.add(head);
16444    
16445                            if (parentTitle != null) {
16446                                    qPos.add(parentTitle);
16447                            }
16448    
16449                            qPos.add(status);
16450    
16451                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
16452                    }
16453                    catch (Exception e) {
16454                            throw processException(e);
16455                    }
16456                    finally {
16457                            closeSession(session);
16458                    }
16459            }
16460    
16461            /**
16462             * 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;.
16463             *
16464             * @param pageId the primary key of the current wiki page
16465             * @param groupId the group ID
16466             * @param nodeId the node ID
16467             * @param head the head
16468             * @param parentTitle the parent title
16469             * @param status the status
16470             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16471             * @return the previous, current, and next wiki page
16472             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
16473             * @throws SystemException if a system exception occurred
16474             */
16475            public WikiPage[] filterFindByG_N_H_P_S_PrevAndNext(long pageId,
16476                    long groupId, long nodeId, boolean head, String parentTitle,
16477                    int status, OrderByComparator orderByComparator)
16478                    throws NoSuchPageException, SystemException {
16479                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16480                            return findByG_N_H_P_S_PrevAndNext(pageId, groupId, nodeId, head,
16481                                    parentTitle, status, orderByComparator);
16482                    }
16483    
16484                    WikiPage wikiPage = findByPrimaryKey(pageId);
16485    
16486                    Session session = null;
16487    
16488                    try {
16489                            session = openSession();
16490    
16491                            WikiPage[] array = new WikiPageImpl[3];
16492    
16493                            array[0] = filterGetByG_N_H_P_S_PrevAndNext(session, wikiPage,
16494                                            groupId, nodeId, head, parentTitle, status,
16495                                            orderByComparator, true);
16496    
16497                            array[1] = wikiPage;
16498    
16499                            array[2] = filterGetByG_N_H_P_S_PrevAndNext(session, wikiPage,
16500                                            groupId, nodeId, head, parentTitle, status,
16501                                            orderByComparator, false);
16502    
16503                            return array;
16504                    }
16505                    catch (Exception e) {
16506                            throw processException(e);
16507                    }
16508                    finally {
16509                            closeSession(session);
16510                    }
16511            }
16512    
16513            protected WikiPage filterGetByG_N_H_P_S_PrevAndNext(Session session,
16514                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
16515                    String parentTitle, int status, OrderByComparator orderByComparator,
16516                    boolean previous) {
16517                    StringBundler query = null;
16518    
16519                    if (orderByComparator != null) {
16520                            query = new StringBundler(6 +
16521                                            (orderByComparator.getOrderByFields().length * 6));
16522                    }
16523                    else {
16524                            query = new StringBundler(3);
16525                    }
16526    
16527                    if (getDB().isSupportsInlineDistinct()) {
16528                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
16529                    }
16530                    else {
16531                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
16532                    }
16533    
16534                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
16535    
16536                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
16537    
16538                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
16539    
16540                    if (parentTitle == null) {
16541                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
16542                    }
16543                    else {
16544                            if (parentTitle.equals(StringPool.BLANK)) {
16545                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
16546                            }
16547                            else {
16548                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
16549                            }
16550                    }
16551    
16552                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
16553    
16554                    if (!getDB().isSupportsInlineDistinct()) {
16555                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
16556                    }
16557    
16558                    if (orderByComparator != null) {
16559                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16560    
16561                            if (orderByConditionFields.length > 0) {
16562                                    query.append(WHERE_AND);
16563                            }
16564    
16565                            for (int i = 0; i < orderByConditionFields.length; i++) {
16566                                    if (getDB().isSupportsInlineDistinct()) {
16567                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16568                                    }
16569                                    else {
16570                                            query.append(_ORDER_BY_ENTITY_TABLE);
16571                                    }
16572    
16573                                    query.append(orderByConditionFields[i]);
16574    
16575                                    if ((i + 1) < orderByConditionFields.length) {
16576                                            if (orderByComparator.isAscending() ^ previous) {
16577                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16578                                            }
16579                                            else {
16580                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16581                                            }
16582                                    }
16583                                    else {
16584                                            if (orderByComparator.isAscending() ^ previous) {
16585                                                    query.append(WHERE_GREATER_THAN);
16586                                            }
16587                                            else {
16588                                                    query.append(WHERE_LESSER_THAN);
16589                                            }
16590                                    }
16591                            }
16592    
16593                            query.append(ORDER_BY_CLAUSE);
16594    
16595                            String[] orderByFields = orderByComparator.getOrderByFields();
16596    
16597                            for (int i = 0; i < orderByFields.length; i++) {
16598                                    if (getDB().isSupportsInlineDistinct()) {
16599                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16600                                    }
16601                                    else {
16602                                            query.append(_ORDER_BY_ENTITY_TABLE);
16603                                    }
16604    
16605                                    query.append(orderByFields[i]);
16606    
16607                                    if ((i + 1) < orderByFields.length) {
16608                                            if (orderByComparator.isAscending() ^ previous) {
16609                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16610                                            }
16611                                            else {
16612                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16613                                            }
16614                                    }
16615                                    else {
16616                                            if (orderByComparator.isAscending() ^ previous) {
16617                                                    query.append(ORDER_BY_ASC);
16618                                            }
16619                                            else {
16620                                                    query.append(ORDER_BY_DESC);
16621                                            }
16622                                    }
16623                            }
16624                    }
16625                    else {
16626                            if (getDB().isSupportsInlineDistinct()) {
16627                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16628                            }
16629                            else {
16630                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
16631                            }
16632                    }
16633    
16634                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16635                                    WikiPage.class.getName(),
16636                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16637    
16638                    SQLQuery q = session.createSQLQuery(sql);
16639    
16640                    q.setFirstResult(0);
16641                    q.setMaxResults(2);
16642    
16643                    if (getDB().isSupportsInlineDistinct()) {
16644                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
16645                    }
16646                    else {
16647                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
16648                    }
16649    
16650                    QueryPos qPos = QueryPos.getInstance(q);
16651    
16652                    qPos.add(groupId);
16653    
16654                    qPos.add(nodeId);
16655    
16656                    qPos.add(head);
16657    
16658                    if (parentTitle != null) {
16659                            qPos.add(parentTitle);
16660                    }
16661    
16662                    qPos.add(status);
16663    
16664                    if (orderByComparator != null) {
16665                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
16666    
16667                            for (Object value : values) {
16668                                    qPos.add(value);
16669                            }
16670                    }
16671    
16672                    List<WikiPage> list = q.list();
16673    
16674                    if (list.size() == 2) {
16675                            return list.get(1);
16676                    }
16677                    else {
16678                            return null;
16679                    }
16680            }
16681    
16682            /**
16683             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63; from the database.
16684             *
16685             * @param groupId the group ID
16686             * @param nodeId the node ID
16687             * @param head the head
16688             * @param parentTitle the parent title
16689             * @param status the status
16690             * @throws SystemException if a system exception occurred
16691             */
16692            public void removeByG_N_H_P_S(long groupId, long nodeId, boolean head,
16693                    String parentTitle, int status) throws SystemException {
16694                    for (WikiPage wikiPage : findByG_N_H_P_S(groupId, nodeId, head,
16695                                    parentTitle, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16696                            remove(wikiPage);
16697                    }
16698            }
16699    
16700            /**
16701             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
16702             *
16703             * @param groupId the group ID
16704             * @param nodeId the node ID
16705             * @param head the head
16706             * @param parentTitle the parent title
16707             * @param status the status
16708             * @return the number of matching wiki pages
16709             * @throws SystemException if a system exception occurred
16710             */
16711            public int countByG_N_H_P_S(long groupId, long nodeId, boolean head,
16712                    String parentTitle, int status) throws SystemException {
16713                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H_P_S;
16714    
16715                    Object[] finderArgs = new Object[] {
16716                                    groupId, nodeId, head, parentTitle, status
16717                            };
16718    
16719                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16720                                    this);
16721    
16722                    if (count == null) {
16723                            StringBundler query = new StringBundler(6);
16724    
16725                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
16726    
16727                            query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
16728    
16729                            query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
16730    
16731                            query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
16732    
16733                            if (parentTitle == null) {
16734                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
16735                            }
16736                            else {
16737                                    if (parentTitle.equals(StringPool.BLANK)) {
16738                                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
16739                                    }
16740                                    else {
16741                                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
16742                                    }
16743                            }
16744    
16745                            query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
16746    
16747                            String sql = query.toString();
16748    
16749                            Session session = null;
16750    
16751                            try {
16752                                    session = openSession();
16753    
16754                                    Query q = session.createQuery(sql);
16755    
16756                                    QueryPos qPos = QueryPos.getInstance(q);
16757    
16758                                    qPos.add(groupId);
16759    
16760                                    qPos.add(nodeId);
16761    
16762                                    qPos.add(head);
16763    
16764                                    if (parentTitle != null) {
16765                                            qPos.add(parentTitle);
16766                                    }
16767    
16768                                    qPos.add(status);
16769    
16770                                    count = (Long)q.uniqueResult();
16771    
16772                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
16773                            }
16774                            catch (Exception e) {
16775                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16776    
16777                                    throw processException(e);
16778                            }
16779                            finally {
16780                                    closeSession(session);
16781                            }
16782                    }
16783    
16784                    return count.intValue();
16785            }
16786    
16787            /**
16788             * 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;.
16789             *
16790             * @param groupId the group ID
16791             * @param nodeId the node ID
16792             * @param head the head
16793             * @param parentTitle the parent title
16794             * @param status the status
16795             * @return the number of matching wiki pages that the user has permission to view
16796             * @throws SystemException if a system exception occurred
16797             */
16798            public int filterCountByG_N_H_P_S(long groupId, long nodeId, boolean head,
16799                    String parentTitle, int status) throws SystemException {
16800                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16801                            return countByG_N_H_P_S(groupId, nodeId, head, parentTitle, status);
16802                    }
16803    
16804                    StringBundler query = new StringBundler(6);
16805    
16806                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
16807    
16808                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
16809    
16810                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
16811    
16812                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
16813    
16814                    if (parentTitle == null) {
16815                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
16816                    }
16817                    else {
16818                            if (parentTitle.equals(StringPool.BLANK)) {
16819                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
16820                            }
16821                            else {
16822                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
16823                            }
16824                    }
16825    
16826                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
16827    
16828                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16829                                    WikiPage.class.getName(),
16830                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16831    
16832                    Session session = null;
16833    
16834                    try {
16835                            session = openSession();
16836    
16837                            SQLQuery q = session.createSQLQuery(sql);
16838    
16839                            q.addScalar(COUNT_COLUMN_NAME,
16840                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16841    
16842                            QueryPos qPos = QueryPos.getInstance(q);
16843    
16844                            qPos.add(groupId);
16845    
16846                            qPos.add(nodeId);
16847    
16848                            qPos.add(head);
16849    
16850                            if (parentTitle != null) {
16851                                    qPos.add(parentTitle);
16852                            }
16853    
16854                            qPos.add(status);
16855    
16856                            Long count = (Long)q.uniqueResult();
16857    
16858                            return count.intValue();
16859                    }
16860                    catch (Exception e) {
16861                            throw processException(e);
16862                    }
16863                    finally {
16864                            closeSession(session);
16865                    }
16866            }
16867    
16868            private static final String _FINDER_COLUMN_G_N_H_P_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
16869            private static final String _FINDER_COLUMN_G_N_H_P_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
16870            private static final String _FINDER_COLUMN_G_N_H_P_S_HEAD_2 = "wikiPage.head = ? AND ";
16871            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
16872            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = lower(CAST_TEXT(?)) AND ";
16873            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR lower(wikiPage.parentTitle) = lower(CAST_TEXT(?))) AND ";
16874            private static final String _FINDER_COLUMN_G_N_H_P_S_STATUS_2 = "wikiPage.status = ?";
16875    
16876            /**
16877             * Caches the wiki page in the entity cache if it is enabled.
16878             *
16879             * @param wikiPage the wiki page
16880             */
16881            public void cacheResult(WikiPage wikiPage) {
16882                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16883                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
16884    
16885                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
16886                            new Object[] { wikiPage.getUuid(), Long.valueOf(
16887                                            wikiPage.getGroupId()) }, wikiPage);
16888    
16889                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
16890                            new Object[] {
16891                                    Long.valueOf(wikiPage.getResourcePrimKey()),
16892                                    Long.valueOf(wikiPage.getNodeId()),
16893                                    Double.valueOf(wikiPage.getVersion())
16894                            }, wikiPage);
16895    
16896                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
16897                            new Object[] {
16898                                    Long.valueOf(wikiPage.getNodeId()),
16899                                    
16900                            wikiPage.getTitle(), Double.valueOf(wikiPage.getVersion())
16901                            }, wikiPage);
16902    
16903                    wikiPage.resetOriginalValues();
16904            }
16905    
16906            /**
16907             * Caches the wiki pages in the entity cache if it is enabled.
16908             *
16909             * @param wikiPages the wiki pages
16910             */
16911            public void cacheResult(List<WikiPage> wikiPages) {
16912                    for (WikiPage wikiPage : wikiPages) {
16913                            if (EntityCacheUtil.getResult(
16914                                                    WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16915                                                    WikiPageImpl.class, wikiPage.getPrimaryKey()) == null) {
16916                                    cacheResult(wikiPage);
16917                            }
16918                            else {
16919                                    wikiPage.resetOriginalValues();
16920                            }
16921                    }
16922            }
16923    
16924            /**
16925             * Clears the cache for all wiki pages.
16926             *
16927             * <p>
16928             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
16929             * </p>
16930             */
16931            @Override
16932            public void clearCache() {
16933                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
16934                            CacheRegistryUtil.clear(WikiPageImpl.class.getName());
16935                    }
16936    
16937                    EntityCacheUtil.clearCache(WikiPageImpl.class.getName());
16938    
16939                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
16940                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
16941                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
16942            }
16943    
16944            /**
16945             * Clears the cache for the wiki page.
16946             *
16947             * <p>
16948             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
16949             * </p>
16950             */
16951            @Override
16952            public void clearCache(WikiPage wikiPage) {
16953                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16954                            WikiPageImpl.class, wikiPage.getPrimaryKey());
16955    
16956                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
16957                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
16958    
16959                    clearUniqueFindersCache(wikiPage);
16960            }
16961    
16962            @Override
16963            public void clearCache(List<WikiPage> wikiPages) {
16964                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
16965                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
16966    
16967                    for (WikiPage wikiPage : wikiPages) {
16968                            EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16969                                    WikiPageImpl.class, wikiPage.getPrimaryKey());
16970    
16971                            clearUniqueFindersCache(wikiPage);
16972                    }
16973            }
16974    
16975            protected void cacheUniqueFindersCache(WikiPage wikiPage) {
16976                    if (wikiPage.isNew()) {
16977                            Object[] args = new Object[] {
16978                                            wikiPage.getUuid(), Long.valueOf(wikiPage.getGroupId())
16979                                    };
16980    
16981                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
16982                                    Long.valueOf(1));
16983                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
16984                                    wikiPage);
16985    
16986                            args = new Object[] {
16987                                            Long.valueOf(wikiPage.getResourcePrimKey()),
16988                                            Long.valueOf(wikiPage.getNodeId()),
16989                                            Double.valueOf(wikiPage.getVersion())
16990                                    };
16991    
16992                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_V, args,
16993                                    Long.valueOf(1));
16994                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V, args, wikiPage);
16995    
16996                            args = new Object[] {
16997                                            Long.valueOf(wikiPage.getNodeId()),
16998                                            
16999                                            wikiPage.getTitle(), Double.valueOf(wikiPage.getVersion())
17000                                    };
17001    
17002                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_V, args,
17003                                    Long.valueOf(1));
17004                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V, args, wikiPage);
17005                    }
17006                    else {
17007                            WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
17008    
17009                            if ((wikiPageModelImpl.getColumnBitmask() &
17010                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
17011                                    Object[] args = new Object[] {
17012                                                    wikiPage.getUuid(), Long.valueOf(wikiPage.getGroupId())
17013                                            };
17014    
17015                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
17016                                            Long.valueOf(1));
17017                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
17018                                            wikiPage);
17019                            }
17020    
17021                            if ((wikiPageModelImpl.getColumnBitmask() &
17022                                            FINDER_PATH_FETCH_BY_R_N_V.getColumnBitmask()) != 0) {
17023                                    Object[] args = new Object[] {
17024                                                    Long.valueOf(wikiPage.getResourcePrimKey()),
17025                                                    Long.valueOf(wikiPage.getNodeId()),
17026                                                    Double.valueOf(wikiPage.getVersion())
17027                                            };
17028    
17029                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_V, args,
17030                                            Long.valueOf(1));
17031                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V, args,
17032                                            wikiPage);
17033                            }
17034    
17035                            if ((wikiPageModelImpl.getColumnBitmask() &
17036                                            FINDER_PATH_FETCH_BY_N_T_V.getColumnBitmask()) != 0) {
17037                                    Object[] args = new Object[] {
17038                                                    Long.valueOf(wikiPage.getNodeId()),
17039                                                    
17040                                                    wikiPage.getTitle(),
17041                                                    Double.valueOf(wikiPage.getVersion())
17042                                            };
17043    
17044                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_V, args,
17045                                            Long.valueOf(1));
17046                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V, args,
17047                                            wikiPage);
17048                            }
17049                    }
17050            }
17051    
17052            protected void clearUniqueFindersCache(WikiPage wikiPage) {
17053                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
17054    
17055                    Object[] args = new Object[] {
17056                                    wikiPage.getUuid(), Long.valueOf(wikiPage.getGroupId())
17057                            };
17058    
17059                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
17060                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
17061    
17062                    if ((wikiPageModelImpl.getColumnBitmask() &
17063                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
17064                            args = new Object[] {
17065                                            wikiPageModelImpl.getOriginalUuid(),
17066                                            Long.valueOf(wikiPageModelImpl.getOriginalGroupId())
17067                                    };
17068    
17069                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
17070                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
17071                    }
17072    
17073                    args = new Object[] {
17074                                    Long.valueOf(wikiPage.getResourcePrimKey()),
17075                                    Long.valueOf(wikiPage.getNodeId()),
17076                                    Double.valueOf(wikiPage.getVersion())
17077                            };
17078    
17079                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_V, args);
17080                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V, args);
17081    
17082                    if ((wikiPageModelImpl.getColumnBitmask() &
17083                                    FINDER_PATH_FETCH_BY_R_N_V.getColumnBitmask()) != 0) {
17084                            args = new Object[] {
17085                                            Long.valueOf(wikiPageModelImpl.getOriginalResourcePrimKey()),
17086                                            Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17087                                            Double.valueOf(wikiPageModelImpl.getOriginalVersion())
17088                                    };
17089    
17090                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_V, args);
17091                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V, args);
17092                    }
17093    
17094                    args = new Object[] {
17095                                    Long.valueOf(wikiPage.getNodeId()),
17096                                    
17097                                    wikiPage.getTitle(), Double.valueOf(wikiPage.getVersion())
17098                            };
17099    
17100                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_V, args);
17101                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V, args);
17102    
17103                    if ((wikiPageModelImpl.getColumnBitmask() &
17104                                    FINDER_PATH_FETCH_BY_N_T_V.getColumnBitmask()) != 0) {
17105                            args = new Object[] {
17106                                            Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17107                                            
17108                                            wikiPageModelImpl.getOriginalTitle(),
17109                                            Double.valueOf(wikiPageModelImpl.getOriginalVersion())
17110                                    };
17111    
17112                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_V, args);
17113                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V, args);
17114                    }
17115            }
17116    
17117            /**
17118             * Creates a new wiki page with the primary key. Does not add the wiki page to the database.
17119             *
17120             * @param pageId the primary key for the new wiki page
17121             * @return the new wiki page
17122             */
17123            public WikiPage create(long pageId) {
17124                    WikiPage wikiPage = new WikiPageImpl();
17125    
17126                    wikiPage.setNew(true);
17127                    wikiPage.setPrimaryKey(pageId);
17128    
17129                    String uuid = PortalUUIDUtil.generate();
17130    
17131                    wikiPage.setUuid(uuid);
17132    
17133                    return wikiPage;
17134            }
17135    
17136            /**
17137             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
17138             *
17139             * @param pageId the primary key of the wiki page
17140             * @return the wiki page that was removed
17141             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17142             * @throws SystemException if a system exception occurred
17143             */
17144            public WikiPage remove(long pageId)
17145                    throws NoSuchPageException, SystemException {
17146                    return remove(Long.valueOf(pageId));
17147            }
17148    
17149            /**
17150             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
17151             *
17152             * @param primaryKey the primary key of the wiki page
17153             * @return the wiki page that was removed
17154             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17155             * @throws SystemException if a system exception occurred
17156             */
17157            @Override
17158            public WikiPage remove(Serializable primaryKey)
17159                    throws NoSuchPageException, SystemException {
17160                    Session session = null;
17161    
17162                    try {
17163                            session = openSession();
17164    
17165                            WikiPage wikiPage = (WikiPage)session.get(WikiPageImpl.class,
17166                                            primaryKey);
17167    
17168                            if (wikiPage == null) {
17169                                    if (_log.isWarnEnabled()) {
17170                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
17171                                    }
17172    
17173                                    throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
17174                                            primaryKey);
17175                            }
17176    
17177                            return remove(wikiPage);
17178                    }
17179                    catch (NoSuchPageException nsee) {
17180                            throw nsee;
17181                    }
17182                    catch (Exception e) {
17183                            throw processException(e);
17184                    }
17185                    finally {
17186                            closeSession(session);
17187                    }
17188            }
17189    
17190            @Override
17191            protected WikiPage removeImpl(WikiPage wikiPage) throws SystemException {
17192                    wikiPage = toUnwrappedModel(wikiPage);
17193    
17194                    Session session = null;
17195    
17196                    try {
17197                            session = openSession();
17198    
17199                            if (!session.contains(wikiPage)) {
17200                                    wikiPage = (WikiPage)session.get(WikiPageImpl.class,
17201                                                    wikiPage.getPrimaryKeyObj());
17202                            }
17203    
17204                            if (wikiPage != null) {
17205                                    session.delete(wikiPage);
17206                            }
17207                    }
17208                    catch (Exception e) {
17209                            throw processException(e);
17210                    }
17211                    finally {
17212                            closeSession(session);
17213                    }
17214    
17215                    if (wikiPage != null) {
17216                            clearCache(wikiPage);
17217                    }
17218    
17219                    return wikiPage;
17220            }
17221    
17222            @Override
17223            public WikiPage updateImpl(com.liferay.portlet.wiki.model.WikiPage wikiPage)
17224                    throws SystemException {
17225                    wikiPage = toUnwrappedModel(wikiPage);
17226    
17227                    boolean isNew = wikiPage.isNew();
17228    
17229                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
17230    
17231                    if (Validator.isNull(wikiPage.getUuid())) {
17232                            String uuid = PortalUUIDUtil.generate();
17233    
17234                            wikiPage.setUuid(uuid);
17235                    }
17236    
17237                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
17238    
17239                    if (userId > 0) {
17240                            long companyId = wikiPage.getCompanyId();
17241    
17242                            long groupId = wikiPage.getGroupId();
17243    
17244                            long pageId = 0;
17245    
17246                            if (!isNew) {
17247                                    pageId = wikiPage.getPrimaryKey();
17248                            }
17249    
17250                            try {
17251                                    wikiPage.setTitle(SanitizerUtil.sanitize(companyId, groupId,
17252                                                    userId,
17253                                                    com.liferay.portlet.wiki.model.WikiPage.class.getName(),
17254                                                    pageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
17255                                                    wikiPage.getTitle(), null));
17256                            }
17257                            catch (SanitizerException se) {
17258                                    throw new SystemException(se);
17259                            }
17260                    }
17261    
17262                    Session session = null;
17263    
17264                    try {
17265                            session = openSession();
17266    
17267                            if (wikiPage.isNew()) {
17268                                    session.save(wikiPage);
17269    
17270                                    wikiPage.setNew(false);
17271                            }
17272                            else {
17273                                    session.merge(wikiPage);
17274                            }
17275                    }
17276                    catch (Exception e) {
17277                            throw processException(e);
17278                    }
17279                    finally {
17280                            closeSession(session);
17281                    }
17282    
17283                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
17284    
17285                    if (isNew || !WikiPageModelImpl.COLUMN_BITMASK_ENABLED) {
17286                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
17287                    }
17288    
17289                    else {
17290                            if ((wikiPageModelImpl.getColumnBitmask() &
17291                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
17292                                    Object[] args = new Object[] { wikiPageModelImpl.getOriginalUuid() };
17293    
17294                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
17295                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
17296                                            args);
17297    
17298                                    args = new Object[] { wikiPageModelImpl.getUuid() };
17299    
17300                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
17301                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
17302                                            args);
17303                            }
17304    
17305                            if ((wikiPageModelImpl.getColumnBitmask() &
17306                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
17307                                    Object[] args = new Object[] {
17308                                                    wikiPageModelImpl.getOriginalUuid(),
17309                                                    Long.valueOf(wikiPageModelImpl.getOriginalCompanyId())
17310                                            };
17311    
17312                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
17313                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
17314                                            args);
17315    
17316                                    args = new Object[] {
17317                                                    wikiPageModelImpl.getUuid(),
17318                                                    Long.valueOf(wikiPageModelImpl.getCompanyId())
17319                                            };
17320    
17321                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
17322                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
17323                                            args);
17324                            }
17325    
17326                            if ((wikiPageModelImpl.getColumnBitmask() &
17327                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID.getColumnBitmask()) != 0) {
17328                                    Object[] args = new Object[] {
17329                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId())
17330                                            };
17331    
17332                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NODEID, args);
17333                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID,
17334                                            args);
17335    
17336                                    args = new Object[] { Long.valueOf(wikiPageModelImpl.getNodeId()) };
17337    
17338                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NODEID, args);
17339                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID,
17340                                            args);
17341                            }
17342    
17343                            if ((wikiPageModelImpl.getColumnBitmask() &
17344                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT.getColumnBitmask()) != 0) {
17345                                    Object[] args = new Object[] {
17346                                                    wikiPageModelImpl.getOriginalFormat()
17347                                            };
17348    
17349                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FORMAT, args);
17350                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT,
17351                                            args);
17352    
17353                                    args = new Object[] { wikiPageModelImpl.getFormat() };
17354    
17355                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FORMAT, args);
17356                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT,
17357                                            args);
17358                            }
17359    
17360                            if ((wikiPageModelImpl.getColumnBitmask() &
17361                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N.getColumnBitmask()) != 0) {
17362                                    Object[] args = new Object[] {
17363                                                    Long.valueOf(wikiPageModelImpl.getOriginalResourcePrimKey()),
17364                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId())
17365                                            };
17366    
17367                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N, args);
17368                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N,
17369                                            args);
17370    
17371                                    args = new Object[] {
17372                                                    Long.valueOf(wikiPageModelImpl.getResourcePrimKey()),
17373                                                    Long.valueOf(wikiPageModelImpl.getNodeId())
17374                                            };
17375    
17376                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N, args);
17377                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N,
17378                                            args);
17379                            }
17380    
17381                            if ((wikiPageModelImpl.getColumnBitmask() &
17382                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T.getColumnBitmask()) != 0) {
17383                                    Object[] args = new Object[] {
17384                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17385                                                    
17386                                                    wikiPageModelImpl.getOriginalTitle()
17387                                            };
17388    
17389                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
17390                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T,
17391                                            args);
17392    
17393                                    args = new Object[] {
17394                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17395                                                    
17396                                                    wikiPageModelImpl.getTitle()
17397                                            };
17398    
17399                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
17400                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T,
17401                                            args);
17402                            }
17403    
17404                            if ((wikiPageModelImpl.getColumnBitmask() &
17405                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H.getColumnBitmask()) != 0) {
17406                                    Object[] args = new Object[] {
17407                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17408                                                    Boolean.valueOf(wikiPageModelImpl.getOriginalHead())
17409                                            };
17410    
17411                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H, args);
17412                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H,
17413                                            args);
17414    
17415                                    args = new Object[] {
17416                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17417                                                    Boolean.valueOf(wikiPageModelImpl.getHead())
17418                                            };
17419    
17420                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H, args);
17421                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H,
17422                                            args);
17423                            }
17424    
17425                            if ((wikiPageModelImpl.getColumnBitmask() &
17426                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P.getColumnBitmask()) != 0) {
17427                                    Object[] args = new Object[] {
17428                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17429                                                    
17430                                                    wikiPageModelImpl.getOriginalParentTitle()
17431                                            };
17432    
17433                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_P, args);
17434                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P,
17435                                            args);
17436    
17437                                    args = new Object[] {
17438                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17439                                                    
17440                                                    wikiPageModelImpl.getParentTitle()
17441                                            };
17442    
17443                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_P, args);
17444                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P,
17445                                            args);
17446                            }
17447    
17448                            if ((wikiPageModelImpl.getColumnBitmask() &
17449                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R.getColumnBitmask()) != 0) {
17450                                    Object[] args = new Object[] {
17451                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17452                                                    
17453                                                    wikiPageModelImpl.getOriginalRedirectTitle()
17454                                            };
17455    
17456                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_R, args);
17457                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R,
17458                                            args);
17459    
17460                                    args = new Object[] {
17461                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17462                                                    
17463                                                    wikiPageModelImpl.getRedirectTitle()
17464                                            };
17465    
17466                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_R, args);
17467                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R,
17468                                            args);
17469                            }
17470    
17471                            if ((wikiPageModelImpl.getColumnBitmask() &
17472                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S.getColumnBitmask()) != 0) {
17473                                    Object[] args = new Object[] {
17474                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17475                                                    Integer.valueOf(wikiPageModelImpl.getOriginalStatus())
17476                                            };
17477    
17478                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_S, args);
17479                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S,
17480                                            args);
17481    
17482                                    args = new Object[] {
17483                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17484                                                    Integer.valueOf(wikiPageModelImpl.getStatus())
17485                                            };
17486    
17487                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_S, args);
17488                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S,
17489                                            args);
17490                            }
17491    
17492                            if ((wikiPageModelImpl.getColumnBitmask() &
17493                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H.getColumnBitmask()) != 0) {
17494                                    Object[] args = new Object[] {
17495                                                    Long.valueOf(wikiPageModelImpl.getOriginalResourcePrimKey()),
17496                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17497                                                    Boolean.valueOf(wikiPageModelImpl.getOriginalHead())
17498                                            };
17499    
17500                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_H, args);
17501                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H,
17502                                            args);
17503    
17504                                    args = new Object[] {
17505                                                    Long.valueOf(wikiPageModelImpl.getResourcePrimKey()),
17506                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17507                                                    Boolean.valueOf(wikiPageModelImpl.getHead())
17508                                            };
17509    
17510                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_H, args);
17511                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H,
17512                                            args);
17513                            }
17514    
17515                            if ((wikiPageModelImpl.getColumnBitmask() &
17516                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S.getColumnBitmask()) != 0) {
17517                                    Object[] args = new Object[] {
17518                                                    Long.valueOf(wikiPageModelImpl.getOriginalResourcePrimKey()),
17519                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17520                                                    Integer.valueOf(wikiPageModelImpl.getOriginalStatus())
17521                                            };
17522    
17523                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_S, args);
17524                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S,
17525                                            args);
17526    
17527                                    args = new Object[] {
17528                                                    Long.valueOf(wikiPageModelImpl.getResourcePrimKey()),
17529                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17530                                                    Integer.valueOf(wikiPageModelImpl.getStatus())
17531                                            };
17532    
17533                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_S, args);
17534                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S,
17535                                            args);
17536                            }
17537    
17538                            if ((wikiPageModelImpl.getColumnBitmask() &
17539                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H.getColumnBitmask()) != 0) {
17540                                    Object[] args = new Object[] {
17541                                                    Long.valueOf(wikiPageModelImpl.getOriginalGroupId()),
17542                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17543                                                    Boolean.valueOf(wikiPageModelImpl.getOriginalHead())
17544                                            };
17545    
17546                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H, args);
17547                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H,
17548                                            args);
17549    
17550                                    args = new Object[] {
17551                                                    Long.valueOf(wikiPageModelImpl.getGroupId()),
17552                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17553                                                    Boolean.valueOf(wikiPageModelImpl.getHead())
17554                                            };
17555    
17556                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H, args);
17557                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H,
17558                                            args);
17559                            }
17560    
17561                            if ((wikiPageModelImpl.getColumnBitmask() &
17562                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S.getColumnBitmask()) != 0) {
17563                                    Object[] args = new Object[] {
17564                                                    Long.valueOf(wikiPageModelImpl.getOriginalGroupId()),
17565                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17566                                                    Integer.valueOf(wikiPageModelImpl.getOriginalStatus())
17567                                            };
17568    
17569                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_S, args);
17570                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S,
17571                                            args);
17572    
17573                                    args = new Object[] {
17574                                                    Long.valueOf(wikiPageModelImpl.getGroupId()),
17575                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17576                                                    Integer.valueOf(wikiPageModelImpl.getStatus())
17577                                            };
17578    
17579                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_S, args);
17580                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S,
17581                                            args);
17582                            }
17583    
17584                            if ((wikiPageModelImpl.getColumnBitmask() &
17585                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S.getColumnBitmask()) != 0) {
17586                                    Object[] args = new Object[] {
17587                                                    Long.valueOf(wikiPageModelImpl.getOriginalUserId()),
17588                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17589                                                    Integer.valueOf(wikiPageModelImpl.getOriginalStatus())
17590                                            };
17591    
17592                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_N_S, args);
17593                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S,
17594                                            args);
17595    
17596                                    args = new Object[] {
17597                                                    Long.valueOf(wikiPageModelImpl.getUserId()),
17598                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17599                                                    Integer.valueOf(wikiPageModelImpl.getStatus())
17600                                            };
17601    
17602                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_N_S, args);
17603                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S,
17604                                            args);
17605                            }
17606    
17607                            if ((wikiPageModelImpl.getColumnBitmask() &
17608                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H.getColumnBitmask()) != 0) {
17609                                    Object[] args = new Object[] {
17610                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17611                                                    
17612                                                    wikiPageModelImpl.getOriginalTitle(),
17613                                                    Boolean.valueOf(wikiPageModelImpl.getOriginalHead())
17614                                            };
17615    
17616                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_H, args);
17617                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H,
17618                                            args);
17619    
17620                                    args = new Object[] {
17621                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17622                                                    
17623                                                    wikiPageModelImpl.getTitle(),
17624                                                    Boolean.valueOf(wikiPageModelImpl.getHead())
17625                                            };
17626    
17627                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_H, args);
17628                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H,
17629                                            args);
17630                            }
17631    
17632                            if ((wikiPageModelImpl.getColumnBitmask() &
17633                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S.getColumnBitmask()) != 0) {
17634                                    Object[] args = new Object[] {
17635                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17636                                                    
17637                                                    wikiPageModelImpl.getOriginalTitle(),
17638                                                    Integer.valueOf(wikiPageModelImpl.getOriginalStatus())
17639                                            };
17640    
17641                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_S, args);
17642                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S,
17643                                            args);
17644    
17645                                    args = new Object[] {
17646                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17647                                                    
17648                                                    wikiPageModelImpl.getTitle(),
17649                                                    Integer.valueOf(wikiPageModelImpl.getStatus())
17650                                            };
17651    
17652                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_S, args);
17653                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S,
17654                                            args);
17655                            }
17656    
17657                            if ((wikiPageModelImpl.getColumnBitmask() &
17658                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P.getColumnBitmask()) != 0) {
17659                                    Object[] args = new Object[] {
17660                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17661                                                    Boolean.valueOf(wikiPageModelImpl.getOriginalHead()),
17662                                                    
17663                                                    wikiPageModelImpl.getOriginalParentTitle()
17664                                            };
17665    
17666                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P, args);
17667                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P,
17668                                            args);
17669    
17670                                    args = new Object[] {
17671                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17672                                                    Boolean.valueOf(wikiPageModelImpl.getHead()),
17673                                                    
17674                                                    wikiPageModelImpl.getParentTitle()
17675                                            };
17676    
17677                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P, args);
17678                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P,
17679                                            args);
17680                            }
17681    
17682                            if ((wikiPageModelImpl.getColumnBitmask() &
17683                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S.getColumnBitmask()) != 0) {
17684                                    Object[] args = new Object[] {
17685                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17686                                                    Boolean.valueOf(wikiPageModelImpl.getOriginalHead()),
17687                                                    Integer.valueOf(wikiPageModelImpl.getOriginalStatus())
17688                                            };
17689    
17690                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_S, args);
17691                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S,
17692                                            args);
17693    
17694                                    args = new Object[] {
17695                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17696                                                    Boolean.valueOf(wikiPageModelImpl.getHead()),
17697                                                    Integer.valueOf(wikiPageModelImpl.getStatus())
17698                                            };
17699    
17700                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_S, args);
17701                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S,
17702                                            args);
17703                            }
17704    
17705                            if ((wikiPageModelImpl.getColumnBitmask() &
17706                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S.getColumnBitmask()) != 0) {
17707                                    Object[] args = new Object[] {
17708                                                    Long.valueOf(wikiPageModelImpl.getOriginalGroupId()),
17709                                                    Long.valueOf(wikiPageModelImpl.getOriginalUserId()),
17710                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17711                                                    Integer.valueOf(wikiPageModelImpl.getOriginalStatus())
17712                                            };
17713    
17714                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N_S, args);
17715                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S,
17716                                            args);
17717    
17718                                    args = new Object[] {
17719                                                    Long.valueOf(wikiPageModelImpl.getGroupId()),
17720                                                    Long.valueOf(wikiPageModelImpl.getUserId()),
17721                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17722                                                    Integer.valueOf(wikiPageModelImpl.getStatus())
17723                                            };
17724    
17725                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N_S, args);
17726                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S,
17727                                            args);
17728                            }
17729    
17730                            if ((wikiPageModelImpl.getColumnBitmask() &
17731                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H.getColumnBitmask()) != 0) {
17732                                    Object[] args = new Object[] {
17733                                                    Long.valueOf(wikiPageModelImpl.getOriginalGroupId()),
17734                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17735                                                    
17736                                                    wikiPageModelImpl.getOriginalTitle(),
17737                                                    Boolean.valueOf(wikiPageModelImpl.getOriginalHead())
17738                                            };
17739    
17740                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_H, args);
17741                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H,
17742                                            args);
17743    
17744                                    args = new Object[] {
17745                                                    Long.valueOf(wikiPageModelImpl.getGroupId()),
17746                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17747                                                    
17748                                                    wikiPageModelImpl.getTitle(),
17749                                                    Boolean.valueOf(wikiPageModelImpl.getHead())
17750                                            };
17751    
17752                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_H, args);
17753                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H,
17754                                            args);
17755                            }
17756    
17757                            if ((wikiPageModelImpl.getColumnBitmask() &
17758                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S.getColumnBitmask()) != 0) {
17759                                    Object[] args = new Object[] {
17760                                                    Long.valueOf(wikiPageModelImpl.getOriginalGroupId()),
17761                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17762                                                    Boolean.valueOf(wikiPageModelImpl.getOriginalHead()),
17763                                                    Integer.valueOf(wikiPageModelImpl.getOriginalStatus())
17764                                            };
17765    
17766                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_S, args);
17767                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S,
17768                                            args);
17769    
17770                                    args = new Object[] {
17771                                                    Long.valueOf(wikiPageModelImpl.getGroupId()),
17772                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17773                                                    Boolean.valueOf(wikiPageModelImpl.getHead()),
17774                                                    Integer.valueOf(wikiPageModelImpl.getStatus())
17775                                            };
17776    
17777                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_S, args);
17778                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S,
17779                                            args);
17780                            }
17781    
17782                            if ((wikiPageModelImpl.getColumnBitmask() &
17783                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S.getColumnBitmask()) != 0) {
17784                                    Object[] args = new Object[] {
17785                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17786                                                    Boolean.valueOf(wikiPageModelImpl.getOriginalHead()),
17787                                                    
17788                                                    wikiPageModelImpl.getOriginalParentTitle(),
17789                                                    Integer.valueOf(wikiPageModelImpl.getOriginalStatus())
17790                                            };
17791    
17792                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P_S, args);
17793                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S,
17794                                            args);
17795    
17796                                    args = new Object[] {
17797                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17798                                                    Boolean.valueOf(wikiPageModelImpl.getHead()),
17799                                                    
17800                                                    wikiPageModelImpl.getParentTitle(),
17801                                                    Integer.valueOf(wikiPageModelImpl.getStatus())
17802                                            };
17803    
17804                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P_S, args);
17805                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S,
17806                                            args);
17807                            }
17808    
17809                            if ((wikiPageModelImpl.getColumnBitmask() &
17810                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S.getColumnBitmask()) != 0) {
17811                                    Object[] args = new Object[] {
17812                                                    Long.valueOf(wikiPageModelImpl.getOriginalGroupId()),
17813                                                    Long.valueOf(wikiPageModelImpl.getOriginalNodeId()),
17814                                                    Boolean.valueOf(wikiPageModelImpl.getOriginalHead()),
17815                                                    
17816                                                    wikiPageModelImpl.getOriginalParentTitle(),
17817                                                    Integer.valueOf(wikiPageModelImpl.getOriginalStatus())
17818                                            };
17819    
17820                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_P_S,
17821                                            args);
17822                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S,
17823                                            args);
17824    
17825                                    args = new Object[] {
17826                                                    Long.valueOf(wikiPageModelImpl.getGroupId()),
17827                                                    Long.valueOf(wikiPageModelImpl.getNodeId()),
17828                                                    Boolean.valueOf(wikiPageModelImpl.getHead()),
17829                                                    
17830                                                    wikiPageModelImpl.getParentTitle(),
17831                                                    Integer.valueOf(wikiPageModelImpl.getStatus())
17832                                            };
17833    
17834                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_P_S,
17835                                            args);
17836                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S,
17837                                            args);
17838                            }
17839                    }
17840    
17841                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17842                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
17843    
17844                    clearUniqueFindersCache(wikiPage);
17845                    cacheUniqueFindersCache(wikiPage);
17846    
17847                    return wikiPage;
17848            }
17849    
17850            protected WikiPage toUnwrappedModel(WikiPage wikiPage) {
17851                    if (wikiPage instanceof WikiPageImpl) {
17852                            return wikiPage;
17853                    }
17854    
17855                    WikiPageImpl wikiPageImpl = new WikiPageImpl();
17856    
17857                    wikiPageImpl.setNew(wikiPage.isNew());
17858                    wikiPageImpl.setPrimaryKey(wikiPage.getPrimaryKey());
17859    
17860                    wikiPageImpl.setUuid(wikiPage.getUuid());
17861                    wikiPageImpl.setPageId(wikiPage.getPageId());
17862                    wikiPageImpl.setResourcePrimKey(wikiPage.getResourcePrimKey());
17863                    wikiPageImpl.setGroupId(wikiPage.getGroupId());
17864                    wikiPageImpl.setCompanyId(wikiPage.getCompanyId());
17865                    wikiPageImpl.setUserId(wikiPage.getUserId());
17866                    wikiPageImpl.setUserName(wikiPage.getUserName());
17867                    wikiPageImpl.setCreateDate(wikiPage.getCreateDate());
17868                    wikiPageImpl.setModifiedDate(wikiPage.getModifiedDate());
17869                    wikiPageImpl.setNodeId(wikiPage.getNodeId());
17870                    wikiPageImpl.setTitle(wikiPage.getTitle());
17871                    wikiPageImpl.setVersion(wikiPage.getVersion());
17872                    wikiPageImpl.setMinorEdit(wikiPage.isMinorEdit());
17873                    wikiPageImpl.setContent(wikiPage.getContent());
17874                    wikiPageImpl.setSummary(wikiPage.getSummary());
17875                    wikiPageImpl.setFormat(wikiPage.getFormat());
17876                    wikiPageImpl.setHead(wikiPage.isHead());
17877                    wikiPageImpl.setParentTitle(wikiPage.getParentTitle());
17878                    wikiPageImpl.setRedirectTitle(wikiPage.getRedirectTitle());
17879                    wikiPageImpl.setStatus(wikiPage.getStatus());
17880                    wikiPageImpl.setStatusByUserId(wikiPage.getStatusByUserId());
17881                    wikiPageImpl.setStatusByUserName(wikiPage.getStatusByUserName());
17882                    wikiPageImpl.setStatusDate(wikiPage.getStatusDate());
17883    
17884                    return wikiPageImpl;
17885            }
17886    
17887            /**
17888             * Returns the wiki page with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
17889             *
17890             * @param primaryKey the primary key of the wiki page
17891             * @return the wiki page
17892             * @throws com.liferay.portal.NoSuchModelException if a wiki page with the primary key could not be found
17893             * @throws SystemException if a system exception occurred
17894             */
17895            @Override
17896            public WikiPage findByPrimaryKey(Serializable primaryKey)
17897                    throws NoSuchModelException, SystemException {
17898                    return findByPrimaryKey(((Long)primaryKey).longValue());
17899            }
17900    
17901            /**
17902             * Returns the wiki page with the primary key or throws a {@link com.liferay.portlet.wiki.NoSuchPageException} if it could not be found.
17903             *
17904             * @param pageId the primary key of the wiki page
17905             * @return the wiki page
17906             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17907             * @throws SystemException if a system exception occurred
17908             */
17909            public WikiPage findByPrimaryKey(long pageId)
17910                    throws NoSuchPageException, SystemException {
17911                    WikiPage wikiPage = fetchByPrimaryKey(pageId);
17912    
17913                    if (wikiPage == null) {
17914                            if (_log.isWarnEnabled()) {
17915                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + pageId);
17916                            }
17917    
17918                            throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
17919                                    pageId);
17920                    }
17921    
17922                    return wikiPage;
17923            }
17924    
17925            /**
17926             * Returns the wiki page with the primary key or returns <code>null</code> if it could not be found.
17927             *
17928             * @param primaryKey the primary key of the wiki page
17929             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
17930             * @throws SystemException if a system exception occurred
17931             */
17932            @Override
17933            public WikiPage fetchByPrimaryKey(Serializable primaryKey)
17934                    throws SystemException {
17935                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
17936            }
17937    
17938            /**
17939             * Returns the wiki page with the primary key or returns <code>null</code> if it could not be found.
17940             *
17941             * @param pageId the primary key of the wiki page
17942             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
17943             * @throws SystemException if a system exception occurred
17944             */
17945            public WikiPage fetchByPrimaryKey(long pageId) throws SystemException {
17946                    WikiPage wikiPage = (WikiPage)EntityCacheUtil.getResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17947                                    WikiPageImpl.class, pageId);
17948    
17949                    if (wikiPage == _nullWikiPage) {
17950                            return null;
17951                    }
17952    
17953                    if (wikiPage == null) {
17954                            Session session = null;
17955    
17956                            try {
17957                                    session = openSession();
17958    
17959                                    wikiPage = (WikiPage)session.get(WikiPageImpl.class,
17960                                                    Long.valueOf(pageId));
17961    
17962                                    if (wikiPage != null) {
17963                                            cacheResult(wikiPage);
17964                                    }
17965                                    else {
17966                                            EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17967                                                    WikiPageImpl.class, pageId, _nullWikiPage);
17968                                    }
17969                            }
17970                            catch (Exception e) {
17971                                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17972                                            WikiPageImpl.class, pageId);
17973    
17974                                    throw processException(e);
17975                            }
17976                            finally {
17977                                    closeSession(session);
17978                            }
17979                    }
17980    
17981                    return wikiPage;
17982            }
17983    
17984            /**
17985             * Returns all the wiki pages.
17986             *
17987             * @return the wiki pages
17988             * @throws SystemException if a system exception occurred
17989             */
17990            public List<WikiPage> findAll() throws SystemException {
17991                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17992            }
17993    
17994            /**
17995             * Returns a range of all the wiki pages.
17996             *
17997             * <p>
17998             * 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.
17999             * </p>
18000             *
18001             * @param start the lower bound of the range of wiki pages
18002             * @param end the upper bound of the range of wiki pages (not inclusive)
18003             * @return the range of wiki pages
18004             * @throws SystemException if a system exception occurred
18005             */
18006            public List<WikiPage> findAll(int start, int end) throws SystemException {
18007                    return findAll(start, end, null);
18008            }
18009    
18010            /**
18011             * Returns an ordered range of all the wiki pages.
18012             *
18013             * <p>
18014             * 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.
18015             * </p>
18016             *
18017             * @param start the lower bound of the range of wiki pages
18018             * @param end the upper bound of the range of wiki pages (not inclusive)
18019             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18020             * @return the ordered range of wiki pages
18021             * @throws SystemException if a system exception occurred
18022             */
18023            public List<WikiPage> findAll(int start, int end,
18024                    OrderByComparator orderByComparator) throws SystemException {
18025                    boolean pagination = true;
18026                    FinderPath finderPath = null;
18027                    Object[] finderArgs = null;
18028    
18029                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18030                                    (orderByComparator == null)) {
18031                            pagination = false;
18032                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
18033                            finderArgs = FINDER_ARGS_EMPTY;
18034                    }
18035                    else {
18036                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
18037                            finderArgs = new Object[] { start, end, orderByComparator };
18038                    }
18039    
18040                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
18041                                    finderArgs, this);
18042    
18043                    if (list == null) {
18044                            StringBundler query = null;
18045                            String sql = null;
18046    
18047                            if (orderByComparator != null) {
18048                                    query = new StringBundler(2 +
18049                                                    (orderByComparator.getOrderByFields().length * 3));
18050    
18051                                    query.append(_SQL_SELECT_WIKIPAGE);
18052    
18053                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18054                                            orderByComparator);
18055    
18056                                    sql = query.toString();
18057                            }
18058                            else {
18059                                    sql = _SQL_SELECT_WIKIPAGE;
18060    
18061                                    if (pagination) {
18062                                            sql = sql.concat(WikiPageModelImpl.ORDER_BY_JPQL);
18063                                    }
18064                            }
18065    
18066                            Session session = null;
18067    
18068                            try {
18069                                    session = openSession();
18070    
18071                                    Query q = session.createQuery(sql);
18072    
18073                                    if (!pagination) {
18074                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
18075                                                            start, end, false);
18076    
18077                                            Collections.sort(list);
18078    
18079                                            list = new UnmodifiableList<WikiPage>(list);
18080                                    }
18081                                    else {
18082                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
18083                                                            start, end);
18084                                    }
18085    
18086                                    cacheResult(list);
18087    
18088                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
18089                            }
18090                            catch (Exception e) {
18091                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18092    
18093                                    throw processException(e);
18094                            }
18095                            finally {
18096                                    closeSession(session);
18097                            }
18098                    }
18099    
18100                    return list;
18101            }
18102    
18103            /**
18104             * Removes all the wiki pages from the database.
18105             *
18106             * @throws SystemException if a system exception occurred
18107             */
18108            public void removeAll() throws SystemException {
18109                    for (WikiPage wikiPage : findAll()) {
18110                            remove(wikiPage);
18111                    }
18112            }
18113    
18114            /**
18115             * Returns the number of wiki pages.
18116             *
18117             * @return the number of wiki pages
18118             * @throws SystemException if a system exception occurred
18119             */
18120            public int countAll() throws SystemException {
18121                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
18122                                    FINDER_ARGS_EMPTY, this);
18123    
18124                    if (count == null) {
18125                            Session session = null;
18126    
18127                            try {
18128                                    session = openSession();
18129    
18130                                    Query q = session.createQuery(_SQL_COUNT_WIKIPAGE);
18131    
18132                                    count = (Long)q.uniqueResult();
18133    
18134                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
18135                                            FINDER_ARGS_EMPTY, count);
18136                            }
18137                            catch (Exception e) {
18138                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
18139                                            FINDER_ARGS_EMPTY);
18140    
18141                                    throw processException(e);
18142                            }
18143                            finally {
18144                                    closeSession(session);
18145                            }
18146                    }
18147    
18148                    return count.intValue();
18149            }
18150    
18151            /**
18152             * Initializes the wiki page persistence.
18153             */
18154            public void afterPropertiesSet() {
18155                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
18156                                            com.liferay.portal.util.PropsUtil.get(
18157                                                    "value.object.listener.com.liferay.portlet.wiki.model.WikiPage")));
18158    
18159                    if (listenerClassNames.length > 0) {
18160                            try {
18161                                    List<ModelListener<WikiPage>> listenersList = new ArrayList<ModelListener<WikiPage>>();
18162    
18163                                    for (String listenerClassName : listenerClassNames) {
18164                                            listenersList.add((ModelListener<WikiPage>)InstanceFactory.newInstance(
18165                                                            listenerClassName));
18166                                    }
18167    
18168                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
18169                            }
18170                            catch (Exception e) {
18171                                    _log.error(e);
18172                            }
18173                    }
18174            }
18175    
18176            public void destroy() {
18177                    EntityCacheUtil.removeCache(WikiPageImpl.class.getName());
18178                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
18179                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18180                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18181            }
18182    
18183            private static final String _SQL_SELECT_WIKIPAGE = "SELECT wikiPage FROM WikiPage wikiPage";
18184            private static final String _SQL_SELECT_WIKIPAGE_WHERE = "SELECT wikiPage FROM WikiPage wikiPage WHERE ";
18185            private static final String _SQL_COUNT_WIKIPAGE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage";
18186            private static final String _SQL_COUNT_WIKIPAGE_WHERE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage WHERE ";
18187            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "wikiPage.resourcePrimKey";
18188            private static final String _FILTER_SQL_SELECT_WIKIPAGE_WHERE = "SELECT DISTINCT {wikiPage.*} FROM WikiPage wikiPage WHERE ";
18189            private static final String _FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1 =
18190                    "SELECT {WikiPage.*} FROM (SELECT DISTINCT wikiPage.pageId FROM WikiPage wikiPage WHERE ";
18191            private static final String _FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2 =
18192                    ") TEMP_TABLE INNER JOIN WikiPage ON TEMP_TABLE.pageId = WikiPage.pageId";
18193            private static final String _FILTER_SQL_COUNT_WIKIPAGE_WHERE = "SELECT COUNT(DISTINCT wikiPage.pageId) AS COUNT_VALUE FROM WikiPage wikiPage WHERE ";
18194            private static final String _FILTER_ENTITY_ALIAS = "wikiPage";
18195            private static final String _FILTER_ENTITY_TABLE = "WikiPage";
18196            private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPage.";
18197            private static final String _ORDER_BY_ENTITY_TABLE = "WikiPage.";
18198            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPage exists with the primary key ";
18199            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPage exists with the key {";
18200            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
18201            private static Log _log = LogFactoryUtil.getLog(WikiPagePersistenceImpl.class);
18202            private static WikiPage _nullWikiPage = new WikiPageImpl() {
18203                            @Override
18204                            public Object clone() {
18205                                    return this;
18206                            }
18207    
18208                            @Override
18209                            public CacheModel<WikiPage> toCacheModel() {
18210                                    return _nullWikiPageCacheModel;
18211                            }
18212                    };
18213    
18214            private static CacheModel<WikiPage> _nullWikiPageCacheModel = new CacheModel<WikiPage>() {
18215                            public WikiPage toEntityModel() {
18216                                    return _nullWikiPage;
18217                            }
18218                    };
18219    }