001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.wiki.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.SQLQuery;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.sanitizer.Sanitizer;
030    import com.liferay.portal.kernel.sanitizer.SanitizerException;
031    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
032    import com.liferay.portal.kernel.util.ContentTypes;
033    import com.liferay.portal.kernel.util.GetterUtil;
034    import com.liferay.portal.kernel.util.InstanceFactory;
035    import com.liferay.portal.kernel.util.OrderByComparator;
036    import com.liferay.portal.kernel.util.SetUtil;
037    import com.liferay.portal.kernel.util.StringBundler;
038    import com.liferay.portal.kernel.util.StringPool;
039    import com.liferay.portal.kernel.util.StringUtil;
040    import com.liferay.portal.kernel.util.UnmodifiableList;
041    import com.liferay.portal.kernel.util.Validator;
042    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
043    import com.liferay.portal.model.CacheModel;
044    import com.liferay.portal.model.ModelListener;
045    import com.liferay.portal.security.auth.PrincipalThreadLocal;
046    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.wiki.NoSuchPageException;
050    import com.liferay.portlet.wiki.model.WikiPage;
051    import com.liferay.portlet.wiki.model.impl.WikiPageImpl;
052    import com.liferay.portlet.wiki.model.impl.WikiPageModelImpl;
053    
054    import java.io.Serializable;
055    
056    import java.util.ArrayList;
057    import java.util.Collections;
058    import java.util.List;
059    import java.util.Set;
060    
061    /**
062     * The persistence implementation for the wiki page service.
063     *
064     * <p>
065     * Caching information and settings can be found in <code>portal.properties</code>
066     * </p>
067     *
068     * @author Brian Wing Shun Chan
069     * @see WikiPagePersistence
070     * @see WikiPageUtil
071     * @generated
072     */
073    public class WikiPagePersistenceImpl extends BasePersistenceImpl<WikiPage>
074            implements WikiPagePersistence {
075            /*
076             * NOTE FOR DEVELOPERS:
077             *
078             * Never modify or reference this class directly. Always use {@link WikiPageUtil} to access the wiki page persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
079             */
080            public static final String FINDER_CLASS_NAME_ENTITY = WikiPageImpl.class.getName();
081            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List1";
083            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List2";
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
086                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
089                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
092                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
095                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
097                            new String[] {
098                                    String.class.getName(),
099                                    
100                            Integer.class.getName(), Integer.class.getName(),
101                                    OrderByComparator.class.getName()
102                            });
103            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
104                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
106                            new String[] { String.class.getName() },
107                            WikiPageModelImpl.UUID_COLUMN_BITMASK |
108                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
109                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
110                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
111            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
112                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
114                            new String[] { String.class.getName() });
115    
116            /**
117             * Returns all the wiki pages where uuid = &#63;.
118             *
119             * @param uuid the uuid
120             * @return the matching wiki pages
121             * @throws SystemException if a system exception occurred
122             */
123            @Override
124            public List<WikiPage> findByUuid(String uuid) throws SystemException {
125                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
126            }
127    
128            /**
129             * Returns a range of all the wiki pages where uuid = &#63;.
130             *
131             * <p>
132             * 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.
133             * </p>
134             *
135             * @param uuid the uuid
136             * @param start the lower bound of the range of wiki pages
137             * @param end the upper bound of the range of wiki pages (not inclusive)
138             * @return the range of matching wiki pages
139             * @throws SystemException if a system exception occurred
140             */
141            @Override
142            public List<WikiPage> findByUuid(String uuid, int start, int end)
143                    throws SystemException {
144                    return findByUuid(uuid, start, end, null);
145            }
146    
147            /**
148             * Returns an ordered range of all the wiki pages where uuid = &#63;.
149             *
150             * <p>
151             * 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.
152             * </p>
153             *
154             * @param uuid the uuid
155             * @param start the lower bound of the range of wiki pages
156             * @param end the upper bound of the range of wiki pages (not inclusive)
157             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
158             * @return the ordered range of matching wiki pages
159             * @throws SystemException if a system exception occurred
160             */
161            @Override
162            public List<WikiPage> findByUuid(String uuid, int start, int end,
163                    OrderByComparator orderByComparator) throws SystemException {
164                    boolean pagination = true;
165                    FinderPath finderPath = null;
166                    Object[] finderArgs = null;
167    
168                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
169                                    (orderByComparator == null)) {
170                            pagination = false;
171                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
172                            finderArgs = new Object[] { uuid };
173                    }
174                    else {
175                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
176                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
177                    }
178    
179                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
180                                    finderArgs, this);
181    
182                    if ((list != null) && !list.isEmpty()) {
183                            for (WikiPage wikiPage : list) {
184                                    if (!Validator.equals(uuid, wikiPage.getUuid())) {
185                                            list = null;
186    
187                                            break;
188                                    }
189                            }
190                    }
191    
192                    if (list == null) {
193                            StringBundler query = null;
194    
195                            if (orderByComparator != null) {
196                                    query = new StringBundler(3 +
197                                                    (orderByComparator.getOrderByFields().length * 3));
198                            }
199                            else {
200                                    query = new StringBundler(3);
201                            }
202    
203                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
204    
205                            boolean bindUuid = false;
206    
207                            if (uuid == null) {
208                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
209                            }
210                            else if (uuid.equals(StringPool.BLANK)) {
211                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
212                            }
213                            else {
214                                    bindUuid = true;
215    
216                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
217                            }
218    
219                            if (orderByComparator != null) {
220                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
221                                            orderByComparator);
222                            }
223                            else
224                             if (pagination) {
225                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
226                            }
227    
228                            String sql = query.toString();
229    
230                            Session session = null;
231    
232                            try {
233                                    session = openSession();
234    
235                                    Query q = session.createQuery(sql);
236    
237                                    QueryPos qPos = QueryPos.getInstance(q);
238    
239                                    if (bindUuid) {
240                                            qPos.add(uuid);
241                                    }
242    
243                                    if (!pagination) {
244                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
245                                                            start, end, false);
246    
247                                            Collections.sort(list);
248    
249                                            list = new UnmodifiableList<WikiPage>(list);
250                                    }
251                                    else {
252                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
253                                                            start, end);
254                                    }
255    
256                                    cacheResult(list);
257    
258                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
259                            }
260                            catch (Exception e) {
261                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
262    
263                                    throw processException(e);
264                            }
265                            finally {
266                                    closeSession(session);
267                            }
268                    }
269    
270                    return list;
271            }
272    
273            /**
274             * Returns the first wiki page in the ordered set where uuid = &#63;.
275             *
276             * @param uuid the uuid
277             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
278             * @return the first matching wiki page
279             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
280             * @throws SystemException if a system exception occurred
281             */
282            @Override
283            public WikiPage findByUuid_First(String uuid,
284                    OrderByComparator orderByComparator)
285                    throws NoSuchPageException, SystemException {
286                    WikiPage wikiPage = fetchByUuid_First(uuid, orderByComparator);
287    
288                    if (wikiPage != null) {
289                            return wikiPage;
290                    }
291    
292                    StringBundler msg = new StringBundler(4);
293    
294                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
295    
296                    msg.append("uuid=");
297                    msg.append(uuid);
298    
299                    msg.append(StringPool.CLOSE_CURLY_BRACE);
300    
301                    throw new NoSuchPageException(msg.toString());
302            }
303    
304            /**
305             * Returns the first wiki page in the ordered set where uuid = &#63;.
306             *
307             * @param uuid the uuid
308             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
309             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
310             * @throws SystemException if a system exception occurred
311             */
312            @Override
313            public WikiPage fetchByUuid_First(String uuid,
314                    OrderByComparator orderByComparator) throws SystemException {
315                    List<WikiPage> list = findByUuid(uuid, 0, 1, orderByComparator);
316    
317                    if (!list.isEmpty()) {
318                            return list.get(0);
319                    }
320    
321                    return null;
322            }
323    
324            /**
325             * Returns the last wiki page in the ordered set where uuid = &#63;.
326             *
327             * @param uuid the uuid
328             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
329             * @return the last matching wiki page
330             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
331             * @throws SystemException if a system exception occurred
332             */
333            @Override
334            public WikiPage findByUuid_Last(String uuid,
335                    OrderByComparator orderByComparator)
336                    throws NoSuchPageException, SystemException {
337                    WikiPage wikiPage = fetchByUuid_Last(uuid, orderByComparator);
338    
339                    if (wikiPage != null) {
340                            return wikiPage;
341                    }
342    
343                    StringBundler msg = new StringBundler(4);
344    
345                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
346    
347                    msg.append("uuid=");
348                    msg.append(uuid);
349    
350                    msg.append(StringPool.CLOSE_CURLY_BRACE);
351    
352                    throw new NoSuchPageException(msg.toString());
353            }
354    
355            /**
356             * Returns the last wiki page in the ordered set where uuid = &#63;.
357             *
358             * @param uuid the uuid
359             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
360             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
361             * @throws SystemException if a system exception occurred
362             */
363            @Override
364            public WikiPage fetchByUuid_Last(String uuid,
365                    OrderByComparator orderByComparator) throws SystemException {
366                    int count = countByUuid(uuid);
367    
368                    if (count == 0) {
369                            return null;
370                    }
371    
372                    List<WikiPage> list = findByUuid(uuid, count - 1, count,
373                                    orderByComparator);
374    
375                    if (!list.isEmpty()) {
376                            return list.get(0);
377                    }
378    
379                    return null;
380            }
381    
382            /**
383             * Returns the wiki pages before and after the current wiki page in the ordered set where uuid = &#63;.
384             *
385             * @param pageId the primary key of the current wiki page
386             * @param uuid the uuid
387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
388             * @return the previous, current, and next wiki page
389             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
390             * @throws SystemException if a system exception occurred
391             */
392            @Override
393            public WikiPage[] findByUuid_PrevAndNext(long pageId, String uuid,
394                    OrderByComparator orderByComparator)
395                    throws NoSuchPageException, SystemException {
396                    WikiPage wikiPage = findByPrimaryKey(pageId);
397    
398                    Session session = null;
399    
400                    try {
401                            session = openSession();
402    
403                            WikiPage[] array = new WikiPageImpl[3];
404    
405                            array[0] = getByUuid_PrevAndNext(session, wikiPage, uuid,
406                                            orderByComparator, true);
407    
408                            array[1] = wikiPage;
409    
410                            array[2] = getByUuid_PrevAndNext(session, wikiPage, uuid,
411                                            orderByComparator, false);
412    
413                            return array;
414                    }
415                    catch (Exception e) {
416                            throw processException(e);
417                    }
418                    finally {
419                            closeSession(session);
420                    }
421            }
422    
423            protected WikiPage getByUuid_PrevAndNext(Session session,
424                    WikiPage wikiPage, String uuid, OrderByComparator orderByComparator,
425                    boolean previous) {
426                    StringBundler query = null;
427    
428                    if (orderByComparator != null) {
429                            query = new StringBundler(6 +
430                                            (orderByComparator.getOrderByFields().length * 6));
431                    }
432                    else {
433                            query = new StringBundler(3);
434                    }
435    
436                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
437    
438                    boolean bindUuid = false;
439    
440                    if (uuid == null) {
441                            query.append(_FINDER_COLUMN_UUID_UUID_1);
442                    }
443                    else if (uuid.equals(StringPool.BLANK)) {
444                            query.append(_FINDER_COLUMN_UUID_UUID_3);
445                    }
446                    else {
447                            bindUuid = true;
448    
449                            query.append(_FINDER_COLUMN_UUID_UUID_2);
450                    }
451    
452                    if (orderByComparator != null) {
453                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
454    
455                            if (orderByConditionFields.length > 0) {
456                                    query.append(WHERE_AND);
457                            }
458    
459                            for (int i = 0; i < orderByConditionFields.length; i++) {
460                                    query.append(_ORDER_BY_ENTITY_ALIAS);
461                                    query.append(orderByConditionFields[i]);
462    
463                                    if ((i + 1) < orderByConditionFields.length) {
464                                            if (orderByComparator.isAscending() ^ previous) {
465                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
466                                            }
467                                            else {
468                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
469                                            }
470                                    }
471                                    else {
472                                            if (orderByComparator.isAscending() ^ previous) {
473                                                    query.append(WHERE_GREATER_THAN);
474                                            }
475                                            else {
476                                                    query.append(WHERE_LESSER_THAN);
477                                            }
478                                    }
479                            }
480    
481                            query.append(ORDER_BY_CLAUSE);
482    
483                            String[] orderByFields = orderByComparator.getOrderByFields();
484    
485                            for (int i = 0; i < orderByFields.length; i++) {
486                                    query.append(_ORDER_BY_ENTITY_ALIAS);
487                                    query.append(orderByFields[i]);
488    
489                                    if ((i + 1) < orderByFields.length) {
490                                            if (orderByComparator.isAscending() ^ previous) {
491                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
492                                            }
493                                            else {
494                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
495                                            }
496                                    }
497                                    else {
498                                            if (orderByComparator.isAscending() ^ previous) {
499                                                    query.append(ORDER_BY_ASC);
500                                            }
501                                            else {
502                                                    query.append(ORDER_BY_DESC);
503                                            }
504                                    }
505                            }
506                    }
507                    else {
508                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
509                    }
510    
511                    String sql = query.toString();
512    
513                    Query q = session.createQuery(sql);
514    
515                    q.setFirstResult(0);
516                    q.setMaxResults(2);
517    
518                    QueryPos qPos = QueryPos.getInstance(q);
519    
520                    if (bindUuid) {
521                            qPos.add(uuid);
522                    }
523    
524                    if (orderByComparator != null) {
525                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
526    
527                            for (Object value : values) {
528                                    qPos.add(value);
529                            }
530                    }
531    
532                    List<WikiPage> list = q.list();
533    
534                    if (list.size() == 2) {
535                            return list.get(1);
536                    }
537                    else {
538                            return null;
539                    }
540            }
541    
542            /**
543             * Removes all the wiki pages where uuid = &#63; from the database.
544             *
545             * @param uuid the uuid
546             * @throws SystemException if a system exception occurred
547             */
548            @Override
549            public void removeByUuid(String uuid) throws SystemException {
550                    for (WikiPage wikiPage : findByUuid(uuid, QueryUtil.ALL_POS,
551                                    QueryUtil.ALL_POS, null)) {
552                            remove(wikiPage);
553                    }
554            }
555    
556            /**
557             * Returns the number of wiki pages where uuid = &#63;.
558             *
559             * @param uuid the uuid
560             * @return the number of matching wiki pages
561             * @throws SystemException if a system exception occurred
562             */
563            @Override
564            public int countByUuid(String uuid) throws SystemException {
565                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
566    
567                    Object[] finderArgs = new Object[] { uuid };
568    
569                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
570                                    this);
571    
572                    if (count == null) {
573                            StringBundler query = new StringBundler(2);
574    
575                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
576    
577                            boolean bindUuid = false;
578    
579                            if (uuid == null) {
580                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
581                            }
582                            else if (uuid.equals(StringPool.BLANK)) {
583                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
584                            }
585                            else {
586                                    bindUuid = true;
587    
588                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
589                            }
590    
591                            String sql = query.toString();
592    
593                            Session session = null;
594    
595                            try {
596                                    session = openSession();
597    
598                                    Query q = session.createQuery(sql);
599    
600                                    QueryPos qPos = QueryPos.getInstance(q);
601    
602                                    if (bindUuid) {
603                                            qPos.add(uuid);
604                                    }
605    
606                                    count = (Long)q.uniqueResult();
607    
608                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
609                            }
610                            catch (Exception e) {
611                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
612    
613                                    throw processException(e);
614                            }
615                            finally {
616                                    closeSession(session);
617                            }
618                    }
619    
620                    return count.intValue();
621            }
622    
623            private static final String _FINDER_COLUMN_UUID_UUID_1 = "wikiPage.uuid IS NULL";
624            private static final String _FINDER_COLUMN_UUID_UUID_2 = "wikiPage.uuid = ?";
625            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(wikiPage.uuid IS NULL OR wikiPage.uuid = '')";
626            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
627                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
628                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
629                            new String[] { String.class.getName(), Long.class.getName() },
630                            WikiPageModelImpl.UUID_COLUMN_BITMASK |
631                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK);
632            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
633                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
634                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
635                            new String[] { String.class.getName(), Long.class.getName() });
636    
637            /**
638             * 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.
639             *
640             * @param uuid the uuid
641             * @param groupId the group ID
642             * @return the matching wiki page
643             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
644             * @throws SystemException if a system exception occurred
645             */
646            @Override
647            public WikiPage findByUUID_G(String uuid, long groupId)
648                    throws NoSuchPageException, SystemException {
649                    WikiPage wikiPage = fetchByUUID_G(uuid, groupId);
650    
651                    if (wikiPage == null) {
652                            StringBundler msg = new StringBundler(6);
653    
654                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
655    
656                            msg.append("uuid=");
657                            msg.append(uuid);
658    
659                            msg.append(", groupId=");
660                            msg.append(groupId);
661    
662                            msg.append(StringPool.CLOSE_CURLY_BRACE);
663    
664                            if (_log.isWarnEnabled()) {
665                                    _log.warn(msg.toString());
666                            }
667    
668                            throw new NoSuchPageException(msg.toString());
669                    }
670    
671                    return wikiPage;
672            }
673    
674            /**
675             * 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.
676             *
677             * @param uuid the uuid
678             * @param groupId the group ID
679             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
680             * @throws SystemException if a system exception occurred
681             */
682            @Override
683            public WikiPage fetchByUUID_G(String uuid, long groupId)
684                    throws SystemException {
685                    return fetchByUUID_G(uuid, groupId, true);
686            }
687    
688            /**
689             * 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.
690             *
691             * @param uuid the uuid
692             * @param groupId the group ID
693             * @param retrieveFromCache whether to use the finder cache
694             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
695             * @throws SystemException if a system exception occurred
696             */
697            @Override
698            public WikiPage fetchByUUID_G(String uuid, long groupId,
699                    boolean retrieveFromCache) throws SystemException {
700                    Object[] finderArgs = new Object[] { uuid, groupId };
701    
702                    Object result = null;
703    
704                    if (retrieveFromCache) {
705                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
706                                            finderArgs, this);
707                    }
708    
709                    if (result instanceof WikiPage) {
710                            WikiPage wikiPage = (WikiPage)result;
711    
712                            if (!Validator.equals(uuid, wikiPage.getUuid()) ||
713                                            (groupId != wikiPage.getGroupId())) {
714                                    result = null;
715                            }
716                    }
717    
718                    if (result == null) {
719                            StringBundler query = new StringBundler(4);
720    
721                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
722    
723                            boolean bindUuid = false;
724    
725                            if (uuid == null) {
726                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
727                            }
728                            else if (uuid.equals(StringPool.BLANK)) {
729                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
730                            }
731                            else {
732                                    bindUuid = true;
733    
734                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
735                            }
736    
737                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
738    
739                            String sql = query.toString();
740    
741                            Session session = null;
742    
743                            try {
744                                    session = openSession();
745    
746                                    Query q = session.createQuery(sql);
747    
748                                    QueryPos qPos = QueryPos.getInstance(q);
749    
750                                    if (bindUuid) {
751                                            qPos.add(uuid);
752                                    }
753    
754                                    qPos.add(groupId);
755    
756                                    List<WikiPage> list = q.list();
757    
758                                    if (list.isEmpty()) {
759                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
760                                                    finderArgs, list);
761                                    }
762                                    else {
763                                            WikiPage wikiPage = list.get(0);
764    
765                                            result = wikiPage;
766    
767                                            cacheResult(wikiPage);
768    
769                                            if ((wikiPage.getUuid() == null) ||
770                                                            !wikiPage.getUuid().equals(uuid) ||
771                                                            (wikiPage.getGroupId() != groupId)) {
772                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
773                                                            finderArgs, wikiPage);
774                                            }
775                                    }
776                            }
777                            catch (Exception e) {
778                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
779                                            finderArgs);
780    
781                                    throw processException(e);
782                            }
783                            finally {
784                                    closeSession(session);
785                            }
786                    }
787    
788                    if (result instanceof List<?>) {
789                            return null;
790                    }
791                    else {
792                            return (WikiPage)result;
793                    }
794            }
795    
796            /**
797             * Removes the wiki page where uuid = &#63; and groupId = &#63; from the database.
798             *
799             * @param uuid the uuid
800             * @param groupId the group ID
801             * @return the wiki page that was removed
802             * @throws SystemException if a system exception occurred
803             */
804            @Override
805            public WikiPage removeByUUID_G(String uuid, long groupId)
806                    throws NoSuchPageException, SystemException {
807                    WikiPage wikiPage = findByUUID_G(uuid, groupId);
808    
809                    return remove(wikiPage);
810            }
811    
812            /**
813             * Returns the number of wiki pages where uuid = &#63; and groupId = &#63;.
814             *
815             * @param uuid the uuid
816             * @param groupId the group ID
817             * @return the number of matching wiki pages
818             * @throws SystemException if a system exception occurred
819             */
820            @Override
821            public int countByUUID_G(String uuid, long groupId)
822                    throws SystemException {
823                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
824    
825                    Object[] finderArgs = new Object[] { uuid, groupId };
826    
827                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
828                                    this);
829    
830                    if (count == null) {
831                            StringBundler query = new StringBundler(3);
832    
833                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
834    
835                            boolean bindUuid = false;
836    
837                            if (uuid == null) {
838                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
839                            }
840                            else if (uuid.equals(StringPool.BLANK)) {
841                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
842                            }
843                            else {
844                                    bindUuid = true;
845    
846                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
847                            }
848    
849                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
850    
851                            String sql = query.toString();
852    
853                            Session session = null;
854    
855                            try {
856                                    session = openSession();
857    
858                                    Query q = session.createQuery(sql);
859    
860                                    QueryPos qPos = QueryPos.getInstance(q);
861    
862                                    if (bindUuid) {
863                                            qPos.add(uuid);
864                                    }
865    
866                                    qPos.add(groupId);
867    
868                                    count = (Long)q.uniqueResult();
869    
870                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
871                            }
872                            catch (Exception e) {
873                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
874    
875                                    throw processException(e);
876                            }
877                            finally {
878                                    closeSession(session);
879                            }
880                    }
881    
882                    return count.intValue();
883            }
884    
885            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "wikiPage.uuid IS NULL AND ";
886            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "wikiPage.uuid = ? AND ";
887            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(wikiPage.uuid IS NULL OR wikiPage.uuid = '') AND ";
888            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "wikiPage.groupId = ?";
889            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
890                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
891                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
892                            new String[] {
893                                    String.class.getName(), Long.class.getName(),
894                                    
895                            Integer.class.getName(), Integer.class.getName(),
896                                    OrderByComparator.class.getName()
897                            });
898            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
899                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
900                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
901                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
902                            new String[] { String.class.getName(), Long.class.getName() },
903                            WikiPageModelImpl.UUID_COLUMN_BITMASK |
904                            WikiPageModelImpl.COMPANYID_COLUMN_BITMASK |
905                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
906                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
907                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
908            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
909                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
910                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
911                            new String[] { String.class.getName(), Long.class.getName() });
912    
913            /**
914             * Returns all the wiki pages where uuid = &#63; and companyId = &#63;.
915             *
916             * @param uuid the uuid
917             * @param companyId the company ID
918             * @return the matching wiki pages
919             * @throws SystemException if a system exception occurred
920             */
921            @Override
922            public List<WikiPage> findByUuid_C(String uuid, long companyId)
923                    throws SystemException {
924                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
925                            QueryUtil.ALL_POS, null);
926            }
927    
928            /**
929             * Returns a range of all the wiki pages where uuid = &#63; and companyId = &#63;.
930             *
931             * <p>
932             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. 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.
933             * </p>
934             *
935             * @param uuid the uuid
936             * @param companyId the company ID
937             * @param start the lower bound of the range of wiki pages
938             * @param end the upper bound of the range of wiki pages (not inclusive)
939             * @return the range of matching wiki pages
940             * @throws SystemException if a system exception occurred
941             */
942            @Override
943            public List<WikiPage> findByUuid_C(String uuid, long companyId, int start,
944                    int end) throws SystemException {
945                    return findByUuid_C(uuid, companyId, start, end, null);
946            }
947    
948            /**
949             * Returns an ordered range of all the wiki pages where uuid = &#63; and companyId = &#63;.
950             *
951             * <p>
952             * 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.
953             * </p>
954             *
955             * @param uuid the uuid
956             * @param companyId the company ID
957             * @param start the lower bound of the range of wiki pages
958             * @param end the upper bound of the range of wiki pages (not inclusive)
959             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
960             * @return the ordered range of matching wiki pages
961             * @throws SystemException if a system exception occurred
962             */
963            @Override
964            public List<WikiPage> findByUuid_C(String uuid, long companyId, int start,
965                    int end, OrderByComparator orderByComparator) throws SystemException {
966                    boolean pagination = true;
967                    FinderPath finderPath = null;
968                    Object[] finderArgs = null;
969    
970                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
971                                    (orderByComparator == null)) {
972                            pagination = false;
973                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
974                            finderArgs = new Object[] { uuid, companyId };
975                    }
976                    else {
977                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
978                            finderArgs = new Object[] {
979                                            uuid, companyId,
980                                            
981                                            start, end, orderByComparator
982                                    };
983                    }
984    
985                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
986                                    finderArgs, this);
987    
988                    if ((list != null) && !list.isEmpty()) {
989                            for (WikiPage wikiPage : list) {
990                                    if (!Validator.equals(uuid, wikiPage.getUuid()) ||
991                                                    (companyId != wikiPage.getCompanyId())) {
992                                            list = null;
993    
994                                            break;
995                                    }
996                            }
997                    }
998    
999                    if (list == null) {
1000                            StringBundler query = null;
1001    
1002                            if (orderByComparator != null) {
1003                                    query = new StringBundler(4 +
1004                                                    (orderByComparator.getOrderByFields().length * 3));
1005                            }
1006                            else {
1007                                    query = new StringBundler(4);
1008                            }
1009    
1010                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1011    
1012                            boolean bindUuid = false;
1013    
1014                            if (uuid == null) {
1015                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1016                            }
1017                            else if (uuid.equals(StringPool.BLANK)) {
1018                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1019                            }
1020                            else {
1021                                    bindUuid = true;
1022    
1023                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1024                            }
1025    
1026                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1027    
1028                            if (orderByComparator != null) {
1029                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1030                                            orderByComparator);
1031                            }
1032                            else
1033                             if (pagination) {
1034                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1035                            }
1036    
1037                            String sql = query.toString();
1038    
1039                            Session session = null;
1040    
1041                            try {
1042                                    session = openSession();
1043    
1044                                    Query q = session.createQuery(sql);
1045    
1046                                    QueryPos qPos = QueryPos.getInstance(q);
1047    
1048                                    if (bindUuid) {
1049                                            qPos.add(uuid);
1050                                    }
1051    
1052                                    qPos.add(companyId);
1053    
1054                                    if (!pagination) {
1055                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1056                                                            start, end, false);
1057    
1058                                            Collections.sort(list);
1059    
1060                                            list = new UnmodifiableList<WikiPage>(list);
1061                                    }
1062                                    else {
1063                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1064                                                            start, end);
1065                                    }
1066    
1067                                    cacheResult(list);
1068    
1069                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1070                            }
1071                            catch (Exception e) {
1072                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1073    
1074                                    throw processException(e);
1075                            }
1076                            finally {
1077                                    closeSession(session);
1078                            }
1079                    }
1080    
1081                    return list;
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
1091             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1092             * @throws SystemException if a system exception occurred
1093             */
1094            @Override
1095            public WikiPage findByUuid_C_First(String uuid, long companyId,
1096                    OrderByComparator orderByComparator)
1097                    throws NoSuchPageException, SystemException {
1098                    WikiPage wikiPage = fetchByUuid_C_First(uuid, companyId,
1099                                    orderByComparator);
1100    
1101                    if (wikiPage != null) {
1102                            return wikiPage;
1103                    }
1104    
1105                    StringBundler msg = new StringBundler(6);
1106    
1107                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1108    
1109                    msg.append("uuid=");
1110                    msg.append(uuid);
1111    
1112                    msg.append(", companyId=");
1113                    msg.append(companyId);
1114    
1115                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1116    
1117                    throw new NoSuchPageException(msg.toString());
1118            }
1119    
1120            /**
1121             * Returns the first wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1122             *
1123             * @param uuid the uuid
1124             * @param companyId the company ID
1125             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1126             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
1127             * @throws SystemException if a system exception occurred
1128             */
1129            @Override
1130            public WikiPage fetchByUuid_C_First(String uuid, long companyId,
1131                    OrderByComparator orderByComparator) throws SystemException {
1132                    List<WikiPage> list = findByUuid_C(uuid, companyId, 0, 1,
1133                                    orderByComparator);
1134    
1135                    if (!list.isEmpty()) {
1136                            return list.get(0);
1137                    }
1138    
1139                    return null;
1140            }
1141    
1142            /**
1143             * Returns the last wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1144             *
1145             * @param uuid the uuid
1146             * @param companyId the company ID
1147             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1148             * @return the last matching wiki page
1149             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1150             * @throws SystemException if a system exception occurred
1151             */
1152            @Override
1153            public WikiPage findByUuid_C_Last(String uuid, long companyId,
1154                    OrderByComparator orderByComparator)
1155                    throws NoSuchPageException, SystemException {
1156                    WikiPage wikiPage = fetchByUuid_C_Last(uuid, companyId,
1157                                    orderByComparator);
1158    
1159                    if (wikiPage != null) {
1160                            return wikiPage;
1161                    }
1162    
1163                    StringBundler msg = new StringBundler(6);
1164    
1165                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1166    
1167                    msg.append("uuid=");
1168                    msg.append(uuid);
1169    
1170                    msg.append(", companyId=");
1171                    msg.append(companyId);
1172    
1173                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1174    
1175                    throw new NoSuchPageException(msg.toString());
1176            }
1177    
1178            /**
1179             * Returns the last wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1180             *
1181             * @param uuid the uuid
1182             * @param companyId the company ID
1183             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1184             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
1185             * @throws SystemException if a system exception occurred
1186             */
1187            @Override
1188            public WikiPage fetchByUuid_C_Last(String uuid, long companyId,
1189                    OrderByComparator orderByComparator) throws SystemException {
1190                    int count = countByUuid_C(uuid, companyId);
1191    
1192                    if (count == 0) {
1193                            return null;
1194                    }
1195    
1196                    List<WikiPage> list = findByUuid_C(uuid, companyId, count - 1, count,
1197                                    orderByComparator);
1198    
1199                    if (!list.isEmpty()) {
1200                            return list.get(0);
1201                    }
1202    
1203                    return null;
1204            }
1205    
1206            /**
1207             * Returns the wiki pages before and after the current wiki page in the ordered set where uuid = &#63; and companyId = &#63;.
1208             *
1209             * @param pageId the primary key of the current wiki page
1210             * @param uuid the uuid
1211             * @param companyId the company ID
1212             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1213             * @return the previous, current, and next wiki page
1214             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
1215             * @throws SystemException if a system exception occurred
1216             */
1217            @Override
1218            public WikiPage[] findByUuid_C_PrevAndNext(long pageId, String uuid,
1219                    long companyId, OrderByComparator orderByComparator)
1220                    throws NoSuchPageException, SystemException {
1221                    WikiPage wikiPage = findByPrimaryKey(pageId);
1222    
1223                    Session session = null;
1224    
1225                    try {
1226                            session = openSession();
1227    
1228                            WikiPage[] array = new WikiPageImpl[3];
1229    
1230                            array[0] = getByUuid_C_PrevAndNext(session, wikiPage, uuid,
1231                                            companyId, orderByComparator, true);
1232    
1233                            array[1] = wikiPage;
1234    
1235                            array[2] = getByUuid_C_PrevAndNext(session, wikiPage, uuid,
1236                                            companyId, orderByComparator, false);
1237    
1238                            return array;
1239                    }
1240                    catch (Exception e) {
1241                            throw processException(e);
1242                    }
1243                    finally {
1244                            closeSession(session);
1245                    }
1246            }
1247    
1248            protected WikiPage getByUuid_C_PrevAndNext(Session session,
1249                    WikiPage wikiPage, String uuid, long companyId,
1250                    OrderByComparator orderByComparator, boolean previous) {
1251                    StringBundler query = null;
1252    
1253                    if (orderByComparator != null) {
1254                            query = new StringBundler(6 +
1255                                            (orderByComparator.getOrderByFields().length * 6));
1256                    }
1257                    else {
1258                            query = new StringBundler(3);
1259                    }
1260    
1261                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1262    
1263                    boolean bindUuid = false;
1264    
1265                    if (uuid == null) {
1266                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1267                    }
1268                    else if (uuid.equals(StringPool.BLANK)) {
1269                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1270                    }
1271                    else {
1272                            bindUuid = true;
1273    
1274                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1275                    }
1276    
1277                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1278    
1279                    if (orderByComparator != null) {
1280                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1281    
1282                            if (orderByConditionFields.length > 0) {
1283                                    query.append(WHERE_AND);
1284                            }
1285    
1286                            for (int i = 0; i < orderByConditionFields.length; i++) {
1287                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1288                                    query.append(orderByConditionFields[i]);
1289    
1290                                    if ((i + 1) < orderByConditionFields.length) {
1291                                            if (orderByComparator.isAscending() ^ previous) {
1292                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1293                                            }
1294                                            else {
1295                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1296                                            }
1297                                    }
1298                                    else {
1299                                            if (orderByComparator.isAscending() ^ previous) {
1300                                                    query.append(WHERE_GREATER_THAN);
1301                                            }
1302                                            else {
1303                                                    query.append(WHERE_LESSER_THAN);
1304                                            }
1305                                    }
1306                            }
1307    
1308                            query.append(ORDER_BY_CLAUSE);
1309    
1310                            String[] orderByFields = orderByComparator.getOrderByFields();
1311    
1312                            for (int i = 0; i < orderByFields.length; i++) {
1313                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1314                                    query.append(orderByFields[i]);
1315    
1316                                    if ((i + 1) < orderByFields.length) {
1317                                            if (orderByComparator.isAscending() ^ previous) {
1318                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1319                                            }
1320                                            else {
1321                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1322                                            }
1323                                    }
1324                                    else {
1325                                            if (orderByComparator.isAscending() ^ previous) {
1326                                                    query.append(ORDER_BY_ASC);
1327                                            }
1328                                            else {
1329                                                    query.append(ORDER_BY_DESC);
1330                                            }
1331                                    }
1332                            }
1333                    }
1334                    else {
1335                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1336                    }
1337    
1338                    String sql = query.toString();
1339    
1340                    Query q = session.createQuery(sql);
1341    
1342                    q.setFirstResult(0);
1343                    q.setMaxResults(2);
1344    
1345                    QueryPos qPos = QueryPos.getInstance(q);
1346    
1347                    if (bindUuid) {
1348                            qPos.add(uuid);
1349                    }
1350    
1351                    qPos.add(companyId);
1352    
1353                    if (orderByComparator != null) {
1354                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
1355    
1356                            for (Object value : values) {
1357                                    qPos.add(value);
1358                            }
1359                    }
1360    
1361                    List<WikiPage> list = q.list();
1362    
1363                    if (list.size() == 2) {
1364                            return list.get(1);
1365                    }
1366                    else {
1367                            return null;
1368                    }
1369            }
1370    
1371            /**
1372             * Removes all the wiki pages where uuid = &#63; and companyId = &#63; from the database.
1373             *
1374             * @param uuid the uuid
1375             * @param companyId the company ID
1376             * @throws SystemException if a system exception occurred
1377             */
1378            @Override
1379            public void removeByUuid_C(String uuid, long companyId)
1380                    throws SystemException {
1381                    for (WikiPage wikiPage : findByUuid_C(uuid, companyId,
1382                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1383                            remove(wikiPage);
1384                    }
1385            }
1386    
1387            /**
1388             * Returns the number of wiki pages where uuid = &#63; and companyId = &#63;.
1389             *
1390             * @param uuid the uuid
1391             * @param companyId the company ID
1392             * @return the number of matching wiki pages
1393             * @throws SystemException if a system exception occurred
1394             */
1395            @Override
1396            public int countByUuid_C(String uuid, long companyId)
1397                    throws SystemException {
1398                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1399    
1400                    Object[] finderArgs = new Object[] { uuid, companyId };
1401    
1402                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1403                                    this);
1404    
1405                    if (count == null) {
1406                            StringBundler query = new StringBundler(3);
1407    
1408                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
1409    
1410                            boolean bindUuid = false;
1411    
1412                            if (uuid == null) {
1413                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1414                            }
1415                            else if (uuid.equals(StringPool.BLANK)) {
1416                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1417                            }
1418                            else {
1419                                    bindUuid = true;
1420    
1421                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1422                            }
1423    
1424                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1425    
1426                            String sql = query.toString();
1427    
1428                            Session session = null;
1429    
1430                            try {
1431                                    session = openSession();
1432    
1433                                    Query q = session.createQuery(sql);
1434    
1435                                    QueryPos qPos = QueryPos.getInstance(q);
1436    
1437                                    if (bindUuid) {
1438                                            qPos.add(uuid);
1439                                    }
1440    
1441                                    qPos.add(companyId);
1442    
1443                                    count = (Long)q.uniqueResult();
1444    
1445                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1446                            }
1447                            catch (Exception e) {
1448                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1449    
1450                                    throw processException(e);
1451                            }
1452                            finally {
1453                                    closeSession(session);
1454                            }
1455                    }
1456    
1457                    return count.intValue();
1458            }
1459    
1460            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "wikiPage.uuid IS NULL AND ";
1461            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "wikiPage.uuid = ? AND ";
1462            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(wikiPage.uuid IS NULL OR wikiPage.uuid = '') AND ";
1463            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "wikiPage.companyId = ?";
1464            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEPRIMKEY =
1465                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1466                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1467                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByResourcePrimKey",
1468                            new String[] {
1469                                    Long.class.getName(),
1470                                    
1471                            Integer.class.getName(), Integer.class.getName(),
1472                                    OrderByComparator.class.getName()
1473                            });
1474            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY =
1475                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1476                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1477                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByResourcePrimKey",
1478                            new String[] { Long.class.getName() },
1479                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
1480                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
1481                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
1482                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
1483            public static final FinderPath FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1484                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1485                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1486                            "countByResourcePrimKey", new String[] { Long.class.getName() });
1487    
1488            /**
1489             * Returns all the wiki pages where resourcePrimKey = &#63;.
1490             *
1491             * @param resourcePrimKey the resource prim key
1492             * @return the matching wiki pages
1493             * @throws SystemException if a system exception occurred
1494             */
1495            @Override
1496            public List<WikiPage> findByResourcePrimKey(long resourcePrimKey)
1497                    throws SystemException {
1498                    return findByResourcePrimKey(resourcePrimKey, QueryUtil.ALL_POS,
1499                            QueryUtil.ALL_POS, null);
1500            }
1501    
1502            /**
1503             * Returns a range of all the wiki pages where resourcePrimKey = &#63;.
1504             *
1505             * <p>
1506             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. 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.
1507             * </p>
1508             *
1509             * @param resourcePrimKey the resource prim key
1510             * @param start the lower bound of the range of wiki pages
1511             * @param end the upper bound of the range of wiki pages (not inclusive)
1512             * @return the range of matching wiki pages
1513             * @throws SystemException if a system exception occurred
1514             */
1515            @Override
1516            public List<WikiPage> findByResourcePrimKey(long resourcePrimKey,
1517                    int start, int end) throws SystemException {
1518                    return findByResourcePrimKey(resourcePrimKey, start, end, null);
1519            }
1520    
1521            /**
1522             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63;.
1523             *
1524             * <p>
1525             * 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.
1526             * </p>
1527             *
1528             * @param resourcePrimKey the resource prim key
1529             * @param start the lower bound of the range of wiki pages
1530             * @param end the upper bound of the range of wiki pages (not inclusive)
1531             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1532             * @return the ordered range of matching wiki pages
1533             * @throws SystemException if a system exception occurred
1534             */
1535            @Override
1536            public List<WikiPage> findByResourcePrimKey(long resourcePrimKey,
1537                    int start, int end, OrderByComparator orderByComparator)
1538                    throws SystemException {
1539                    boolean pagination = true;
1540                    FinderPath finderPath = null;
1541                    Object[] finderArgs = null;
1542    
1543                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1544                                    (orderByComparator == null)) {
1545                            pagination = false;
1546                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY;
1547                            finderArgs = new Object[] { resourcePrimKey };
1548                    }
1549                    else {
1550                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEPRIMKEY;
1551                            finderArgs = new Object[] {
1552                                            resourcePrimKey,
1553                                            
1554                                            start, end, orderByComparator
1555                                    };
1556                    }
1557    
1558                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
1559                                    finderArgs, this);
1560    
1561                    if ((list != null) && !list.isEmpty()) {
1562                            for (WikiPage wikiPage : list) {
1563                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey())) {
1564                                            list = null;
1565    
1566                                            break;
1567                                    }
1568                            }
1569                    }
1570    
1571                    if (list == null) {
1572                            StringBundler query = null;
1573    
1574                            if (orderByComparator != null) {
1575                                    query = new StringBundler(3 +
1576                                                    (orderByComparator.getOrderByFields().length * 3));
1577                            }
1578                            else {
1579                                    query = new StringBundler(3);
1580                            }
1581    
1582                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1583    
1584                            query.append(_FINDER_COLUMN_RESOURCEPRIMKEY_RESOURCEPRIMKEY_2);
1585    
1586                            if (orderByComparator != null) {
1587                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1588                                            orderByComparator);
1589                            }
1590                            else
1591                             if (pagination) {
1592                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1593                            }
1594    
1595                            String sql = query.toString();
1596    
1597                            Session session = null;
1598    
1599                            try {
1600                                    session = openSession();
1601    
1602                                    Query q = session.createQuery(sql);
1603    
1604                                    QueryPos qPos = QueryPos.getInstance(q);
1605    
1606                                    qPos.add(resourcePrimKey);
1607    
1608                                    if (!pagination) {
1609                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1610                                                            start, end, false);
1611    
1612                                            Collections.sort(list);
1613    
1614                                            list = new UnmodifiableList<WikiPage>(list);
1615                                    }
1616                                    else {
1617                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
1618                                                            start, end);
1619                                    }
1620    
1621                                    cacheResult(list);
1622    
1623                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1624                            }
1625                            catch (Exception e) {
1626                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1627    
1628                                    throw processException(e);
1629                            }
1630                            finally {
1631                                    closeSession(session);
1632                            }
1633                    }
1634    
1635                    return list;
1636            }
1637    
1638            /**
1639             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63;.
1640             *
1641             * @param resourcePrimKey the resource prim key
1642             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1643             * @return the first matching wiki page
1644             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1645             * @throws SystemException if a system exception occurred
1646             */
1647            @Override
1648            public WikiPage findByResourcePrimKey_First(long resourcePrimKey,
1649                    OrderByComparator orderByComparator)
1650                    throws NoSuchPageException, SystemException {
1651                    WikiPage wikiPage = fetchByResourcePrimKey_First(resourcePrimKey,
1652                                    orderByComparator);
1653    
1654                    if (wikiPage != null) {
1655                            return wikiPage;
1656                    }
1657    
1658                    StringBundler msg = new StringBundler(4);
1659    
1660                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1661    
1662                    msg.append("resourcePrimKey=");
1663                    msg.append(resourcePrimKey);
1664    
1665                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1666    
1667                    throw new NoSuchPageException(msg.toString());
1668            }
1669    
1670            /**
1671             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63;.
1672             *
1673             * @param resourcePrimKey the resource prim key
1674             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1675             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
1676             * @throws SystemException if a system exception occurred
1677             */
1678            @Override
1679            public WikiPage fetchByResourcePrimKey_First(long resourcePrimKey,
1680                    OrderByComparator orderByComparator) throws SystemException {
1681                    List<WikiPage> list = findByResourcePrimKey(resourcePrimKey, 0, 1,
1682                                    orderByComparator);
1683    
1684                    if (!list.isEmpty()) {
1685                            return list.get(0);
1686                    }
1687    
1688                    return null;
1689            }
1690    
1691            /**
1692             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63;.
1693             *
1694             * @param resourcePrimKey the resource prim key
1695             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1696             * @return the last matching wiki page
1697             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
1698             * @throws SystemException if a system exception occurred
1699             */
1700            @Override
1701            public WikiPage findByResourcePrimKey_Last(long resourcePrimKey,
1702                    OrderByComparator orderByComparator)
1703                    throws NoSuchPageException, SystemException {
1704                    WikiPage wikiPage = fetchByResourcePrimKey_Last(resourcePrimKey,
1705                                    orderByComparator);
1706    
1707                    if (wikiPage != null) {
1708                            return wikiPage;
1709                    }
1710    
1711                    StringBundler msg = new StringBundler(4);
1712    
1713                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1714    
1715                    msg.append("resourcePrimKey=");
1716                    msg.append(resourcePrimKey);
1717    
1718                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1719    
1720                    throw new NoSuchPageException(msg.toString());
1721            }
1722    
1723            /**
1724             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63;.
1725             *
1726             * @param resourcePrimKey the resource prim key
1727             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1728             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
1729             * @throws SystemException if a system exception occurred
1730             */
1731            @Override
1732            public WikiPage fetchByResourcePrimKey_Last(long resourcePrimKey,
1733                    OrderByComparator orderByComparator) throws SystemException {
1734                    int count = countByResourcePrimKey(resourcePrimKey);
1735    
1736                    if (count == 0) {
1737                            return null;
1738                    }
1739    
1740                    List<WikiPage> list = findByResourcePrimKey(resourcePrimKey, count - 1,
1741                                    count, orderByComparator);
1742    
1743                    if (!list.isEmpty()) {
1744                            return list.get(0);
1745                    }
1746    
1747                    return null;
1748            }
1749    
1750            /**
1751             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63;.
1752             *
1753             * @param pageId the primary key of the current wiki page
1754             * @param resourcePrimKey the resource prim key
1755             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1756             * @return the previous, current, and next wiki page
1757             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
1758             * @throws SystemException if a system exception occurred
1759             */
1760            @Override
1761            public WikiPage[] findByResourcePrimKey_PrevAndNext(long pageId,
1762                    long resourcePrimKey, OrderByComparator orderByComparator)
1763                    throws NoSuchPageException, SystemException {
1764                    WikiPage wikiPage = findByPrimaryKey(pageId);
1765    
1766                    Session session = null;
1767    
1768                    try {
1769                            session = openSession();
1770    
1771                            WikiPage[] array = new WikiPageImpl[3];
1772    
1773                            array[0] = getByResourcePrimKey_PrevAndNext(session, wikiPage,
1774                                            resourcePrimKey, orderByComparator, true);
1775    
1776                            array[1] = wikiPage;
1777    
1778                            array[2] = getByResourcePrimKey_PrevAndNext(session, wikiPage,
1779                                            resourcePrimKey, orderByComparator, false);
1780    
1781                            return array;
1782                    }
1783                    catch (Exception e) {
1784                            throw processException(e);
1785                    }
1786                    finally {
1787                            closeSession(session);
1788                    }
1789            }
1790    
1791            protected WikiPage getByResourcePrimKey_PrevAndNext(Session session,
1792                    WikiPage wikiPage, long resourcePrimKey,
1793                    OrderByComparator orderByComparator, boolean previous) {
1794                    StringBundler query = null;
1795    
1796                    if (orderByComparator != null) {
1797                            query = new StringBundler(6 +
1798                                            (orderByComparator.getOrderByFields().length * 6));
1799                    }
1800                    else {
1801                            query = new StringBundler(3);
1802                    }
1803    
1804                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
1805    
1806                    query.append(_FINDER_COLUMN_RESOURCEPRIMKEY_RESOURCEPRIMKEY_2);
1807    
1808                    if (orderByComparator != null) {
1809                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1810    
1811                            if (orderByConditionFields.length > 0) {
1812                                    query.append(WHERE_AND);
1813                            }
1814    
1815                            for (int i = 0; i < orderByConditionFields.length; i++) {
1816                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1817                                    query.append(orderByConditionFields[i]);
1818    
1819                                    if ((i + 1) < orderByConditionFields.length) {
1820                                            if (orderByComparator.isAscending() ^ previous) {
1821                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1822                                            }
1823                                            else {
1824                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1825                                            }
1826                                    }
1827                                    else {
1828                                            if (orderByComparator.isAscending() ^ previous) {
1829                                                    query.append(WHERE_GREATER_THAN);
1830                                            }
1831                                            else {
1832                                                    query.append(WHERE_LESSER_THAN);
1833                                            }
1834                                    }
1835                            }
1836    
1837                            query.append(ORDER_BY_CLAUSE);
1838    
1839                            String[] orderByFields = orderByComparator.getOrderByFields();
1840    
1841                            for (int i = 0; i < orderByFields.length; i++) {
1842                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1843                                    query.append(orderByFields[i]);
1844    
1845                                    if ((i + 1) < orderByFields.length) {
1846                                            if (orderByComparator.isAscending() ^ previous) {
1847                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1848                                            }
1849                                            else {
1850                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1851                                            }
1852                                    }
1853                                    else {
1854                                            if (orderByComparator.isAscending() ^ previous) {
1855                                                    query.append(ORDER_BY_ASC);
1856                                            }
1857                                            else {
1858                                                    query.append(ORDER_BY_DESC);
1859                                            }
1860                                    }
1861                            }
1862                    }
1863                    else {
1864                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
1865                    }
1866    
1867                    String sql = query.toString();
1868    
1869                    Query q = session.createQuery(sql);
1870    
1871                    q.setFirstResult(0);
1872                    q.setMaxResults(2);
1873    
1874                    QueryPos qPos = QueryPos.getInstance(q);
1875    
1876                    qPos.add(resourcePrimKey);
1877    
1878                    if (orderByComparator != null) {
1879                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
1880    
1881                            for (Object value : values) {
1882                                    qPos.add(value);
1883                            }
1884                    }
1885    
1886                    List<WikiPage> list = q.list();
1887    
1888                    if (list.size() == 2) {
1889                            return list.get(1);
1890                    }
1891                    else {
1892                            return null;
1893                    }
1894            }
1895    
1896            /**
1897             * Removes all the wiki pages where resourcePrimKey = &#63; from the database.
1898             *
1899             * @param resourcePrimKey the resource prim key
1900             * @throws SystemException if a system exception occurred
1901             */
1902            @Override
1903            public void removeByResourcePrimKey(long resourcePrimKey)
1904                    throws SystemException {
1905                    for (WikiPage wikiPage : findByResourcePrimKey(resourcePrimKey,
1906                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1907                            remove(wikiPage);
1908                    }
1909            }
1910    
1911            /**
1912             * Returns the number of wiki pages where resourcePrimKey = &#63;.
1913             *
1914             * @param resourcePrimKey the resource prim key
1915             * @return the number of matching wiki pages
1916             * @throws SystemException if a system exception occurred
1917             */
1918            @Override
1919            public int countByResourcePrimKey(long resourcePrimKey)
1920                    throws SystemException {
1921                    FinderPath finderPath = FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY;
1922    
1923                    Object[] finderArgs = new Object[] { resourcePrimKey };
1924    
1925                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1926                                    this);
1927    
1928                    if (count == null) {
1929                            StringBundler query = new StringBundler(2);
1930    
1931                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
1932    
1933                            query.append(_FINDER_COLUMN_RESOURCEPRIMKEY_RESOURCEPRIMKEY_2);
1934    
1935                            String sql = query.toString();
1936    
1937                            Session session = null;
1938    
1939                            try {
1940                                    session = openSession();
1941    
1942                                    Query q = session.createQuery(sql);
1943    
1944                                    QueryPos qPos = QueryPos.getInstance(q);
1945    
1946                                    qPos.add(resourcePrimKey);
1947    
1948                                    count = (Long)q.uniqueResult();
1949    
1950                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1951                            }
1952                            catch (Exception e) {
1953                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1954    
1955                                    throw processException(e);
1956                            }
1957                            finally {
1958                                    closeSession(session);
1959                            }
1960                    }
1961    
1962                    return count.intValue();
1963            }
1964    
1965            private static final String _FINDER_COLUMN_RESOURCEPRIMKEY_RESOURCEPRIMKEY_2 =
1966                    "wikiPage.resourcePrimKey = ?";
1967            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NODEID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1968                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1969                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByNodeId",
1970                            new String[] {
1971                                    Long.class.getName(),
1972                                    
1973                            Integer.class.getName(), Integer.class.getName(),
1974                                    OrderByComparator.class.getName()
1975                            });
1976            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID =
1977                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1978                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
1979                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByNodeId",
1980                            new String[] { Long.class.getName() },
1981                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
1982                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
1983                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
1984            public static final FinderPath FINDER_PATH_COUNT_BY_NODEID = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
1985                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1986                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByNodeId",
1987                            new String[] { Long.class.getName() });
1988    
1989            /**
1990             * Returns all the wiki pages where nodeId = &#63;.
1991             *
1992             * @param nodeId the node ID
1993             * @return the matching wiki pages
1994             * @throws SystemException if a system exception occurred
1995             */
1996            @Override
1997            public List<WikiPage> findByNodeId(long nodeId) throws SystemException {
1998                    return findByNodeId(nodeId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1999            }
2000    
2001            /**
2002             * Returns a range of all the wiki pages where nodeId = &#63;.
2003             *
2004             * <p>
2005             * 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.
2006             * </p>
2007             *
2008             * @param nodeId the node ID
2009             * @param start the lower bound of the range of wiki pages
2010             * @param end the upper bound of the range of wiki pages (not inclusive)
2011             * @return the range of matching wiki pages
2012             * @throws SystemException if a system exception occurred
2013             */
2014            @Override
2015            public List<WikiPage> findByNodeId(long nodeId, int start, int end)
2016                    throws SystemException {
2017                    return findByNodeId(nodeId, start, end, null);
2018            }
2019    
2020            /**
2021             * Returns an ordered range of all the wiki pages where nodeId = &#63;.
2022             *
2023             * <p>
2024             * 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.
2025             * </p>
2026             *
2027             * @param nodeId the node ID
2028             * @param start the lower bound of the range of wiki pages
2029             * @param end the upper bound of the range of wiki pages (not inclusive)
2030             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2031             * @return the ordered range of matching wiki pages
2032             * @throws SystemException if a system exception occurred
2033             */
2034            @Override
2035            public List<WikiPage> findByNodeId(long nodeId, int start, int end,
2036                    OrderByComparator orderByComparator) throws SystemException {
2037                    boolean pagination = true;
2038                    FinderPath finderPath = null;
2039                    Object[] finderArgs = null;
2040    
2041                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2042                                    (orderByComparator == null)) {
2043                            pagination = false;
2044                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID;
2045                            finderArgs = new Object[] { nodeId };
2046                    }
2047                    else {
2048                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NODEID;
2049                            finderArgs = new Object[] { nodeId, start, end, orderByComparator };
2050                    }
2051    
2052                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
2053                                    finderArgs, this);
2054    
2055                    if ((list != null) && !list.isEmpty()) {
2056                            for (WikiPage wikiPage : list) {
2057                                    if ((nodeId != wikiPage.getNodeId())) {
2058                                            list = null;
2059    
2060                                            break;
2061                                    }
2062                            }
2063                    }
2064    
2065                    if (list == null) {
2066                            StringBundler query = null;
2067    
2068                            if (orderByComparator != null) {
2069                                    query = new StringBundler(3 +
2070                                                    (orderByComparator.getOrderByFields().length * 3));
2071                            }
2072                            else {
2073                                    query = new StringBundler(3);
2074                            }
2075    
2076                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2077    
2078                            query.append(_FINDER_COLUMN_NODEID_NODEID_2);
2079    
2080                            if (orderByComparator != null) {
2081                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2082                                            orderByComparator);
2083                            }
2084                            else
2085                             if (pagination) {
2086                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2087                            }
2088    
2089                            String sql = query.toString();
2090    
2091                            Session session = null;
2092    
2093                            try {
2094                                    session = openSession();
2095    
2096                                    Query q = session.createQuery(sql);
2097    
2098                                    QueryPos qPos = QueryPos.getInstance(q);
2099    
2100                                    qPos.add(nodeId);
2101    
2102                                    if (!pagination) {
2103                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2104                                                            start, end, false);
2105    
2106                                            Collections.sort(list);
2107    
2108                                            list = new UnmodifiableList<WikiPage>(list);
2109                                    }
2110                                    else {
2111                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2112                                                            start, end);
2113                                    }
2114    
2115                                    cacheResult(list);
2116    
2117                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2118                            }
2119                            catch (Exception e) {
2120                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2121    
2122                                    throw processException(e);
2123                            }
2124                            finally {
2125                                    closeSession(session);
2126                            }
2127                    }
2128    
2129                    return list;
2130            }
2131    
2132            /**
2133             * Returns the first wiki page in the ordered set where nodeId = &#63;.
2134             *
2135             * @param nodeId the node ID
2136             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2137             * @return the first matching wiki page
2138             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2139             * @throws SystemException if a system exception occurred
2140             */
2141            @Override
2142            public WikiPage findByNodeId_First(long nodeId,
2143                    OrderByComparator orderByComparator)
2144                    throws NoSuchPageException, SystemException {
2145                    WikiPage wikiPage = fetchByNodeId_First(nodeId, orderByComparator);
2146    
2147                    if (wikiPage != null) {
2148                            return wikiPage;
2149                    }
2150    
2151                    StringBundler msg = new StringBundler(4);
2152    
2153                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2154    
2155                    msg.append("nodeId=");
2156                    msg.append(nodeId);
2157    
2158                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2159    
2160                    throw new NoSuchPageException(msg.toString());
2161            }
2162    
2163            /**
2164             * Returns the first wiki page in the ordered set where nodeId = &#63;.
2165             *
2166             * @param nodeId the node ID
2167             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2168             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
2169             * @throws SystemException if a system exception occurred
2170             */
2171            @Override
2172            public WikiPage fetchByNodeId_First(long nodeId,
2173                    OrderByComparator orderByComparator) throws SystemException {
2174                    List<WikiPage> list = findByNodeId(nodeId, 0, 1, orderByComparator);
2175    
2176                    if (!list.isEmpty()) {
2177                            return list.get(0);
2178                    }
2179    
2180                    return null;
2181            }
2182    
2183            /**
2184             * Returns the last wiki page in the ordered set where nodeId = &#63;.
2185             *
2186             * @param nodeId the node ID
2187             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2188             * @return the last matching wiki page
2189             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2190             * @throws SystemException if a system exception occurred
2191             */
2192            @Override
2193            public WikiPage findByNodeId_Last(long nodeId,
2194                    OrderByComparator orderByComparator)
2195                    throws NoSuchPageException, SystemException {
2196                    WikiPage wikiPage = fetchByNodeId_Last(nodeId, orderByComparator);
2197    
2198                    if (wikiPage != null) {
2199                            return wikiPage;
2200                    }
2201    
2202                    StringBundler msg = new StringBundler(4);
2203    
2204                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2205    
2206                    msg.append("nodeId=");
2207                    msg.append(nodeId);
2208    
2209                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2210    
2211                    throw new NoSuchPageException(msg.toString());
2212            }
2213    
2214            /**
2215             * Returns the last wiki page in the ordered set where nodeId = &#63;.
2216             *
2217             * @param nodeId the node ID
2218             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2219             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
2220             * @throws SystemException if a system exception occurred
2221             */
2222            @Override
2223            public WikiPage fetchByNodeId_Last(long nodeId,
2224                    OrderByComparator orderByComparator) throws SystemException {
2225                    int count = countByNodeId(nodeId);
2226    
2227                    if (count == 0) {
2228                            return null;
2229                    }
2230    
2231                    List<WikiPage> list = findByNodeId(nodeId, count - 1, count,
2232                                    orderByComparator);
2233    
2234                    if (!list.isEmpty()) {
2235                            return list.get(0);
2236                    }
2237    
2238                    return null;
2239            }
2240    
2241            /**
2242             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63;.
2243             *
2244             * @param pageId the primary key of the current wiki page
2245             * @param nodeId the node ID
2246             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2247             * @return the previous, current, and next wiki page
2248             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
2249             * @throws SystemException if a system exception occurred
2250             */
2251            @Override
2252            public WikiPage[] findByNodeId_PrevAndNext(long pageId, long nodeId,
2253                    OrderByComparator orderByComparator)
2254                    throws NoSuchPageException, SystemException {
2255                    WikiPage wikiPage = findByPrimaryKey(pageId);
2256    
2257                    Session session = null;
2258    
2259                    try {
2260                            session = openSession();
2261    
2262                            WikiPage[] array = new WikiPageImpl[3];
2263    
2264                            array[0] = getByNodeId_PrevAndNext(session, wikiPage, nodeId,
2265                                            orderByComparator, true);
2266    
2267                            array[1] = wikiPage;
2268    
2269                            array[2] = getByNodeId_PrevAndNext(session, wikiPage, nodeId,
2270                                            orderByComparator, false);
2271    
2272                            return array;
2273                    }
2274                    catch (Exception e) {
2275                            throw processException(e);
2276                    }
2277                    finally {
2278                            closeSession(session);
2279                    }
2280            }
2281    
2282            protected WikiPage getByNodeId_PrevAndNext(Session session,
2283                    WikiPage wikiPage, long nodeId, OrderByComparator orderByComparator,
2284                    boolean previous) {
2285                    StringBundler query = null;
2286    
2287                    if (orderByComparator != null) {
2288                            query = new StringBundler(6 +
2289                                            (orderByComparator.getOrderByFields().length * 6));
2290                    }
2291                    else {
2292                            query = new StringBundler(3);
2293                    }
2294    
2295                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2296    
2297                    query.append(_FINDER_COLUMN_NODEID_NODEID_2);
2298    
2299                    if (orderByComparator != null) {
2300                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2301    
2302                            if (orderByConditionFields.length > 0) {
2303                                    query.append(WHERE_AND);
2304                            }
2305    
2306                            for (int i = 0; i < orderByConditionFields.length; i++) {
2307                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2308                                    query.append(orderByConditionFields[i]);
2309    
2310                                    if ((i + 1) < orderByConditionFields.length) {
2311                                            if (orderByComparator.isAscending() ^ previous) {
2312                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2313                                            }
2314                                            else {
2315                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2316                                            }
2317                                    }
2318                                    else {
2319                                            if (orderByComparator.isAscending() ^ previous) {
2320                                                    query.append(WHERE_GREATER_THAN);
2321                                            }
2322                                            else {
2323                                                    query.append(WHERE_LESSER_THAN);
2324                                            }
2325                                    }
2326                            }
2327    
2328                            query.append(ORDER_BY_CLAUSE);
2329    
2330                            String[] orderByFields = orderByComparator.getOrderByFields();
2331    
2332                            for (int i = 0; i < orderByFields.length; i++) {
2333                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2334                                    query.append(orderByFields[i]);
2335    
2336                                    if ((i + 1) < orderByFields.length) {
2337                                            if (orderByComparator.isAscending() ^ previous) {
2338                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2339                                            }
2340                                            else {
2341                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2342                                            }
2343                                    }
2344                                    else {
2345                                            if (orderByComparator.isAscending() ^ previous) {
2346                                                    query.append(ORDER_BY_ASC);
2347                                            }
2348                                            else {
2349                                                    query.append(ORDER_BY_DESC);
2350                                            }
2351                                    }
2352                            }
2353                    }
2354                    else {
2355                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2356                    }
2357    
2358                    String sql = query.toString();
2359    
2360                    Query q = session.createQuery(sql);
2361    
2362                    q.setFirstResult(0);
2363                    q.setMaxResults(2);
2364    
2365                    QueryPos qPos = QueryPos.getInstance(q);
2366    
2367                    qPos.add(nodeId);
2368    
2369                    if (orderByComparator != null) {
2370                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
2371    
2372                            for (Object value : values) {
2373                                    qPos.add(value);
2374                            }
2375                    }
2376    
2377                    List<WikiPage> list = q.list();
2378    
2379                    if (list.size() == 2) {
2380                            return list.get(1);
2381                    }
2382                    else {
2383                            return null;
2384                    }
2385            }
2386    
2387            /**
2388             * Removes all the wiki pages where nodeId = &#63; from the database.
2389             *
2390             * @param nodeId the node ID
2391             * @throws SystemException if a system exception occurred
2392             */
2393            @Override
2394            public void removeByNodeId(long nodeId) throws SystemException {
2395                    for (WikiPage wikiPage : findByNodeId(nodeId, QueryUtil.ALL_POS,
2396                                    QueryUtil.ALL_POS, null)) {
2397                            remove(wikiPage);
2398                    }
2399            }
2400    
2401            /**
2402             * Returns the number of wiki pages where nodeId = &#63;.
2403             *
2404             * @param nodeId the node ID
2405             * @return the number of matching wiki pages
2406             * @throws SystemException if a system exception occurred
2407             */
2408            @Override
2409            public int countByNodeId(long nodeId) throws SystemException {
2410                    FinderPath finderPath = FINDER_PATH_COUNT_BY_NODEID;
2411    
2412                    Object[] finderArgs = new Object[] { nodeId };
2413    
2414                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2415                                    this);
2416    
2417                    if (count == null) {
2418                            StringBundler query = new StringBundler(2);
2419    
2420                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
2421    
2422                            query.append(_FINDER_COLUMN_NODEID_NODEID_2);
2423    
2424                            String sql = query.toString();
2425    
2426                            Session session = null;
2427    
2428                            try {
2429                                    session = openSession();
2430    
2431                                    Query q = session.createQuery(sql);
2432    
2433                                    QueryPos qPos = QueryPos.getInstance(q);
2434    
2435                                    qPos.add(nodeId);
2436    
2437                                    count = (Long)q.uniqueResult();
2438    
2439                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2440                            }
2441                            catch (Exception e) {
2442                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2443    
2444                                    throw processException(e);
2445                            }
2446                            finally {
2447                                    closeSession(session);
2448                            }
2449                    }
2450    
2451                    return count.intValue();
2452            }
2453    
2454            private static final String _FINDER_COLUMN_NODEID_NODEID_2 = "wikiPage.nodeId = ?";
2455            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FORMAT = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2456                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2457                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByFormat",
2458                            new String[] {
2459                                    String.class.getName(),
2460                                    
2461                            Integer.class.getName(), Integer.class.getName(),
2462                                    OrderByComparator.class.getName()
2463                            });
2464            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT =
2465                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2466                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2467                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByFormat",
2468                            new String[] { String.class.getName() },
2469                            WikiPageModelImpl.FORMAT_COLUMN_BITMASK |
2470                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
2471                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
2472                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
2473            public static final FinderPath FINDER_PATH_COUNT_BY_FORMAT = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2474                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2475                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFormat",
2476                            new String[] { String.class.getName() });
2477    
2478            /**
2479             * Returns all the wiki pages where format = &#63;.
2480             *
2481             * @param format the format
2482             * @return the matching wiki pages
2483             * @throws SystemException if a system exception occurred
2484             */
2485            @Override
2486            public List<WikiPage> findByFormat(String format) throws SystemException {
2487                    return findByFormat(format, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2488            }
2489    
2490            /**
2491             * Returns a range of all the wiki pages where format = &#63;.
2492             *
2493             * <p>
2494             * 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.
2495             * </p>
2496             *
2497             * @param format the format
2498             * @param start the lower bound of the range of wiki pages
2499             * @param end the upper bound of the range of wiki pages (not inclusive)
2500             * @return the range of matching wiki pages
2501             * @throws SystemException if a system exception occurred
2502             */
2503            @Override
2504            public List<WikiPage> findByFormat(String format, int start, int end)
2505                    throws SystemException {
2506                    return findByFormat(format, start, end, null);
2507            }
2508    
2509            /**
2510             * Returns an ordered range of all the wiki pages where format = &#63;.
2511             *
2512             * <p>
2513             * 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.
2514             * </p>
2515             *
2516             * @param format the format
2517             * @param start the lower bound of the range of wiki pages
2518             * @param end the upper bound of the range of wiki pages (not inclusive)
2519             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2520             * @return the ordered range of matching wiki pages
2521             * @throws SystemException if a system exception occurred
2522             */
2523            @Override
2524            public List<WikiPage> findByFormat(String format, int start, int end,
2525                    OrderByComparator orderByComparator) throws SystemException {
2526                    boolean pagination = true;
2527                    FinderPath finderPath = null;
2528                    Object[] finderArgs = null;
2529    
2530                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2531                                    (orderByComparator == null)) {
2532                            pagination = false;
2533                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT;
2534                            finderArgs = new Object[] { format };
2535                    }
2536                    else {
2537                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FORMAT;
2538                            finderArgs = new Object[] { format, start, end, orderByComparator };
2539                    }
2540    
2541                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
2542                                    finderArgs, this);
2543    
2544                    if ((list != null) && !list.isEmpty()) {
2545                            for (WikiPage wikiPage : list) {
2546                                    if (!Validator.equals(format, wikiPage.getFormat())) {
2547                                            list = null;
2548    
2549                                            break;
2550                                    }
2551                            }
2552                    }
2553    
2554                    if (list == null) {
2555                            StringBundler query = null;
2556    
2557                            if (orderByComparator != null) {
2558                                    query = new StringBundler(3 +
2559                                                    (orderByComparator.getOrderByFields().length * 3));
2560                            }
2561                            else {
2562                                    query = new StringBundler(3);
2563                            }
2564    
2565                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2566    
2567                            boolean bindFormat = false;
2568    
2569                            if (format == null) {
2570                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
2571                            }
2572                            else if (format.equals(StringPool.BLANK)) {
2573                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
2574                            }
2575                            else {
2576                                    bindFormat = true;
2577    
2578                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
2579                            }
2580    
2581                            if (orderByComparator != null) {
2582                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2583                                            orderByComparator);
2584                            }
2585                            else
2586                             if (pagination) {
2587                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2588                            }
2589    
2590                            String sql = query.toString();
2591    
2592                            Session session = null;
2593    
2594                            try {
2595                                    session = openSession();
2596    
2597                                    Query q = session.createQuery(sql);
2598    
2599                                    QueryPos qPos = QueryPos.getInstance(q);
2600    
2601                                    if (bindFormat) {
2602                                            qPos.add(format);
2603                                    }
2604    
2605                                    if (!pagination) {
2606                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2607                                                            start, end, false);
2608    
2609                                            Collections.sort(list);
2610    
2611                                            list = new UnmodifiableList<WikiPage>(list);
2612                                    }
2613                                    else {
2614                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
2615                                                            start, end);
2616                                    }
2617    
2618                                    cacheResult(list);
2619    
2620                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2621                            }
2622                            catch (Exception e) {
2623                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2624    
2625                                    throw processException(e);
2626                            }
2627                            finally {
2628                                    closeSession(session);
2629                            }
2630                    }
2631    
2632                    return list;
2633            }
2634    
2635            /**
2636             * Returns the first wiki page in the ordered set where format = &#63;.
2637             *
2638             * @param format the format
2639             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2640             * @return the first 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            @Override
2645            public WikiPage findByFormat_First(String format,
2646                    OrderByComparator orderByComparator)
2647                    throws NoSuchPageException, SystemException {
2648                    WikiPage wikiPage = fetchByFormat_First(format, orderByComparator);
2649    
2650                    if (wikiPage != null) {
2651                            return wikiPage;
2652                    }
2653    
2654                    StringBundler msg = new StringBundler(4);
2655    
2656                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2657    
2658                    msg.append("format=");
2659                    msg.append(format);
2660    
2661                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2662    
2663                    throw new NoSuchPageException(msg.toString());
2664            }
2665    
2666            /**
2667             * Returns the first wiki page in the ordered set where format = &#63;.
2668             *
2669             * @param format the format
2670             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2671             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
2672             * @throws SystemException if a system exception occurred
2673             */
2674            @Override
2675            public WikiPage fetchByFormat_First(String format,
2676                    OrderByComparator orderByComparator) throws SystemException {
2677                    List<WikiPage> list = findByFormat(format, 0, 1, orderByComparator);
2678    
2679                    if (!list.isEmpty()) {
2680                            return list.get(0);
2681                    }
2682    
2683                    return null;
2684            }
2685    
2686            /**
2687             * Returns the last wiki page in the ordered set where format = &#63;.
2688             *
2689             * @param format the format
2690             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2691             * @return the last matching wiki page
2692             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
2693             * @throws SystemException if a system exception occurred
2694             */
2695            @Override
2696            public WikiPage findByFormat_Last(String format,
2697                    OrderByComparator orderByComparator)
2698                    throws NoSuchPageException, SystemException {
2699                    WikiPage wikiPage = fetchByFormat_Last(format, orderByComparator);
2700    
2701                    if (wikiPage != null) {
2702                            return wikiPage;
2703                    }
2704    
2705                    StringBundler msg = new StringBundler(4);
2706    
2707                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2708    
2709                    msg.append("format=");
2710                    msg.append(format);
2711    
2712                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2713    
2714                    throw new NoSuchPageException(msg.toString());
2715            }
2716    
2717            /**
2718             * Returns the last wiki page in the ordered set where format = &#63;.
2719             *
2720             * @param format the format
2721             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2722             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
2723             * @throws SystemException if a system exception occurred
2724             */
2725            @Override
2726            public WikiPage fetchByFormat_Last(String format,
2727                    OrderByComparator orderByComparator) throws SystemException {
2728                    int count = countByFormat(format);
2729    
2730                    if (count == 0) {
2731                            return null;
2732                    }
2733    
2734                    List<WikiPage> list = findByFormat(format, count - 1, count,
2735                                    orderByComparator);
2736    
2737                    if (!list.isEmpty()) {
2738                            return list.get(0);
2739                    }
2740    
2741                    return null;
2742            }
2743    
2744            /**
2745             * Returns the wiki pages before and after the current wiki page in the ordered set where format = &#63;.
2746             *
2747             * @param pageId the primary key of the current wiki page
2748             * @param format the format
2749             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2750             * @return the previous, current, and next wiki page
2751             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
2752             * @throws SystemException if a system exception occurred
2753             */
2754            @Override
2755            public WikiPage[] findByFormat_PrevAndNext(long pageId, String format,
2756                    OrderByComparator orderByComparator)
2757                    throws NoSuchPageException, SystemException {
2758                    WikiPage wikiPage = findByPrimaryKey(pageId);
2759    
2760                    Session session = null;
2761    
2762                    try {
2763                            session = openSession();
2764    
2765                            WikiPage[] array = new WikiPageImpl[3];
2766    
2767                            array[0] = getByFormat_PrevAndNext(session, wikiPage, format,
2768                                            orderByComparator, true);
2769    
2770                            array[1] = wikiPage;
2771    
2772                            array[2] = getByFormat_PrevAndNext(session, wikiPage, format,
2773                                            orderByComparator, false);
2774    
2775                            return array;
2776                    }
2777                    catch (Exception e) {
2778                            throw processException(e);
2779                    }
2780                    finally {
2781                            closeSession(session);
2782                    }
2783            }
2784    
2785            protected WikiPage getByFormat_PrevAndNext(Session session,
2786                    WikiPage wikiPage, String format, OrderByComparator orderByComparator,
2787                    boolean previous) {
2788                    StringBundler query = null;
2789    
2790                    if (orderByComparator != null) {
2791                            query = new StringBundler(6 +
2792                                            (orderByComparator.getOrderByFields().length * 6));
2793                    }
2794                    else {
2795                            query = new StringBundler(3);
2796                    }
2797    
2798                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
2799    
2800                    boolean bindFormat = false;
2801    
2802                    if (format == null) {
2803                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
2804                    }
2805                    else if (format.equals(StringPool.BLANK)) {
2806                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
2807                    }
2808                    else {
2809                            bindFormat = true;
2810    
2811                            query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
2812                    }
2813    
2814                    if (orderByComparator != null) {
2815                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2816    
2817                            if (orderByConditionFields.length > 0) {
2818                                    query.append(WHERE_AND);
2819                            }
2820    
2821                            for (int i = 0; i < orderByConditionFields.length; i++) {
2822                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2823                                    query.append(orderByConditionFields[i]);
2824    
2825                                    if ((i + 1) < orderByConditionFields.length) {
2826                                            if (orderByComparator.isAscending() ^ previous) {
2827                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2828                                            }
2829                                            else {
2830                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2831                                            }
2832                                    }
2833                                    else {
2834                                            if (orderByComparator.isAscending() ^ previous) {
2835                                                    query.append(WHERE_GREATER_THAN);
2836                                            }
2837                                            else {
2838                                                    query.append(WHERE_LESSER_THAN);
2839                                            }
2840                                    }
2841                            }
2842    
2843                            query.append(ORDER_BY_CLAUSE);
2844    
2845                            String[] orderByFields = orderByComparator.getOrderByFields();
2846    
2847                            for (int i = 0; i < orderByFields.length; i++) {
2848                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2849                                    query.append(orderByFields[i]);
2850    
2851                                    if ((i + 1) < orderByFields.length) {
2852                                            if (orderByComparator.isAscending() ^ previous) {
2853                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2854                                            }
2855                                            else {
2856                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2857                                            }
2858                                    }
2859                                    else {
2860                                            if (orderByComparator.isAscending() ^ previous) {
2861                                                    query.append(ORDER_BY_ASC);
2862                                            }
2863                                            else {
2864                                                    query.append(ORDER_BY_DESC);
2865                                            }
2866                                    }
2867                            }
2868                    }
2869                    else {
2870                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
2871                    }
2872    
2873                    String sql = query.toString();
2874    
2875                    Query q = session.createQuery(sql);
2876    
2877                    q.setFirstResult(0);
2878                    q.setMaxResults(2);
2879    
2880                    QueryPos qPos = QueryPos.getInstance(q);
2881    
2882                    if (bindFormat) {
2883                            qPos.add(format);
2884                    }
2885    
2886                    if (orderByComparator != null) {
2887                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
2888    
2889                            for (Object value : values) {
2890                                    qPos.add(value);
2891                            }
2892                    }
2893    
2894                    List<WikiPage> list = q.list();
2895    
2896                    if (list.size() == 2) {
2897                            return list.get(1);
2898                    }
2899                    else {
2900                            return null;
2901                    }
2902            }
2903    
2904            /**
2905             * Removes all the wiki pages where format = &#63; from the database.
2906             *
2907             * @param format the format
2908             * @throws SystemException if a system exception occurred
2909             */
2910            @Override
2911            public void removeByFormat(String format) throws SystemException {
2912                    for (WikiPage wikiPage : findByFormat(format, QueryUtil.ALL_POS,
2913                                    QueryUtil.ALL_POS, null)) {
2914                            remove(wikiPage);
2915                    }
2916            }
2917    
2918            /**
2919             * Returns the number of wiki pages where format = &#63;.
2920             *
2921             * @param format the format
2922             * @return the number of matching wiki pages
2923             * @throws SystemException if a system exception occurred
2924             */
2925            @Override
2926            public int countByFormat(String format) throws SystemException {
2927                    FinderPath finderPath = FINDER_PATH_COUNT_BY_FORMAT;
2928    
2929                    Object[] finderArgs = new Object[] { format };
2930    
2931                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2932                                    this);
2933    
2934                    if (count == null) {
2935                            StringBundler query = new StringBundler(2);
2936    
2937                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
2938    
2939                            boolean bindFormat = false;
2940    
2941                            if (format == null) {
2942                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_1);
2943                            }
2944                            else if (format.equals(StringPool.BLANK)) {
2945                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_3);
2946                            }
2947                            else {
2948                                    bindFormat = true;
2949    
2950                                    query.append(_FINDER_COLUMN_FORMAT_FORMAT_2);
2951                            }
2952    
2953                            String sql = query.toString();
2954    
2955                            Session session = null;
2956    
2957                            try {
2958                                    session = openSession();
2959    
2960                                    Query q = session.createQuery(sql);
2961    
2962                                    QueryPos qPos = QueryPos.getInstance(q);
2963    
2964                                    if (bindFormat) {
2965                                            qPos.add(format);
2966                                    }
2967    
2968                                    count = (Long)q.uniqueResult();
2969    
2970                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2971                            }
2972                            catch (Exception e) {
2973                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2974    
2975                                    throw processException(e);
2976                            }
2977                            finally {
2978                                    closeSession(session);
2979                            }
2980                    }
2981    
2982                    return count.intValue();
2983            }
2984    
2985            private static final String _FINDER_COLUMN_FORMAT_FORMAT_1 = "wikiPage.format IS NULL";
2986            private static final String _FINDER_COLUMN_FORMAT_FORMAT_2 = "wikiPage.format = ?";
2987            private static final String _FINDER_COLUMN_FORMAT_FORMAT_3 = "(wikiPage.format IS NULL OR wikiPage.format = '')";
2988            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2989                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2990                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_N",
2991                            new String[] {
2992                                    Long.class.getName(), Long.class.getName(),
2993                                    
2994                            Integer.class.getName(), Integer.class.getName(),
2995                                    OrderByComparator.class.getName()
2996                            });
2997            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
2998                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
2999                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_N",
3000                            new String[] { Long.class.getName(), Long.class.getName() },
3001                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
3002                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
3003                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
3004                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
3005            public static final FinderPath FINDER_PATH_COUNT_BY_R_N = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3006                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3007                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N",
3008                            new String[] { Long.class.getName(), Long.class.getName() });
3009    
3010            /**
3011             * Returns all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
3012             *
3013             * @param resourcePrimKey the resource prim key
3014             * @param nodeId the node ID
3015             * @return the matching wiki pages
3016             * @throws SystemException if a system exception occurred
3017             */
3018            @Override
3019            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId)
3020                    throws SystemException {
3021                    return findByR_N(resourcePrimKey, nodeId, QueryUtil.ALL_POS,
3022                            QueryUtil.ALL_POS, null);
3023            }
3024    
3025            /**
3026             * Returns a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
3027             *
3028             * <p>
3029             * 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.
3030             * </p>
3031             *
3032             * @param resourcePrimKey the resource prim key
3033             * @param nodeId the node ID
3034             * @param start the lower bound of the range of wiki pages
3035             * @param end the upper bound of the range of wiki pages (not inclusive)
3036             * @return the range of matching wiki pages
3037             * @throws SystemException if a system exception occurred
3038             */
3039            @Override
3040            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId,
3041                    int start, int end) throws SystemException {
3042                    return findByR_N(resourcePrimKey, nodeId, start, end, null);
3043            }
3044    
3045            /**
3046             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
3047             *
3048             * <p>
3049             * 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.
3050             * </p>
3051             *
3052             * @param resourcePrimKey the resource prim key
3053             * @param nodeId the node ID
3054             * @param start the lower bound of the range of wiki pages
3055             * @param end the upper bound of the range of wiki pages (not inclusive)
3056             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3057             * @return the ordered range of matching wiki pages
3058             * @throws SystemException if a system exception occurred
3059             */
3060            @Override
3061            public List<WikiPage> findByR_N(long resourcePrimKey, long nodeId,
3062                    int start, int end, OrderByComparator orderByComparator)
3063                    throws SystemException {
3064                    boolean pagination = true;
3065                    FinderPath finderPath = null;
3066                    Object[] finderArgs = null;
3067    
3068                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3069                                    (orderByComparator == null)) {
3070                            pagination = false;
3071                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N;
3072                            finderArgs = new Object[] { resourcePrimKey, nodeId };
3073                    }
3074                    else {
3075                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N;
3076                            finderArgs = new Object[] {
3077                                            resourcePrimKey, nodeId,
3078                                            
3079                                            start, end, orderByComparator
3080                                    };
3081                    }
3082    
3083                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
3084                                    finderArgs, this);
3085    
3086                    if ((list != null) && !list.isEmpty()) {
3087                            for (WikiPage wikiPage : list) {
3088                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
3089                                                    (nodeId != wikiPage.getNodeId())) {
3090                                            list = null;
3091    
3092                                            break;
3093                                    }
3094                            }
3095                    }
3096    
3097                    if (list == null) {
3098                            StringBundler query = null;
3099    
3100                            if (orderByComparator != null) {
3101                                    query = new StringBundler(4 +
3102                                                    (orderByComparator.getOrderByFields().length * 3));
3103                            }
3104                            else {
3105                                    query = new StringBundler(4);
3106                            }
3107    
3108                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3109    
3110                            query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
3111    
3112                            query.append(_FINDER_COLUMN_R_N_NODEID_2);
3113    
3114                            if (orderByComparator != null) {
3115                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3116                                            orderByComparator);
3117                            }
3118                            else
3119                             if (pagination) {
3120                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3121                            }
3122    
3123                            String sql = query.toString();
3124    
3125                            Session session = null;
3126    
3127                            try {
3128                                    session = openSession();
3129    
3130                                    Query q = session.createQuery(sql);
3131    
3132                                    QueryPos qPos = QueryPos.getInstance(q);
3133    
3134                                    qPos.add(resourcePrimKey);
3135    
3136                                    qPos.add(nodeId);
3137    
3138                                    if (!pagination) {
3139                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3140                                                            start, end, false);
3141    
3142                                            Collections.sort(list);
3143    
3144                                            list = new UnmodifiableList<WikiPage>(list);
3145                                    }
3146                                    else {
3147                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3148                                                            start, end);
3149                                    }
3150    
3151                                    cacheResult(list);
3152    
3153                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3154                            }
3155                            catch (Exception e) {
3156                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3157    
3158                                    throw processException(e);
3159                            }
3160                            finally {
3161                                    closeSession(session);
3162                            }
3163                    }
3164    
3165                    return list;
3166            }
3167    
3168            /**
3169             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
3170             *
3171             * @param resourcePrimKey the resource prim key
3172             * @param nodeId the node ID
3173             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3174             * @return the first matching wiki page
3175             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3176             * @throws SystemException if a system exception occurred
3177             */
3178            @Override
3179            public WikiPage findByR_N_First(long resourcePrimKey, long nodeId,
3180                    OrderByComparator orderByComparator)
3181                    throws NoSuchPageException, SystemException {
3182                    WikiPage wikiPage = fetchByR_N_First(resourcePrimKey, nodeId,
3183                                    orderByComparator);
3184    
3185                    if (wikiPage != null) {
3186                            return wikiPage;
3187                    }
3188    
3189                    StringBundler msg = new StringBundler(6);
3190    
3191                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3192    
3193                    msg.append("resourcePrimKey=");
3194                    msg.append(resourcePrimKey);
3195    
3196                    msg.append(", nodeId=");
3197                    msg.append(nodeId);
3198    
3199                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3200    
3201                    throw new NoSuchPageException(msg.toString());
3202            }
3203    
3204            /**
3205             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
3206             *
3207             * @param resourcePrimKey the resource prim key
3208             * @param nodeId the node ID
3209             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3210             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
3211             * @throws SystemException if a system exception occurred
3212             */
3213            @Override
3214            public WikiPage fetchByR_N_First(long resourcePrimKey, long nodeId,
3215                    OrderByComparator orderByComparator) throws SystemException {
3216                    List<WikiPage> list = findByR_N(resourcePrimKey, nodeId, 0, 1,
3217                                    orderByComparator);
3218    
3219                    if (!list.isEmpty()) {
3220                            return list.get(0);
3221                    }
3222    
3223                    return null;
3224            }
3225    
3226            /**
3227             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
3228             *
3229             * @param resourcePrimKey the resource prim key
3230             * @param nodeId the node ID
3231             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3232             * @return the last matching wiki page
3233             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3234             * @throws SystemException if a system exception occurred
3235             */
3236            @Override
3237            public WikiPage findByR_N_Last(long resourcePrimKey, long nodeId,
3238                    OrderByComparator orderByComparator)
3239                    throws NoSuchPageException, SystemException {
3240                    WikiPage wikiPage = fetchByR_N_Last(resourcePrimKey, nodeId,
3241                                    orderByComparator);
3242    
3243                    if (wikiPage != null) {
3244                            return wikiPage;
3245                    }
3246    
3247                    StringBundler msg = new StringBundler(6);
3248    
3249                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3250    
3251                    msg.append("resourcePrimKey=");
3252                    msg.append(resourcePrimKey);
3253    
3254                    msg.append(", nodeId=");
3255                    msg.append(nodeId);
3256    
3257                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3258    
3259                    throw new NoSuchPageException(msg.toString());
3260            }
3261    
3262            /**
3263             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
3264             *
3265             * @param resourcePrimKey the resource prim key
3266             * @param nodeId the node ID
3267             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3268             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
3269             * @throws SystemException if a system exception occurred
3270             */
3271            @Override
3272            public WikiPage fetchByR_N_Last(long resourcePrimKey, long nodeId,
3273                    OrderByComparator orderByComparator) throws SystemException {
3274                    int count = countByR_N(resourcePrimKey, nodeId);
3275    
3276                    if (count == 0) {
3277                            return null;
3278                    }
3279    
3280                    List<WikiPage> list = findByR_N(resourcePrimKey, nodeId, count - 1,
3281                                    count, orderByComparator);
3282    
3283                    if (!list.isEmpty()) {
3284                            return list.get(0);
3285                    }
3286    
3287                    return null;
3288            }
3289    
3290            /**
3291             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63;.
3292             *
3293             * @param pageId the primary key of the current wiki page
3294             * @param resourcePrimKey the resource prim key
3295             * @param nodeId the node ID
3296             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3297             * @return the previous, current, and next wiki page
3298             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
3299             * @throws SystemException if a system exception occurred
3300             */
3301            @Override
3302            public WikiPage[] findByR_N_PrevAndNext(long pageId, long resourcePrimKey,
3303                    long nodeId, OrderByComparator orderByComparator)
3304                    throws NoSuchPageException, SystemException {
3305                    WikiPage wikiPage = findByPrimaryKey(pageId);
3306    
3307                    Session session = null;
3308    
3309                    try {
3310                            session = openSession();
3311    
3312                            WikiPage[] array = new WikiPageImpl[3];
3313    
3314                            array[0] = getByR_N_PrevAndNext(session, wikiPage, resourcePrimKey,
3315                                            nodeId, orderByComparator, true);
3316    
3317                            array[1] = wikiPage;
3318    
3319                            array[2] = getByR_N_PrevAndNext(session, wikiPage, resourcePrimKey,
3320                                            nodeId, orderByComparator, false);
3321    
3322                            return array;
3323                    }
3324                    catch (Exception e) {
3325                            throw processException(e);
3326                    }
3327                    finally {
3328                            closeSession(session);
3329                    }
3330            }
3331    
3332            protected WikiPage getByR_N_PrevAndNext(Session session, WikiPage wikiPage,
3333                    long resourcePrimKey, long nodeId, OrderByComparator orderByComparator,
3334                    boolean previous) {
3335                    StringBundler query = null;
3336    
3337                    if (orderByComparator != null) {
3338                            query = new StringBundler(6 +
3339                                            (orderByComparator.getOrderByFields().length * 6));
3340                    }
3341                    else {
3342                            query = new StringBundler(3);
3343                    }
3344    
3345                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3346    
3347                    query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
3348    
3349                    query.append(_FINDER_COLUMN_R_N_NODEID_2);
3350    
3351                    if (orderByComparator != null) {
3352                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3353    
3354                            if (orderByConditionFields.length > 0) {
3355                                    query.append(WHERE_AND);
3356                            }
3357    
3358                            for (int i = 0; i < orderByConditionFields.length; i++) {
3359                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3360                                    query.append(orderByConditionFields[i]);
3361    
3362                                    if ((i + 1) < orderByConditionFields.length) {
3363                                            if (orderByComparator.isAscending() ^ previous) {
3364                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3365                                            }
3366                                            else {
3367                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3368                                            }
3369                                    }
3370                                    else {
3371                                            if (orderByComparator.isAscending() ^ previous) {
3372                                                    query.append(WHERE_GREATER_THAN);
3373                                            }
3374                                            else {
3375                                                    query.append(WHERE_LESSER_THAN);
3376                                            }
3377                                    }
3378                            }
3379    
3380                            query.append(ORDER_BY_CLAUSE);
3381    
3382                            String[] orderByFields = orderByComparator.getOrderByFields();
3383    
3384                            for (int i = 0; i < orderByFields.length; i++) {
3385                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3386                                    query.append(orderByFields[i]);
3387    
3388                                    if ((i + 1) < orderByFields.length) {
3389                                            if (orderByComparator.isAscending() ^ previous) {
3390                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3391                                            }
3392                                            else {
3393                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3394                                            }
3395                                    }
3396                                    else {
3397                                            if (orderByComparator.isAscending() ^ previous) {
3398                                                    query.append(ORDER_BY_ASC);
3399                                            }
3400                                            else {
3401                                                    query.append(ORDER_BY_DESC);
3402                                            }
3403                                    }
3404                            }
3405                    }
3406                    else {
3407                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3408                    }
3409    
3410                    String sql = query.toString();
3411    
3412                    Query q = session.createQuery(sql);
3413    
3414                    q.setFirstResult(0);
3415                    q.setMaxResults(2);
3416    
3417                    QueryPos qPos = QueryPos.getInstance(q);
3418    
3419                    qPos.add(resourcePrimKey);
3420    
3421                    qPos.add(nodeId);
3422    
3423                    if (orderByComparator != null) {
3424                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
3425    
3426                            for (Object value : values) {
3427                                    qPos.add(value);
3428                            }
3429                    }
3430    
3431                    List<WikiPage> list = q.list();
3432    
3433                    if (list.size() == 2) {
3434                            return list.get(1);
3435                    }
3436                    else {
3437                            return null;
3438                    }
3439            }
3440    
3441            /**
3442             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; from the database.
3443             *
3444             * @param resourcePrimKey the resource prim key
3445             * @param nodeId the node ID
3446             * @throws SystemException if a system exception occurred
3447             */
3448            @Override
3449            public void removeByR_N(long resourcePrimKey, long nodeId)
3450                    throws SystemException {
3451                    for (WikiPage wikiPage : findByR_N(resourcePrimKey, nodeId,
3452                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3453                            remove(wikiPage);
3454                    }
3455            }
3456    
3457            /**
3458             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63;.
3459             *
3460             * @param resourcePrimKey the resource prim key
3461             * @param nodeId the node ID
3462             * @return the number of matching wiki pages
3463             * @throws SystemException if a system exception occurred
3464             */
3465            @Override
3466            public int countByR_N(long resourcePrimKey, long nodeId)
3467                    throws SystemException {
3468                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N;
3469    
3470                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId };
3471    
3472                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3473                                    this);
3474    
3475                    if (count == null) {
3476                            StringBundler query = new StringBundler(3);
3477    
3478                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
3479    
3480                            query.append(_FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2);
3481    
3482                            query.append(_FINDER_COLUMN_R_N_NODEID_2);
3483    
3484                            String sql = query.toString();
3485    
3486                            Session session = null;
3487    
3488                            try {
3489                                    session = openSession();
3490    
3491                                    Query q = session.createQuery(sql);
3492    
3493                                    QueryPos qPos = QueryPos.getInstance(q);
3494    
3495                                    qPos.add(resourcePrimKey);
3496    
3497                                    qPos.add(nodeId);
3498    
3499                                    count = (Long)q.uniqueResult();
3500    
3501                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3502                            }
3503                            catch (Exception e) {
3504                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3505    
3506                                    throw processException(e);
3507                            }
3508                            finally {
3509                                    closeSession(session);
3510                            }
3511                    }
3512    
3513                    return count.intValue();
3514            }
3515    
3516            private static final String _FINDER_COLUMN_R_N_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
3517            private static final String _FINDER_COLUMN_R_N_NODEID_2 = "wikiPage.nodeId = ?";
3518            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3519                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
3520                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_S",
3521                            new String[] {
3522                                    Long.class.getName(), Integer.class.getName(),
3523                                    
3524                            Integer.class.getName(), Integer.class.getName(),
3525                                    OrderByComparator.class.getName()
3526                            });
3527            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3528                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
3529                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_S",
3530                            new String[] { Long.class.getName(), Integer.class.getName() },
3531                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
3532                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
3533                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
3534                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
3535                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
3536            public static final FinderPath FINDER_PATH_COUNT_BY_R_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
3537                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3538                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_S",
3539                            new String[] { Long.class.getName(), Integer.class.getName() });
3540    
3541            /**
3542             * Returns all the wiki pages where resourcePrimKey = &#63; and status = &#63;.
3543             *
3544             * @param resourcePrimKey the resource prim key
3545             * @param status the status
3546             * @return the matching wiki pages
3547             * @throws SystemException if a system exception occurred
3548             */
3549            @Override
3550            public List<WikiPage> findByR_S(long resourcePrimKey, int status)
3551                    throws SystemException {
3552                    return findByR_S(resourcePrimKey, status, QueryUtil.ALL_POS,
3553                            QueryUtil.ALL_POS, null);
3554            }
3555    
3556            /**
3557             * Returns a range of all the wiki pages where resourcePrimKey = &#63; and status = &#63;.
3558             *
3559             * <p>
3560             * 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.
3561             * </p>
3562             *
3563             * @param resourcePrimKey the resource prim key
3564             * @param status the status
3565             * @param start the lower bound of the range of wiki pages
3566             * @param end the upper bound of the range of wiki pages (not inclusive)
3567             * @return the range of matching wiki pages
3568             * @throws SystemException if a system exception occurred
3569             */
3570            @Override
3571            public List<WikiPage> findByR_S(long resourcePrimKey, int status,
3572                    int start, int end) throws SystemException {
3573                    return findByR_S(resourcePrimKey, status, start, end, null);
3574            }
3575    
3576            /**
3577             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63; and status = &#63;.
3578             *
3579             * <p>
3580             * 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.
3581             * </p>
3582             *
3583             * @param resourcePrimKey the resource prim key
3584             * @param status the status
3585             * @param start the lower bound of the range of wiki pages
3586             * @param end the upper bound of the range of wiki pages (not inclusive)
3587             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3588             * @return the ordered range of matching wiki pages
3589             * @throws SystemException if a system exception occurred
3590             */
3591            @Override
3592            public List<WikiPage> findByR_S(long resourcePrimKey, int status,
3593                    int start, int end, OrderByComparator orderByComparator)
3594                    throws SystemException {
3595                    boolean pagination = true;
3596                    FinderPath finderPath = null;
3597                    Object[] finderArgs = null;
3598    
3599                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3600                                    (orderByComparator == null)) {
3601                            pagination = false;
3602                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S;
3603                            finderArgs = new Object[] { resourcePrimKey, status };
3604                    }
3605                    else {
3606                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S;
3607                            finderArgs = new Object[] {
3608                                            resourcePrimKey, status,
3609                                            
3610                                            start, end, orderByComparator
3611                                    };
3612                    }
3613    
3614                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
3615                                    finderArgs, this);
3616    
3617                    if ((list != null) && !list.isEmpty()) {
3618                            for (WikiPage wikiPage : list) {
3619                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
3620                                                    (status != wikiPage.getStatus())) {
3621                                            list = null;
3622    
3623                                            break;
3624                                    }
3625                            }
3626                    }
3627    
3628                    if (list == null) {
3629                            StringBundler query = null;
3630    
3631                            if (orderByComparator != null) {
3632                                    query = new StringBundler(4 +
3633                                                    (orderByComparator.getOrderByFields().length * 3));
3634                            }
3635                            else {
3636                                    query = new StringBundler(4);
3637                            }
3638    
3639                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3640    
3641                            query.append(_FINDER_COLUMN_R_S_RESOURCEPRIMKEY_2);
3642    
3643                            query.append(_FINDER_COLUMN_R_S_STATUS_2);
3644    
3645                            if (orderByComparator != null) {
3646                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3647                                            orderByComparator);
3648                            }
3649                            else
3650                             if (pagination) {
3651                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3652                            }
3653    
3654                            String sql = query.toString();
3655    
3656                            Session session = null;
3657    
3658                            try {
3659                                    session = openSession();
3660    
3661                                    Query q = session.createQuery(sql);
3662    
3663                                    QueryPos qPos = QueryPos.getInstance(q);
3664    
3665                                    qPos.add(resourcePrimKey);
3666    
3667                                    qPos.add(status);
3668    
3669                                    if (!pagination) {
3670                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3671                                                            start, end, false);
3672    
3673                                            Collections.sort(list);
3674    
3675                                            list = new UnmodifiableList<WikiPage>(list);
3676                                    }
3677                                    else {
3678                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
3679                                                            start, end);
3680                                    }
3681    
3682                                    cacheResult(list);
3683    
3684                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3685                            }
3686                            catch (Exception e) {
3687                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3688    
3689                                    throw processException(e);
3690                            }
3691                            finally {
3692                                    closeSession(session);
3693                            }
3694                    }
3695    
3696                    return list;
3697            }
3698    
3699            /**
3700             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and status = &#63;.
3701             *
3702             * @param resourcePrimKey the resource prim key
3703             * @param status the status
3704             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3705             * @return the first matching wiki page
3706             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3707             * @throws SystemException if a system exception occurred
3708             */
3709            @Override
3710            public WikiPage findByR_S_First(long resourcePrimKey, int status,
3711                    OrderByComparator orderByComparator)
3712                    throws NoSuchPageException, SystemException {
3713                    WikiPage wikiPage = fetchByR_S_First(resourcePrimKey, status,
3714                                    orderByComparator);
3715    
3716                    if (wikiPage != null) {
3717                            return wikiPage;
3718                    }
3719    
3720                    StringBundler msg = new StringBundler(6);
3721    
3722                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3723    
3724                    msg.append("resourcePrimKey=");
3725                    msg.append(resourcePrimKey);
3726    
3727                    msg.append(", status=");
3728                    msg.append(status);
3729    
3730                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3731    
3732                    throw new NoSuchPageException(msg.toString());
3733            }
3734    
3735            /**
3736             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and status = &#63;.
3737             *
3738             * @param resourcePrimKey the resource prim key
3739             * @param status the status
3740             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3741             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
3742             * @throws SystemException if a system exception occurred
3743             */
3744            @Override
3745            public WikiPage fetchByR_S_First(long resourcePrimKey, int status,
3746                    OrderByComparator orderByComparator) throws SystemException {
3747                    List<WikiPage> list = findByR_S(resourcePrimKey, status, 0, 1,
3748                                    orderByComparator);
3749    
3750                    if (!list.isEmpty()) {
3751                            return list.get(0);
3752                    }
3753    
3754                    return null;
3755            }
3756    
3757            /**
3758             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and status = &#63;.
3759             *
3760             * @param resourcePrimKey the resource prim key
3761             * @param status the status
3762             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3763             * @return the last matching wiki page
3764             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
3765             * @throws SystemException if a system exception occurred
3766             */
3767            @Override
3768            public WikiPage findByR_S_Last(long resourcePrimKey, int status,
3769                    OrderByComparator orderByComparator)
3770                    throws NoSuchPageException, SystemException {
3771                    WikiPage wikiPage = fetchByR_S_Last(resourcePrimKey, status,
3772                                    orderByComparator);
3773    
3774                    if (wikiPage != null) {
3775                            return wikiPage;
3776                    }
3777    
3778                    StringBundler msg = new StringBundler(6);
3779    
3780                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3781    
3782                    msg.append("resourcePrimKey=");
3783                    msg.append(resourcePrimKey);
3784    
3785                    msg.append(", status=");
3786                    msg.append(status);
3787    
3788                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3789    
3790                    throw new NoSuchPageException(msg.toString());
3791            }
3792    
3793            /**
3794             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and status = &#63;.
3795             *
3796             * @param resourcePrimKey the resource prim key
3797             * @param status the status
3798             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3799             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
3800             * @throws SystemException if a system exception occurred
3801             */
3802            @Override
3803            public WikiPage fetchByR_S_Last(long resourcePrimKey, int status,
3804                    OrderByComparator orderByComparator) throws SystemException {
3805                    int count = countByR_S(resourcePrimKey, status);
3806    
3807                    if (count == 0) {
3808                            return null;
3809                    }
3810    
3811                    List<WikiPage> list = findByR_S(resourcePrimKey, status, count - 1,
3812                                    count, orderByComparator);
3813    
3814                    if (!list.isEmpty()) {
3815                            return list.get(0);
3816                    }
3817    
3818                    return null;
3819            }
3820    
3821            /**
3822             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and status = &#63;.
3823             *
3824             * @param pageId the primary key of the current wiki page
3825             * @param resourcePrimKey the resource prim key
3826             * @param status the status
3827             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3828             * @return the previous, current, and next wiki page
3829             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
3830             * @throws SystemException if a system exception occurred
3831             */
3832            @Override
3833            public WikiPage[] findByR_S_PrevAndNext(long pageId, long resourcePrimKey,
3834                    int status, OrderByComparator orderByComparator)
3835                    throws NoSuchPageException, SystemException {
3836                    WikiPage wikiPage = findByPrimaryKey(pageId);
3837    
3838                    Session session = null;
3839    
3840                    try {
3841                            session = openSession();
3842    
3843                            WikiPage[] array = new WikiPageImpl[3];
3844    
3845                            array[0] = getByR_S_PrevAndNext(session, wikiPage, resourcePrimKey,
3846                                            status, orderByComparator, true);
3847    
3848                            array[1] = wikiPage;
3849    
3850                            array[2] = getByR_S_PrevAndNext(session, wikiPage, resourcePrimKey,
3851                                            status, orderByComparator, false);
3852    
3853                            return array;
3854                    }
3855                    catch (Exception e) {
3856                            throw processException(e);
3857                    }
3858                    finally {
3859                            closeSession(session);
3860                    }
3861            }
3862    
3863            protected WikiPage getByR_S_PrevAndNext(Session session, WikiPage wikiPage,
3864                    long resourcePrimKey, int status, OrderByComparator orderByComparator,
3865                    boolean previous) {
3866                    StringBundler query = null;
3867    
3868                    if (orderByComparator != null) {
3869                            query = new StringBundler(6 +
3870                                            (orderByComparator.getOrderByFields().length * 6));
3871                    }
3872                    else {
3873                            query = new StringBundler(3);
3874                    }
3875    
3876                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
3877    
3878                    query.append(_FINDER_COLUMN_R_S_RESOURCEPRIMKEY_2);
3879    
3880                    query.append(_FINDER_COLUMN_R_S_STATUS_2);
3881    
3882                    if (orderByComparator != null) {
3883                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3884    
3885                            if (orderByConditionFields.length > 0) {
3886                                    query.append(WHERE_AND);
3887                            }
3888    
3889                            for (int i = 0; i < orderByConditionFields.length; i++) {
3890                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3891                                    query.append(orderByConditionFields[i]);
3892    
3893                                    if ((i + 1) < orderByConditionFields.length) {
3894                                            if (orderByComparator.isAscending() ^ previous) {
3895                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3896                                            }
3897                                            else {
3898                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3899                                            }
3900                                    }
3901                                    else {
3902                                            if (orderByComparator.isAscending() ^ previous) {
3903                                                    query.append(WHERE_GREATER_THAN);
3904                                            }
3905                                            else {
3906                                                    query.append(WHERE_LESSER_THAN);
3907                                            }
3908                                    }
3909                            }
3910    
3911                            query.append(ORDER_BY_CLAUSE);
3912    
3913                            String[] orderByFields = orderByComparator.getOrderByFields();
3914    
3915                            for (int i = 0; i < orderByFields.length; i++) {
3916                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3917                                    query.append(orderByFields[i]);
3918    
3919                                    if ((i + 1) < orderByFields.length) {
3920                                            if (orderByComparator.isAscending() ^ previous) {
3921                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3922                                            }
3923                                            else {
3924                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3925                                            }
3926                                    }
3927                                    else {
3928                                            if (orderByComparator.isAscending() ^ previous) {
3929                                                    query.append(ORDER_BY_ASC);
3930                                            }
3931                                            else {
3932                                                    query.append(ORDER_BY_DESC);
3933                                            }
3934                                    }
3935                            }
3936                    }
3937                    else {
3938                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
3939                    }
3940    
3941                    String sql = query.toString();
3942    
3943                    Query q = session.createQuery(sql);
3944    
3945                    q.setFirstResult(0);
3946                    q.setMaxResults(2);
3947    
3948                    QueryPos qPos = QueryPos.getInstance(q);
3949    
3950                    qPos.add(resourcePrimKey);
3951    
3952                    qPos.add(status);
3953    
3954                    if (orderByComparator != null) {
3955                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
3956    
3957                            for (Object value : values) {
3958                                    qPos.add(value);
3959                            }
3960                    }
3961    
3962                    List<WikiPage> list = q.list();
3963    
3964                    if (list.size() == 2) {
3965                            return list.get(1);
3966                    }
3967                    else {
3968                            return null;
3969                    }
3970            }
3971    
3972            /**
3973             * Removes all the wiki pages where resourcePrimKey = &#63; and status = &#63; from the database.
3974             *
3975             * @param resourcePrimKey the resource prim key
3976             * @param status the status
3977             * @throws SystemException if a system exception occurred
3978             */
3979            @Override
3980            public void removeByR_S(long resourcePrimKey, int status)
3981                    throws SystemException {
3982                    for (WikiPage wikiPage : findByR_S(resourcePrimKey, status,
3983                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3984                            remove(wikiPage);
3985                    }
3986            }
3987    
3988            /**
3989             * Returns the number of wiki pages where resourcePrimKey = &#63; and status = &#63;.
3990             *
3991             * @param resourcePrimKey the resource prim key
3992             * @param status the status
3993             * @return the number of matching wiki pages
3994             * @throws SystemException if a system exception occurred
3995             */
3996            @Override
3997            public int countByR_S(long resourcePrimKey, int status)
3998                    throws SystemException {
3999                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_S;
4000    
4001                    Object[] finderArgs = new Object[] { resourcePrimKey, status };
4002    
4003                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4004                                    this);
4005    
4006                    if (count == null) {
4007                            StringBundler query = new StringBundler(3);
4008    
4009                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
4010    
4011                            query.append(_FINDER_COLUMN_R_S_RESOURCEPRIMKEY_2);
4012    
4013                            query.append(_FINDER_COLUMN_R_S_STATUS_2);
4014    
4015                            String sql = query.toString();
4016    
4017                            Session session = null;
4018    
4019                            try {
4020                                    session = openSession();
4021    
4022                                    Query q = session.createQuery(sql);
4023    
4024                                    QueryPos qPos = QueryPos.getInstance(q);
4025    
4026                                    qPos.add(resourcePrimKey);
4027    
4028                                    qPos.add(status);
4029    
4030                                    count = (Long)q.uniqueResult();
4031    
4032                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4033                            }
4034                            catch (Exception e) {
4035                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4036    
4037                                    throw processException(e);
4038                            }
4039                            finally {
4040                                    closeSession(session);
4041                            }
4042                    }
4043    
4044                    return count.intValue();
4045            }
4046    
4047            private static final String _FINDER_COLUMN_R_S_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
4048            private static final String _FINDER_COLUMN_R_S_STATUS_2 = "wikiPage.status = ?";
4049            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4050                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4051                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_T",
4052                            new String[] {
4053                                    Long.class.getName(), String.class.getName(),
4054                                    
4055                            Integer.class.getName(), Integer.class.getName(),
4056                                    OrderByComparator.class.getName()
4057                            });
4058            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4059                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4060                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_T",
4061                            new String[] { Long.class.getName(), String.class.getName() },
4062                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
4063                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
4064                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
4065            public static final FinderPath FINDER_PATH_COUNT_BY_N_T = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4066                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4067                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T",
4068                            new String[] { Long.class.getName(), String.class.getName() });
4069    
4070            /**
4071             * Returns all the wiki pages where nodeId = &#63; and title = &#63;.
4072             *
4073             * @param nodeId the node ID
4074             * @param title the title
4075             * @return the matching wiki pages
4076             * @throws SystemException if a system exception occurred
4077             */
4078            @Override
4079            public List<WikiPage> findByN_T(long nodeId, String title)
4080                    throws SystemException {
4081                    return findByN_T(nodeId, title, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4082                            null);
4083            }
4084    
4085            /**
4086             * Returns a range of all the wiki pages where nodeId = &#63; and title = &#63;.
4087             *
4088             * <p>
4089             * 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.
4090             * </p>
4091             *
4092             * @param nodeId the node ID
4093             * @param title the title
4094             * @param start the lower bound of the range of wiki pages
4095             * @param end the upper bound of the range of wiki pages (not inclusive)
4096             * @return the range of matching wiki pages
4097             * @throws SystemException if a system exception occurred
4098             */
4099            @Override
4100            public List<WikiPage> findByN_T(long nodeId, String title, int start,
4101                    int end) throws SystemException {
4102                    return findByN_T(nodeId, title, start, end, null);
4103            }
4104    
4105            /**
4106             * Returns an ordered range of all the wiki pages where nodeId = &#63; and title = &#63;.
4107             *
4108             * <p>
4109             * 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.
4110             * </p>
4111             *
4112             * @param nodeId the node ID
4113             * @param title the title
4114             * @param start the lower bound of the range of wiki pages
4115             * @param end the upper bound of the range of wiki pages (not inclusive)
4116             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4117             * @return the ordered range of matching wiki pages
4118             * @throws SystemException if a system exception occurred
4119             */
4120            @Override
4121            public List<WikiPage> findByN_T(long nodeId, String title, int start,
4122                    int end, OrderByComparator orderByComparator) throws SystemException {
4123                    boolean pagination = true;
4124                    FinderPath finderPath = null;
4125                    Object[] finderArgs = null;
4126    
4127                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4128                                    (orderByComparator == null)) {
4129                            pagination = false;
4130                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T;
4131                            finderArgs = new Object[] { nodeId, title };
4132                    }
4133                    else {
4134                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T;
4135                            finderArgs = new Object[] {
4136                                            nodeId, title,
4137                                            
4138                                            start, end, orderByComparator
4139                                    };
4140                    }
4141    
4142                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
4143                                    finderArgs, this);
4144    
4145                    if ((list != null) && !list.isEmpty()) {
4146                            for (WikiPage wikiPage : list) {
4147                                    if ((nodeId != wikiPage.getNodeId()) ||
4148                                                    !Validator.equals(title, wikiPage.getTitle())) {
4149                                            list = null;
4150    
4151                                            break;
4152                                    }
4153                            }
4154                    }
4155    
4156                    if (list == null) {
4157                            StringBundler query = null;
4158    
4159                            if (orderByComparator != null) {
4160                                    query = new StringBundler(4 +
4161                                                    (orderByComparator.getOrderByFields().length * 3));
4162                            }
4163                            else {
4164                                    query = new StringBundler(4);
4165                            }
4166    
4167                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4168    
4169                            query.append(_FINDER_COLUMN_N_T_NODEID_2);
4170    
4171                            boolean bindTitle = false;
4172    
4173                            if (title == null) {
4174                                    query.append(_FINDER_COLUMN_N_T_TITLE_1);
4175                            }
4176                            else if (title.equals(StringPool.BLANK)) {
4177                                    query.append(_FINDER_COLUMN_N_T_TITLE_3);
4178                            }
4179                            else {
4180                                    bindTitle = true;
4181    
4182                                    query.append(_FINDER_COLUMN_N_T_TITLE_2);
4183                            }
4184    
4185                            if (orderByComparator != null) {
4186                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4187                                            orderByComparator);
4188                            }
4189                            else
4190                             if (pagination) {
4191                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4192                            }
4193    
4194                            String sql = query.toString();
4195    
4196                            Session session = null;
4197    
4198                            try {
4199                                    session = openSession();
4200    
4201                                    Query q = session.createQuery(sql);
4202    
4203                                    QueryPos qPos = QueryPos.getInstance(q);
4204    
4205                                    qPos.add(nodeId);
4206    
4207                                    if (bindTitle) {
4208                                            qPos.add(title.toLowerCase());
4209                                    }
4210    
4211                                    if (!pagination) {
4212                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4213                                                            start, end, false);
4214    
4215                                            Collections.sort(list);
4216    
4217                                            list = new UnmodifiableList<WikiPage>(list);
4218                                    }
4219                                    else {
4220                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4221                                                            start, end);
4222                                    }
4223    
4224                                    cacheResult(list);
4225    
4226                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4227                            }
4228                            catch (Exception e) {
4229                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4230    
4231                                    throw processException(e);
4232                            }
4233                            finally {
4234                                    closeSession(session);
4235                            }
4236                    }
4237    
4238                    return list;
4239            }
4240    
4241            /**
4242             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63;.
4243             *
4244             * @param nodeId the node ID
4245             * @param title the title
4246             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4247             * @return the first matching wiki page
4248             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4249             * @throws SystemException if a system exception occurred
4250             */
4251            @Override
4252            public WikiPage findByN_T_First(long nodeId, String title,
4253                    OrderByComparator orderByComparator)
4254                    throws NoSuchPageException, SystemException {
4255                    WikiPage wikiPage = fetchByN_T_First(nodeId, title, orderByComparator);
4256    
4257                    if (wikiPage != null) {
4258                            return wikiPage;
4259                    }
4260    
4261                    StringBundler msg = new StringBundler(6);
4262    
4263                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4264    
4265                    msg.append("nodeId=");
4266                    msg.append(nodeId);
4267    
4268                    msg.append(", title=");
4269                    msg.append(title);
4270    
4271                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4272    
4273                    throw new NoSuchPageException(msg.toString());
4274            }
4275    
4276            /**
4277             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63;.
4278             *
4279             * @param nodeId the node ID
4280             * @param title the title
4281             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4282             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
4283             * @throws SystemException if a system exception occurred
4284             */
4285            @Override
4286            public WikiPage fetchByN_T_First(long nodeId, String title,
4287                    OrderByComparator orderByComparator) throws SystemException {
4288                    List<WikiPage> list = findByN_T(nodeId, title, 0, 1, orderByComparator);
4289    
4290                    if (!list.isEmpty()) {
4291                            return list.get(0);
4292                    }
4293    
4294                    return null;
4295            }
4296    
4297            /**
4298             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63;.
4299             *
4300             * @param nodeId the node ID
4301             * @param title the title
4302             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4303             * @return the last matching wiki page
4304             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4305             * @throws SystemException if a system exception occurred
4306             */
4307            @Override
4308            public WikiPage findByN_T_Last(long nodeId, String title,
4309                    OrderByComparator orderByComparator)
4310                    throws NoSuchPageException, SystemException {
4311                    WikiPage wikiPage = fetchByN_T_Last(nodeId, title, orderByComparator);
4312    
4313                    if (wikiPage != null) {
4314                            return wikiPage;
4315                    }
4316    
4317                    StringBundler msg = new StringBundler(6);
4318    
4319                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4320    
4321                    msg.append("nodeId=");
4322                    msg.append(nodeId);
4323    
4324                    msg.append(", title=");
4325                    msg.append(title);
4326    
4327                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4328    
4329                    throw new NoSuchPageException(msg.toString());
4330            }
4331    
4332            /**
4333             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63;.
4334             *
4335             * @param nodeId the node ID
4336             * @param title the title
4337             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4338             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
4339             * @throws SystemException if a system exception occurred
4340             */
4341            @Override
4342            public WikiPage fetchByN_T_Last(long nodeId, String title,
4343                    OrderByComparator orderByComparator) throws SystemException {
4344                    int count = countByN_T(nodeId, title);
4345    
4346                    if (count == 0) {
4347                            return null;
4348                    }
4349    
4350                    List<WikiPage> list = findByN_T(nodeId, title, count - 1, count,
4351                                    orderByComparator);
4352    
4353                    if (!list.isEmpty()) {
4354                            return list.get(0);
4355                    }
4356    
4357                    return null;
4358            }
4359    
4360            /**
4361             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63;.
4362             *
4363             * @param pageId the primary key of the current wiki page
4364             * @param nodeId the node ID
4365             * @param title the title
4366             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4367             * @return the previous, current, and next wiki page
4368             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
4369             * @throws SystemException if a system exception occurred
4370             */
4371            @Override
4372            public WikiPage[] findByN_T_PrevAndNext(long pageId, long nodeId,
4373                    String title, OrderByComparator orderByComparator)
4374                    throws NoSuchPageException, SystemException {
4375                    WikiPage wikiPage = findByPrimaryKey(pageId);
4376    
4377                    Session session = null;
4378    
4379                    try {
4380                            session = openSession();
4381    
4382                            WikiPage[] array = new WikiPageImpl[3];
4383    
4384                            array[0] = getByN_T_PrevAndNext(session, wikiPage, nodeId, title,
4385                                            orderByComparator, true);
4386    
4387                            array[1] = wikiPage;
4388    
4389                            array[2] = getByN_T_PrevAndNext(session, wikiPage, nodeId, title,
4390                                            orderByComparator, false);
4391    
4392                            return array;
4393                    }
4394                    catch (Exception e) {
4395                            throw processException(e);
4396                    }
4397                    finally {
4398                            closeSession(session);
4399                    }
4400            }
4401    
4402            protected WikiPage getByN_T_PrevAndNext(Session session, WikiPage wikiPage,
4403                    long nodeId, String title, OrderByComparator orderByComparator,
4404                    boolean previous) {
4405                    StringBundler query = null;
4406    
4407                    if (orderByComparator != null) {
4408                            query = new StringBundler(6 +
4409                                            (orderByComparator.getOrderByFields().length * 6));
4410                    }
4411                    else {
4412                            query = new StringBundler(3);
4413                    }
4414    
4415                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4416    
4417                    query.append(_FINDER_COLUMN_N_T_NODEID_2);
4418    
4419                    boolean bindTitle = false;
4420    
4421                    if (title == null) {
4422                            query.append(_FINDER_COLUMN_N_T_TITLE_1);
4423                    }
4424                    else if (title.equals(StringPool.BLANK)) {
4425                            query.append(_FINDER_COLUMN_N_T_TITLE_3);
4426                    }
4427                    else {
4428                            bindTitle = true;
4429    
4430                            query.append(_FINDER_COLUMN_N_T_TITLE_2);
4431                    }
4432    
4433                    if (orderByComparator != null) {
4434                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4435    
4436                            if (orderByConditionFields.length > 0) {
4437                                    query.append(WHERE_AND);
4438                            }
4439    
4440                            for (int i = 0; i < orderByConditionFields.length; i++) {
4441                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4442                                    query.append(orderByConditionFields[i]);
4443    
4444                                    if ((i + 1) < orderByConditionFields.length) {
4445                                            if (orderByComparator.isAscending() ^ previous) {
4446                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4447                                            }
4448                                            else {
4449                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4450                                            }
4451                                    }
4452                                    else {
4453                                            if (orderByComparator.isAscending() ^ previous) {
4454                                                    query.append(WHERE_GREATER_THAN);
4455                                            }
4456                                            else {
4457                                                    query.append(WHERE_LESSER_THAN);
4458                                            }
4459                                    }
4460                            }
4461    
4462                            query.append(ORDER_BY_CLAUSE);
4463    
4464                            String[] orderByFields = orderByComparator.getOrderByFields();
4465    
4466                            for (int i = 0; i < orderByFields.length; i++) {
4467                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4468                                    query.append(orderByFields[i]);
4469    
4470                                    if ((i + 1) < orderByFields.length) {
4471                                            if (orderByComparator.isAscending() ^ previous) {
4472                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4473                                            }
4474                                            else {
4475                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4476                                            }
4477                                    }
4478                                    else {
4479                                            if (orderByComparator.isAscending() ^ previous) {
4480                                                    query.append(ORDER_BY_ASC);
4481                                            }
4482                                            else {
4483                                                    query.append(ORDER_BY_DESC);
4484                                            }
4485                                    }
4486                            }
4487                    }
4488                    else {
4489                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4490                    }
4491    
4492                    String sql = query.toString();
4493    
4494                    Query q = session.createQuery(sql);
4495    
4496                    q.setFirstResult(0);
4497                    q.setMaxResults(2);
4498    
4499                    QueryPos qPos = QueryPos.getInstance(q);
4500    
4501                    qPos.add(nodeId);
4502    
4503                    if (bindTitle) {
4504                            qPos.add(title.toLowerCase());
4505                    }
4506    
4507                    if (orderByComparator != null) {
4508                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
4509    
4510                            for (Object value : values) {
4511                                    qPos.add(value);
4512                            }
4513                    }
4514    
4515                    List<WikiPage> list = q.list();
4516    
4517                    if (list.size() == 2) {
4518                            return list.get(1);
4519                    }
4520                    else {
4521                            return null;
4522                    }
4523            }
4524    
4525            /**
4526             * Removes all the wiki pages where nodeId = &#63; and title = &#63; from the database.
4527             *
4528             * @param nodeId the node ID
4529             * @param title the title
4530             * @throws SystemException if a system exception occurred
4531             */
4532            @Override
4533            public void removeByN_T(long nodeId, String title)
4534                    throws SystemException {
4535                    for (WikiPage wikiPage : findByN_T(nodeId, title, QueryUtil.ALL_POS,
4536                                    QueryUtil.ALL_POS, null)) {
4537                            remove(wikiPage);
4538                    }
4539            }
4540    
4541            /**
4542             * Returns the number of wiki pages where nodeId = &#63; and title = &#63;.
4543             *
4544             * @param nodeId the node ID
4545             * @param title the title
4546             * @return the number of matching wiki pages
4547             * @throws SystemException if a system exception occurred
4548             */
4549            @Override
4550            public int countByN_T(long nodeId, String title) throws SystemException {
4551                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T;
4552    
4553                    Object[] finderArgs = new Object[] { nodeId, title };
4554    
4555                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4556                                    this);
4557    
4558                    if (count == null) {
4559                            StringBundler query = new StringBundler(3);
4560    
4561                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
4562    
4563                            query.append(_FINDER_COLUMN_N_T_NODEID_2);
4564    
4565                            boolean bindTitle = false;
4566    
4567                            if (title == null) {
4568                                    query.append(_FINDER_COLUMN_N_T_TITLE_1);
4569                            }
4570                            else if (title.equals(StringPool.BLANK)) {
4571                                    query.append(_FINDER_COLUMN_N_T_TITLE_3);
4572                            }
4573                            else {
4574                                    bindTitle = true;
4575    
4576                                    query.append(_FINDER_COLUMN_N_T_TITLE_2);
4577                            }
4578    
4579                            String sql = query.toString();
4580    
4581                            Session session = null;
4582    
4583                            try {
4584                                    session = openSession();
4585    
4586                                    Query q = session.createQuery(sql);
4587    
4588                                    QueryPos qPos = QueryPos.getInstance(q);
4589    
4590                                    qPos.add(nodeId);
4591    
4592                                    if (bindTitle) {
4593                                            qPos.add(title.toLowerCase());
4594                                    }
4595    
4596                                    count = (Long)q.uniqueResult();
4597    
4598                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4599                            }
4600                            catch (Exception e) {
4601                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4602    
4603                                    throw processException(e);
4604                            }
4605                            finally {
4606                                    closeSession(session);
4607                            }
4608                    }
4609    
4610                    return count.intValue();
4611            }
4612    
4613            private static final String _FINDER_COLUMN_N_T_NODEID_2 = "wikiPage.nodeId = ? AND ";
4614            private static final String _FINDER_COLUMN_N_T_TITLE_1 = "wikiPage.title IS NULL";
4615            private static final String _FINDER_COLUMN_N_T_TITLE_2 = "lower(wikiPage.title) = ?";
4616            private static final String _FINDER_COLUMN_N_T_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '')";
4617            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4618                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4619                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H",
4620                            new String[] {
4621                                    Long.class.getName(), Boolean.class.getName(),
4622                                    
4623                            Integer.class.getName(), Integer.class.getName(),
4624                                    OrderByComparator.class.getName()
4625                            });
4626            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4627                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
4628                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H",
4629                            new String[] { Long.class.getName(), Boolean.class.getName() },
4630                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
4631                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
4632                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
4633                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
4634            public static final FinderPath FINDER_PATH_COUNT_BY_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
4635                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4636                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H",
4637                            new String[] { Long.class.getName(), Boolean.class.getName() });
4638    
4639            /**
4640             * Returns all the wiki pages where nodeId = &#63; and head = &#63;.
4641             *
4642             * @param nodeId the node ID
4643             * @param head the head
4644             * @return the matching wiki pages
4645             * @throws SystemException if a system exception occurred
4646             */
4647            @Override
4648            public List<WikiPage> findByN_H(long nodeId, boolean head)
4649                    throws SystemException {
4650                    return findByN_H(nodeId, head, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4651                            null);
4652            }
4653    
4654            /**
4655             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63;.
4656             *
4657             * <p>
4658             * 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.
4659             * </p>
4660             *
4661             * @param nodeId the node ID
4662             * @param head the head
4663             * @param start the lower bound of the range of wiki pages
4664             * @param end the upper bound of the range of wiki pages (not inclusive)
4665             * @return the range of matching wiki pages
4666             * @throws SystemException if a system exception occurred
4667             */
4668            @Override
4669            public List<WikiPage> findByN_H(long nodeId, boolean head, int start,
4670                    int end) throws SystemException {
4671                    return findByN_H(nodeId, head, start, end, null);
4672            }
4673    
4674            /**
4675             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63;.
4676             *
4677             * <p>
4678             * 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.
4679             * </p>
4680             *
4681             * @param nodeId the node ID
4682             * @param head the head
4683             * @param start the lower bound of the range of wiki pages
4684             * @param end the upper bound of the range of wiki pages (not inclusive)
4685             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4686             * @return the ordered range of matching wiki pages
4687             * @throws SystemException if a system exception occurred
4688             */
4689            @Override
4690            public List<WikiPage> findByN_H(long nodeId, boolean head, int start,
4691                    int end, OrderByComparator orderByComparator) throws SystemException {
4692                    boolean pagination = true;
4693                    FinderPath finderPath = null;
4694                    Object[] finderArgs = null;
4695    
4696                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4697                                    (orderByComparator == null)) {
4698                            pagination = false;
4699                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H;
4700                            finderArgs = new Object[] { nodeId, head };
4701                    }
4702                    else {
4703                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H;
4704                            finderArgs = new Object[] {
4705                                            nodeId, head,
4706                                            
4707                                            start, end, orderByComparator
4708                                    };
4709                    }
4710    
4711                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
4712                                    finderArgs, this);
4713    
4714                    if ((list != null) && !list.isEmpty()) {
4715                            for (WikiPage wikiPage : list) {
4716                                    if ((nodeId != wikiPage.getNodeId()) ||
4717                                                    (head != wikiPage.getHead())) {
4718                                            list = null;
4719    
4720                                            break;
4721                                    }
4722                            }
4723                    }
4724    
4725                    if (list == null) {
4726                            StringBundler query = null;
4727    
4728                            if (orderByComparator != null) {
4729                                    query = new StringBundler(4 +
4730                                                    (orderByComparator.getOrderByFields().length * 3));
4731                            }
4732                            else {
4733                                    query = new StringBundler(4);
4734                            }
4735    
4736                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4737    
4738                            query.append(_FINDER_COLUMN_N_H_NODEID_2);
4739    
4740                            query.append(_FINDER_COLUMN_N_H_HEAD_2);
4741    
4742                            if (orderByComparator != null) {
4743                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4744                                            orderByComparator);
4745                            }
4746                            else
4747                             if (pagination) {
4748                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
4749                            }
4750    
4751                            String sql = query.toString();
4752    
4753                            Session session = null;
4754    
4755                            try {
4756                                    session = openSession();
4757    
4758                                    Query q = session.createQuery(sql);
4759    
4760                                    QueryPos qPos = QueryPos.getInstance(q);
4761    
4762                                    qPos.add(nodeId);
4763    
4764                                    qPos.add(head);
4765    
4766                                    if (!pagination) {
4767                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4768                                                            start, end, false);
4769    
4770                                            Collections.sort(list);
4771    
4772                                            list = new UnmodifiableList<WikiPage>(list);
4773                                    }
4774                                    else {
4775                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
4776                                                            start, end);
4777                                    }
4778    
4779                                    cacheResult(list);
4780    
4781                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4782                            }
4783                            catch (Exception e) {
4784                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4785    
4786                                    throw processException(e);
4787                            }
4788                            finally {
4789                                    closeSession(session);
4790                            }
4791                    }
4792    
4793                    return list;
4794            }
4795    
4796            /**
4797             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63;.
4798             *
4799             * @param nodeId the node ID
4800             * @param head the head
4801             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4802             * @return the first matching wiki page
4803             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4804             * @throws SystemException if a system exception occurred
4805             */
4806            @Override
4807            public WikiPage findByN_H_First(long nodeId, boolean head,
4808                    OrderByComparator orderByComparator)
4809                    throws NoSuchPageException, SystemException {
4810                    WikiPage wikiPage = fetchByN_H_First(nodeId, head, orderByComparator);
4811    
4812                    if (wikiPage != null) {
4813                            return wikiPage;
4814                    }
4815    
4816                    StringBundler msg = new StringBundler(6);
4817    
4818                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4819    
4820                    msg.append("nodeId=");
4821                    msg.append(nodeId);
4822    
4823                    msg.append(", head=");
4824                    msg.append(head);
4825    
4826                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4827    
4828                    throw new NoSuchPageException(msg.toString());
4829            }
4830    
4831            /**
4832             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63;.
4833             *
4834             * @param nodeId the node ID
4835             * @param head the head
4836             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4837             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
4838             * @throws SystemException if a system exception occurred
4839             */
4840            @Override
4841            public WikiPage fetchByN_H_First(long nodeId, boolean head,
4842                    OrderByComparator orderByComparator) throws SystemException {
4843                    List<WikiPage> list = findByN_H(nodeId, head, 0, 1, orderByComparator);
4844    
4845                    if (!list.isEmpty()) {
4846                            return list.get(0);
4847                    }
4848    
4849                    return null;
4850            }
4851    
4852            /**
4853             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63;.
4854             *
4855             * @param nodeId the node ID
4856             * @param head the head
4857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4858             * @return the last matching wiki page
4859             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
4860             * @throws SystemException if a system exception occurred
4861             */
4862            @Override
4863            public WikiPage findByN_H_Last(long nodeId, boolean head,
4864                    OrderByComparator orderByComparator)
4865                    throws NoSuchPageException, SystemException {
4866                    WikiPage wikiPage = fetchByN_H_Last(nodeId, head, orderByComparator);
4867    
4868                    if (wikiPage != null) {
4869                            return wikiPage;
4870                    }
4871    
4872                    StringBundler msg = new StringBundler(6);
4873    
4874                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4875    
4876                    msg.append("nodeId=");
4877                    msg.append(nodeId);
4878    
4879                    msg.append(", head=");
4880                    msg.append(head);
4881    
4882                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4883    
4884                    throw new NoSuchPageException(msg.toString());
4885            }
4886    
4887            /**
4888             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63;.
4889             *
4890             * @param nodeId the node ID
4891             * @param head the head
4892             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4893             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
4894             * @throws SystemException if a system exception occurred
4895             */
4896            @Override
4897            public WikiPage fetchByN_H_Last(long nodeId, boolean head,
4898                    OrderByComparator orderByComparator) throws SystemException {
4899                    int count = countByN_H(nodeId, head);
4900    
4901                    if (count == 0) {
4902                            return null;
4903                    }
4904    
4905                    List<WikiPage> list = findByN_H(nodeId, head, count - 1, count,
4906                                    orderByComparator);
4907    
4908                    if (!list.isEmpty()) {
4909                            return list.get(0);
4910                    }
4911    
4912                    return null;
4913            }
4914    
4915            /**
4916             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63;.
4917             *
4918             * @param pageId the primary key of the current wiki page
4919             * @param nodeId the node ID
4920             * @param head the head
4921             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4922             * @return the previous, current, and next wiki page
4923             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
4924             * @throws SystemException if a system exception occurred
4925             */
4926            @Override
4927            public WikiPage[] findByN_H_PrevAndNext(long pageId, long nodeId,
4928                    boolean head, OrderByComparator orderByComparator)
4929                    throws NoSuchPageException, SystemException {
4930                    WikiPage wikiPage = findByPrimaryKey(pageId);
4931    
4932                    Session session = null;
4933    
4934                    try {
4935                            session = openSession();
4936    
4937                            WikiPage[] array = new WikiPageImpl[3];
4938    
4939                            array[0] = getByN_H_PrevAndNext(session, wikiPage, nodeId, head,
4940                                            orderByComparator, true);
4941    
4942                            array[1] = wikiPage;
4943    
4944                            array[2] = getByN_H_PrevAndNext(session, wikiPage, nodeId, head,
4945                                            orderByComparator, false);
4946    
4947                            return array;
4948                    }
4949                    catch (Exception e) {
4950                            throw processException(e);
4951                    }
4952                    finally {
4953                            closeSession(session);
4954                    }
4955            }
4956    
4957            protected WikiPage getByN_H_PrevAndNext(Session session, WikiPage wikiPage,
4958                    long nodeId, boolean head, OrderByComparator orderByComparator,
4959                    boolean previous) {
4960                    StringBundler query = null;
4961    
4962                    if (orderByComparator != null) {
4963                            query = new StringBundler(6 +
4964                                            (orderByComparator.getOrderByFields().length * 6));
4965                    }
4966                    else {
4967                            query = new StringBundler(3);
4968                    }
4969    
4970                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
4971    
4972                    query.append(_FINDER_COLUMN_N_H_NODEID_2);
4973    
4974                    query.append(_FINDER_COLUMN_N_H_HEAD_2);
4975    
4976                    if (orderByComparator != null) {
4977                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4978    
4979                            if (orderByConditionFields.length > 0) {
4980                                    query.append(WHERE_AND);
4981                            }
4982    
4983                            for (int i = 0; i < orderByConditionFields.length; i++) {
4984                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4985                                    query.append(orderByConditionFields[i]);
4986    
4987                                    if ((i + 1) < orderByConditionFields.length) {
4988                                            if (orderByComparator.isAscending() ^ previous) {
4989                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4990                                            }
4991                                            else {
4992                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4993                                            }
4994                                    }
4995                                    else {
4996                                            if (orderByComparator.isAscending() ^ previous) {
4997                                                    query.append(WHERE_GREATER_THAN);
4998                                            }
4999                                            else {
5000                                                    query.append(WHERE_LESSER_THAN);
5001                                            }
5002                                    }
5003                            }
5004    
5005                            query.append(ORDER_BY_CLAUSE);
5006    
5007                            String[] orderByFields = orderByComparator.getOrderByFields();
5008    
5009                            for (int i = 0; i < orderByFields.length; i++) {
5010                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5011                                    query.append(orderByFields[i]);
5012    
5013                                    if ((i + 1) < orderByFields.length) {
5014                                            if (orderByComparator.isAscending() ^ previous) {
5015                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5016                                            }
5017                                            else {
5018                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5019                                            }
5020                                    }
5021                                    else {
5022                                            if (orderByComparator.isAscending() ^ previous) {
5023                                                    query.append(ORDER_BY_ASC);
5024                                            }
5025                                            else {
5026                                                    query.append(ORDER_BY_DESC);
5027                                            }
5028                                    }
5029                            }
5030                    }
5031                    else {
5032                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5033                    }
5034    
5035                    String sql = query.toString();
5036    
5037                    Query q = session.createQuery(sql);
5038    
5039                    q.setFirstResult(0);
5040                    q.setMaxResults(2);
5041    
5042                    QueryPos qPos = QueryPos.getInstance(q);
5043    
5044                    qPos.add(nodeId);
5045    
5046                    qPos.add(head);
5047    
5048                    if (orderByComparator != null) {
5049                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
5050    
5051                            for (Object value : values) {
5052                                    qPos.add(value);
5053                            }
5054                    }
5055    
5056                    List<WikiPage> list = q.list();
5057    
5058                    if (list.size() == 2) {
5059                            return list.get(1);
5060                    }
5061                    else {
5062                            return null;
5063                    }
5064            }
5065    
5066            /**
5067             * Removes all the wiki pages where nodeId = &#63; and head = &#63; from the database.
5068             *
5069             * @param nodeId the node ID
5070             * @param head the head
5071             * @throws SystemException if a system exception occurred
5072             */
5073            @Override
5074            public void removeByN_H(long nodeId, boolean head)
5075                    throws SystemException {
5076                    for (WikiPage wikiPage : findByN_H(nodeId, head, QueryUtil.ALL_POS,
5077                                    QueryUtil.ALL_POS, null)) {
5078                            remove(wikiPage);
5079                    }
5080            }
5081    
5082            /**
5083             * Returns the number of wiki pages where nodeId = &#63; and head = &#63;.
5084             *
5085             * @param nodeId the node ID
5086             * @param head the head
5087             * @return the number of matching wiki pages
5088             * @throws SystemException if a system exception occurred
5089             */
5090            @Override
5091            public int countByN_H(long nodeId, boolean head) throws SystemException {
5092                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H;
5093    
5094                    Object[] finderArgs = new Object[] { nodeId, head };
5095    
5096                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5097                                    this);
5098    
5099                    if (count == null) {
5100                            StringBundler query = new StringBundler(3);
5101    
5102                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
5103    
5104                            query.append(_FINDER_COLUMN_N_H_NODEID_2);
5105    
5106                            query.append(_FINDER_COLUMN_N_H_HEAD_2);
5107    
5108                            String sql = query.toString();
5109    
5110                            Session session = null;
5111    
5112                            try {
5113                                    session = openSession();
5114    
5115                                    Query q = session.createQuery(sql);
5116    
5117                                    QueryPos qPos = QueryPos.getInstance(q);
5118    
5119                                    qPos.add(nodeId);
5120    
5121                                    qPos.add(head);
5122    
5123                                    count = (Long)q.uniqueResult();
5124    
5125                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5126                            }
5127                            catch (Exception e) {
5128                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5129    
5130                                    throw processException(e);
5131                            }
5132                            finally {
5133                                    closeSession(session);
5134                            }
5135                    }
5136    
5137                    return count.intValue();
5138            }
5139    
5140            private static final String _FINDER_COLUMN_N_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
5141            private static final String _FINDER_COLUMN_N_H_HEAD_2 = "wikiPage.head = ?";
5142            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5143                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5144                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_P",
5145                            new String[] {
5146                                    Long.class.getName(), String.class.getName(),
5147                                    
5148                            Integer.class.getName(), Integer.class.getName(),
5149                                    OrderByComparator.class.getName()
5150                            });
5151            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5152                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5153                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_P",
5154                            new String[] { Long.class.getName(), String.class.getName() },
5155                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
5156                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
5157                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
5158                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
5159            public static final FinderPath FINDER_PATH_COUNT_BY_N_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5160                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5161                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_P",
5162                            new String[] { Long.class.getName(), String.class.getName() });
5163    
5164            /**
5165             * Returns all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
5166             *
5167             * @param nodeId the node ID
5168             * @param parentTitle the parent title
5169             * @return the matching wiki pages
5170             * @throws SystemException if a system exception occurred
5171             */
5172            @Override
5173            public List<WikiPage> findByN_P(long nodeId, String parentTitle)
5174                    throws SystemException {
5175                    return findByN_P(nodeId, parentTitle, QueryUtil.ALL_POS,
5176                            QueryUtil.ALL_POS, null);
5177            }
5178    
5179            /**
5180             * Returns a range of all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
5181             *
5182             * <p>
5183             * 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.
5184             * </p>
5185             *
5186             * @param nodeId the node ID
5187             * @param parentTitle the parent title
5188             * @param start the lower bound of the range of wiki pages
5189             * @param end the upper bound of the range of wiki pages (not inclusive)
5190             * @return the range of matching wiki pages
5191             * @throws SystemException if a system exception occurred
5192             */
5193            @Override
5194            public List<WikiPage> findByN_P(long nodeId, String parentTitle, int start,
5195                    int end) throws SystemException {
5196                    return findByN_P(nodeId, parentTitle, start, end, null);
5197            }
5198    
5199            /**
5200             * Returns an ordered range of all the wiki pages where nodeId = &#63; and parentTitle = &#63;.
5201             *
5202             * <p>
5203             * 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.
5204             * </p>
5205             *
5206             * @param nodeId the node ID
5207             * @param parentTitle the parent title
5208             * @param start the lower bound of the range of wiki pages
5209             * @param end the upper bound of the range of wiki pages (not inclusive)
5210             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5211             * @return the ordered range of matching wiki pages
5212             * @throws SystemException if a system exception occurred
5213             */
5214            @Override
5215            public List<WikiPage> findByN_P(long nodeId, String parentTitle, int start,
5216                    int end, OrderByComparator orderByComparator) throws SystemException {
5217                    boolean pagination = true;
5218                    FinderPath finderPath = null;
5219                    Object[] finderArgs = null;
5220    
5221                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5222                                    (orderByComparator == null)) {
5223                            pagination = false;
5224                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P;
5225                            finderArgs = new Object[] { nodeId, parentTitle };
5226                    }
5227                    else {
5228                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_P;
5229                            finderArgs = new Object[] {
5230                                            nodeId, parentTitle,
5231                                            
5232                                            start, end, orderByComparator
5233                                    };
5234                    }
5235    
5236                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
5237                                    finderArgs, this);
5238    
5239                    if ((list != null) && !list.isEmpty()) {
5240                            for (WikiPage wikiPage : list) {
5241                                    if ((nodeId != wikiPage.getNodeId()) ||
5242                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle())) {
5243                                            list = null;
5244    
5245                                            break;
5246                                    }
5247                            }
5248                    }
5249    
5250                    if (list == null) {
5251                            StringBundler query = null;
5252    
5253                            if (orderByComparator != null) {
5254                                    query = new StringBundler(4 +
5255                                                    (orderByComparator.getOrderByFields().length * 3));
5256                            }
5257                            else {
5258                                    query = new StringBundler(4);
5259                            }
5260    
5261                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5262    
5263                            query.append(_FINDER_COLUMN_N_P_NODEID_2);
5264    
5265                            boolean bindParentTitle = false;
5266    
5267                            if (parentTitle == null) {
5268                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
5269                            }
5270                            else if (parentTitle.equals(StringPool.BLANK)) {
5271                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
5272                            }
5273                            else {
5274                                    bindParentTitle = true;
5275    
5276                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
5277                            }
5278    
5279                            if (orderByComparator != null) {
5280                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5281                                            orderByComparator);
5282                            }
5283                            else
5284                             if (pagination) {
5285                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5286                            }
5287    
5288                            String sql = query.toString();
5289    
5290                            Session session = null;
5291    
5292                            try {
5293                                    session = openSession();
5294    
5295                                    Query q = session.createQuery(sql);
5296    
5297                                    QueryPos qPos = QueryPos.getInstance(q);
5298    
5299                                    qPos.add(nodeId);
5300    
5301                                    if (bindParentTitle) {
5302                                            qPos.add(parentTitle.toLowerCase());
5303                                    }
5304    
5305                                    if (!pagination) {
5306                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
5307                                                            start, end, false);
5308    
5309                                            Collections.sort(list);
5310    
5311                                            list = new UnmodifiableList<WikiPage>(list);
5312                                    }
5313                                    else {
5314                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
5315                                                            start, end);
5316                                    }
5317    
5318                                    cacheResult(list);
5319    
5320                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5321                            }
5322                            catch (Exception e) {
5323                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5324    
5325                                    throw processException(e);
5326                            }
5327                            finally {
5328                                    closeSession(session);
5329                            }
5330                    }
5331    
5332                    return list;
5333            }
5334    
5335            /**
5336             * Returns the first wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
5337             *
5338             * @param nodeId the node ID
5339             * @param parentTitle the parent title
5340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5341             * @return the first matching wiki page
5342             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5343             * @throws SystemException if a system exception occurred
5344             */
5345            @Override
5346            public WikiPage findByN_P_First(long nodeId, String parentTitle,
5347                    OrderByComparator orderByComparator)
5348                    throws NoSuchPageException, SystemException {
5349                    WikiPage wikiPage = fetchByN_P_First(nodeId, parentTitle,
5350                                    orderByComparator);
5351    
5352                    if (wikiPage != null) {
5353                            return wikiPage;
5354                    }
5355    
5356                    StringBundler msg = new StringBundler(6);
5357    
5358                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5359    
5360                    msg.append("nodeId=");
5361                    msg.append(nodeId);
5362    
5363                    msg.append(", parentTitle=");
5364                    msg.append(parentTitle);
5365    
5366                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5367    
5368                    throw new NoSuchPageException(msg.toString());
5369            }
5370    
5371            /**
5372             * Returns the first wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
5373             *
5374             * @param nodeId the node ID
5375             * @param parentTitle the parent title
5376             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5377             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
5378             * @throws SystemException if a system exception occurred
5379             */
5380            @Override
5381            public WikiPage fetchByN_P_First(long nodeId, String parentTitle,
5382                    OrderByComparator orderByComparator) throws SystemException {
5383                    List<WikiPage> list = findByN_P(nodeId, parentTitle, 0, 1,
5384                                    orderByComparator);
5385    
5386                    if (!list.isEmpty()) {
5387                            return list.get(0);
5388                    }
5389    
5390                    return null;
5391            }
5392    
5393            /**
5394             * Returns the last wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
5395             *
5396             * @param nodeId the node ID
5397             * @param parentTitle the parent title
5398             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5399             * @return the last matching wiki page
5400             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5401             * @throws SystemException if a system exception occurred
5402             */
5403            @Override
5404            public WikiPage findByN_P_Last(long nodeId, String parentTitle,
5405                    OrderByComparator orderByComparator)
5406                    throws NoSuchPageException, SystemException {
5407                    WikiPage wikiPage = fetchByN_P_Last(nodeId, parentTitle,
5408                                    orderByComparator);
5409    
5410                    if (wikiPage != null) {
5411                            return wikiPage;
5412                    }
5413    
5414                    StringBundler msg = new StringBundler(6);
5415    
5416                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5417    
5418                    msg.append("nodeId=");
5419                    msg.append(nodeId);
5420    
5421                    msg.append(", parentTitle=");
5422                    msg.append(parentTitle);
5423    
5424                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5425    
5426                    throw new NoSuchPageException(msg.toString());
5427            }
5428    
5429            /**
5430             * Returns the last wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
5431             *
5432             * @param nodeId the node ID
5433             * @param parentTitle the parent title
5434             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5435             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
5436             * @throws SystemException if a system exception occurred
5437             */
5438            @Override
5439            public WikiPage fetchByN_P_Last(long nodeId, String parentTitle,
5440                    OrderByComparator orderByComparator) throws SystemException {
5441                    int count = countByN_P(nodeId, parentTitle);
5442    
5443                    if (count == 0) {
5444                            return null;
5445                    }
5446    
5447                    List<WikiPage> list = findByN_P(nodeId, parentTitle, count - 1, count,
5448                                    orderByComparator);
5449    
5450                    if (!list.isEmpty()) {
5451                            return list.get(0);
5452                    }
5453    
5454                    return null;
5455            }
5456    
5457            /**
5458             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and parentTitle = &#63;.
5459             *
5460             * @param pageId the primary key of the current wiki page
5461             * @param nodeId the node ID
5462             * @param parentTitle the parent title
5463             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5464             * @return the previous, current, and next wiki page
5465             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
5466             * @throws SystemException if a system exception occurred
5467             */
5468            @Override
5469            public WikiPage[] findByN_P_PrevAndNext(long pageId, long nodeId,
5470                    String parentTitle, OrderByComparator orderByComparator)
5471                    throws NoSuchPageException, SystemException {
5472                    WikiPage wikiPage = findByPrimaryKey(pageId);
5473    
5474                    Session session = null;
5475    
5476                    try {
5477                            session = openSession();
5478    
5479                            WikiPage[] array = new WikiPageImpl[3];
5480    
5481                            array[0] = getByN_P_PrevAndNext(session, wikiPage, nodeId,
5482                                            parentTitle, orderByComparator, true);
5483    
5484                            array[1] = wikiPage;
5485    
5486                            array[2] = getByN_P_PrevAndNext(session, wikiPage, nodeId,
5487                                            parentTitle, orderByComparator, false);
5488    
5489                            return array;
5490                    }
5491                    catch (Exception e) {
5492                            throw processException(e);
5493                    }
5494                    finally {
5495                            closeSession(session);
5496                    }
5497            }
5498    
5499            protected WikiPage getByN_P_PrevAndNext(Session session, WikiPage wikiPage,
5500                    long nodeId, String parentTitle, OrderByComparator orderByComparator,
5501                    boolean previous) {
5502                    StringBundler query = null;
5503    
5504                    if (orderByComparator != null) {
5505                            query = new StringBundler(6 +
5506                                            (orderByComparator.getOrderByFields().length * 6));
5507                    }
5508                    else {
5509                            query = new StringBundler(3);
5510                    }
5511    
5512                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5513    
5514                    query.append(_FINDER_COLUMN_N_P_NODEID_2);
5515    
5516                    boolean bindParentTitle = false;
5517    
5518                    if (parentTitle == null) {
5519                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
5520                    }
5521                    else if (parentTitle.equals(StringPool.BLANK)) {
5522                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
5523                    }
5524                    else {
5525                            bindParentTitle = true;
5526    
5527                            query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
5528                    }
5529    
5530                    if (orderByComparator != null) {
5531                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5532    
5533                            if (orderByConditionFields.length > 0) {
5534                                    query.append(WHERE_AND);
5535                            }
5536    
5537                            for (int i = 0; i < orderByConditionFields.length; i++) {
5538                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5539                                    query.append(orderByConditionFields[i]);
5540    
5541                                    if ((i + 1) < orderByConditionFields.length) {
5542                                            if (orderByComparator.isAscending() ^ previous) {
5543                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5544                                            }
5545                                            else {
5546                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5547                                            }
5548                                    }
5549                                    else {
5550                                            if (orderByComparator.isAscending() ^ previous) {
5551                                                    query.append(WHERE_GREATER_THAN);
5552                                            }
5553                                            else {
5554                                                    query.append(WHERE_LESSER_THAN);
5555                                            }
5556                                    }
5557                            }
5558    
5559                            query.append(ORDER_BY_CLAUSE);
5560    
5561                            String[] orderByFields = orderByComparator.getOrderByFields();
5562    
5563                            for (int i = 0; i < orderByFields.length; i++) {
5564                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5565                                    query.append(orderByFields[i]);
5566    
5567                                    if ((i + 1) < orderByFields.length) {
5568                                            if (orderByComparator.isAscending() ^ previous) {
5569                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5570                                            }
5571                                            else {
5572                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5573                                            }
5574                                    }
5575                                    else {
5576                                            if (orderByComparator.isAscending() ^ previous) {
5577                                                    query.append(ORDER_BY_ASC);
5578                                            }
5579                                            else {
5580                                                    query.append(ORDER_BY_DESC);
5581                                            }
5582                                    }
5583                            }
5584                    }
5585                    else {
5586                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5587                    }
5588    
5589                    String sql = query.toString();
5590    
5591                    Query q = session.createQuery(sql);
5592    
5593                    q.setFirstResult(0);
5594                    q.setMaxResults(2);
5595    
5596                    QueryPos qPos = QueryPos.getInstance(q);
5597    
5598                    qPos.add(nodeId);
5599    
5600                    if (bindParentTitle) {
5601                            qPos.add(parentTitle.toLowerCase());
5602                    }
5603    
5604                    if (orderByComparator != null) {
5605                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
5606    
5607                            for (Object value : values) {
5608                                    qPos.add(value);
5609                            }
5610                    }
5611    
5612                    List<WikiPage> list = q.list();
5613    
5614                    if (list.size() == 2) {
5615                            return list.get(1);
5616                    }
5617                    else {
5618                            return null;
5619                    }
5620            }
5621    
5622            /**
5623             * Removes all the wiki pages where nodeId = &#63; and parentTitle = &#63; from the database.
5624             *
5625             * @param nodeId the node ID
5626             * @param parentTitle the parent title
5627             * @throws SystemException if a system exception occurred
5628             */
5629            @Override
5630            public void removeByN_P(long nodeId, String parentTitle)
5631                    throws SystemException {
5632                    for (WikiPage wikiPage : findByN_P(nodeId, parentTitle,
5633                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5634                            remove(wikiPage);
5635                    }
5636            }
5637    
5638            /**
5639             * Returns the number of wiki pages where nodeId = &#63; and parentTitle = &#63;.
5640             *
5641             * @param nodeId the node ID
5642             * @param parentTitle the parent title
5643             * @return the number of matching wiki pages
5644             * @throws SystemException if a system exception occurred
5645             */
5646            @Override
5647            public int countByN_P(long nodeId, String parentTitle)
5648                    throws SystemException {
5649                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_P;
5650    
5651                    Object[] finderArgs = new Object[] { nodeId, parentTitle };
5652    
5653                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5654                                    this);
5655    
5656                    if (count == null) {
5657                            StringBundler query = new StringBundler(3);
5658    
5659                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
5660    
5661                            query.append(_FINDER_COLUMN_N_P_NODEID_2);
5662    
5663                            boolean bindParentTitle = false;
5664    
5665                            if (parentTitle == null) {
5666                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_1);
5667                            }
5668                            else if (parentTitle.equals(StringPool.BLANK)) {
5669                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_3);
5670                            }
5671                            else {
5672                                    bindParentTitle = true;
5673    
5674                                    query.append(_FINDER_COLUMN_N_P_PARENTTITLE_2);
5675                            }
5676    
5677                            String sql = query.toString();
5678    
5679                            Session session = null;
5680    
5681                            try {
5682                                    session = openSession();
5683    
5684                                    Query q = session.createQuery(sql);
5685    
5686                                    QueryPos qPos = QueryPos.getInstance(q);
5687    
5688                                    qPos.add(nodeId);
5689    
5690                                    if (bindParentTitle) {
5691                                            qPos.add(parentTitle.toLowerCase());
5692                                    }
5693    
5694                                    count = (Long)q.uniqueResult();
5695    
5696                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5697                            }
5698                            catch (Exception e) {
5699                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5700    
5701                                    throw processException(e);
5702                            }
5703                            finally {
5704                                    closeSession(session);
5705                            }
5706                    }
5707    
5708                    return count.intValue();
5709            }
5710    
5711            private static final String _FINDER_COLUMN_N_P_NODEID_2 = "wikiPage.nodeId = ? AND ";
5712            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL";
5713            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ?";
5714            private static final String _FINDER_COLUMN_N_P_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '')";
5715            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5716                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5717                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_R",
5718                            new String[] {
5719                                    Long.class.getName(), String.class.getName(),
5720                                    
5721                            Integer.class.getName(), Integer.class.getName(),
5722                                    OrderByComparator.class.getName()
5723                            });
5724            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5725                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
5726                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_R",
5727                            new String[] { Long.class.getName(), String.class.getName() },
5728                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
5729                            WikiPageModelImpl.REDIRECTTITLE_COLUMN_BITMASK |
5730                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
5731                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
5732            public static final FinderPath FINDER_PATH_COUNT_BY_N_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
5733                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5734                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_R",
5735                            new String[] { Long.class.getName(), String.class.getName() });
5736    
5737            /**
5738             * Returns all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
5739             *
5740             * @param nodeId the node ID
5741             * @param redirectTitle the redirect title
5742             * @return the matching wiki pages
5743             * @throws SystemException if a system exception occurred
5744             */
5745            @Override
5746            public List<WikiPage> findByN_R(long nodeId, String redirectTitle)
5747                    throws SystemException {
5748                    return findByN_R(nodeId, redirectTitle, QueryUtil.ALL_POS,
5749                            QueryUtil.ALL_POS, null);
5750            }
5751    
5752            /**
5753             * Returns a range of all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
5754             *
5755             * <p>
5756             * 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.
5757             * </p>
5758             *
5759             * @param nodeId the node ID
5760             * @param redirectTitle the redirect title
5761             * @param start the lower bound of the range of wiki pages
5762             * @param end the upper bound of the range of wiki pages (not inclusive)
5763             * @return the range of matching wiki pages
5764             * @throws SystemException if a system exception occurred
5765             */
5766            @Override
5767            public List<WikiPage> findByN_R(long nodeId, String redirectTitle,
5768                    int start, int end) throws SystemException {
5769                    return findByN_R(nodeId, redirectTitle, start, end, null);
5770            }
5771    
5772            /**
5773             * Returns an ordered range of all the wiki pages where nodeId = &#63; and redirectTitle = &#63;.
5774             *
5775             * <p>
5776             * 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.
5777             * </p>
5778             *
5779             * @param nodeId the node ID
5780             * @param redirectTitle the redirect title
5781             * @param start the lower bound of the range of wiki pages
5782             * @param end the upper bound of the range of wiki pages (not inclusive)
5783             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5784             * @return the ordered range of matching wiki pages
5785             * @throws SystemException if a system exception occurred
5786             */
5787            @Override
5788            public List<WikiPage> findByN_R(long nodeId, String redirectTitle,
5789                    int start, int end, OrderByComparator orderByComparator)
5790                    throws SystemException {
5791                    boolean pagination = true;
5792                    FinderPath finderPath = null;
5793                    Object[] finderArgs = null;
5794    
5795                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5796                                    (orderByComparator == null)) {
5797                            pagination = false;
5798                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R;
5799                            finderArgs = new Object[] { nodeId, redirectTitle };
5800                    }
5801                    else {
5802                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_R;
5803                            finderArgs = new Object[] {
5804                                            nodeId, redirectTitle,
5805                                            
5806                                            start, end, orderByComparator
5807                                    };
5808                    }
5809    
5810                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
5811                                    finderArgs, this);
5812    
5813                    if ((list != null) && !list.isEmpty()) {
5814                            for (WikiPage wikiPage : list) {
5815                                    if ((nodeId != wikiPage.getNodeId()) ||
5816                                                    !Validator.equals(redirectTitle,
5817                                                            wikiPage.getRedirectTitle())) {
5818                                            list = null;
5819    
5820                                            break;
5821                                    }
5822                            }
5823                    }
5824    
5825                    if (list == null) {
5826                            StringBundler query = null;
5827    
5828                            if (orderByComparator != null) {
5829                                    query = new StringBundler(4 +
5830                                                    (orderByComparator.getOrderByFields().length * 3));
5831                            }
5832                            else {
5833                                    query = new StringBundler(4);
5834                            }
5835    
5836                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
5837    
5838                            query.append(_FINDER_COLUMN_N_R_NODEID_2);
5839    
5840                            boolean bindRedirectTitle = false;
5841    
5842                            if (redirectTitle == null) {
5843                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
5844                            }
5845                            else if (redirectTitle.equals(StringPool.BLANK)) {
5846                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
5847                            }
5848                            else {
5849                                    bindRedirectTitle = true;
5850    
5851                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
5852                            }
5853    
5854                            if (orderByComparator != null) {
5855                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5856                                            orderByComparator);
5857                            }
5858                            else
5859                             if (pagination) {
5860                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
5861                            }
5862    
5863                            String sql = query.toString();
5864    
5865                            Session session = null;
5866    
5867                            try {
5868                                    session = openSession();
5869    
5870                                    Query q = session.createQuery(sql);
5871    
5872                                    QueryPos qPos = QueryPos.getInstance(q);
5873    
5874                                    qPos.add(nodeId);
5875    
5876                                    if (bindRedirectTitle) {
5877                                            qPos.add(redirectTitle.toLowerCase());
5878                                    }
5879    
5880                                    if (!pagination) {
5881                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
5882                                                            start, end, false);
5883    
5884                                            Collections.sort(list);
5885    
5886                                            list = new UnmodifiableList<WikiPage>(list);
5887                                    }
5888                                    else {
5889                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
5890                                                            start, end);
5891                                    }
5892    
5893                                    cacheResult(list);
5894    
5895                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5896                            }
5897                            catch (Exception e) {
5898                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5899    
5900                                    throw processException(e);
5901                            }
5902                            finally {
5903                                    closeSession(session);
5904                            }
5905                    }
5906    
5907                    return list;
5908            }
5909    
5910            /**
5911             * Returns the first wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
5912             *
5913             * @param nodeId the node ID
5914             * @param redirectTitle the redirect title
5915             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5916             * @return the first matching wiki page
5917             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5918             * @throws SystemException if a system exception occurred
5919             */
5920            @Override
5921            public WikiPage findByN_R_First(long nodeId, String redirectTitle,
5922                    OrderByComparator orderByComparator)
5923                    throws NoSuchPageException, SystemException {
5924                    WikiPage wikiPage = fetchByN_R_First(nodeId, redirectTitle,
5925                                    orderByComparator);
5926    
5927                    if (wikiPage != null) {
5928                            return wikiPage;
5929                    }
5930    
5931                    StringBundler msg = new StringBundler(6);
5932    
5933                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5934    
5935                    msg.append("nodeId=");
5936                    msg.append(nodeId);
5937    
5938                    msg.append(", redirectTitle=");
5939                    msg.append(redirectTitle);
5940    
5941                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5942    
5943                    throw new NoSuchPageException(msg.toString());
5944            }
5945    
5946            /**
5947             * Returns the first wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
5948             *
5949             * @param nodeId the node ID
5950             * @param redirectTitle the redirect title
5951             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5952             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
5953             * @throws SystemException if a system exception occurred
5954             */
5955            @Override
5956            public WikiPage fetchByN_R_First(long nodeId, String redirectTitle,
5957                    OrderByComparator orderByComparator) throws SystemException {
5958                    List<WikiPage> list = findByN_R(nodeId, redirectTitle, 0, 1,
5959                                    orderByComparator);
5960    
5961                    if (!list.isEmpty()) {
5962                            return list.get(0);
5963                    }
5964    
5965                    return null;
5966            }
5967    
5968            /**
5969             * Returns the last wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
5970             *
5971             * @param nodeId the node ID
5972             * @param redirectTitle the redirect title
5973             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5974             * @return the last matching wiki page
5975             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
5976             * @throws SystemException if a system exception occurred
5977             */
5978            @Override
5979            public WikiPage findByN_R_Last(long nodeId, String redirectTitle,
5980                    OrderByComparator orderByComparator)
5981                    throws NoSuchPageException, SystemException {
5982                    WikiPage wikiPage = fetchByN_R_Last(nodeId, redirectTitle,
5983                                    orderByComparator);
5984    
5985                    if (wikiPage != null) {
5986                            return wikiPage;
5987                    }
5988    
5989                    StringBundler msg = new StringBundler(6);
5990    
5991                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5992    
5993                    msg.append("nodeId=");
5994                    msg.append(nodeId);
5995    
5996                    msg.append(", redirectTitle=");
5997                    msg.append(redirectTitle);
5998    
5999                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6000    
6001                    throw new NoSuchPageException(msg.toString());
6002            }
6003    
6004            /**
6005             * Returns the last wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
6006             *
6007             * @param nodeId the node ID
6008             * @param redirectTitle the redirect title
6009             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6010             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
6011             * @throws SystemException if a system exception occurred
6012             */
6013            @Override
6014            public WikiPage fetchByN_R_Last(long nodeId, String redirectTitle,
6015                    OrderByComparator orderByComparator) throws SystemException {
6016                    int count = countByN_R(nodeId, redirectTitle);
6017    
6018                    if (count == 0) {
6019                            return null;
6020                    }
6021    
6022                    List<WikiPage> list = findByN_R(nodeId, redirectTitle, count - 1,
6023                                    count, orderByComparator);
6024    
6025                    if (!list.isEmpty()) {
6026                            return list.get(0);
6027                    }
6028    
6029                    return null;
6030            }
6031    
6032            /**
6033             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and redirectTitle = &#63;.
6034             *
6035             * @param pageId the primary key of the current wiki page
6036             * @param nodeId the node ID
6037             * @param redirectTitle the redirect title
6038             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6039             * @return the previous, current, and next wiki page
6040             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
6041             * @throws SystemException if a system exception occurred
6042             */
6043            @Override
6044            public WikiPage[] findByN_R_PrevAndNext(long pageId, long nodeId,
6045                    String redirectTitle, OrderByComparator orderByComparator)
6046                    throws NoSuchPageException, SystemException {
6047                    WikiPage wikiPage = findByPrimaryKey(pageId);
6048    
6049                    Session session = null;
6050    
6051                    try {
6052                            session = openSession();
6053    
6054                            WikiPage[] array = new WikiPageImpl[3];
6055    
6056                            array[0] = getByN_R_PrevAndNext(session, wikiPage, nodeId,
6057                                            redirectTitle, orderByComparator, true);
6058    
6059                            array[1] = wikiPage;
6060    
6061                            array[2] = getByN_R_PrevAndNext(session, wikiPage, nodeId,
6062                                            redirectTitle, orderByComparator, false);
6063    
6064                            return array;
6065                    }
6066                    catch (Exception e) {
6067                            throw processException(e);
6068                    }
6069                    finally {
6070                            closeSession(session);
6071                    }
6072            }
6073    
6074            protected WikiPage getByN_R_PrevAndNext(Session session, WikiPage wikiPage,
6075                    long nodeId, String redirectTitle, OrderByComparator orderByComparator,
6076                    boolean previous) {
6077                    StringBundler query = null;
6078    
6079                    if (orderByComparator != null) {
6080                            query = new StringBundler(6 +
6081                                            (orderByComparator.getOrderByFields().length * 6));
6082                    }
6083                    else {
6084                            query = new StringBundler(3);
6085                    }
6086    
6087                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6088    
6089                    query.append(_FINDER_COLUMN_N_R_NODEID_2);
6090    
6091                    boolean bindRedirectTitle = false;
6092    
6093                    if (redirectTitle == null) {
6094                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
6095                    }
6096                    else if (redirectTitle.equals(StringPool.BLANK)) {
6097                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
6098                    }
6099                    else {
6100                            bindRedirectTitle = true;
6101    
6102                            query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
6103                    }
6104    
6105                    if (orderByComparator != null) {
6106                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6107    
6108                            if (orderByConditionFields.length > 0) {
6109                                    query.append(WHERE_AND);
6110                            }
6111    
6112                            for (int i = 0; i < orderByConditionFields.length; i++) {
6113                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6114                                    query.append(orderByConditionFields[i]);
6115    
6116                                    if ((i + 1) < orderByConditionFields.length) {
6117                                            if (orderByComparator.isAscending() ^ previous) {
6118                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6119                                            }
6120                                            else {
6121                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6122                                            }
6123                                    }
6124                                    else {
6125                                            if (orderByComparator.isAscending() ^ previous) {
6126                                                    query.append(WHERE_GREATER_THAN);
6127                                            }
6128                                            else {
6129                                                    query.append(WHERE_LESSER_THAN);
6130                                            }
6131                                    }
6132                            }
6133    
6134                            query.append(ORDER_BY_CLAUSE);
6135    
6136                            String[] orderByFields = orderByComparator.getOrderByFields();
6137    
6138                            for (int i = 0; i < orderByFields.length; i++) {
6139                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6140                                    query.append(orderByFields[i]);
6141    
6142                                    if ((i + 1) < orderByFields.length) {
6143                                            if (orderByComparator.isAscending() ^ previous) {
6144                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6145                                            }
6146                                            else {
6147                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6148                                            }
6149                                    }
6150                                    else {
6151                                            if (orderByComparator.isAscending() ^ previous) {
6152                                                    query.append(ORDER_BY_ASC);
6153                                            }
6154                                            else {
6155                                                    query.append(ORDER_BY_DESC);
6156                                            }
6157                                    }
6158                            }
6159                    }
6160                    else {
6161                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6162                    }
6163    
6164                    String sql = query.toString();
6165    
6166                    Query q = session.createQuery(sql);
6167    
6168                    q.setFirstResult(0);
6169                    q.setMaxResults(2);
6170    
6171                    QueryPos qPos = QueryPos.getInstance(q);
6172    
6173                    qPos.add(nodeId);
6174    
6175                    if (bindRedirectTitle) {
6176                            qPos.add(redirectTitle.toLowerCase());
6177                    }
6178    
6179                    if (orderByComparator != null) {
6180                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
6181    
6182                            for (Object value : values) {
6183                                    qPos.add(value);
6184                            }
6185                    }
6186    
6187                    List<WikiPage> list = q.list();
6188    
6189                    if (list.size() == 2) {
6190                            return list.get(1);
6191                    }
6192                    else {
6193                            return null;
6194                    }
6195            }
6196    
6197            /**
6198             * Removes all the wiki pages where nodeId = &#63; and redirectTitle = &#63; from the database.
6199             *
6200             * @param nodeId the node ID
6201             * @param redirectTitle the redirect title
6202             * @throws SystemException if a system exception occurred
6203             */
6204            @Override
6205            public void removeByN_R(long nodeId, String redirectTitle)
6206                    throws SystemException {
6207                    for (WikiPage wikiPage : findByN_R(nodeId, redirectTitle,
6208                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6209                            remove(wikiPage);
6210                    }
6211            }
6212    
6213            /**
6214             * Returns the number of wiki pages where nodeId = &#63; and redirectTitle = &#63;.
6215             *
6216             * @param nodeId the node ID
6217             * @param redirectTitle the redirect title
6218             * @return the number of matching wiki pages
6219             * @throws SystemException if a system exception occurred
6220             */
6221            @Override
6222            public int countByN_R(long nodeId, String redirectTitle)
6223                    throws SystemException {
6224                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_R;
6225    
6226                    Object[] finderArgs = new Object[] { nodeId, redirectTitle };
6227    
6228                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6229                                    this);
6230    
6231                    if (count == null) {
6232                            StringBundler query = new StringBundler(3);
6233    
6234                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
6235    
6236                            query.append(_FINDER_COLUMN_N_R_NODEID_2);
6237    
6238                            boolean bindRedirectTitle = false;
6239    
6240                            if (redirectTitle == null) {
6241                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_1);
6242                            }
6243                            else if (redirectTitle.equals(StringPool.BLANK)) {
6244                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_3);
6245                            }
6246                            else {
6247                                    bindRedirectTitle = true;
6248    
6249                                    query.append(_FINDER_COLUMN_N_R_REDIRECTTITLE_2);
6250                            }
6251    
6252                            String sql = query.toString();
6253    
6254                            Session session = null;
6255    
6256                            try {
6257                                    session = openSession();
6258    
6259                                    Query q = session.createQuery(sql);
6260    
6261                                    QueryPos qPos = QueryPos.getInstance(q);
6262    
6263                                    qPos.add(nodeId);
6264    
6265                                    if (bindRedirectTitle) {
6266                                            qPos.add(redirectTitle.toLowerCase());
6267                                    }
6268    
6269                                    count = (Long)q.uniqueResult();
6270    
6271                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6272                            }
6273                            catch (Exception e) {
6274                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6275    
6276                                    throw processException(e);
6277                            }
6278                            finally {
6279                                    closeSession(session);
6280                            }
6281                    }
6282    
6283                    return count.intValue();
6284            }
6285    
6286            private static final String _FINDER_COLUMN_N_R_NODEID_2 = "wikiPage.nodeId = ? AND ";
6287            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_1 = "wikiPage.redirectTitle IS NULL";
6288            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_2 = "lower(wikiPage.redirectTitle) = ?";
6289            private static final String _FINDER_COLUMN_N_R_REDIRECTTITLE_3 = "(wikiPage.redirectTitle IS NULL OR wikiPage.redirectTitle = '')";
6290            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6291                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
6292                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_S",
6293                            new String[] {
6294                                    Long.class.getName(), Integer.class.getName(),
6295                                    
6296                            Integer.class.getName(), Integer.class.getName(),
6297                                    OrderByComparator.class.getName()
6298                            });
6299            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6300                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
6301                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_S",
6302                            new String[] { Long.class.getName(), Integer.class.getName() },
6303                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
6304                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
6305                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
6306                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
6307            public static final FinderPath FINDER_PATH_COUNT_BY_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6308                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6309                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_S",
6310                            new String[] { Long.class.getName(), Integer.class.getName() });
6311    
6312            /**
6313             * Returns all the wiki pages where nodeId = &#63; and status = &#63;.
6314             *
6315             * @param nodeId the node ID
6316             * @param status the status
6317             * @return the matching wiki pages
6318             * @throws SystemException if a system exception occurred
6319             */
6320            @Override
6321            public List<WikiPage> findByN_S(long nodeId, int status)
6322                    throws SystemException {
6323                    return findByN_S(nodeId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6324                            null);
6325            }
6326    
6327            /**
6328             * Returns a range of all the wiki pages where nodeId = &#63; and status = &#63;.
6329             *
6330             * <p>
6331             * 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.
6332             * </p>
6333             *
6334             * @param nodeId the node ID
6335             * @param status the status
6336             * @param start the lower bound of the range of wiki pages
6337             * @param end the upper bound of the range of wiki pages (not inclusive)
6338             * @return the range of matching wiki pages
6339             * @throws SystemException if a system exception occurred
6340             */
6341            @Override
6342            public List<WikiPage> findByN_S(long nodeId, int status, int start, int end)
6343                    throws SystemException {
6344                    return findByN_S(nodeId, status, start, end, null);
6345            }
6346    
6347            /**
6348             * Returns an ordered range of all the wiki pages where nodeId = &#63; and status = &#63;.
6349             *
6350             * <p>
6351             * 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.
6352             * </p>
6353             *
6354             * @param nodeId the node ID
6355             * @param status the status
6356             * @param start the lower bound of the range of wiki pages
6357             * @param end the upper bound of the range of wiki pages (not inclusive)
6358             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6359             * @return the ordered range of matching wiki pages
6360             * @throws SystemException if a system exception occurred
6361             */
6362            @Override
6363            public List<WikiPage> findByN_S(long nodeId, int status, int start,
6364                    int end, OrderByComparator orderByComparator) throws SystemException {
6365                    boolean pagination = true;
6366                    FinderPath finderPath = null;
6367                    Object[] finderArgs = null;
6368    
6369                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6370                                    (orderByComparator == null)) {
6371                            pagination = false;
6372                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S;
6373                            finderArgs = new Object[] { nodeId, status };
6374                    }
6375                    else {
6376                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_S;
6377                            finderArgs = new Object[] {
6378                                            nodeId, status,
6379                                            
6380                                            start, end, orderByComparator
6381                                    };
6382                    }
6383    
6384                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
6385                                    finderArgs, this);
6386    
6387                    if ((list != null) && !list.isEmpty()) {
6388                            for (WikiPage wikiPage : list) {
6389                                    if ((nodeId != wikiPage.getNodeId()) ||
6390                                                    (status != wikiPage.getStatus())) {
6391                                            list = null;
6392    
6393                                            break;
6394                                    }
6395                            }
6396                    }
6397    
6398                    if (list == null) {
6399                            StringBundler query = null;
6400    
6401                            if (orderByComparator != null) {
6402                                    query = new StringBundler(4 +
6403                                                    (orderByComparator.getOrderByFields().length * 3));
6404                            }
6405                            else {
6406                                    query = new StringBundler(4);
6407                            }
6408    
6409                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6410    
6411                            query.append(_FINDER_COLUMN_N_S_NODEID_2);
6412    
6413                            query.append(_FINDER_COLUMN_N_S_STATUS_2);
6414    
6415                            if (orderByComparator != null) {
6416                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6417                                            orderByComparator);
6418                            }
6419                            else
6420                             if (pagination) {
6421                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6422                            }
6423    
6424                            String sql = query.toString();
6425    
6426                            Session session = null;
6427    
6428                            try {
6429                                    session = openSession();
6430    
6431                                    Query q = session.createQuery(sql);
6432    
6433                                    QueryPos qPos = QueryPos.getInstance(q);
6434    
6435                                    qPos.add(nodeId);
6436    
6437                                    qPos.add(status);
6438    
6439                                    if (!pagination) {
6440                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6441                                                            start, end, false);
6442    
6443                                            Collections.sort(list);
6444    
6445                                            list = new UnmodifiableList<WikiPage>(list);
6446                                    }
6447                                    else {
6448                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
6449                                                            start, end);
6450                                    }
6451    
6452                                    cacheResult(list);
6453    
6454                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6455                            }
6456                            catch (Exception e) {
6457                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6458    
6459                                    throw processException(e);
6460                            }
6461                            finally {
6462                                    closeSession(session);
6463                            }
6464                    }
6465    
6466                    return list;
6467            }
6468    
6469            /**
6470             * Returns the first wiki page in the ordered set where nodeId = &#63; and status = &#63;.
6471             *
6472             * @param nodeId the node ID
6473             * @param status the status
6474             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6475             * @return the first matching wiki page
6476             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6477             * @throws SystemException if a system exception occurred
6478             */
6479            @Override
6480            public WikiPage findByN_S_First(long nodeId, int status,
6481                    OrderByComparator orderByComparator)
6482                    throws NoSuchPageException, SystemException {
6483                    WikiPage wikiPage = fetchByN_S_First(nodeId, status, orderByComparator);
6484    
6485                    if (wikiPage != null) {
6486                            return wikiPage;
6487                    }
6488    
6489                    StringBundler msg = new StringBundler(6);
6490    
6491                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6492    
6493                    msg.append("nodeId=");
6494                    msg.append(nodeId);
6495    
6496                    msg.append(", status=");
6497                    msg.append(status);
6498    
6499                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6500    
6501                    throw new NoSuchPageException(msg.toString());
6502            }
6503    
6504            /**
6505             * Returns the first wiki page in the ordered set where nodeId = &#63; and status = &#63;.
6506             *
6507             * @param nodeId the node ID
6508             * @param status the status
6509             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6510             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
6511             * @throws SystemException if a system exception occurred
6512             */
6513            @Override
6514            public WikiPage fetchByN_S_First(long nodeId, int status,
6515                    OrderByComparator orderByComparator) throws SystemException {
6516                    List<WikiPage> list = findByN_S(nodeId, status, 0, 1, orderByComparator);
6517    
6518                    if (!list.isEmpty()) {
6519                            return list.get(0);
6520                    }
6521    
6522                    return null;
6523            }
6524    
6525            /**
6526             * Returns the last wiki page in the ordered set where nodeId = &#63; and status = &#63;.
6527             *
6528             * @param nodeId the node ID
6529             * @param status the status
6530             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6531             * @return the last matching wiki page
6532             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6533             * @throws SystemException if a system exception occurred
6534             */
6535            @Override
6536            public WikiPage findByN_S_Last(long nodeId, int status,
6537                    OrderByComparator orderByComparator)
6538                    throws NoSuchPageException, SystemException {
6539                    WikiPage wikiPage = fetchByN_S_Last(nodeId, status, orderByComparator);
6540    
6541                    if (wikiPage != null) {
6542                            return wikiPage;
6543                    }
6544    
6545                    StringBundler msg = new StringBundler(6);
6546    
6547                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6548    
6549                    msg.append("nodeId=");
6550                    msg.append(nodeId);
6551    
6552                    msg.append(", status=");
6553                    msg.append(status);
6554    
6555                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6556    
6557                    throw new NoSuchPageException(msg.toString());
6558            }
6559    
6560            /**
6561             * Returns the last wiki page in the ordered set where nodeId = &#63; and status = &#63;.
6562             *
6563             * @param nodeId the node ID
6564             * @param status the status
6565             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6566             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
6567             * @throws SystemException if a system exception occurred
6568             */
6569            @Override
6570            public WikiPage fetchByN_S_Last(long nodeId, int status,
6571                    OrderByComparator orderByComparator) throws SystemException {
6572                    int count = countByN_S(nodeId, status);
6573    
6574                    if (count == 0) {
6575                            return null;
6576                    }
6577    
6578                    List<WikiPage> list = findByN_S(nodeId, status, count - 1, count,
6579                                    orderByComparator);
6580    
6581                    if (!list.isEmpty()) {
6582                            return list.get(0);
6583                    }
6584    
6585                    return null;
6586            }
6587    
6588            /**
6589             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and status = &#63;.
6590             *
6591             * @param pageId the primary key of the current wiki page
6592             * @param nodeId the node ID
6593             * @param status the status
6594             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6595             * @return the previous, current, and next wiki page
6596             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
6597             * @throws SystemException if a system exception occurred
6598             */
6599            @Override
6600            public WikiPage[] findByN_S_PrevAndNext(long pageId, long nodeId,
6601                    int status, OrderByComparator orderByComparator)
6602                    throws NoSuchPageException, SystemException {
6603                    WikiPage wikiPage = findByPrimaryKey(pageId);
6604    
6605                    Session session = null;
6606    
6607                    try {
6608                            session = openSession();
6609    
6610                            WikiPage[] array = new WikiPageImpl[3];
6611    
6612                            array[0] = getByN_S_PrevAndNext(session, wikiPage, nodeId, status,
6613                                            orderByComparator, true);
6614    
6615                            array[1] = wikiPage;
6616    
6617                            array[2] = getByN_S_PrevAndNext(session, wikiPage, nodeId, status,
6618                                            orderByComparator, false);
6619    
6620                            return array;
6621                    }
6622                    catch (Exception e) {
6623                            throw processException(e);
6624                    }
6625                    finally {
6626                            closeSession(session);
6627                    }
6628            }
6629    
6630            protected WikiPage getByN_S_PrevAndNext(Session session, WikiPage wikiPage,
6631                    long nodeId, int status, OrderByComparator orderByComparator,
6632                    boolean previous) {
6633                    StringBundler query = null;
6634    
6635                    if (orderByComparator != null) {
6636                            query = new StringBundler(6 +
6637                                            (orderByComparator.getOrderByFields().length * 6));
6638                    }
6639                    else {
6640                            query = new StringBundler(3);
6641                    }
6642    
6643                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6644    
6645                    query.append(_FINDER_COLUMN_N_S_NODEID_2);
6646    
6647                    query.append(_FINDER_COLUMN_N_S_STATUS_2);
6648    
6649                    if (orderByComparator != null) {
6650                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6651    
6652                            if (orderByConditionFields.length > 0) {
6653                                    query.append(WHERE_AND);
6654                            }
6655    
6656                            for (int i = 0; i < orderByConditionFields.length; i++) {
6657                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6658                                    query.append(orderByConditionFields[i]);
6659    
6660                                    if ((i + 1) < orderByConditionFields.length) {
6661                                            if (orderByComparator.isAscending() ^ previous) {
6662                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6663                                            }
6664                                            else {
6665                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6666                                            }
6667                                    }
6668                                    else {
6669                                            if (orderByComparator.isAscending() ^ previous) {
6670                                                    query.append(WHERE_GREATER_THAN);
6671                                            }
6672                                            else {
6673                                                    query.append(WHERE_LESSER_THAN);
6674                                            }
6675                                    }
6676                            }
6677    
6678                            query.append(ORDER_BY_CLAUSE);
6679    
6680                            String[] orderByFields = orderByComparator.getOrderByFields();
6681    
6682                            for (int i = 0; i < orderByFields.length; i++) {
6683                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6684                                    query.append(orderByFields[i]);
6685    
6686                                    if ((i + 1) < orderByFields.length) {
6687                                            if (orderByComparator.isAscending() ^ previous) {
6688                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6689                                            }
6690                                            else {
6691                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6692                                            }
6693                                    }
6694                                    else {
6695                                            if (orderByComparator.isAscending() ^ previous) {
6696                                                    query.append(ORDER_BY_ASC);
6697                                            }
6698                                            else {
6699                                                    query.append(ORDER_BY_DESC);
6700                                            }
6701                                    }
6702                            }
6703                    }
6704                    else {
6705                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
6706                    }
6707    
6708                    String sql = query.toString();
6709    
6710                    Query q = session.createQuery(sql);
6711    
6712                    q.setFirstResult(0);
6713                    q.setMaxResults(2);
6714    
6715                    QueryPos qPos = QueryPos.getInstance(q);
6716    
6717                    qPos.add(nodeId);
6718    
6719                    qPos.add(status);
6720    
6721                    if (orderByComparator != null) {
6722                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
6723    
6724                            for (Object value : values) {
6725                                    qPos.add(value);
6726                            }
6727                    }
6728    
6729                    List<WikiPage> list = q.list();
6730    
6731                    if (list.size() == 2) {
6732                            return list.get(1);
6733                    }
6734                    else {
6735                            return null;
6736                    }
6737            }
6738    
6739            /**
6740             * Removes all the wiki pages where nodeId = &#63; and status = &#63; from the database.
6741             *
6742             * @param nodeId the node ID
6743             * @param status the status
6744             * @throws SystemException if a system exception occurred
6745             */
6746            @Override
6747            public void removeByN_S(long nodeId, int status) throws SystemException {
6748                    for (WikiPage wikiPage : findByN_S(nodeId, status, QueryUtil.ALL_POS,
6749                                    QueryUtil.ALL_POS, null)) {
6750                            remove(wikiPage);
6751                    }
6752            }
6753    
6754            /**
6755             * Returns the number of wiki pages where nodeId = &#63; and status = &#63;.
6756             *
6757             * @param nodeId the node ID
6758             * @param status the status
6759             * @return the number of matching wiki pages
6760             * @throws SystemException if a system exception occurred
6761             */
6762            @Override
6763            public int countByN_S(long nodeId, int status) throws SystemException {
6764                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_S;
6765    
6766                    Object[] finderArgs = new Object[] { nodeId, status };
6767    
6768                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6769                                    this);
6770    
6771                    if (count == null) {
6772                            StringBundler query = new StringBundler(3);
6773    
6774                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
6775    
6776                            query.append(_FINDER_COLUMN_N_S_NODEID_2);
6777    
6778                            query.append(_FINDER_COLUMN_N_S_STATUS_2);
6779    
6780                            String sql = query.toString();
6781    
6782                            Session session = null;
6783    
6784                            try {
6785                                    session = openSession();
6786    
6787                                    Query q = session.createQuery(sql);
6788    
6789                                    QueryPos qPos = QueryPos.getInstance(q);
6790    
6791                                    qPos.add(nodeId);
6792    
6793                                    qPos.add(status);
6794    
6795                                    count = (Long)q.uniqueResult();
6796    
6797                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6798                            }
6799                            catch (Exception e) {
6800                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6801    
6802                                    throw processException(e);
6803                            }
6804                            finally {
6805                                    closeSession(session);
6806                            }
6807                    }
6808    
6809                    return count.intValue();
6810            }
6811    
6812            private static final String _FINDER_COLUMN_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
6813            private static final String _FINDER_COLUMN_N_S_STATUS_2 = "wikiPage.status = ?";
6814            public static final FinderPath FINDER_PATH_FETCH_BY_R_N_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6815                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
6816                            FINDER_CLASS_NAME_ENTITY, "fetchByR_N_V",
6817                            new String[] {
6818                                    Long.class.getName(), Long.class.getName(),
6819                                    Double.class.getName()
6820                            },
6821                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
6822                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
6823                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
6824            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
6825                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6826                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N_V",
6827                            new String[] {
6828                                    Long.class.getName(), Long.class.getName(),
6829                                    Double.class.getName()
6830                            });
6831    
6832            /**
6833             * 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.
6834             *
6835             * @param resourcePrimKey the resource prim key
6836             * @param nodeId the node ID
6837             * @param version the version
6838             * @return the matching wiki page
6839             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
6840             * @throws SystemException if a system exception occurred
6841             */
6842            @Override
6843            public WikiPage findByR_N_V(long resourcePrimKey, long nodeId,
6844                    double version) throws NoSuchPageException, SystemException {
6845                    WikiPage wikiPage = fetchByR_N_V(resourcePrimKey, nodeId, version);
6846    
6847                    if (wikiPage == null) {
6848                            StringBundler msg = new StringBundler(8);
6849    
6850                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6851    
6852                            msg.append("resourcePrimKey=");
6853                            msg.append(resourcePrimKey);
6854    
6855                            msg.append(", nodeId=");
6856                            msg.append(nodeId);
6857    
6858                            msg.append(", version=");
6859                            msg.append(version);
6860    
6861                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6862    
6863                            if (_log.isWarnEnabled()) {
6864                                    _log.warn(msg.toString());
6865                            }
6866    
6867                            throw new NoSuchPageException(msg.toString());
6868                    }
6869    
6870                    return wikiPage;
6871            }
6872    
6873            /**
6874             * 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.
6875             *
6876             * @param resourcePrimKey the resource prim key
6877             * @param nodeId the node ID
6878             * @param version the version
6879             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
6880             * @throws SystemException if a system exception occurred
6881             */
6882            @Override
6883            public WikiPage fetchByR_N_V(long resourcePrimKey, long nodeId,
6884                    double version) throws SystemException {
6885                    return fetchByR_N_V(resourcePrimKey, nodeId, version, true);
6886            }
6887    
6888            /**
6889             * 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.
6890             *
6891             * @param resourcePrimKey the resource prim key
6892             * @param nodeId the node ID
6893             * @param version the version
6894             * @param retrieveFromCache whether to use the finder cache
6895             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
6896             * @throws SystemException if a system exception occurred
6897             */
6898            @Override
6899            public WikiPage fetchByR_N_V(long resourcePrimKey, long nodeId,
6900                    double version, boolean retrieveFromCache) throws SystemException {
6901                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, version };
6902    
6903                    Object result = null;
6904    
6905                    if (retrieveFromCache) {
6906                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_R_N_V,
6907                                            finderArgs, this);
6908                    }
6909    
6910                    if (result instanceof WikiPage) {
6911                            WikiPage wikiPage = (WikiPage)result;
6912    
6913                            if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
6914                                            (nodeId != wikiPage.getNodeId()) ||
6915                                            (version != wikiPage.getVersion())) {
6916                                    result = null;
6917                            }
6918                    }
6919    
6920                    if (result == null) {
6921                            StringBundler query = new StringBundler(5);
6922    
6923                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
6924    
6925                            query.append(_FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2);
6926    
6927                            query.append(_FINDER_COLUMN_R_N_V_NODEID_2);
6928    
6929                            query.append(_FINDER_COLUMN_R_N_V_VERSION_2);
6930    
6931                            String sql = query.toString();
6932    
6933                            Session session = null;
6934    
6935                            try {
6936                                    session = openSession();
6937    
6938                                    Query q = session.createQuery(sql);
6939    
6940                                    QueryPos qPos = QueryPos.getInstance(q);
6941    
6942                                    qPos.add(resourcePrimKey);
6943    
6944                                    qPos.add(nodeId);
6945    
6946                                    qPos.add(version);
6947    
6948                                    List<WikiPage> list = q.list();
6949    
6950                                    if (list.isEmpty()) {
6951                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
6952                                                    finderArgs, list);
6953                                    }
6954                                    else {
6955                                            WikiPage wikiPage = list.get(0);
6956    
6957                                            result = wikiPage;
6958    
6959                                            cacheResult(wikiPage);
6960    
6961                                            if ((wikiPage.getResourcePrimKey() != resourcePrimKey) ||
6962                                                            (wikiPage.getNodeId() != nodeId) ||
6963                                                            (wikiPage.getVersion() != version)) {
6964                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
6965                                                            finderArgs, wikiPage);
6966                                            }
6967                                    }
6968                            }
6969                            catch (Exception e) {
6970                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V,
6971                                            finderArgs);
6972    
6973                                    throw processException(e);
6974                            }
6975                            finally {
6976                                    closeSession(session);
6977                            }
6978                    }
6979    
6980                    if (result instanceof List<?>) {
6981                            return null;
6982                    }
6983                    else {
6984                            return (WikiPage)result;
6985                    }
6986            }
6987    
6988            /**
6989             * Removes the wiki page where resourcePrimKey = &#63; and nodeId = &#63; and version = &#63; from the database.
6990             *
6991             * @param resourcePrimKey the resource prim key
6992             * @param nodeId the node ID
6993             * @param version the version
6994             * @return the wiki page that was removed
6995             * @throws SystemException if a system exception occurred
6996             */
6997            @Override
6998            public WikiPage removeByR_N_V(long resourcePrimKey, long nodeId,
6999                    double version) throws NoSuchPageException, SystemException {
7000                    WikiPage wikiPage = findByR_N_V(resourcePrimKey, nodeId, version);
7001    
7002                    return remove(wikiPage);
7003            }
7004    
7005            /**
7006             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and version = &#63;.
7007             *
7008             * @param resourcePrimKey the resource prim key
7009             * @param nodeId the node ID
7010             * @param version the version
7011             * @return the number of matching wiki pages
7012             * @throws SystemException if a system exception occurred
7013             */
7014            @Override
7015            public int countByR_N_V(long resourcePrimKey, long nodeId, double version)
7016                    throws SystemException {
7017                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N_V;
7018    
7019                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, version };
7020    
7021                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7022                                    this);
7023    
7024                    if (count == null) {
7025                            StringBundler query = new StringBundler(4);
7026    
7027                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
7028    
7029                            query.append(_FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2);
7030    
7031                            query.append(_FINDER_COLUMN_R_N_V_NODEID_2);
7032    
7033                            query.append(_FINDER_COLUMN_R_N_V_VERSION_2);
7034    
7035                            String sql = query.toString();
7036    
7037                            Session session = null;
7038    
7039                            try {
7040                                    session = openSession();
7041    
7042                                    Query q = session.createQuery(sql);
7043    
7044                                    QueryPos qPos = QueryPos.getInstance(q);
7045    
7046                                    qPos.add(resourcePrimKey);
7047    
7048                                    qPos.add(nodeId);
7049    
7050                                    qPos.add(version);
7051    
7052                                    count = (Long)q.uniqueResult();
7053    
7054                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7055                            }
7056                            catch (Exception e) {
7057                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7058    
7059                                    throw processException(e);
7060                            }
7061                            finally {
7062                                    closeSession(session);
7063                            }
7064                    }
7065    
7066                    return count.intValue();
7067            }
7068    
7069            private static final String _FINDER_COLUMN_R_N_V_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
7070            private static final String _FINDER_COLUMN_R_N_V_NODEID_2 = "wikiPage.nodeId = ? AND ";
7071            private static final String _FINDER_COLUMN_R_N_V_VERSION_2 = "wikiPage.version = ?";
7072            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7073                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
7074                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_N_H",
7075                            new String[] {
7076                                    Long.class.getName(), Long.class.getName(),
7077                                    Boolean.class.getName(),
7078                                    
7079                            Integer.class.getName(), Integer.class.getName(),
7080                                    OrderByComparator.class.getName()
7081                            });
7082            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7083                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
7084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_N_H",
7085                            new String[] {
7086                                    Long.class.getName(), Long.class.getName(),
7087                                    Boolean.class.getName()
7088                            },
7089                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
7090                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
7091                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
7092                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
7093                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
7094            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7095                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N_H",
7097                            new String[] {
7098                                    Long.class.getName(), Long.class.getName(),
7099                                    Boolean.class.getName()
7100                            });
7101    
7102            /**
7103             * Returns all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
7104             *
7105             * @param resourcePrimKey the resource prim key
7106             * @param nodeId the node ID
7107             * @param head the head
7108             * @return the matching wiki pages
7109             * @throws SystemException if a system exception occurred
7110             */
7111            @Override
7112            public List<WikiPage> findByR_N_H(long resourcePrimKey, long nodeId,
7113                    boolean head) throws SystemException {
7114                    return findByR_N_H(resourcePrimKey, nodeId, head, QueryUtil.ALL_POS,
7115                            QueryUtil.ALL_POS, null);
7116            }
7117    
7118            /**
7119             * Returns a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
7120             *
7121             * <p>
7122             * 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.
7123             * </p>
7124             *
7125             * @param resourcePrimKey the resource prim key
7126             * @param nodeId the node ID
7127             * @param head the head
7128             * @param start the lower bound of the range of wiki pages
7129             * @param end the upper bound of the range of wiki pages (not inclusive)
7130             * @return the range of matching wiki pages
7131             * @throws SystemException if a system exception occurred
7132             */
7133            @Override
7134            public List<WikiPage> findByR_N_H(long resourcePrimKey, long nodeId,
7135                    boolean head, int start, int end) throws SystemException {
7136                    return findByR_N_H(resourcePrimKey, nodeId, head, start, end, null);
7137            }
7138    
7139            /**
7140             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
7141             *
7142             * <p>
7143             * 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.
7144             * </p>
7145             *
7146             * @param resourcePrimKey the resource prim key
7147             * @param nodeId the node ID
7148             * @param head the head
7149             * @param start the lower bound of the range of wiki pages
7150             * @param end the upper bound of the range of wiki pages (not inclusive)
7151             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7152             * @return the ordered range of matching wiki pages
7153             * @throws SystemException if a system exception occurred
7154             */
7155            @Override
7156            public List<WikiPage> findByR_N_H(long resourcePrimKey, long nodeId,
7157                    boolean head, int start, int end, OrderByComparator orderByComparator)
7158                    throws SystemException {
7159                    boolean pagination = true;
7160                    FinderPath finderPath = null;
7161                    Object[] finderArgs = null;
7162    
7163                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7164                                    (orderByComparator == null)) {
7165                            pagination = false;
7166                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H;
7167                            finderArgs = new Object[] { resourcePrimKey, nodeId, head };
7168                    }
7169                    else {
7170                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_H;
7171                            finderArgs = new Object[] {
7172                                            resourcePrimKey, nodeId, head,
7173                                            
7174                                            start, end, orderByComparator
7175                                    };
7176                    }
7177    
7178                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
7179                                    finderArgs, this);
7180    
7181                    if ((list != null) && !list.isEmpty()) {
7182                            for (WikiPage wikiPage : list) {
7183                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
7184                                                    (nodeId != wikiPage.getNodeId()) ||
7185                                                    (head != wikiPage.getHead())) {
7186                                            list = null;
7187    
7188                                            break;
7189                                    }
7190                            }
7191                    }
7192    
7193                    if (list == null) {
7194                            StringBundler query = null;
7195    
7196                            if (orderByComparator != null) {
7197                                    query = new StringBundler(5 +
7198                                                    (orderByComparator.getOrderByFields().length * 3));
7199                            }
7200                            else {
7201                                    query = new StringBundler(5);
7202                            }
7203    
7204                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
7205    
7206                            query.append(_FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2);
7207    
7208                            query.append(_FINDER_COLUMN_R_N_H_NODEID_2);
7209    
7210                            query.append(_FINDER_COLUMN_R_N_H_HEAD_2);
7211    
7212                            if (orderByComparator != null) {
7213                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7214                                            orderByComparator);
7215                            }
7216                            else
7217                             if (pagination) {
7218                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7219                            }
7220    
7221                            String sql = query.toString();
7222    
7223                            Session session = null;
7224    
7225                            try {
7226                                    session = openSession();
7227    
7228                                    Query q = session.createQuery(sql);
7229    
7230                                    QueryPos qPos = QueryPos.getInstance(q);
7231    
7232                                    qPos.add(resourcePrimKey);
7233    
7234                                    qPos.add(nodeId);
7235    
7236                                    qPos.add(head);
7237    
7238                                    if (!pagination) {
7239                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
7240                                                            start, end, false);
7241    
7242                                            Collections.sort(list);
7243    
7244                                            list = new UnmodifiableList<WikiPage>(list);
7245                                    }
7246                                    else {
7247                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
7248                                                            start, end);
7249                                    }
7250    
7251                                    cacheResult(list);
7252    
7253                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7254                            }
7255                            catch (Exception e) {
7256                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7257    
7258                                    throw processException(e);
7259                            }
7260                            finally {
7261                                    closeSession(session);
7262                            }
7263                    }
7264    
7265                    return list;
7266            }
7267    
7268            /**
7269             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
7270             *
7271             * @param resourcePrimKey the resource prim key
7272             * @param nodeId the node ID
7273             * @param head the head
7274             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7275             * @return the first matching wiki page
7276             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
7277             * @throws SystemException if a system exception occurred
7278             */
7279            @Override
7280            public WikiPage findByR_N_H_First(long resourcePrimKey, long nodeId,
7281                    boolean head, OrderByComparator orderByComparator)
7282                    throws NoSuchPageException, SystemException {
7283                    WikiPage wikiPage = fetchByR_N_H_First(resourcePrimKey, nodeId, head,
7284                                    orderByComparator);
7285    
7286                    if (wikiPage != null) {
7287                            return wikiPage;
7288                    }
7289    
7290                    StringBundler msg = new StringBundler(8);
7291    
7292                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7293    
7294                    msg.append("resourcePrimKey=");
7295                    msg.append(resourcePrimKey);
7296    
7297                    msg.append(", nodeId=");
7298                    msg.append(nodeId);
7299    
7300                    msg.append(", head=");
7301                    msg.append(head);
7302    
7303                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7304    
7305                    throw new NoSuchPageException(msg.toString());
7306            }
7307    
7308            /**
7309             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
7310             *
7311             * @param resourcePrimKey the resource prim key
7312             * @param nodeId the node ID
7313             * @param head the head
7314             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7315             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
7316             * @throws SystemException if a system exception occurred
7317             */
7318            @Override
7319            public WikiPage fetchByR_N_H_First(long resourcePrimKey, long nodeId,
7320                    boolean head, OrderByComparator orderByComparator)
7321                    throws SystemException {
7322                    List<WikiPage> list = findByR_N_H(resourcePrimKey, nodeId, head, 0, 1,
7323                                    orderByComparator);
7324    
7325                    if (!list.isEmpty()) {
7326                            return list.get(0);
7327                    }
7328    
7329                    return null;
7330            }
7331    
7332            /**
7333             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
7334             *
7335             * @param resourcePrimKey the resource prim key
7336             * @param nodeId the node ID
7337             * @param head the head
7338             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7339             * @return the last matching wiki page
7340             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
7341             * @throws SystemException if a system exception occurred
7342             */
7343            @Override
7344            public WikiPage findByR_N_H_Last(long resourcePrimKey, long nodeId,
7345                    boolean head, OrderByComparator orderByComparator)
7346                    throws NoSuchPageException, SystemException {
7347                    WikiPage wikiPage = fetchByR_N_H_Last(resourcePrimKey, nodeId, head,
7348                                    orderByComparator);
7349    
7350                    if (wikiPage != null) {
7351                            return wikiPage;
7352                    }
7353    
7354                    StringBundler msg = new StringBundler(8);
7355    
7356                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7357    
7358                    msg.append("resourcePrimKey=");
7359                    msg.append(resourcePrimKey);
7360    
7361                    msg.append(", nodeId=");
7362                    msg.append(nodeId);
7363    
7364                    msg.append(", head=");
7365                    msg.append(head);
7366    
7367                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7368    
7369                    throw new NoSuchPageException(msg.toString());
7370            }
7371    
7372            /**
7373             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
7374             *
7375             * @param resourcePrimKey the resource prim key
7376             * @param nodeId the node ID
7377             * @param head the head
7378             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7379             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
7380             * @throws SystemException if a system exception occurred
7381             */
7382            @Override
7383            public WikiPage fetchByR_N_H_Last(long resourcePrimKey, long nodeId,
7384                    boolean head, OrderByComparator orderByComparator)
7385                    throws SystemException {
7386                    int count = countByR_N_H(resourcePrimKey, nodeId, head);
7387    
7388                    if (count == 0) {
7389                            return null;
7390                    }
7391    
7392                    List<WikiPage> list = findByR_N_H(resourcePrimKey, nodeId, head,
7393                                    count - 1, count, orderByComparator);
7394    
7395                    if (!list.isEmpty()) {
7396                            return list.get(0);
7397                    }
7398    
7399                    return null;
7400            }
7401    
7402            /**
7403             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
7404             *
7405             * @param pageId the primary key of the current wiki page
7406             * @param resourcePrimKey the resource prim key
7407             * @param nodeId the node ID
7408             * @param head the head
7409             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7410             * @return the previous, current, and next wiki page
7411             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
7412             * @throws SystemException if a system exception occurred
7413             */
7414            @Override
7415            public WikiPage[] findByR_N_H_PrevAndNext(long pageId,
7416                    long resourcePrimKey, long nodeId, boolean head,
7417                    OrderByComparator orderByComparator)
7418                    throws NoSuchPageException, SystemException {
7419                    WikiPage wikiPage = findByPrimaryKey(pageId);
7420    
7421                    Session session = null;
7422    
7423                    try {
7424                            session = openSession();
7425    
7426                            WikiPage[] array = new WikiPageImpl[3];
7427    
7428                            array[0] = getByR_N_H_PrevAndNext(session, wikiPage,
7429                                            resourcePrimKey, nodeId, head, orderByComparator, true);
7430    
7431                            array[1] = wikiPage;
7432    
7433                            array[2] = getByR_N_H_PrevAndNext(session, wikiPage,
7434                                            resourcePrimKey, nodeId, head, orderByComparator, false);
7435    
7436                            return array;
7437                    }
7438                    catch (Exception e) {
7439                            throw processException(e);
7440                    }
7441                    finally {
7442                            closeSession(session);
7443                    }
7444            }
7445    
7446            protected WikiPage getByR_N_H_PrevAndNext(Session session,
7447                    WikiPage wikiPage, long resourcePrimKey, long nodeId, boolean head,
7448                    OrderByComparator orderByComparator, boolean previous) {
7449                    StringBundler query = null;
7450    
7451                    if (orderByComparator != null) {
7452                            query = new StringBundler(6 +
7453                                            (orderByComparator.getOrderByFields().length * 6));
7454                    }
7455                    else {
7456                            query = new StringBundler(3);
7457                    }
7458    
7459                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
7460    
7461                    query.append(_FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2);
7462    
7463                    query.append(_FINDER_COLUMN_R_N_H_NODEID_2);
7464    
7465                    query.append(_FINDER_COLUMN_R_N_H_HEAD_2);
7466    
7467                    if (orderByComparator != null) {
7468                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7469    
7470                            if (orderByConditionFields.length > 0) {
7471                                    query.append(WHERE_AND);
7472                            }
7473    
7474                            for (int i = 0; i < orderByConditionFields.length; i++) {
7475                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7476                                    query.append(orderByConditionFields[i]);
7477    
7478                                    if ((i + 1) < orderByConditionFields.length) {
7479                                            if (orderByComparator.isAscending() ^ previous) {
7480                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7481                                            }
7482                                            else {
7483                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7484                                            }
7485                                    }
7486                                    else {
7487                                            if (orderByComparator.isAscending() ^ previous) {
7488                                                    query.append(WHERE_GREATER_THAN);
7489                                            }
7490                                            else {
7491                                                    query.append(WHERE_LESSER_THAN);
7492                                            }
7493                                    }
7494                            }
7495    
7496                            query.append(ORDER_BY_CLAUSE);
7497    
7498                            String[] orderByFields = orderByComparator.getOrderByFields();
7499    
7500                            for (int i = 0; i < orderByFields.length; i++) {
7501                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7502                                    query.append(orderByFields[i]);
7503    
7504                                    if ((i + 1) < orderByFields.length) {
7505                                            if (orderByComparator.isAscending() ^ previous) {
7506                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7507                                            }
7508                                            else {
7509                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7510                                            }
7511                                    }
7512                                    else {
7513                                            if (orderByComparator.isAscending() ^ previous) {
7514                                                    query.append(ORDER_BY_ASC);
7515                                            }
7516                                            else {
7517                                                    query.append(ORDER_BY_DESC);
7518                                            }
7519                                    }
7520                            }
7521                    }
7522                    else {
7523                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7524                    }
7525    
7526                    String sql = query.toString();
7527    
7528                    Query q = session.createQuery(sql);
7529    
7530                    q.setFirstResult(0);
7531                    q.setMaxResults(2);
7532    
7533                    QueryPos qPos = QueryPos.getInstance(q);
7534    
7535                    qPos.add(resourcePrimKey);
7536    
7537                    qPos.add(nodeId);
7538    
7539                    qPos.add(head);
7540    
7541                    if (orderByComparator != null) {
7542                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
7543    
7544                            for (Object value : values) {
7545                                    qPos.add(value);
7546                            }
7547                    }
7548    
7549                    List<WikiPage> list = q.list();
7550    
7551                    if (list.size() == 2) {
7552                            return list.get(1);
7553                    }
7554                    else {
7555                            return null;
7556                    }
7557            }
7558    
7559            /**
7560             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63; from the database.
7561             *
7562             * @param resourcePrimKey the resource prim key
7563             * @param nodeId the node ID
7564             * @param head the head
7565             * @throws SystemException if a system exception occurred
7566             */
7567            @Override
7568            public void removeByR_N_H(long resourcePrimKey, long nodeId, boolean head)
7569                    throws SystemException {
7570                    for (WikiPage wikiPage : findByR_N_H(resourcePrimKey, nodeId, head,
7571                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7572                            remove(wikiPage);
7573                    }
7574            }
7575    
7576            /**
7577             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and head = &#63;.
7578             *
7579             * @param resourcePrimKey the resource prim key
7580             * @param nodeId the node ID
7581             * @param head the head
7582             * @return the number of matching wiki pages
7583             * @throws SystemException if a system exception occurred
7584             */
7585            @Override
7586            public int countByR_N_H(long resourcePrimKey, long nodeId, boolean head)
7587                    throws SystemException {
7588                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N_H;
7589    
7590                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, head };
7591    
7592                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7593                                    this);
7594    
7595                    if (count == null) {
7596                            StringBundler query = new StringBundler(4);
7597    
7598                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
7599    
7600                            query.append(_FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2);
7601    
7602                            query.append(_FINDER_COLUMN_R_N_H_NODEID_2);
7603    
7604                            query.append(_FINDER_COLUMN_R_N_H_HEAD_2);
7605    
7606                            String sql = query.toString();
7607    
7608                            Session session = null;
7609    
7610                            try {
7611                                    session = openSession();
7612    
7613                                    Query q = session.createQuery(sql);
7614    
7615                                    QueryPos qPos = QueryPos.getInstance(q);
7616    
7617                                    qPos.add(resourcePrimKey);
7618    
7619                                    qPos.add(nodeId);
7620    
7621                                    qPos.add(head);
7622    
7623                                    count = (Long)q.uniqueResult();
7624    
7625                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7626                            }
7627                            catch (Exception e) {
7628                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7629    
7630                                    throw processException(e);
7631                            }
7632                            finally {
7633                                    closeSession(session);
7634                            }
7635                    }
7636    
7637                    return count.intValue();
7638            }
7639    
7640            private static final String _FINDER_COLUMN_R_N_H_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
7641            private static final String _FINDER_COLUMN_R_N_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
7642            private static final String _FINDER_COLUMN_R_N_H_HEAD_2 = "wikiPage.head = ?";
7643            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7644                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
7645                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByR_N_S",
7646                            new String[] {
7647                                    Long.class.getName(), Long.class.getName(),
7648                                    Integer.class.getName(),
7649                                    
7650                            Integer.class.getName(), Integer.class.getName(),
7651                                    OrderByComparator.class.getName()
7652                            });
7653            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7654                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
7655                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_N_S",
7656                            new String[] {
7657                                    Long.class.getName(), Long.class.getName(),
7658                                    Integer.class.getName()
7659                            },
7660                            WikiPageModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
7661                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
7662                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
7663                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
7664                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
7665            public static final FinderPath FINDER_PATH_COUNT_BY_R_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
7666                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7667                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_N_S",
7668                            new String[] {
7669                                    Long.class.getName(), Long.class.getName(),
7670                                    Integer.class.getName()
7671                            });
7672    
7673            /**
7674             * Returns all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
7675             *
7676             * @param resourcePrimKey the resource prim key
7677             * @param nodeId the node ID
7678             * @param status the status
7679             * @return the matching wiki pages
7680             * @throws SystemException if a system exception occurred
7681             */
7682            @Override
7683            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
7684                    int status) throws SystemException {
7685                    return findByR_N_S(resourcePrimKey, nodeId, status, QueryUtil.ALL_POS,
7686                            QueryUtil.ALL_POS, null);
7687            }
7688    
7689            /**
7690             * Returns a range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
7691             *
7692             * <p>
7693             * 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.
7694             * </p>
7695             *
7696             * @param resourcePrimKey the resource prim key
7697             * @param nodeId the node ID
7698             * @param status the status
7699             * @param start the lower bound of the range of wiki pages
7700             * @param end the upper bound of the range of wiki pages (not inclusive)
7701             * @return the range of matching wiki pages
7702             * @throws SystemException if a system exception occurred
7703             */
7704            @Override
7705            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
7706                    int status, int start, int end) throws SystemException {
7707                    return findByR_N_S(resourcePrimKey, nodeId, status, start, end, null);
7708            }
7709    
7710            /**
7711             * Returns an ordered range of all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
7712             *
7713             * <p>
7714             * 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.
7715             * </p>
7716             *
7717             * @param resourcePrimKey the resource prim key
7718             * @param nodeId the node ID
7719             * @param status the status
7720             * @param start the lower bound of the range of wiki pages
7721             * @param end the upper bound of the range of wiki pages (not inclusive)
7722             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7723             * @return the ordered range of matching wiki pages
7724             * @throws SystemException if a system exception occurred
7725             */
7726            @Override
7727            public List<WikiPage> findByR_N_S(long resourcePrimKey, long nodeId,
7728                    int status, int start, int end, OrderByComparator orderByComparator)
7729                    throws SystemException {
7730                    boolean pagination = true;
7731                    FinderPath finderPath = null;
7732                    Object[] finderArgs = null;
7733    
7734                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7735                                    (orderByComparator == null)) {
7736                            pagination = false;
7737                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S;
7738                            finderArgs = new Object[] { resourcePrimKey, nodeId, status };
7739                    }
7740                    else {
7741                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_N_S;
7742                            finderArgs = new Object[] {
7743                                            resourcePrimKey, nodeId, status,
7744                                            
7745                                            start, end, orderByComparator
7746                                    };
7747                    }
7748    
7749                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
7750                                    finderArgs, this);
7751    
7752                    if ((list != null) && !list.isEmpty()) {
7753                            for (WikiPage wikiPage : list) {
7754                                    if ((resourcePrimKey != wikiPage.getResourcePrimKey()) ||
7755                                                    (nodeId != wikiPage.getNodeId()) ||
7756                                                    (status != wikiPage.getStatus())) {
7757                                            list = null;
7758    
7759                                            break;
7760                                    }
7761                            }
7762                    }
7763    
7764                    if (list == null) {
7765                            StringBundler query = null;
7766    
7767                            if (orderByComparator != null) {
7768                                    query = new StringBundler(5 +
7769                                                    (orderByComparator.getOrderByFields().length * 3));
7770                            }
7771                            else {
7772                                    query = new StringBundler(5);
7773                            }
7774    
7775                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
7776    
7777                            query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
7778    
7779                            query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
7780    
7781                            query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
7782    
7783                            if (orderByComparator != null) {
7784                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7785                                            orderByComparator);
7786                            }
7787                            else
7788                             if (pagination) {
7789                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
7790                            }
7791    
7792                            String sql = query.toString();
7793    
7794                            Session session = null;
7795    
7796                            try {
7797                                    session = openSession();
7798    
7799                                    Query q = session.createQuery(sql);
7800    
7801                                    QueryPos qPos = QueryPos.getInstance(q);
7802    
7803                                    qPos.add(resourcePrimKey);
7804    
7805                                    qPos.add(nodeId);
7806    
7807                                    qPos.add(status);
7808    
7809                                    if (!pagination) {
7810                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
7811                                                            start, end, false);
7812    
7813                                            Collections.sort(list);
7814    
7815                                            list = new UnmodifiableList<WikiPage>(list);
7816                                    }
7817                                    else {
7818                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
7819                                                            start, end);
7820                                    }
7821    
7822                                    cacheResult(list);
7823    
7824                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7825                            }
7826                            catch (Exception e) {
7827                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7828    
7829                                    throw processException(e);
7830                            }
7831                            finally {
7832                                    closeSession(session);
7833                            }
7834                    }
7835    
7836                    return list;
7837            }
7838    
7839            /**
7840             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
7841             *
7842             * @param resourcePrimKey the resource prim key
7843             * @param nodeId the node ID
7844             * @param status the status
7845             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7846             * @return the first matching wiki page
7847             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
7848             * @throws SystemException if a system exception occurred
7849             */
7850            @Override
7851            public WikiPage findByR_N_S_First(long resourcePrimKey, long nodeId,
7852                    int status, OrderByComparator orderByComparator)
7853                    throws NoSuchPageException, SystemException {
7854                    WikiPage wikiPage = fetchByR_N_S_First(resourcePrimKey, nodeId, status,
7855                                    orderByComparator);
7856    
7857                    if (wikiPage != null) {
7858                            return wikiPage;
7859                    }
7860    
7861                    StringBundler msg = new StringBundler(8);
7862    
7863                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7864    
7865                    msg.append("resourcePrimKey=");
7866                    msg.append(resourcePrimKey);
7867    
7868                    msg.append(", nodeId=");
7869                    msg.append(nodeId);
7870    
7871                    msg.append(", status=");
7872                    msg.append(status);
7873    
7874                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7875    
7876                    throw new NoSuchPageException(msg.toString());
7877            }
7878    
7879            /**
7880             * Returns the first wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
7881             *
7882             * @param resourcePrimKey the resource prim key
7883             * @param nodeId the node ID
7884             * @param status the status
7885             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7886             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
7887             * @throws SystemException if a system exception occurred
7888             */
7889            @Override
7890            public WikiPage fetchByR_N_S_First(long resourcePrimKey, long nodeId,
7891                    int status, OrderByComparator orderByComparator)
7892                    throws SystemException {
7893                    List<WikiPage> list = findByR_N_S(resourcePrimKey, nodeId, status, 0,
7894                                    1, orderByComparator);
7895    
7896                    if (!list.isEmpty()) {
7897                            return list.get(0);
7898                    }
7899    
7900                    return null;
7901            }
7902    
7903            /**
7904             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
7905             *
7906             * @param resourcePrimKey the resource prim key
7907             * @param nodeId the node ID
7908             * @param status the status
7909             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7910             * @return the last matching wiki page
7911             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
7912             * @throws SystemException if a system exception occurred
7913             */
7914            @Override
7915            public WikiPage findByR_N_S_Last(long resourcePrimKey, long nodeId,
7916                    int status, OrderByComparator orderByComparator)
7917                    throws NoSuchPageException, SystemException {
7918                    WikiPage wikiPage = fetchByR_N_S_Last(resourcePrimKey, nodeId, status,
7919                                    orderByComparator);
7920    
7921                    if (wikiPage != null) {
7922                            return wikiPage;
7923                    }
7924    
7925                    StringBundler msg = new StringBundler(8);
7926    
7927                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7928    
7929                    msg.append("resourcePrimKey=");
7930                    msg.append(resourcePrimKey);
7931    
7932                    msg.append(", nodeId=");
7933                    msg.append(nodeId);
7934    
7935                    msg.append(", status=");
7936                    msg.append(status);
7937    
7938                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7939    
7940                    throw new NoSuchPageException(msg.toString());
7941            }
7942    
7943            /**
7944             * Returns the last wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
7945             *
7946             * @param resourcePrimKey the resource prim key
7947             * @param nodeId the node ID
7948             * @param status the status
7949             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7950             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
7951             * @throws SystemException if a system exception occurred
7952             */
7953            @Override
7954            public WikiPage fetchByR_N_S_Last(long resourcePrimKey, long nodeId,
7955                    int status, OrderByComparator orderByComparator)
7956                    throws SystemException {
7957                    int count = countByR_N_S(resourcePrimKey, nodeId, status);
7958    
7959                    if (count == 0) {
7960                            return null;
7961                    }
7962    
7963                    List<WikiPage> list = findByR_N_S(resourcePrimKey, nodeId, status,
7964                                    count - 1, count, orderByComparator);
7965    
7966                    if (!list.isEmpty()) {
7967                            return list.get(0);
7968                    }
7969    
7970                    return null;
7971            }
7972    
7973            /**
7974             * Returns the wiki pages before and after the current wiki page in the ordered set where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
7975             *
7976             * @param pageId the primary key of the current wiki page
7977             * @param resourcePrimKey the resource prim key
7978             * @param nodeId the node ID
7979             * @param status the status
7980             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7981             * @return the previous, current, and next wiki page
7982             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
7983             * @throws SystemException if a system exception occurred
7984             */
7985            @Override
7986            public WikiPage[] findByR_N_S_PrevAndNext(long pageId,
7987                    long resourcePrimKey, long nodeId, int status,
7988                    OrderByComparator orderByComparator)
7989                    throws NoSuchPageException, SystemException {
7990                    WikiPage wikiPage = findByPrimaryKey(pageId);
7991    
7992                    Session session = null;
7993    
7994                    try {
7995                            session = openSession();
7996    
7997                            WikiPage[] array = new WikiPageImpl[3];
7998    
7999                            array[0] = getByR_N_S_PrevAndNext(session, wikiPage,
8000                                            resourcePrimKey, nodeId, status, orderByComparator, true);
8001    
8002                            array[1] = wikiPage;
8003    
8004                            array[2] = getByR_N_S_PrevAndNext(session, wikiPage,
8005                                            resourcePrimKey, nodeId, status, orderByComparator, false);
8006    
8007                            return array;
8008                    }
8009                    catch (Exception e) {
8010                            throw processException(e);
8011                    }
8012                    finally {
8013                            closeSession(session);
8014                    }
8015            }
8016    
8017            protected WikiPage getByR_N_S_PrevAndNext(Session session,
8018                    WikiPage wikiPage, long resourcePrimKey, long nodeId, int status,
8019                    OrderByComparator orderByComparator, boolean previous) {
8020                    StringBundler query = null;
8021    
8022                    if (orderByComparator != null) {
8023                            query = new StringBundler(6 +
8024                                            (orderByComparator.getOrderByFields().length * 6));
8025                    }
8026                    else {
8027                            query = new StringBundler(3);
8028                    }
8029    
8030                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
8031    
8032                    query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
8033    
8034                    query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
8035    
8036                    query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
8037    
8038                    if (orderByComparator != null) {
8039                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8040    
8041                            if (orderByConditionFields.length > 0) {
8042                                    query.append(WHERE_AND);
8043                            }
8044    
8045                            for (int i = 0; i < orderByConditionFields.length; i++) {
8046                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8047                                    query.append(orderByConditionFields[i]);
8048    
8049                                    if ((i + 1) < orderByConditionFields.length) {
8050                                            if (orderByComparator.isAscending() ^ previous) {
8051                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8052                                            }
8053                                            else {
8054                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8055                                            }
8056                                    }
8057                                    else {
8058                                            if (orderByComparator.isAscending() ^ previous) {
8059                                                    query.append(WHERE_GREATER_THAN);
8060                                            }
8061                                            else {
8062                                                    query.append(WHERE_LESSER_THAN);
8063                                            }
8064                                    }
8065                            }
8066    
8067                            query.append(ORDER_BY_CLAUSE);
8068    
8069                            String[] orderByFields = orderByComparator.getOrderByFields();
8070    
8071                            for (int i = 0; i < orderByFields.length; i++) {
8072                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8073                                    query.append(orderByFields[i]);
8074    
8075                                    if ((i + 1) < orderByFields.length) {
8076                                            if (orderByComparator.isAscending() ^ previous) {
8077                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8078                                            }
8079                                            else {
8080                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8081                                            }
8082                                    }
8083                                    else {
8084                                            if (orderByComparator.isAscending() ^ previous) {
8085                                                    query.append(ORDER_BY_ASC);
8086                                            }
8087                                            else {
8088                                                    query.append(ORDER_BY_DESC);
8089                                            }
8090                                    }
8091                            }
8092                    }
8093                    else {
8094                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8095                    }
8096    
8097                    String sql = query.toString();
8098    
8099                    Query q = session.createQuery(sql);
8100    
8101                    q.setFirstResult(0);
8102                    q.setMaxResults(2);
8103    
8104                    QueryPos qPos = QueryPos.getInstance(q);
8105    
8106                    qPos.add(resourcePrimKey);
8107    
8108                    qPos.add(nodeId);
8109    
8110                    qPos.add(status);
8111    
8112                    if (orderByComparator != null) {
8113                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
8114    
8115                            for (Object value : values) {
8116                                    qPos.add(value);
8117                            }
8118                    }
8119    
8120                    List<WikiPage> list = q.list();
8121    
8122                    if (list.size() == 2) {
8123                            return list.get(1);
8124                    }
8125                    else {
8126                            return null;
8127                    }
8128            }
8129    
8130            /**
8131             * Removes all the wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63; from the database.
8132             *
8133             * @param resourcePrimKey the resource prim key
8134             * @param nodeId the node ID
8135             * @param status the status
8136             * @throws SystemException if a system exception occurred
8137             */
8138            @Override
8139            public void removeByR_N_S(long resourcePrimKey, long nodeId, int status)
8140                    throws SystemException {
8141                    for (WikiPage wikiPage : findByR_N_S(resourcePrimKey, nodeId, status,
8142                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8143                            remove(wikiPage);
8144                    }
8145            }
8146    
8147            /**
8148             * Returns the number of wiki pages where resourcePrimKey = &#63; and nodeId = &#63; and status = &#63;.
8149             *
8150             * @param resourcePrimKey the resource prim key
8151             * @param nodeId the node ID
8152             * @param status the status
8153             * @return the number of matching wiki pages
8154             * @throws SystemException if a system exception occurred
8155             */
8156            @Override
8157            public int countByR_N_S(long resourcePrimKey, long nodeId, int status)
8158                    throws SystemException {
8159                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_N_S;
8160    
8161                    Object[] finderArgs = new Object[] { resourcePrimKey, nodeId, status };
8162    
8163                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8164                                    this);
8165    
8166                    if (count == null) {
8167                            StringBundler query = new StringBundler(4);
8168    
8169                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
8170    
8171                            query.append(_FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2);
8172    
8173                            query.append(_FINDER_COLUMN_R_N_S_NODEID_2);
8174    
8175                            query.append(_FINDER_COLUMN_R_N_S_STATUS_2);
8176    
8177                            String sql = query.toString();
8178    
8179                            Session session = null;
8180    
8181                            try {
8182                                    session = openSession();
8183    
8184                                    Query q = session.createQuery(sql);
8185    
8186                                    QueryPos qPos = QueryPos.getInstance(q);
8187    
8188                                    qPos.add(resourcePrimKey);
8189    
8190                                    qPos.add(nodeId);
8191    
8192                                    qPos.add(status);
8193    
8194                                    count = (Long)q.uniqueResult();
8195    
8196                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8197                            }
8198                            catch (Exception e) {
8199                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8200    
8201                                    throw processException(e);
8202                            }
8203                            finally {
8204                                    closeSession(session);
8205                            }
8206                    }
8207    
8208                    return count.intValue();
8209            }
8210    
8211            private static final String _FINDER_COLUMN_R_N_S_RESOURCEPRIMKEY_2 = "wikiPage.resourcePrimKey = ? AND ";
8212            private static final String _FINDER_COLUMN_R_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
8213            private static final String _FINDER_COLUMN_R_N_S_STATUS_2 = "wikiPage.status = ?";
8214            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
8215                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
8216                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H",
8217                            new String[] {
8218                                    Long.class.getName(), Long.class.getName(),
8219                                    Boolean.class.getName(),
8220                                    
8221                            Integer.class.getName(), Integer.class.getName(),
8222                                    OrderByComparator.class.getName()
8223                            });
8224            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
8225                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
8226                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H",
8227                            new String[] {
8228                                    Long.class.getName(), Long.class.getName(),
8229                                    Boolean.class.getName()
8230                            },
8231                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
8232                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
8233                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
8234                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
8235                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
8236            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
8237                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8238                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H",
8239                            new String[] {
8240                                    Long.class.getName(), Long.class.getName(),
8241                                    Boolean.class.getName()
8242                            });
8243    
8244            /**
8245             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
8246             *
8247             * @param groupId the group ID
8248             * @param nodeId the node ID
8249             * @param head the head
8250             * @return the matching wiki pages
8251             * @throws SystemException if a system exception occurred
8252             */
8253            @Override
8254            public List<WikiPage> findByG_N_H(long groupId, long nodeId, boolean head)
8255                    throws SystemException {
8256                    return findByG_N_H(groupId, nodeId, head, QueryUtil.ALL_POS,
8257                            QueryUtil.ALL_POS, null);
8258            }
8259    
8260            /**
8261             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
8262             *
8263             * <p>
8264             * 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.
8265             * </p>
8266             *
8267             * @param groupId the group ID
8268             * @param nodeId the node ID
8269             * @param head the head
8270             * @param start the lower bound of the range of wiki pages
8271             * @param end the upper bound of the range of wiki pages (not inclusive)
8272             * @return the range of matching wiki pages
8273             * @throws SystemException if a system exception occurred
8274             */
8275            @Override
8276            public List<WikiPage> findByG_N_H(long groupId, long nodeId, boolean head,
8277                    int start, int end) throws SystemException {
8278                    return findByG_N_H(groupId, nodeId, head, start, end, null);
8279            }
8280    
8281            /**
8282             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
8283             *
8284             * <p>
8285             * 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.
8286             * </p>
8287             *
8288             * @param groupId the group ID
8289             * @param nodeId the node ID
8290             * @param head the head
8291             * @param start the lower bound of the range of wiki pages
8292             * @param end the upper bound of the range of wiki pages (not inclusive)
8293             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8294             * @return the ordered range of matching wiki pages
8295             * @throws SystemException if a system exception occurred
8296             */
8297            @Override
8298            public List<WikiPage> findByG_N_H(long groupId, long nodeId, boolean head,
8299                    int start, int end, OrderByComparator orderByComparator)
8300                    throws SystemException {
8301                    boolean pagination = true;
8302                    FinderPath finderPath = null;
8303                    Object[] finderArgs = null;
8304    
8305                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8306                                    (orderByComparator == null)) {
8307                            pagination = false;
8308                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H;
8309                            finderArgs = new Object[] { groupId, nodeId, head };
8310                    }
8311                    else {
8312                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H;
8313                            finderArgs = new Object[] {
8314                                            groupId, nodeId, head,
8315                                            
8316                                            start, end, orderByComparator
8317                                    };
8318                    }
8319    
8320                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
8321                                    finderArgs, this);
8322    
8323                    if ((list != null) && !list.isEmpty()) {
8324                            for (WikiPage wikiPage : list) {
8325                                    if ((groupId != wikiPage.getGroupId()) ||
8326                                                    (nodeId != wikiPage.getNodeId()) ||
8327                                                    (head != wikiPage.getHead())) {
8328                                            list = null;
8329    
8330                                            break;
8331                                    }
8332                            }
8333                    }
8334    
8335                    if (list == null) {
8336                            StringBundler query = null;
8337    
8338                            if (orderByComparator != null) {
8339                                    query = new StringBundler(5 +
8340                                                    (orderByComparator.getOrderByFields().length * 3));
8341                            }
8342                            else {
8343                                    query = new StringBundler(5);
8344                            }
8345    
8346                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
8347    
8348                            query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
8349    
8350                            query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
8351    
8352                            query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
8353    
8354                            if (orderByComparator != null) {
8355                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8356                                            orderByComparator);
8357                            }
8358                            else
8359                             if (pagination) {
8360                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8361                            }
8362    
8363                            String sql = query.toString();
8364    
8365                            Session session = null;
8366    
8367                            try {
8368                                    session = openSession();
8369    
8370                                    Query q = session.createQuery(sql);
8371    
8372                                    QueryPos qPos = QueryPos.getInstance(q);
8373    
8374                                    qPos.add(groupId);
8375    
8376                                    qPos.add(nodeId);
8377    
8378                                    qPos.add(head);
8379    
8380                                    if (!pagination) {
8381                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
8382                                                            start, end, false);
8383    
8384                                            Collections.sort(list);
8385    
8386                                            list = new UnmodifiableList<WikiPage>(list);
8387                                    }
8388                                    else {
8389                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
8390                                                            start, end);
8391                                    }
8392    
8393                                    cacheResult(list);
8394    
8395                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8396                            }
8397                            catch (Exception e) {
8398                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8399    
8400                                    throw processException(e);
8401                            }
8402                            finally {
8403                                    closeSession(session);
8404                            }
8405                    }
8406    
8407                    return list;
8408            }
8409    
8410            /**
8411             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
8412             *
8413             * @param groupId the group ID
8414             * @param nodeId the node ID
8415             * @param head the head
8416             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8417             * @return the first matching wiki page
8418             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
8419             * @throws SystemException if a system exception occurred
8420             */
8421            @Override
8422            public WikiPage findByG_N_H_First(long groupId, long nodeId, boolean head,
8423                    OrderByComparator orderByComparator)
8424                    throws NoSuchPageException, SystemException {
8425                    WikiPage wikiPage = fetchByG_N_H_First(groupId, nodeId, head,
8426                                    orderByComparator);
8427    
8428                    if (wikiPage != null) {
8429                            return wikiPage;
8430                    }
8431    
8432                    StringBundler msg = new StringBundler(8);
8433    
8434                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8435    
8436                    msg.append("groupId=");
8437                    msg.append(groupId);
8438    
8439                    msg.append(", nodeId=");
8440                    msg.append(nodeId);
8441    
8442                    msg.append(", head=");
8443                    msg.append(head);
8444    
8445                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8446    
8447                    throw new NoSuchPageException(msg.toString());
8448            }
8449    
8450            /**
8451             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
8452             *
8453             * @param groupId the group ID
8454             * @param nodeId the node ID
8455             * @param head the head
8456             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8457             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
8458             * @throws SystemException if a system exception occurred
8459             */
8460            @Override
8461            public WikiPage fetchByG_N_H_First(long groupId, long nodeId, boolean head,
8462                    OrderByComparator orderByComparator) throws SystemException {
8463                    List<WikiPage> list = findByG_N_H(groupId, nodeId, head, 0, 1,
8464                                    orderByComparator);
8465    
8466                    if (!list.isEmpty()) {
8467                            return list.get(0);
8468                    }
8469    
8470                    return null;
8471            }
8472    
8473            /**
8474             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
8475             *
8476             * @param groupId the group ID
8477             * @param nodeId the node ID
8478             * @param head the head
8479             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8480             * @return the last matching wiki page
8481             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
8482             * @throws SystemException if a system exception occurred
8483             */
8484            @Override
8485            public WikiPage findByG_N_H_Last(long groupId, long nodeId, boolean head,
8486                    OrderByComparator orderByComparator)
8487                    throws NoSuchPageException, SystemException {
8488                    WikiPage wikiPage = fetchByG_N_H_Last(groupId, nodeId, head,
8489                                    orderByComparator);
8490    
8491                    if (wikiPage != null) {
8492                            return wikiPage;
8493                    }
8494    
8495                    StringBundler msg = new StringBundler(8);
8496    
8497                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8498    
8499                    msg.append("groupId=");
8500                    msg.append(groupId);
8501    
8502                    msg.append(", nodeId=");
8503                    msg.append(nodeId);
8504    
8505                    msg.append(", head=");
8506                    msg.append(head);
8507    
8508                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8509    
8510                    throw new NoSuchPageException(msg.toString());
8511            }
8512    
8513            /**
8514             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
8515             *
8516             * @param groupId the group ID
8517             * @param nodeId the node ID
8518             * @param head the head
8519             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8520             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
8521             * @throws SystemException if a system exception occurred
8522             */
8523            @Override
8524            public WikiPage fetchByG_N_H_Last(long groupId, long nodeId, boolean head,
8525                    OrderByComparator orderByComparator) throws SystemException {
8526                    int count = countByG_N_H(groupId, nodeId, head);
8527    
8528                    if (count == 0) {
8529                            return null;
8530                    }
8531    
8532                    List<WikiPage> list = findByG_N_H(groupId, nodeId, head, count - 1,
8533                                    count, orderByComparator);
8534    
8535                    if (!list.isEmpty()) {
8536                            return list.get(0);
8537                    }
8538    
8539                    return null;
8540            }
8541    
8542            /**
8543             * Returns the wiki pages before and after the current wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63;.
8544             *
8545             * @param pageId the primary key of the current wiki page
8546             * @param groupId the group ID
8547             * @param nodeId the node ID
8548             * @param head the head
8549             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8550             * @return the previous, current, and next wiki page
8551             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
8552             * @throws SystemException if a system exception occurred
8553             */
8554            @Override
8555            public WikiPage[] findByG_N_H_PrevAndNext(long pageId, long groupId,
8556                    long nodeId, boolean head, OrderByComparator orderByComparator)
8557                    throws NoSuchPageException, SystemException {
8558                    WikiPage wikiPage = findByPrimaryKey(pageId);
8559    
8560                    Session session = null;
8561    
8562                    try {
8563                            session = openSession();
8564    
8565                            WikiPage[] array = new WikiPageImpl[3];
8566    
8567                            array[0] = getByG_N_H_PrevAndNext(session, wikiPage, groupId,
8568                                            nodeId, head, orderByComparator, true);
8569    
8570                            array[1] = wikiPage;
8571    
8572                            array[2] = getByG_N_H_PrevAndNext(session, wikiPage, groupId,
8573                                            nodeId, head, orderByComparator, false);
8574    
8575                            return array;
8576                    }
8577                    catch (Exception e) {
8578                            throw processException(e);
8579                    }
8580                    finally {
8581                            closeSession(session);
8582                    }
8583            }
8584    
8585            protected WikiPage getByG_N_H_PrevAndNext(Session session,
8586                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
8587                    OrderByComparator orderByComparator, boolean previous) {
8588                    StringBundler query = null;
8589    
8590                    if (orderByComparator != null) {
8591                            query = new StringBundler(6 +
8592                                            (orderByComparator.getOrderByFields().length * 6));
8593                    }
8594                    else {
8595                            query = new StringBundler(3);
8596                    }
8597    
8598                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
8599    
8600                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
8601    
8602                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
8603    
8604                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
8605    
8606                    if (orderByComparator != null) {
8607                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8608    
8609                            if (orderByConditionFields.length > 0) {
8610                                    query.append(WHERE_AND);
8611                            }
8612    
8613                            for (int i = 0; i < orderByConditionFields.length; i++) {
8614                                    query.append(_ORDER_BY_ENTITY_ALIAS);
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                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8641                                    query.append(orderByFields[i]);
8642    
8643                                    if ((i + 1) < orderByFields.length) {
8644                                            if (orderByComparator.isAscending() ^ previous) {
8645                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8646                                            }
8647                                            else {
8648                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8649                                            }
8650                                    }
8651                                    else {
8652                                            if (orderByComparator.isAscending() ^ previous) {
8653                                                    query.append(ORDER_BY_ASC);
8654                                            }
8655                                            else {
8656                                                    query.append(ORDER_BY_DESC);
8657                                            }
8658                                    }
8659                            }
8660                    }
8661                    else {
8662                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8663                    }
8664    
8665                    String sql = query.toString();
8666    
8667                    Query q = session.createQuery(sql);
8668    
8669                    q.setFirstResult(0);
8670                    q.setMaxResults(2);
8671    
8672                    QueryPos qPos = QueryPos.getInstance(q);
8673    
8674                    qPos.add(groupId);
8675    
8676                    qPos.add(nodeId);
8677    
8678                    qPos.add(head);
8679    
8680                    if (orderByComparator != null) {
8681                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
8682    
8683                            for (Object value : values) {
8684                                    qPos.add(value);
8685                            }
8686                    }
8687    
8688                    List<WikiPage> list = q.list();
8689    
8690                    if (list.size() == 2) {
8691                            return list.get(1);
8692                    }
8693                    else {
8694                            return null;
8695                    }
8696            }
8697    
8698            /**
8699             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
8700             *
8701             * @param groupId the group ID
8702             * @param nodeId the node ID
8703             * @param head the head
8704             * @return the matching wiki pages that the user has permission to view
8705             * @throws SystemException if a system exception occurred
8706             */
8707            @Override
8708            public List<WikiPage> filterFindByG_N_H(long groupId, long nodeId,
8709                    boolean head) throws SystemException {
8710                    return filterFindByG_N_H(groupId, nodeId, head, QueryUtil.ALL_POS,
8711                            QueryUtil.ALL_POS, null);
8712            }
8713    
8714            /**
8715             * Returns a range of all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
8716             *
8717             * <p>
8718             * 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.
8719             * </p>
8720             *
8721             * @param groupId the group ID
8722             * @param nodeId the node ID
8723             * @param head the head
8724             * @param start the lower bound of the range of wiki pages
8725             * @param end the upper bound of the range of wiki pages (not inclusive)
8726             * @return the range of matching wiki pages that the user has permission to view
8727             * @throws SystemException if a system exception occurred
8728             */
8729            @Override
8730            public List<WikiPage> filterFindByG_N_H(long groupId, long nodeId,
8731                    boolean head, int start, int end) throws SystemException {
8732                    return filterFindByG_N_H(groupId, nodeId, head, start, end, null);
8733            }
8734    
8735            /**
8736             * 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;.
8737             *
8738             * <p>
8739             * 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.
8740             * </p>
8741             *
8742             * @param groupId the group ID
8743             * @param nodeId the node ID
8744             * @param head the head
8745             * @param start the lower bound of the range of wiki pages
8746             * @param end the upper bound of the range of wiki pages (not inclusive)
8747             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8748             * @return the ordered range of matching wiki pages that the user has permission to view
8749             * @throws SystemException if a system exception occurred
8750             */
8751            @Override
8752            public List<WikiPage> filterFindByG_N_H(long groupId, long nodeId,
8753                    boolean head, int start, int end, OrderByComparator orderByComparator)
8754                    throws SystemException {
8755                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8756                            return findByG_N_H(groupId, nodeId, head, start, end,
8757                                    orderByComparator);
8758                    }
8759    
8760                    StringBundler query = null;
8761    
8762                    if (orderByComparator != null) {
8763                            query = new StringBundler(5 +
8764                                            (orderByComparator.getOrderByFields().length * 3));
8765                    }
8766                    else {
8767                            query = new StringBundler(5);
8768                    }
8769    
8770                    if (getDB().isSupportsInlineDistinct()) {
8771                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
8772                    }
8773                    else {
8774                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
8775                    }
8776    
8777                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
8778    
8779                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
8780    
8781                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
8782    
8783                    if (!getDB().isSupportsInlineDistinct()) {
8784                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
8785                    }
8786    
8787                    if (orderByComparator != null) {
8788                            if (getDB().isSupportsInlineDistinct()) {
8789                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8790                                            orderByComparator, true);
8791                            }
8792                            else {
8793                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8794                                            orderByComparator, true);
8795                            }
8796                    }
8797                    else {
8798                            if (getDB().isSupportsInlineDistinct()) {
8799                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8800                            }
8801                            else {
8802                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
8803                            }
8804                    }
8805    
8806                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8807                                    WikiPage.class.getName(),
8808                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8809    
8810                    Session session = null;
8811    
8812                    try {
8813                            session = openSession();
8814    
8815                            SQLQuery q = session.createSQLQuery(sql);
8816    
8817                            if (getDB().isSupportsInlineDistinct()) {
8818                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
8819                            }
8820                            else {
8821                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
8822                            }
8823    
8824                            QueryPos qPos = QueryPos.getInstance(q);
8825    
8826                            qPos.add(groupId);
8827    
8828                            qPos.add(nodeId);
8829    
8830                            qPos.add(head);
8831    
8832                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
8833                    }
8834                    catch (Exception e) {
8835                            throw processException(e);
8836                    }
8837                    finally {
8838                            closeSession(session);
8839                    }
8840            }
8841    
8842            /**
8843             * 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;.
8844             *
8845             * @param pageId the primary key of the current wiki page
8846             * @param groupId the group ID
8847             * @param nodeId the node ID
8848             * @param head the head
8849             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8850             * @return the previous, current, and next wiki page
8851             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
8852             * @throws SystemException if a system exception occurred
8853             */
8854            @Override
8855            public WikiPage[] filterFindByG_N_H_PrevAndNext(long pageId, long groupId,
8856                    long nodeId, boolean head, OrderByComparator orderByComparator)
8857                    throws NoSuchPageException, SystemException {
8858                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8859                            return findByG_N_H_PrevAndNext(pageId, groupId, nodeId, head,
8860                                    orderByComparator);
8861                    }
8862    
8863                    WikiPage wikiPage = findByPrimaryKey(pageId);
8864    
8865                    Session session = null;
8866    
8867                    try {
8868                            session = openSession();
8869    
8870                            WikiPage[] array = new WikiPageImpl[3];
8871    
8872                            array[0] = filterGetByG_N_H_PrevAndNext(session, wikiPage, groupId,
8873                                            nodeId, head, orderByComparator, true);
8874    
8875                            array[1] = wikiPage;
8876    
8877                            array[2] = filterGetByG_N_H_PrevAndNext(session, wikiPage, groupId,
8878                                            nodeId, head, orderByComparator, false);
8879    
8880                            return array;
8881                    }
8882                    catch (Exception e) {
8883                            throw processException(e);
8884                    }
8885                    finally {
8886                            closeSession(session);
8887                    }
8888            }
8889    
8890            protected WikiPage filterGetByG_N_H_PrevAndNext(Session session,
8891                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
8892                    OrderByComparator orderByComparator, boolean previous) {
8893                    StringBundler query = null;
8894    
8895                    if (orderByComparator != null) {
8896                            query = new StringBundler(6 +
8897                                            (orderByComparator.getOrderByFields().length * 6));
8898                    }
8899                    else {
8900                            query = new StringBundler(3);
8901                    }
8902    
8903                    if (getDB().isSupportsInlineDistinct()) {
8904                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
8905                    }
8906                    else {
8907                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
8908                    }
8909    
8910                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
8911    
8912                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
8913    
8914                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
8915    
8916                    if (!getDB().isSupportsInlineDistinct()) {
8917                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
8918                    }
8919    
8920                    if (orderByComparator != null) {
8921                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8922    
8923                            if (orderByConditionFields.length > 0) {
8924                                    query.append(WHERE_AND);
8925                            }
8926    
8927                            for (int i = 0; i < orderByConditionFields.length; i++) {
8928                                    if (getDB().isSupportsInlineDistinct()) {
8929                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8930                                    }
8931                                    else {
8932                                            query.append(_ORDER_BY_ENTITY_TABLE);
8933                                    }
8934    
8935                                    query.append(orderByConditionFields[i]);
8936    
8937                                    if ((i + 1) < orderByConditionFields.length) {
8938                                            if (orderByComparator.isAscending() ^ previous) {
8939                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8940                                            }
8941                                            else {
8942                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8943                                            }
8944                                    }
8945                                    else {
8946                                            if (orderByComparator.isAscending() ^ previous) {
8947                                                    query.append(WHERE_GREATER_THAN);
8948                                            }
8949                                            else {
8950                                                    query.append(WHERE_LESSER_THAN);
8951                                            }
8952                                    }
8953                            }
8954    
8955                            query.append(ORDER_BY_CLAUSE);
8956    
8957                            String[] orderByFields = orderByComparator.getOrderByFields();
8958    
8959                            for (int i = 0; i < orderByFields.length; i++) {
8960                                    if (getDB().isSupportsInlineDistinct()) {
8961                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8962                                    }
8963                                    else {
8964                                            query.append(_ORDER_BY_ENTITY_TABLE);
8965                                    }
8966    
8967                                    query.append(orderByFields[i]);
8968    
8969                                    if ((i + 1) < orderByFields.length) {
8970                                            if (orderByComparator.isAscending() ^ previous) {
8971                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8972                                            }
8973                                            else {
8974                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8975                                            }
8976                                    }
8977                                    else {
8978                                            if (orderByComparator.isAscending() ^ previous) {
8979                                                    query.append(ORDER_BY_ASC);
8980                                            }
8981                                            else {
8982                                                    query.append(ORDER_BY_DESC);
8983                                            }
8984                                    }
8985                            }
8986                    }
8987                    else {
8988                            if (getDB().isSupportsInlineDistinct()) {
8989                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
8990                            }
8991                            else {
8992                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
8993                            }
8994                    }
8995    
8996                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8997                                    WikiPage.class.getName(),
8998                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8999    
9000                    SQLQuery q = session.createSQLQuery(sql);
9001    
9002                    q.setFirstResult(0);
9003                    q.setMaxResults(2);
9004    
9005                    if (getDB().isSupportsInlineDistinct()) {
9006                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
9007                    }
9008                    else {
9009                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
9010                    }
9011    
9012                    QueryPos qPos = QueryPos.getInstance(q);
9013    
9014                    qPos.add(groupId);
9015    
9016                    qPos.add(nodeId);
9017    
9018                    qPos.add(head);
9019    
9020                    if (orderByComparator != null) {
9021                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
9022    
9023                            for (Object value : values) {
9024                                    qPos.add(value);
9025                            }
9026                    }
9027    
9028                    List<WikiPage> list = q.list();
9029    
9030                    if (list.size() == 2) {
9031                            return list.get(1);
9032                    }
9033                    else {
9034                            return null;
9035                    }
9036            }
9037    
9038            /**
9039             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; from the database.
9040             *
9041             * @param groupId the group ID
9042             * @param nodeId the node ID
9043             * @param head the head
9044             * @throws SystemException if a system exception occurred
9045             */
9046            @Override
9047            public void removeByG_N_H(long groupId, long nodeId, boolean head)
9048                    throws SystemException {
9049                    for (WikiPage wikiPage : findByG_N_H(groupId, nodeId, head,
9050                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9051                            remove(wikiPage);
9052                    }
9053            }
9054    
9055            /**
9056             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63;.
9057             *
9058             * @param groupId the group ID
9059             * @param nodeId the node ID
9060             * @param head the head
9061             * @return the number of matching wiki pages
9062             * @throws SystemException if a system exception occurred
9063             */
9064            @Override
9065            public int countByG_N_H(long groupId, long nodeId, boolean head)
9066                    throws SystemException {
9067                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H;
9068    
9069                    Object[] finderArgs = new Object[] { groupId, nodeId, head };
9070    
9071                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9072                                    this);
9073    
9074                    if (count == null) {
9075                            StringBundler query = new StringBundler(4);
9076    
9077                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
9078    
9079                            query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
9080    
9081                            query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
9082    
9083                            query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
9084    
9085                            String sql = query.toString();
9086    
9087                            Session session = null;
9088    
9089                            try {
9090                                    session = openSession();
9091    
9092                                    Query q = session.createQuery(sql);
9093    
9094                                    QueryPos qPos = QueryPos.getInstance(q);
9095    
9096                                    qPos.add(groupId);
9097    
9098                                    qPos.add(nodeId);
9099    
9100                                    qPos.add(head);
9101    
9102                                    count = (Long)q.uniqueResult();
9103    
9104                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9105                            }
9106                            catch (Exception e) {
9107                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9108    
9109                                    throw processException(e);
9110                            }
9111                            finally {
9112                                    closeSession(session);
9113                            }
9114                    }
9115    
9116                    return count.intValue();
9117            }
9118    
9119            /**
9120             * Returns the number of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63;.
9121             *
9122             * @param groupId the group ID
9123             * @param nodeId the node ID
9124             * @param head the head
9125             * @return the number of matching wiki pages that the user has permission to view
9126             * @throws SystemException if a system exception occurred
9127             */
9128            @Override
9129            public int filterCountByG_N_H(long groupId, long nodeId, boolean head)
9130                    throws SystemException {
9131                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9132                            return countByG_N_H(groupId, nodeId, head);
9133                    }
9134    
9135                    StringBundler query = new StringBundler(4);
9136    
9137                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
9138    
9139                    query.append(_FINDER_COLUMN_G_N_H_GROUPID_2);
9140    
9141                    query.append(_FINDER_COLUMN_G_N_H_NODEID_2);
9142    
9143                    query.append(_FINDER_COLUMN_G_N_H_HEAD_2);
9144    
9145                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9146                                    WikiPage.class.getName(),
9147                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9148    
9149                    Session session = null;
9150    
9151                    try {
9152                            session = openSession();
9153    
9154                            SQLQuery q = session.createSQLQuery(sql);
9155    
9156                            q.addScalar(COUNT_COLUMN_NAME,
9157                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9158    
9159                            QueryPos qPos = QueryPos.getInstance(q);
9160    
9161                            qPos.add(groupId);
9162    
9163                            qPos.add(nodeId);
9164    
9165                            qPos.add(head);
9166    
9167                            Long count = (Long)q.uniqueResult();
9168    
9169                            return count.intValue();
9170                    }
9171                    catch (Exception e) {
9172                            throw processException(e);
9173                    }
9174                    finally {
9175                            closeSession(session);
9176                    }
9177            }
9178    
9179            private static final String _FINDER_COLUMN_G_N_H_GROUPID_2 = "wikiPage.groupId = ? AND ";
9180            private static final String _FINDER_COLUMN_G_N_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
9181            private static final String _FINDER_COLUMN_G_N_H_HEAD_2 = "wikiPage.head = ?";
9182            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9183                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
9184                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_S",
9185                            new String[] {
9186                                    Long.class.getName(), Long.class.getName(),
9187                                    Integer.class.getName(),
9188                                    
9189                            Integer.class.getName(), Integer.class.getName(),
9190                                    OrderByComparator.class.getName()
9191                            });
9192            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9193                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
9194                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_S",
9195                            new String[] {
9196                                    Long.class.getName(), Long.class.getName(),
9197                                    Integer.class.getName()
9198                            },
9199                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
9200                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
9201                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
9202                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
9203                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
9204            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
9205                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9206                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_S",
9207                            new String[] {
9208                                    Long.class.getName(), Long.class.getName(),
9209                                    Integer.class.getName()
9210                            });
9211    
9212            /**
9213             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
9214             *
9215             * @param groupId the group ID
9216             * @param nodeId the node ID
9217             * @param status the status
9218             * @return the matching wiki pages
9219             * @throws SystemException if a system exception occurred
9220             */
9221            @Override
9222            public List<WikiPage> findByG_N_S(long groupId, long nodeId, int status)
9223                    throws SystemException {
9224                    return findByG_N_S(groupId, nodeId, status, QueryUtil.ALL_POS,
9225                            QueryUtil.ALL_POS, null);
9226            }
9227    
9228            /**
9229             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
9230             *
9231             * <p>
9232             * 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.
9233             * </p>
9234             *
9235             * @param groupId the group ID
9236             * @param nodeId the node ID
9237             * @param status the status
9238             * @param start the lower bound of the range of wiki pages
9239             * @param end the upper bound of the range of wiki pages (not inclusive)
9240             * @return the range of matching wiki pages
9241             * @throws SystemException if a system exception occurred
9242             */
9243            @Override
9244            public List<WikiPage> findByG_N_S(long groupId, long nodeId, int status,
9245                    int start, int end) throws SystemException {
9246                    return findByG_N_S(groupId, nodeId, status, start, end, null);
9247            }
9248    
9249            /**
9250             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
9251             *
9252             * <p>
9253             * 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.
9254             * </p>
9255             *
9256             * @param groupId the group ID
9257             * @param nodeId the node ID
9258             * @param status the status
9259             * @param start the lower bound of the range of wiki pages
9260             * @param end the upper bound of the range of wiki pages (not inclusive)
9261             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9262             * @return the ordered range of matching wiki pages
9263             * @throws SystemException if a system exception occurred
9264             */
9265            @Override
9266            public List<WikiPage> findByG_N_S(long groupId, long nodeId, int status,
9267                    int start, int end, OrderByComparator orderByComparator)
9268                    throws SystemException {
9269                    boolean pagination = true;
9270                    FinderPath finderPath = null;
9271                    Object[] finderArgs = null;
9272    
9273                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9274                                    (orderByComparator == null)) {
9275                            pagination = false;
9276                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S;
9277                            finderArgs = new Object[] { groupId, nodeId, status };
9278                    }
9279                    else {
9280                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_S;
9281                            finderArgs = new Object[] {
9282                                            groupId, nodeId, status,
9283                                            
9284                                            start, end, orderByComparator
9285                                    };
9286                    }
9287    
9288                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
9289                                    finderArgs, this);
9290    
9291                    if ((list != null) && !list.isEmpty()) {
9292                            for (WikiPage wikiPage : list) {
9293                                    if ((groupId != wikiPage.getGroupId()) ||
9294                                                    (nodeId != wikiPage.getNodeId()) ||
9295                                                    (status != wikiPage.getStatus())) {
9296                                            list = null;
9297    
9298                                            break;
9299                                    }
9300                            }
9301                    }
9302    
9303                    if (list == null) {
9304                            StringBundler query = null;
9305    
9306                            if (orderByComparator != null) {
9307                                    query = new StringBundler(5 +
9308                                                    (orderByComparator.getOrderByFields().length * 3));
9309                            }
9310                            else {
9311                                    query = new StringBundler(5);
9312                            }
9313    
9314                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
9315    
9316                            query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
9317    
9318                            query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
9319    
9320                            query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
9321    
9322                            if (orderByComparator != null) {
9323                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9324                                            orderByComparator);
9325                            }
9326                            else
9327                             if (pagination) {
9328                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
9329                            }
9330    
9331                            String sql = query.toString();
9332    
9333                            Session session = null;
9334    
9335                            try {
9336                                    session = openSession();
9337    
9338                                    Query q = session.createQuery(sql);
9339    
9340                                    QueryPos qPos = QueryPos.getInstance(q);
9341    
9342                                    qPos.add(groupId);
9343    
9344                                    qPos.add(nodeId);
9345    
9346                                    qPos.add(status);
9347    
9348                                    if (!pagination) {
9349                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
9350                                                            start, end, false);
9351    
9352                                            Collections.sort(list);
9353    
9354                                            list = new UnmodifiableList<WikiPage>(list);
9355                                    }
9356                                    else {
9357                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
9358                                                            start, end);
9359                                    }
9360    
9361                                    cacheResult(list);
9362    
9363                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9364                            }
9365                            catch (Exception e) {
9366                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9367    
9368                                    throw processException(e);
9369                            }
9370                            finally {
9371                                    closeSession(session);
9372                            }
9373                    }
9374    
9375                    return list;
9376            }
9377    
9378            /**
9379             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
9380             *
9381             * @param groupId the group ID
9382             * @param nodeId the node ID
9383             * @param status the status
9384             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9385             * @return the first matching wiki page
9386             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9387             * @throws SystemException if a system exception occurred
9388             */
9389            @Override
9390            public WikiPage findByG_N_S_First(long groupId, long nodeId, int status,
9391                    OrderByComparator orderByComparator)
9392                    throws NoSuchPageException, SystemException {
9393                    WikiPage wikiPage = fetchByG_N_S_First(groupId, nodeId, status,
9394                                    orderByComparator);
9395    
9396                    if (wikiPage != null) {
9397                            return wikiPage;
9398                    }
9399    
9400                    StringBundler msg = new StringBundler(8);
9401    
9402                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9403    
9404                    msg.append("groupId=");
9405                    msg.append(groupId);
9406    
9407                    msg.append(", nodeId=");
9408                    msg.append(nodeId);
9409    
9410                    msg.append(", status=");
9411                    msg.append(status);
9412    
9413                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9414    
9415                    throw new NoSuchPageException(msg.toString());
9416            }
9417    
9418            /**
9419             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
9420             *
9421             * @param groupId the group ID
9422             * @param nodeId the node ID
9423             * @param status the status
9424             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9425             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
9426             * @throws SystemException if a system exception occurred
9427             */
9428            @Override
9429            public WikiPage fetchByG_N_S_First(long groupId, long nodeId, int status,
9430                    OrderByComparator orderByComparator) throws SystemException {
9431                    List<WikiPage> list = findByG_N_S(groupId, nodeId, status, 0, 1,
9432                                    orderByComparator);
9433    
9434                    if (!list.isEmpty()) {
9435                            return list.get(0);
9436                    }
9437    
9438                    return null;
9439            }
9440    
9441            /**
9442             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
9443             *
9444             * @param groupId the group ID
9445             * @param nodeId the node ID
9446             * @param status the status
9447             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9448             * @return the last matching wiki page
9449             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
9450             * @throws SystemException if a system exception occurred
9451             */
9452            @Override
9453            public WikiPage findByG_N_S_Last(long groupId, long nodeId, int status,
9454                    OrderByComparator orderByComparator)
9455                    throws NoSuchPageException, SystemException {
9456                    WikiPage wikiPage = fetchByG_N_S_Last(groupId, nodeId, status,
9457                                    orderByComparator);
9458    
9459                    if (wikiPage != null) {
9460                            return wikiPage;
9461                    }
9462    
9463                    StringBundler msg = new StringBundler(8);
9464    
9465                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9466    
9467                    msg.append("groupId=");
9468                    msg.append(groupId);
9469    
9470                    msg.append(", nodeId=");
9471                    msg.append(nodeId);
9472    
9473                    msg.append(", status=");
9474                    msg.append(status);
9475    
9476                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9477    
9478                    throw new NoSuchPageException(msg.toString());
9479            }
9480    
9481            /**
9482             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
9483             *
9484             * @param groupId the group ID
9485             * @param nodeId the node ID
9486             * @param status the status
9487             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9488             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
9489             * @throws SystemException if a system exception occurred
9490             */
9491            @Override
9492            public WikiPage fetchByG_N_S_Last(long groupId, long nodeId, int status,
9493                    OrderByComparator orderByComparator) throws SystemException {
9494                    int count = countByG_N_S(groupId, nodeId, status);
9495    
9496                    if (count == 0) {
9497                            return null;
9498                    }
9499    
9500                    List<WikiPage> list = findByG_N_S(groupId, nodeId, status, count - 1,
9501                                    count, orderByComparator);
9502    
9503                    if (!list.isEmpty()) {
9504                            return list.get(0);
9505                    }
9506    
9507                    return null;
9508            }
9509    
9510            /**
9511             * Returns the wiki pages before and after the current wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and status = &#63;.
9512             *
9513             * @param pageId the primary key of the current wiki page
9514             * @param groupId the group ID
9515             * @param nodeId the node ID
9516             * @param status the status
9517             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9518             * @return the previous, current, and next wiki page
9519             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
9520             * @throws SystemException if a system exception occurred
9521             */
9522            @Override
9523            public WikiPage[] findByG_N_S_PrevAndNext(long pageId, long groupId,
9524                    long nodeId, int status, OrderByComparator orderByComparator)
9525                    throws NoSuchPageException, SystemException {
9526                    WikiPage wikiPage = findByPrimaryKey(pageId);
9527    
9528                    Session session = null;
9529    
9530                    try {
9531                            session = openSession();
9532    
9533                            WikiPage[] array = new WikiPageImpl[3];
9534    
9535                            array[0] = getByG_N_S_PrevAndNext(session, wikiPage, groupId,
9536                                            nodeId, status, orderByComparator, true);
9537    
9538                            array[1] = wikiPage;
9539    
9540                            array[2] = getByG_N_S_PrevAndNext(session, wikiPage, groupId,
9541                                            nodeId, status, orderByComparator, false);
9542    
9543                            return array;
9544                    }
9545                    catch (Exception e) {
9546                            throw processException(e);
9547                    }
9548                    finally {
9549                            closeSession(session);
9550                    }
9551            }
9552    
9553            protected WikiPage getByG_N_S_PrevAndNext(Session session,
9554                    WikiPage wikiPage, long groupId, long nodeId, int status,
9555                    OrderByComparator orderByComparator, boolean previous) {
9556                    StringBundler query = null;
9557    
9558                    if (orderByComparator != null) {
9559                            query = new StringBundler(6 +
9560                                            (orderByComparator.getOrderByFields().length * 6));
9561                    }
9562                    else {
9563                            query = new StringBundler(3);
9564                    }
9565    
9566                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
9567    
9568                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
9569    
9570                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
9571    
9572                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
9573    
9574                    if (orderByComparator != null) {
9575                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9576    
9577                            if (orderByConditionFields.length > 0) {
9578                                    query.append(WHERE_AND);
9579                            }
9580    
9581                            for (int i = 0; i < orderByConditionFields.length; i++) {
9582                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9583                                    query.append(orderByConditionFields[i]);
9584    
9585                                    if ((i + 1) < orderByConditionFields.length) {
9586                                            if (orderByComparator.isAscending() ^ previous) {
9587                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9588                                            }
9589                                            else {
9590                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9591                                            }
9592                                    }
9593                                    else {
9594                                            if (orderByComparator.isAscending() ^ previous) {
9595                                                    query.append(WHERE_GREATER_THAN);
9596                                            }
9597                                            else {
9598                                                    query.append(WHERE_LESSER_THAN);
9599                                            }
9600                                    }
9601                            }
9602    
9603                            query.append(ORDER_BY_CLAUSE);
9604    
9605                            String[] orderByFields = orderByComparator.getOrderByFields();
9606    
9607                            for (int i = 0; i < orderByFields.length; i++) {
9608                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9609                                    query.append(orderByFields[i]);
9610    
9611                                    if ((i + 1) < orderByFields.length) {
9612                                            if (orderByComparator.isAscending() ^ previous) {
9613                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9614                                            }
9615                                            else {
9616                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9617                                            }
9618                                    }
9619                                    else {
9620                                            if (orderByComparator.isAscending() ^ previous) {
9621                                                    query.append(ORDER_BY_ASC);
9622                                            }
9623                                            else {
9624                                                    query.append(ORDER_BY_DESC);
9625                                            }
9626                                    }
9627                            }
9628                    }
9629                    else {
9630                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
9631                    }
9632    
9633                    String sql = query.toString();
9634    
9635                    Query q = session.createQuery(sql);
9636    
9637                    q.setFirstResult(0);
9638                    q.setMaxResults(2);
9639    
9640                    QueryPos qPos = QueryPos.getInstance(q);
9641    
9642                    qPos.add(groupId);
9643    
9644                    qPos.add(nodeId);
9645    
9646                    qPos.add(status);
9647    
9648                    if (orderByComparator != null) {
9649                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
9650    
9651                            for (Object value : values) {
9652                                    qPos.add(value);
9653                            }
9654                    }
9655    
9656                    List<WikiPage> list = q.list();
9657    
9658                    if (list.size() == 2) {
9659                            return list.get(1);
9660                    }
9661                    else {
9662                            return null;
9663                    }
9664            }
9665    
9666            /**
9667             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
9668             *
9669             * @param groupId the group ID
9670             * @param nodeId the node ID
9671             * @param status the status
9672             * @return the matching wiki pages that the user has permission to view
9673             * @throws SystemException if a system exception occurred
9674             */
9675            @Override
9676            public List<WikiPage> filterFindByG_N_S(long groupId, long nodeId,
9677                    int status) throws SystemException {
9678                    return filterFindByG_N_S(groupId, nodeId, status, QueryUtil.ALL_POS,
9679                            QueryUtil.ALL_POS, null);
9680            }
9681    
9682            /**
9683             * Returns a range of all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
9684             *
9685             * <p>
9686             * 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.
9687             * </p>
9688             *
9689             * @param groupId the group ID
9690             * @param nodeId the node ID
9691             * @param status the status
9692             * @param start the lower bound of the range of wiki pages
9693             * @param end the upper bound of the range of wiki pages (not inclusive)
9694             * @return the range of matching wiki pages that the user has permission to view
9695             * @throws SystemException if a system exception occurred
9696             */
9697            @Override
9698            public List<WikiPage> filterFindByG_N_S(long groupId, long nodeId,
9699                    int status, int start, int end) throws SystemException {
9700                    return filterFindByG_N_S(groupId, nodeId, status, start, end, null);
9701            }
9702    
9703            /**
9704             * 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;.
9705             *
9706             * <p>
9707             * 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.
9708             * </p>
9709             *
9710             * @param groupId the group ID
9711             * @param nodeId the node ID
9712             * @param status the status
9713             * @param start the lower bound of the range of wiki pages
9714             * @param end the upper bound of the range of wiki pages (not inclusive)
9715             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9716             * @return the ordered range of matching wiki pages that the user has permission to view
9717             * @throws SystemException if a system exception occurred
9718             */
9719            @Override
9720            public List<WikiPage> filterFindByG_N_S(long groupId, long nodeId,
9721                    int status, int start, int end, OrderByComparator orderByComparator)
9722                    throws SystemException {
9723                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9724                            return findByG_N_S(groupId, nodeId, status, start, end,
9725                                    orderByComparator);
9726                    }
9727    
9728                    StringBundler query = null;
9729    
9730                    if (orderByComparator != null) {
9731                            query = new StringBundler(5 +
9732                                            (orderByComparator.getOrderByFields().length * 3));
9733                    }
9734                    else {
9735                            query = new StringBundler(5);
9736                    }
9737    
9738                    if (getDB().isSupportsInlineDistinct()) {
9739                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
9740                    }
9741                    else {
9742                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
9743                    }
9744    
9745                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
9746    
9747                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
9748    
9749                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
9750    
9751                    if (!getDB().isSupportsInlineDistinct()) {
9752                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
9753                    }
9754    
9755                    if (orderByComparator != null) {
9756                            if (getDB().isSupportsInlineDistinct()) {
9757                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9758                                            orderByComparator, true);
9759                            }
9760                            else {
9761                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
9762                                            orderByComparator, true);
9763                            }
9764                    }
9765                    else {
9766                            if (getDB().isSupportsInlineDistinct()) {
9767                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
9768                            }
9769                            else {
9770                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
9771                            }
9772                    }
9773    
9774                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9775                                    WikiPage.class.getName(),
9776                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9777    
9778                    Session session = null;
9779    
9780                    try {
9781                            session = openSession();
9782    
9783                            SQLQuery q = session.createSQLQuery(sql);
9784    
9785                            if (getDB().isSupportsInlineDistinct()) {
9786                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
9787                            }
9788                            else {
9789                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
9790                            }
9791    
9792                            QueryPos qPos = QueryPos.getInstance(q);
9793    
9794                            qPos.add(groupId);
9795    
9796                            qPos.add(nodeId);
9797    
9798                            qPos.add(status);
9799    
9800                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
9801                    }
9802                    catch (Exception e) {
9803                            throw processException(e);
9804                    }
9805                    finally {
9806                            closeSession(session);
9807                    }
9808            }
9809    
9810            /**
9811             * 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;.
9812             *
9813             * @param pageId the primary key of the current wiki page
9814             * @param groupId the group ID
9815             * @param nodeId the node ID
9816             * @param status the status
9817             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9818             * @return the previous, current, and next wiki page
9819             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
9820             * @throws SystemException if a system exception occurred
9821             */
9822            @Override
9823            public WikiPage[] filterFindByG_N_S_PrevAndNext(long pageId, long groupId,
9824                    long nodeId, int status, OrderByComparator orderByComparator)
9825                    throws NoSuchPageException, SystemException {
9826                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9827                            return findByG_N_S_PrevAndNext(pageId, groupId, nodeId, status,
9828                                    orderByComparator);
9829                    }
9830    
9831                    WikiPage wikiPage = findByPrimaryKey(pageId);
9832    
9833                    Session session = null;
9834    
9835                    try {
9836                            session = openSession();
9837    
9838                            WikiPage[] array = new WikiPageImpl[3];
9839    
9840                            array[0] = filterGetByG_N_S_PrevAndNext(session, wikiPage, groupId,
9841                                            nodeId, status, orderByComparator, true);
9842    
9843                            array[1] = wikiPage;
9844    
9845                            array[2] = filterGetByG_N_S_PrevAndNext(session, wikiPage, groupId,
9846                                            nodeId, status, orderByComparator, false);
9847    
9848                            return array;
9849                    }
9850                    catch (Exception e) {
9851                            throw processException(e);
9852                    }
9853                    finally {
9854                            closeSession(session);
9855                    }
9856            }
9857    
9858            protected WikiPage filterGetByG_N_S_PrevAndNext(Session session,
9859                    WikiPage wikiPage, long groupId, long nodeId, int status,
9860                    OrderByComparator orderByComparator, boolean previous) {
9861                    StringBundler query = null;
9862    
9863                    if (orderByComparator != null) {
9864                            query = new StringBundler(6 +
9865                                            (orderByComparator.getOrderByFields().length * 6));
9866                    }
9867                    else {
9868                            query = new StringBundler(3);
9869                    }
9870    
9871                    if (getDB().isSupportsInlineDistinct()) {
9872                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
9873                    }
9874                    else {
9875                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
9876                    }
9877    
9878                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
9879    
9880                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
9881    
9882                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
9883    
9884                    if (!getDB().isSupportsInlineDistinct()) {
9885                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
9886                    }
9887    
9888                    if (orderByComparator != null) {
9889                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9890    
9891                            if (orderByConditionFields.length > 0) {
9892                                    query.append(WHERE_AND);
9893                            }
9894    
9895                            for (int i = 0; i < orderByConditionFields.length; i++) {
9896                                    if (getDB().isSupportsInlineDistinct()) {
9897                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9898                                    }
9899                                    else {
9900                                            query.append(_ORDER_BY_ENTITY_TABLE);
9901                                    }
9902    
9903                                    query.append(orderByConditionFields[i]);
9904    
9905                                    if ((i + 1) < orderByConditionFields.length) {
9906                                            if (orderByComparator.isAscending() ^ previous) {
9907                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9908                                            }
9909                                            else {
9910                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9911                                            }
9912                                    }
9913                                    else {
9914                                            if (orderByComparator.isAscending() ^ previous) {
9915                                                    query.append(WHERE_GREATER_THAN);
9916                                            }
9917                                            else {
9918                                                    query.append(WHERE_LESSER_THAN);
9919                                            }
9920                                    }
9921                            }
9922    
9923                            query.append(ORDER_BY_CLAUSE);
9924    
9925                            String[] orderByFields = orderByComparator.getOrderByFields();
9926    
9927                            for (int i = 0; i < orderByFields.length; i++) {
9928                                    if (getDB().isSupportsInlineDistinct()) {
9929                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9930                                    }
9931                                    else {
9932                                            query.append(_ORDER_BY_ENTITY_TABLE);
9933                                    }
9934    
9935                                    query.append(orderByFields[i]);
9936    
9937                                    if ((i + 1) < orderByFields.length) {
9938                                            if (orderByComparator.isAscending() ^ previous) {
9939                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9940                                            }
9941                                            else {
9942                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9943                                            }
9944                                    }
9945                                    else {
9946                                            if (orderByComparator.isAscending() ^ previous) {
9947                                                    query.append(ORDER_BY_ASC);
9948                                            }
9949                                            else {
9950                                                    query.append(ORDER_BY_DESC);
9951                                            }
9952                                    }
9953                            }
9954                    }
9955                    else {
9956                            if (getDB().isSupportsInlineDistinct()) {
9957                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
9958                            }
9959                            else {
9960                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
9961                            }
9962                    }
9963    
9964                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9965                                    WikiPage.class.getName(),
9966                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9967    
9968                    SQLQuery q = session.createSQLQuery(sql);
9969    
9970                    q.setFirstResult(0);
9971                    q.setMaxResults(2);
9972    
9973                    if (getDB().isSupportsInlineDistinct()) {
9974                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
9975                    }
9976                    else {
9977                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
9978                    }
9979    
9980                    QueryPos qPos = QueryPos.getInstance(q);
9981    
9982                    qPos.add(groupId);
9983    
9984                    qPos.add(nodeId);
9985    
9986                    qPos.add(status);
9987    
9988                    if (orderByComparator != null) {
9989                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
9990    
9991                            for (Object value : values) {
9992                                    qPos.add(value);
9993                            }
9994                    }
9995    
9996                    List<WikiPage> list = q.list();
9997    
9998                    if (list.size() == 2) {
9999                            return list.get(1);
10000                    }
10001                    else {
10002                            return null;
10003                    }
10004            }
10005    
10006            /**
10007             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63; from the database.
10008             *
10009             * @param groupId the group ID
10010             * @param nodeId the node ID
10011             * @param status the status
10012             * @throws SystemException if a system exception occurred
10013             */
10014            @Override
10015            public void removeByG_N_S(long groupId, long nodeId, int status)
10016                    throws SystemException {
10017                    for (WikiPage wikiPage : findByG_N_S(groupId, nodeId, status,
10018                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10019                            remove(wikiPage);
10020                    }
10021            }
10022    
10023            /**
10024             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and status = &#63;.
10025             *
10026             * @param groupId the group ID
10027             * @param nodeId the node ID
10028             * @param status the status
10029             * @return the number of matching wiki pages
10030             * @throws SystemException if a system exception occurred
10031             */
10032            @Override
10033            public int countByG_N_S(long groupId, long nodeId, int status)
10034                    throws SystemException {
10035                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_S;
10036    
10037                    Object[] finderArgs = new Object[] { groupId, nodeId, status };
10038    
10039                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10040                                    this);
10041    
10042                    if (count == null) {
10043                            StringBundler query = new StringBundler(4);
10044    
10045                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
10046    
10047                            query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
10048    
10049                            query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
10050    
10051                            query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
10052    
10053                            String sql = query.toString();
10054    
10055                            Session session = null;
10056    
10057                            try {
10058                                    session = openSession();
10059    
10060                                    Query q = session.createQuery(sql);
10061    
10062                                    QueryPos qPos = QueryPos.getInstance(q);
10063    
10064                                    qPos.add(groupId);
10065    
10066                                    qPos.add(nodeId);
10067    
10068                                    qPos.add(status);
10069    
10070                                    count = (Long)q.uniqueResult();
10071    
10072                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10073                            }
10074                            catch (Exception e) {
10075                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10076    
10077                                    throw processException(e);
10078                            }
10079                            finally {
10080                                    closeSession(session);
10081                            }
10082                    }
10083    
10084                    return count.intValue();
10085            }
10086    
10087            /**
10088             * Returns the number of wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and status = &#63;.
10089             *
10090             * @param groupId the group ID
10091             * @param nodeId the node ID
10092             * @param status the status
10093             * @return the number of matching wiki pages that the user has permission to view
10094             * @throws SystemException if a system exception occurred
10095             */
10096            @Override
10097            public int filterCountByG_N_S(long groupId, long nodeId, int status)
10098                    throws SystemException {
10099                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10100                            return countByG_N_S(groupId, nodeId, status);
10101                    }
10102    
10103                    StringBundler query = new StringBundler(4);
10104    
10105                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
10106    
10107                    query.append(_FINDER_COLUMN_G_N_S_GROUPID_2);
10108    
10109                    query.append(_FINDER_COLUMN_G_N_S_NODEID_2);
10110    
10111                    query.append(_FINDER_COLUMN_G_N_S_STATUS_2);
10112    
10113                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10114                                    WikiPage.class.getName(),
10115                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10116    
10117                    Session session = null;
10118    
10119                    try {
10120                            session = openSession();
10121    
10122                            SQLQuery q = session.createSQLQuery(sql);
10123    
10124                            q.addScalar(COUNT_COLUMN_NAME,
10125                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10126    
10127                            QueryPos qPos = QueryPos.getInstance(q);
10128    
10129                            qPos.add(groupId);
10130    
10131                            qPos.add(nodeId);
10132    
10133                            qPos.add(status);
10134    
10135                            Long count = (Long)q.uniqueResult();
10136    
10137                            return count.intValue();
10138                    }
10139                    catch (Exception e) {
10140                            throw processException(e);
10141                    }
10142                    finally {
10143                            closeSession(session);
10144                    }
10145            }
10146    
10147            private static final String _FINDER_COLUMN_G_N_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
10148            private static final String _FINDER_COLUMN_G_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
10149            private static final String _FINDER_COLUMN_G_N_S_STATUS_2 = "wikiPage.status = ?";
10150            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10151                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
10152                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_N_S",
10153                            new String[] {
10154                                    Long.class.getName(), Long.class.getName(),
10155                                    Integer.class.getName(),
10156                                    
10157                            Integer.class.getName(), Integer.class.getName(),
10158                                    OrderByComparator.class.getName()
10159                            });
10160            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10161                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
10162                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_N_S",
10163                            new String[] {
10164                                    Long.class.getName(), Long.class.getName(),
10165                                    Integer.class.getName()
10166                            },
10167                            WikiPageModelImpl.USERID_COLUMN_BITMASK |
10168                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
10169                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
10170                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
10171                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
10172            public static final FinderPath FINDER_PATH_COUNT_BY_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10173                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10174                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_N_S",
10175                            new String[] {
10176                                    Long.class.getName(), Long.class.getName(),
10177                                    Integer.class.getName()
10178                            });
10179    
10180            /**
10181             * Returns all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
10182             *
10183             * @param userId the user ID
10184             * @param nodeId the node ID
10185             * @param status the status
10186             * @return the matching wiki pages
10187             * @throws SystemException if a system exception occurred
10188             */
10189            @Override
10190            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status)
10191                    throws SystemException {
10192                    return findByU_N_S(userId, nodeId, status, QueryUtil.ALL_POS,
10193                            QueryUtil.ALL_POS, null);
10194            }
10195    
10196            /**
10197             * Returns a range of all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
10198             *
10199             * <p>
10200             * 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.
10201             * </p>
10202             *
10203             * @param userId the user ID
10204             * @param nodeId the node ID
10205             * @param status the status
10206             * @param start the lower bound of the range of wiki pages
10207             * @param end the upper bound of the range of wiki pages (not inclusive)
10208             * @return the range of matching wiki pages
10209             * @throws SystemException if a system exception occurred
10210             */
10211            @Override
10212            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status,
10213                    int start, int end) throws SystemException {
10214                    return findByU_N_S(userId, nodeId, status, start, end, null);
10215            }
10216    
10217            /**
10218             * Returns an ordered range of all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
10219             *
10220             * <p>
10221             * 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.
10222             * </p>
10223             *
10224             * @param userId the user ID
10225             * @param nodeId the node ID
10226             * @param status the status
10227             * @param start the lower bound of the range of wiki pages
10228             * @param end the upper bound of the range of wiki pages (not inclusive)
10229             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10230             * @return the ordered range of matching wiki pages
10231             * @throws SystemException if a system exception occurred
10232             */
10233            @Override
10234            public List<WikiPage> findByU_N_S(long userId, long nodeId, int status,
10235                    int start, int end, OrderByComparator orderByComparator)
10236                    throws SystemException {
10237                    boolean pagination = true;
10238                    FinderPath finderPath = null;
10239                    Object[] finderArgs = null;
10240    
10241                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10242                                    (orderByComparator == null)) {
10243                            pagination = false;
10244                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S;
10245                            finderArgs = new Object[] { userId, nodeId, status };
10246                    }
10247                    else {
10248                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_N_S;
10249                            finderArgs = new Object[] {
10250                                            userId, nodeId, status,
10251                                            
10252                                            start, end, orderByComparator
10253                                    };
10254                    }
10255    
10256                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
10257                                    finderArgs, this);
10258    
10259                    if ((list != null) && !list.isEmpty()) {
10260                            for (WikiPage wikiPage : list) {
10261                                    if ((userId != wikiPage.getUserId()) ||
10262                                                    (nodeId != wikiPage.getNodeId()) ||
10263                                                    (status != wikiPage.getStatus())) {
10264                                            list = null;
10265    
10266                                            break;
10267                                    }
10268                            }
10269                    }
10270    
10271                    if (list == null) {
10272                            StringBundler query = null;
10273    
10274                            if (orderByComparator != null) {
10275                                    query = new StringBundler(5 +
10276                                                    (orderByComparator.getOrderByFields().length * 3));
10277                            }
10278                            else {
10279                                    query = new StringBundler(5);
10280                            }
10281    
10282                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
10283    
10284                            query.append(_FINDER_COLUMN_U_N_S_USERID_2);
10285    
10286                            query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
10287    
10288                            query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
10289    
10290                            if (orderByComparator != null) {
10291                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10292                                            orderByComparator);
10293                            }
10294                            else
10295                             if (pagination) {
10296                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
10297                            }
10298    
10299                            String sql = query.toString();
10300    
10301                            Session session = null;
10302    
10303                            try {
10304                                    session = openSession();
10305    
10306                                    Query q = session.createQuery(sql);
10307    
10308                                    QueryPos qPos = QueryPos.getInstance(q);
10309    
10310                                    qPos.add(userId);
10311    
10312                                    qPos.add(nodeId);
10313    
10314                                    qPos.add(status);
10315    
10316                                    if (!pagination) {
10317                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
10318                                                            start, end, false);
10319    
10320                                            Collections.sort(list);
10321    
10322                                            list = new UnmodifiableList<WikiPage>(list);
10323                                    }
10324                                    else {
10325                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
10326                                                            start, end);
10327                                    }
10328    
10329                                    cacheResult(list);
10330    
10331                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10332                            }
10333                            catch (Exception e) {
10334                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10335    
10336                                    throw processException(e);
10337                            }
10338                            finally {
10339                                    closeSession(session);
10340                            }
10341                    }
10342    
10343                    return list;
10344            }
10345    
10346            /**
10347             * Returns the first wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
10348             *
10349             * @param userId the user ID
10350             * @param nodeId the node ID
10351             * @param status the status
10352             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10353             * @return the first matching wiki page
10354             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
10355             * @throws SystemException if a system exception occurred
10356             */
10357            @Override
10358            public WikiPage findByU_N_S_First(long userId, long nodeId, int status,
10359                    OrderByComparator orderByComparator)
10360                    throws NoSuchPageException, SystemException {
10361                    WikiPage wikiPage = fetchByU_N_S_First(userId, nodeId, status,
10362                                    orderByComparator);
10363    
10364                    if (wikiPage != null) {
10365                            return wikiPage;
10366                    }
10367    
10368                    StringBundler msg = new StringBundler(8);
10369    
10370                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10371    
10372                    msg.append("userId=");
10373                    msg.append(userId);
10374    
10375                    msg.append(", nodeId=");
10376                    msg.append(nodeId);
10377    
10378                    msg.append(", status=");
10379                    msg.append(status);
10380    
10381                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10382    
10383                    throw new NoSuchPageException(msg.toString());
10384            }
10385    
10386            /**
10387             * Returns the first wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
10388             *
10389             * @param userId the user ID
10390             * @param nodeId the node ID
10391             * @param status the status
10392             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10393             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
10394             * @throws SystemException if a system exception occurred
10395             */
10396            @Override
10397            public WikiPage fetchByU_N_S_First(long userId, long nodeId, int status,
10398                    OrderByComparator orderByComparator) throws SystemException {
10399                    List<WikiPage> list = findByU_N_S(userId, nodeId, status, 0, 1,
10400                                    orderByComparator);
10401    
10402                    if (!list.isEmpty()) {
10403                            return list.get(0);
10404                    }
10405    
10406                    return null;
10407            }
10408    
10409            /**
10410             * Returns the last wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
10411             *
10412             * @param userId the user ID
10413             * @param nodeId the node ID
10414             * @param status the status
10415             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10416             * @return the last matching wiki page
10417             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
10418             * @throws SystemException if a system exception occurred
10419             */
10420            @Override
10421            public WikiPage findByU_N_S_Last(long userId, long nodeId, int status,
10422                    OrderByComparator orderByComparator)
10423                    throws NoSuchPageException, SystemException {
10424                    WikiPage wikiPage = fetchByU_N_S_Last(userId, nodeId, status,
10425                                    orderByComparator);
10426    
10427                    if (wikiPage != null) {
10428                            return wikiPage;
10429                    }
10430    
10431                    StringBundler msg = new StringBundler(8);
10432    
10433                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10434    
10435                    msg.append("userId=");
10436                    msg.append(userId);
10437    
10438                    msg.append(", nodeId=");
10439                    msg.append(nodeId);
10440    
10441                    msg.append(", status=");
10442                    msg.append(status);
10443    
10444                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10445    
10446                    throw new NoSuchPageException(msg.toString());
10447            }
10448    
10449            /**
10450             * Returns the last wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
10451             *
10452             * @param userId the user ID
10453             * @param nodeId the node ID
10454             * @param status the status
10455             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10456             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
10457             * @throws SystemException if a system exception occurred
10458             */
10459            @Override
10460            public WikiPage fetchByU_N_S_Last(long userId, long nodeId, int status,
10461                    OrderByComparator orderByComparator) throws SystemException {
10462                    int count = countByU_N_S(userId, nodeId, status);
10463    
10464                    if (count == 0) {
10465                            return null;
10466                    }
10467    
10468                    List<WikiPage> list = findByU_N_S(userId, nodeId, status, count - 1,
10469                                    count, orderByComparator);
10470    
10471                    if (!list.isEmpty()) {
10472                            return list.get(0);
10473                    }
10474    
10475                    return null;
10476            }
10477    
10478            /**
10479             * Returns the wiki pages before and after the current wiki page in the ordered set where userId = &#63; and nodeId = &#63; and status = &#63;.
10480             *
10481             * @param pageId the primary key of the current wiki page
10482             * @param userId the user ID
10483             * @param nodeId the node ID
10484             * @param status the status
10485             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10486             * @return the previous, current, and next wiki page
10487             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
10488             * @throws SystemException if a system exception occurred
10489             */
10490            @Override
10491            public WikiPage[] findByU_N_S_PrevAndNext(long pageId, long userId,
10492                    long nodeId, int status, OrderByComparator orderByComparator)
10493                    throws NoSuchPageException, SystemException {
10494                    WikiPage wikiPage = findByPrimaryKey(pageId);
10495    
10496                    Session session = null;
10497    
10498                    try {
10499                            session = openSession();
10500    
10501                            WikiPage[] array = new WikiPageImpl[3];
10502    
10503                            array[0] = getByU_N_S_PrevAndNext(session, wikiPage, userId,
10504                                            nodeId, status, orderByComparator, true);
10505    
10506                            array[1] = wikiPage;
10507    
10508                            array[2] = getByU_N_S_PrevAndNext(session, wikiPage, userId,
10509                                            nodeId, status, orderByComparator, false);
10510    
10511                            return array;
10512                    }
10513                    catch (Exception e) {
10514                            throw processException(e);
10515                    }
10516                    finally {
10517                            closeSession(session);
10518                    }
10519            }
10520    
10521            protected WikiPage getByU_N_S_PrevAndNext(Session session,
10522                    WikiPage wikiPage, long userId, long nodeId, int status,
10523                    OrderByComparator orderByComparator, boolean previous) {
10524                    StringBundler query = null;
10525    
10526                    if (orderByComparator != null) {
10527                            query = new StringBundler(6 +
10528                                            (orderByComparator.getOrderByFields().length * 6));
10529                    }
10530                    else {
10531                            query = new StringBundler(3);
10532                    }
10533    
10534                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
10535    
10536                    query.append(_FINDER_COLUMN_U_N_S_USERID_2);
10537    
10538                    query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
10539    
10540                    query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
10541    
10542                    if (orderByComparator != null) {
10543                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10544    
10545                            if (orderByConditionFields.length > 0) {
10546                                    query.append(WHERE_AND);
10547                            }
10548    
10549                            for (int i = 0; i < orderByConditionFields.length; i++) {
10550                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10551                                    query.append(orderByConditionFields[i]);
10552    
10553                                    if ((i + 1) < orderByConditionFields.length) {
10554                                            if (orderByComparator.isAscending() ^ previous) {
10555                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10556                                            }
10557                                            else {
10558                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10559                                            }
10560                                    }
10561                                    else {
10562                                            if (orderByComparator.isAscending() ^ previous) {
10563                                                    query.append(WHERE_GREATER_THAN);
10564                                            }
10565                                            else {
10566                                                    query.append(WHERE_LESSER_THAN);
10567                                            }
10568                                    }
10569                            }
10570    
10571                            query.append(ORDER_BY_CLAUSE);
10572    
10573                            String[] orderByFields = orderByComparator.getOrderByFields();
10574    
10575                            for (int i = 0; i < orderByFields.length; i++) {
10576                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10577                                    query.append(orderByFields[i]);
10578    
10579                                    if ((i + 1) < orderByFields.length) {
10580                                            if (orderByComparator.isAscending() ^ previous) {
10581                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10582                                            }
10583                                            else {
10584                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10585                                            }
10586                                    }
10587                                    else {
10588                                            if (orderByComparator.isAscending() ^ previous) {
10589                                                    query.append(ORDER_BY_ASC);
10590                                            }
10591                                            else {
10592                                                    query.append(ORDER_BY_DESC);
10593                                            }
10594                                    }
10595                            }
10596                    }
10597                    else {
10598                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
10599                    }
10600    
10601                    String sql = query.toString();
10602    
10603                    Query q = session.createQuery(sql);
10604    
10605                    q.setFirstResult(0);
10606                    q.setMaxResults(2);
10607    
10608                    QueryPos qPos = QueryPos.getInstance(q);
10609    
10610                    qPos.add(userId);
10611    
10612                    qPos.add(nodeId);
10613    
10614                    qPos.add(status);
10615    
10616                    if (orderByComparator != null) {
10617                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
10618    
10619                            for (Object value : values) {
10620                                    qPos.add(value);
10621                            }
10622                    }
10623    
10624                    List<WikiPage> list = q.list();
10625    
10626                    if (list.size() == 2) {
10627                            return list.get(1);
10628                    }
10629                    else {
10630                            return null;
10631                    }
10632            }
10633    
10634            /**
10635             * Removes all the wiki pages where userId = &#63; and nodeId = &#63; and status = &#63; from the database.
10636             *
10637             * @param userId the user ID
10638             * @param nodeId the node ID
10639             * @param status the status
10640             * @throws SystemException if a system exception occurred
10641             */
10642            @Override
10643            public void removeByU_N_S(long userId, long nodeId, int status)
10644                    throws SystemException {
10645                    for (WikiPage wikiPage : findByU_N_S(userId, nodeId, status,
10646                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10647                            remove(wikiPage);
10648                    }
10649            }
10650    
10651            /**
10652             * Returns the number of wiki pages where userId = &#63; and nodeId = &#63; and status = &#63;.
10653             *
10654             * @param userId the user ID
10655             * @param nodeId the node ID
10656             * @param status the status
10657             * @return the number of matching wiki pages
10658             * @throws SystemException if a system exception occurred
10659             */
10660            @Override
10661            public int countByU_N_S(long userId, long nodeId, int status)
10662                    throws SystemException {
10663                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_N_S;
10664    
10665                    Object[] finderArgs = new Object[] { userId, nodeId, status };
10666    
10667                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10668                                    this);
10669    
10670                    if (count == null) {
10671                            StringBundler query = new StringBundler(4);
10672    
10673                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
10674    
10675                            query.append(_FINDER_COLUMN_U_N_S_USERID_2);
10676    
10677                            query.append(_FINDER_COLUMN_U_N_S_NODEID_2);
10678    
10679                            query.append(_FINDER_COLUMN_U_N_S_STATUS_2);
10680    
10681                            String sql = query.toString();
10682    
10683                            Session session = null;
10684    
10685                            try {
10686                                    session = openSession();
10687    
10688                                    Query q = session.createQuery(sql);
10689    
10690                                    QueryPos qPos = QueryPos.getInstance(q);
10691    
10692                                    qPos.add(userId);
10693    
10694                                    qPos.add(nodeId);
10695    
10696                                    qPos.add(status);
10697    
10698                                    count = (Long)q.uniqueResult();
10699    
10700                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10701                            }
10702                            catch (Exception e) {
10703                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10704    
10705                                    throw processException(e);
10706                            }
10707                            finally {
10708                                    closeSession(session);
10709                            }
10710                    }
10711    
10712                    return count.intValue();
10713            }
10714    
10715            private static final String _FINDER_COLUMN_U_N_S_USERID_2 = "wikiPage.userId = ? AND ";
10716            private static final String _FINDER_COLUMN_U_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
10717            private static final String _FINDER_COLUMN_U_N_S_STATUS_2 = "wikiPage.status = ?";
10718            public static final FinderPath FINDER_PATH_FETCH_BY_N_T_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10719                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
10720                            FINDER_CLASS_NAME_ENTITY, "fetchByN_T_V",
10721                            new String[] {
10722                                    Long.class.getName(), String.class.getName(),
10723                                    Double.class.getName()
10724                            },
10725                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
10726                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
10727                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
10728            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_V = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
10729                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10730                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T_V",
10731                            new String[] {
10732                                    Long.class.getName(), String.class.getName(),
10733                                    Double.class.getName()
10734                            });
10735    
10736            /**
10737             * 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.
10738             *
10739             * @param nodeId the node ID
10740             * @param title the title
10741             * @param version the version
10742             * @return the matching wiki page
10743             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
10744             * @throws SystemException if a system exception occurred
10745             */
10746            @Override
10747            public WikiPage findByN_T_V(long nodeId, String title, double version)
10748                    throws NoSuchPageException, SystemException {
10749                    WikiPage wikiPage = fetchByN_T_V(nodeId, title, version);
10750    
10751                    if (wikiPage == null) {
10752                            StringBundler msg = new StringBundler(8);
10753    
10754                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10755    
10756                            msg.append("nodeId=");
10757                            msg.append(nodeId);
10758    
10759                            msg.append(", title=");
10760                            msg.append(title);
10761    
10762                            msg.append(", version=");
10763                            msg.append(version);
10764    
10765                            msg.append(StringPool.CLOSE_CURLY_BRACE);
10766    
10767                            if (_log.isWarnEnabled()) {
10768                                    _log.warn(msg.toString());
10769                            }
10770    
10771                            throw new NoSuchPageException(msg.toString());
10772                    }
10773    
10774                    return wikiPage;
10775            }
10776    
10777            /**
10778             * 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.
10779             *
10780             * @param nodeId the node ID
10781             * @param title the title
10782             * @param version the version
10783             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
10784             * @throws SystemException if a system exception occurred
10785             */
10786            @Override
10787            public WikiPage fetchByN_T_V(long nodeId, String title, double version)
10788                    throws SystemException {
10789                    return fetchByN_T_V(nodeId, title, version, true);
10790            }
10791    
10792            /**
10793             * 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.
10794             *
10795             * @param nodeId the node ID
10796             * @param title the title
10797             * @param version the version
10798             * @param retrieveFromCache whether to use the finder cache
10799             * @return the matching wiki page, or <code>null</code> if a matching wiki page could not be found
10800             * @throws SystemException if a system exception occurred
10801             */
10802            @Override
10803            public WikiPage fetchByN_T_V(long nodeId, String title, double version,
10804                    boolean retrieveFromCache) throws SystemException {
10805                    Object[] finderArgs = new Object[] { nodeId, title, version };
10806    
10807                    Object result = null;
10808    
10809                    if (retrieveFromCache) {
10810                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_T_V,
10811                                            finderArgs, this);
10812                    }
10813    
10814                    if (result instanceof WikiPage) {
10815                            WikiPage wikiPage = (WikiPage)result;
10816    
10817                            if ((nodeId != wikiPage.getNodeId()) ||
10818                                            !Validator.equals(title, wikiPage.getTitle()) ||
10819                                            (version != wikiPage.getVersion())) {
10820                                    result = null;
10821                            }
10822                    }
10823    
10824                    if (result == null) {
10825                            StringBundler query = new StringBundler(5);
10826    
10827                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
10828    
10829                            query.append(_FINDER_COLUMN_N_T_V_NODEID_2);
10830    
10831                            boolean bindTitle = false;
10832    
10833                            if (title == null) {
10834                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_1);
10835                            }
10836                            else if (title.equals(StringPool.BLANK)) {
10837                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_3);
10838                            }
10839                            else {
10840                                    bindTitle = true;
10841    
10842                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_2);
10843                            }
10844    
10845                            query.append(_FINDER_COLUMN_N_T_V_VERSION_2);
10846    
10847                            String sql = query.toString();
10848    
10849                            Session session = null;
10850    
10851                            try {
10852                                    session = openSession();
10853    
10854                                    Query q = session.createQuery(sql);
10855    
10856                                    QueryPos qPos = QueryPos.getInstance(q);
10857    
10858                                    qPos.add(nodeId);
10859    
10860                                    if (bindTitle) {
10861                                            qPos.add(title.toLowerCase());
10862                                    }
10863    
10864                                    qPos.add(version);
10865    
10866                                    List<WikiPage> list = q.list();
10867    
10868                                    if (list.isEmpty()) {
10869                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
10870                                                    finderArgs, list);
10871                                    }
10872                                    else {
10873                                            WikiPage wikiPage = list.get(0);
10874    
10875                                            result = wikiPage;
10876    
10877                                            cacheResult(wikiPage);
10878    
10879                                            if ((wikiPage.getNodeId() != nodeId) ||
10880                                                            (wikiPage.getTitle() == null) ||
10881                                                            !wikiPage.getTitle().equals(title) ||
10882                                                            (wikiPage.getVersion() != version)) {
10883                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
10884                                                            finderArgs, wikiPage);
10885                                            }
10886                                    }
10887                            }
10888                            catch (Exception e) {
10889                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V,
10890                                            finderArgs);
10891    
10892                                    throw processException(e);
10893                            }
10894                            finally {
10895                                    closeSession(session);
10896                            }
10897                    }
10898    
10899                    if (result instanceof List<?>) {
10900                            return null;
10901                    }
10902                    else {
10903                            return (WikiPage)result;
10904                    }
10905            }
10906    
10907            /**
10908             * Removes the wiki page where nodeId = &#63; and title = &#63; and version = &#63; from the database.
10909             *
10910             * @param nodeId the node ID
10911             * @param title the title
10912             * @param version the version
10913             * @return the wiki page that was removed
10914             * @throws SystemException if a system exception occurred
10915             */
10916            @Override
10917            public WikiPage removeByN_T_V(long nodeId, String title, double version)
10918                    throws NoSuchPageException, SystemException {
10919                    WikiPage wikiPage = findByN_T_V(nodeId, title, version);
10920    
10921                    return remove(wikiPage);
10922            }
10923    
10924            /**
10925             * Returns the number of wiki pages where nodeId = &#63; and title = &#63; and version = &#63;.
10926             *
10927             * @param nodeId the node ID
10928             * @param title the title
10929             * @param version the version
10930             * @return the number of matching wiki pages
10931             * @throws SystemException if a system exception occurred
10932             */
10933            @Override
10934            public int countByN_T_V(long nodeId, String title, double version)
10935                    throws SystemException {
10936                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T_V;
10937    
10938                    Object[] finderArgs = new Object[] { nodeId, title, version };
10939    
10940                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10941                                    this);
10942    
10943                    if (count == null) {
10944                            StringBundler query = new StringBundler(4);
10945    
10946                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
10947    
10948                            query.append(_FINDER_COLUMN_N_T_V_NODEID_2);
10949    
10950                            boolean bindTitle = false;
10951    
10952                            if (title == null) {
10953                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_1);
10954                            }
10955                            else if (title.equals(StringPool.BLANK)) {
10956                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_3);
10957                            }
10958                            else {
10959                                    bindTitle = true;
10960    
10961                                    query.append(_FINDER_COLUMN_N_T_V_TITLE_2);
10962                            }
10963    
10964                            query.append(_FINDER_COLUMN_N_T_V_VERSION_2);
10965    
10966                            String sql = query.toString();
10967    
10968                            Session session = null;
10969    
10970                            try {
10971                                    session = openSession();
10972    
10973                                    Query q = session.createQuery(sql);
10974    
10975                                    QueryPos qPos = QueryPos.getInstance(q);
10976    
10977                                    qPos.add(nodeId);
10978    
10979                                    if (bindTitle) {
10980                                            qPos.add(title.toLowerCase());
10981                                    }
10982    
10983                                    qPos.add(version);
10984    
10985                                    count = (Long)q.uniqueResult();
10986    
10987                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10988                            }
10989                            catch (Exception e) {
10990                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10991    
10992                                    throw processException(e);
10993                            }
10994                            finally {
10995                                    closeSession(session);
10996                            }
10997                    }
10998    
10999                    return count.intValue();
11000            }
11001    
11002            private static final String _FINDER_COLUMN_N_T_V_NODEID_2 = "wikiPage.nodeId = ? AND ";
11003            private static final String _FINDER_COLUMN_N_T_V_TITLE_1 = "wikiPage.title IS NULL AND ";
11004            private static final String _FINDER_COLUMN_N_T_V_TITLE_2 = "lower(wikiPage.title) = ? AND ";
11005            private static final String _FINDER_COLUMN_N_T_V_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
11006            private static final String _FINDER_COLUMN_N_T_V_VERSION_2 = "wikiPage.version = ?";
11007            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11008                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
11009                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_T_H",
11010                            new String[] {
11011                                    Long.class.getName(), String.class.getName(),
11012                                    Boolean.class.getName(),
11013                                    
11014                            Integer.class.getName(), Integer.class.getName(),
11015                                    OrderByComparator.class.getName()
11016                            });
11017            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11018                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
11019                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_T_H",
11020                            new String[] {
11021                                    Long.class.getName(), String.class.getName(),
11022                                    Boolean.class.getName()
11023                            },
11024                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
11025                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
11026                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
11027                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
11028            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11029                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11030                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T_H",
11031                            new String[] {
11032                                    Long.class.getName(), String.class.getName(),
11033                                    Boolean.class.getName()
11034                            });
11035    
11036            /**
11037             * Returns all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
11038             *
11039             * @param nodeId the node ID
11040             * @param title the title
11041             * @param head the head
11042             * @return the matching wiki pages
11043             * @throws SystemException if a system exception occurred
11044             */
11045            @Override
11046            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head)
11047                    throws SystemException {
11048                    return findByN_T_H(nodeId, title, head, QueryUtil.ALL_POS,
11049                            QueryUtil.ALL_POS, null);
11050            }
11051    
11052            /**
11053             * Returns a range of all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
11054             *
11055             * <p>
11056             * 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.
11057             * </p>
11058             *
11059             * @param nodeId the node ID
11060             * @param title the title
11061             * @param head the head
11062             * @param start the lower bound of the range of wiki pages
11063             * @param end the upper bound of the range of wiki pages (not inclusive)
11064             * @return the range of matching wiki pages
11065             * @throws SystemException if a system exception occurred
11066             */
11067            @Override
11068            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head,
11069                    int start, int end) throws SystemException {
11070                    return findByN_T_H(nodeId, title, head, start, end, null);
11071            }
11072    
11073            /**
11074             * Returns an ordered range of all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
11075             *
11076             * <p>
11077             * 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.
11078             * </p>
11079             *
11080             * @param nodeId the node ID
11081             * @param title the title
11082             * @param head the head
11083             * @param start the lower bound of the range of wiki pages
11084             * @param end the upper bound of the range of wiki pages (not inclusive)
11085             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11086             * @return the ordered range of matching wiki pages
11087             * @throws SystemException if a system exception occurred
11088             */
11089            @Override
11090            public List<WikiPage> findByN_T_H(long nodeId, String title, boolean head,
11091                    int start, int end, OrderByComparator orderByComparator)
11092                    throws SystemException {
11093                    boolean pagination = true;
11094                    FinderPath finderPath = null;
11095                    Object[] finderArgs = null;
11096    
11097                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11098                                    (orderByComparator == null)) {
11099                            pagination = false;
11100                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H;
11101                            finderArgs = new Object[] { nodeId, title, head };
11102                    }
11103                    else {
11104                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_H;
11105                            finderArgs = new Object[] {
11106                                            nodeId, title, head,
11107                                            
11108                                            start, end, orderByComparator
11109                                    };
11110                    }
11111    
11112                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
11113                                    finderArgs, this);
11114    
11115                    if ((list != null) && !list.isEmpty()) {
11116                            for (WikiPage wikiPage : list) {
11117                                    if ((nodeId != wikiPage.getNodeId()) ||
11118                                                    !Validator.equals(title, wikiPage.getTitle()) ||
11119                                                    (head != wikiPage.getHead())) {
11120                                            list = null;
11121    
11122                                            break;
11123                                    }
11124                            }
11125                    }
11126    
11127                    if (list == null) {
11128                            StringBundler query = null;
11129    
11130                            if (orderByComparator != null) {
11131                                    query = new StringBundler(5 +
11132                                                    (orderByComparator.getOrderByFields().length * 3));
11133                            }
11134                            else {
11135                                    query = new StringBundler(5);
11136                            }
11137    
11138                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11139    
11140                            query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
11141    
11142                            boolean bindTitle = false;
11143    
11144                            if (title == null) {
11145                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
11146                            }
11147                            else if (title.equals(StringPool.BLANK)) {
11148                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
11149                            }
11150                            else {
11151                                    bindTitle = true;
11152    
11153                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
11154                            }
11155    
11156                            query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
11157    
11158                            if (orderByComparator != null) {
11159                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11160                                            orderByComparator);
11161                            }
11162                            else
11163                             if (pagination) {
11164                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11165                            }
11166    
11167                            String sql = query.toString();
11168    
11169                            Session session = null;
11170    
11171                            try {
11172                                    session = openSession();
11173    
11174                                    Query q = session.createQuery(sql);
11175    
11176                                    QueryPos qPos = QueryPos.getInstance(q);
11177    
11178                                    qPos.add(nodeId);
11179    
11180                                    if (bindTitle) {
11181                                            qPos.add(title.toLowerCase());
11182                                    }
11183    
11184                                    qPos.add(head);
11185    
11186                                    if (!pagination) {
11187                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11188                                                            start, end, false);
11189    
11190                                            Collections.sort(list);
11191    
11192                                            list = new UnmodifiableList<WikiPage>(list);
11193                                    }
11194                                    else {
11195                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11196                                                            start, end);
11197                                    }
11198    
11199                                    cacheResult(list);
11200    
11201                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11202                            }
11203                            catch (Exception e) {
11204                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11205    
11206                                    throw processException(e);
11207                            }
11208                            finally {
11209                                    closeSession(session);
11210                            }
11211                    }
11212    
11213                    return list;
11214            }
11215    
11216            /**
11217             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
11218             *
11219             * @param nodeId the node ID
11220             * @param title the title
11221             * @param head the head
11222             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11223             * @return the first matching wiki page
11224             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11225             * @throws SystemException if a system exception occurred
11226             */
11227            @Override
11228            public WikiPage findByN_T_H_First(long nodeId, String title, boolean head,
11229                    OrderByComparator orderByComparator)
11230                    throws NoSuchPageException, SystemException {
11231                    WikiPage wikiPage = fetchByN_T_H_First(nodeId, title, head,
11232                                    orderByComparator);
11233    
11234                    if (wikiPage != null) {
11235                            return wikiPage;
11236                    }
11237    
11238                    StringBundler msg = new StringBundler(8);
11239    
11240                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11241    
11242                    msg.append("nodeId=");
11243                    msg.append(nodeId);
11244    
11245                    msg.append(", title=");
11246                    msg.append(title);
11247    
11248                    msg.append(", head=");
11249                    msg.append(head);
11250    
11251                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11252    
11253                    throw new NoSuchPageException(msg.toString());
11254            }
11255    
11256            /**
11257             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
11258             *
11259             * @param nodeId the node ID
11260             * @param title the title
11261             * @param head the head
11262             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11263             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
11264             * @throws SystemException if a system exception occurred
11265             */
11266            @Override
11267            public WikiPage fetchByN_T_H_First(long nodeId, String title, boolean head,
11268                    OrderByComparator orderByComparator) throws SystemException {
11269                    List<WikiPage> list = findByN_T_H(nodeId, title, head, 0, 1,
11270                                    orderByComparator);
11271    
11272                    if (!list.isEmpty()) {
11273                            return list.get(0);
11274                    }
11275    
11276                    return null;
11277            }
11278    
11279            /**
11280             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
11281             *
11282             * @param nodeId the node ID
11283             * @param title the title
11284             * @param head the head
11285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11286             * @return the last matching wiki page
11287             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11288             * @throws SystemException if a system exception occurred
11289             */
11290            @Override
11291            public WikiPage findByN_T_H_Last(long nodeId, String title, boolean head,
11292                    OrderByComparator orderByComparator)
11293                    throws NoSuchPageException, SystemException {
11294                    WikiPage wikiPage = fetchByN_T_H_Last(nodeId, title, head,
11295                                    orderByComparator);
11296    
11297                    if (wikiPage != null) {
11298                            return wikiPage;
11299                    }
11300    
11301                    StringBundler msg = new StringBundler(8);
11302    
11303                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11304    
11305                    msg.append("nodeId=");
11306                    msg.append(nodeId);
11307    
11308                    msg.append(", title=");
11309                    msg.append(title);
11310    
11311                    msg.append(", head=");
11312                    msg.append(head);
11313    
11314                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11315    
11316                    throw new NoSuchPageException(msg.toString());
11317            }
11318    
11319            /**
11320             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
11321             *
11322             * @param nodeId the node ID
11323             * @param title the title
11324             * @param head the head
11325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11326             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
11327             * @throws SystemException if a system exception occurred
11328             */
11329            @Override
11330            public WikiPage fetchByN_T_H_Last(long nodeId, String title, boolean head,
11331                    OrderByComparator orderByComparator) throws SystemException {
11332                    int count = countByN_T_H(nodeId, title, head);
11333    
11334                    if (count == 0) {
11335                            return null;
11336                    }
11337    
11338                    List<WikiPage> list = findByN_T_H(nodeId, title, head, count - 1,
11339                                    count, orderByComparator);
11340    
11341                    if (!list.isEmpty()) {
11342                            return list.get(0);
11343                    }
11344    
11345                    return null;
11346            }
11347    
11348            /**
11349             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63; and head = &#63;.
11350             *
11351             * @param pageId the primary key of the current wiki page
11352             * @param nodeId the node ID
11353             * @param title the title
11354             * @param head the head
11355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11356             * @return the previous, current, and next wiki page
11357             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
11358             * @throws SystemException if a system exception occurred
11359             */
11360            @Override
11361            public WikiPage[] findByN_T_H_PrevAndNext(long pageId, long nodeId,
11362                    String title, boolean head, OrderByComparator orderByComparator)
11363                    throws NoSuchPageException, SystemException {
11364                    WikiPage wikiPage = findByPrimaryKey(pageId);
11365    
11366                    Session session = null;
11367    
11368                    try {
11369                            session = openSession();
11370    
11371                            WikiPage[] array = new WikiPageImpl[3];
11372    
11373                            array[0] = getByN_T_H_PrevAndNext(session, wikiPage, nodeId, title,
11374                                            head, orderByComparator, true);
11375    
11376                            array[1] = wikiPage;
11377    
11378                            array[2] = getByN_T_H_PrevAndNext(session, wikiPage, nodeId, title,
11379                                            head, orderByComparator, false);
11380    
11381                            return array;
11382                    }
11383                    catch (Exception e) {
11384                            throw processException(e);
11385                    }
11386                    finally {
11387                            closeSession(session);
11388                    }
11389            }
11390    
11391            protected WikiPage getByN_T_H_PrevAndNext(Session session,
11392                    WikiPage wikiPage, long nodeId, String title, boolean head,
11393                    OrderByComparator orderByComparator, boolean previous) {
11394                    StringBundler query = null;
11395    
11396                    if (orderByComparator != null) {
11397                            query = new StringBundler(6 +
11398                                            (orderByComparator.getOrderByFields().length * 6));
11399                    }
11400                    else {
11401                            query = new StringBundler(3);
11402                    }
11403    
11404                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11405    
11406                    query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
11407    
11408                    boolean bindTitle = false;
11409    
11410                    if (title == null) {
11411                            query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
11412                    }
11413                    else if (title.equals(StringPool.BLANK)) {
11414                            query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
11415                    }
11416                    else {
11417                            bindTitle = true;
11418    
11419                            query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
11420                    }
11421    
11422                    query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
11423    
11424                    if (orderByComparator != null) {
11425                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11426    
11427                            if (orderByConditionFields.length > 0) {
11428                                    query.append(WHERE_AND);
11429                            }
11430    
11431                            for (int i = 0; i < orderByConditionFields.length; i++) {
11432                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11433                                    query.append(orderByConditionFields[i]);
11434    
11435                                    if ((i + 1) < orderByConditionFields.length) {
11436                                            if (orderByComparator.isAscending() ^ previous) {
11437                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11438                                            }
11439                                            else {
11440                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11441                                            }
11442                                    }
11443                                    else {
11444                                            if (orderByComparator.isAscending() ^ previous) {
11445                                                    query.append(WHERE_GREATER_THAN);
11446                                            }
11447                                            else {
11448                                                    query.append(WHERE_LESSER_THAN);
11449                                            }
11450                                    }
11451                            }
11452    
11453                            query.append(ORDER_BY_CLAUSE);
11454    
11455                            String[] orderByFields = orderByComparator.getOrderByFields();
11456    
11457                            for (int i = 0; i < orderByFields.length; i++) {
11458                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11459                                    query.append(orderByFields[i]);
11460    
11461                                    if ((i + 1) < orderByFields.length) {
11462                                            if (orderByComparator.isAscending() ^ previous) {
11463                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11464                                            }
11465                                            else {
11466                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11467                                            }
11468                                    }
11469                                    else {
11470                                            if (orderByComparator.isAscending() ^ previous) {
11471                                                    query.append(ORDER_BY_ASC);
11472                                            }
11473                                            else {
11474                                                    query.append(ORDER_BY_DESC);
11475                                            }
11476                                    }
11477                            }
11478                    }
11479                    else {
11480                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11481                    }
11482    
11483                    String sql = query.toString();
11484    
11485                    Query q = session.createQuery(sql);
11486    
11487                    q.setFirstResult(0);
11488                    q.setMaxResults(2);
11489    
11490                    QueryPos qPos = QueryPos.getInstance(q);
11491    
11492                    qPos.add(nodeId);
11493    
11494                    if (bindTitle) {
11495                            qPos.add(title.toLowerCase());
11496                    }
11497    
11498                    qPos.add(head);
11499    
11500                    if (orderByComparator != null) {
11501                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
11502    
11503                            for (Object value : values) {
11504                                    qPos.add(value);
11505                            }
11506                    }
11507    
11508                    List<WikiPage> list = q.list();
11509    
11510                    if (list.size() == 2) {
11511                            return list.get(1);
11512                    }
11513                    else {
11514                            return null;
11515                    }
11516            }
11517    
11518            /**
11519             * Removes all the wiki pages where nodeId = &#63; and title = &#63; and head = &#63; from the database.
11520             *
11521             * @param nodeId the node ID
11522             * @param title the title
11523             * @param head the head
11524             * @throws SystemException if a system exception occurred
11525             */
11526            @Override
11527            public void removeByN_T_H(long nodeId, String title, boolean head)
11528                    throws SystemException {
11529                    for (WikiPage wikiPage : findByN_T_H(nodeId, title, head,
11530                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11531                            remove(wikiPage);
11532                    }
11533            }
11534    
11535            /**
11536             * Returns the number of wiki pages where nodeId = &#63; and title = &#63; and head = &#63;.
11537             *
11538             * @param nodeId the node ID
11539             * @param title the title
11540             * @param head the head
11541             * @return the number of matching wiki pages
11542             * @throws SystemException if a system exception occurred
11543             */
11544            @Override
11545            public int countByN_T_H(long nodeId, String title, boolean head)
11546                    throws SystemException {
11547                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T_H;
11548    
11549                    Object[] finderArgs = new Object[] { nodeId, title, head };
11550    
11551                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11552                                    this);
11553    
11554                    if (count == null) {
11555                            StringBundler query = new StringBundler(4);
11556    
11557                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
11558    
11559                            query.append(_FINDER_COLUMN_N_T_H_NODEID_2);
11560    
11561                            boolean bindTitle = false;
11562    
11563                            if (title == null) {
11564                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_1);
11565                            }
11566                            else if (title.equals(StringPool.BLANK)) {
11567                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_3);
11568                            }
11569                            else {
11570                                    bindTitle = true;
11571    
11572                                    query.append(_FINDER_COLUMN_N_T_H_TITLE_2);
11573                            }
11574    
11575                            query.append(_FINDER_COLUMN_N_T_H_HEAD_2);
11576    
11577                            String sql = query.toString();
11578    
11579                            Session session = null;
11580    
11581                            try {
11582                                    session = openSession();
11583    
11584                                    Query q = session.createQuery(sql);
11585    
11586                                    QueryPos qPos = QueryPos.getInstance(q);
11587    
11588                                    qPos.add(nodeId);
11589    
11590                                    if (bindTitle) {
11591                                            qPos.add(title.toLowerCase());
11592                                    }
11593    
11594                                    qPos.add(head);
11595    
11596                                    count = (Long)q.uniqueResult();
11597    
11598                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11599                            }
11600                            catch (Exception e) {
11601                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11602    
11603                                    throw processException(e);
11604                            }
11605                            finally {
11606                                    closeSession(session);
11607                            }
11608                    }
11609    
11610                    return count.intValue();
11611            }
11612    
11613            private static final String _FINDER_COLUMN_N_T_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
11614            private static final String _FINDER_COLUMN_N_T_H_TITLE_1 = "wikiPage.title IS NULL AND ";
11615            private static final String _FINDER_COLUMN_N_T_H_TITLE_2 = "lower(wikiPage.title) = ? AND ";
11616            private static final String _FINDER_COLUMN_N_T_H_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
11617            private static final String _FINDER_COLUMN_N_T_H_HEAD_2 = "wikiPage.head = ?";
11618            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11619                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
11620                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_T_S",
11621                            new String[] {
11622                                    Long.class.getName(), String.class.getName(),
11623                                    Integer.class.getName(),
11624                                    
11625                            Integer.class.getName(), Integer.class.getName(),
11626                                    OrderByComparator.class.getName()
11627                            });
11628            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11629                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
11630                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_T_S",
11631                            new String[] {
11632                                    Long.class.getName(), String.class.getName(),
11633                                    Integer.class.getName()
11634                            },
11635                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
11636                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
11637                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
11638                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
11639            public static final FinderPath FINDER_PATH_COUNT_BY_N_T_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
11640                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11641                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_T_S",
11642                            new String[] {
11643                                    Long.class.getName(), String.class.getName(),
11644                                    Integer.class.getName()
11645                            });
11646    
11647            /**
11648             * Returns all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
11649             *
11650             * @param nodeId the node ID
11651             * @param title the title
11652             * @param status the status
11653             * @return the matching wiki pages
11654             * @throws SystemException if a system exception occurred
11655             */
11656            @Override
11657            public List<WikiPage> findByN_T_S(long nodeId, String title, int status)
11658                    throws SystemException {
11659                    return findByN_T_S(nodeId, title, status, QueryUtil.ALL_POS,
11660                            QueryUtil.ALL_POS, null);
11661            }
11662    
11663            /**
11664             * Returns a range of all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
11665             *
11666             * <p>
11667             * 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.
11668             * </p>
11669             *
11670             * @param nodeId the node ID
11671             * @param title the title
11672             * @param status the status
11673             * @param start the lower bound of the range of wiki pages
11674             * @param end the upper bound of the range of wiki pages (not inclusive)
11675             * @return the range of matching wiki pages
11676             * @throws SystemException if a system exception occurred
11677             */
11678            @Override
11679            public List<WikiPage> findByN_T_S(long nodeId, String title, int status,
11680                    int start, int end) throws SystemException {
11681                    return findByN_T_S(nodeId, title, status, start, end, null);
11682            }
11683    
11684            /**
11685             * Returns an ordered range of all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
11686             *
11687             * <p>
11688             * 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.
11689             * </p>
11690             *
11691             * @param nodeId the node ID
11692             * @param title the title
11693             * @param status the status
11694             * @param start the lower bound of the range of wiki pages
11695             * @param end the upper bound of the range of wiki pages (not inclusive)
11696             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11697             * @return the ordered range of matching wiki pages
11698             * @throws SystemException if a system exception occurred
11699             */
11700            @Override
11701            public List<WikiPage> findByN_T_S(long nodeId, String title, int status,
11702                    int start, int end, OrderByComparator orderByComparator)
11703                    throws SystemException {
11704                    boolean pagination = true;
11705                    FinderPath finderPath = null;
11706                    Object[] finderArgs = null;
11707    
11708                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11709                                    (orderByComparator == null)) {
11710                            pagination = false;
11711                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S;
11712                            finderArgs = new Object[] { nodeId, title, status };
11713                    }
11714                    else {
11715                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_T_S;
11716                            finderArgs = new Object[] {
11717                                            nodeId, title, status,
11718                                            
11719                                            start, end, orderByComparator
11720                                    };
11721                    }
11722    
11723                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
11724                                    finderArgs, this);
11725    
11726                    if ((list != null) && !list.isEmpty()) {
11727                            for (WikiPage wikiPage : list) {
11728                                    if ((nodeId != wikiPage.getNodeId()) ||
11729                                                    !Validator.equals(title, wikiPage.getTitle()) ||
11730                                                    (status != wikiPage.getStatus())) {
11731                                            list = null;
11732    
11733                                            break;
11734                                    }
11735                            }
11736                    }
11737    
11738                    if (list == null) {
11739                            StringBundler query = null;
11740    
11741                            if (orderByComparator != null) {
11742                                    query = new StringBundler(5 +
11743                                                    (orderByComparator.getOrderByFields().length * 3));
11744                            }
11745                            else {
11746                                    query = new StringBundler(5);
11747                            }
11748    
11749                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
11750    
11751                            query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
11752    
11753                            boolean bindTitle = false;
11754    
11755                            if (title == null) {
11756                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
11757                            }
11758                            else if (title.equals(StringPool.BLANK)) {
11759                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
11760                            }
11761                            else {
11762                                    bindTitle = true;
11763    
11764                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
11765                            }
11766    
11767                            query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
11768    
11769                            if (orderByComparator != null) {
11770                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11771                                            orderByComparator);
11772                            }
11773                            else
11774                             if (pagination) {
11775                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
11776                            }
11777    
11778                            String sql = query.toString();
11779    
11780                            Session session = null;
11781    
11782                            try {
11783                                    session = openSession();
11784    
11785                                    Query q = session.createQuery(sql);
11786    
11787                                    QueryPos qPos = QueryPos.getInstance(q);
11788    
11789                                    qPos.add(nodeId);
11790    
11791                                    if (bindTitle) {
11792                                            qPos.add(title.toLowerCase());
11793                                    }
11794    
11795                                    qPos.add(status);
11796    
11797                                    if (!pagination) {
11798                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11799                                                            start, end, false);
11800    
11801                                            Collections.sort(list);
11802    
11803                                            list = new UnmodifiableList<WikiPage>(list);
11804                                    }
11805                                    else {
11806                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
11807                                                            start, end);
11808                                    }
11809    
11810                                    cacheResult(list);
11811    
11812                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11813                            }
11814                            catch (Exception e) {
11815                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11816    
11817                                    throw processException(e);
11818                            }
11819                            finally {
11820                                    closeSession(session);
11821                            }
11822                    }
11823    
11824                    return list;
11825            }
11826    
11827            /**
11828             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
11829             *
11830             * @param nodeId the node ID
11831             * @param title the title
11832             * @param status the status
11833             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11834             * @return the first matching wiki page
11835             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11836             * @throws SystemException if a system exception occurred
11837             */
11838            @Override
11839            public WikiPage findByN_T_S_First(long nodeId, String title, int status,
11840                    OrderByComparator orderByComparator)
11841                    throws NoSuchPageException, SystemException {
11842                    WikiPage wikiPage = fetchByN_T_S_First(nodeId, title, status,
11843                                    orderByComparator);
11844    
11845                    if (wikiPage != null) {
11846                            return wikiPage;
11847                    }
11848    
11849                    StringBundler msg = new StringBundler(8);
11850    
11851                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11852    
11853                    msg.append("nodeId=");
11854                    msg.append(nodeId);
11855    
11856                    msg.append(", title=");
11857                    msg.append(title);
11858    
11859                    msg.append(", status=");
11860                    msg.append(status);
11861    
11862                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11863    
11864                    throw new NoSuchPageException(msg.toString());
11865            }
11866    
11867            /**
11868             * Returns the first wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
11869             *
11870             * @param nodeId the node ID
11871             * @param title the title
11872             * @param status the status
11873             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11874             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
11875             * @throws SystemException if a system exception occurred
11876             */
11877            @Override
11878            public WikiPage fetchByN_T_S_First(long nodeId, String title, int status,
11879                    OrderByComparator orderByComparator) throws SystemException {
11880                    List<WikiPage> list = findByN_T_S(nodeId, title, status, 0, 1,
11881                                    orderByComparator);
11882    
11883                    if (!list.isEmpty()) {
11884                            return list.get(0);
11885                    }
11886    
11887                    return null;
11888            }
11889    
11890            /**
11891             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
11892             *
11893             * @param nodeId the node ID
11894             * @param title the title
11895             * @param status the status
11896             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11897             * @return the last matching wiki page
11898             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
11899             * @throws SystemException if a system exception occurred
11900             */
11901            @Override
11902            public WikiPage findByN_T_S_Last(long nodeId, String title, int status,
11903                    OrderByComparator orderByComparator)
11904                    throws NoSuchPageException, SystemException {
11905                    WikiPage wikiPage = fetchByN_T_S_Last(nodeId, title, status,
11906                                    orderByComparator);
11907    
11908                    if (wikiPage != null) {
11909                            return wikiPage;
11910                    }
11911    
11912                    StringBundler msg = new StringBundler(8);
11913    
11914                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11915    
11916                    msg.append("nodeId=");
11917                    msg.append(nodeId);
11918    
11919                    msg.append(", title=");
11920                    msg.append(title);
11921    
11922                    msg.append(", status=");
11923                    msg.append(status);
11924    
11925                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11926    
11927                    throw new NoSuchPageException(msg.toString());
11928            }
11929    
11930            /**
11931             * Returns the last wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
11932             *
11933             * @param nodeId the node ID
11934             * @param title the title
11935             * @param status the status
11936             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11937             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
11938             * @throws SystemException if a system exception occurred
11939             */
11940            @Override
11941            public WikiPage fetchByN_T_S_Last(long nodeId, String title, int status,
11942                    OrderByComparator orderByComparator) throws SystemException {
11943                    int count = countByN_T_S(nodeId, title, status);
11944    
11945                    if (count == 0) {
11946                            return null;
11947                    }
11948    
11949                    List<WikiPage> list = findByN_T_S(nodeId, title, status, count - 1,
11950                                    count, orderByComparator);
11951    
11952                    if (!list.isEmpty()) {
11953                            return list.get(0);
11954                    }
11955    
11956                    return null;
11957            }
11958    
11959            /**
11960             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and title = &#63; and status = &#63;.
11961             *
11962             * @param pageId the primary key of the current wiki page
11963             * @param nodeId the node ID
11964             * @param title the title
11965             * @param status the status
11966             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11967             * @return the previous, current, and next wiki page
11968             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
11969             * @throws SystemException if a system exception occurred
11970             */
11971            @Override
11972            public WikiPage[] findByN_T_S_PrevAndNext(long pageId, long nodeId,
11973                    String title, int status, OrderByComparator orderByComparator)
11974                    throws NoSuchPageException, SystemException {
11975                    WikiPage wikiPage = findByPrimaryKey(pageId);
11976    
11977                    Session session = null;
11978    
11979                    try {
11980                            session = openSession();
11981    
11982                            WikiPage[] array = new WikiPageImpl[3];
11983    
11984                            array[0] = getByN_T_S_PrevAndNext(session, wikiPage, nodeId, title,
11985                                            status, orderByComparator, true);
11986    
11987                            array[1] = wikiPage;
11988    
11989                            array[2] = getByN_T_S_PrevAndNext(session, wikiPage, nodeId, title,
11990                                            status, orderByComparator, false);
11991    
11992                            return array;
11993                    }
11994                    catch (Exception e) {
11995                            throw processException(e);
11996                    }
11997                    finally {
11998                            closeSession(session);
11999                    }
12000            }
12001    
12002            protected WikiPage getByN_T_S_PrevAndNext(Session session,
12003                    WikiPage wikiPage, long nodeId, String title, int status,
12004                    OrderByComparator orderByComparator, boolean previous) {
12005                    StringBundler query = null;
12006    
12007                    if (orderByComparator != null) {
12008                            query = new StringBundler(6 +
12009                                            (orderByComparator.getOrderByFields().length * 6));
12010                    }
12011                    else {
12012                            query = new StringBundler(3);
12013                    }
12014    
12015                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
12016    
12017                    query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
12018    
12019                    boolean bindTitle = false;
12020    
12021                    if (title == null) {
12022                            query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
12023                    }
12024                    else if (title.equals(StringPool.BLANK)) {
12025                            query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
12026                    }
12027                    else {
12028                            bindTitle = true;
12029    
12030                            query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
12031                    }
12032    
12033                    query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
12034    
12035                    if (orderByComparator != null) {
12036                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12037    
12038                            if (orderByConditionFields.length > 0) {
12039                                    query.append(WHERE_AND);
12040                            }
12041    
12042                            for (int i = 0; i < orderByConditionFields.length; i++) {
12043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12044                                    query.append(orderByConditionFields[i]);
12045    
12046                                    if ((i + 1) < orderByConditionFields.length) {
12047                                            if (orderByComparator.isAscending() ^ previous) {
12048                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12049                                            }
12050                                            else {
12051                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12052                                            }
12053                                    }
12054                                    else {
12055                                            if (orderByComparator.isAscending() ^ previous) {
12056                                                    query.append(WHERE_GREATER_THAN);
12057                                            }
12058                                            else {
12059                                                    query.append(WHERE_LESSER_THAN);
12060                                            }
12061                                    }
12062                            }
12063    
12064                            query.append(ORDER_BY_CLAUSE);
12065    
12066                            String[] orderByFields = orderByComparator.getOrderByFields();
12067    
12068                            for (int i = 0; i < orderByFields.length; i++) {
12069                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12070                                    query.append(orderByFields[i]);
12071    
12072                                    if ((i + 1) < orderByFields.length) {
12073                                            if (orderByComparator.isAscending() ^ previous) {
12074                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12075                                            }
12076                                            else {
12077                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12078                                            }
12079                                    }
12080                                    else {
12081                                            if (orderByComparator.isAscending() ^ previous) {
12082                                                    query.append(ORDER_BY_ASC);
12083                                            }
12084                                            else {
12085                                                    query.append(ORDER_BY_DESC);
12086                                            }
12087                                    }
12088                            }
12089                    }
12090                    else {
12091                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12092                    }
12093    
12094                    String sql = query.toString();
12095    
12096                    Query q = session.createQuery(sql);
12097    
12098                    q.setFirstResult(0);
12099                    q.setMaxResults(2);
12100    
12101                    QueryPos qPos = QueryPos.getInstance(q);
12102    
12103                    qPos.add(nodeId);
12104    
12105                    if (bindTitle) {
12106                            qPos.add(title.toLowerCase());
12107                    }
12108    
12109                    qPos.add(status);
12110    
12111                    if (orderByComparator != null) {
12112                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
12113    
12114                            for (Object value : values) {
12115                                    qPos.add(value);
12116                            }
12117                    }
12118    
12119                    List<WikiPage> list = q.list();
12120    
12121                    if (list.size() == 2) {
12122                            return list.get(1);
12123                    }
12124                    else {
12125                            return null;
12126                    }
12127            }
12128    
12129            /**
12130             * Removes all the wiki pages where nodeId = &#63; and title = &#63; and status = &#63; from the database.
12131             *
12132             * @param nodeId the node ID
12133             * @param title the title
12134             * @param status the status
12135             * @throws SystemException if a system exception occurred
12136             */
12137            @Override
12138            public void removeByN_T_S(long nodeId, String title, int status)
12139                    throws SystemException {
12140                    for (WikiPage wikiPage : findByN_T_S(nodeId, title, status,
12141                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12142                            remove(wikiPage);
12143                    }
12144            }
12145    
12146            /**
12147             * Returns the number of wiki pages where nodeId = &#63; and title = &#63; and status = &#63;.
12148             *
12149             * @param nodeId the node ID
12150             * @param title the title
12151             * @param status the status
12152             * @return the number of matching wiki pages
12153             * @throws SystemException if a system exception occurred
12154             */
12155            @Override
12156            public int countByN_T_S(long nodeId, String title, int status)
12157                    throws SystemException {
12158                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_T_S;
12159    
12160                    Object[] finderArgs = new Object[] { nodeId, title, status };
12161    
12162                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12163                                    this);
12164    
12165                    if (count == null) {
12166                            StringBundler query = new StringBundler(4);
12167    
12168                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
12169    
12170                            query.append(_FINDER_COLUMN_N_T_S_NODEID_2);
12171    
12172                            boolean bindTitle = false;
12173    
12174                            if (title == null) {
12175                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_1);
12176                            }
12177                            else if (title.equals(StringPool.BLANK)) {
12178                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_3);
12179                            }
12180                            else {
12181                                    bindTitle = true;
12182    
12183                                    query.append(_FINDER_COLUMN_N_T_S_TITLE_2);
12184                            }
12185    
12186                            query.append(_FINDER_COLUMN_N_T_S_STATUS_2);
12187    
12188                            String sql = query.toString();
12189    
12190                            Session session = null;
12191    
12192                            try {
12193                                    session = openSession();
12194    
12195                                    Query q = session.createQuery(sql);
12196    
12197                                    QueryPos qPos = QueryPos.getInstance(q);
12198    
12199                                    qPos.add(nodeId);
12200    
12201                                    if (bindTitle) {
12202                                            qPos.add(title.toLowerCase());
12203                                    }
12204    
12205                                    qPos.add(status);
12206    
12207                                    count = (Long)q.uniqueResult();
12208    
12209                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12210                            }
12211                            catch (Exception e) {
12212                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12213    
12214                                    throw processException(e);
12215                            }
12216                            finally {
12217                                    closeSession(session);
12218                            }
12219                    }
12220    
12221                    return count.intValue();
12222            }
12223    
12224            private static final String _FINDER_COLUMN_N_T_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
12225            private static final String _FINDER_COLUMN_N_T_S_TITLE_1 = "wikiPage.title IS NULL AND ";
12226            private static final String _FINDER_COLUMN_N_T_S_TITLE_2 = "lower(wikiPage.title) = ? AND ";
12227            private static final String _FINDER_COLUMN_N_T_S_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
12228            private static final String _FINDER_COLUMN_N_T_S_STATUS_2 = "wikiPage.status = ?";
12229            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12230                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
12231                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_P",
12232                            new String[] {
12233                                    Long.class.getName(), Boolean.class.getName(),
12234                                    String.class.getName(),
12235                                    
12236                            Integer.class.getName(), Integer.class.getName(),
12237                                    OrderByComparator.class.getName()
12238                            });
12239            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12240                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
12241                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_P",
12242                            new String[] {
12243                                    Long.class.getName(), Boolean.class.getName(),
12244                                    String.class.getName()
12245                            },
12246                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
12247                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
12248                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
12249                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
12250                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
12251            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_P = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12252                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12253                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_P",
12254                            new String[] {
12255                                    Long.class.getName(), Boolean.class.getName(),
12256                                    String.class.getName()
12257                            });
12258    
12259            /**
12260             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
12261             *
12262             * @param nodeId the node ID
12263             * @param head the head
12264             * @param parentTitle the parent title
12265             * @return the matching wiki pages
12266             * @throws SystemException if a system exception occurred
12267             */
12268            @Override
12269            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
12270                    String parentTitle) throws SystemException {
12271                    return findByN_H_P(nodeId, head, parentTitle, QueryUtil.ALL_POS,
12272                            QueryUtil.ALL_POS, null);
12273            }
12274    
12275            /**
12276             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
12277             *
12278             * <p>
12279             * 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.
12280             * </p>
12281             *
12282             * @param nodeId the node ID
12283             * @param head the head
12284             * @param parentTitle the parent title
12285             * @param start the lower bound of the range of wiki pages
12286             * @param end the upper bound of the range of wiki pages (not inclusive)
12287             * @return the range of matching wiki pages
12288             * @throws SystemException if a system exception occurred
12289             */
12290            @Override
12291            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
12292                    String parentTitle, int start, int end) throws SystemException {
12293                    return findByN_H_P(nodeId, head, parentTitle, start, end, null);
12294            }
12295    
12296            /**
12297             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
12298             *
12299             * <p>
12300             * 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.
12301             * </p>
12302             *
12303             * @param nodeId the node ID
12304             * @param head the head
12305             * @param parentTitle the parent title
12306             * @param start the lower bound of the range of wiki pages
12307             * @param end the upper bound of the range of wiki pages (not inclusive)
12308             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12309             * @return the ordered range of matching wiki pages
12310             * @throws SystemException if a system exception occurred
12311             */
12312            @Override
12313            public List<WikiPage> findByN_H_P(long nodeId, boolean head,
12314                    String parentTitle, int start, int end,
12315                    OrderByComparator orderByComparator) throws SystemException {
12316                    boolean pagination = true;
12317                    FinderPath finderPath = null;
12318                    Object[] finderArgs = null;
12319    
12320                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12321                                    (orderByComparator == null)) {
12322                            pagination = false;
12323                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P;
12324                            finderArgs = new Object[] { nodeId, head, parentTitle };
12325                    }
12326                    else {
12327                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P;
12328                            finderArgs = new Object[] {
12329                                            nodeId, head, parentTitle,
12330                                            
12331                                            start, end, orderByComparator
12332                                    };
12333                    }
12334    
12335                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
12336                                    finderArgs, this);
12337    
12338                    if ((list != null) && !list.isEmpty()) {
12339                            for (WikiPage wikiPage : list) {
12340                                    if ((nodeId != wikiPage.getNodeId()) ||
12341                                                    (head != wikiPage.getHead()) ||
12342                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle())) {
12343                                            list = null;
12344    
12345                                            break;
12346                                    }
12347                            }
12348                    }
12349    
12350                    if (list == null) {
12351                            StringBundler query = null;
12352    
12353                            if (orderByComparator != null) {
12354                                    query = new StringBundler(5 +
12355                                                    (orderByComparator.getOrderByFields().length * 3));
12356                            }
12357                            else {
12358                                    query = new StringBundler(5);
12359                            }
12360    
12361                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
12362    
12363                            query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
12364    
12365                            query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
12366    
12367                            boolean bindParentTitle = false;
12368    
12369                            if (parentTitle == null) {
12370                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
12371                            }
12372                            else if (parentTitle.equals(StringPool.BLANK)) {
12373                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
12374                            }
12375                            else {
12376                                    bindParentTitle = true;
12377    
12378                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
12379                            }
12380    
12381                            if (orderByComparator != null) {
12382                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12383                                            orderByComparator);
12384                            }
12385                            else
12386                             if (pagination) {
12387                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12388                            }
12389    
12390                            String sql = query.toString();
12391    
12392                            Session session = null;
12393    
12394                            try {
12395                                    session = openSession();
12396    
12397                                    Query q = session.createQuery(sql);
12398    
12399                                    QueryPos qPos = QueryPos.getInstance(q);
12400    
12401                                    qPos.add(nodeId);
12402    
12403                                    qPos.add(head);
12404    
12405                                    if (bindParentTitle) {
12406                                            qPos.add(parentTitle.toLowerCase());
12407                                    }
12408    
12409                                    if (!pagination) {
12410                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
12411                                                            start, end, false);
12412    
12413                                            Collections.sort(list);
12414    
12415                                            list = new UnmodifiableList<WikiPage>(list);
12416                                    }
12417                                    else {
12418                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
12419                                                            start, end);
12420                                    }
12421    
12422                                    cacheResult(list);
12423    
12424                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
12425                            }
12426                            catch (Exception e) {
12427                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12428    
12429                                    throw processException(e);
12430                            }
12431                            finally {
12432                                    closeSession(session);
12433                            }
12434                    }
12435    
12436                    return list;
12437            }
12438    
12439            /**
12440             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
12441             *
12442             * @param nodeId the node ID
12443             * @param head the head
12444             * @param parentTitle the parent title
12445             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12446             * @return the first matching wiki page
12447             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
12448             * @throws SystemException if a system exception occurred
12449             */
12450            @Override
12451            public WikiPage findByN_H_P_First(long nodeId, boolean head,
12452                    String parentTitle, OrderByComparator orderByComparator)
12453                    throws NoSuchPageException, SystemException {
12454                    WikiPage wikiPage = fetchByN_H_P_First(nodeId, head, parentTitle,
12455                                    orderByComparator);
12456    
12457                    if (wikiPage != null) {
12458                            return wikiPage;
12459                    }
12460    
12461                    StringBundler msg = new StringBundler(8);
12462    
12463                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12464    
12465                    msg.append("nodeId=");
12466                    msg.append(nodeId);
12467    
12468                    msg.append(", head=");
12469                    msg.append(head);
12470    
12471                    msg.append(", parentTitle=");
12472                    msg.append(parentTitle);
12473    
12474                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12475    
12476                    throw new NoSuchPageException(msg.toString());
12477            }
12478    
12479            /**
12480             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
12481             *
12482             * @param nodeId the node ID
12483             * @param head the head
12484             * @param parentTitle the parent title
12485             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12486             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
12487             * @throws SystemException if a system exception occurred
12488             */
12489            @Override
12490            public WikiPage fetchByN_H_P_First(long nodeId, boolean head,
12491                    String parentTitle, OrderByComparator orderByComparator)
12492                    throws SystemException {
12493                    List<WikiPage> list = findByN_H_P(nodeId, head, parentTitle, 0, 1,
12494                                    orderByComparator);
12495    
12496                    if (!list.isEmpty()) {
12497                            return list.get(0);
12498                    }
12499    
12500                    return null;
12501            }
12502    
12503            /**
12504             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
12505             *
12506             * @param nodeId the node ID
12507             * @param head the head
12508             * @param parentTitle the parent title
12509             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12510             * @return the last matching wiki page
12511             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
12512             * @throws SystemException if a system exception occurred
12513             */
12514            @Override
12515            public WikiPage findByN_H_P_Last(long nodeId, boolean head,
12516                    String parentTitle, OrderByComparator orderByComparator)
12517                    throws NoSuchPageException, SystemException {
12518                    WikiPage wikiPage = fetchByN_H_P_Last(nodeId, head, parentTitle,
12519                                    orderByComparator);
12520    
12521                    if (wikiPage != null) {
12522                            return wikiPage;
12523                    }
12524    
12525                    StringBundler msg = new StringBundler(8);
12526    
12527                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12528    
12529                    msg.append("nodeId=");
12530                    msg.append(nodeId);
12531    
12532                    msg.append(", head=");
12533                    msg.append(head);
12534    
12535                    msg.append(", parentTitle=");
12536                    msg.append(parentTitle);
12537    
12538                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12539    
12540                    throw new NoSuchPageException(msg.toString());
12541            }
12542    
12543            /**
12544             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
12545             *
12546             * @param nodeId the node ID
12547             * @param head the head
12548             * @param parentTitle the parent title
12549             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12550             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
12551             * @throws SystemException if a system exception occurred
12552             */
12553            @Override
12554            public WikiPage fetchByN_H_P_Last(long nodeId, boolean head,
12555                    String parentTitle, OrderByComparator orderByComparator)
12556                    throws SystemException {
12557                    int count = countByN_H_P(nodeId, head, parentTitle);
12558    
12559                    if (count == 0) {
12560                            return null;
12561                    }
12562    
12563                    List<WikiPage> list = findByN_H_P(nodeId, head, parentTitle, count - 1,
12564                                    count, orderByComparator);
12565    
12566                    if (!list.isEmpty()) {
12567                            return list.get(0);
12568                    }
12569    
12570                    return null;
12571            }
12572    
12573            /**
12574             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
12575             *
12576             * @param pageId the primary key of the current wiki page
12577             * @param nodeId the node ID
12578             * @param head the head
12579             * @param parentTitle the parent title
12580             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12581             * @return the previous, current, and next wiki page
12582             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
12583             * @throws SystemException if a system exception occurred
12584             */
12585            @Override
12586            public WikiPage[] findByN_H_P_PrevAndNext(long pageId, long nodeId,
12587                    boolean head, String parentTitle, OrderByComparator orderByComparator)
12588                    throws NoSuchPageException, SystemException {
12589                    WikiPage wikiPage = findByPrimaryKey(pageId);
12590    
12591                    Session session = null;
12592    
12593                    try {
12594                            session = openSession();
12595    
12596                            WikiPage[] array = new WikiPageImpl[3];
12597    
12598                            array[0] = getByN_H_P_PrevAndNext(session, wikiPage, nodeId, head,
12599                                            parentTitle, orderByComparator, true);
12600    
12601                            array[1] = wikiPage;
12602    
12603                            array[2] = getByN_H_P_PrevAndNext(session, wikiPage, nodeId, head,
12604                                            parentTitle, orderByComparator, false);
12605    
12606                            return array;
12607                    }
12608                    catch (Exception e) {
12609                            throw processException(e);
12610                    }
12611                    finally {
12612                            closeSession(session);
12613                    }
12614            }
12615    
12616            protected WikiPage getByN_H_P_PrevAndNext(Session session,
12617                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
12618                    OrderByComparator orderByComparator, boolean previous) {
12619                    StringBundler query = null;
12620    
12621                    if (orderByComparator != null) {
12622                            query = new StringBundler(6 +
12623                                            (orderByComparator.getOrderByFields().length * 6));
12624                    }
12625                    else {
12626                            query = new StringBundler(3);
12627                    }
12628    
12629                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
12630    
12631                    query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
12632    
12633                    query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
12634    
12635                    boolean bindParentTitle = false;
12636    
12637                    if (parentTitle == null) {
12638                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
12639                    }
12640                    else if (parentTitle.equals(StringPool.BLANK)) {
12641                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
12642                    }
12643                    else {
12644                            bindParentTitle = true;
12645    
12646                            query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
12647                    }
12648    
12649                    if (orderByComparator != null) {
12650                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12651    
12652                            if (orderByConditionFields.length > 0) {
12653                                    query.append(WHERE_AND);
12654                            }
12655    
12656                            for (int i = 0; i < orderByConditionFields.length; i++) {
12657                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12658                                    query.append(orderByConditionFields[i]);
12659    
12660                                    if ((i + 1) < orderByConditionFields.length) {
12661                                            if (orderByComparator.isAscending() ^ previous) {
12662                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12663                                            }
12664                                            else {
12665                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12666                                            }
12667                                    }
12668                                    else {
12669                                            if (orderByComparator.isAscending() ^ previous) {
12670                                                    query.append(WHERE_GREATER_THAN);
12671                                            }
12672                                            else {
12673                                                    query.append(WHERE_LESSER_THAN);
12674                                            }
12675                                    }
12676                            }
12677    
12678                            query.append(ORDER_BY_CLAUSE);
12679    
12680                            String[] orderByFields = orderByComparator.getOrderByFields();
12681    
12682                            for (int i = 0; i < orderByFields.length; i++) {
12683                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12684                                    query.append(orderByFields[i]);
12685    
12686                                    if ((i + 1) < orderByFields.length) {
12687                                            if (orderByComparator.isAscending() ^ previous) {
12688                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12689                                            }
12690                                            else {
12691                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12692                                            }
12693                                    }
12694                                    else {
12695                                            if (orderByComparator.isAscending() ^ previous) {
12696                                                    query.append(ORDER_BY_ASC);
12697                                            }
12698                                            else {
12699                                                    query.append(ORDER_BY_DESC);
12700                                            }
12701                                    }
12702                            }
12703                    }
12704                    else {
12705                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
12706                    }
12707    
12708                    String sql = query.toString();
12709    
12710                    Query q = session.createQuery(sql);
12711    
12712                    q.setFirstResult(0);
12713                    q.setMaxResults(2);
12714    
12715                    QueryPos qPos = QueryPos.getInstance(q);
12716    
12717                    qPos.add(nodeId);
12718    
12719                    qPos.add(head);
12720    
12721                    if (bindParentTitle) {
12722                            qPos.add(parentTitle.toLowerCase());
12723                    }
12724    
12725                    if (orderByComparator != null) {
12726                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
12727    
12728                            for (Object value : values) {
12729                                    qPos.add(value);
12730                            }
12731                    }
12732    
12733                    List<WikiPage> list = q.list();
12734    
12735                    if (list.size() == 2) {
12736                            return list.get(1);
12737                    }
12738                    else {
12739                            return null;
12740                    }
12741            }
12742    
12743            /**
12744             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; from the database.
12745             *
12746             * @param nodeId the node ID
12747             * @param head the head
12748             * @param parentTitle the parent title
12749             * @throws SystemException if a system exception occurred
12750             */
12751            @Override
12752            public void removeByN_H_P(long nodeId, boolean head, String parentTitle)
12753                    throws SystemException {
12754                    for (WikiPage wikiPage : findByN_H_P(nodeId, head, parentTitle,
12755                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12756                            remove(wikiPage);
12757                    }
12758            }
12759    
12760            /**
12761             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63;.
12762             *
12763             * @param nodeId the node ID
12764             * @param head the head
12765             * @param parentTitle the parent title
12766             * @return the number of matching wiki pages
12767             * @throws SystemException if a system exception occurred
12768             */
12769            @Override
12770            public int countByN_H_P(long nodeId, boolean head, String parentTitle)
12771                    throws SystemException {
12772                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_P;
12773    
12774                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle };
12775    
12776                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12777                                    this);
12778    
12779                    if (count == null) {
12780                            StringBundler query = new StringBundler(4);
12781    
12782                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
12783    
12784                            query.append(_FINDER_COLUMN_N_H_P_NODEID_2);
12785    
12786                            query.append(_FINDER_COLUMN_N_H_P_HEAD_2);
12787    
12788                            boolean bindParentTitle = false;
12789    
12790                            if (parentTitle == null) {
12791                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_1);
12792                            }
12793                            else if (parentTitle.equals(StringPool.BLANK)) {
12794                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_3);
12795                            }
12796                            else {
12797                                    bindParentTitle = true;
12798    
12799                                    query.append(_FINDER_COLUMN_N_H_P_PARENTTITLE_2);
12800                            }
12801    
12802                            String sql = query.toString();
12803    
12804                            Session session = null;
12805    
12806                            try {
12807                                    session = openSession();
12808    
12809                                    Query q = session.createQuery(sql);
12810    
12811                                    QueryPos qPos = QueryPos.getInstance(q);
12812    
12813                                    qPos.add(nodeId);
12814    
12815                                    qPos.add(head);
12816    
12817                                    if (bindParentTitle) {
12818                                            qPos.add(parentTitle.toLowerCase());
12819                                    }
12820    
12821                                    count = (Long)q.uniqueResult();
12822    
12823                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12824                            }
12825                            catch (Exception e) {
12826                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12827    
12828                                    throw processException(e);
12829                            }
12830                            finally {
12831                                    closeSession(session);
12832                            }
12833                    }
12834    
12835                    return count.intValue();
12836            }
12837    
12838            private static final String _FINDER_COLUMN_N_H_P_NODEID_2 = "wikiPage.nodeId = ? AND ";
12839            private static final String _FINDER_COLUMN_N_H_P_HEAD_2 = "wikiPage.head = ? AND ";
12840            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL";
12841            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ?";
12842            private static final String _FINDER_COLUMN_N_H_P_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '')";
12843            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12844                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
12845                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_R",
12846                            new String[] {
12847                                    Long.class.getName(), Boolean.class.getName(),
12848                                    String.class.getName(),
12849                                    
12850                            Integer.class.getName(), Integer.class.getName(),
12851                                    OrderByComparator.class.getName()
12852                            });
12853            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12854                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
12855                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_R",
12856                            new String[] {
12857                                    Long.class.getName(), Boolean.class.getName(),
12858                                    String.class.getName()
12859                            },
12860                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
12861                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
12862                            WikiPageModelImpl.REDIRECTTITLE_COLUMN_BITMASK |
12863                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
12864                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
12865            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_R = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
12866                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12867                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_R",
12868                            new String[] {
12869                                    Long.class.getName(), Boolean.class.getName(),
12870                                    String.class.getName()
12871                            });
12872    
12873            /**
12874             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63;.
12875             *
12876             * @param nodeId the node ID
12877             * @param head the head
12878             * @param redirectTitle the redirect title
12879             * @return the matching wiki pages
12880             * @throws SystemException if a system exception occurred
12881             */
12882            @Override
12883            public List<WikiPage> findByN_H_R(long nodeId, boolean head,
12884                    String redirectTitle) throws SystemException {
12885                    return findByN_H_R(nodeId, head, redirectTitle, QueryUtil.ALL_POS,
12886                            QueryUtil.ALL_POS, null);
12887            }
12888    
12889            /**
12890             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63;.
12891             *
12892             * <p>
12893             * 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.
12894             * </p>
12895             *
12896             * @param nodeId the node ID
12897             * @param head the head
12898             * @param redirectTitle the redirect title
12899             * @param start the lower bound of the range of wiki pages
12900             * @param end the upper bound of the range of wiki pages (not inclusive)
12901             * @return the range of matching wiki pages
12902             * @throws SystemException if a system exception occurred
12903             */
12904            @Override
12905            public List<WikiPage> findByN_H_R(long nodeId, boolean head,
12906                    String redirectTitle, int start, int end) throws SystemException {
12907                    return findByN_H_R(nodeId, head, redirectTitle, start, end, null);
12908            }
12909    
12910            /**
12911             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63;.
12912             *
12913             * <p>
12914             * 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.
12915             * </p>
12916             *
12917             * @param nodeId the node ID
12918             * @param head the head
12919             * @param redirectTitle the redirect title
12920             * @param start the lower bound of the range of wiki pages
12921             * @param end the upper bound of the range of wiki pages (not inclusive)
12922             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12923             * @return the ordered range of matching wiki pages
12924             * @throws SystemException if a system exception occurred
12925             */
12926            @Override
12927            public List<WikiPage> findByN_H_R(long nodeId, boolean head,
12928                    String redirectTitle, int start, int end,
12929                    OrderByComparator orderByComparator) throws SystemException {
12930                    boolean pagination = true;
12931                    FinderPath finderPath = null;
12932                    Object[] finderArgs = null;
12933    
12934                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12935                                    (orderByComparator == null)) {
12936                            pagination = false;
12937                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R;
12938                            finderArgs = new Object[] { nodeId, head, redirectTitle };
12939                    }
12940                    else {
12941                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_R;
12942                            finderArgs = new Object[] {
12943                                            nodeId, head, redirectTitle,
12944                                            
12945                                            start, end, orderByComparator
12946                                    };
12947                    }
12948    
12949                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
12950                                    finderArgs, this);
12951    
12952                    if ((list != null) && !list.isEmpty()) {
12953                            for (WikiPage wikiPage : list) {
12954                                    if ((nodeId != wikiPage.getNodeId()) ||
12955                                                    (head != wikiPage.getHead()) ||
12956                                                    !Validator.equals(redirectTitle,
12957                                                            wikiPage.getRedirectTitle())) {
12958                                            list = null;
12959    
12960                                            break;
12961                                    }
12962                            }
12963                    }
12964    
12965                    if (list == null) {
12966                            StringBundler query = null;
12967    
12968                            if (orderByComparator != null) {
12969                                    query = new StringBundler(5 +
12970                                                    (orderByComparator.getOrderByFields().length * 3));
12971                            }
12972                            else {
12973                                    query = new StringBundler(5);
12974                            }
12975    
12976                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
12977    
12978                            query.append(_FINDER_COLUMN_N_H_R_NODEID_2);
12979    
12980                            query.append(_FINDER_COLUMN_N_H_R_HEAD_2);
12981    
12982                            boolean bindRedirectTitle = false;
12983    
12984                            if (redirectTitle == null) {
12985                                    query.append(_FINDER_COLUMN_N_H_R_REDIRECTTITLE_1);
12986                            }
12987                            else if (redirectTitle.equals(StringPool.BLANK)) {
12988                                    query.append(_FINDER_COLUMN_N_H_R_REDIRECTTITLE_3);
12989                            }
12990                            else {
12991                                    bindRedirectTitle = true;
12992    
12993                                    query.append(_FINDER_COLUMN_N_H_R_REDIRECTTITLE_2);
12994                            }
12995    
12996                            if (orderByComparator != null) {
12997                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12998                                            orderByComparator);
12999                            }
13000                            else
13001                             if (pagination) {
13002                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13003                            }
13004    
13005                            String sql = query.toString();
13006    
13007                            Session session = null;
13008    
13009                            try {
13010                                    session = openSession();
13011    
13012                                    Query q = session.createQuery(sql);
13013    
13014                                    QueryPos qPos = QueryPos.getInstance(q);
13015    
13016                                    qPos.add(nodeId);
13017    
13018                                    qPos.add(head);
13019    
13020                                    if (bindRedirectTitle) {
13021                                            qPos.add(redirectTitle.toLowerCase());
13022                                    }
13023    
13024                                    if (!pagination) {
13025                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13026                                                            start, end, false);
13027    
13028                                            Collections.sort(list);
13029    
13030                                            list = new UnmodifiableList<WikiPage>(list);
13031                                    }
13032                                    else {
13033                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13034                                                            start, end);
13035                                    }
13036    
13037                                    cacheResult(list);
13038    
13039                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13040                            }
13041                            catch (Exception e) {
13042                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13043    
13044                                    throw processException(e);
13045                            }
13046                            finally {
13047                                    closeSession(session);
13048                            }
13049                    }
13050    
13051                    return list;
13052            }
13053    
13054            /**
13055             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63;.
13056             *
13057             * @param nodeId the node ID
13058             * @param head the head
13059             * @param redirectTitle the redirect title
13060             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13061             * @return the first matching wiki page
13062             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13063             * @throws SystemException if a system exception occurred
13064             */
13065            @Override
13066            public WikiPage findByN_H_R_First(long nodeId, boolean head,
13067                    String redirectTitle, OrderByComparator orderByComparator)
13068                    throws NoSuchPageException, SystemException {
13069                    WikiPage wikiPage = fetchByN_H_R_First(nodeId, head, redirectTitle,
13070                                    orderByComparator);
13071    
13072                    if (wikiPage != null) {
13073                            return wikiPage;
13074                    }
13075    
13076                    StringBundler msg = new StringBundler(8);
13077    
13078                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13079    
13080                    msg.append("nodeId=");
13081                    msg.append(nodeId);
13082    
13083                    msg.append(", head=");
13084                    msg.append(head);
13085    
13086                    msg.append(", redirectTitle=");
13087                    msg.append(redirectTitle);
13088    
13089                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13090    
13091                    throw new NoSuchPageException(msg.toString());
13092            }
13093    
13094            /**
13095             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63;.
13096             *
13097             * @param nodeId the node ID
13098             * @param head the head
13099             * @param redirectTitle the redirect title
13100             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13101             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
13102             * @throws SystemException if a system exception occurred
13103             */
13104            @Override
13105            public WikiPage fetchByN_H_R_First(long nodeId, boolean head,
13106                    String redirectTitle, OrderByComparator orderByComparator)
13107                    throws SystemException {
13108                    List<WikiPage> list = findByN_H_R(nodeId, head, redirectTitle, 0, 1,
13109                                    orderByComparator);
13110    
13111                    if (!list.isEmpty()) {
13112                            return list.get(0);
13113                    }
13114    
13115                    return null;
13116            }
13117    
13118            /**
13119             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63;.
13120             *
13121             * @param nodeId the node ID
13122             * @param head the head
13123             * @param redirectTitle the redirect title
13124             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13125             * @return the last matching wiki page
13126             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13127             * @throws SystemException if a system exception occurred
13128             */
13129            @Override
13130            public WikiPage findByN_H_R_Last(long nodeId, boolean head,
13131                    String redirectTitle, OrderByComparator orderByComparator)
13132                    throws NoSuchPageException, SystemException {
13133                    WikiPage wikiPage = fetchByN_H_R_Last(nodeId, head, redirectTitle,
13134                                    orderByComparator);
13135    
13136                    if (wikiPage != null) {
13137                            return wikiPage;
13138                    }
13139    
13140                    StringBundler msg = new StringBundler(8);
13141    
13142                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13143    
13144                    msg.append("nodeId=");
13145                    msg.append(nodeId);
13146    
13147                    msg.append(", head=");
13148                    msg.append(head);
13149    
13150                    msg.append(", redirectTitle=");
13151                    msg.append(redirectTitle);
13152    
13153                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13154    
13155                    throw new NoSuchPageException(msg.toString());
13156            }
13157    
13158            /**
13159             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63;.
13160             *
13161             * @param nodeId the node ID
13162             * @param head the head
13163             * @param redirectTitle the redirect title
13164             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13165             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
13166             * @throws SystemException if a system exception occurred
13167             */
13168            @Override
13169            public WikiPage fetchByN_H_R_Last(long nodeId, boolean head,
13170                    String redirectTitle, OrderByComparator orderByComparator)
13171                    throws SystemException {
13172                    int count = countByN_H_R(nodeId, head, redirectTitle);
13173    
13174                    if (count == 0) {
13175                            return null;
13176                    }
13177    
13178                    List<WikiPage> list = findByN_H_R(nodeId, head, redirectTitle,
13179                                    count - 1, count, orderByComparator);
13180    
13181                    if (!list.isEmpty()) {
13182                            return list.get(0);
13183                    }
13184    
13185                    return null;
13186            }
13187    
13188            /**
13189             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63;.
13190             *
13191             * @param pageId the primary key of the current wiki page
13192             * @param nodeId the node ID
13193             * @param head the head
13194             * @param redirectTitle the redirect title
13195             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13196             * @return the previous, current, and next wiki page
13197             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
13198             * @throws SystemException if a system exception occurred
13199             */
13200            @Override
13201            public WikiPage[] findByN_H_R_PrevAndNext(long pageId, long nodeId,
13202                    boolean head, String redirectTitle, OrderByComparator orderByComparator)
13203                    throws NoSuchPageException, SystemException {
13204                    WikiPage wikiPage = findByPrimaryKey(pageId);
13205    
13206                    Session session = null;
13207    
13208                    try {
13209                            session = openSession();
13210    
13211                            WikiPage[] array = new WikiPageImpl[3];
13212    
13213                            array[0] = getByN_H_R_PrevAndNext(session, wikiPage, nodeId, head,
13214                                            redirectTitle, orderByComparator, true);
13215    
13216                            array[1] = wikiPage;
13217    
13218                            array[2] = getByN_H_R_PrevAndNext(session, wikiPage, nodeId, head,
13219                                            redirectTitle, orderByComparator, false);
13220    
13221                            return array;
13222                    }
13223                    catch (Exception e) {
13224                            throw processException(e);
13225                    }
13226                    finally {
13227                            closeSession(session);
13228                    }
13229            }
13230    
13231            protected WikiPage getByN_H_R_PrevAndNext(Session session,
13232                    WikiPage wikiPage, long nodeId, boolean head, String redirectTitle,
13233                    OrderByComparator orderByComparator, boolean previous) {
13234                    StringBundler query = null;
13235    
13236                    if (orderByComparator != null) {
13237                            query = new StringBundler(6 +
13238                                            (orderByComparator.getOrderByFields().length * 6));
13239                    }
13240                    else {
13241                            query = new StringBundler(3);
13242                    }
13243    
13244                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13245    
13246                    query.append(_FINDER_COLUMN_N_H_R_NODEID_2);
13247    
13248                    query.append(_FINDER_COLUMN_N_H_R_HEAD_2);
13249    
13250                    boolean bindRedirectTitle = false;
13251    
13252                    if (redirectTitle == null) {
13253                            query.append(_FINDER_COLUMN_N_H_R_REDIRECTTITLE_1);
13254                    }
13255                    else if (redirectTitle.equals(StringPool.BLANK)) {
13256                            query.append(_FINDER_COLUMN_N_H_R_REDIRECTTITLE_3);
13257                    }
13258                    else {
13259                            bindRedirectTitle = true;
13260    
13261                            query.append(_FINDER_COLUMN_N_H_R_REDIRECTTITLE_2);
13262                    }
13263    
13264                    if (orderByComparator != null) {
13265                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13266    
13267                            if (orderByConditionFields.length > 0) {
13268                                    query.append(WHERE_AND);
13269                            }
13270    
13271                            for (int i = 0; i < orderByConditionFields.length; i++) {
13272                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13273                                    query.append(orderByConditionFields[i]);
13274    
13275                                    if ((i + 1) < orderByConditionFields.length) {
13276                                            if (orderByComparator.isAscending() ^ previous) {
13277                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13278                                            }
13279                                            else {
13280                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13281                                            }
13282                                    }
13283                                    else {
13284                                            if (orderByComparator.isAscending() ^ previous) {
13285                                                    query.append(WHERE_GREATER_THAN);
13286                                            }
13287                                            else {
13288                                                    query.append(WHERE_LESSER_THAN);
13289                                            }
13290                                    }
13291                            }
13292    
13293                            query.append(ORDER_BY_CLAUSE);
13294    
13295                            String[] orderByFields = orderByComparator.getOrderByFields();
13296    
13297                            for (int i = 0; i < orderByFields.length; i++) {
13298                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13299                                    query.append(orderByFields[i]);
13300    
13301                                    if ((i + 1) < orderByFields.length) {
13302                                            if (orderByComparator.isAscending() ^ previous) {
13303                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13304                                            }
13305                                            else {
13306                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13307                                            }
13308                                    }
13309                                    else {
13310                                            if (orderByComparator.isAscending() ^ previous) {
13311                                                    query.append(ORDER_BY_ASC);
13312                                            }
13313                                            else {
13314                                                    query.append(ORDER_BY_DESC);
13315                                            }
13316                                    }
13317                            }
13318                    }
13319                    else {
13320                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13321                    }
13322    
13323                    String sql = query.toString();
13324    
13325                    Query q = session.createQuery(sql);
13326    
13327                    q.setFirstResult(0);
13328                    q.setMaxResults(2);
13329    
13330                    QueryPos qPos = QueryPos.getInstance(q);
13331    
13332                    qPos.add(nodeId);
13333    
13334                    qPos.add(head);
13335    
13336                    if (bindRedirectTitle) {
13337                            qPos.add(redirectTitle.toLowerCase());
13338                    }
13339    
13340                    if (orderByComparator != null) {
13341                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
13342    
13343                            for (Object value : values) {
13344                                    qPos.add(value);
13345                            }
13346                    }
13347    
13348                    List<WikiPage> list = q.list();
13349    
13350                    if (list.size() == 2) {
13351                            return list.get(1);
13352                    }
13353                    else {
13354                            return null;
13355                    }
13356            }
13357    
13358            /**
13359             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; from the database.
13360             *
13361             * @param nodeId the node ID
13362             * @param head the head
13363             * @param redirectTitle the redirect title
13364             * @throws SystemException if a system exception occurred
13365             */
13366            @Override
13367            public void removeByN_H_R(long nodeId, boolean head, String redirectTitle)
13368                    throws SystemException {
13369                    for (WikiPage wikiPage : findByN_H_R(nodeId, head, redirectTitle,
13370                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13371                            remove(wikiPage);
13372                    }
13373            }
13374    
13375            /**
13376             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63;.
13377             *
13378             * @param nodeId the node ID
13379             * @param head the head
13380             * @param redirectTitle the redirect title
13381             * @return the number of matching wiki pages
13382             * @throws SystemException if a system exception occurred
13383             */
13384            @Override
13385            public int countByN_H_R(long nodeId, boolean head, String redirectTitle)
13386                    throws SystemException {
13387                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_R;
13388    
13389                    Object[] finderArgs = new Object[] { nodeId, head, redirectTitle };
13390    
13391                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13392                                    this);
13393    
13394                    if (count == null) {
13395                            StringBundler query = new StringBundler(4);
13396    
13397                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
13398    
13399                            query.append(_FINDER_COLUMN_N_H_R_NODEID_2);
13400    
13401                            query.append(_FINDER_COLUMN_N_H_R_HEAD_2);
13402    
13403                            boolean bindRedirectTitle = false;
13404    
13405                            if (redirectTitle == null) {
13406                                    query.append(_FINDER_COLUMN_N_H_R_REDIRECTTITLE_1);
13407                            }
13408                            else if (redirectTitle.equals(StringPool.BLANK)) {
13409                                    query.append(_FINDER_COLUMN_N_H_R_REDIRECTTITLE_3);
13410                            }
13411                            else {
13412                                    bindRedirectTitle = true;
13413    
13414                                    query.append(_FINDER_COLUMN_N_H_R_REDIRECTTITLE_2);
13415                            }
13416    
13417                            String sql = query.toString();
13418    
13419                            Session session = null;
13420    
13421                            try {
13422                                    session = openSession();
13423    
13424                                    Query q = session.createQuery(sql);
13425    
13426                                    QueryPos qPos = QueryPos.getInstance(q);
13427    
13428                                    qPos.add(nodeId);
13429    
13430                                    qPos.add(head);
13431    
13432                                    if (bindRedirectTitle) {
13433                                            qPos.add(redirectTitle.toLowerCase());
13434                                    }
13435    
13436                                    count = (Long)q.uniqueResult();
13437    
13438                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
13439                            }
13440                            catch (Exception e) {
13441                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13442    
13443                                    throw processException(e);
13444                            }
13445                            finally {
13446                                    closeSession(session);
13447                            }
13448                    }
13449    
13450                    return count.intValue();
13451            }
13452    
13453            private static final String _FINDER_COLUMN_N_H_R_NODEID_2 = "wikiPage.nodeId = ? AND ";
13454            private static final String _FINDER_COLUMN_N_H_R_HEAD_2 = "wikiPage.head = ? AND ";
13455            private static final String _FINDER_COLUMN_N_H_R_REDIRECTTITLE_1 = "wikiPage.redirectTitle IS NULL";
13456            private static final String _FINDER_COLUMN_N_H_R_REDIRECTTITLE_2 = "lower(wikiPage.redirectTitle) = ?";
13457            private static final String _FINDER_COLUMN_N_H_R_REDIRECTTITLE_3 = "(wikiPage.redirectTitle IS NULL OR wikiPage.redirectTitle = '')";
13458            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13459                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
13460                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_S",
13461                            new String[] {
13462                                    Long.class.getName(), Boolean.class.getName(),
13463                                    Integer.class.getName(),
13464                                    
13465                            Integer.class.getName(), Integer.class.getName(),
13466                                    OrderByComparator.class.getName()
13467                            });
13468            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13469                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
13470                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_S",
13471                            new String[] {
13472                                    Long.class.getName(), Boolean.class.getName(),
13473                                    Integer.class.getName()
13474                            },
13475                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
13476                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
13477                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
13478                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
13479                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
13480            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
13481                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13482                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_S",
13483                            new String[] {
13484                                    Long.class.getName(), Boolean.class.getName(),
13485                                    Integer.class.getName()
13486                            });
13487    
13488            /**
13489             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
13490             *
13491             * @param nodeId the node ID
13492             * @param head the head
13493             * @param status the status
13494             * @return the matching wiki pages
13495             * @throws SystemException if a system exception occurred
13496             */
13497            @Override
13498            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status)
13499                    throws SystemException {
13500                    return findByN_H_S(nodeId, head, status, QueryUtil.ALL_POS,
13501                            QueryUtil.ALL_POS, null);
13502            }
13503    
13504            /**
13505             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
13506             *
13507             * <p>
13508             * 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.
13509             * </p>
13510             *
13511             * @param nodeId the node ID
13512             * @param head the head
13513             * @param status the status
13514             * @param start the lower bound of the range of wiki pages
13515             * @param end the upper bound of the range of wiki pages (not inclusive)
13516             * @return the range of matching wiki pages
13517             * @throws SystemException if a system exception occurred
13518             */
13519            @Override
13520            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status,
13521                    int start, int end) throws SystemException {
13522                    return findByN_H_S(nodeId, head, status, start, end, null);
13523            }
13524    
13525            /**
13526             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
13527             *
13528             * <p>
13529             * 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.
13530             * </p>
13531             *
13532             * @param nodeId the node ID
13533             * @param head the head
13534             * @param status the status
13535             * @param start the lower bound of the range of wiki pages
13536             * @param end the upper bound of the range of wiki pages (not inclusive)
13537             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13538             * @return the ordered range of matching wiki pages
13539             * @throws SystemException if a system exception occurred
13540             */
13541            @Override
13542            public List<WikiPage> findByN_H_S(long nodeId, boolean head, int status,
13543                    int start, int end, OrderByComparator orderByComparator)
13544                    throws SystemException {
13545                    boolean pagination = true;
13546                    FinderPath finderPath = null;
13547                    Object[] finderArgs = null;
13548    
13549                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13550                                    (orderByComparator == null)) {
13551                            pagination = false;
13552                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S;
13553                            finderArgs = new Object[] { nodeId, head, status };
13554                    }
13555                    else {
13556                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_S;
13557                            finderArgs = new Object[] {
13558                                            nodeId, head, status,
13559                                            
13560                                            start, end, orderByComparator
13561                                    };
13562                    }
13563    
13564                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
13565                                    finderArgs, this);
13566    
13567                    if ((list != null) && !list.isEmpty()) {
13568                            for (WikiPage wikiPage : list) {
13569                                    if ((nodeId != wikiPage.getNodeId()) ||
13570                                                    (head != wikiPage.getHead()) ||
13571                                                    (status != wikiPage.getStatus())) {
13572                                            list = null;
13573    
13574                                            break;
13575                                    }
13576                            }
13577                    }
13578    
13579                    if (list == null) {
13580                            StringBundler query = null;
13581    
13582                            if (orderByComparator != null) {
13583                                    query = new StringBundler(5 +
13584                                                    (orderByComparator.getOrderByFields().length * 3));
13585                            }
13586                            else {
13587                                    query = new StringBundler(5);
13588                            }
13589    
13590                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13591    
13592                            query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
13593    
13594                            query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
13595    
13596                            query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
13597    
13598                            if (orderByComparator != null) {
13599                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13600                                            orderByComparator);
13601                            }
13602                            else
13603                             if (pagination) {
13604                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13605                            }
13606    
13607                            String sql = query.toString();
13608    
13609                            Session session = null;
13610    
13611                            try {
13612                                    session = openSession();
13613    
13614                                    Query q = session.createQuery(sql);
13615    
13616                                    QueryPos qPos = QueryPos.getInstance(q);
13617    
13618                                    qPos.add(nodeId);
13619    
13620                                    qPos.add(head);
13621    
13622                                    qPos.add(status);
13623    
13624                                    if (!pagination) {
13625                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13626                                                            start, end, false);
13627    
13628                                            Collections.sort(list);
13629    
13630                                            list = new UnmodifiableList<WikiPage>(list);
13631                                    }
13632                                    else {
13633                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
13634                                                            start, end);
13635                                    }
13636    
13637                                    cacheResult(list);
13638    
13639                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13640                            }
13641                            catch (Exception e) {
13642                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13643    
13644                                    throw processException(e);
13645                            }
13646                            finally {
13647                                    closeSession(session);
13648                            }
13649                    }
13650    
13651                    return list;
13652            }
13653    
13654            /**
13655             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
13656             *
13657             * @param nodeId the node ID
13658             * @param head the head
13659             * @param status the status
13660             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13661             * @return the first matching wiki page
13662             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13663             * @throws SystemException if a system exception occurred
13664             */
13665            @Override
13666            public WikiPage findByN_H_S_First(long nodeId, boolean head, int status,
13667                    OrderByComparator orderByComparator)
13668                    throws NoSuchPageException, SystemException {
13669                    WikiPage wikiPage = fetchByN_H_S_First(nodeId, head, status,
13670                                    orderByComparator);
13671    
13672                    if (wikiPage != null) {
13673                            return wikiPage;
13674                    }
13675    
13676                    StringBundler msg = new StringBundler(8);
13677    
13678                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13679    
13680                    msg.append("nodeId=");
13681                    msg.append(nodeId);
13682    
13683                    msg.append(", head=");
13684                    msg.append(head);
13685    
13686                    msg.append(", status=");
13687                    msg.append(status);
13688    
13689                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13690    
13691                    throw new NoSuchPageException(msg.toString());
13692            }
13693    
13694            /**
13695             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
13696             *
13697             * @param nodeId the node ID
13698             * @param head the head
13699             * @param status the status
13700             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13701             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
13702             * @throws SystemException if a system exception occurred
13703             */
13704            @Override
13705            public WikiPage fetchByN_H_S_First(long nodeId, boolean head, int status,
13706                    OrderByComparator orderByComparator) throws SystemException {
13707                    List<WikiPage> list = findByN_H_S(nodeId, head, status, 0, 1,
13708                                    orderByComparator);
13709    
13710                    if (!list.isEmpty()) {
13711                            return list.get(0);
13712                    }
13713    
13714                    return null;
13715            }
13716    
13717            /**
13718             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
13719             *
13720             * @param nodeId the node ID
13721             * @param head the head
13722             * @param status the status
13723             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13724             * @return the last matching wiki page
13725             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
13726             * @throws SystemException if a system exception occurred
13727             */
13728            @Override
13729            public WikiPage findByN_H_S_Last(long nodeId, boolean head, int status,
13730                    OrderByComparator orderByComparator)
13731                    throws NoSuchPageException, SystemException {
13732                    WikiPage wikiPage = fetchByN_H_S_Last(nodeId, head, status,
13733                                    orderByComparator);
13734    
13735                    if (wikiPage != null) {
13736                            return wikiPage;
13737                    }
13738    
13739                    StringBundler msg = new StringBundler(8);
13740    
13741                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13742    
13743                    msg.append("nodeId=");
13744                    msg.append(nodeId);
13745    
13746                    msg.append(", head=");
13747                    msg.append(head);
13748    
13749                    msg.append(", status=");
13750                    msg.append(status);
13751    
13752                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13753    
13754                    throw new NoSuchPageException(msg.toString());
13755            }
13756    
13757            /**
13758             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
13759             *
13760             * @param nodeId the node ID
13761             * @param head the head
13762             * @param status the status
13763             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13764             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
13765             * @throws SystemException if a system exception occurred
13766             */
13767            @Override
13768            public WikiPage fetchByN_H_S_Last(long nodeId, boolean head, int status,
13769                    OrderByComparator orderByComparator) throws SystemException {
13770                    int count = countByN_H_S(nodeId, head, status);
13771    
13772                    if (count == 0) {
13773                            return null;
13774                    }
13775    
13776                    List<WikiPage> list = findByN_H_S(nodeId, head, status, count - 1,
13777                                    count, orderByComparator);
13778    
13779                    if (!list.isEmpty()) {
13780                            return list.get(0);
13781                    }
13782    
13783                    return null;
13784            }
13785    
13786            /**
13787             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and status = &#63;.
13788             *
13789             * @param pageId the primary key of the current wiki page
13790             * @param nodeId the node ID
13791             * @param head the head
13792             * @param status the status
13793             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13794             * @return the previous, current, and next wiki page
13795             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
13796             * @throws SystemException if a system exception occurred
13797             */
13798            @Override
13799            public WikiPage[] findByN_H_S_PrevAndNext(long pageId, long nodeId,
13800                    boolean head, int status, OrderByComparator orderByComparator)
13801                    throws NoSuchPageException, SystemException {
13802                    WikiPage wikiPage = findByPrimaryKey(pageId);
13803    
13804                    Session session = null;
13805    
13806                    try {
13807                            session = openSession();
13808    
13809                            WikiPage[] array = new WikiPageImpl[3];
13810    
13811                            array[0] = getByN_H_S_PrevAndNext(session, wikiPage, nodeId, head,
13812                                            status, orderByComparator, true);
13813    
13814                            array[1] = wikiPage;
13815    
13816                            array[2] = getByN_H_S_PrevAndNext(session, wikiPage, nodeId, head,
13817                                            status, orderByComparator, false);
13818    
13819                            return array;
13820                    }
13821                    catch (Exception e) {
13822                            throw processException(e);
13823                    }
13824                    finally {
13825                            closeSession(session);
13826                    }
13827            }
13828    
13829            protected WikiPage getByN_H_S_PrevAndNext(Session session,
13830                    WikiPage wikiPage, long nodeId, boolean head, int status,
13831                    OrderByComparator orderByComparator, boolean previous) {
13832                    StringBundler query = null;
13833    
13834                    if (orderByComparator != null) {
13835                            query = new StringBundler(6 +
13836                                            (orderByComparator.getOrderByFields().length * 6));
13837                    }
13838                    else {
13839                            query = new StringBundler(3);
13840                    }
13841    
13842                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
13843    
13844                    query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
13845    
13846                    query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
13847    
13848                    query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
13849    
13850                    if (orderByComparator != null) {
13851                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13852    
13853                            if (orderByConditionFields.length > 0) {
13854                                    query.append(WHERE_AND);
13855                            }
13856    
13857                            for (int i = 0; i < orderByConditionFields.length; i++) {
13858                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13859                                    query.append(orderByConditionFields[i]);
13860    
13861                                    if ((i + 1) < orderByConditionFields.length) {
13862                                            if (orderByComparator.isAscending() ^ previous) {
13863                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13864                                            }
13865                                            else {
13866                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13867                                            }
13868                                    }
13869                                    else {
13870                                            if (orderByComparator.isAscending() ^ previous) {
13871                                                    query.append(WHERE_GREATER_THAN);
13872                                            }
13873                                            else {
13874                                                    query.append(WHERE_LESSER_THAN);
13875                                            }
13876                                    }
13877                            }
13878    
13879                            query.append(ORDER_BY_CLAUSE);
13880    
13881                            String[] orderByFields = orderByComparator.getOrderByFields();
13882    
13883                            for (int i = 0; i < orderByFields.length; i++) {
13884                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13885                                    query.append(orderByFields[i]);
13886    
13887                                    if ((i + 1) < orderByFields.length) {
13888                                            if (orderByComparator.isAscending() ^ previous) {
13889                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13890                                            }
13891                                            else {
13892                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13893                                            }
13894                                    }
13895                                    else {
13896                                            if (orderByComparator.isAscending() ^ previous) {
13897                                                    query.append(ORDER_BY_ASC);
13898                                            }
13899                                            else {
13900                                                    query.append(ORDER_BY_DESC);
13901                                            }
13902                                    }
13903                            }
13904                    }
13905                    else {
13906                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
13907                    }
13908    
13909                    String sql = query.toString();
13910    
13911                    Query q = session.createQuery(sql);
13912    
13913                    q.setFirstResult(0);
13914                    q.setMaxResults(2);
13915    
13916                    QueryPos qPos = QueryPos.getInstance(q);
13917    
13918                    qPos.add(nodeId);
13919    
13920                    qPos.add(head);
13921    
13922                    qPos.add(status);
13923    
13924                    if (orderByComparator != null) {
13925                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
13926    
13927                            for (Object value : values) {
13928                                    qPos.add(value);
13929                            }
13930                    }
13931    
13932                    List<WikiPage> list = q.list();
13933    
13934                    if (list.size() == 2) {
13935                            return list.get(1);
13936                    }
13937                    else {
13938                            return null;
13939                    }
13940            }
13941    
13942            /**
13943             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and status = &#63; from the database.
13944             *
13945             * @param nodeId the node ID
13946             * @param head the head
13947             * @param status the status
13948             * @throws SystemException if a system exception occurred
13949             */
13950            @Override
13951            public void removeByN_H_S(long nodeId, boolean head, int status)
13952                    throws SystemException {
13953                    for (WikiPage wikiPage : findByN_H_S(nodeId, head, status,
13954                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13955                            remove(wikiPage);
13956                    }
13957            }
13958    
13959            /**
13960             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and status = &#63;.
13961             *
13962             * @param nodeId the node ID
13963             * @param head the head
13964             * @param status the status
13965             * @return the number of matching wiki pages
13966             * @throws SystemException if a system exception occurred
13967             */
13968            @Override
13969            public int countByN_H_S(long nodeId, boolean head, int status)
13970                    throws SystemException {
13971                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_S;
13972    
13973                    Object[] finderArgs = new Object[] { nodeId, head, status };
13974    
13975                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13976                                    this);
13977    
13978                    if (count == null) {
13979                            StringBundler query = new StringBundler(4);
13980    
13981                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
13982    
13983                            query.append(_FINDER_COLUMN_N_H_S_NODEID_2);
13984    
13985                            query.append(_FINDER_COLUMN_N_H_S_HEAD_2);
13986    
13987                            query.append(_FINDER_COLUMN_N_H_S_STATUS_2);
13988    
13989                            String sql = query.toString();
13990    
13991                            Session session = null;
13992    
13993                            try {
13994                                    session = openSession();
13995    
13996                                    Query q = session.createQuery(sql);
13997    
13998                                    QueryPos qPos = QueryPos.getInstance(q);
13999    
14000                                    qPos.add(nodeId);
14001    
14002                                    qPos.add(head);
14003    
14004                                    qPos.add(status);
14005    
14006                                    count = (Long)q.uniqueResult();
14007    
14008                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14009                            }
14010                            catch (Exception e) {
14011                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14012    
14013                                    throw processException(e);
14014                            }
14015                            finally {
14016                                    closeSession(session);
14017                            }
14018                    }
14019    
14020                    return count.intValue();
14021            }
14022    
14023            private static final String _FINDER_COLUMN_N_H_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
14024            private static final String _FINDER_COLUMN_N_H_S_HEAD_2 = "wikiPage.head = ? AND ";
14025            private static final String _FINDER_COLUMN_N_H_S_STATUS_2 = "wikiPage.status = ?";
14026            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_NOTS = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14027                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
14028                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_NotS",
14029                            new String[] {
14030                                    Long.class.getName(), Boolean.class.getName(),
14031                                    Integer.class.getName(),
14032                                    
14033                            Integer.class.getName(), Integer.class.getName(),
14034                                    OrderByComparator.class.getName()
14035                            });
14036            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_N_H_NOTS =
14037                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14038                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14039                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByN_H_NotS",
14040                            new String[] {
14041                                    Long.class.getName(), Boolean.class.getName(),
14042                                    Integer.class.getName()
14043                            });
14044    
14045            /**
14046             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and status &ne; &#63;.
14047             *
14048             * @param nodeId the node ID
14049             * @param head the head
14050             * @param status the status
14051             * @return the matching wiki pages
14052             * @throws SystemException if a system exception occurred
14053             */
14054            @Override
14055            public List<WikiPage> findByN_H_NotS(long nodeId, boolean head, int status)
14056                    throws SystemException {
14057                    return findByN_H_NotS(nodeId, head, status, QueryUtil.ALL_POS,
14058                            QueryUtil.ALL_POS, null);
14059            }
14060    
14061            /**
14062             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and status &ne; &#63;.
14063             *
14064             * <p>
14065             * 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.
14066             * </p>
14067             *
14068             * @param nodeId the node ID
14069             * @param head the head
14070             * @param status the status
14071             * @param start the lower bound of the range of wiki pages
14072             * @param end the upper bound of the range of wiki pages (not inclusive)
14073             * @return the range of matching wiki pages
14074             * @throws SystemException if a system exception occurred
14075             */
14076            @Override
14077            public List<WikiPage> findByN_H_NotS(long nodeId, boolean head, int status,
14078                    int start, int end) throws SystemException {
14079                    return findByN_H_NotS(nodeId, head, status, start, end, null);
14080            }
14081    
14082            /**
14083             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and status &ne; &#63;.
14084             *
14085             * <p>
14086             * 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.
14087             * </p>
14088             *
14089             * @param nodeId the node ID
14090             * @param head the head
14091             * @param status the status
14092             * @param start the lower bound of the range of wiki pages
14093             * @param end the upper bound of the range of wiki pages (not inclusive)
14094             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14095             * @return the ordered range of matching wiki pages
14096             * @throws SystemException if a system exception occurred
14097             */
14098            @Override
14099            public List<WikiPage> findByN_H_NotS(long nodeId, boolean head, int status,
14100                    int start, int end, OrderByComparator orderByComparator)
14101                    throws SystemException {
14102                    boolean pagination = true;
14103                    FinderPath finderPath = null;
14104                    Object[] finderArgs = null;
14105    
14106                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_NOTS;
14107                    finderArgs = new Object[] {
14108                                    nodeId, head, status,
14109                                    
14110                                    start, end, orderByComparator
14111                            };
14112    
14113                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
14114                                    finderArgs, this);
14115    
14116                    if ((list != null) && !list.isEmpty()) {
14117                            for (WikiPage wikiPage : list) {
14118                                    if ((nodeId != wikiPage.getNodeId()) ||
14119                                                    (head != wikiPage.getHead()) ||
14120                                                    (status == wikiPage.getStatus())) {
14121                                            list = null;
14122    
14123                                            break;
14124                                    }
14125                            }
14126                    }
14127    
14128                    if (list == null) {
14129                            StringBundler query = null;
14130    
14131                            if (orderByComparator != null) {
14132                                    query = new StringBundler(5 +
14133                                                    (orderByComparator.getOrderByFields().length * 3));
14134                            }
14135                            else {
14136                                    query = new StringBundler(5);
14137                            }
14138    
14139                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14140    
14141                            query.append(_FINDER_COLUMN_N_H_NOTS_NODEID_2);
14142    
14143                            query.append(_FINDER_COLUMN_N_H_NOTS_HEAD_2);
14144    
14145                            query.append(_FINDER_COLUMN_N_H_NOTS_STATUS_2);
14146    
14147                            if (orderByComparator != null) {
14148                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14149                                            orderByComparator);
14150                            }
14151                            else
14152                             if (pagination) {
14153                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14154                            }
14155    
14156                            String sql = query.toString();
14157    
14158                            Session session = null;
14159    
14160                            try {
14161                                    session = openSession();
14162    
14163                                    Query q = session.createQuery(sql);
14164    
14165                                    QueryPos qPos = QueryPos.getInstance(q);
14166    
14167                                    qPos.add(nodeId);
14168    
14169                                    qPos.add(head);
14170    
14171                                    qPos.add(status);
14172    
14173                                    if (!pagination) {
14174                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14175                                                            start, end, false);
14176    
14177                                            Collections.sort(list);
14178    
14179                                            list = new UnmodifiableList<WikiPage>(list);
14180                                    }
14181                                    else {
14182                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14183                                                            start, end);
14184                                    }
14185    
14186                                    cacheResult(list);
14187    
14188                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14189                            }
14190                            catch (Exception e) {
14191                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14192    
14193                                    throw processException(e);
14194                            }
14195                            finally {
14196                                    closeSession(session);
14197                            }
14198                    }
14199    
14200                    return list;
14201            }
14202    
14203            /**
14204             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status &ne; &#63;.
14205             *
14206             * @param nodeId the node ID
14207             * @param head the head
14208             * @param status the status
14209             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14210             * @return the first matching wiki page
14211             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14212             * @throws SystemException if a system exception occurred
14213             */
14214            @Override
14215            public WikiPage findByN_H_NotS_First(long nodeId, boolean head, int status,
14216                    OrderByComparator orderByComparator)
14217                    throws NoSuchPageException, SystemException {
14218                    WikiPage wikiPage = fetchByN_H_NotS_First(nodeId, head, status,
14219                                    orderByComparator);
14220    
14221                    if (wikiPage != null) {
14222                            return wikiPage;
14223                    }
14224    
14225                    StringBundler msg = new StringBundler(8);
14226    
14227                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14228    
14229                    msg.append("nodeId=");
14230                    msg.append(nodeId);
14231    
14232                    msg.append(", head=");
14233                    msg.append(head);
14234    
14235                    msg.append(", status=");
14236                    msg.append(status);
14237    
14238                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14239    
14240                    throw new NoSuchPageException(msg.toString());
14241            }
14242    
14243            /**
14244             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and status &ne; &#63;.
14245             *
14246             * @param nodeId the node ID
14247             * @param head the head
14248             * @param status the status
14249             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14250             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
14251             * @throws SystemException if a system exception occurred
14252             */
14253            @Override
14254            public WikiPage fetchByN_H_NotS_First(long nodeId, boolean head,
14255                    int status, OrderByComparator orderByComparator)
14256                    throws SystemException {
14257                    List<WikiPage> list = findByN_H_NotS(nodeId, head, status, 0, 1,
14258                                    orderByComparator);
14259    
14260                    if (!list.isEmpty()) {
14261                            return list.get(0);
14262                    }
14263    
14264                    return null;
14265            }
14266    
14267            /**
14268             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status &ne; &#63;.
14269             *
14270             * @param nodeId the node ID
14271             * @param head the head
14272             * @param status the status
14273             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14274             * @return the last matching wiki page
14275             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14276             * @throws SystemException if a system exception occurred
14277             */
14278            @Override
14279            public WikiPage findByN_H_NotS_Last(long nodeId, boolean head, int status,
14280                    OrderByComparator orderByComparator)
14281                    throws NoSuchPageException, SystemException {
14282                    WikiPage wikiPage = fetchByN_H_NotS_Last(nodeId, head, status,
14283                                    orderByComparator);
14284    
14285                    if (wikiPage != null) {
14286                            return wikiPage;
14287                    }
14288    
14289                    StringBundler msg = new StringBundler(8);
14290    
14291                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14292    
14293                    msg.append("nodeId=");
14294                    msg.append(nodeId);
14295    
14296                    msg.append(", head=");
14297                    msg.append(head);
14298    
14299                    msg.append(", status=");
14300                    msg.append(status);
14301    
14302                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14303    
14304                    throw new NoSuchPageException(msg.toString());
14305            }
14306    
14307            /**
14308             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and status &ne; &#63;.
14309             *
14310             * @param nodeId the node ID
14311             * @param head the head
14312             * @param status the status
14313             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14314             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
14315             * @throws SystemException if a system exception occurred
14316             */
14317            @Override
14318            public WikiPage fetchByN_H_NotS_Last(long nodeId, boolean head, int status,
14319                    OrderByComparator orderByComparator) throws SystemException {
14320                    int count = countByN_H_NotS(nodeId, head, status);
14321    
14322                    if (count == 0) {
14323                            return null;
14324                    }
14325    
14326                    List<WikiPage> list = findByN_H_NotS(nodeId, head, status, count - 1,
14327                                    count, orderByComparator);
14328    
14329                    if (!list.isEmpty()) {
14330                            return list.get(0);
14331                    }
14332    
14333                    return null;
14334            }
14335    
14336            /**
14337             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and status &ne; &#63;.
14338             *
14339             * @param pageId the primary key of the current wiki page
14340             * @param nodeId the node ID
14341             * @param head the head
14342             * @param status the status
14343             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14344             * @return the previous, current, and next wiki page
14345             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
14346             * @throws SystemException if a system exception occurred
14347             */
14348            @Override
14349            public WikiPage[] findByN_H_NotS_PrevAndNext(long pageId, long nodeId,
14350                    boolean head, int status, OrderByComparator orderByComparator)
14351                    throws NoSuchPageException, SystemException {
14352                    WikiPage wikiPage = findByPrimaryKey(pageId);
14353    
14354                    Session session = null;
14355    
14356                    try {
14357                            session = openSession();
14358    
14359                            WikiPage[] array = new WikiPageImpl[3];
14360    
14361                            array[0] = getByN_H_NotS_PrevAndNext(session, wikiPage, nodeId,
14362                                            head, status, orderByComparator, true);
14363    
14364                            array[1] = wikiPage;
14365    
14366                            array[2] = getByN_H_NotS_PrevAndNext(session, wikiPage, nodeId,
14367                                            head, status, orderByComparator, false);
14368    
14369                            return array;
14370                    }
14371                    catch (Exception e) {
14372                            throw processException(e);
14373                    }
14374                    finally {
14375                            closeSession(session);
14376                    }
14377            }
14378    
14379            protected WikiPage getByN_H_NotS_PrevAndNext(Session session,
14380                    WikiPage wikiPage, long nodeId, boolean head, int status,
14381                    OrderByComparator orderByComparator, boolean previous) {
14382                    StringBundler query = null;
14383    
14384                    if (orderByComparator != null) {
14385                            query = new StringBundler(6 +
14386                                            (orderByComparator.getOrderByFields().length * 6));
14387                    }
14388                    else {
14389                            query = new StringBundler(3);
14390                    }
14391    
14392                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14393    
14394                    query.append(_FINDER_COLUMN_N_H_NOTS_NODEID_2);
14395    
14396                    query.append(_FINDER_COLUMN_N_H_NOTS_HEAD_2);
14397    
14398                    query.append(_FINDER_COLUMN_N_H_NOTS_STATUS_2);
14399    
14400                    if (orderByComparator != null) {
14401                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14402    
14403                            if (orderByConditionFields.length > 0) {
14404                                    query.append(WHERE_AND);
14405                            }
14406    
14407                            for (int i = 0; i < orderByConditionFields.length; i++) {
14408                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14409                                    query.append(orderByConditionFields[i]);
14410    
14411                                    if ((i + 1) < orderByConditionFields.length) {
14412                                            if (orderByComparator.isAscending() ^ previous) {
14413                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14414                                            }
14415                                            else {
14416                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14417                                            }
14418                                    }
14419                                    else {
14420                                            if (orderByComparator.isAscending() ^ previous) {
14421                                                    query.append(WHERE_GREATER_THAN);
14422                                            }
14423                                            else {
14424                                                    query.append(WHERE_LESSER_THAN);
14425                                            }
14426                                    }
14427                            }
14428    
14429                            query.append(ORDER_BY_CLAUSE);
14430    
14431                            String[] orderByFields = orderByComparator.getOrderByFields();
14432    
14433                            for (int i = 0; i < orderByFields.length; i++) {
14434                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14435                                    query.append(orderByFields[i]);
14436    
14437                                    if ((i + 1) < orderByFields.length) {
14438                                            if (orderByComparator.isAscending() ^ previous) {
14439                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14440                                            }
14441                                            else {
14442                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14443                                            }
14444                                    }
14445                                    else {
14446                                            if (orderByComparator.isAscending() ^ previous) {
14447                                                    query.append(ORDER_BY_ASC);
14448                                            }
14449                                            else {
14450                                                    query.append(ORDER_BY_DESC);
14451                                            }
14452                                    }
14453                            }
14454                    }
14455                    else {
14456                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14457                    }
14458    
14459                    String sql = query.toString();
14460    
14461                    Query q = session.createQuery(sql);
14462    
14463                    q.setFirstResult(0);
14464                    q.setMaxResults(2);
14465    
14466                    QueryPos qPos = QueryPos.getInstance(q);
14467    
14468                    qPos.add(nodeId);
14469    
14470                    qPos.add(head);
14471    
14472                    qPos.add(status);
14473    
14474                    if (orderByComparator != null) {
14475                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
14476    
14477                            for (Object value : values) {
14478                                    qPos.add(value);
14479                            }
14480                    }
14481    
14482                    List<WikiPage> list = q.list();
14483    
14484                    if (list.size() == 2) {
14485                            return list.get(1);
14486                    }
14487                    else {
14488                            return null;
14489                    }
14490            }
14491    
14492            /**
14493             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and status &ne; &#63; from the database.
14494             *
14495             * @param nodeId the node ID
14496             * @param head the head
14497             * @param status the status
14498             * @throws SystemException if a system exception occurred
14499             */
14500            @Override
14501            public void removeByN_H_NotS(long nodeId, boolean head, int status)
14502                    throws SystemException {
14503                    for (WikiPage wikiPage : findByN_H_NotS(nodeId, head, status,
14504                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14505                            remove(wikiPage);
14506                    }
14507            }
14508    
14509            /**
14510             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and status &ne; &#63;.
14511             *
14512             * @param nodeId the node ID
14513             * @param head the head
14514             * @param status the status
14515             * @return the number of matching wiki pages
14516             * @throws SystemException if a system exception occurred
14517             */
14518            @Override
14519            public int countByN_H_NotS(long nodeId, boolean head, int status)
14520                    throws SystemException {
14521                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_N_H_NOTS;
14522    
14523                    Object[] finderArgs = new Object[] { nodeId, head, status };
14524    
14525                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14526                                    this);
14527    
14528                    if (count == null) {
14529                            StringBundler query = new StringBundler(4);
14530    
14531                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
14532    
14533                            query.append(_FINDER_COLUMN_N_H_NOTS_NODEID_2);
14534    
14535                            query.append(_FINDER_COLUMN_N_H_NOTS_HEAD_2);
14536    
14537                            query.append(_FINDER_COLUMN_N_H_NOTS_STATUS_2);
14538    
14539                            String sql = query.toString();
14540    
14541                            Session session = null;
14542    
14543                            try {
14544                                    session = openSession();
14545    
14546                                    Query q = session.createQuery(sql);
14547    
14548                                    QueryPos qPos = QueryPos.getInstance(q);
14549    
14550                                    qPos.add(nodeId);
14551    
14552                                    qPos.add(head);
14553    
14554                                    qPos.add(status);
14555    
14556                                    count = (Long)q.uniqueResult();
14557    
14558                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14559                            }
14560                            catch (Exception e) {
14561                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14562    
14563                                    throw processException(e);
14564                            }
14565                            finally {
14566                                    closeSession(session);
14567                            }
14568                    }
14569    
14570                    return count.intValue();
14571            }
14572    
14573            private static final String _FINDER_COLUMN_N_H_NOTS_NODEID_2 = "wikiPage.nodeId = ? AND ";
14574            private static final String _FINDER_COLUMN_N_H_NOTS_HEAD_2 = "wikiPage.head = ? AND ";
14575            private static final String _FINDER_COLUMN_N_H_NOTS_STATUS_2 = "wikiPage.status != ?";
14576            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14577                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
14578                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_N_S",
14579                            new String[] {
14580                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
14581                                    Integer.class.getName(),
14582                                    
14583                            Integer.class.getName(), Integer.class.getName(),
14584                                    OrderByComparator.class.getName()
14585                            });
14586            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S =
14587                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14588                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
14589                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_N_S",
14590                            new String[] {
14591                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
14592                                    Integer.class.getName()
14593                            },
14594                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
14595                            WikiPageModelImpl.USERID_COLUMN_BITMASK |
14596                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
14597                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
14598                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
14599                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
14600            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_N_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
14601                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14602                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_N_S",
14603                            new String[] {
14604                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
14605                                    Integer.class.getName()
14606                            });
14607    
14608            /**
14609             * Returns all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14610             *
14611             * @param groupId the group ID
14612             * @param userId the user ID
14613             * @param nodeId the node ID
14614             * @param status the status
14615             * @return the matching wiki pages
14616             * @throws SystemException if a system exception occurred
14617             */
14618            @Override
14619            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
14620                    int status) throws SystemException {
14621                    return findByG_U_N_S(groupId, userId, nodeId, status,
14622                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14623            }
14624    
14625            /**
14626             * Returns a range of all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14627             *
14628             * <p>
14629             * 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.
14630             * </p>
14631             *
14632             * @param groupId the group ID
14633             * @param userId the user ID
14634             * @param nodeId the node ID
14635             * @param status the status
14636             * @param start the lower bound of the range of wiki pages
14637             * @param end the upper bound of the range of wiki pages (not inclusive)
14638             * @return the range of matching wiki pages
14639             * @throws SystemException if a system exception occurred
14640             */
14641            @Override
14642            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
14643                    int status, int start, int end) throws SystemException {
14644                    return findByG_U_N_S(groupId, userId, nodeId, status, start, end, null);
14645            }
14646    
14647            /**
14648             * Returns an ordered range of all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14649             *
14650             * <p>
14651             * 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.
14652             * </p>
14653             *
14654             * @param groupId the group ID
14655             * @param userId the user ID
14656             * @param nodeId the node ID
14657             * @param status the status
14658             * @param start the lower bound of the range of wiki pages
14659             * @param end the upper bound of the range of wiki pages (not inclusive)
14660             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14661             * @return the ordered range of matching wiki pages
14662             * @throws SystemException if a system exception occurred
14663             */
14664            @Override
14665            public List<WikiPage> findByG_U_N_S(long groupId, long userId, long nodeId,
14666                    int status, int start, int end, OrderByComparator orderByComparator)
14667                    throws SystemException {
14668                    boolean pagination = true;
14669                    FinderPath finderPath = null;
14670                    Object[] finderArgs = null;
14671    
14672                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14673                                    (orderByComparator == null)) {
14674                            pagination = false;
14675                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S;
14676                            finderArgs = new Object[] { groupId, userId, nodeId, status };
14677                    }
14678                    else {
14679                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_N_S;
14680                            finderArgs = new Object[] {
14681                                            groupId, userId, nodeId, status,
14682                                            
14683                                            start, end, orderByComparator
14684                                    };
14685                    }
14686    
14687                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
14688                                    finderArgs, this);
14689    
14690                    if ((list != null) && !list.isEmpty()) {
14691                            for (WikiPage wikiPage : list) {
14692                                    if ((groupId != wikiPage.getGroupId()) ||
14693                                                    (userId != wikiPage.getUserId()) ||
14694                                                    (nodeId != wikiPage.getNodeId()) ||
14695                                                    (status != wikiPage.getStatus())) {
14696                                            list = null;
14697    
14698                                            break;
14699                                    }
14700                            }
14701                    }
14702    
14703                    if (list == null) {
14704                            StringBundler query = null;
14705    
14706                            if (orderByComparator != null) {
14707                                    query = new StringBundler(6 +
14708                                                    (orderByComparator.getOrderByFields().length * 3));
14709                            }
14710                            else {
14711                                    query = new StringBundler(6);
14712                            }
14713    
14714                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14715    
14716                            query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
14717    
14718                            query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
14719    
14720                            query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
14721    
14722                            query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
14723    
14724                            if (orderByComparator != null) {
14725                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14726                                            orderByComparator);
14727                            }
14728                            else
14729                             if (pagination) {
14730                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
14731                            }
14732    
14733                            String sql = query.toString();
14734    
14735                            Session session = null;
14736    
14737                            try {
14738                                    session = openSession();
14739    
14740                                    Query q = session.createQuery(sql);
14741    
14742                                    QueryPos qPos = QueryPos.getInstance(q);
14743    
14744                                    qPos.add(groupId);
14745    
14746                                    qPos.add(userId);
14747    
14748                                    qPos.add(nodeId);
14749    
14750                                    qPos.add(status);
14751    
14752                                    if (!pagination) {
14753                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14754                                                            start, end, false);
14755    
14756                                            Collections.sort(list);
14757    
14758                                            list = new UnmodifiableList<WikiPage>(list);
14759                                    }
14760                                    else {
14761                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
14762                                                            start, end);
14763                                    }
14764    
14765                                    cacheResult(list);
14766    
14767                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14768                            }
14769                            catch (Exception e) {
14770                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14771    
14772                                    throw processException(e);
14773                            }
14774                            finally {
14775                                    closeSession(session);
14776                            }
14777                    }
14778    
14779                    return list;
14780            }
14781    
14782            /**
14783             * Returns the first wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14784             *
14785             * @param groupId the group ID
14786             * @param userId the user ID
14787             * @param nodeId the node ID
14788             * @param status the status
14789             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14790             * @return the first matching wiki page
14791             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14792             * @throws SystemException if a system exception occurred
14793             */
14794            @Override
14795            public WikiPage findByG_U_N_S_First(long groupId, long userId, long nodeId,
14796                    int status, OrderByComparator orderByComparator)
14797                    throws NoSuchPageException, SystemException {
14798                    WikiPage wikiPage = fetchByG_U_N_S_First(groupId, userId, nodeId,
14799                                    status, orderByComparator);
14800    
14801                    if (wikiPage != null) {
14802                            return wikiPage;
14803                    }
14804    
14805                    StringBundler msg = new StringBundler(10);
14806    
14807                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14808    
14809                    msg.append("groupId=");
14810                    msg.append(groupId);
14811    
14812                    msg.append(", userId=");
14813                    msg.append(userId);
14814    
14815                    msg.append(", nodeId=");
14816                    msg.append(nodeId);
14817    
14818                    msg.append(", status=");
14819                    msg.append(status);
14820    
14821                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14822    
14823                    throw new NoSuchPageException(msg.toString());
14824            }
14825    
14826            /**
14827             * Returns the first wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14828             *
14829             * @param groupId the group ID
14830             * @param userId the user ID
14831             * @param nodeId the node ID
14832             * @param status the status
14833             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14834             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
14835             * @throws SystemException if a system exception occurred
14836             */
14837            @Override
14838            public WikiPage fetchByG_U_N_S_First(long groupId, long userId,
14839                    long nodeId, int status, OrderByComparator orderByComparator)
14840                    throws SystemException {
14841                    List<WikiPage> list = findByG_U_N_S(groupId, userId, nodeId, status, 0,
14842                                    1, orderByComparator);
14843    
14844                    if (!list.isEmpty()) {
14845                            return list.get(0);
14846                    }
14847    
14848                    return null;
14849            }
14850    
14851            /**
14852             * Returns the last wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14853             *
14854             * @param groupId the group ID
14855             * @param userId the user ID
14856             * @param nodeId the node ID
14857             * @param status the status
14858             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14859             * @return the last matching wiki page
14860             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
14861             * @throws SystemException if a system exception occurred
14862             */
14863            @Override
14864            public WikiPage findByG_U_N_S_Last(long groupId, long userId, long nodeId,
14865                    int status, OrderByComparator orderByComparator)
14866                    throws NoSuchPageException, SystemException {
14867                    WikiPage wikiPage = fetchByG_U_N_S_Last(groupId, userId, nodeId,
14868                                    status, orderByComparator);
14869    
14870                    if (wikiPage != null) {
14871                            return wikiPage;
14872                    }
14873    
14874                    StringBundler msg = new StringBundler(10);
14875    
14876                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14877    
14878                    msg.append("groupId=");
14879                    msg.append(groupId);
14880    
14881                    msg.append(", userId=");
14882                    msg.append(userId);
14883    
14884                    msg.append(", nodeId=");
14885                    msg.append(nodeId);
14886    
14887                    msg.append(", status=");
14888                    msg.append(status);
14889    
14890                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14891    
14892                    throw new NoSuchPageException(msg.toString());
14893            }
14894    
14895            /**
14896             * Returns the last wiki page in the ordered set where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
14897             *
14898             * @param groupId the group ID
14899             * @param userId the user ID
14900             * @param nodeId the node ID
14901             * @param status the status
14902             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14903             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
14904             * @throws SystemException if a system exception occurred
14905             */
14906            @Override
14907            public WikiPage fetchByG_U_N_S_Last(long groupId, long userId, long nodeId,
14908                    int status, OrderByComparator orderByComparator)
14909                    throws SystemException {
14910                    int count = countByG_U_N_S(groupId, userId, nodeId, status);
14911    
14912                    if (count == 0) {
14913                            return null;
14914                    }
14915    
14916                    List<WikiPage> list = findByG_U_N_S(groupId, userId, nodeId, status,
14917                                    count - 1, count, orderByComparator);
14918    
14919                    if (!list.isEmpty()) {
14920                            return list.get(0);
14921                    }
14922    
14923                    return null;
14924            }
14925    
14926            /**
14927             * 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;.
14928             *
14929             * @param pageId the primary key of the current wiki page
14930             * @param groupId the group ID
14931             * @param userId the user ID
14932             * @param nodeId the node ID
14933             * @param status the status
14934             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14935             * @return the previous, current, and next wiki page
14936             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
14937             * @throws SystemException if a system exception occurred
14938             */
14939            @Override
14940            public WikiPage[] findByG_U_N_S_PrevAndNext(long pageId, long groupId,
14941                    long userId, long nodeId, int status,
14942                    OrderByComparator orderByComparator)
14943                    throws NoSuchPageException, SystemException {
14944                    WikiPage wikiPage = findByPrimaryKey(pageId);
14945    
14946                    Session session = null;
14947    
14948                    try {
14949                            session = openSession();
14950    
14951                            WikiPage[] array = new WikiPageImpl[3];
14952    
14953                            array[0] = getByG_U_N_S_PrevAndNext(session, wikiPage, groupId,
14954                                            userId, nodeId, status, orderByComparator, true);
14955    
14956                            array[1] = wikiPage;
14957    
14958                            array[2] = getByG_U_N_S_PrevAndNext(session, wikiPage, groupId,
14959                                            userId, nodeId, status, orderByComparator, false);
14960    
14961                            return array;
14962                    }
14963                    catch (Exception e) {
14964                            throw processException(e);
14965                    }
14966                    finally {
14967                            closeSession(session);
14968                    }
14969            }
14970    
14971            protected WikiPage getByG_U_N_S_PrevAndNext(Session session,
14972                    WikiPage wikiPage, long groupId, long userId, long nodeId, int status,
14973                    OrderByComparator orderByComparator, boolean previous) {
14974                    StringBundler query = null;
14975    
14976                    if (orderByComparator != null) {
14977                            query = new StringBundler(6 +
14978                                            (orderByComparator.getOrderByFields().length * 6));
14979                    }
14980                    else {
14981                            query = new StringBundler(3);
14982                    }
14983    
14984                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
14985    
14986                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
14987    
14988                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
14989    
14990                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
14991    
14992                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
14993    
14994                    if (orderByComparator != null) {
14995                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14996    
14997                            if (orderByConditionFields.length > 0) {
14998                                    query.append(WHERE_AND);
14999                            }
15000    
15001                            for (int i = 0; i < orderByConditionFields.length; i++) {
15002                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15003                                    query.append(orderByConditionFields[i]);
15004    
15005                                    if ((i + 1) < orderByConditionFields.length) {
15006                                            if (orderByComparator.isAscending() ^ previous) {
15007                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15008                                            }
15009                                            else {
15010                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15011                                            }
15012                                    }
15013                                    else {
15014                                            if (orderByComparator.isAscending() ^ previous) {
15015                                                    query.append(WHERE_GREATER_THAN);
15016                                            }
15017                                            else {
15018                                                    query.append(WHERE_LESSER_THAN);
15019                                            }
15020                                    }
15021                            }
15022    
15023                            query.append(ORDER_BY_CLAUSE);
15024    
15025                            String[] orderByFields = orderByComparator.getOrderByFields();
15026    
15027                            for (int i = 0; i < orderByFields.length; i++) {
15028                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15029                                    query.append(orderByFields[i]);
15030    
15031                                    if ((i + 1) < orderByFields.length) {
15032                                            if (orderByComparator.isAscending() ^ previous) {
15033                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15034                                            }
15035                                            else {
15036                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15037                                            }
15038                                    }
15039                                    else {
15040                                            if (orderByComparator.isAscending() ^ previous) {
15041                                                    query.append(ORDER_BY_ASC);
15042                                            }
15043                                            else {
15044                                                    query.append(ORDER_BY_DESC);
15045                                            }
15046                                    }
15047                            }
15048                    }
15049                    else {
15050                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15051                    }
15052    
15053                    String sql = query.toString();
15054    
15055                    Query q = session.createQuery(sql);
15056    
15057                    q.setFirstResult(0);
15058                    q.setMaxResults(2);
15059    
15060                    QueryPos qPos = QueryPos.getInstance(q);
15061    
15062                    qPos.add(groupId);
15063    
15064                    qPos.add(userId);
15065    
15066                    qPos.add(nodeId);
15067    
15068                    qPos.add(status);
15069    
15070                    if (orderByComparator != null) {
15071                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
15072    
15073                            for (Object value : values) {
15074                                    qPos.add(value);
15075                            }
15076                    }
15077    
15078                    List<WikiPage> list = q.list();
15079    
15080                    if (list.size() == 2) {
15081                            return list.get(1);
15082                    }
15083                    else {
15084                            return null;
15085                    }
15086            }
15087    
15088            /**
15089             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
15090             *
15091             * @param groupId the group ID
15092             * @param userId the user ID
15093             * @param nodeId the node ID
15094             * @param status the status
15095             * @return the matching wiki pages that the user has permission to view
15096             * @throws SystemException if a system exception occurred
15097             */
15098            @Override
15099            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
15100                    long nodeId, int status) throws SystemException {
15101                    return filterFindByG_U_N_S(groupId, userId, nodeId, status,
15102                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15103            }
15104    
15105            /**
15106             * 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;.
15107             *
15108             * <p>
15109             * 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.
15110             * </p>
15111             *
15112             * @param groupId the group ID
15113             * @param userId the user ID
15114             * @param nodeId the node ID
15115             * @param status the status
15116             * @param start the lower bound of the range of wiki pages
15117             * @param end the upper bound of the range of wiki pages (not inclusive)
15118             * @return the range of matching wiki pages that the user has permission to view
15119             * @throws SystemException if a system exception occurred
15120             */
15121            @Override
15122            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
15123                    long nodeId, int status, int start, int end) throws SystemException {
15124                    return filterFindByG_U_N_S(groupId, userId, nodeId, status, start, end,
15125                            null);
15126            }
15127    
15128            /**
15129             * 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;.
15130             *
15131             * <p>
15132             * 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.
15133             * </p>
15134             *
15135             * @param groupId the group ID
15136             * @param userId the user ID
15137             * @param nodeId the node ID
15138             * @param status the status
15139             * @param start the lower bound of the range of wiki pages
15140             * @param end the upper bound of the range of wiki pages (not inclusive)
15141             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15142             * @return the ordered range of matching wiki pages that the user has permission to view
15143             * @throws SystemException if a system exception occurred
15144             */
15145            @Override
15146            public List<WikiPage> filterFindByG_U_N_S(long groupId, long userId,
15147                    long nodeId, int status, int start, int end,
15148                    OrderByComparator orderByComparator) throws SystemException {
15149                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15150                            return findByG_U_N_S(groupId, userId, nodeId, status, start, end,
15151                                    orderByComparator);
15152                    }
15153    
15154                    StringBundler query = null;
15155    
15156                    if (orderByComparator != null) {
15157                            query = new StringBundler(6 +
15158                                            (orderByComparator.getOrderByFields().length * 3));
15159                    }
15160                    else {
15161                            query = new StringBundler(6);
15162                    }
15163    
15164                    if (getDB().isSupportsInlineDistinct()) {
15165                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
15166                    }
15167                    else {
15168                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
15169                    }
15170    
15171                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
15172    
15173                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
15174    
15175                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
15176    
15177                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
15178    
15179                    if (!getDB().isSupportsInlineDistinct()) {
15180                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
15181                    }
15182    
15183                    if (orderByComparator != null) {
15184                            if (getDB().isSupportsInlineDistinct()) {
15185                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15186                                            orderByComparator, true);
15187                            }
15188                            else {
15189                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
15190                                            orderByComparator, true);
15191                            }
15192                    }
15193                    else {
15194                            if (getDB().isSupportsInlineDistinct()) {
15195                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15196                            }
15197                            else {
15198                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
15199                            }
15200                    }
15201    
15202                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15203                                    WikiPage.class.getName(),
15204                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15205    
15206                    Session session = null;
15207    
15208                    try {
15209                            session = openSession();
15210    
15211                            SQLQuery q = session.createSQLQuery(sql);
15212    
15213                            if (getDB().isSupportsInlineDistinct()) {
15214                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
15215                            }
15216                            else {
15217                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
15218                            }
15219    
15220                            QueryPos qPos = QueryPos.getInstance(q);
15221    
15222                            qPos.add(groupId);
15223    
15224                            qPos.add(userId);
15225    
15226                            qPos.add(nodeId);
15227    
15228                            qPos.add(status);
15229    
15230                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
15231                    }
15232                    catch (Exception e) {
15233                            throw processException(e);
15234                    }
15235                    finally {
15236                            closeSession(session);
15237                    }
15238            }
15239    
15240            /**
15241             * 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;.
15242             *
15243             * @param pageId the primary key of the current wiki page
15244             * @param groupId the group ID
15245             * @param userId the user ID
15246             * @param nodeId the node ID
15247             * @param status the status
15248             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15249             * @return the previous, current, and next wiki page
15250             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
15251             * @throws SystemException if a system exception occurred
15252             */
15253            @Override
15254            public WikiPage[] filterFindByG_U_N_S_PrevAndNext(long pageId,
15255                    long groupId, long userId, long nodeId, int status,
15256                    OrderByComparator orderByComparator)
15257                    throws NoSuchPageException, SystemException {
15258                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15259                            return findByG_U_N_S_PrevAndNext(pageId, groupId, userId, nodeId,
15260                                    status, orderByComparator);
15261                    }
15262    
15263                    WikiPage wikiPage = findByPrimaryKey(pageId);
15264    
15265                    Session session = null;
15266    
15267                    try {
15268                            session = openSession();
15269    
15270                            WikiPage[] array = new WikiPageImpl[3];
15271    
15272                            array[0] = filterGetByG_U_N_S_PrevAndNext(session, wikiPage,
15273                                            groupId, userId, nodeId, status, orderByComparator, true);
15274    
15275                            array[1] = wikiPage;
15276    
15277                            array[2] = filterGetByG_U_N_S_PrevAndNext(session, wikiPage,
15278                                            groupId, userId, nodeId, status, orderByComparator, false);
15279    
15280                            return array;
15281                    }
15282                    catch (Exception e) {
15283                            throw processException(e);
15284                    }
15285                    finally {
15286                            closeSession(session);
15287                    }
15288            }
15289    
15290            protected WikiPage filterGetByG_U_N_S_PrevAndNext(Session session,
15291                    WikiPage wikiPage, long groupId, long userId, long nodeId, int status,
15292                    OrderByComparator orderByComparator, boolean previous) {
15293                    StringBundler query = null;
15294    
15295                    if (orderByComparator != null) {
15296                            query = new StringBundler(6 +
15297                                            (orderByComparator.getOrderByFields().length * 6));
15298                    }
15299                    else {
15300                            query = new StringBundler(3);
15301                    }
15302    
15303                    if (getDB().isSupportsInlineDistinct()) {
15304                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
15305                    }
15306                    else {
15307                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
15308                    }
15309    
15310                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
15311    
15312                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
15313    
15314                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
15315    
15316                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
15317    
15318                    if (!getDB().isSupportsInlineDistinct()) {
15319                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
15320                    }
15321    
15322                    if (orderByComparator != null) {
15323                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15324    
15325                            if (orderByConditionFields.length > 0) {
15326                                    query.append(WHERE_AND);
15327                            }
15328    
15329                            for (int i = 0; i < orderByConditionFields.length; i++) {
15330                                    if (getDB().isSupportsInlineDistinct()) {
15331                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15332                                    }
15333                                    else {
15334                                            query.append(_ORDER_BY_ENTITY_TABLE);
15335                                    }
15336    
15337                                    query.append(orderByConditionFields[i]);
15338    
15339                                    if ((i + 1) < orderByConditionFields.length) {
15340                                            if (orderByComparator.isAscending() ^ previous) {
15341                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15342                                            }
15343                                            else {
15344                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15345                                            }
15346                                    }
15347                                    else {
15348                                            if (orderByComparator.isAscending() ^ previous) {
15349                                                    query.append(WHERE_GREATER_THAN);
15350                                            }
15351                                            else {
15352                                                    query.append(WHERE_LESSER_THAN);
15353                                            }
15354                                    }
15355                            }
15356    
15357                            query.append(ORDER_BY_CLAUSE);
15358    
15359                            String[] orderByFields = orderByComparator.getOrderByFields();
15360    
15361                            for (int i = 0; i < orderByFields.length; i++) {
15362                                    if (getDB().isSupportsInlineDistinct()) {
15363                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15364                                    }
15365                                    else {
15366                                            query.append(_ORDER_BY_ENTITY_TABLE);
15367                                    }
15368    
15369                                    query.append(orderByFields[i]);
15370    
15371                                    if ((i + 1) < orderByFields.length) {
15372                                            if (orderByComparator.isAscending() ^ previous) {
15373                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15374                                            }
15375                                            else {
15376                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15377                                            }
15378                                    }
15379                                    else {
15380                                            if (orderByComparator.isAscending() ^ previous) {
15381                                                    query.append(ORDER_BY_ASC);
15382                                            }
15383                                            else {
15384                                                    query.append(ORDER_BY_DESC);
15385                                            }
15386                                    }
15387                            }
15388                    }
15389                    else {
15390                            if (getDB().isSupportsInlineDistinct()) {
15391                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15392                            }
15393                            else {
15394                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
15395                            }
15396                    }
15397    
15398                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15399                                    WikiPage.class.getName(),
15400                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15401    
15402                    SQLQuery q = session.createSQLQuery(sql);
15403    
15404                    q.setFirstResult(0);
15405                    q.setMaxResults(2);
15406    
15407                    if (getDB().isSupportsInlineDistinct()) {
15408                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
15409                    }
15410                    else {
15411                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
15412                    }
15413    
15414                    QueryPos qPos = QueryPos.getInstance(q);
15415    
15416                    qPos.add(groupId);
15417    
15418                    qPos.add(userId);
15419    
15420                    qPos.add(nodeId);
15421    
15422                    qPos.add(status);
15423    
15424                    if (orderByComparator != null) {
15425                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
15426    
15427                            for (Object value : values) {
15428                                    qPos.add(value);
15429                            }
15430                    }
15431    
15432                    List<WikiPage> list = q.list();
15433    
15434                    if (list.size() == 2) {
15435                            return list.get(1);
15436                    }
15437                    else {
15438                            return null;
15439                    }
15440            }
15441    
15442            /**
15443             * Removes all the wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63; from the database.
15444             *
15445             * @param groupId the group ID
15446             * @param userId the user ID
15447             * @param nodeId the node ID
15448             * @param status the status
15449             * @throws SystemException if a system exception occurred
15450             */
15451            @Override
15452            public void removeByG_U_N_S(long groupId, long userId, long nodeId,
15453                    int status) throws SystemException {
15454                    for (WikiPage wikiPage : findByG_U_N_S(groupId, userId, nodeId, status,
15455                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15456                            remove(wikiPage);
15457                    }
15458            }
15459    
15460            /**
15461             * Returns the number of wiki pages where groupId = &#63; and userId = &#63; and nodeId = &#63; and status = &#63;.
15462             *
15463             * @param groupId the group ID
15464             * @param userId the user ID
15465             * @param nodeId the node ID
15466             * @param status the status
15467             * @return the number of matching wiki pages
15468             * @throws SystemException if a system exception occurred
15469             */
15470            @Override
15471            public int countByG_U_N_S(long groupId, long userId, long nodeId, int status)
15472                    throws SystemException {
15473                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_N_S;
15474    
15475                    Object[] finderArgs = new Object[] { groupId, userId, nodeId, status };
15476    
15477                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15478                                    this);
15479    
15480                    if (count == null) {
15481                            StringBundler query = new StringBundler(5);
15482    
15483                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
15484    
15485                            query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
15486    
15487                            query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
15488    
15489                            query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
15490    
15491                            query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
15492    
15493                            String sql = query.toString();
15494    
15495                            Session session = null;
15496    
15497                            try {
15498                                    session = openSession();
15499    
15500                                    Query q = session.createQuery(sql);
15501    
15502                                    QueryPos qPos = QueryPos.getInstance(q);
15503    
15504                                    qPos.add(groupId);
15505    
15506                                    qPos.add(userId);
15507    
15508                                    qPos.add(nodeId);
15509    
15510                                    qPos.add(status);
15511    
15512                                    count = (Long)q.uniqueResult();
15513    
15514                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15515                            }
15516                            catch (Exception e) {
15517                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15518    
15519                                    throw processException(e);
15520                            }
15521                            finally {
15522                                    closeSession(session);
15523                            }
15524                    }
15525    
15526                    return count.intValue();
15527            }
15528    
15529            /**
15530             * 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;.
15531             *
15532             * @param groupId the group ID
15533             * @param userId the user ID
15534             * @param nodeId the node ID
15535             * @param status the status
15536             * @return the number of matching wiki pages that the user has permission to view
15537             * @throws SystemException if a system exception occurred
15538             */
15539            @Override
15540            public int filterCountByG_U_N_S(long groupId, long userId, long nodeId,
15541                    int status) throws SystemException {
15542                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15543                            return countByG_U_N_S(groupId, userId, nodeId, status);
15544                    }
15545    
15546                    StringBundler query = new StringBundler(5);
15547    
15548                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
15549    
15550                    query.append(_FINDER_COLUMN_G_U_N_S_GROUPID_2);
15551    
15552                    query.append(_FINDER_COLUMN_G_U_N_S_USERID_2);
15553    
15554                    query.append(_FINDER_COLUMN_G_U_N_S_NODEID_2);
15555    
15556                    query.append(_FINDER_COLUMN_G_U_N_S_STATUS_2);
15557    
15558                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15559                                    WikiPage.class.getName(),
15560                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15561    
15562                    Session session = null;
15563    
15564                    try {
15565                            session = openSession();
15566    
15567                            SQLQuery q = session.createSQLQuery(sql);
15568    
15569                            q.addScalar(COUNT_COLUMN_NAME,
15570                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
15571    
15572                            QueryPos qPos = QueryPos.getInstance(q);
15573    
15574                            qPos.add(groupId);
15575    
15576                            qPos.add(userId);
15577    
15578                            qPos.add(nodeId);
15579    
15580                            qPos.add(status);
15581    
15582                            Long count = (Long)q.uniqueResult();
15583    
15584                            return count.intValue();
15585                    }
15586                    catch (Exception e) {
15587                            throw processException(e);
15588                    }
15589                    finally {
15590                            closeSession(session);
15591                    }
15592            }
15593    
15594            private static final String _FINDER_COLUMN_G_U_N_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
15595            private static final String _FINDER_COLUMN_G_U_N_S_USERID_2 = "wikiPage.userId = ? AND ";
15596            private static final String _FINDER_COLUMN_G_U_N_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
15597            private static final String _FINDER_COLUMN_G_U_N_S_STATUS_2 = "wikiPage.status = ?";
15598            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15599                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15600                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_T_H",
15601                            new String[] {
15602                                    Long.class.getName(), Long.class.getName(),
15603                                    String.class.getName(), Boolean.class.getName(),
15604                                    
15605                            Integer.class.getName(), Integer.class.getName(),
15606                                    OrderByComparator.class.getName()
15607                            });
15608            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H =
15609                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15610                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
15611                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_T_H",
15612                            new String[] {
15613                                    Long.class.getName(), Long.class.getName(),
15614                                    String.class.getName(), Boolean.class.getName()
15615                            },
15616                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
15617                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
15618                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
15619                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
15620                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
15621            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_T_H = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
15622                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15623                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_T_H",
15624                            new String[] {
15625                                    Long.class.getName(), Long.class.getName(),
15626                                    String.class.getName(), Boolean.class.getName()
15627                            });
15628    
15629            /**
15630             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15631             *
15632             * @param groupId the group ID
15633             * @param nodeId the node ID
15634             * @param title the title
15635             * @param head the head
15636             * @return the matching wiki pages
15637             * @throws SystemException if a system exception occurred
15638             */
15639            @Override
15640            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
15641                    String title, boolean head) throws SystemException {
15642                    return findByG_N_T_H(groupId, nodeId, title, head, QueryUtil.ALL_POS,
15643                            QueryUtil.ALL_POS, null);
15644            }
15645    
15646            /**
15647             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15648             *
15649             * <p>
15650             * 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.
15651             * </p>
15652             *
15653             * @param groupId the group ID
15654             * @param nodeId the node ID
15655             * @param title the title
15656             * @param head the head
15657             * @param start the lower bound of the range of wiki pages
15658             * @param end the upper bound of the range of wiki pages (not inclusive)
15659             * @return the range of matching wiki pages
15660             * @throws SystemException if a system exception occurred
15661             */
15662            @Override
15663            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
15664                    String title, boolean head, int start, int end)
15665                    throws SystemException {
15666                    return findByG_N_T_H(groupId, nodeId, title, head, start, end, null);
15667            }
15668    
15669            /**
15670             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15671             *
15672             * <p>
15673             * 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.
15674             * </p>
15675             *
15676             * @param groupId the group ID
15677             * @param nodeId the node ID
15678             * @param title the title
15679             * @param head the head
15680             * @param start the lower bound of the range of wiki pages
15681             * @param end the upper bound of the range of wiki pages (not inclusive)
15682             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15683             * @return the ordered range of matching wiki pages
15684             * @throws SystemException if a system exception occurred
15685             */
15686            @Override
15687            public List<WikiPage> findByG_N_T_H(long groupId, long nodeId,
15688                    String title, boolean head, int start, int end,
15689                    OrderByComparator orderByComparator) throws SystemException {
15690                    boolean pagination = true;
15691                    FinderPath finderPath = null;
15692                    Object[] finderArgs = null;
15693    
15694                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15695                                    (orderByComparator == null)) {
15696                            pagination = false;
15697                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H;
15698                            finderArgs = new Object[] { groupId, nodeId, title, head };
15699                    }
15700                    else {
15701                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_H;
15702                            finderArgs = new Object[] {
15703                                            groupId, nodeId, title, head,
15704                                            
15705                                            start, end, orderByComparator
15706                                    };
15707                    }
15708    
15709                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
15710                                    finderArgs, this);
15711    
15712                    if ((list != null) && !list.isEmpty()) {
15713                            for (WikiPage wikiPage : list) {
15714                                    if ((groupId != wikiPage.getGroupId()) ||
15715                                                    (nodeId != wikiPage.getNodeId()) ||
15716                                                    !Validator.equals(title, wikiPage.getTitle()) ||
15717                                                    (head != wikiPage.getHead())) {
15718                                            list = null;
15719    
15720                                            break;
15721                                    }
15722                            }
15723                    }
15724    
15725                    if (list == null) {
15726                            StringBundler query = null;
15727    
15728                            if (orderByComparator != null) {
15729                                    query = new StringBundler(6 +
15730                                                    (orderByComparator.getOrderByFields().length * 3));
15731                            }
15732                            else {
15733                                    query = new StringBundler(6);
15734                            }
15735    
15736                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
15737    
15738                            query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
15739    
15740                            query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
15741    
15742                            boolean bindTitle = false;
15743    
15744                            if (title == null) {
15745                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
15746                            }
15747                            else if (title.equals(StringPool.BLANK)) {
15748                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
15749                            }
15750                            else {
15751                                    bindTitle = true;
15752    
15753                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
15754                            }
15755    
15756                            query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
15757    
15758                            if (orderByComparator != null) {
15759                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15760                                            orderByComparator);
15761                            }
15762                            else
15763                             if (pagination) {
15764                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
15765                            }
15766    
15767                            String sql = query.toString();
15768    
15769                            Session session = null;
15770    
15771                            try {
15772                                    session = openSession();
15773    
15774                                    Query q = session.createQuery(sql);
15775    
15776                                    QueryPos qPos = QueryPos.getInstance(q);
15777    
15778                                    qPos.add(groupId);
15779    
15780                                    qPos.add(nodeId);
15781    
15782                                    if (bindTitle) {
15783                                            qPos.add(title.toLowerCase());
15784                                    }
15785    
15786                                    qPos.add(head);
15787    
15788                                    if (!pagination) {
15789                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15790                                                            start, end, false);
15791    
15792                                            Collections.sort(list);
15793    
15794                                            list = new UnmodifiableList<WikiPage>(list);
15795                                    }
15796                                    else {
15797                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
15798                                                            start, end);
15799                                    }
15800    
15801                                    cacheResult(list);
15802    
15803                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15804                            }
15805                            catch (Exception e) {
15806                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15807    
15808                                    throw processException(e);
15809                            }
15810                            finally {
15811                                    closeSession(session);
15812                            }
15813                    }
15814    
15815                    return list;
15816            }
15817    
15818            /**
15819             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15820             *
15821             * @param groupId the group ID
15822             * @param nodeId the node ID
15823             * @param title the title
15824             * @param head the head
15825             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15826             * @return the first matching wiki page
15827             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
15828             * @throws SystemException if a system exception occurred
15829             */
15830            @Override
15831            public WikiPage findByG_N_T_H_First(long groupId, long nodeId,
15832                    String title, boolean head, OrderByComparator orderByComparator)
15833                    throws NoSuchPageException, SystemException {
15834                    WikiPage wikiPage = fetchByG_N_T_H_First(groupId, nodeId, title, head,
15835                                    orderByComparator);
15836    
15837                    if (wikiPage != null) {
15838                            return wikiPage;
15839                    }
15840    
15841                    StringBundler msg = new StringBundler(10);
15842    
15843                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15844    
15845                    msg.append("groupId=");
15846                    msg.append(groupId);
15847    
15848                    msg.append(", nodeId=");
15849                    msg.append(nodeId);
15850    
15851                    msg.append(", title=");
15852                    msg.append(title);
15853    
15854                    msg.append(", head=");
15855                    msg.append(head);
15856    
15857                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15858    
15859                    throw new NoSuchPageException(msg.toString());
15860            }
15861    
15862            /**
15863             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15864             *
15865             * @param groupId the group ID
15866             * @param nodeId the node ID
15867             * @param title the title
15868             * @param head the head
15869             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15870             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
15871             * @throws SystemException if a system exception occurred
15872             */
15873            @Override
15874            public WikiPage fetchByG_N_T_H_First(long groupId, long nodeId,
15875                    String title, boolean head, OrderByComparator orderByComparator)
15876                    throws SystemException {
15877                    List<WikiPage> list = findByG_N_T_H(groupId, nodeId, title, head, 0, 1,
15878                                    orderByComparator);
15879    
15880                    if (!list.isEmpty()) {
15881                            return list.get(0);
15882                    }
15883    
15884                    return null;
15885            }
15886    
15887            /**
15888             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15889             *
15890             * @param groupId the group ID
15891             * @param nodeId the node ID
15892             * @param title the title
15893             * @param head the head
15894             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15895             * @return the last matching wiki page
15896             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
15897             * @throws SystemException if a system exception occurred
15898             */
15899            @Override
15900            public WikiPage findByG_N_T_H_Last(long groupId, long nodeId, String title,
15901                    boolean head, OrderByComparator orderByComparator)
15902                    throws NoSuchPageException, SystemException {
15903                    WikiPage wikiPage = fetchByG_N_T_H_Last(groupId, nodeId, title, head,
15904                                    orderByComparator);
15905    
15906                    if (wikiPage != null) {
15907                            return wikiPage;
15908                    }
15909    
15910                    StringBundler msg = new StringBundler(10);
15911    
15912                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15913    
15914                    msg.append("groupId=");
15915                    msg.append(groupId);
15916    
15917                    msg.append(", nodeId=");
15918                    msg.append(nodeId);
15919    
15920                    msg.append(", title=");
15921                    msg.append(title);
15922    
15923                    msg.append(", head=");
15924                    msg.append(head);
15925    
15926                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15927    
15928                    throw new NoSuchPageException(msg.toString());
15929            }
15930    
15931            /**
15932             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
15933             *
15934             * @param groupId the group ID
15935             * @param nodeId the node ID
15936             * @param title the title
15937             * @param head the head
15938             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15939             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
15940             * @throws SystemException if a system exception occurred
15941             */
15942            @Override
15943            public WikiPage fetchByG_N_T_H_Last(long groupId, long nodeId,
15944                    String title, boolean head, OrderByComparator orderByComparator)
15945                    throws SystemException {
15946                    int count = countByG_N_T_H(groupId, nodeId, title, head);
15947    
15948                    if (count == 0) {
15949                            return null;
15950                    }
15951    
15952                    List<WikiPage> list = findByG_N_T_H(groupId, nodeId, title, head,
15953                                    count - 1, count, orderByComparator);
15954    
15955                    if (!list.isEmpty()) {
15956                            return list.get(0);
15957                    }
15958    
15959                    return null;
15960            }
15961    
15962            /**
15963             * 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;.
15964             *
15965             * @param pageId the primary key of the current wiki page
15966             * @param groupId the group ID
15967             * @param nodeId the node ID
15968             * @param title the title
15969             * @param head the head
15970             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15971             * @return the previous, current, and next wiki page
15972             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
15973             * @throws SystemException if a system exception occurred
15974             */
15975            @Override
15976            public WikiPage[] findByG_N_T_H_PrevAndNext(long pageId, long groupId,
15977                    long nodeId, String title, boolean head,
15978                    OrderByComparator orderByComparator)
15979                    throws NoSuchPageException, SystemException {
15980                    WikiPage wikiPage = findByPrimaryKey(pageId);
15981    
15982                    Session session = null;
15983    
15984                    try {
15985                            session = openSession();
15986    
15987                            WikiPage[] array = new WikiPageImpl[3];
15988    
15989                            array[0] = getByG_N_T_H_PrevAndNext(session, wikiPage, groupId,
15990                                            nodeId, title, head, orderByComparator, true);
15991    
15992                            array[1] = wikiPage;
15993    
15994                            array[2] = getByG_N_T_H_PrevAndNext(session, wikiPage, groupId,
15995                                            nodeId, title, head, orderByComparator, false);
15996    
15997                            return array;
15998                    }
15999                    catch (Exception e) {
16000                            throw processException(e);
16001                    }
16002                    finally {
16003                            closeSession(session);
16004                    }
16005            }
16006    
16007            protected WikiPage getByG_N_T_H_PrevAndNext(Session session,
16008                    WikiPage wikiPage, long groupId, long nodeId, String title,
16009                    boolean head, OrderByComparator orderByComparator, boolean previous) {
16010                    StringBundler query = null;
16011    
16012                    if (orderByComparator != null) {
16013                            query = new StringBundler(6 +
16014                                            (orderByComparator.getOrderByFields().length * 6));
16015                    }
16016                    else {
16017                            query = new StringBundler(3);
16018                    }
16019    
16020                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
16021    
16022                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
16023    
16024                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
16025    
16026                    boolean bindTitle = false;
16027    
16028                    if (title == null) {
16029                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
16030                    }
16031                    else if (title.equals(StringPool.BLANK)) {
16032                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
16033                    }
16034                    else {
16035                            bindTitle = true;
16036    
16037                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
16038                    }
16039    
16040                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
16041    
16042                    if (orderByComparator != null) {
16043                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16044    
16045                            if (orderByConditionFields.length > 0) {
16046                                    query.append(WHERE_AND);
16047                            }
16048    
16049                            for (int i = 0; i < orderByConditionFields.length; i++) {
16050                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16051                                    query.append(orderByConditionFields[i]);
16052    
16053                                    if ((i + 1) < orderByConditionFields.length) {
16054                                            if (orderByComparator.isAscending() ^ previous) {
16055                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16056                                            }
16057                                            else {
16058                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16059                                            }
16060                                    }
16061                                    else {
16062                                            if (orderByComparator.isAscending() ^ previous) {
16063                                                    query.append(WHERE_GREATER_THAN);
16064                                            }
16065                                            else {
16066                                                    query.append(WHERE_LESSER_THAN);
16067                                            }
16068                                    }
16069                            }
16070    
16071                            query.append(ORDER_BY_CLAUSE);
16072    
16073                            String[] orderByFields = orderByComparator.getOrderByFields();
16074    
16075                            for (int i = 0; i < orderByFields.length; i++) {
16076                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16077                                    query.append(orderByFields[i]);
16078    
16079                                    if ((i + 1) < orderByFields.length) {
16080                                            if (orderByComparator.isAscending() ^ previous) {
16081                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16082                                            }
16083                                            else {
16084                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16085                                            }
16086                                    }
16087                                    else {
16088                                            if (orderByComparator.isAscending() ^ previous) {
16089                                                    query.append(ORDER_BY_ASC);
16090                                            }
16091                                            else {
16092                                                    query.append(ORDER_BY_DESC);
16093                                            }
16094                                    }
16095                            }
16096                    }
16097                    else {
16098                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16099                    }
16100    
16101                    String sql = query.toString();
16102    
16103                    Query q = session.createQuery(sql);
16104    
16105                    q.setFirstResult(0);
16106                    q.setMaxResults(2);
16107    
16108                    QueryPos qPos = QueryPos.getInstance(q);
16109    
16110                    qPos.add(groupId);
16111    
16112                    qPos.add(nodeId);
16113    
16114                    if (bindTitle) {
16115                            qPos.add(title.toLowerCase());
16116                    }
16117    
16118                    qPos.add(head);
16119    
16120                    if (orderByComparator != null) {
16121                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
16122    
16123                            for (Object value : values) {
16124                                    qPos.add(value);
16125                            }
16126                    }
16127    
16128                    List<WikiPage> list = q.list();
16129    
16130                    if (list.size() == 2) {
16131                            return list.get(1);
16132                    }
16133                    else {
16134                            return null;
16135                    }
16136            }
16137    
16138            /**
16139             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
16140             *
16141             * @param groupId the group ID
16142             * @param nodeId the node ID
16143             * @param title the title
16144             * @param head the head
16145             * @return the matching wiki pages that the user has permission to view
16146             * @throws SystemException if a system exception occurred
16147             */
16148            @Override
16149            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
16150                    String title, boolean head) throws SystemException {
16151                    return filterFindByG_N_T_H(groupId, nodeId, title, head,
16152                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16153            }
16154    
16155            /**
16156             * 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;.
16157             *
16158             * <p>
16159             * 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.
16160             * </p>
16161             *
16162             * @param groupId the group ID
16163             * @param nodeId the node ID
16164             * @param title the title
16165             * @param head the head
16166             * @param start the lower bound of the range of wiki pages
16167             * @param end the upper bound of the range of wiki pages (not inclusive)
16168             * @return the range of matching wiki pages that the user has permission to view
16169             * @throws SystemException if a system exception occurred
16170             */
16171            @Override
16172            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
16173                    String title, boolean head, int start, int end)
16174                    throws SystemException {
16175                    return filterFindByG_N_T_H(groupId, nodeId, title, head, start, end,
16176                            null);
16177            }
16178    
16179            /**
16180             * 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;.
16181             *
16182             * <p>
16183             * 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.
16184             * </p>
16185             *
16186             * @param groupId the group ID
16187             * @param nodeId the node ID
16188             * @param title the title
16189             * @param head the head
16190             * @param start the lower bound of the range of wiki pages
16191             * @param end the upper bound of the range of wiki pages (not inclusive)
16192             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16193             * @return the ordered range of matching wiki pages that the user has permission to view
16194             * @throws SystemException if a system exception occurred
16195             */
16196            @Override
16197            public List<WikiPage> filterFindByG_N_T_H(long groupId, long nodeId,
16198                    String title, boolean head, int start, int end,
16199                    OrderByComparator orderByComparator) throws SystemException {
16200                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16201                            return findByG_N_T_H(groupId, nodeId, title, head, start, end,
16202                                    orderByComparator);
16203                    }
16204    
16205                    StringBundler query = null;
16206    
16207                    if (orderByComparator != null) {
16208                            query = new StringBundler(6 +
16209                                            (orderByComparator.getOrderByFields().length * 3));
16210                    }
16211                    else {
16212                            query = new StringBundler(6);
16213                    }
16214    
16215                    if (getDB().isSupportsInlineDistinct()) {
16216                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
16217                    }
16218                    else {
16219                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
16220                    }
16221    
16222                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
16223    
16224                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
16225    
16226                    boolean bindTitle = false;
16227    
16228                    if (title == null) {
16229                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
16230                    }
16231                    else if (title.equals(StringPool.BLANK)) {
16232                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
16233                    }
16234                    else {
16235                            bindTitle = true;
16236    
16237                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
16238                    }
16239    
16240                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
16241    
16242                    if (!getDB().isSupportsInlineDistinct()) {
16243                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
16244                    }
16245    
16246                    if (orderByComparator != null) {
16247                            if (getDB().isSupportsInlineDistinct()) {
16248                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16249                                            orderByComparator, true);
16250                            }
16251                            else {
16252                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16253                                            orderByComparator, true);
16254                            }
16255                    }
16256                    else {
16257                            if (getDB().isSupportsInlineDistinct()) {
16258                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16259                            }
16260                            else {
16261                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
16262                            }
16263                    }
16264    
16265                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16266                                    WikiPage.class.getName(),
16267                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16268    
16269                    Session session = null;
16270    
16271                    try {
16272                            session = openSession();
16273    
16274                            SQLQuery q = session.createSQLQuery(sql);
16275    
16276                            if (getDB().isSupportsInlineDistinct()) {
16277                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
16278                            }
16279                            else {
16280                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
16281                            }
16282    
16283                            QueryPos qPos = QueryPos.getInstance(q);
16284    
16285                            qPos.add(groupId);
16286    
16287                            qPos.add(nodeId);
16288    
16289                            if (bindTitle) {
16290                                    qPos.add(title.toLowerCase());
16291                            }
16292    
16293                            qPos.add(head);
16294    
16295                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
16296                    }
16297                    catch (Exception e) {
16298                            throw processException(e);
16299                    }
16300                    finally {
16301                            closeSession(session);
16302                    }
16303            }
16304    
16305            /**
16306             * 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;.
16307             *
16308             * @param pageId the primary key of the current wiki page
16309             * @param groupId the group ID
16310             * @param nodeId the node ID
16311             * @param title the title
16312             * @param head the head
16313             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16314             * @return the previous, current, and next wiki page
16315             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
16316             * @throws SystemException if a system exception occurred
16317             */
16318            @Override
16319            public WikiPage[] filterFindByG_N_T_H_PrevAndNext(long pageId,
16320                    long groupId, long nodeId, String title, boolean head,
16321                    OrderByComparator orderByComparator)
16322                    throws NoSuchPageException, SystemException {
16323                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16324                            return findByG_N_T_H_PrevAndNext(pageId, groupId, nodeId, title,
16325                                    head, orderByComparator);
16326                    }
16327    
16328                    WikiPage wikiPage = findByPrimaryKey(pageId);
16329    
16330                    Session session = null;
16331    
16332                    try {
16333                            session = openSession();
16334    
16335                            WikiPage[] array = new WikiPageImpl[3];
16336    
16337                            array[0] = filterGetByG_N_T_H_PrevAndNext(session, wikiPage,
16338                                            groupId, nodeId, title, head, orderByComparator, true);
16339    
16340                            array[1] = wikiPage;
16341    
16342                            array[2] = filterGetByG_N_T_H_PrevAndNext(session, wikiPage,
16343                                            groupId, nodeId, title, head, orderByComparator, false);
16344    
16345                            return array;
16346                    }
16347                    catch (Exception e) {
16348                            throw processException(e);
16349                    }
16350                    finally {
16351                            closeSession(session);
16352                    }
16353            }
16354    
16355            protected WikiPage filterGetByG_N_T_H_PrevAndNext(Session session,
16356                    WikiPage wikiPage, long groupId, long nodeId, String title,
16357                    boolean head, OrderByComparator orderByComparator, boolean previous) {
16358                    StringBundler query = null;
16359    
16360                    if (orderByComparator != null) {
16361                            query = new StringBundler(6 +
16362                                            (orderByComparator.getOrderByFields().length * 6));
16363                    }
16364                    else {
16365                            query = new StringBundler(3);
16366                    }
16367    
16368                    if (getDB().isSupportsInlineDistinct()) {
16369                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
16370                    }
16371                    else {
16372                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
16373                    }
16374    
16375                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
16376    
16377                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
16378    
16379                    boolean bindTitle = false;
16380    
16381                    if (title == null) {
16382                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
16383                    }
16384                    else if (title.equals(StringPool.BLANK)) {
16385                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
16386                    }
16387                    else {
16388                            bindTitle = true;
16389    
16390                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
16391                    }
16392    
16393                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
16394    
16395                    if (!getDB().isSupportsInlineDistinct()) {
16396                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
16397                    }
16398    
16399                    if (orderByComparator != null) {
16400                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16401    
16402                            if (orderByConditionFields.length > 0) {
16403                                    query.append(WHERE_AND);
16404                            }
16405    
16406                            for (int i = 0; i < orderByConditionFields.length; i++) {
16407                                    if (getDB().isSupportsInlineDistinct()) {
16408                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16409                                    }
16410                                    else {
16411                                            query.append(_ORDER_BY_ENTITY_TABLE);
16412                                    }
16413    
16414                                    query.append(orderByConditionFields[i]);
16415    
16416                                    if ((i + 1) < orderByConditionFields.length) {
16417                                            if (orderByComparator.isAscending() ^ previous) {
16418                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16419                                            }
16420                                            else {
16421                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16422                                            }
16423                                    }
16424                                    else {
16425                                            if (orderByComparator.isAscending() ^ previous) {
16426                                                    query.append(WHERE_GREATER_THAN);
16427                                            }
16428                                            else {
16429                                                    query.append(WHERE_LESSER_THAN);
16430                                            }
16431                                    }
16432                            }
16433    
16434                            query.append(ORDER_BY_CLAUSE);
16435    
16436                            String[] orderByFields = orderByComparator.getOrderByFields();
16437    
16438                            for (int i = 0; i < orderByFields.length; i++) {
16439                                    if (getDB().isSupportsInlineDistinct()) {
16440                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16441                                    }
16442                                    else {
16443                                            query.append(_ORDER_BY_ENTITY_TABLE);
16444                                    }
16445    
16446                                    query.append(orderByFields[i]);
16447    
16448                                    if ((i + 1) < orderByFields.length) {
16449                                            if (orderByComparator.isAscending() ^ previous) {
16450                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16451                                            }
16452                                            else {
16453                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16454                                            }
16455                                    }
16456                                    else {
16457                                            if (orderByComparator.isAscending() ^ previous) {
16458                                                    query.append(ORDER_BY_ASC);
16459                                            }
16460                                            else {
16461                                                    query.append(ORDER_BY_DESC);
16462                                            }
16463                                    }
16464                            }
16465                    }
16466                    else {
16467                            if (getDB().isSupportsInlineDistinct()) {
16468                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16469                            }
16470                            else {
16471                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
16472                            }
16473                    }
16474    
16475                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16476                                    WikiPage.class.getName(),
16477                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16478    
16479                    SQLQuery q = session.createSQLQuery(sql);
16480    
16481                    q.setFirstResult(0);
16482                    q.setMaxResults(2);
16483    
16484                    if (getDB().isSupportsInlineDistinct()) {
16485                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
16486                    }
16487                    else {
16488                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
16489                    }
16490    
16491                    QueryPos qPos = QueryPos.getInstance(q);
16492    
16493                    qPos.add(groupId);
16494    
16495                    qPos.add(nodeId);
16496    
16497                    if (bindTitle) {
16498                            qPos.add(title.toLowerCase());
16499                    }
16500    
16501                    qPos.add(head);
16502    
16503                    if (orderByComparator != null) {
16504                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
16505    
16506                            for (Object value : values) {
16507                                    qPos.add(value);
16508                            }
16509                    }
16510    
16511                    List<WikiPage> list = q.list();
16512    
16513                    if (list.size() == 2) {
16514                            return list.get(1);
16515                    }
16516                    else {
16517                            return null;
16518                    }
16519            }
16520    
16521            /**
16522             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63; from the database.
16523             *
16524             * @param groupId the group ID
16525             * @param nodeId the node ID
16526             * @param title the title
16527             * @param head the head
16528             * @throws SystemException if a system exception occurred
16529             */
16530            @Override
16531            public void removeByG_N_T_H(long groupId, long nodeId, String title,
16532                    boolean head) throws SystemException {
16533                    for (WikiPage wikiPage : findByG_N_T_H(groupId, nodeId, title, head,
16534                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16535                            remove(wikiPage);
16536                    }
16537            }
16538    
16539            /**
16540             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and title = &#63; and head = &#63;.
16541             *
16542             * @param groupId the group ID
16543             * @param nodeId the node ID
16544             * @param title the title
16545             * @param head the head
16546             * @return the number of matching wiki pages
16547             * @throws SystemException if a system exception occurred
16548             */
16549            @Override
16550            public int countByG_N_T_H(long groupId, long nodeId, String title,
16551                    boolean head) throws SystemException {
16552                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_T_H;
16553    
16554                    Object[] finderArgs = new Object[] { groupId, nodeId, title, head };
16555    
16556                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16557                                    this);
16558    
16559                    if (count == null) {
16560                            StringBundler query = new StringBundler(5);
16561    
16562                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
16563    
16564                            query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
16565    
16566                            query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
16567    
16568                            boolean bindTitle = false;
16569    
16570                            if (title == null) {
16571                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
16572                            }
16573                            else if (title.equals(StringPool.BLANK)) {
16574                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
16575                            }
16576                            else {
16577                                    bindTitle = true;
16578    
16579                                    query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
16580                            }
16581    
16582                            query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
16583    
16584                            String sql = query.toString();
16585    
16586                            Session session = null;
16587    
16588                            try {
16589                                    session = openSession();
16590    
16591                                    Query q = session.createQuery(sql);
16592    
16593                                    QueryPos qPos = QueryPos.getInstance(q);
16594    
16595                                    qPos.add(groupId);
16596    
16597                                    qPos.add(nodeId);
16598    
16599                                    if (bindTitle) {
16600                                            qPos.add(title.toLowerCase());
16601                                    }
16602    
16603                                    qPos.add(head);
16604    
16605                                    count = (Long)q.uniqueResult();
16606    
16607                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
16608                            }
16609                            catch (Exception e) {
16610                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16611    
16612                                    throw processException(e);
16613                            }
16614                            finally {
16615                                    closeSession(session);
16616                            }
16617                    }
16618    
16619                    return count.intValue();
16620            }
16621    
16622            /**
16623             * 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;.
16624             *
16625             * @param groupId the group ID
16626             * @param nodeId the node ID
16627             * @param title the title
16628             * @param head the head
16629             * @return the number of matching wiki pages that the user has permission to view
16630             * @throws SystemException if a system exception occurred
16631             */
16632            @Override
16633            public int filterCountByG_N_T_H(long groupId, long nodeId, String title,
16634                    boolean head) throws SystemException {
16635                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16636                            return countByG_N_T_H(groupId, nodeId, title, head);
16637                    }
16638    
16639                    StringBundler query = new StringBundler(5);
16640    
16641                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
16642    
16643                    query.append(_FINDER_COLUMN_G_N_T_H_GROUPID_2);
16644    
16645                    query.append(_FINDER_COLUMN_G_N_T_H_NODEID_2);
16646    
16647                    boolean bindTitle = false;
16648    
16649                    if (title == null) {
16650                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_1);
16651                    }
16652                    else if (title.equals(StringPool.BLANK)) {
16653                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_3);
16654                    }
16655                    else {
16656                            bindTitle = true;
16657    
16658                            query.append(_FINDER_COLUMN_G_N_T_H_TITLE_2);
16659                    }
16660    
16661                    query.append(_FINDER_COLUMN_G_N_T_H_HEAD_2);
16662    
16663                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16664                                    WikiPage.class.getName(),
16665                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16666    
16667                    Session session = null;
16668    
16669                    try {
16670                            session = openSession();
16671    
16672                            SQLQuery q = session.createSQLQuery(sql);
16673    
16674                            q.addScalar(COUNT_COLUMN_NAME,
16675                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16676    
16677                            QueryPos qPos = QueryPos.getInstance(q);
16678    
16679                            qPos.add(groupId);
16680    
16681                            qPos.add(nodeId);
16682    
16683                            if (bindTitle) {
16684                                    qPos.add(title.toLowerCase());
16685                            }
16686    
16687                            qPos.add(head);
16688    
16689                            Long count = (Long)q.uniqueResult();
16690    
16691                            return count.intValue();
16692                    }
16693                    catch (Exception e) {
16694                            throw processException(e);
16695                    }
16696                    finally {
16697                            closeSession(session);
16698                    }
16699            }
16700    
16701            private static final String _FINDER_COLUMN_G_N_T_H_GROUPID_2 = "wikiPage.groupId = ? AND ";
16702            private static final String _FINDER_COLUMN_G_N_T_H_NODEID_2 = "wikiPage.nodeId = ? AND ";
16703            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_1 = "wikiPage.title IS NULL AND ";
16704            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_2 = "lower(wikiPage.title) = ? AND ";
16705            private static final String _FINDER_COLUMN_G_N_T_H_TITLE_3 = "(wikiPage.title IS NULL OR wikiPage.title = '') AND ";
16706            private static final String _FINDER_COLUMN_G_N_T_H_HEAD_2 = "wikiPage.head = ?";
16707            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16708                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
16709                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H_S",
16710                            new String[] {
16711                                    Long.class.getName(), Long.class.getName(),
16712                                    Boolean.class.getName(), Integer.class.getName(),
16713                                    
16714                            Integer.class.getName(), Integer.class.getName(),
16715                                    OrderByComparator.class.getName()
16716                            });
16717            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S =
16718                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16719                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
16720                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H_S",
16721                            new String[] {
16722                                    Long.class.getName(), Long.class.getName(),
16723                                    Boolean.class.getName(), Integer.class.getName()
16724                            },
16725                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
16726                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
16727                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
16728                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
16729                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
16730                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
16731            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
16732                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16733                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H_S",
16734                            new String[] {
16735                                    Long.class.getName(), Long.class.getName(),
16736                                    Boolean.class.getName(), Integer.class.getName()
16737                            });
16738    
16739            /**
16740             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16741             *
16742             * @param groupId the group ID
16743             * @param nodeId the node ID
16744             * @param head the head
16745             * @param status the status
16746             * @return the matching wiki pages
16747             * @throws SystemException if a system exception occurred
16748             */
16749            @Override
16750            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
16751                    boolean head, int status) throws SystemException {
16752                    return findByG_N_H_S(groupId, nodeId, head, status, QueryUtil.ALL_POS,
16753                            QueryUtil.ALL_POS, null);
16754            }
16755    
16756            /**
16757             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16758             *
16759             * <p>
16760             * 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.
16761             * </p>
16762             *
16763             * @param groupId the group ID
16764             * @param nodeId the node ID
16765             * @param head the head
16766             * @param status the status
16767             * @param start the lower bound of the range of wiki pages
16768             * @param end the upper bound of the range of wiki pages (not inclusive)
16769             * @return the range of matching wiki pages
16770             * @throws SystemException if a system exception occurred
16771             */
16772            @Override
16773            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
16774                    boolean head, int status, int start, int end) throws SystemException {
16775                    return findByG_N_H_S(groupId, nodeId, head, status, start, end, null);
16776            }
16777    
16778            /**
16779             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16780             *
16781             * <p>
16782             * 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.
16783             * </p>
16784             *
16785             * @param groupId the group ID
16786             * @param nodeId the node ID
16787             * @param head the head
16788             * @param status the status
16789             * @param start the lower bound of the range of wiki pages
16790             * @param end the upper bound of the range of wiki pages (not inclusive)
16791             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16792             * @return the ordered range of matching wiki pages
16793             * @throws SystemException if a system exception occurred
16794             */
16795            @Override
16796            public List<WikiPage> findByG_N_H_S(long groupId, long nodeId,
16797                    boolean head, int status, int start, int end,
16798                    OrderByComparator orderByComparator) throws SystemException {
16799                    boolean pagination = true;
16800                    FinderPath finderPath = null;
16801                    Object[] finderArgs = null;
16802    
16803                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16804                                    (orderByComparator == null)) {
16805                            pagination = false;
16806                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S;
16807                            finderArgs = new Object[] { groupId, nodeId, head, status };
16808                    }
16809                    else {
16810                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_S;
16811                            finderArgs = new Object[] {
16812                                            groupId, nodeId, head, status,
16813                                            
16814                                            start, end, orderByComparator
16815                                    };
16816                    }
16817    
16818                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
16819                                    finderArgs, this);
16820    
16821                    if ((list != null) && !list.isEmpty()) {
16822                            for (WikiPage wikiPage : list) {
16823                                    if ((groupId != wikiPage.getGroupId()) ||
16824                                                    (nodeId != wikiPage.getNodeId()) ||
16825                                                    (head != wikiPage.getHead()) ||
16826                                                    (status != wikiPage.getStatus())) {
16827                                            list = null;
16828    
16829                                            break;
16830                                    }
16831                            }
16832                    }
16833    
16834                    if (list == null) {
16835                            StringBundler query = null;
16836    
16837                            if (orderByComparator != null) {
16838                                    query = new StringBundler(6 +
16839                                                    (orderByComparator.getOrderByFields().length * 3));
16840                            }
16841                            else {
16842                                    query = new StringBundler(6);
16843                            }
16844    
16845                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
16846    
16847                            query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
16848    
16849                            query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
16850    
16851                            query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
16852    
16853                            query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
16854    
16855                            if (orderByComparator != null) {
16856                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16857                                            orderByComparator);
16858                            }
16859                            else
16860                             if (pagination) {
16861                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
16862                            }
16863    
16864                            String sql = query.toString();
16865    
16866                            Session session = null;
16867    
16868                            try {
16869                                    session = openSession();
16870    
16871                                    Query q = session.createQuery(sql);
16872    
16873                                    QueryPos qPos = QueryPos.getInstance(q);
16874    
16875                                    qPos.add(groupId);
16876    
16877                                    qPos.add(nodeId);
16878    
16879                                    qPos.add(head);
16880    
16881                                    qPos.add(status);
16882    
16883                                    if (!pagination) {
16884                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
16885                                                            start, end, false);
16886    
16887                                            Collections.sort(list);
16888    
16889                                            list = new UnmodifiableList<WikiPage>(list);
16890                                    }
16891                                    else {
16892                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
16893                                                            start, end);
16894                                    }
16895    
16896                                    cacheResult(list);
16897    
16898                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
16899                            }
16900                            catch (Exception e) {
16901                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16902    
16903                                    throw processException(e);
16904                            }
16905                            finally {
16906                                    closeSession(session);
16907                            }
16908                    }
16909    
16910                    return list;
16911            }
16912    
16913            /**
16914             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16915             *
16916             * @param groupId the group ID
16917             * @param nodeId the node ID
16918             * @param head the head
16919             * @param status the status
16920             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16921             * @return the first matching wiki page
16922             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
16923             * @throws SystemException if a system exception occurred
16924             */
16925            @Override
16926            public WikiPage findByG_N_H_S_First(long groupId, long nodeId,
16927                    boolean head, int status, OrderByComparator orderByComparator)
16928                    throws NoSuchPageException, SystemException {
16929                    WikiPage wikiPage = fetchByG_N_H_S_First(groupId, nodeId, head, status,
16930                                    orderByComparator);
16931    
16932                    if (wikiPage != null) {
16933                            return wikiPage;
16934                    }
16935    
16936                    StringBundler msg = new StringBundler(10);
16937    
16938                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16939    
16940                    msg.append("groupId=");
16941                    msg.append(groupId);
16942    
16943                    msg.append(", nodeId=");
16944                    msg.append(nodeId);
16945    
16946                    msg.append(", head=");
16947                    msg.append(head);
16948    
16949                    msg.append(", status=");
16950                    msg.append(status);
16951    
16952                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16953    
16954                    throw new NoSuchPageException(msg.toString());
16955            }
16956    
16957            /**
16958             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16959             *
16960             * @param groupId the group ID
16961             * @param nodeId the node ID
16962             * @param head the head
16963             * @param status the status
16964             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16965             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
16966             * @throws SystemException if a system exception occurred
16967             */
16968            @Override
16969            public WikiPage fetchByG_N_H_S_First(long groupId, long nodeId,
16970                    boolean head, int status, OrderByComparator orderByComparator)
16971                    throws SystemException {
16972                    List<WikiPage> list = findByG_N_H_S(groupId, nodeId, head, status, 0,
16973                                    1, orderByComparator);
16974    
16975                    if (!list.isEmpty()) {
16976                            return list.get(0);
16977                    }
16978    
16979                    return null;
16980            }
16981    
16982            /**
16983             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
16984             *
16985             * @param groupId the group ID
16986             * @param nodeId the node ID
16987             * @param head the head
16988             * @param status the status
16989             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16990             * @return the last matching wiki page
16991             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
16992             * @throws SystemException if a system exception occurred
16993             */
16994            @Override
16995            public WikiPage findByG_N_H_S_Last(long groupId, long nodeId, boolean head,
16996                    int status, OrderByComparator orderByComparator)
16997                    throws NoSuchPageException, SystemException {
16998                    WikiPage wikiPage = fetchByG_N_H_S_Last(groupId, nodeId, head, status,
16999                                    orderByComparator);
17000    
17001                    if (wikiPage != null) {
17002                            return wikiPage;
17003                    }
17004    
17005                    StringBundler msg = new StringBundler(10);
17006    
17007                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17008    
17009                    msg.append("groupId=");
17010                    msg.append(groupId);
17011    
17012                    msg.append(", nodeId=");
17013                    msg.append(nodeId);
17014    
17015                    msg.append(", head=");
17016                    msg.append(head);
17017    
17018                    msg.append(", status=");
17019                    msg.append(status);
17020    
17021                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17022    
17023                    throw new NoSuchPageException(msg.toString());
17024            }
17025    
17026            /**
17027             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
17028             *
17029             * @param groupId the group ID
17030             * @param nodeId the node ID
17031             * @param head the head
17032             * @param status the status
17033             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17034             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
17035             * @throws SystemException if a system exception occurred
17036             */
17037            @Override
17038            public WikiPage fetchByG_N_H_S_Last(long groupId, long nodeId,
17039                    boolean head, int status, OrderByComparator orderByComparator)
17040                    throws SystemException {
17041                    int count = countByG_N_H_S(groupId, nodeId, head, status);
17042    
17043                    if (count == 0) {
17044                            return null;
17045                    }
17046    
17047                    List<WikiPage> list = findByG_N_H_S(groupId, nodeId, head, status,
17048                                    count - 1, count, orderByComparator);
17049    
17050                    if (!list.isEmpty()) {
17051                            return list.get(0);
17052                    }
17053    
17054                    return null;
17055            }
17056    
17057            /**
17058             * 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;.
17059             *
17060             * @param pageId the primary key of the current wiki page
17061             * @param groupId the group ID
17062             * @param nodeId the node ID
17063             * @param head the head
17064             * @param status the status
17065             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17066             * @return the previous, current, and next wiki page
17067             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17068             * @throws SystemException if a system exception occurred
17069             */
17070            @Override
17071            public WikiPage[] findByG_N_H_S_PrevAndNext(long pageId, long groupId,
17072                    long nodeId, boolean head, int status,
17073                    OrderByComparator orderByComparator)
17074                    throws NoSuchPageException, SystemException {
17075                    WikiPage wikiPage = findByPrimaryKey(pageId);
17076    
17077                    Session session = null;
17078    
17079                    try {
17080                            session = openSession();
17081    
17082                            WikiPage[] array = new WikiPageImpl[3];
17083    
17084                            array[0] = getByG_N_H_S_PrevAndNext(session, wikiPage, groupId,
17085                                            nodeId, head, status, orderByComparator, true);
17086    
17087                            array[1] = wikiPage;
17088    
17089                            array[2] = getByG_N_H_S_PrevAndNext(session, wikiPage, groupId,
17090                                            nodeId, head, status, orderByComparator, false);
17091    
17092                            return array;
17093                    }
17094                    catch (Exception e) {
17095                            throw processException(e);
17096                    }
17097                    finally {
17098                            closeSession(session);
17099                    }
17100            }
17101    
17102            protected WikiPage getByG_N_H_S_PrevAndNext(Session session,
17103                    WikiPage wikiPage, long groupId, long nodeId, boolean head, int status,
17104                    OrderByComparator orderByComparator, boolean previous) {
17105                    StringBundler query = null;
17106    
17107                    if (orderByComparator != null) {
17108                            query = new StringBundler(6 +
17109                                            (orderByComparator.getOrderByFields().length * 6));
17110                    }
17111                    else {
17112                            query = new StringBundler(3);
17113                    }
17114    
17115                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
17116    
17117                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
17118    
17119                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
17120    
17121                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
17122    
17123                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
17124    
17125                    if (orderByComparator != null) {
17126                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17127    
17128                            if (orderByConditionFields.length > 0) {
17129                                    query.append(WHERE_AND);
17130                            }
17131    
17132                            for (int i = 0; i < orderByConditionFields.length; i++) {
17133                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17134                                    query.append(orderByConditionFields[i]);
17135    
17136                                    if ((i + 1) < orderByConditionFields.length) {
17137                                            if (orderByComparator.isAscending() ^ previous) {
17138                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17139                                            }
17140                                            else {
17141                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17142                                            }
17143                                    }
17144                                    else {
17145                                            if (orderByComparator.isAscending() ^ previous) {
17146                                                    query.append(WHERE_GREATER_THAN);
17147                                            }
17148                                            else {
17149                                                    query.append(WHERE_LESSER_THAN);
17150                                            }
17151                                    }
17152                            }
17153    
17154                            query.append(ORDER_BY_CLAUSE);
17155    
17156                            String[] orderByFields = orderByComparator.getOrderByFields();
17157    
17158                            for (int i = 0; i < orderByFields.length; i++) {
17159                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17160                                    query.append(orderByFields[i]);
17161    
17162                                    if ((i + 1) < orderByFields.length) {
17163                                            if (orderByComparator.isAscending() ^ previous) {
17164                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17165                                            }
17166                                            else {
17167                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17168                                            }
17169                                    }
17170                                    else {
17171                                            if (orderByComparator.isAscending() ^ previous) {
17172                                                    query.append(ORDER_BY_ASC);
17173                                            }
17174                                            else {
17175                                                    query.append(ORDER_BY_DESC);
17176                                            }
17177                                    }
17178                            }
17179                    }
17180                    else {
17181                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
17182                    }
17183    
17184                    String sql = query.toString();
17185    
17186                    Query q = session.createQuery(sql);
17187    
17188                    q.setFirstResult(0);
17189                    q.setMaxResults(2);
17190    
17191                    QueryPos qPos = QueryPos.getInstance(q);
17192    
17193                    qPos.add(groupId);
17194    
17195                    qPos.add(nodeId);
17196    
17197                    qPos.add(head);
17198    
17199                    qPos.add(status);
17200    
17201                    if (orderByComparator != null) {
17202                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
17203    
17204                            for (Object value : values) {
17205                                    qPos.add(value);
17206                            }
17207                    }
17208    
17209                    List<WikiPage> list = q.list();
17210    
17211                    if (list.size() == 2) {
17212                            return list.get(1);
17213                    }
17214                    else {
17215                            return null;
17216                    }
17217            }
17218    
17219            /**
17220             * Returns all the wiki pages that the user has permission to view where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
17221             *
17222             * @param groupId the group ID
17223             * @param nodeId the node ID
17224             * @param head the head
17225             * @param status the status
17226             * @return the matching wiki pages that the user has permission to view
17227             * @throws SystemException if a system exception occurred
17228             */
17229            @Override
17230            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
17231                    boolean head, int status) throws SystemException {
17232                    return filterFindByG_N_H_S(groupId, nodeId, head, status,
17233                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17234            }
17235    
17236            /**
17237             * 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;.
17238             *
17239             * <p>
17240             * 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.
17241             * </p>
17242             *
17243             * @param groupId the group ID
17244             * @param nodeId the node ID
17245             * @param head the head
17246             * @param status the status
17247             * @param start the lower bound of the range of wiki pages
17248             * @param end the upper bound of the range of wiki pages (not inclusive)
17249             * @return the range of matching wiki pages that the user has permission to view
17250             * @throws SystemException if a system exception occurred
17251             */
17252            @Override
17253            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
17254                    boolean head, int status, int start, int end) throws SystemException {
17255                    return filterFindByG_N_H_S(groupId, nodeId, head, status, start, end,
17256                            null);
17257            }
17258    
17259            /**
17260             * 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;.
17261             *
17262             * <p>
17263             * 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.
17264             * </p>
17265             *
17266             * @param groupId the group ID
17267             * @param nodeId the node ID
17268             * @param head the head
17269             * @param status the status
17270             * @param start the lower bound of the range of wiki pages
17271             * @param end the upper bound of the range of wiki pages (not inclusive)
17272             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17273             * @return the ordered range of matching wiki pages that the user has permission to view
17274             * @throws SystemException if a system exception occurred
17275             */
17276            @Override
17277            public List<WikiPage> filterFindByG_N_H_S(long groupId, long nodeId,
17278                    boolean head, int status, int start, int end,
17279                    OrderByComparator orderByComparator) throws SystemException {
17280                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17281                            return findByG_N_H_S(groupId, nodeId, head, status, start, end,
17282                                    orderByComparator);
17283                    }
17284    
17285                    StringBundler query = null;
17286    
17287                    if (orderByComparator != null) {
17288                            query = new StringBundler(6 +
17289                                            (orderByComparator.getOrderByFields().length * 3));
17290                    }
17291                    else {
17292                            query = new StringBundler(6);
17293                    }
17294    
17295                    if (getDB().isSupportsInlineDistinct()) {
17296                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
17297                    }
17298                    else {
17299                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
17300                    }
17301    
17302                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
17303    
17304                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
17305    
17306                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
17307    
17308                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
17309    
17310                    if (!getDB().isSupportsInlineDistinct()) {
17311                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
17312                    }
17313    
17314                    if (orderByComparator != null) {
17315                            if (getDB().isSupportsInlineDistinct()) {
17316                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17317                                            orderByComparator, true);
17318                            }
17319                            else {
17320                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17321                                            orderByComparator, true);
17322                            }
17323                    }
17324                    else {
17325                            if (getDB().isSupportsInlineDistinct()) {
17326                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
17327                            }
17328                            else {
17329                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
17330                            }
17331                    }
17332    
17333                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17334                                    WikiPage.class.getName(),
17335                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17336    
17337                    Session session = null;
17338    
17339                    try {
17340                            session = openSession();
17341    
17342                            SQLQuery q = session.createSQLQuery(sql);
17343    
17344                            if (getDB().isSupportsInlineDistinct()) {
17345                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
17346                            }
17347                            else {
17348                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
17349                            }
17350    
17351                            QueryPos qPos = QueryPos.getInstance(q);
17352    
17353                            qPos.add(groupId);
17354    
17355                            qPos.add(nodeId);
17356    
17357                            qPos.add(head);
17358    
17359                            qPos.add(status);
17360    
17361                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
17362                    }
17363                    catch (Exception e) {
17364                            throw processException(e);
17365                    }
17366                    finally {
17367                            closeSession(session);
17368                    }
17369            }
17370    
17371            /**
17372             * 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;.
17373             *
17374             * @param pageId the primary key of the current wiki page
17375             * @param groupId the group ID
17376             * @param nodeId the node ID
17377             * @param head the head
17378             * @param status the status
17379             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17380             * @return the previous, current, and next wiki page
17381             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
17382             * @throws SystemException if a system exception occurred
17383             */
17384            @Override
17385            public WikiPage[] filterFindByG_N_H_S_PrevAndNext(long pageId,
17386                    long groupId, long nodeId, boolean head, int status,
17387                    OrderByComparator orderByComparator)
17388                    throws NoSuchPageException, SystemException {
17389                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17390                            return findByG_N_H_S_PrevAndNext(pageId, groupId, nodeId, head,
17391                                    status, orderByComparator);
17392                    }
17393    
17394                    WikiPage wikiPage = findByPrimaryKey(pageId);
17395    
17396                    Session session = null;
17397    
17398                    try {
17399                            session = openSession();
17400    
17401                            WikiPage[] array = new WikiPageImpl[3];
17402    
17403                            array[0] = filterGetByG_N_H_S_PrevAndNext(session, wikiPage,
17404                                            groupId, nodeId, head, status, orderByComparator, true);
17405    
17406                            array[1] = wikiPage;
17407    
17408                            array[2] = filterGetByG_N_H_S_PrevAndNext(session, wikiPage,
17409                                            groupId, nodeId, head, status, orderByComparator, false);
17410    
17411                            return array;
17412                    }
17413                    catch (Exception e) {
17414                            throw processException(e);
17415                    }
17416                    finally {
17417                            closeSession(session);
17418                    }
17419            }
17420    
17421            protected WikiPage filterGetByG_N_H_S_PrevAndNext(Session session,
17422                    WikiPage wikiPage, long groupId, long nodeId, boolean head, int status,
17423                    OrderByComparator orderByComparator, boolean previous) {
17424                    StringBundler query = null;
17425    
17426                    if (orderByComparator != null) {
17427                            query = new StringBundler(6 +
17428                                            (orderByComparator.getOrderByFields().length * 6));
17429                    }
17430                    else {
17431                            query = new StringBundler(3);
17432                    }
17433    
17434                    if (getDB().isSupportsInlineDistinct()) {
17435                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
17436                    }
17437                    else {
17438                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
17439                    }
17440    
17441                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
17442    
17443                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
17444    
17445                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
17446    
17447                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
17448    
17449                    if (!getDB().isSupportsInlineDistinct()) {
17450                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
17451                    }
17452    
17453                    if (orderByComparator != null) {
17454                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17455    
17456                            if (orderByConditionFields.length > 0) {
17457                                    query.append(WHERE_AND);
17458                            }
17459    
17460                            for (int i = 0; i < orderByConditionFields.length; i++) {
17461                                    if (getDB().isSupportsInlineDistinct()) {
17462                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17463                                    }
17464                                    else {
17465                                            query.append(_ORDER_BY_ENTITY_TABLE);
17466                                    }
17467    
17468                                    query.append(orderByConditionFields[i]);
17469    
17470                                    if ((i + 1) < orderByConditionFields.length) {
17471                                            if (orderByComparator.isAscending() ^ previous) {
17472                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17473                                            }
17474                                            else {
17475                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17476                                            }
17477                                    }
17478                                    else {
17479                                            if (orderByComparator.isAscending() ^ previous) {
17480                                                    query.append(WHERE_GREATER_THAN);
17481                                            }
17482                                            else {
17483                                                    query.append(WHERE_LESSER_THAN);
17484                                            }
17485                                    }
17486                            }
17487    
17488                            query.append(ORDER_BY_CLAUSE);
17489    
17490                            String[] orderByFields = orderByComparator.getOrderByFields();
17491    
17492                            for (int i = 0; i < orderByFields.length; i++) {
17493                                    if (getDB().isSupportsInlineDistinct()) {
17494                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17495                                    }
17496                                    else {
17497                                            query.append(_ORDER_BY_ENTITY_TABLE);
17498                                    }
17499    
17500                                    query.append(orderByFields[i]);
17501    
17502                                    if ((i + 1) < orderByFields.length) {
17503                                            if (orderByComparator.isAscending() ^ previous) {
17504                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17505                                            }
17506                                            else {
17507                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17508                                            }
17509                                    }
17510                                    else {
17511                                            if (orderByComparator.isAscending() ^ previous) {
17512                                                    query.append(ORDER_BY_ASC);
17513                                            }
17514                                            else {
17515                                                    query.append(ORDER_BY_DESC);
17516                                            }
17517                                    }
17518                            }
17519                    }
17520                    else {
17521                            if (getDB().isSupportsInlineDistinct()) {
17522                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
17523                            }
17524                            else {
17525                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
17526                            }
17527                    }
17528    
17529                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17530                                    WikiPage.class.getName(),
17531                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17532    
17533                    SQLQuery q = session.createSQLQuery(sql);
17534    
17535                    q.setFirstResult(0);
17536                    q.setMaxResults(2);
17537    
17538                    if (getDB().isSupportsInlineDistinct()) {
17539                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
17540                    }
17541                    else {
17542                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
17543                    }
17544    
17545                    QueryPos qPos = QueryPos.getInstance(q);
17546    
17547                    qPos.add(groupId);
17548    
17549                    qPos.add(nodeId);
17550    
17551                    qPos.add(head);
17552    
17553                    qPos.add(status);
17554    
17555                    if (orderByComparator != null) {
17556                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
17557    
17558                            for (Object value : values) {
17559                                    qPos.add(value);
17560                            }
17561                    }
17562    
17563                    List<WikiPage> list = q.list();
17564    
17565                    if (list.size() == 2) {
17566                            return list.get(1);
17567                    }
17568                    else {
17569                            return null;
17570                    }
17571            }
17572    
17573            /**
17574             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63; from the database.
17575             *
17576             * @param groupId the group ID
17577             * @param nodeId the node ID
17578             * @param head the head
17579             * @param status the status
17580             * @throws SystemException if a system exception occurred
17581             */
17582            @Override
17583            public void removeByG_N_H_S(long groupId, long nodeId, boolean head,
17584                    int status) throws SystemException {
17585                    for (WikiPage wikiPage : findByG_N_H_S(groupId, nodeId, head, status,
17586                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17587                            remove(wikiPage);
17588                    }
17589            }
17590    
17591            /**
17592             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and status = &#63;.
17593             *
17594             * @param groupId the group ID
17595             * @param nodeId the node ID
17596             * @param head the head
17597             * @param status the status
17598             * @return the number of matching wiki pages
17599             * @throws SystemException if a system exception occurred
17600             */
17601            @Override
17602            public int countByG_N_H_S(long groupId, long nodeId, boolean head,
17603                    int status) throws SystemException {
17604                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H_S;
17605    
17606                    Object[] finderArgs = new Object[] { groupId, nodeId, head, status };
17607    
17608                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
17609                                    this);
17610    
17611                    if (count == null) {
17612                            StringBundler query = new StringBundler(5);
17613    
17614                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
17615    
17616                            query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
17617    
17618                            query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
17619    
17620                            query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
17621    
17622                            query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
17623    
17624                            String sql = query.toString();
17625    
17626                            Session session = null;
17627    
17628                            try {
17629                                    session = openSession();
17630    
17631                                    Query q = session.createQuery(sql);
17632    
17633                                    QueryPos qPos = QueryPos.getInstance(q);
17634    
17635                                    qPos.add(groupId);
17636    
17637                                    qPos.add(nodeId);
17638    
17639                                    qPos.add(head);
17640    
17641                                    qPos.add(status);
17642    
17643                                    count = (Long)q.uniqueResult();
17644    
17645                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
17646                            }
17647                            catch (Exception e) {
17648                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17649    
17650                                    throw processException(e);
17651                            }
17652                            finally {
17653                                    closeSession(session);
17654                            }
17655                    }
17656    
17657                    return count.intValue();
17658            }
17659    
17660            /**
17661             * 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;.
17662             *
17663             * @param groupId the group ID
17664             * @param nodeId the node ID
17665             * @param head the head
17666             * @param status the status
17667             * @return the number of matching wiki pages that the user has permission to view
17668             * @throws SystemException if a system exception occurred
17669             */
17670            @Override
17671            public int filterCountByG_N_H_S(long groupId, long nodeId, boolean head,
17672                    int status) throws SystemException {
17673                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17674                            return countByG_N_H_S(groupId, nodeId, head, status);
17675                    }
17676    
17677                    StringBundler query = new StringBundler(5);
17678    
17679                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
17680    
17681                    query.append(_FINDER_COLUMN_G_N_H_S_GROUPID_2);
17682    
17683                    query.append(_FINDER_COLUMN_G_N_H_S_NODEID_2);
17684    
17685                    query.append(_FINDER_COLUMN_G_N_H_S_HEAD_2);
17686    
17687                    query.append(_FINDER_COLUMN_G_N_H_S_STATUS_2);
17688    
17689                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17690                                    WikiPage.class.getName(),
17691                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17692    
17693                    Session session = null;
17694    
17695                    try {
17696                            session = openSession();
17697    
17698                            SQLQuery q = session.createSQLQuery(sql);
17699    
17700                            q.addScalar(COUNT_COLUMN_NAME,
17701                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17702    
17703                            QueryPos qPos = QueryPos.getInstance(q);
17704    
17705                            qPos.add(groupId);
17706    
17707                            qPos.add(nodeId);
17708    
17709                            qPos.add(head);
17710    
17711                            qPos.add(status);
17712    
17713                            Long count = (Long)q.uniqueResult();
17714    
17715                            return count.intValue();
17716                    }
17717                    catch (Exception e) {
17718                            throw processException(e);
17719                    }
17720                    finally {
17721                            closeSession(session);
17722                    }
17723            }
17724    
17725            private static final String _FINDER_COLUMN_G_N_H_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
17726            private static final String _FINDER_COLUMN_G_N_H_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
17727            private static final String _FINDER_COLUMN_G_N_H_S_HEAD_2 = "wikiPage.head = ? AND ";
17728            private static final String _FINDER_COLUMN_G_N_H_S_STATUS_2 = "wikiPage.status = ?";
17729            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17730                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
17731                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_P_S",
17732                            new String[] {
17733                                    Long.class.getName(), Boolean.class.getName(),
17734                                    String.class.getName(), Integer.class.getName(),
17735                                    
17736                            Integer.class.getName(), Integer.class.getName(),
17737                                    OrderByComparator.class.getName()
17738                            });
17739            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S =
17740                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17741                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
17742                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_P_S",
17743                            new String[] {
17744                                    Long.class.getName(), Boolean.class.getName(),
17745                                    String.class.getName(), Integer.class.getName()
17746                            },
17747                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
17748                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
17749                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
17750                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
17751                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
17752                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
17753            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
17754                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17755                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_P_S",
17756                            new String[] {
17757                                    Long.class.getName(), Boolean.class.getName(),
17758                                    String.class.getName(), Integer.class.getName()
17759                            });
17760    
17761            /**
17762             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17763             *
17764             * @param nodeId the node ID
17765             * @param head the head
17766             * @param parentTitle the parent title
17767             * @param status the status
17768             * @return the matching wiki pages
17769             * @throws SystemException if a system exception occurred
17770             */
17771            @Override
17772            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
17773                    String parentTitle, int status) throws SystemException {
17774                    return findByN_H_P_S(nodeId, head, parentTitle, status,
17775                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17776            }
17777    
17778            /**
17779             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17780             *
17781             * <p>
17782             * 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.
17783             * </p>
17784             *
17785             * @param nodeId the node ID
17786             * @param head the head
17787             * @param parentTitle the parent title
17788             * @param status the status
17789             * @param start the lower bound of the range of wiki pages
17790             * @param end the upper bound of the range of wiki pages (not inclusive)
17791             * @return the range of matching wiki pages
17792             * @throws SystemException if a system exception occurred
17793             */
17794            @Override
17795            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
17796                    String parentTitle, int status, int start, int end)
17797                    throws SystemException {
17798                    return findByN_H_P_S(nodeId, head, parentTitle, status, start, end, null);
17799            }
17800    
17801            /**
17802             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17803             *
17804             * <p>
17805             * 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.
17806             * </p>
17807             *
17808             * @param nodeId the node ID
17809             * @param head the head
17810             * @param parentTitle the parent title
17811             * @param status the status
17812             * @param start the lower bound of the range of wiki pages
17813             * @param end the upper bound of the range of wiki pages (not inclusive)
17814             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17815             * @return the ordered range of matching wiki pages
17816             * @throws SystemException if a system exception occurred
17817             */
17818            @Override
17819            public List<WikiPage> findByN_H_P_S(long nodeId, boolean head,
17820                    String parentTitle, int status, int start, int end,
17821                    OrderByComparator orderByComparator) throws SystemException {
17822                    boolean pagination = true;
17823                    FinderPath finderPath = null;
17824                    Object[] finderArgs = null;
17825    
17826                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17827                                    (orderByComparator == null)) {
17828                            pagination = false;
17829                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S;
17830                            finderArgs = new Object[] { nodeId, head, parentTitle, status };
17831                    }
17832                    else {
17833                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_S;
17834                            finderArgs = new Object[] {
17835                                            nodeId, head, parentTitle, status,
17836                                            
17837                                            start, end, orderByComparator
17838                                    };
17839                    }
17840    
17841                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
17842                                    finderArgs, this);
17843    
17844                    if ((list != null) && !list.isEmpty()) {
17845                            for (WikiPage wikiPage : list) {
17846                                    if ((nodeId != wikiPage.getNodeId()) ||
17847                                                    (head != wikiPage.getHead()) ||
17848                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
17849                                                    (status != wikiPage.getStatus())) {
17850                                            list = null;
17851    
17852                                            break;
17853                                    }
17854                            }
17855                    }
17856    
17857                    if (list == null) {
17858                            StringBundler query = null;
17859    
17860                            if (orderByComparator != null) {
17861                                    query = new StringBundler(6 +
17862                                                    (orderByComparator.getOrderByFields().length * 3));
17863                            }
17864                            else {
17865                                    query = new StringBundler(6);
17866                            }
17867    
17868                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
17869    
17870                            query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
17871    
17872                            query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
17873    
17874                            boolean bindParentTitle = false;
17875    
17876                            if (parentTitle == null) {
17877                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
17878                            }
17879                            else if (parentTitle.equals(StringPool.BLANK)) {
17880                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
17881                            }
17882                            else {
17883                                    bindParentTitle = true;
17884    
17885                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
17886                            }
17887    
17888                            query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
17889    
17890                            if (orderByComparator != null) {
17891                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17892                                            orderByComparator);
17893                            }
17894                            else
17895                             if (pagination) {
17896                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
17897                            }
17898    
17899                            String sql = query.toString();
17900    
17901                            Session session = null;
17902    
17903                            try {
17904                                    session = openSession();
17905    
17906                                    Query q = session.createQuery(sql);
17907    
17908                                    QueryPos qPos = QueryPos.getInstance(q);
17909    
17910                                    qPos.add(nodeId);
17911    
17912                                    qPos.add(head);
17913    
17914                                    if (bindParentTitle) {
17915                                            qPos.add(parentTitle.toLowerCase());
17916                                    }
17917    
17918                                    qPos.add(status);
17919    
17920                                    if (!pagination) {
17921                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
17922                                                            start, end, false);
17923    
17924                                            Collections.sort(list);
17925    
17926                                            list = new UnmodifiableList<WikiPage>(list);
17927                                    }
17928                                    else {
17929                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
17930                                                            start, end);
17931                                    }
17932    
17933                                    cacheResult(list);
17934    
17935                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
17936                            }
17937                            catch (Exception e) {
17938                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17939    
17940                                    throw processException(e);
17941                            }
17942                            finally {
17943                                    closeSession(session);
17944                            }
17945                    }
17946    
17947                    return list;
17948            }
17949    
17950            /**
17951             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17952             *
17953             * @param nodeId the node ID
17954             * @param head the head
17955             * @param parentTitle the parent title
17956             * @param status the status
17957             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17958             * @return the first matching wiki page
17959             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
17960             * @throws SystemException if a system exception occurred
17961             */
17962            @Override
17963            public WikiPage findByN_H_P_S_First(long nodeId, boolean head,
17964                    String parentTitle, int status, OrderByComparator orderByComparator)
17965                    throws NoSuchPageException, SystemException {
17966                    WikiPage wikiPage = fetchByN_H_P_S_First(nodeId, head, parentTitle,
17967                                    status, orderByComparator);
17968    
17969                    if (wikiPage != null) {
17970                            return wikiPage;
17971                    }
17972    
17973                    StringBundler msg = new StringBundler(10);
17974    
17975                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17976    
17977                    msg.append("nodeId=");
17978                    msg.append(nodeId);
17979    
17980                    msg.append(", head=");
17981                    msg.append(head);
17982    
17983                    msg.append(", parentTitle=");
17984                    msg.append(parentTitle);
17985    
17986                    msg.append(", status=");
17987                    msg.append(status);
17988    
17989                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17990    
17991                    throw new NoSuchPageException(msg.toString());
17992            }
17993    
17994            /**
17995             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
17996             *
17997             * @param nodeId the node ID
17998             * @param head the head
17999             * @param parentTitle the parent title
18000             * @param status the status
18001             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18002             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
18003             * @throws SystemException if a system exception occurred
18004             */
18005            @Override
18006            public WikiPage fetchByN_H_P_S_First(long nodeId, boolean head,
18007                    String parentTitle, int status, OrderByComparator orderByComparator)
18008                    throws SystemException {
18009                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
18010                                    0, 1, orderByComparator);
18011    
18012                    if (!list.isEmpty()) {
18013                            return list.get(0);
18014                    }
18015    
18016                    return null;
18017            }
18018    
18019            /**
18020             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
18021             *
18022             * @param nodeId the node ID
18023             * @param head the head
18024             * @param parentTitle the parent title
18025             * @param status the status
18026             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18027             * @return the last matching wiki page
18028             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
18029             * @throws SystemException if a system exception occurred
18030             */
18031            @Override
18032            public WikiPage findByN_H_P_S_Last(long nodeId, boolean head,
18033                    String parentTitle, int status, OrderByComparator orderByComparator)
18034                    throws NoSuchPageException, SystemException {
18035                    WikiPage wikiPage = fetchByN_H_P_S_Last(nodeId, head, parentTitle,
18036                                    status, orderByComparator);
18037    
18038                    if (wikiPage != null) {
18039                            return wikiPage;
18040                    }
18041    
18042                    StringBundler msg = new StringBundler(10);
18043    
18044                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18045    
18046                    msg.append("nodeId=");
18047                    msg.append(nodeId);
18048    
18049                    msg.append(", head=");
18050                    msg.append(head);
18051    
18052                    msg.append(", parentTitle=");
18053                    msg.append(parentTitle);
18054    
18055                    msg.append(", status=");
18056                    msg.append(status);
18057    
18058                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18059    
18060                    throw new NoSuchPageException(msg.toString());
18061            }
18062    
18063            /**
18064             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
18065             *
18066             * @param nodeId the node ID
18067             * @param head the head
18068             * @param parentTitle the parent title
18069             * @param status the status
18070             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18071             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
18072             * @throws SystemException if a system exception occurred
18073             */
18074            @Override
18075            public WikiPage fetchByN_H_P_S_Last(long nodeId, boolean head,
18076                    String parentTitle, int status, OrderByComparator orderByComparator)
18077                    throws SystemException {
18078                    int count = countByN_H_P_S(nodeId, head, parentTitle, status);
18079    
18080                    if (count == 0) {
18081                            return null;
18082                    }
18083    
18084                    List<WikiPage> list = findByN_H_P_S(nodeId, head, parentTitle, status,
18085                                    count - 1, count, orderByComparator);
18086    
18087                    if (!list.isEmpty()) {
18088                            return list.get(0);
18089                    }
18090    
18091                    return null;
18092            }
18093    
18094            /**
18095             * 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;.
18096             *
18097             * @param pageId the primary key of the current wiki page
18098             * @param nodeId the node ID
18099             * @param head the head
18100             * @param parentTitle the parent title
18101             * @param status the status
18102             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18103             * @return the previous, current, and next wiki page
18104             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
18105             * @throws SystemException if a system exception occurred
18106             */
18107            @Override
18108            public WikiPage[] findByN_H_P_S_PrevAndNext(long pageId, long nodeId,
18109                    boolean head, String parentTitle, int status,
18110                    OrderByComparator orderByComparator)
18111                    throws NoSuchPageException, SystemException {
18112                    WikiPage wikiPage = findByPrimaryKey(pageId);
18113    
18114                    Session session = null;
18115    
18116                    try {
18117                            session = openSession();
18118    
18119                            WikiPage[] array = new WikiPageImpl[3];
18120    
18121                            array[0] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
18122                                            head, parentTitle, status, orderByComparator, true);
18123    
18124                            array[1] = wikiPage;
18125    
18126                            array[2] = getByN_H_P_S_PrevAndNext(session, wikiPage, nodeId,
18127                                            head, parentTitle, status, orderByComparator, false);
18128    
18129                            return array;
18130                    }
18131                    catch (Exception e) {
18132                            throw processException(e);
18133                    }
18134                    finally {
18135                            closeSession(session);
18136                    }
18137            }
18138    
18139            protected WikiPage getByN_H_P_S_PrevAndNext(Session session,
18140                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
18141                    int status, OrderByComparator orderByComparator, boolean previous) {
18142                    StringBundler query = null;
18143    
18144                    if (orderByComparator != null) {
18145                            query = new StringBundler(6 +
18146                                            (orderByComparator.getOrderByFields().length * 6));
18147                    }
18148                    else {
18149                            query = new StringBundler(3);
18150                    }
18151    
18152                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
18153    
18154                    query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
18155    
18156                    query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
18157    
18158                    boolean bindParentTitle = false;
18159    
18160                    if (parentTitle == null) {
18161                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
18162                    }
18163                    else if (parentTitle.equals(StringPool.BLANK)) {
18164                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
18165                    }
18166                    else {
18167                            bindParentTitle = true;
18168    
18169                            query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
18170                    }
18171    
18172                    query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
18173    
18174                    if (orderByComparator != null) {
18175                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18176    
18177                            if (orderByConditionFields.length > 0) {
18178                                    query.append(WHERE_AND);
18179                            }
18180    
18181                            for (int i = 0; i < orderByConditionFields.length; i++) {
18182                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18183                                    query.append(orderByConditionFields[i]);
18184    
18185                                    if ((i + 1) < orderByConditionFields.length) {
18186                                            if (orderByComparator.isAscending() ^ previous) {
18187                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18188                                            }
18189                                            else {
18190                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18191                                            }
18192                                    }
18193                                    else {
18194                                            if (orderByComparator.isAscending() ^ previous) {
18195                                                    query.append(WHERE_GREATER_THAN);
18196                                            }
18197                                            else {
18198                                                    query.append(WHERE_LESSER_THAN);
18199                                            }
18200                                    }
18201                            }
18202    
18203                            query.append(ORDER_BY_CLAUSE);
18204    
18205                            String[] orderByFields = orderByComparator.getOrderByFields();
18206    
18207                            for (int i = 0; i < orderByFields.length; i++) {
18208                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18209                                    query.append(orderByFields[i]);
18210    
18211                                    if ((i + 1) < orderByFields.length) {
18212                                            if (orderByComparator.isAscending() ^ previous) {
18213                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18214                                            }
18215                                            else {
18216                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18217                                            }
18218                                    }
18219                                    else {
18220                                            if (orderByComparator.isAscending() ^ previous) {
18221                                                    query.append(ORDER_BY_ASC);
18222                                            }
18223                                            else {
18224                                                    query.append(ORDER_BY_DESC);
18225                                            }
18226                                    }
18227                            }
18228                    }
18229                    else {
18230                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
18231                    }
18232    
18233                    String sql = query.toString();
18234    
18235                    Query q = session.createQuery(sql);
18236    
18237                    q.setFirstResult(0);
18238                    q.setMaxResults(2);
18239    
18240                    QueryPos qPos = QueryPos.getInstance(q);
18241    
18242                    qPos.add(nodeId);
18243    
18244                    qPos.add(head);
18245    
18246                    if (bindParentTitle) {
18247                            qPos.add(parentTitle.toLowerCase());
18248                    }
18249    
18250                    qPos.add(status);
18251    
18252                    if (orderByComparator != null) {
18253                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
18254    
18255                            for (Object value : values) {
18256                                    qPos.add(value);
18257                            }
18258                    }
18259    
18260                    List<WikiPage> list = q.list();
18261    
18262                    if (list.size() == 2) {
18263                            return list.get(1);
18264                    }
18265                    else {
18266                            return null;
18267                    }
18268            }
18269    
18270            /**
18271             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63; from the database.
18272             *
18273             * @param nodeId the node ID
18274             * @param head the head
18275             * @param parentTitle the parent title
18276             * @param status the status
18277             * @throws SystemException if a system exception occurred
18278             */
18279            @Override
18280            public void removeByN_H_P_S(long nodeId, boolean head, String parentTitle,
18281                    int status) throws SystemException {
18282                    for (WikiPage wikiPage : findByN_H_P_S(nodeId, head, parentTitle,
18283                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18284                            remove(wikiPage);
18285                    }
18286            }
18287    
18288            /**
18289             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
18290             *
18291             * @param nodeId the node ID
18292             * @param head the head
18293             * @param parentTitle the parent title
18294             * @param status the status
18295             * @return the number of matching wiki pages
18296             * @throws SystemException if a system exception occurred
18297             */
18298            @Override
18299            public int countByN_H_P_S(long nodeId, boolean head, String parentTitle,
18300                    int status) throws SystemException {
18301                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_P_S;
18302    
18303                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle, status };
18304    
18305                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18306                                    this);
18307    
18308                    if (count == null) {
18309                            StringBundler query = new StringBundler(5);
18310    
18311                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
18312    
18313                            query.append(_FINDER_COLUMN_N_H_P_S_NODEID_2);
18314    
18315                            query.append(_FINDER_COLUMN_N_H_P_S_HEAD_2);
18316    
18317                            boolean bindParentTitle = false;
18318    
18319                            if (parentTitle == null) {
18320                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_1);
18321                            }
18322                            else if (parentTitle.equals(StringPool.BLANK)) {
18323                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_3);
18324                            }
18325                            else {
18326                                    bindParentTitle = true;
18327    
18328                                    query.append(_FINDER_COLUMN_N_H_P_S_PARENTTITLE_2);
18329                            }
18330    
18331                            query.append(_FINDER_COLUMN_N_H_P_S_STATUS_2);
18332    
18333                            String sql = query.toString();
18334    
18335                            Session session = null;
18336    
18337                            try {
18338                                    session = openSession();
18339    
18340                                    Query q = session.createQuery(sql);
18341    
18342                                    QueryPos qPos = QueryPos.getInstance(q);
18343    
18344                                    qPos.add(nodeId);
18345    
18346                                    qPos.add(head);
18347    
18348                                    if (bindParentTitle) {
18349                                            qPos.add(parentTitle.toLowerCase());
18350                                    }
18351    
18352                                    qPos.add(status);
18353    
18354                                    count = (Long)q.uniqueResult();
18355    
18356                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
18357                            }
18358                            catch (Exception e) {
18359                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18360    
18361                                    throw processException(e);
18362                            }
18363                            finally {
18364                                    closeSession(session);
18365                            }
18366                    }
18367    
18368                    return count.intValue();
18369            }
18370    
18371            private static final String _FINDER_COLUMN_N_H_P_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
18372            private static final String _FINDER_COLUMN_N_H_P_S_HEAD_2 = "wikiPage.head = ? AND ";
18373            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
18374            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ? AND ";
18375            private static final String _FINDER_COLUMN_N_H_P_S_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '') AND ";
18376            private static final String _FINDER_COLUMN_N_H_P_S_STATUS_2 = "wikiPage.status = ?";
18377            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_NOTS =
18378                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18379                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
18380                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_P_NotS",
18381                            new String[] {
18382                                    Long.class.getName(), Boolean.class.getName(),
18383                                    String.class.getName(), Integer.class.getName(),
18384                                    
18385                            Integer.class.getName(), Integer.class.getName(),
18386                                    OrderByComparator.class.getName()
18387                            });
18388            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_N_H_P_NOTS =
18389                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
18390                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
18391                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByN_H_P_NotS",
18392                            new String[] {
18393                                    Long.class.getName(), Boolean.class.getName(),
18394                                    String.class.getName(), Integer.class.getName()
18395                            });
18396    
18397            /**
18398             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
18399             *
18400             * @param nodeId the node ID
18401             * @param head the head
18402             * @param parentTitle the parent title
18403             * @param status the status
18404             * @return the matching wiki pages
18405             * @throws SystemException if a system exception occurred
18406             */
18407            @Override
18408            public List<WikiPage> findByN_H_P_NotS(long nodeId, boolean head,
18409                    String parentTitle, int status) throws SystemException {
18410                    return findByN_H_P_NotS(nodeId, head, parentTitle, status,
18411                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18412            }
18413    
18414            /**
18415             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
18416             *
18417             * <p>
18418             * 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.
18419             * </p>
18420             *
18421             * @param nodeId the node ID
18422             * @param head the head
18423             * @param parentTitle the parent title
18424             * @param status the status
18425             * @param start the lower bound of the range of wiki pages
18426             * @param end the upper bound of the range of wiki pages (not inclusive)
18427             * @return the range of matching wiki pages
18428             * @throws SystemException if a system exception occurred
18429             */
18430            @Override
18431            public List<WikiPage> findByN_H_P_NotS(long nodeId, boolean head,
18432                    String parentTitle, int status, int start, int end)
18433                    throws SystemException {
18434                    return findByN_H_P_NotS(nodeId, head, parentTitle, status, start, end,
18435                            null);
18436            }
18437    
18438            /**
18439             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
18440             *
18441             * <p>
18442             * 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.
18443             * </p>
18444             *
18445             * @param nodeId the node ID
18446             * @param head the head
18447             * @param parentTitle the parent title
18448             * @param status the status
18449             * @param start the lower bound of the range of wiki pages
18450             * @param end the upper bound of the range of wiki pages (not inclusive)
18451             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18452             * @return the ordered range of matching wiki pages
18453             * @throws SystemException if a system exception occurred
18454             */
18455            @Override
18456            public List<WikiPage> findByN_H_P_NotS(long nodeId, boolean head,
18457                    String parentTitle, int status, int start, int end,
18458                    OrderByComparator orderByComparator) throws SystemException {
18459                    boolean pagination = true;
18460                    FinderPath finderPath = null;
18461                    Object[] finderArgs = null;
18462    
18463                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_P_NOTS;
18464                    finderArgs = new Object[] {
18465                                    nodeId, head, parentTitle, status,
18466                                    
18467                                    start, end, orderByComparator
18468                            };
18469    
18470                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
18471                                    finderArgs, this);
18472    
18473                    if ((list != null) && !list.isEmpty()) {
18474                            for (WikiPage wikiPage : list) {
18475                                    if ((nodeId != wikiPage.getNodeId()) ||
18476                                                    (head != wikiPage.getHead()) ||
18477                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
18478                                                    (status == wikiPage.getStatus())) {
18479                                            list = null;
18480    
18481                                            break;
18482                                    }
18483                            }
18484                    }
18485    
18486                    if (list == null) {
18487                            StringBundler query = null;
18488    
18489                            if (orderByComparator != null) {
18490                                    query = new StringBundler(6 +
18491                                                    (orderByComparator.getOrderByFields().length * 3));
18492                            }
18493                            else {
18494                                    query = new StringBundler(6);
18495                            }
18496    
18497                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
18498    
18499                            query.append(_FINDER_COLUMN_N_H_P_NOTS_NODEID_2);
18500    
18501                            query.append(_FINDER_COLUMN_N_H_P_NOTS_HEAD_2);
18502    
18503                            boolean bindParentTitle = false;
18504    
18505                            if (parentTitle == null) {
18506                                    query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_1);
18507                            }
18508                            else if (parentTitle.equals(StringPool.BLANK)) {
18509                                    query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_3);
18510                            }
18511                            else {
18512                                    bindParentTitle = true;
18513    
18514                                    query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_2);
18515                            }
18516    
18517                            query.append(_FINDER_COLUMN_N_H_P_NOTS_STATUS_2);
18518    
18519                            if (orderByComparator != null) {
18520                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18521                                            orderByComparator);
18522                            }
18523                            else
18524                             if (pagination) {
18525                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
18526                            }
18527    
18528                            String sql = query.toString();
18529    
18530                            Session session = null;
18531    
18532                            try {
18533                                    session = openSession();
18534    
18535                                    Query q = session.createQuery(sql);
18536    
18537                                    QueryPos qPos = QueryPos.getInstance(q);
18538    
18539                                    qPos.add(nodeId);
18540    
18541                                    qPos.add(head);
18542    
18543                                    if (bindParentTitle) {
18544                                            qPos.add(parentTitle.toLowerCase());
18545                                    }
18546    
18547                                    qPos.add(status);
18548    
18549                                    if (!pagination) {
18550                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
18551                                                            start, end, false);
18552    
18553                                            Collections.sort(list);
18554    
18555                                            list = new UnmodifiableList<WikiPage>(list);
18556                                    }
18557                                    else {
18558                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
18559                                                            start, end);
18560                                    }
18561    
18562                                    cacheResult(list);
18563    
18564                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
18565                            }
18566                            catch (Exception e) {
18567                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18568    
18569                                    throw processException(e);
18570                            }
18571                            finally {
18572                                    closeSession(session);
18573                            }
18574                    }
18575    
18576                    return list;
18577            }
18578    
18579            /**
18580             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
18581             *
18582             * @param nodeId the node ID
18583             * @param head the head
18584             * @param parentTitle the parent title
18585             * @param status the status
18586             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18587             * @return the first matching wiki page
18588             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
18589             * @throws SystemException if a system exception occurred
18590             */
18591            @Override
18592            public WikiPage findByN_H_P_NotS_First(long nodeId, boolean head,
18593                    String parentTitle, int status, OrderByComparator orderByComparator)
18594                    throws NoSuchPageException, SystemException {
18595                    WikiPage wikiPage = fetchByN_H_P_NotS_First(nodeId, head, parentTitle,
18596                                    status, orderByComparator);
18597    
18598                    if (wikiPage != null) {
18599                            return wikiPage;
18600                    }
18601    
18602                    StringBundler msg = new StringBundler(10);
18603    
18604                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18605    
18606                    msg.append("nodeId=");
18607                    msg.append(nodeId);
18608    
18609                    msg.append(", head=");
18610                    msg.append(head);
18611    
18612                    msg.append(", parentTitle=");
18613                    msg.append(parentTitle);
18614    
18615                    msg.append(", status=");
18616                    msg.append(status);
18617    
18618                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18619    
18620                    throw new NoSuchPageException(msg.toString());
18621            }
18622    
18623            /**
18624             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
18625             *
18626             * @param nodeId the node ID
18627             * @param head the head
18628             * @param parentTitle the parent title
18629             * @param status the status
18630             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18631             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
18632             * @throws SystemException if a system exception occurred
18633             */
18634            @Override
18635            public WikiPage fetchByN_H_P_NotS_First(long nodeId, boolean head,
18636                    String parentTitle, int status, OrderByComparator orderByComparator)
18637                    throws SystemException {
18638                    List<WikiPage> list = findByN_H_P_NotS(nodeId, head, parentTitle,
18639                                    status, 0, 1, orderByComparator);
18640    
18641                    if (!list.isEmpty()) {
18642                            return list.get(0);
18643                    }
18644    
18645                    return null;
18646            }
18647    
18648            /**
18649             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
18650             *
18651             * @param nodeId the node ID
18652             * @param head the head
18653             * @param parentTitle the parent title
18654             * @param status the status
18655             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18656             * @return the last matching wiki page
18657             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
18658             * @throws SystemException if a system exception occurred
18659             */
18660            @Override
18661            public WikiPage findByN_H_P_NotS_Last(long nodeId, boolean head,
18662                    String parentTitle, int status, OrderByComparator orderByComparator)
18663                    throws NoSuchPageException, SystemException {
18664                    WikiPage wikiPage = fetchByN_H_P_NotS_Last(nodeId, head, parentTitle,
18665                                    status, orderByComparator);
18666    
18667                    if (wikiPage != null) {
18668                            return wikiPage;
18669                    }
18670    
18671                    StringBundler msg = new StringBundler(10);
18672    
18673                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18674    
18675                    msg.append("nodeId=");
18676                    msg.append(nodeId);
18677    
18678                    msg.append(", head=");
18679                    msg.append(head);
18680    
18681                    msg.append(", parentTitle=");
18682                    msg.append(parentTitle);
18683    
18684                    msg.append(", status=");
18685                    msg.append(status);
18686    
18687                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18688    
18689                    throw new NoSuchPageException(msg.toString());
18690            }
18691    
18692            /**
18693             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
18694             *
18695             * @param nodeId the node ID
18696             * @param head the head
18697             * @param parentTitle the parent title
18698             * @param status the status
18699             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18700             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
18701             * @throws SystemException if a system exception occurred
18702             */
18703            @Override
18704            public WikiPage fetchByN_H_P_NotS_Last(long nodeId, boolean head,
18705                    String parentTitle, int status, OrderByComparator orderByComparator)
18706                    throws SystemException {
18707                    int count = countByN_H_P_NotS(nodeId, head, parentTitle, status);
18708    
18709                    if (count == 0) {
18710                            return null;
18711                    }
18712    
18713                    List<WikiPage> list = findByN_H_P_NotS(nodeId, head, parentTitle,
18714                                    status, count - 1, count, orderByComparator);
18715    
18716                    if (!list.isEmpty()) {
18717                            return list.get(0);
18718                    }
18719    
18720                    return null;
18721            }
18722    
18723            /**
18724             * 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 &ne; &#63;.
18725             *
18726             * @param pageId the primary key of the current wiki page
18727             * @param nodeId the node ID
18728             * @param head the head
18729             * @param parentTitle the parent title
18730             * @param status the status
18731             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18732             * @return the previous, current, and next wiki page
18733             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
18734             * @throws SystemException if a system exception occurred
18735             */
18736            @Override
18737            public WikiPage[] findByN_H_P_NotS_PrevAndNext(long pageId, long nodeId,
18738                    boolean head, String parentTitle, int status,
18739                    OrderByComparator orderByComparator)
18740                    throws NoSuchPageException, SystemException {
18741                    WikiPage wikiPage = findByPrimaryKey(pageId);
18742    
18743                    Session session = null;
18744    
18745                    try {
18746                            session = openSession();
18747    
18748                            WikiPage[] array = new WikiPageImpl[3];
18749    
18750                            array[0] = getByN_H_P_NotS_PrevAndNext(session, wikiPage, nodeId,
18751                                            head, parentTitle, status, orderByComparator, true);
18752    
18753                            array[1] = wikiPage;
18754    
18755                            array[2] = getByN_H_P_NotS_PrevAndNext(session, wikiPage, nodeId,
18756                                            head, parentTitle, status, orderByComparator, false);
18757    
18758                            return array;
18759                    }
18760                    catch (Exception e) {
18761                            throw processException(e);
18762                    }
18763                    finally {
18764                            closeSession(session);
18765                    }
18766            }
18767    
18768            protected WikiPage getByN_H_P_NotS_PrevAndNext(Session session,
18769                    WikiPage wikiPage, long nodeId, boolean head, String parentTitle,
18770                    int status, OrderByComparator orderByComparator, boolean previous) {
18771                    StringBundler query = null;
18772    
18773                    if (orderByComparator != null) {
18774                            query = new StringBundler(6 +
18775                                            (orderByComparator.getOrderByFields().length * 6));
18776                    }
18777                    else {
18778                            query = new StringBundler(3);
18779                    }
18780    
18781                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
18782    
18783                    query.append(_FINDER_COLUMN_N_H_P_NOTS_NODEID_2);
18784    
18785                    query.append(_FINDER_COLUMN_N_H_P_NOTS_HEAD_2);
18786    
18787                    boolean bindParentTitle = false;
18788    
18789                    if (parentTitle == null) {
18790                            query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_1);
18791                    }
18792                    else if (parentTitle.equals(StringPool.BLANK)) {
18793                            query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_3);
18794                    }
18795                    else {
18796                            bindParentTitle = true;
18797    
18798                            query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_2);
18799                    }
18800    
18801                    query.append(_FINDER_COLUMN_N_H_P_NOTS_STATUS_2);
18802    
18803                    if (orderByComparator != null) {
18804                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18805    
18806                            if (orderByConditionFields.length > 0) {
18807                                    query.append(WHERE_AND);
18808                            }
18809    
18810                            for (int i = 0; i < orderByConditionFields.length; i++) {
18811                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18812                                    query.append(orderByConditionFields[i]);
18813    
18814                                    if ((i + 1) < orderByConditionFields.length) {
18815                                            if (orderByComparator.isAscending() ^ previous) {
18816                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18817                                            }
18818                                            else {
18819                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18820                                            }
18821                                    }
18822                                    else {
18823                                            if (orderByComparator.isAscending() ^ previous) {
18824                                                    query.append(WHERE_GREATER_THAN);
18825                                            }
18826                                            else {
18827                                                    query.append(WHERE_LESSER_THAN);
18828                                            }
18829                                    }
18830                            }
18831    
18832                            query.append(ORDER_BY_CLAUSE);
18833    
18834                            String[] orderByFields = orderByComparator.getOrderByFields();
18835    
18836                            for (int i = 0; i < orderByFields.length; i++) {
18837                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18838                                    query.append(orderByFields[i]);
18839    
18840                                    if ((i + 1) < orderByFields.length) {
18841                                            if (orderByComparator.isAscending() ^ previous) {
18842                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18843                                            }
18844                                            else {
18845                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18846                                            }
18847                                    }
18848                                    else {
18849                                            if (orderByComparator.isAscending() ^ previous) {
18850                                                    query.append(ORDER_BY_ASC);
18851                                            }
18852                                            else {
18853                                                    query.append(ORDER_BY_DESC);
18854                                            }
18855                                    }
18856                            }
18857                    }
18858                    else {
18859                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
18860                    }
18861    
18862                    String sql = query.toString();
18863    
18864                    Query q = session.createQuery(sql);
18865    
18866                    q.setFirstResult(0);
18867                    q.setMaxResults(2);
18868    
18869                    QueryPos qPos = QueryPos.getInstance(q);
18870    
18871                    qPos.add(nodeId);
18872    
18873                    qPos.add(head);
18874    
18875                    if (bindParentTitle) {
18876                            qPos.add(parentTitle.toLowerCase());
18877                    }
18878    
18879                    qPos.add(status);
18880    
18881                    if (orderByComparator != null) {
18882                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
18883    
18884                            for (Object value : values) {
18885                                    qPos.add(value);
18886                            }
18887                    }
18888    
18889                    List<WikiPage> list = q.list();
18890    
18891                    if (list.size() == 2) {
18892                            return list.get(1);
18893                    }
18894                    else {
18895                            return null;
18896                    }
18897            }
18898    
18899            /**
18900             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63; from the database.
18901             *
18902             * @param nodeId the node ID
18903             * @param head the head
18904             * @param parentTitle the parent title
18905             * @param status the status
18906             * @throws SystemException if a system exception occurred
18907             */
18908            @Override
18909            public void removeByN_H_P_NotS(long nodeId, boolean head,
18910                    String parentTitle, int status) throws SystemException {
18911                    for (WikiPage wikiPage : findByN_H_P_NotS(nodeId, head, parentTitle,
18912                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18913                            remove(wikiPage);
18914                    }
18915            }
18916    
18917            /**
18918             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and parentTitle = &#63; and status &ne; &#63;.
18919             *
18920             * @param nodeId the node ID
18921             * @param head the head
18922             * @param parentTitle the parent title
18923             * @param status the status
18924             * @return the number of matching wiki pages
18925             * @throws SystemException if a system exception occurred
18926             */
18927            @Override
18928            public int countByN_H_P_NotS(long nodeId, boolean head, String parentTitle,
18929                    int status) throws SystemException {
18930                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_N_H_P_NOTS;
18931    
18932                    Object[] finderArgs = new Object[] { nodeId, head, parentTitle, status };
18933    
18934                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18935                                    this);
18936    
18937                    if (count == null) {
18938                            StringBundler query = new StringBundler(5);
18939    
18940                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
18941    
18942                            query.append(_FINDER_COLUMN_N_H_P_NOTS_NODEID_2);
18943    
18944                            query.append(_FINDER_COLUMN_N_H_P_NOTS_HEAD_2);
18945    
18946                            boolean bindParentTitle = false;
18947    
18948                            if (parentTitle == null) {
18949                                    query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_1);
18950                            }
18951                            else if (parentTitle.equals(StringPool.BLANK)) {
18952                                    query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_3);
18953                            }
18954                            else {
18955                                    bindParentTitle = true;
18956    
18957                                    query.append(_FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_2);
18958                            }
18959    
18960                            query.append(_FINDER_COLUMN_N_H_P_NOTS_STATUS_2);
18961    
18962                            String sql = query.toString();
18963    
18964                            Session session = null;
18965    
18966                            try {
18967                                    session = openSession();
18968    
18969                                    Query q = session.createQuery(sql);
18970    
18971                                    QueryPos qPos = QueryPos.getInstance(q);
18972    
18973                                    qPos.add(nodeId);
18974    
18975                                    qPos.add(head);
18976    
18977                                    if (bindParentTitle) {
18978                                            qPos.add(parentTitle.toLowerCase());
18979                                    }
18980    
18981                                    qPos.add(status);
18982    
18983                                    count = (Long)q.uniqueResult();
18984    
18985                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
18986                            }
18987                            catch (Exception e) {
18988                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18989    
18990                                    throw processException(e);
18991                            }
18992                            finally {
18993                                    closeSession(session);
18994                            }
18995                    }
18996    
18997                    return count.intValue();
18998            }
18999    
19000            private static final String _FINDER_COLUMN_N_H_P_NOTS_NODEID_2 = "wikiPage.nodeId = ? AND ";
19001            private static final String _FINDER_COLUMN_N_H_P_NOTS_HEAD_2 = "wikiPage.head = ? AND ";
19002            private static final String _FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
19003            private static final String _FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ? AND ";
19004            private static final String _FINDER_COLUMN_N_H_P_NOTS_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '') AND ";
19005            private static final String _FINDER_COLUMN_N_H_P_NOTS_STATUS_2 = "wikiPage.status != ?";
19006            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_R_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19007                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
19008                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_R_S",
19009                            new String[] {
19010                                    Long.class.getName(), Boolean.class.getName(),
19011                                    String.class.getName(), Integer.class.getName(),
19012                                    
19013                            Integer.class.getName(), Integer.class.getName(),
19014                                    OrderByComparator.class.getName()
19015                            });
19016            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R_S =
19017                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19018                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
19019                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByN_H_R_S",
19020                            new String[] {
19021                                    Long.class.getName(), Boolean.class.getName(),
19022                                    String.class.getName(), Integer.class.getName()
19023                            },
19024                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
19025                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
19026                            WikiPageModelImpl.REDIRECTTITLE_COLUMN_BITMASK |
19027                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
19028                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
19029                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
19030            public static final FinderPath FINDER_PATH_COUNT_BY_N_H_R_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19031                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
19032                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_H_R_S",
19033                            new String[] {
19034                                    Long.class.getName(), Boolean.class.getName(),
19035                                    String.class.getName(), Integer.class.getName()
19036                            });
19037    
19038            /**
19039             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
19040             *
19041             * @param nodeId the node ID
19042             * @param head the head
19043             * @param redirectTitle the redirect title
19044             * @param status the status
19045             * @return the matching wiki pages
19046             * @throws SystemException if a system exception occurred
19047             */
19048            @Override
19049            public List<WikiPage> findByN_H_R_S(long nodeId, boolean head,
19050                    String redirectTitle, int status) throws SystemException {
19051                    return findByN_H_R_S(nodeId, head, redirectTitle, status,
19052                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19053            }
19054    
19055            /**
19056             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
19057             *
19058             * <p>
19059             * 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.
19060             * </p>
19061             *
19062             * @param nodeId the node ID
19063             * @param head the head
19064             * @param redirectTitle the redirect title
19065             * @param status the status
19066             * @param start the lower bound of the range of wiki pages
19067             * @param end the upper bound of the range of wiki pages (not inclusive)
19068             * @return the range of matching wiki pages
19069             * @throws SystemException if a system exception occurred
19070             */
19071            @Override
19072            public List<WikiPage> findByN_H_R_S(long nodeId, boolean head,
19073                    String redirectTitle, int status, int start, int end)
19074                    throws SystemException {
19075                    return findByN_H_R_S(nodeId, head, redirectTitle, status, start, end,
19076                            null);
19077            }
19078    
19079            /**
19080             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
19081             *
19082             * <p>
19083             * 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.
19084             * </p>
19085             *
19086             * @param nodeId the node ID
19087             * @param head the head
19088             * @param redirectTitle the redirect title
19089             * @param status the status
19090             * @param start the lower bound of the range of wiki pages
19091             * @param end the upper bound of the range of wiki pages (not inclusive)
19092             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19093             * @return the ordered range of matching wiki pages
19094             * @throws SystemException if a system exception occurred
19095             */
19096            @Override
19097            public List<WikiPage> findByN_H_R_S(long nodeId, boolean head,
19098                    String redirectTitle, int status, int start, int end,
19099                    OrderByComparator orderByComparator) throws SystemException {
19100                    boolean pagination = true;
19101                    FinderPath finderPath = null;
19102                    Object[] finderArgs = null;
19103    
19104                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
19105                                    (orderByComparator == null)) {
19106                            pagination = false;
19107                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R_S;
19108                            finderArgs = new Object[] { nodeId, head, redirectTitle, status };
19109                    }
19110                    else {
19111                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_R_S;
19112                            finderArgs = new Object[] {
19113                                            nodeId, head, redirectTitle, status,
19114                                            
19115                                            start, end, orderByComparator
19116                                    };
19117                    }
19118    
19119                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
19120                                    finderArgs, this);
19121    
19122                    if ((list != null) && !list.isEmpty()) {
19123                            for (WikiPage wikiPage : list) {
19124                                    if ((nodeId != wikiPage.getNodeId()) ||
19125                                                    (head != wikiPage.getHead()) ||
19126                                                    !Validator.equals(redirectTitle,
19127                                                            wikiPage.getRedirectTitle()) ||
19128                                                    (status != wikiPage.getStatus())) {
19129                                            list = null;
19130    
19131                                            break;
19132                                    }
19133                            }
19134                    }
19135    
19136                    if (list == null) {
19137                            StringBundler query = null;
19138    
19139                            if (orderByComparator != null) {
19140                                    query = new StringBundler(6 +
19141                                                    (orderByComparator.getOrderByFields().length * 3));
19142                            }
19143                            else {
19144                                    query = new StringBundler(6);
19145                            }
19146    
19147                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
19148    
19149                            query.append(_FINDER_COLUMN_N_H_R_S_NODEID_2);
19150    
19151                            query.append(_FINDER_COLUMN_N_H_R_S_HEAD_2);
19152    
19153                            boolean bindRedirectTitle = false;
19154    
19155                            if (redirectTitle == null) {
19156                                    query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_1);
19157                            }
19158                            else if (redirectTitle.equals(StringPool.BLANK)) {
19159                                    query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_3);
19160                            }
19161                            else {
19162                                    bindRedirectTitle = true;
19163    
19164                                    query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_2);
19165                            }
19166    
19167                            query.append(_FINDER_COLUMN_N_H_R_S_STATUS_2);
19168    
19169                            if (orderByComparator != null) {
19170                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19171                                            orderByComparator);
19172                            }
19173                            else
19174                             if (pagination) {
19175                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
19176                            }
19177    
19178                            String sql = query.toString();
19179    
19180                            Session session = null;
19181    
19182                            try {
19183                                    session = openSession();
19184    
19185                                    Query q = session.createQuery(sql);
19186    
19187                                    QueryPos qPos = QueryPos.getInstance(q);
19188    
19189                                    qPos.add(nodeId);
19190    
19191                                    qPos.add(head);
19192    
19193                                    if (bindRedirectTitle) {
19194                                            qPos.add(redirectTitle.toLowerCase());
19195                                    }
19196    
19197                                    qPos.add(status);
19198    
19199                                    if (!pagination) {
19200                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
19201                                                            start, end, false);
19202    
19203                                            Collections.sort(list);
19204    
19205                                            list = new UnmodifiableList<WikiPage>(list);
19206                                    }
19207                                    else {
19208                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
19209                                                            start, end);
19210                                    }
19211    
19212                                    cacheResult(list);
19213    
19214                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
19215                            }
19216                            catch (Exception e) {
19217                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19218    
19219                                    throw processException(e);
19220                            }
19221                            finally {
19222                                    closeSession(session);
19223                            }
19224                    }
19225    
19226                    return list;
19227            }
19228    
19229            /**
19230             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
19231             *
19232             * @param nodeId the node ID
19233             * @param head the head
19234             * @param redirectTitle the redirect title
19235             * @param status the status
19236             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19237             * @return the first matching wiki page
19238             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
19239             * @throws SystemException if a system exception occurred
19240             */
19241            @Override
19242            public WikiPage findByN_H_R_S_First(long nodeId, boolean head,
19243                    String redirectTitle, int status, OrderByComparator orderByComparator)
19244                    throws NoSuchPageException, SystemException {
19245                    WikiPage wikiPage = fetchByN_H_R_S_First(nodeId, head, redirectTitle,
19246                                    status, orderByComparator);
19247    
19248                    if (wikiPage != null) {
19249                            return wikiPage;
19250                    }
19251    
19252                    StringBundler msg = new StringBundler(10);
19253    
19254                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
19255    
19256                    msg.append("nodeId=");
19257                    msg.append(nodeId);
19258    
19259                    msg.append(", head=");
19260                    msg.append(head);
19261    
19262                    msg.append(", redirectTitle=");
19263                    msg.append(redirectTitle);
19264    
19265                    msg.append(", status=");
19266                    msg.append(status);
19267    
19268                    msg.append(StringPool.CLOSE_CURLY_BRACE);
19269    
19270                    throw new NoSuchPageException(msg.toString());
19271            }
19272    
19273            /**
19274             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
19275             *
19276             * @param nodeId the node ID
19277             * @param head the head
19278             * @param redirectTitle the redirect title
19279             * @param status the status
19280             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19281             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
19282             * @throws SystemException if a system exception occurred
19283             */
19284            @Override
19285            public WikiPage fetchByN_H_R_S_First(long nodeId, boolean head,
19286                    String redirectTitle, int status, OrderByComparator orderByComparator)
19287                    throws SystemException {
19288                    List<WikiPage> list = findByN_H_R_S(nodeId, head, redirectTitle,
19289                                    status, 0, 1, orderByComparator);
19290    
19291                    if (!list.isEmpty()) {
19292                            return list.get(0);
19293                    }
19294    
19295                    return null;
19296            }
19297    
19298            /**
19299             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
19300             *
19301             * @param nodeId the node ID
19302             * @param head the head
19303             * @param redirectTitle the redirect title
19304             * @param status the status
19305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19306             * @return the last matching wiki page
19307             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
19308             * @throws SystemException if a system exception occurred
19309             */
19310            @Override
19311            public WikiPage findByN_H_R_S_Last(long nodeId, boolean head,
19312                    String redirectTitle, int status, OrderByComparator orderByComparator)
19313                    throws NoSuchPageException, SystemException {
19314                    WikiPage wikiPage = fetchByN_H_R_S_Last(nodeId, head, redirectTitle,
19315                                    status, orderByComparator);
19316    
19317                    if (wikiPage != null) {
19318                            return wikiPage;
19319                    }
19320    
19321                    StringBundler msg = new StringBundler(10);
19322    
19323                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
19324    
19325                    msg.append("nodeId=");
19326                    msg.append(nodeId);
19327    
19328                    msg.append(", head=");
19329                    msg.append(head);
19330    
19331                    msg.append(", redirectTitle=");
19332                    msg.append(redirectTitle);
19333    
19334                    msg.append(", status=");
19335                    msg.append(status);
19336    
19337                    msg.append(StringPool.CLOSE_CURLY_BRACE);
19338    
19339                    throw new NoSuchPageException(msg.toString());
19340            }
19341    
19342            /**
19343             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
19344             *
19345             * @param nodeId the node ID
19346             * @param head the head
19347             * @param redirectTitle the redirect title
19348             * @param status the status
19349             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19350             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
19351             * @throws SystemException if a system exception occurred
19352             */
19353            @Override
19354            public WikiPage fetchByN_H_R_S_Last(long nodeId, boolean head,
19355                    String redirectTitle, int status, OrderByComparator orderByComparator)
19356                    throws SystemException {
19357                    int count = countByN_H_R_S(nodeId, head, redirectTitle, status);
19358    
19359                    if (count == 0) {
19360                            return null;
19361                    }
19362    
19363                    List<WikiPage> list = findByN_H_R_S(nodeId, head, redirectTitle,
19364                                    status, count - 1, count, orderByComparator);
19365    
19366                    if (!list.isEmpty()) {
19367                            return list.get(0);
19368                    }
19369    
19370                    return null;
19371            }
19372    
19373            /**
19374             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
19375             *
19376             * @param pageId the primary key of the current wiki page
19377             * @param nodeId the node ID
19378             * @param head the head
19379             * @param redirectTitle the redirect title
19380             * @param status the status
19381             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19382             * @return the previous, current, and next wiki page
19383             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
19384             * @throws SystemException if a system exception occurred
19385             */
19386            @Override
19387            public WikiPage[] findByN_H_R_S_PrevAndNext(long pageId, long nodeId,
19388                    boolean head, String redirectTitle, int status,
19389                    OrderByComparator orderByComparator)
19390                    throws NoSuchPageException, SystemException {
19391                    WikiPage wikiPage = findByPrimaryKey(pageId);
19392    
19393                    Session session = null;
19394    
19395                    try {
19396                            session = openSession();
19397    
19398                            WikiPage[] array = new WikiPageImpl[3];
19399    
19400                            array[0] = getByN_H_R_S_PrevAndNext(session, wikiPage, nodeId,
19401                                            head, redirectTitle, status, orderByComparator, true);
19402    
19403                            array[1] = wikiPage;
19404    
19405                            array[2] = getByN_H_R_S_PrevAndNext(session, wikiPage, nodeId,
19406                                            head, redirectTitle, status, orderByComparator, false);
19407    
19408                            return array;
19409                    }
19410                    catch (Exception e) {
19411                            throw processException(e);
19412                    }
19413                    finally {
19414                            closeSession(session);
19415                    }
19416            }
19417    
19418            protected WikiPage getByN_H_R_S_PrevAndNext(Session session,
19419                    WikiPage wikiPage, long nodeId, boolean head, String redirectTitle,
19420                    int status, OrderByComparator orderByComparator, boolean previous) {
19421                    StringBundler query = null;
19422    
19423                    if (orderByComparator != null) {
19424                            query = new StringBundler(6 +
19425                                            (orderByComparator.getOrderByFields().length * 6));
19426                    }
19427                    else {
19428                            query = new StringBundler(3);
19429                    }
19430    
19431                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
19432    
19433                    query.append(_FINDER_COLUMN_N_H_R_S_NODEID_2);
19434    
19435                    query.append(_FINDER_COLUMN_N_H_R_S_HEAD_2);
19436    
19437                    boolean bindRedirectTitle = false;
19438    
19439                    if (redirectTitle == null) {
19440                            query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_1);
19441                    }
19442                    else if (redirectTitle.equals(StringPool.BLANK)) {
19443                            query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_3);
19444                    }
19445                    else {
19446                            bindRedirectTitle = true;
19447    
19448                            query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_2);
19449                    }
19450    
19451                    query.append(_FINDER_COLUMN_N_H_R_S_STATUS_2);
19452    
19453                    if (orderByComparator != null) {
19454                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
19455    
19456                            if (orderByConditionFields.length > 0) {
19457                                    query.append(WHERE_AND);
19458                            }
19459    
19460                            for (int i = 0; i < orderByConditionFields.length; i++) {
19461                                    query.append(_ORDER_BY_ENTITY_ALIAS);
19462                                    query.append(orderByConditionFields[i]);
19463    
19464                                    if ((i + 1) < orderByConditionFields.length) {
19465                                            if (orderByComparator.isAscending() ^ previous) {
19466                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
19467                                            }
19468                                            else {
19469                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
19470                                            }
19471                                    }
19472                                    else {
19473                                            if (orderByComparator.isAscending() ^ previous) {
19474                                                    query.append(WHERE_GREATER_THAN);
19475                                            }
19476                                            else {
19477                                                    query.append(WHERE_LESSER_THAN);
19478                                            }
19479                                    }
19480                            }
19481    
19482                            query.append(ORDER_BY_CLAUSE);
19483    
19484                            String[] orderByFields = orderByComparator.getOrderByFields();
19485    
19486                            for (int i = 0; i < orderByFields.length; i++) {
19487                                    query.append(_ORDER_BY_ENTITY_ALIAS);
19488                                    query.append(orderByFields[i]);
19489    
19490                                    if ((i + 1) < orderByFields.length) {
19491                                            if (orderByComparator.isAscending() ^ previous) {
19492                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
19493                                            }
19494                                            else {
19495                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
19496                                            }
19497                                    }
19498                                    else {
19499                                            if (orderByComparator.isAscending() ^ previous) {
19500                                                    query.append(ORDER_BY_ASC);
19501                                            }
19502                                            else {
19503                                                    query.append(ORDER_BY_DESC);
19504                                            }
19505                                    }
19506                            }
19507                    }
19508                    else {
19509                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
19510                    }
19511    
19512                    String sql = query.toString();
19513    
19514                    Query q = session.createQuery(sql);
19515    
19516                    q.setFirstResult(0);
19517                    q.setMaxResults(2);
19518    
19519                    QueryPos qPos = QueryPos.getInstance(q);
19520    
19521                    qPos.add(nodeId);
19522    
19523                    qPos.add(head);
19524    
19525                    if (bindRedirectTitle) {
19526                            qPos.add(redirectTitle.toLowerCase());
19527                    }
19528    
19529                    qPos.add(status);
19530    
19531                    if (orderByComparator != null) {
19532                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
19533    
19534                            for (Object value : values) {
19535                                    qPos.add(value);
19536                            }
19537                    }
19538    
19539                    List<WikiPage> list = q.list();
19540    
19541                    if (list.size() == 2) {
19542                            return list.get(1);
19543                    }
19544                    else {
19545                            return null;
19546                    }
19547            }
19548    
19549            /**
19550             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63; from the database.
19551             *
19552             * @param nodeId the node ID
19553             * @param head the head
19554             * @param redirectTitle the redirect title
19555             * @param status the status
19556             * @throws SystemException if a system exception occurred
19557             */
19558            @Override
19559            public void removeByN_H_R_S(long nodeId, boolean head,
19560                    String redirectTitle, int status) throws SystemException {
19561                    for (WikiPage wikiPage : findByN_H_R_S(nodeId, head, redirectTitle,
19562                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
19563                            remove(wikiPage);
19564                    }
19565            }
19566    
19567            /**
19568             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status = &#63;.
19569             *
19570             * @param nodeId the node ID
19571             * @param head the head
19572             * @param redirectTitle the redirect title
19573             * @param status the status
19574             * @return the number of matching wiki pages
19575             * @throws SystemException if a system exception occurred
19576             */
19577            @Override
19578            public int countByN_H_R_S(long nodeId, boolean head, String redirectTitle,
19579                    int status) throws SystemException {
19580                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_H_R_S;
19581    
19582                    Object[] finderArgs = new Object[] { nodeId, head, redirectTitle, status };
19583    
19584                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
19585                                    this);
19586    
19587                    if (count == null) {
19588                            StringBundler query = new StringBundler(5);
19589    
19590                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
19591    
19592                            query.append(_FINDER_COLUMN_N_H_R_S_NODEID_2);
19593    
19594                            query.append(_FINDER_COLUMN_N_H_R_S_HEAD_2);
19595    
19596                            boolean bindRedirectTitle = false;
19597    
19598                            if (redirectTitle == null) {
19599                                    query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_1);
19600                            }
19601                            else if (redirectTitle.equals(StringPool.BLANK)) {
19602                                    query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_3);
19603                            }
19604                            else {
19605                                    bindRedirectTitle = true;
19606    
19607                                    query.append(_FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_2);
19608                            }
19609    
19610                            query.append(_FINDER_COLUMN_N_H_R_S_STATUS_2);
19611    
19612                            String sql = query.toString();
19613    
19614                            Session session = null;
19615    
19616                            try {
19617                                    session = openSession();
19618    
19619                                    Query q = session.createQuery(sql);
19620    
19621                                    QueryPos qPos = QueryPos.getInstance(q);
19622    
19623                                    qPos.add(nodeId);
19624    
19625                                    qPos.add(head);
19626    
19627                                    if (bindRedirectTitle) {
19628                                            qPos.add(redirectTitle.toLowerCase());
19629                                    }
19630    
19631                                    qPos.add(status);
19632    
19633                                    count = (Long)q.uniqueResult();
19634    
19635                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
19636                            }
19637                            catch (Exception e) {
19638                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19639    
19640                                    throw processException(e);
19641                            }
19642                            finally {
19643                                    closeSession(session);
19644                            }
19645                    }
19646    
19647                    return count.intValue();
19648            }
19649    
19650            private static final String _FINDER_COLUMN_N_H_R_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
19651            private static final String _FINDER_COLUMN_N_H_R_S_HEAD_2 = "wikiPage.head = ? AND ";
19652            private static final String _FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_1 = "wikiPage.redirectTitle IS NULL AND ";
19653            private static final String _FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_2 = "lower(wikiPage.redirectTitle) = ? AND ";
19654            private static final String _FINDER_COLUMN_N_H_R_S_REDIRECTTITLE_3 = "(wikiPage.redirectTitle IS NULL OR wikiPage.redirectTitle = '') AND ";
19655            private static final String _FINDER_COLUMN_N_H_R_S_STATUS_2 = "wikiPage.status = ?";
19656            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_R_NOTS =
19657                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19658                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
19659                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByN_H_R_NotS",
19660                            new String[] {
19661                                    Long.class.getName(), Boolean.class.getName(),
19662                                    String.class.getName(), Integer.class.getName(),
19663                                    
19664                            Integer.class.getName(), Integer.class.getName(),
19665                                    OrderByComparator.class.getName()
19666                            });
19667            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_N_H_R_NOTS =
19668                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
19669                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
19670                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByN_H_R_NotS",
19671                            new String[] {
19672                                    Long.class.getName(), Boolean.class.getName(),
19673                                    String.class.getName(), Integer.class.getName()
19674                            });
19675    
19676            /**
19677             * Returns all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19678             *
19679             * @param nodeId the node ID
19680             * @param head the head
19681             * @param redirectTitle the redirect title
19682             * @param status the status
19683             * @return the matching wiki pages
19684             * @throws SystemException if a system exception occurred
19685             */
19686            @Override
19687            public List<WikiPage> findByN_H_R_NotS(long nodeId, boolean head,
19688                    String redirectTitle, int status) throws SystemException {
19689                    return findByN_H_R_NotS(nodeId, head, redirectTitle, status,
19690                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19691            }
19692    
19693            /**
19694             * Returns a range of all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19695             *
19696             * <p>
19697             * 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.
19698             * </p>
19699             *
19700             * @param nodeId the node ID
19701             * @param head the head
19702             * @param redirectTitle the redirect title
19703             * @param status the status
19704             * @param start the lower bound of the range of wiki pages
19705             * @param end the upper bound of the range of wiki pages (not inclusive)
19706             * @return the range of matching wiki pages
19707             * @throws SystemException if a system exception occurred
19708             */
19709            @Override
19710            public List<WikiPage> findByN_H_R_NotS(long nodeId, boolean head,
19711                    String redirectTitle, int status, int start, int end)
19712                    throws SystemException {
19713                    return findByN_H_R_NotS(nodeId, head, redirectTitle, status, start,
19714                            end, null);
19715            }
19716    
19717            /**
19718             * Returns an ordered range of all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19719             *
19720             * <p>
19721             * 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.
19722             * </p>
19723             *
19724             * @param nodeId the node ID
19725             * @param head the head
19726             * @param redirectTitle the redirect title
19727             * @param status the status
19728             * @param start the lower bound of the range of wiki pages
19729             * @param end the upper bound of the range of wiki pages (not inclusive)
19730             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19731             * @return the ordered range of matching wiki pages
19732             * @throws SystemException if a system exception occurred
19733             */
19734            @Override
19735            public List<WikiPage> findByN_H_R_NotS(long nodeId, boolean head,
19736                    String redirectTitle, int status, int start, int end,
19737                    OrderByComparator orderByComparator) throws SystemException {
19738                    boolean pagination = true;
19739                    FinderPath finderPath = null;
19740                    Object[] finderArgs = null;
19741    
19742                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_H_R_NOTS;
19743                    finderArgs = new Object[] {
19744                                    nodeId, head, redirectTitle, status,
19745                                    
19746                                    start, end, orderByComparator
19747                            };
19748    
19749                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
19750                                    finderArgs, this);
19751    
19752                    if ((list != null) && !list.isEmpty()) {
19753                            for (WikiPage wikiPage : list) {
19754                                    if ((nodeId != wikiPage.getNodeId()) ||
19755                                                    (head != wikiPage.getHead()) ||
19756                                                    !Validator.equals(redirectTitle,
19757                                                            wikiPage.getRedirectTitle()) ||
19758                                                    (status == wikiPage.getStatus())) {
19759                                            list = null;
19760    
19761                                            break;
19762                                    }
19763                            }
19764                    }
19765    
19766                    if (list == null) {
19767                            StringBundler query = null;
19768    
19769                            if (orderByComparator != null) {
19770                                    query = new StringBundler(6 +
19771                                                    (orderByComparator.getOrderByFields().length * 3));
19772                            }
19773                            else {
19774                                    query = new StringBundler(6);
19775                            }
19776    
19777                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
19778    
19779                            query.append(_FINDER_COLUMN_N_H_R_NOTS_NODEID_2);
19780    
19781                            query.append(_FINDER_COLUMN_N_H_R_NOTS_HEAD_2);
19782    
19783                            boolean bindRedirectTitle = false;
19784    
19785                            if (redirectTitle == null) {
19786                                    query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_1);
19787                            }
19788                            else if (redirectTitle.equals(StringPool.BLANK)) {
19789                                    query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_3);
19790                            }
19791                            else {
19792                                    bindRedirectTitle = true;
19793    
19794                                    query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_2);
19795                            }
19796    
19797                            query.append(_FINDER_COLUMN_N_H_R_NOTS_STATUS_2);
19798    
19799                            if (orderByComparator != null) {
19800                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19801                                            orderByComparator);
19802                            }
19803                            else
19804                             if (pagination) {
19805                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
19806                            }
19807    
19808                            String sql = query.toString();
19809    
19810                            Session session = null;
19811    
19812                            try {
19813                                    session = openSession();
19814    
19815                                    Query q = session.createQuery(sql);
19816    
19817                                    QueryPos qPos = QueryPos.getInstance(q);
19818    
19819                                    qPos.add(nodeId);
19820    
19821                                    qPos.add(head);
19822    
19823                                    if (bindRedirectTitle) {
19824                                            qPos.add(redirectTitle.toLowerCase());
19825                                    }
19826    
19827                                    qPos.add(status);
19828    
19829                                    if (!pagination) {
19830                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
19831                                                            start, end, false);
19832    
19833                                            Collections.sort(list);
19834    
19835                                            list = new UnmodifiableList<WikiPage>(list);
19836                                    }
19837                                    else {
19838                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
19839                                                            start, end);
19840                                    }
19841    
19842                                    cacheResult(list);
19843    
19844                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
19845                            }
19846                            catch (Exception e) {
19847                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19848    
19849                                    throw processException(e);
19850                            }
19851                            finally {
19852                                    closeSession(session);
19853                            }
19854                    }
19855    
19856                    return list;
19857            }
19858    
19859            /**
19860             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19861             *
19862             * @param nodeId the node ID
19863             * @param head the head
19864             * @param redirectTitle the redirect title
19865             * @param status the status
19866             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19867             * @return the first matching wiki page
19868             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
19869             * @throws SystemException if a system exception occurred
19870             */
19871            @Override
19872            public WikiPage findByN_H_R_NotS_First(long nodeId, boolean head,
19873                    String redirectTitle, int status, OrderByComparator orderByComparator)
19874                    throws NoSuchPageException, SystemException {
19875                    WikiPage wikiPage = fetchByN_H_R_NotS_First(nodeId, head,
19876                                    redirectTitle, status, orderByComparator);
19877    
19878                    if (wikiPage != null) {
19879                            return wikiPage;
19880                    }
19881    
19882                    StringBundler msg = new StringBundler(10);
19883    
19884                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
19885    
19886                    msg.append("nodeId=");
19887                    msg.append(nodeId);
19888    
19889                    msg.append(", head=");
19890                    msg.append(head);
19891    
19892                    msg.append(", redirectTitle=");
19893                    msg.append(redirectTitle);
19894    
19895                    msg.append(", status=");
19896                    msg.append(status);
19897    
19898                    msg.append(StringPool.CLOSE_CURLY_BRACE);
19899    
19900                    throw new NoSuchPageException(msg.toString());
19901            }
19902    
19903            /**
19904             * Returns the first wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19905             *
19906             * @param nodeId the node ID
19907             * @param head the head
19908             * @param redirectTitle the redirect title
19909             * @param status the status
19910             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19911             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
19912             * @throws SystemException if a system exception occurred
19913             */
19914            @Override
19915            public WikiPage fetchByN_H_R_NotS_First(long nodeId, boolean head,
19916                    String redirectTitle, int status, OrderByComparator orderByComparator)
19917                    throws SystemException {
19918                    List<WikiPage> list = findByN_H_R_NotS(nodeId, head, redirectTitle,
19919                                    status, 0, 1, orderByComparator);
19920    
19921                    if (!list.isEmpty()) {
19922                            return list.get(0);
19923                    }
19924    
19925                    return null;
19926            }
19927    
19928            /**
19929             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19930             *
19931             * @param nodeId the node ID
19932             * @param head the head
19933             * @param redirectTitle the redirect title
19934             * @param status the status
19935             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19936             * @return the last matching wiki page
19937             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
19938             * @throws SystemException if a system exception occurred
19939             */
19940            @Override
19941            public WikiPage findByN_H_R_NotS_Last(long nodeId, boolean head,
19942                    String redirectTitle, int status, OrderByComparator orderByComparator)
19943                    throws NoSuchPageException, SystemException {
19944                    WikiPage wikiPage = fetchByN_H_R_NotS_Last(nodeId, head, redirectTitle,
19945                                    status, orderByComparator);
19946    
19947                    if (wikiPage != null) {
19948                            return wikiPage;
19949                    }
19950    
19951                    StringBundler msg = new StringBundler(10);
19952    
19953                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
19954    
19955                    msg.append("nodeId=");
19956                    msg.append(nodeId);
19957    
19958                    msg.append(", head=");
19959                    msg.append(head);
19960    
19961                    msg.append(", redirectTitle=");
19962                    msg.append(redirectTitle);
19963    
19964                    msg.append(", status=");
19965                    msg.append(status);
19966    
19967                    msg.append(StringPool.CLOSE_CURLY_BRACE);
19968    
19969                    throw new NoSuchPageException(msg.toString());
19970            }
19971    
19972            /**
19973             * Returns the last wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
19974             *
19975             * @param nodeId the node ID
19976             * @param head the head
19977             * @param redirectTitle the redirect title
19978             * @param status the status
19979             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19980             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
19981             * @throws SystemException if a system exception occurred
19982             */
19983            @Override
19984            public WikiPage fetchByN_H_R_NotS_Last(long nodeId, boolean head,
19985                    String redirectTitle, int status, OrderByComparator orderByComparator)
19986                    throws SystemException {
19987                    int count = countByN_H_R_NotS(nodeId, head, redirectTitle, status);
19988    
19989                    if (count == 0) {
19990                            return null;
19991                    }
19992    
19993                    List<WikiPage> list = findByN_H_R_NotS(nodeId, head, redirectTitle,
19994                                    status, count - 1, count, orderByComparator);
19995    
19996                    if (!list.isEmpty()) {
19997                            return list.get(0);
19998                    }
19999    
20000                    return null;
20001            }
20002    
20003            /**
20004             * Returns the wiki pages before and after the current wiki page in the ordered set where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
20005             *
20006             * @param pageId the primary key of the current wiki page
20007             * @param nodeId the node ID
20008             * @param head the head
20009             * @param redirectTitle the redirect title
20010             * @param status the status
20011             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20012             * @return the previous, current, and next wiki page
20013             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
20014             * @throws SystemException if a system exception occurred
20015             */
20016            @Override
20017            public WikiPage[] findByN_H_R_NotS_PrevAndNext(long pageId, long nodeId,
20018                    boolean head, String redirectTitle, int status,
20019                    OrderByComparator orderByComparator)
20020                    throws NoSuchPageException, SystemException {
20021                    WikiPage wikiPage = findByPrimaryKey(pageId);
20022    
20023                    Session session = null;
20024    
20025                    try {
20026                            session = openSession();
20027    
20028                            WikiPage[] array = new WikiPageImpl[3];
20029    
20030                            array[0] = getByN_H_R_NotS_PrevAndNext(session, wikiPage, nodeId,
20031                                            head, redirectTitle, status, orderByComparator, true);
20032    
20033                            array[1] = wikiPage;
20034    
20035                            array[2] = getByN_H_R_NotS_PrevAndNext(session, wikiPage, nodeId,
20036                                            head, redirectTitle, status, orderByComparator, false);
20037    
20038                            return array;
20039                    }
20040                    catch (Exception e) {
20041                            throw processException(e);
20042                    }
20043                    finally {
20044                            closeSession(session);
20045                    }
20046            }
20047    
20048            protected WikiPage getByN_H_R_NotS_PrevAndNext(Session session,
20049                    WikiPage wikiPage, long nodeId, boolean head, String redirectTitle,
20050                    int status, OrderByComparator orderByComparator, boolean previous) {
20051                    StringBundler query = null;
20052    
20053                    if (orderByComparator != null) {
20054                            query = new StringBundler(6 +
20055                                            (orderByComparator.getOrderByFields().length * 6));
20056                    }
20057                    else {
20058                            query = new StringBundler(3);
20059                    }
20060    
20061                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
20062    
20063                    query.append(_FINDER_COLUMN_N_H_R_NOTS_NODEID_2);
20064    
20065                    query.append(_FINDER_COLUMN_N_H_R_NOTS_HEAD_2);
20066    
20067                    boolean bindRedirectTitle = false;
20068    
20069                    if (redirectTitle == null) {
20070                            query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_1);
20071                    }
20072                    else if (redirectTitle.equals(StringPool.BLANK)) {
20073                            query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_3);
20074                    }
20075                    else {
20076                            bindRedirectTitle = true;
20077    
20078                            query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_2);
20079                    }
20080    
20081                    query.append(_FINDER_COLUMN_N_H_R_NOTS_STATUS_2);
20082    
20083                    if (orderByComparator != null) {
20084                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
20085    
20086                            if (orderByConditionFields.length > 0) {
20087                                    query.append(WHERE_AND);
20088                            }
20089    
20090                            for (int i = 0; i < orderByConditionFields.length; i++) {
20091                                    query.append(_ORDER_BY_ENTITY_ALIAS);
20092                                    query.append(orderByConditionFields[i]);
20093    
20094                                    if ((i + 1) < orderByConditionFields.length) {
20095                                            if (orderByComparator.isAscending() ^ previous) {
20096                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
20097                                            }
20098                                            else {
20099                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
20100                                            }
20101                                    }
20102                                    else {
20103                                            if (orderByComparator.isAscending() ^ previous) {
20104                                                    query.append(WHERE_GREATER_THAN);
20105                                            }
20106                                            else {
20107                                                    query.append(WHERE_LESSER_THAN);
20108                                            }
20109                                    }
20110                            }
20111    
20112                            query.append(ORDER_BY_CLAUSE);
20113    
20114                            String[] orderByFields = orderByComparator.getOrderByFields();
20115    
20116                            for (int i = 0; i < orderByFields.length; i++) {
20117                                    query.append(_ORDER_BY_ENTITY_ALIAS);
20118                                    query.append(orderByFields[i]);
20119    
20120                                    if ((i + 1) < orderByFields.length) {
20121                                            if (orderByComparator.isAscending() ^ previous) {
20122                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
20123                                            }
20124                                            else {
20125                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
20126                                            }
20127                                    }
20128                                    else {
20129                                            if (orderByComparator.isAscending() ^ previous) {
20130                                                    query.append(ORDER_BY_ASC);
20131                                            }
20132                                            else {
20133                                                    query.append(ORDER_BY_DESC);
20134                                            }
20135                                    }
20136                            }
20137                    }
20138                    else {
20139                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
20140                    }
20141    
20142                    String sql = query.toString();
20143    
20144                    Query q = session.createQuery(sql);
20145    
20146                    q.setFirstResult(0);
20147                    q.setMaxResults(2);
20148    
20149                    QueryPos qPos = QueryPos.getInstance(q);
20150    
20151                    qPos.add(nodeId);
20152    
20153                    qPos.add(head);
20154    
20155                    if (bindRedirectTitle) {
20156                            qPos.add(redirectTitle.toLowerCase());
20157                    }
20158    
20159                    qPos.add(status);
20160    
20161                    if (orderByComparator != null) {
20162                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
20163    
20164                            for (Object value : values) {
20165                                    qPos.add(value);
20166                            }
20167                    }
20168    
20169                    List<WikiPage> list = q.list();
20170    
20171                    if (list.size() == 2) {
20172                            return list.get(1);
20173                    }
20174                    else {
20175                            return null;
20176                    }
20177            }
20178    
20179            /**
20180             * Removes all the wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63; from the database.
20181             *
20182             * @param nodeId the node ID
20183             * @param head the head
20184             * @param redirectTitle the redirect title
20185             * @param status the status
20186             * @throws SystemException if a system exception occurred
20187             */
20188            @Override
20189            public void removeByN_H_R_NotS(long nodeId, boolean head,
20190                    String redirectTitle, int status) throws SystemException {
20191                    for (WikiPage wikiPage : findByN_H_R_NotS(nodeId, head, redirectTitle,
20192                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
20193                            remove(wikiPage);
20194                    }
20195            }
20196    
20197            /**
20198             * Returns the number of wiki pages where nodeId = &#63; and head = &#63; and redirectTitle = &#63; and status &ne; &#63;.
20199             *
20200             * @param nodeId the node ID
20201             * @param head the head
20202             * @param redirectTitle the redirect title
20203             * @param status the status
20204             * @return the number of matching wiki pages
20205             * @throws SystemException if a system exception occurred
20206             */
20207            @Override
20208            public int countByN_H_R_NotS(long nodeId, boolean head,
20209                    String redirectTitle, int status) throws SystemException {
20210                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_N_H_R_NOTS;
20211    
20212                    Object[] finderArgs = new Object[] { nodeId, head, redirectTitle, status };
20213    
20214                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
20215                                    this);
20216    
20217                    if (count == null) {
20218                            StringBundler query = new StringBundler(5);
20219    
20220                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
20221    
20222                            query.append(_FINDER_COLUMN_N_H_R_NOTS_NODEID_2);
20223    
20224                            query.append(_FINDER_COLUMN_N_H_R_NOTS_HEAD_2);
20225    
20226                            boolean bindRedirectTitle = false;
20227    
20228                            if (redirectTitle == null) {
20229                                    query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_1);
20230                            }
20231                            else if (redirectTitle.equals(StringPool.BLANK)) {
20232                                    query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_3);
20233                            }
20234                            else {
20235                                    bindRedirectTitle = true;
20236    
20237                                    query.append(_FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_2);
20238                            }
20239    
20240                            query.append(_FINDER_COLUMN_N_H_R_NOTS_STATUS_2);
20241    
20242                            String sql = query.toString();
20243    
20244                            Session session = null;
20245    
20246                            try {
20247                                    session = openSession();
20248    
20249                                    Query q = session.createQuery(sql);
20250    
20251                                    QueryPos qPos = QueryPos.getInstance(q);
20252    
20253                                    qPos.add(nodeId);
20254    
20255                                    qPos.add(head);
20256    
20257                                    if (bindRedirectTitle) {
20258                                            qPos.add(redirectTitle.toLowerCase());
20259                                    }
20260    
20261                                    qPos.add(status);
20262    
20263                                    count = (Long)q.uniqueResult();
20264    
20265                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
20266                            }
20267                            catch (Exception e) {
20268                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
20269    
20270                                    throw processException(e);
20271                            }
20272                            finally {
20273                                    closeSession(session);
20274                            }
20275                    }
20276    
20277                    return count.intValue();
20278            }
20279    
20280            private static final String _FINDER_COLUMN_N_H_R_NOTS_NODEID_2 = "wikiPage.nodeId = ? AND ";
20281            private static final String _FINDER_COLUMN_N_H_R_NOTS_HEAD_2 = "wikiPage.head = ? AND ";
20282            private static final String _FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_1 = "wikiPage.redirectTitle IS NULL AND ";
20283            private static final String _FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_2 = "lower(wikiPage.redirectTitle) = ? AND ";
20284            private static final String _FINDER_COLUMN_N_H_R_NOTS_REDIRECTTITLE_3 = "(wikiPage.redirectTitle IS NULL OR wikiPage.redirectTitle = '') AND ";
20285            private static final String _FINDER_COLUMN_N_H_R_NOTS_STATUS_2 = "wikiPage.status != ?";
20286            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_P_S =
20287                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
20288                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
20289                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N_H_P_S",
20290                            new String[] {
20291                                    Long.class.getName(), Long.class.getName(),
20292                                    Boolean.class.getName(), String.class.getName(),
20293                                    Integer.class.getName(),
20294                                    
20295                            Integer.class.getName(), Integer.class.getName(),
20296                                    OrderByComparator.class.getName()
20297                            });
20298            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S =
20299                    new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
20300                            WikiPageModelImpl.FINDER_CACHE_ENABLED, WikiPageImpl.class,
20301                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_H_P_S",
20302                            new String[] {
20303                                    Long.class.getName(), Long.class.getName(),
20304                                    Boolean.class.getName(), String.class.getName(),
20305                                    Integer.class.getName()
20306                            },
20307                            WikiPageModelImpl.GROUPID_COLUMN_BITMASK |
20308                            WikiPageModelImpl.NODEID_COLUMN_BITMASK |
20309                            WikiPageModelImpl.HEAD_COLUMN_BITMASK |
20310                            WikiPageModelImpl.PARENTTITLE_COLUMN_BITMASK |
20311                            WikiPageModelImpl.STATUS_COLUMN_BITMASK |
20312                            WikiPageModelImpl.TITLE_COLUMN_BITMASK |
20313                            WikiPageModelImpl.VERSION_COLUMN_BITMASK);
20314            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_H_P_S = new FinderPath(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
20315                            WikiPageModelImpl.FINDER_CACHE_ENABLED, Long.class,
20316                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_H_P_S",
20317                            new String[] {
20318                                    Long.class.getName(), Long.class.getName(),
20319                                    Boolean.class.getName(), String.class.getName(),
20320                                    Integer.class.getName()
20321                            });
20322    
20323            /**
20324             * Returns all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
20325             *
20326             * @param groupId the group ID
20327             * @param nodeId the node ID
20328             * @param head the head
20329             * @param parentTitle the parent title
20330             * @param status the status
20331             * @return the matching wiki pages
20332             * @throws SystemException if a system exception occurred
20333             */
20334            @Override
20335            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
20336                    boolean head, String parentTitle, int status) throws SystemException {
20337                    return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
20338                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
20339            }
20340    
20341            /**
20342             * Returns a range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
20343             *
20344             * <p>
20345             * 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.
20346             * </p>
20347             *
20348             * @param groupId the group ID
20349             * @param nodeId the node ID
20350             * @param head the head
20351             * @param parentTitle the parent title
20352             * @param status the status
20353             * @param start the lower bound of the range of wiki pages
20354             * @param end the upper bound of the range of wiki pages (not inclusive)
20355             * @return the range of matching wiki pages
20356             * @throws SystemException if a system exception occurred
20357             */
20358            @Override
20359            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
20360                    boolean head, String parentTitle, int status, int start, int end)
20361                    throws SystemException {
20362                    return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
20363                            start, end, null);
20364            }
20365    
20366            /**
20367             * Returns an ordered range of all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
20368             *
20369             * <p>
20370             * 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.
20371             * </p>
20372             *
20373             * @param groupId the group ID
20374             * @param nodeId the node ID
20375             * @param head the head
20376             * @param parentTitle the parent title
20377             * @param status the status
20378             * @param start the lower bound of the range of wiki pages
20379             * @param end the upper bound of the range of wiki pages (not inclusive)
20380             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20381             * @return the ordered range of matching wiki pages
20382             * @throws SystemException if a system exception occurred
20383             */
20384            @Override
20385            public List<WikiPage> findByG_N_H_P_S(long groupId, long nodeId,
20386                    boolean head, String parentTitle, int status, int start, int end,
20387                    OrderByComparator orderByComparator) throws SystemException {
20388                    boolean pagination = true;
20389                    FinderPath finderPath = null;
20390                    Object[] finderArgs = null;
20391    
20392                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
20393                                    (orderByComparator == null)) {
20394                            pagination = false;
20395                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S;
20396                            finderArgs = new Object[] { groupId, nodeId, head, parentTitle, status };
20397                    }
20398                    else {
20399                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_H_P_S;
20400                            finderArgs = new Object[] {
20401                                            groupId, nodeId, head, parentTitle, status,
20402                                            
20403                                            start, end, orderByComparator
20404                                    };
20405                    }
20406    
20407                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
20408                                    finderArgs, this);
20409    
20410                    if ((list != null) && !list.isEmpty()) {
20411                            for (WikiPage wikiPage : list) {
20412                                    if ((groupId != wikiPage.getGroupId()) ||
20413                                                    (nodeId != wikiPage.getNodeId()) ||
20414                                                    (head != wikiPage.getHead()) ||
20415                                                    !Validator.equals(parentTitle, wikiPage.getParentTitle()) ||
20416                                                    (status != wikiPage.getStatus())) {
20417                                            list = null;
20418    
20419                                            break;
20420                                    }
20421                            }
20422                    }
20423    
20424                    if (list == null) {
20425                            StringBundler query = null;
20426    
20427                            if (orderByComparator != null) {
20428                                    query = new StringBundler(7 +
20429                                                    (orderByComparator.getOrderByFields().length * 3));
20430                            }
20431                            else {
20432                                    query = new StringBundler(7);
20433                            }
20434    
20435                            query.append(_SQL_SELECT_WIKIPAGE_WHERE);
20436    
20437                            query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
20438    
20439                            query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
20440    
20441                            query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
20442    
20443                            boolean bindParentTitle = false;
20444    
20445                            if (parentTitle == null) {
20446                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
20447                            }
20448                            else if (parentTitle.equals(StringPool.BLANK)) {
20449                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
20450                            }
20451                            else {
20452                                    bindParentTitle = true;
20453    
20454                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
20455                            }
20456    
20457                            query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
20458    
20459                            if (orderByComparator != null) {
20460                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
20461                                            orderByComparator);
20462                            }
20463                            else
20464                             if (pagination) {
20465                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
20466                            }
20467    
20468                            String sql = query.toString();
20469    
20470                            Session session = null;
20471    
20472                            try {
20473                                    session = openSession();
20474    
20475                                    Query q = session.createQuery(sql);
20476    
20477                                    QueryPos qPos = QueryPos.getInstance(q);
20478    
20479                                    qPos.add(groupId);
20480    
20481                                    qPos.add(nodeId);
20482    
20483                                    qPos.add(head);
20484    
20485                                    if (bindParentTitle) {
20486                                            qPos.add(parentTitle.toLowerCase());
20487                                    }
20488    
20489                                    qPos.add(status);
20490    
20491                                    if (!pagination) {
20492                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
20493                                                            start, end, false);
20494    
20495                                            Collections.sort(list);
20496    
20497                                            list = new UnmodifiableList<WikiPage>(list);
20498                                    }
20499                                    else {
20500                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
20501                                                            start, end);
20502                                    }
20503    
20504                                    cacheResult(list);
20505    
20506                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
20507                            }
20508                            catch (Exception e) {
20509                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
20510    
20511                                    throw processException(e);
20512                            }
20513                            finally {
20514                                    closeSession(session);
20515                            }
20516                    }
20517    
20518                    return list;
20519            }
20520    
20521            /**
20522             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
20523             *
20524             * @param groupId the group ID
20525             * @param nodeId the node ID
20526             * @param head the head
20527             * @param parentTitle the parent title
20528             * @param status the status
20529             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20530             * @return the first matching wiki page
20531             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
20532             * @throws SystemException if a system exception occurred
20533             */
20534            @Override
20535            public WikiPage findByG_N_H_P_S_First(long groupId, long nodeId,
20536                    boolean head, String parentTitle, int status,
20537                    OrderByComparator orderByComparator)
20538                    throws NoSuchPageException, SystemException {
20539                    WikiPage wikiPage = fetchByG_N_H_P_S_First(groupId, nodeId, head,
20540                                    parentTitle, status, orderByComparator);
20541    
20542                    if (wikiPage != null) {
20543                            return wikiPage;
20544                    }
20545    
20546                    StringBundler msg = new StringBundler(12);
20547    
20548                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
20549    
20550                    msg.append("groupId=");
20551                    msg.append(groupId);
20552    
20553                    msg.append(", nodeId=");
20554                    msg.append(nodeId);
20555    
20556                    msg.append(", head=");
20557                    msg.append(head);
20558    
20559                    msg.append(", parentTitle=");
20560                    msg.append(parentTitle);
20561    
20562                    msg.append(", status=");
20563                    msg.append(status);
20564    
20565                    msg.append(StringPool.CLOSE_CURLY_BRACE);
20566    
20567                    throw new NoSuchPageException(msg.toString());
20568            }
20569    
20570            /**
20571             * Returns the first wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
20572             *
20573             * @param groupId the group ID
20574             * @param nodeId the node ID
20575             * @param head the head
20576             * @param parentTitle the parent title
20577             * @param status the status
20578             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20579             * @return the first matching wiki page, or <code>null</code> if a matching wiki page could not be found
20580             * @throws SystemException if a system exception occurred
20581             */
20582            @Override
20583            public WikiPage fetchByG_N_H_P_S_First(long groupId, long nodeId,
20584                    boolean head, String parentTitle, int status,
20585                    OrderByComparator orderByComparator) throws SystemException {
20586                    List<WikiPage> list = findByG_N_H_P_S(groupId, nodeId, head,
20587                                    parentTitle, status, 0, 1, orderByComparator);
20588    
20589                    if (!list.isEmpty()) {
20590                            return list.get(0);
20591                    }
20592    
20593                    return null;
20594            }
20595    
20596            /**
20597             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
20598             *
20599             * @param groupId the group ID
20600             * @param nodeId the node ID
20601             * @param head the head
20602             * @param parentTitle the parent title
20603             * @param status the status
20604             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20605             * @return the last matching wiki page
20606             * @throws com.liferay.portlet.wiki.NoSuchPageException if a matching wiki page could not be found
20607             * @throws SystemException if a system exception occurred
20608             */
20609            @Override
20610            public WikiPage findByG_N_H_P_S_Last(long groupId, long nodeId,
20611                    boolean head, String parentTitle, int status,
20612                    OrderByComparator orderByComparator)
20613                    throws NoSuchPageException, SystemException {
20614                    WikiPage wikiPage = fetchByG_N_H_P_S_Last(groupId, nodeId, head,
20615                                    parentTitle, status, orderByComparator);
20616    
20617                    if (wikiPage != null) {
20618                            return wikiPage;
20619                    }
20620    
20621                    StringBundler msg = new StringBundler(12);
20622    
20623                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
20624    
20625                    msg.append("groupId=");
20626                    msg.append(groupId);
20627    
20628                    msg.append(", nodeId=");
20629                    msg.append(nodeId);
20630    
20631                    msg.append(", head=");
20632                    msg.append(head);
20633    
20634                    msg.append(", parentTitle=");
20635                    msg.append(parentTitle);
20636    
20637                    msg.append(", status=");
20638                    msg.append(status);
20639    
20640                    msg.append(StringPool.CLOSE_CURLY_BRACE);
20641    
20642                    throw new NoSuchPageException(msg.toString());
20643            }
20644    
20645            /**
20646             * Returns the last wiki page in the ordered set where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
20647             *
20648             * @param groupId the group ID
20649             * @param nodeId the node ID
20650             * @param head the head
20651             * @param parentTitle the parent title
20652             * @param status the status
20653             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20654             * @return the last matching wiki page, or <code>null</code> if a matching wiki page could not be found
20655             * @throws SystemException if a system exception occurred
20656             */
20657            @Override
20658            public WikiPage fetchByG_N_H_P_S_Last(long groupId, long nodeId,
20659                    boolean head, String parentTitle, int status,
20660                    OrderByComparator orderByComparator) throws SystemException {
20661                    int count = countByG_N_H_P_S(groupId, nodeId, head, parentTitle, status);
20662    
20663                    if (count == 0) {
20664                            return null;
20665                    }
20666    
20667                    List<WikiPage> list = findByG_N_H_P_S(groupId, nodeId, head,
20668                                    parentTitle, status, count - 1, count, orderByComparator);
20669    
20670                    if (!list.isEmpty()) {
20671                            return list.get(0);
20672                    }
20673    
20674                    return null;
20675            }
20676    
20677            /**
20678             * 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;.
20679             *
20680             * @param pageId the primary key of the current wiki page
20681             * @param groupId the group ID
20682             * @param nodeId the node ID
20683             * @param head the head
20684             * @param parentTitle the parent title
20685             * @param status the status
20686             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20687             * @return the previous, current, and next wiki page
20688             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
20689             * @throws SystemException if a system exception occurred
20690             */
20691            @Override
20692            public WikiPage[] findByG_N_H_P_S_PrevAndNext(long pageId, long groupId,
20693                    long nodeId, boolean head, String parentTitle, int status,
20694                    OrderByComparator orderByComparator)
20695                    throws NoSuchPageException, SystemException {
20696                    WikiPage wikiPage = findByPrimaryKey(pageId);
20697    
20698                    Session session = null;
20699    
20700                    try {
20701                            session = openSession();
20702    
20703                            WikiPage[] array = new WikiPageImpl[3];
20704    
20705                            array[0] = getByG_N_H_P_S_PrevAndNext(session, wikiPage, groupId,
20706                                            nodeId, head, parentTitle, status, orderByComparator, true);
20707    
20708                            array[1] = wikiPage;
20709    
20710                            array[2] = getByG_N_H_P_S_PrevAndNext(session, wikiPage, groupId,
20711                                            nodeId, head, parentTitle, status, orderByComparator, false);
20712    
20713                            return array;
20714                    }
20715                    catch (Exception e) {
20716                            throw processException(e);
20717                    }
20718                    finally {
20719                            closeSession(session);
20720                    }
20721            }
20722    
20723            protected WikiPage getByG_N_H_P_S_PrevAndNext(Session session,
20724                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
20725                    String parentTitle, int status, OrderByComparator orderByComparator,
20726                    boolean previous) {
20727                    StringBundler query = null;
20728    
20729                    if (orderByComparator != null) {
20730                            query = new StringBundler(6 +
20731                                            (orderByComparator.getOrderByFields().length * 6));
20732                    }
20733                    else {
20734                            query = new StringBundler(3);
20735                    }
20736    
20737                    query.append(_SQL_SELECT_WIKIPAGE_WHERE);
20738    
20739                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
20740    
20741                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
20742    
20743                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
20744    
20745                    boolean bindParentTitle = false;
20746    
20747                    if (parentTitle == null) {
20748                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
20749                    }
20750                    else if (parentTitle.equals(StringPool.BLANK)) {
20751                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
20752                    }
20753                    else {
20754                            bindParentTitle = true;
20755    
20756                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
20757                    }
20758    
20759                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
20760    
20761                    if (orderByComparator != null) {
20762                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
20763    
20764                            if (orderByConditionFields.length > 0) {
20765                                    query.append(WHERE_AND);
20766                            }
20767    
20768                            for (int i = 0; i < orderByConditionFields.length; i++) {
20769                                    query.append(_ORDER_BY_ENTITY_ALIAS);
20770                                    query.append(orderByConditionFields[i]);
20771    
20772                                    if ((i + 1) < orderByConditionFields.length) {
20773                                            if (orderByComparator.isAscending() ^ previous) {
20774                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
20775                                            }
20776                                            else {
20777                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
20778                                            }
20779                                    }
20780                                    else {
20781                                            if (orderByComparator.isAscending() ^ previous) {
20782                                                    query.append(WHERE_GREATER_THAN);
20783                                            }
20784                                            else {
20785                                                    query.append(WHERE_LESSER_THAN);
20786                                            }
20787                                    }
20788                            }
20789    
20790                            query.append(ORDER_BY_CLAUSE);
20791    
20792                            String[] orderByFields = orderByComparator.getOrderByFields();
20793    
20794                            for (int i = 0; i < orderByFields.length; i++) {
20795                                    query.append(_ORDER_BY_ENTITY_ALIAS);
20796                                    query.append(orderByFields[i]);
20797    
20798                                    if ((i + 1) < orderByFields.length) {
20799                                            if (orderByComparator.isAscending() ^ previous) {
20800                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
20801                                            }
20802                                            else {
20803                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
20804                                            }
20805                                    }
20806                                    else {
20807                                            if (orderByComparator.isAscending() ^ previous) {
20808                                                    query.append(ORDER_BY_ASC);
20809                                            }
20810                                            else {
20811                                                    query.append(ORDER_BY_DESC);
20812                                            }
20813                                    }
20814                            }
20815                    }
20816                    else {
20817                            query.append(WikiPageModelImpl.ORDER_BY_JPQL);
20818                    }
20819    
20820                    String sql = query.toString();
20821    
20822                    Query q = session.createQuery(sql);
20823    
20824                    q.setFirstResult(0);
20825                    q.setMaxResults(2);
20826    
20827                    QueryPos qPos = QueryPos.getInstance(q);
20828    
20829                    qPos.add(groupId);
20830    
20831                    qPos.add(nodeId);
20832    
20833                    qPos.add(head);
20834    
20835                    if (bindParentTitle) {
20836                            qPos.add(parentTitle.toLowerCase());
20837                    }
20838    
20839                    qPos.add(status);
20840    
20841                    if (orderByComparator != null) {
20842                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
20843    
20844                            for (Object value : values) {
20845                                    qPos.add(value);
20846                            }
20847                    }
20848    
20849                    List<WikiPage> list = q.list();
20850    
20851                    if (list.size() == 2) {
20852                            return list.get(1);
20853                    }
20854                    else {
20855                            return null;
20856                    }
20857            }
20858    
20859            /**
20860             * 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;.
20861             *
20862             * @param groupId the group ID
20863             * @param nodeId the node ID
20864             * @param head the head
20865             * @param parentTitle the parent title
20866             * @param status the status
20867             * @return the matching wiki pages that the user has permission to view
20868             * @throws SystemException if a system exception occurred
20869             */
20870            @Override
20871            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
20872                    boolean head, String parentTitle, int status) throws SystemException {
20873                    return filterFindByG_N_H_P_S(groupId, nodeId, head, parentTitle,
20874                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
20875            }
20876    
20877            /**
20878             * 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;.
20879             *
20880             * <p>
20881             * 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.
20882             * </p>
20883             *
20884             * @param groupId the group ID
20885             * @param nodeId the node ID
20886             * @param head the head
20887             * @param parentTitle the parent title
20888             * @param status the status
20889             * @param start the lower bound of the range of wiki pages
20890             * @param end the upper bound of the range of wiki pages (not inclusive)
20891             * @return the range of matching wiki pages that the user has permission to view
20892             * @throws SystemException if a system exception occurred
20893             */
20894            @Override
20895            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
20896                    boolean head, String parentTitle, int status, int start, int end)
20897                    throws SystemException {
20898                    return filterFindByG_N_H_P_S(groupId, nodeId, head, parentTitle,
20899                            status, start, end, null);
20900            }
20901    
20902            /**
20903             * 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;.
20904             *
20905             * <p>
20906             * 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.
20907             * </p>
20908             *
20909             * @param groupId the group ID
20910             * @param nodeId the node ID
20911             * @param head the head
20912             * @param parentTitle the parent title
20913             * @param status the status
20914             * @param start the lower bound of the range of wiki pages
20915             * @param end the upper bound of the range of wiki pages (not inclusive)
20916             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20917             * @return the ordered range of matching wiki pages that the user has permission to view
20918             * @throws SystemException if a system exception occurred
20919             */
20920            @Override
20921            public List<WikiPage> filterFindByG_N_H_P_S(long groupId, long nodeId,
20922                    boolean head, String parentTitle, int status, int start, int end,
20923                    OrderByComparator orderByComparator) throws SystemException {
20924                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
20925                            return findByG_N_H_P_S(groupId, nodeId, head, parentTitle, status,
20926                                    start, end, orderByComparator);
20927                    }
20928    
20929                    StringBundler query = null;
20930    
20931                    if (orderByComparator != null) {
20932                            query = new StringBundler(7 +
20933                                            (orderByComparator.getOrderByFields().length * 3));
20934                    }
20935                    else {
20936                            query = new StringBundler(7);
20937                    }
20938    
20939                    if (getDB().isSupportsInlineDistinct()) {
20940                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
20941                    }
20942                    else {
20943                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
20944                    }
20945    
20946                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
20947    
20948                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
20949    
20950                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
20951    
20952                    boolean bindParentTitle = false;
20953    
20954                    if (parentTitle == null) {
20955                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
20956                    }
20957                    else if (parentTitle.equals(StringPool.BLANK)) {
20958                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
20959                    }
20960                    else {
20961                            bindParentTitle = true;
20962    
20963                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
20964                    }
20965    
20966                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
20967    
20968                    if (!getDB().isSupportsInlineDistinct()) {
20969                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
20970                    }
20971    
20972                    if (orderByComparator != null) {
20973                            if (getDB().isSupportsInlineDistinct()) {
20974                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
20975                                            orderByComparator, true);
20976                            }
20977                            else {
20978                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
20979                                            orderByComparator, true);
20980                            }
20981                    }
20982                    else {
20983                            if (getDB().isSupportsInlineDistinct()) {
20984                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
20985                            }
20986                            else {
20987                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
20988                            }
20989                    }
20990    
20991                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
20992                                    WikiPage.class.getName(),
20993                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
20994    
20995                    Session session = null;
20996    
20997                    try {
20998                            session = openSession();
20999    
21000                            SQLQuery q = session.createSQLQuery(sql);
21001    
21002                            if (getDB().isSupportsInlineDistinct()) {
21003                                    q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
21004                            }
21005                            else {
21006                                    q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
21007                            }
21008    
21009                            QueryPos qPos = QueryPos.getInstance(q);
21010    
21011                            qPos.add(groupId);
21012    
21013                            qPos.add(nodeId);
21014    
21015                            qPos.add(head);
21016    
21017                            if (bindParentTitle) {
21018                                    qPos.add(parentTitle.toLowerCase());
21019                            }
21020    
21021                            qPos.add(status);
21022    
21023                            return (List<WikiPage>)QueryUtil.list(q, getDialect(), start, end);
21024                    }
21025                    catch (Exception e) {
21026                            throw processException(e);
21027                    }
21028                    finally {
21029                            closeSession(session);
21030                    }
21031            }
21032    
21033            /**
21034             * 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;.
21035             *
21036             * @param pageId the primary key of the current wiki page
21037             * @param groupId the group ID
21038             * @param nodeId the node ID
21039             * @param head the head
21040             * @param parentTitle the parent title
21041             * @param status the status
21042             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
21043             * @return the previous, current, and next wiki page
21044             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
21045             * @throws SystemException if a system exception occurred
21046             */
21047            @Override
21048            public WikiPage[] filterFindByG_N_H_P_S_PrevAndNext(long pageId,
21049                    long groupId, long nodeId, boolean head, String parentTitle,
21050                    int status, OrderByComparator orderByComparator)
21051                    throws NoSuchPageException, SystemException {
21052                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
21053                            return findByG_N_H_P_S_PrevAndNext(pageId, groupId, nodeId, head,
21054                                    parentTitle, status, orderByComparator);
21055                    }
21056    
21057                    WikiPage wikiPage = findByPrimaryKey(pageId);
21058    
21059                    Session session = null;
21060    
21061                    try {
21062                            session = openSession();
21063    
21064                            WikiPage[] array = new WikiPageImpl[3];
21065    
21066                            array[0] = filterGetByG_N_H_P_S_PrevAndNext(session, wikiPage,
21067                                            groupId, nodeId, head, parentTitle, status,
21068                                            orderByComparator, true);
21069    
21070                            array[1] = wikiPage;
21071    
21072                            array[2] = filterGetByG_N_H_P_S_PrevAndNext(session, wikiPage,
21073                                            groupId, nodeId, head, parentTitle, status,
21074                                            orderByComparator, false);
21075    
21076                            return array;
21077                    }
21078                    catch (Exception e) {
21079                            throw processException(e);
21080                    }
21081                    finally {
21082                            closeSession(session);
21083                    }
21084            }
21085    
21086            protected WikiPage filterGetByG_N_H_P_S_PrevAndNext(Session session,
21087                    WikiPage wikiPage, long groupId, long nodeId, boolean head,
21088                    String parentTitle, int status, OrderByComparator orderByComparator,
21089                    boolean previous) {
21090                    StringBundler query = null;
21091    
21092                    if (orderByComparator != null) {
21093                            query = new StringBundler(6 +
21094                                            (orderByComparator.getOrderByFields().length * 6));
21095                    }
21096                    else {
21097                            query = new StringBundler(3);
21098                    }
21099    
21100                    if (getDB().isSupportsInlineDistinct()) {
21101                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_WHERE);
21102                    }
21103                    else {
21104                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1);
21105                    }
21106    
21107                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
21108    
21109                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
21110    
21111                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
21112    
21113                    boolean bindParentTitle = false;
21114    
21115                    if (parentTitle == null) {
21116                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
21117                    }
21118                    else if (parentTitle.equals(StringPool.BLANK)) {
21119                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
21120                    }
21121                    else {
21122                            bindParentTitle = true;
21123    
21124                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
21125                    }
21126    
21127                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
21128    
21129                    if (!getDB().isSupportsInlineDistinct()) {
21130                            query.append(_FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2);
21131                    }
21132    
21133                    if (orderByComparator != null) {
21134                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
21135    
21136                            if (orderByConditionFields.length > 0) {
21137                                    query.append(WHERE_AND);
21138                            }
21139    
21140                            for (int i = 0; i < orderByConditionFields.length; i++) {
21141                                    if (getDB().isSupportsInlineDistinct()) {
21142                                            query.append(_ORDER_BY_ENTITY_ALIAS);
21143                                    }
21144                                    else {
21145                                            query.append(_ORDER_BY_ENTITY_TABLE);
21146                                    }
21147    
21148                                    query.append(orderByConditionFields[i]);
21149    
21150                                    if ((i + 1) < orderByConditionFields.length) {
21151                                            if (orderByComparator.isAscending() ^ previous) {
21152                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
21153                                            }
21154                                            else {
21155                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
21156                                            }
21157                                    }
21158                                    else {
21159                                            if (orderByComparator.isAscending() ^ previous) {
21160                                                    query.append(WHERE_GREATER_THAN);
21161                                            }
21162                                            else {
21163                                                    query.append(WHERE_LESSER_THAN);
21164                                            }
21165                                    }
21166                            }
21167    
21168                            query.append(ORDER_BY_CLAUSE);
21169    
21170                            String[] orderByFields = orderByComparator.getOrderByFields();
21171    
21172                            for (int i = 0; i < orderByFields.length; i++) {
21173                                    if (getDB().isSupportsInlineDistinct()) {
21174                                            query.append(_ORDER_BY_ENTITY_ALIAS);
21175                                    }
21176                                    else {
21177                                            query.append(_ORDER_BY_ENTITY_TABLE);
21178                                    }
21179    
21180                                    query.append(orderByFields[i]);
21181    
21182                                    if ((i + 1) < orderByFields.length) {
21183                                            if (orderByComparator.isAscending() ^ previous) {
21184                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
21185                                            }
21186                                            else {
21187                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
21188                                            }
21189                                    }
21190                                    else {
21191                                            if (orderByComparator.isAscending() ^ previous) {
21192                                                    query.append(ORDER_BY_ASC);
21193                                            }
21194                                            else {
21195                                                    query.append(ORDER_BY_DESC);
21196                                            }
21197                                    }
21198                            }
21199                    }
21200                    else {
21201                            if (getDB().isSupportsInlineDistinct()) {
21202                                    query.append(WikiPageModelImpl.ORDER_BY_JPQL);
21203                            }
21204                            else {
21205                                    query.append(WikiPageModelImpl.ORDER_BY_SQL);
21206                            }
21207                    }
21208    
21209                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
21210                                    WikiPage.class.getName(),
21211                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
21212    
21213                    SQLQuery q = session.createSQLQuery(sql);
21214    
21215                    q.setFirstResult(0);
21216                    q.setMaxResults(2);
21217    
21218                    if (getDB().isSupportsInlineDistinct()) {
21219                            q.addEntity(_FILTER_ENTITY_ALIAS, WikiPageImpl.class);
21220                    }
21221                    else {
21222                            q.addEntity(_FILTER_ENTITY_TABLE, WikiPageImpl.class);
21223                    }
21224    
21225                    QueryPos qPos = QueryPos.getInstance(q);
21226    
21227                    qPos.add(groupId);
21228    
21229                    qPos.add(nodeId);
21230    
21231                    qPos.add(head);
21232    
21233                    if (bindParentTitle) {
21234                            qPos.add(parentTitle.toLowerCase());
21235                    }
21236    
21237                    qPos.add(status);
21238    
21239                    if (orderByComparator != null) {
21240                            Object[] values = orderByComparator.getOrderByConditionValues(wikiPage);
21241    
21242                            for (Object value : values) {
21243                                    qPos.add(value);
21244                            }
21245                    }
21246    
21247                    List<WikiPage> list = q.list();
21248    
21249                    if (list.size() == 2) {
21250                            return list.get(1);
21251                    }
21252                    else {
21253                            return null;
21254                    }
21255            }
21256    
21257            /**
21258             * Removes all the wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63; from the database.
21259             *
21260             * @param groupId the group ID
21261             * @param nodeId the node ID
21262             * @param head the head
21263             * @param parentTitle the parent title
21264             * @param status the status
21265             * @throws SystemException if a system exception occurred
21266             */
21267            @Override
21268            public void removeByG_N_H_P_S(long groupId, long nodeId, boolean head,
21269                    String parentTitle, int status) throws SystemException {
21270                    for (WikiPage wikiPage : findByG_N_H_P_S(groupId, nodeId, head,
21271                                    parentTitle, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
21272                            remove(wikiPage);
21273                    }
21274            }
21275    
21276            /**
21277             * Returns the number of wiki pages where groupId = &#63; and nodeId = &#63; and head = &#63; and parentTitle = &#63; and status = &#63;.
21278             *
21279             * @param groupId the group ID
21280             * @param nodeId the node ID
21281             * @param head the head
21282             * @param parentTitle the parent title
21283             * @param status the status
21284             * @return the number of matching wiki pages
21285             * @throws SystemException if a system exception occurred
21286             */
21287            @Override
21288            public int countByG_N_H_P_S(long groupId, long nodeId, boolean head,
21289                    String parentTitle, int status) throws SystemException {
21290                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_H_P_S;
21291    
21292                    Object[] finderArgs = new Object[] {
21293                                    groupId, nodeId, head, parentTitle, status
21294                            };
21295    
21296                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
21297                                    this);
21298    
21299                    if (count == null) {
21300                            StringBundler query = new StringBundler(6);
21301    
21302                            query.append(_SQL_COUNT_WIKIPAGE_WHERE);
21303    
21304                            query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
21305    
21306                            query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
21307    
21308                            query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
21309    
21310                            boolean bindParentTitle = false;
21311    
21312                            if (parentTitle == null) {
21313                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
21314                            }
21315                            else if (parentTitle.equals(StringPool.BLANK)) {
21316                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
21317                            }
21318                            else {
21319                                    bindParentTitle = true;
21320    
21321                                    query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
21322                            }
21323    
21324                            query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
21325    
21326                            String sql = query.toString();
21327    
21328                            Session session = null;
21329    
21330                            try {
21331                                    session = openSession();
21332    
21333                                    Query q = session.createQuery(sql);
21334    
21335                                    QueryPos qPos = QueryPos.getInstance(q);
21336    
21337                                    qPos.add(groupId);
21338    
21339                                    qPos.add(nodeId);
21340    
21341                                    qPos.add(head);
21342    
21343                                    if (bindParentTitle) {
21344                                            qPos.add(parentTitle.toLowerCase());
21345                                    }
21346    
21347                                    qPos.add(status);
21348    
21349                                    count = (Long)q.uniqueResult();
21350    
21351                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
21352                            }
21353                            catch (Exception e) {
21354                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
21355    
21356                                    throw processException(e);
21357                            }
21358                            finally {
21359                                    closeSession(session);
21360                            }
21361                    }
21362    
21363                    return count.intValue();
21364            }
21365    
21366            /**
21367             * 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;.
21368             *
21369             * @param groupId the group ID
21370             * @param nodeId the node ID
21371             * @param head the head
21372             * @param parentTitle the parent title
21373             * @param status the status
21374             * @return the number of matching wiki pages that the user has permission to view
21375             * @throws SystemException if a system exception occurred
21376             */
21377            @Override
21378            public int filterCountByG_N_H_P_S(long groupId, long nodeId, boolean head,
21379                    String parentTitle, int status) throws SystemException {
21380                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
21381                            return countByG_N_H_P_S(groupId, nodeId, head, parentTitle, status);
21382                    }
21383    
21384                    StringBundler query = new StringBundler(6);
21385    
21386                    query.append(_FILTER_SQL_COUNT_WIKIPAGE_WHERE);
21387    
21388                    query.append(_FINDER_COLUMN_G_N_H_P_S_GROUPID_2);
21389    
21390                    query.append(_FINDER_COLUMN_G_N_H_P_S_NODEID_2);
21391    
21392                    query.append(_FINDER_COLUMN_G_N_H_P_S_HEAD_2);
21393    
21394                    boolean bindParentTitle = false;
21395    
21396                    if (parentTitle == null) {
21397                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1);
21398                    }
21399                    else if (parentTitle.equals(StringPool.BLANK)) {
21400                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3);
21401                    }
21402                    else {
21403                            bindParentTitle = true;
21404    
21405                            query.append(_FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2);
21406                    }
21407    
21408                    query.append(_FINDER_COLUMN_G_N_H_P_S_STATUS_2);
21409    
21410                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
21411                                    WikiPage.class.getName(),
21412                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
21413    
21414                    Session session = null;
21415    
21416                    try {
21417                            session = openSession();
21418    
21419                            SQLQuery q = session.createSQLQuery(sql);
21420    
21421                            q.addScalar(COUNT_COLUMN_NAME,
21422                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
21423    
21424                            QueryPos qPos = QueryPos.getInstance(q);
21425    
21426                            qPos.add(groupId);
21427    
21428                            qPos.add(nodeId);
21429    
21430                            qPos.add(head);
21431    
21432                            if (bindParentTitle) {
21433                                    qPos.add(parentTitle.toLowerCase());
21434                            }
21435    
21436                            qPos.add(status);
21437    
21438                            Long count = (Long)q.uniqueResult();
21439    
21440                            return count.intValue();
21441                    }
21442                    catch (Exception e) {
21443                            throw processException(e);
21444                    }
21445                    finally {
21446                            closeSession(session);
21447                    }
21448            }
21449    
21450            private static final String _FINDER_COLUMN_G_N_H_P_S_GROUPID_2 = "wikiPage.groupId = ? AND ";
21451            private static final String _FINDER_COLUMN_G_N_H_P_S_NODEID_2 = "wikiPage.nodeId = ? AND ";
21452            private static final String _FINDER_COLUMN_G_N_H_P_S_HEAD_2 = "wikiPage.head = ? AND ";
21453            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_1 = "wikiPage.parentTitle IS NULL AND ";
21454            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_2 = "lower(wikiPage.parentTitle) = ? AND ";
21455            private static final String _FINDER_COLUMN_G_N_H_P_S_PARENTTITLE_3 = "(wikiPage.parentTitle IS NULL OR wikiPage.parentTitle = '') AND ";
21456            private static final String _FINDER_COLUMN_G_N_H_P_S_STATUS_2 = "wikiPage.status = ?";
21457    
21458            public WikiPagePersistenceImpl() {
21459                    setModelClass(WikiPage.class);
21460            }
21461    
21462            /**
21463             * Caches the wiki page in the entity cache if it is enabled.
21464             *
21465             * @param wikiPage the wiki page
21466             */
21467            @Override
21468            public void cacheResult(WikiPage wikiPage) {
21469                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
21470                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
21471    
21472                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
21473                            new Object[] { wikiPage.getUuid(), wikiPage.getGroupId() }, wikiPage);
21474    
21475                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V,
21476                            new Object[] {
21477                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
21478                                    wikiPage.getVersion()
21479                            }, wikiPage);
21480    
21481                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V,
21482                            new Object[] {
21483                                    wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion()
21484                            }, wikiPage);
21485    
21486                    wikiPage.resetOriginalValues();
21487            }
21488    
21489            /**
21490             * Caches the wiki pages in the entity cache if it is enabled.
21491             *
21492             * @param wikiPages the wiki pages
21493             */
21494            @Override
21495            public void cacheResult(List<WikiPage> wikiPages) {
21496                    for (WikiPage wikiPage : wikiPages) {
21497                            if (EntityCacheUtil.getResult(
21498                                                    WikiPageModelImpl.ENTITY_CACHE_ENABLED,
21499                                                    WikiPageImpl.class, wikiPage.getPrimaryKey()) == null) {
21500                                    cacheResult(wikiPage);
21501                            }
21502                            else {
21503                                    wikiPage.resetOriginalValues();
21504                            }
21505                    }
21506            }
21507    
21508            /**
21509             * Clears the cache for all wiki pages.
21510             *
21511             * <p>
21512             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
21513             * </p>
21514             */
21515            @Override
21516            public void clearCache() {
21517                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
21518                            CacheRegistryUtil.clear(WikiPageImpl.class.getName());
21519                    }
21520    
21521                    EntityCacheUtil.clearCache(WikiPageImpl.class.getName());
21522    
21523                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
21524                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
21525                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
21526            }
21527    
21528            /**
21529             * Clears the cache for the wiki page.
21530             *
21531             * <p>
21532             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
21533             * </p>
21534             */
21535            @Override
21536            public void clearCache(WikiPage wikiPage) {
21537                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
21538                            WikiPageImpl.class, wikiPage.getPrimaryKey());
21539    
21540                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
21541                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
21542    
21543                    clearUniqueFindersCache(wikiPage);
21544            }
21545    
21546            @Override
21547            public void clearCache(List<WikiPage> wikiPages) {
21548                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
21549                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
21550    
21551                    for (WikiPage wikiPage : wikiPages) {
21552                            EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
21553                                    WikiPageImpl.class, wikiPage.getPrimaryKey());
21554    
21555                            clearUniqueFindersCache(wikiPage);
21556                    }
21557            }
21558    
21559            protected void cacheUniqueFindersCache(WikiPage wikiPage) {
21560                    if (wikiPage.isNew()) {
21561                            Object[] args = new Object[] {
21562                                            wikiPage.getUuid(), wikiPage.getGroupId()
21563                                    };
21564    
21565                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
21566                                    Long.valueOf(1));
21567                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
21568                                    wikiPage);
21569    
21570                            args = new Object[] {
21571                                            wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
21572                                            wikiPage.getVersion()
21573                                    };
21574    
21575                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_V, args,
21576                                    Long.valueOf(1));
21577                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V, args, wikiPage);
21578    
21579                            args = new Object[] {
21580                                            wikiPage.getNodeId(), wikiPage.getTitle(),
21581                                            wikiPage.getVersion()
21582                                    };
21583    
21584                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_V, args,
21585                                    Long.valueOf(1));
21586                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V, args, wikiPage);
21587                    }
21588                    else {
21589                            WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
21590    
21591                            if ((wikiPageModelImpl.getColumnBitmask() &
21592                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
21593                                    Object[] args = new Object[] {
21594                                                    wikiPage.getUuid(), wikiPage.getGroupId()
21595                                            };
21596    
21597                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
21598                                            Long.valueOf(1));
21599                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
21600                                            wikiPage);
21601                            }
21602    
21603                            if ((wikiPageModelImpl.getColumnBitmask() &
21604                                            FINDER_PATH_FETCH_BY_R_N_V.getColumnBitmask()) != 0) {
21605                                    Object[] args = new Object[] {
21606                                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
21607                                                    wikiPage.getVersion()
21608                                            };
21609    
21610                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_N_V, args,
21611                                            Long.valueOf(1));
21612                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_N_V, args,
21613                                            wikiPage);
21614                            }
21615    
21616                            if ((wikiPageModelImpl.getColumnBitmask() &
21617                                            FINDER_PATH_FETCH_BY_N_T_V.getColumnBitmask()) != 0) {
21618                                    Object[] args = new Object[] {
21619                                                    wikiPage.getNodeId(), wikiPage.getTitle(),
21620                                                    wikiPage.getVersion()
21621                                            };
21622    
21623                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_T_V, args,
21624                                            Long.valueOf(1));
21625                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_T_V, args,
21626                                            wikiPage);
21627                            }
21628                    }
21629            }
21630    
21631            protected void clearUniqueFindersCache(WikiPage wikiPage) {
21632                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
21633    
21634                    Object[] args = new Object[] { wikiPage.getUuid(), wikiPage.getGroupId() };
21635    
21636                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
21637                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
21638    
21639                    if ((wikiPageModelImpl.getColumnBitmask() &
21640                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
21641                            args = new Object[] {
21642                                            wikiPageModelImpl.getOriginalUuid(),
21643                                            wikiPageModelImpl.getOriginalGroupId()
21644                                    };
21645    
21646                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
21647                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
21648                    }
21649    
21650                    args = new Object[] {
21651                                    wikiPage.getResourcePrimKey(), wikiPage.getNodeId(),
21652                                    wikiPage.getVersion()
21653                            };
21654    
21655                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_V, args);
21656                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V, args);
21657    
21658                    if ((wikiPageModelImpl.getColumnBitmask() &
21659                                    FINDER_PATH_FETCH_BY_R_N_V.getColumnBitmask()) != 0) {
21660                            args = new Object[] {
21661                                            wikiPageModelImpl.getOriginalResourcePrimKey(),
21662                                            wikiPageModelImpl.getOriginalNodeId(),
21663                                            wikiPageModelImpl.getOriginalVersion()
21664                                    };
21665    
21666                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_V, args);
21667                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_N_V, args);
21668                    }
21669    
21670                    args = new Object[] {
21671                                    wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion()
21672                            };
21673    
21674                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_V, args);
21675                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V, args);
21676    
21677                    if ((wikiPageModelImpl.getColumnBitmask() &
21678                                    FINDER_PATH_FETCH_BY_N_T_V.getColumnBitmask()) != 0) {
21679                            args = new Object[] {
21680                                            wikiPageModelImpl.getOriginalNodeId(),
21681                                            wikiPageModelImpl.getOriginalTitle(),
21682                                            wikiPageModelImpl.getOriginalVersion()
21683                                    };
21684    
21685                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_V, args);
21686                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_T_V, args);
21687                    }
21688            }
21689    
21690            /**
21691             * Creates a new wiki page with the primary key. Does not add the wiki page to the database.
21692             *
21693             * @param pageId the primary key for the new wiki page
21694             * @return the new wiki page
21695             */
21696            @Override
21697            public WikiPage create(long pageId) {
21698                    WikiPage wikiPage = new WikiPageImpl();
21699    
21700                    wikiPage.setNew(true);
21701                    wikiPage.setPrimaryKey(pageId);
21702    
21703                    String uuid = PortalUUIDUtil.generate();
21704    
21705                    wikiPage.setUuid(uuid);
21706    
21707                    return wikiPage;
21708            }
21709    
21710            /**
21711             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
21712             *
21713             * @param pageId the primary key of the wiki page
21714             * @return the wiki page that was removed
21715             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
21716             * @throws SystemException if a system exception occurred
21717             */
21718            @Override
21719            public WikiPage remove(long pageId)
21720                    throws NoSuchPageException, SystemException {
21721                    return remove((Serializable)pageId);
21722            }
21723    
21724            /**
21725             * Removes the wiki page with the primary key from the database. Also notifies the appropriate model listeners.
21726             *
21727             * @param primaryKey the primary key of the wiki page
21728             * @return the wiki page that was removed
21729             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
21730             * @throws SystemException if a system exception occurred
21731             */
21732            @Override
21733            public WikiPage remove(Serializable primaryKey)
21734                    throws NoSuchPageException, SystemException {
21735                    Session session = null;
21736    
21737                    try {
21738                            session = openSession();
21739    
21740                            WikiPage wikiPage = (WikiPage)session.get(WikiPageImpl.class,
21741                                            primaryKey);
21742    
21743                            if (wikiPage == null) {
21744                                    if (_log.isWarnEnabled()) {
21745                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
21746                                    }
21747    
21748                                    throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
21749                                            primaryKey);
21750                            }
21751    
21752                            return remove(wikiPage);
21753                    }
21754                    catch (NoSuchPageException nsee) {
21755                            throw nsee;
21756                    }
21757                    catch (Exception e) {
21758                            throw processException(e);
21759                    }
21760                    finally {
21761                            closeSession(session);
21762                    }
21763            }
21764    
21765            @Override
21766            protected WikiPage removeImpl(WikiPage wikiPage) throws SystemException {
21767                    wikiPage = toUnwrappedModel(wikiPage);
21768    
21769                    Session session = null;
21770    
21771                    try {
21772                            session = openSession();
21773    
21774                            if (!session.contains(wikiPage)) {
21775                                    wikiPage = (WikiPage)session.get(WikiPageImpl.class,
21776                                                    wikiPage.getPrimaryKeyObj());
21777                            }
21778    
21779                            if (wikiPage != null) {
21780                                    session.delete(wikiPage);
21781                            }
21782                    }
21783                    catch (Exception e) {
21784                            throw processException(e);
21785                    }
21786                    finally {
21787                            closeSession(session);
21788                    }
21789    
21790                    if (wikiPage != null) {
21791                            clearCache(wikiPage);
21792                    }
21793    
21794                    return wikiPage;
21795            }
21796    
21797            @Override
21798            public WikiPage updateImpl(com.liferay.portlet.wiki.model.WikiPage wikiPage)
21799                    throws SystemException {
21800                    wikiPage = toUnwrappedModel(wikiPage);
21801    
21802                    boolean isNew = wikiPage.isNew();
21803    
21804                    WikiPageModelImpl wikiPageModelImpl = (WikiPageModelImpl)wikiPage;
21805    
21806                    if (Validator.isNull(wikiPage.getUuid())) {
21807                            String uuid = PortalUUIDUtil.generate();
21808    
21809                            wikiPage.setUuid(uuid);
21810                    }
21811    
21812                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
21813    
21814                    if (userId > 0) {
21815                            long companyId = wikiPage.getCompanyId();
21816    
21817                            long groupId = wikiPage.getGroupId();
21818    
21819                            long pageId = 0;
21820    
21821                            if (!isNew) {
21822                                    pageId = wikiPage.getPrimaryKey();
21823                            }
21824    
21825                            try {
21826                                    wikiPage.setTitle(SanitizerUtil.sanitize(companyId, groupId,
21827                                                    userId,
21828                                                    com.liferay.portlet.wiki.model.WikiPage.class.getName(),
21829                                                    pageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
21830                                                    wikiPage.getTitle(), null));
21831                            }
21832                            catch (SanitizerException se) {
21833                                    throw new SystemException(se);
21834                            }
21835                    }
21836    
21837                    Session session = null;
21838    
21839                    try {
21840                            session = openSession();
21841    
21842                            if (wikiPage.isNew()) {
21843                                    session.save(wikiPage);
21844    
21845                                    wikiPage.setNew(false);
21846                            }
21847                            else {
21848                                    session.merge(wikiPage);
21849                            }
21850                    }
21851                    catch (Exception e) {
21852                            throw processException(e);
21853                    }
21854                    finally {
21855                            closeSession(session);
21856                    }
21857    
21858                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
21859    
21860                    if (isNew || !WikiPageModelImpl.COLUMN_BITMASK_ENABLED) {
21861                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
21862                    }
21863    
21864                    else {
21865                            if ((wikiPageModelImpl.getColumnBitmask() &
21866                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
21867                                    Object[] args = new Object[] { wikiPageModelImpl.getOriginalUuid() };
21868    
21869                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
21870                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
21871                                            args);
21872    
21873                                    args = new Object[] { wikiPageModelImpl.getUuid() };
21874    
21875                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
21876                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
21877                                            args);
21878                            }
21879    
21880                            if ((wikiPageModelImpl.getColumnBitmask() &
21881                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
21882                                    Object[] args = new Object[] {
21883                                                    wikiPageModelImpl.getOriginalUuid(),
21884                                                    wikiPageModelImpl.getOriginalCompanyId()
21885                                            };
21886    
21887                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
21888                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
21889                                            args);
21890    
21891                                    args = new Object[] {
21892                                                    wikiPageModelImpl.getUuid(),
21893                                                    wikiPageModelImpl.getCompanyId()
21894                                            };
21895    
21896                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
21897                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
21898                                            args);
21899                            }
21900    
21901                            if ((wikiPageModelImpl.getColumnBitmask() &
21902                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY.getColumnBitmask()) != 0) {
21903                                    Object[] args = new Object[] {
21904                                                    wikiPageModelImpl.getOriginalResourcePrimKey()
21905                                            };
21906    
21907                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY,
21908                                            args);
21909                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY,
21910                                            args);
21911    
21912                                    args = new Object[] { wikiPageModelImpl.getResourcePrimKey() };
21913    
21914                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY,
21915                                            args);
21916                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY,
21917                                            args);
21918                            }
21919    
21920                            if ((wikiPageModelImpl.getColumnBitmask() &
21921                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID.getColumnBitmask()) != 0) {
21922                                    Object[] args = new Object[] {
21923                                                    wikiPageModelImpl.getOriginalNodeId()
21924                                            };
21925    
21926                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NODEID, args);
21927                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID,
21928                                            args);
21929    
21930                                    args = new Object[] { wikiPageModelImpl.getNodeId() };
21931    
21932                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NODEID, args);
21933                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NODEID,
21934                                            args);
21935                            }
21936    
21937                            if ((wikiPageModelImpl.getColumnBitmask() &
21938                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT.getColumnBitmask()) != 0) {
21939                                    Object[] args = new Object[] {
21940                                                    wikiPageModelImpl.getOriginalFormat()
21941                                            };
21942    
21943                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FORMAT, args);
21944                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT,
21945                                            args);
21946    
21947                                    args = new Object[] { wikiPageModelImpl.getFormat() };
21948    
21949                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FORMAT, args);
21950                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FORMAT,
21951                                            args);
21952                            }
21953    
21954                            if ((wikiPageModelImpl.getColumnBitmask() &
21955                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N.getColumnBitmask()) != 0) {
21956                                    Object[] args = new Object[] {
21957                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
21958                                                    wikiPageModelImpl.getOriginalNodeId()
21959                                            };
21960    
21961                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N, args);
21962                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N,
21963                                            args);
21964    
21965                                    args = new Object[] {
21966                                                    wikiPageModelImpl.getResourcePrimKey(),
21967                                                    wikiPageModelImpl.getNodeId()
21968                                            };
21969    
21970                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N, args);
21971                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N,
21972                                            args);
21973                            }
21974    
21975                            if ((wikiPageModelImpl.getColumnBitmask() &
21976                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S.getColumnBitmask()) != 0) {
21977                                    Object[] args = new Object[] {
21978                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
21979                                                    wikiPageModelImpl.getOriginalStatus()
21980                                            };
21981    
21982                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
21983                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
21984                                            args);
21985    
21986                                    args = new Object[] {
21987                                                    wikiPageModelImpl.getResourcePrimKey(),
21988                                                    wikiPageModelImpl.getStatus()
21989                                            };
21990    
21991                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
21992                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
21993                                            args);
21994                            }
21995    
21996                            if ((wikiPageModelImpl.getColumnBitmask() &
21997                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T.getColumnBitmask()) != 0) {
21998                                    Object[] args = new Object[] {
21999                                                    wikiPageModelImpl.getOriginalNodeId(),
22000                                                    wikiPageModelImpl.getOriginalTitle()
22001                                            };
22002    
22003                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
22004                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T,
22005                                            args);
22006    
22007                                    args = new Object[] {
22008                                                    wikiPageModelImpl.getNodeId(),
22009                                                    wikiPageModelImpl.getTitle()
22010                                            };
22011    
22012                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T, args);
22013                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T,
22014                                            args);
22015                            }
22016    
22017                            if ((wikiPageModelImpl.getColumnBitmask() &
22018                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H.getColumnBitmask()) != 0) {
22019                                    Object[] args = new Object[] {
22020                                                    wikiPageModelImpl.getOriginalNodeId(),
22021                                                    wikiPageModelImpl.getOriginalHead()
22022                                            };
22023    
22024                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H, args);
22025                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H,
22026                                            args);
22027    
22028                                    args = new Object[] {
22029                                                    wikiPageModelImpl.getNodeId(),
22030                                                    wikiPageModelImpl.getHead()
22031                                            };
22032    
22033                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H, args);
22034                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H,
22035                                            args);
22036                            }
22037    
22038                            if ((wikiPageModelImpl.getColumnBitmask() &
22039                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P.getColumnBitmask()) != 0) {
22040                                    Object[] args = new Object[] {
22041                                                    wikiPageModelImpl.getOriginalNodeId(),
22042                                                    wikiPageModelImpl.getOriginalParentTitle()
22043                                            };
22044    
22045                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_P, args);
22046                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P,
22047                                            args);
22048    
22049                                    args = new Object[] {
22050                                                    wikiPageModelImpl.getNodeId(),
22051                                                    wikiPageModelImpl.getParentTitle()
22052                                            };
22053    
22054                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_P, args);
22055                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_P,
22056                                            args);
22057                            }
22058    
22059                            if ((wikiPageModelImpl.getColumnBitmask() &
22060                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R.getColumnBitmask()) != 0) {
22061                                    Object[] args = new Object[] {
22062                                                    wikiPageModelImpl.getOriginalNodeId(),
22063                                                    wikiPageModelImpl.getOriginalRedirectTitle()
22064                                            };
22065    
22066                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_R, args);
22067                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R,
22068                                            args);
22069    
22070                                    args = new Object[] {
22071                                                    wikiPageModelImpl.getNodeId(),
22072                                                    wikiPageModelImpl.getRedirectTitle()
22073                                            };
22074    
22075                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_R, args);
22076                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_R,
22077                                            args);
22078                            }
22079    
22080                            if ((wikiPageModelImpl.getColumnBitmask() &
22081                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S.getColumnBitmask()) != 0) {
22082                                    Object[] args = new Object[] {
22083                                                    wikiPageModelImpl.getOriginalNodeId(),
22084                                                    wikiPageModelImpl.getOriginalStatus()
22085                                            };
22086    
22087                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_S, args);
22088                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S,
22089                                            args);
22090    
22091                                    args = new Object[] {
22092                                                    wikiPageModelImpl.getNodeId(),
22093                                                    wikiPageModelImpl.getStatus()
22094                                            };
22095    
22096                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_S, args);
22097                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_S,
22098                                            args);
22099                            }
22100    
22101                            if ((wikiPageModelImpl.getColumnBitmask() &
22102                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H.getColumnBitmask()) != 0) {
22103                                    Object[] args = new Object[] {
22104                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
22105                                                    wikiPageModelImpl.getOriginalNodeId(),
22106                                                    wikiPageModelImpl.getOriginalHead()
22107                                            };
22108    
22109                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_H, args);
22110                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H,
22111                                            args);
22112    
22113                                    args = new Object[] {
22114                                                    wikiPageModelImpl.getResourcePrimKey(),
22115                                                    wikiPageModelImpl.getNodeId(),
22116                                                    wikiPageModelImpl.getHead()
22117                                            };
22118    
22119                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_H, args);
22120                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_H,
22121                                            args);
22122                            }
22123    
22124                            if ((wikiPageModelImpl.getColumnBitmask() &
22125                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S.getColumnBitmask()) != 0) {
22126                                    Object[] args = new Object[] {
22127                                                    wikiPageModelImpl.getOriginalResourcePrimKey(),
22128                                                    wikiPageModelImpl.getOriginalNodeId(),
22129                                                    wikiPageModelImpl.getOriginalStatus()
22130                                            };
22131    
22132                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_S, args);
22133                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S,
22134                                            args);
22135    
22136                                    args = new Object[] {
22137                                                    wikiPageModelImpl.getResourcePrimKey(),
22138                                                    wikiPageModelImpl.getNodeId(),
22139                                                    wikiPageModelImpl.getStatus()
22140                                            };
22141    
22142                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_N_S, args);
22143                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_N_S,
22144                                            args);
22145                            }
22146    
22147                            if ((wikiPageModelImpl.getColumnBitmask() &
22148                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H.getColumnBitmask()) != 0) {
22149                                    Object[] args = new Object[] {
22150                                                    wikiPageModelImpl.getOriginalGroupId(),
22151                                                    wikiPageModelImpl.getOriginalNodeId(),
22152                                                    wikiPageModelImpl.getOriginalHead()
22153                                            };
22154    
22155                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H, args);
22156                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H,
22157                                            args);
22158    
22159                                    args = new Object[] {
22160                                                    wikiPageModelImpl.getGroupId(),
22161                                                    wikiPageModelImpl.getNodeId(),
22162                                                    wikiPageModelImpl.getHead()
22163                                            };
22164    
22165                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H, args);
22166                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H,
22167                                            args);
22168                            }
22169    
22170                            if ((wikiPageModelImpl.getColumnBitmask() &
22171                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S.getColumnBitmask()) != 0) {
22172                                    Object[] args = new Object[] {
22173                                                    wikiPageModelImpl.getOriginalGroupId(),
22174                                                    wikiPageModelImpl.getOriginalNodeId(),
22175                                                    wikiPageModelImpl.getOriginalStatus()
22176                                            };
22177    
22178                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_S, args);
22179                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S,
22180                                            args);
22181    
22182                                    args = new Object[] {
22183                                                    wikiPageModelImpl.getGroupId(),
22184                                                    wikiPageModelImpl.getNodeId(),
22185                                                    wikiPageModelImpl.getStatus()
22186                                            };
22187    
22188                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_S, args);
22189                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_S,
22190                                            args);
22191                            }
22192    
22193                            if ((wikiPageModelImpl.getColumnBitmask() &
22194                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S.getColumnBitmask()) != 0) {
22195                                    Object[] args = new Object[] {
22196                                                    wikiPageModelImpl.getOriginalUserId(),
22197                                                    wikiPageModelImpl.getOriginalNodeId(),
22198                                                    wikiPageModelImpl.getOriginalStatus()
22199                                            };
22200    
22201                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_N_S, args);
22202                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S,
22203                                            args);
22204    
22205                                    args = new Object[] {
22206                                                    wikiPageModelImpl.getUserId(),
22207                                                    wikiPageModelImpl.getNodeId(),
22208                                                    wikiPageModelImpl.getStatus()
22209                                            };
22210    
22211                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_N_S, args);
22212                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_N_S,
22213                                            args);
22214                            }
22215    
22216                            if ((wikiPageModelImpl.getColumnBitmask() &
22217                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H.getColumnBitmask()) != 0) {
22218                                    Object[] args = new Object[] {
22219                                                    wikiPageModelImpl.getOriginalNodeId(),
22220                                                    wikiPageModelImpl.getOriginalTitle(),
22221                                                    wikiPageModelImpl.getOriginalHead()
22222                                            };
22223    
22224                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_H, args);
22225                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H,
22226                                            args);
22227    
22228                                    args = new Object[] {
22229                                                    wikiPageModelImpl.getNodeId(),
22230                                                    wikiPageModelImpl.getTitle(),
22231                                                    wikiPageModelImpl.getHead()
22232                                            };
22233    
22234                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_H, args);
22235                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_H,
22236                                            args);
22237                            }
22238    
22239                            if ((wikiPageModelImpl.getColumnBitmask() &
22240                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S.getColumnBitmask()) != 0) {
22241                                    Object[] args = new Object[] {
22242                                                    wikiPageModelImpl.getOriginalNodeId(),
22243                                                    wikiPageModelImpl.getOriginalTitle(),
22244                                                    wikiPageModelImpl.getOriginalStatus()
22245                                            };
22246    
22247                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_S, args);
22248                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S,
22249                                            args);
22250    
22251                                    args = new Object[] {
22252                                                    wikiPageModelImpl.getNodeId(),
22253                                                    wikiPageModelImpl.getTitle(),
22254                                                    wikiPageModelImpl.getStatus()
22255                                            };
22256    
22257                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_T_S, args);
22258                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_T_S,
22259                                            args);
22260                            }
22261    
22262                            if ((wikiPageModelImpl.getColumnBitmask() &
22263                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P.getColumnBitmask()) != 0) {
22264                                    Object[] args = new Object[] {
22265                                                    wikiPageModelImpl.getOriginalNodeId(),
22266                                                    wikiPageModelImpl.getOriginalHead(),
22267                                                    wikiPageModelImpl.getOriginalParentTitle()
22268                                            };
22269    
22270                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P, args);
22271                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P,
22272                                            args);
22273    
22274                                    args = new Object[] {
22275                                                    wikiPageModelImpl.getNodeId(),
22276                                                    wikiPageModelImpl.getHead(),
22277                                                    wikiPageModelImpl.getParentTitle()
22278                                            };
22279    
22280                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P, args);
22281                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P,
22282                                            args);
22283                            }
22284    
22285                            if ((wikiPageModelImpl.getColumnBitmask() &
22286                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R.getColumnBitmask()) != 0) {
22287                                    Object[] args = new Object[] {
22288                                                    wikiPageModelImpl.getOriginalNodeId(),
22289                                                    wikiPageModelImpl.getOriginalHead(),
22290                                                    wikiPageModelImpl.getOriginalRedirectTitle()
22291                                            };
22292    
22293                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_R, args);
22294                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R,
22295                                            args);
22296    
22297                                    args = new Object[] {
22298                                                    wikiPageModelImpl.getNodeId(),
22299                                                    wikiPageModelImpl.getHead(),
22300                                                    wikiPageModelImpl.getRedirectTitle()
22301                                            };
22302    
22303                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_R, args);
22304                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R,
22305                                            args);
22306                            }
22307    
22308                            if ((wikiPageModelImpl.getColumnBitmask() &
22309                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S.getColumnBitmask()) != 0) {
22310                                    Object[] args = new Object[] {
22311                                                    wikiPageModelImpl.getOriginalNodeId(),
22312                                                    wikiPageModelImpl.getOriginalHead(),
22313                                                    wikiPageModelImpl.getOriginalStatus()
22314                                            };
22315    
22316                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_S, args);
22317                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S,
22318                                            args);
22319    
22320                                    args = new Object[] {
22321                                                    wikiPageModelImpl.getNodeId(),
22322                                                    wikiPageModelImpl.getHead(),
22323                                                    wikiPageModelImpl.getStatus()
22324                                            };
22325    
22326                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_S, args);
22327                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_S,
22328                                            args);
22329                            }
22330    
22331                            if ((wikiPageModelImpl.getColumnBitmask() &
22332                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S.getColumnBitmask()) != 0) {
22333                                    Object[] args = new Object[] {
22334                                                    wikiPageModelImpl.getOriginalGroupId(),
22335                                                    wikiPageModelImpl.getOriginalUserId(),
22336                                                    wikiPageModelImpl.getOriginalNodeId(),
22337                                                    wikiPageModelImpl.getOriginalStatus()
22338                                            };
22339    
22340                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N_S, args);
22341                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S,
22342                                            args);
22343    
22344                                    args = new Object[] {
22345                                                    wikiPageModelImpl.getGroupId(),
22346                                                    wikiPageModelImpl.getUserId(),
22347                                                    wikiPageModelImpl.getNodeId(),
22348                                                    wikiPageModelImpl.getStatus()
22349                                            };
22350    
22351                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N_S, args);
22352                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_N_S,
22353                                            args);
22354                            }
22355    
22356                            if ((wikiPageModelImpl.getColumnBitmask() &
22357                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H.getColumnBitmask()) != 0) {
22358                                    Object[] args = new Object[] {
22359                                                    wikiPageModelImpl.getOriginalGroupId(),
22360                                                    wikiPageModelImpl.getOriginalNodeId(),
22361                                                    wikiPageModelImpl.getOriginalTitle(),
22362                                                    wikiPageModelImpl.getOriginalHead()
22363                                            };
22364    
22365                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_H, args);
22366                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H,
22367                                            args);
22368    
22369                                    args = new Object[] {
22370                                                    wikiPageModelImpl.getGroupId(),
22371                                                    wikiPageModelImpl.getNodeId(),
22372                                                    wikiPageModelImpl.getTitle(),
22373                                                    wikiPageModelImpl.getHead()
22374                                            };
22375    
22376                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_H, args);
22377                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_H,
22378                                            args);
22379                            }
22380    
22381                            if ((wikiPageModelImpl.getColumnBitmask() &
22382                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S.getColumnBitmask()) != 0) {
22383                                    Object[] args = new Object[] {
22384                                                    wikiPageModelImpl.getOriginalGroupId(),
22385                                                    wikiPageModelImpl.getOriginalNodeId(),
22386                                                    wikiPageModelImpl.getOriginalHead(),
22387                                                    wikiPageModelImpl.getOriginalStatus()
22388                                            };
22389    
22390                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_S, args);
22391                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S,
22392                                            args);
22393    
22394                                    args = new Object[] {
22395                                                    wikiPageModelImpl.getGroupId(),
22396                                                    wikiPageModelImpl.getNodeId(),
22397                                                    wikiPageModelImpl.getHead(),
22398                                                    wikiPageModelImpl.getStatus()
22399                                            };
22400    
22401                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_S, args);
22402                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_S,
22403                                            args);
22404                            }
22405    
22406                            if ((wikiPageModelImpl.getColumnBitmask() &
22407                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S.getColumnBitmask()) != 0) {
22408                                    Object[] args = new Object[] {
22409                                                    wikiPageModelImpl.getOriginalNodeId(),
22410                                                    wikiPageModelImpl.getOriginalHead(),
22411                                                    wikiPageModelImpl.getOriginalParentTitle(),
22412                                                    wikiPageModelImpl.getOriginalStatus()
22413                                            };
22414    
22415                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P_S, args);
22416                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S,
22417                                            args);
22418    
22419                                    args = new Object[] {
22420                                                    wikiPageModelImpl.getNodeId(),
22421                                                    wikiPageModelImpl.getHead(),
22422                                                    wikiPageModelImpl.getParentTitle(),
22423                                                    wikiPageModelImpl.getStatus()
22424                                            };
22425    
22426                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_P_S, args);
22427                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_P_S,
22428                                            args);
22429                            }
22430    
22431                            if ((wikiPageModelImpl.getColumnBitmask() &
22432                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R_S.getColumnBitmask()) != 0) {
22433                                    Object[] args = new Object[] {
22434                                                    wikiPageModelImpl.getOriginalNodeId(),
22435                                                    wikiPageModelImpl.getOriginalHead(),
22436                                                    wikiPageModelImpl.getOriginalRedirectTitle(),
22437                                                    wikiPageModelImpl.getOriginalStatus()
22438                                            };
22439    
22440                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_R_S, args);
22441                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R_S,
22442                                            args);
22443    
22444                                    args = new Object[] {
22445                                                    wikiPageModelImpl.getNodeId(),
22446                                                    wikiPageModelImpl.getHead(),
22447                                                    wikiPageModelImpl.getRedirectTitle(),
22448                                                    wikiPageModelImpl.getStatus()
22449                                            };
22450    
22451                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_H_R_S, args);
22452                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_H_R_S,
22453                                            args);
22454                            }
22455    
22456                            if ((wikiPageModelImpl.getColumnBitmask() &
22457                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S.getColumnBitmask()) != 0) {
22458                                    Object[] args = new Object[] {
22459                                                    wikiPageModelImpl.getOriginalGroupId(),
22460                                                    wikiPageModelImpl.getOriginalNodeId(),
22461                                                    wikiPageModelImpl.getOriginalHead(),
22462                                                    wikiPageModelImpl.getOriginalParentTitle(),
22463                                                    wikiPageModelImpl.getOriginalStatus()
22464                                            };
22465    
22466                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_P_S,
22467                                            args);
22468                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S,
22469                                            args);
22470    
22471                                    args = new Object[] {
22472                                                    wikiPageModelImpl.getGroupId(),
22473                                                    wikiPageModelImpl.getNodeId(),
22474                                                    wikiPageModelImpl.getHead(),
22475                                                    wikiPageModelImpl.getParentTitle(),
22476                                                    wikiPageModelImpl.getStatus()
22477                                            };
22478    
22479                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_H_P_S,
22480                                            args);
22481                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_H_P_S,
22482                                            args);
22483                            }
22484                    }
22485    
22486                    EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
22487                            WikiPageImpl.class, wikiPage.getPrimaryKey(), wikiPage);
22488    
22489                    clearUniqueFindersCache(wikiPage);
22490                    cacheUniqueFindersCache(wikiPage);
22491    
22492                    return wikiPage;
22493            }
22494    
22495            protected WikiPage toUnwrappedModel(WikiPage wikiPage) {
22496                    if (wikiPage instanceof WikiPageImpl) {
22497                            return wikiPage;
22498                    }
22499    
22500                    WikiPageImpl wikiPageImpl = new WikiPageImpl();
22501    
22502                    wikiPageImpl.setNew(wikiPage.isNew());
22503                    wikiPageImpl.setPrimaryKey(wikiPage.getPrimaryKey());
22504    
22505                    wikiPageImpl.setUuid(wikiPage.getUuid());
22506                    wikiPageImpl.setPageId(wikiPage.getPageId());
22507                    wikiPageImpl.setResourcePrimKey(wikiPage.getResourcePrimKey());
22508                    wikiPageImpl.setGroupId(wikiPage.getGroupId());
22509                    wikiPageImpl.setCompanyId(wikiPage.getCompanyId());
22510                    wikiPageImpl.setUserId(wikiPage.getUserId());
22511                    wikiPageImpl.setUserName(wikiPage.getUserName());
22512                    wikiPageImpl.setCreateDate(wikiPage.getCreateDate());
22513                    wikiPageImpl.setModifiedDate(wikiPage.getModifiedDate());
22514                    wikiPageImpl.setNodeId(wikiPage.getNodeId());
22515                    wikiPageImpl.setTitle(wikiPage.getTitle());
22516                    wikiPageImpl.setVersion(wikiPage.getVersion());
22517                    wikiPageImpl.setMinorEdit(wikiPage.isMinorEdit());
22518                    wikiPageImpl.setContent(wikiPage.getContent());
22519                    wikiPageImpl.setSummary(wikiPage.getSummary());
22520                    wikiPageImpl.setFormat(wikiPage.getFormat());
22521                    wikiPageImpl.setHead(wikiPage.isHead());
22522                    wikiPageImpl.setParentTitle(wikiPage.getParentTitle());
22523                    wikiPageImpl.setRedirectTitle(wikiPage.getRedirectTitle());
22524                    wikiPageImpl.setStatus(wikiPage.getStatus());
22525                    wikiPageImpl.setStatusByUserId(wikiPage.getStatusByUserId());
22526                    wikiPageImpl.setStatusByUserName(wikiPage.getStatusByUserName());
22527                    wikiPageImpl.setStatusDate(wikiPage.getStatusDate());
22528    
22529                    return wikiPageImpl;
22530            }
22531    
22532            /**
22533             * Returns the wiki page with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
22534             *
22535             * @param primaryKey the primary key of the wiki page
22536             * @return the wiki page
22537             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
22538             * @throws SystemException if a system exception occurred
22539             */
22540            @Override
22541            public WikiPage findByPrimaryKey(Serializable primaryKey)
22542                    throws NoSuchPageException, SystemException {
22543                    WikiPage wikiPage = fetchByPrimaryKey(primaryKey);
22544    
22545                    if (wikiPage == null) {
22546                            if (_log.isWarnEnabled()) {
22547                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
22548                            }
22549    
22550                            throw new NoSuchPageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
22551                                    primaryKey);
22552                    }
22553    
22554                    return wikiPage;
22555            }
22556    
22557            /**
22558             * Returns the wiki page with the primary key or throws a {@link com.liferay.portlet.wiki.NoSuchPageException} if it could not be found.
22559             *
22560             * @param pageId the primary key of the wiki page
22561             * @return the wiki page
22562             * @throws com.liferay.portlet.wiki.NoSuchPageException if a wiki page with the primary key could not be found
22563             * @throws SystemException if a system exception occurred
22564             */
22565            @Override
22566            public WikiPage findByPrimaryKey(long pageId)
22567                    throws NoSuchPageException, SystemException {
22568                    return findByPrimaryKey((Serializable)pageId);
22569            }
22570    
22571            /**
22572             * Returns the wiki page with the primary key or returns <code>null</code> if it could not be found.
22573             *
22574             * @param primaryKey the primary key of the wiki page
22575             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
22576             * @throws SystemException if a system exception occurred
22577             */
22578            @Override
22579            public WikiPage fetchByPrimaryKey(Serializable primaryKey)
22580                    throws SystemException {
22581                    WikiPage wikiPage = (WikiPage)EntityCacheUtil.getResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
22582                                    WikiPageImpl.class, primaryKey);
22583    
22584                    if (wikiPage == _nullWikiPage) {
22585                            return null;
22586                    }
22587    
22588                    if (wikiPage == null) {
22589                            Session session = null;
22590    
22591                            try {
22592                                    session = openSession();
22593    
22594                                    wikiPage = (WikiPage)session.get(WikiPageImpl.class, primaryKey);
22595    
22596                                    if (wikiPage != null) {
22597                                            cacheResult(wikiPage);
22598                                    }
22599                                    else {
22600                                            EntityCacheUtil.putResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
22601                                                    WikiPageImpl.class, primaryKey, _nullWikiPage);
22602                                    }
22603                            }
22604                            catch (Exception e) {
22605                                    EntityCacheUtil.removeResult(WikiPageModelImpl.ENTITY_CACHE_ENABLED,
22606                                            WikiPageImpl.class, primaryKey);
22607    
22608                                    throw processException(e);
22609                            }
22610                            finally {
22611                                    closeSession(session);
22612                            }
22613                    }
22614    
22615                    return wikiPage;
22616            }
22617    
22618            /**
22619             * Returns the wiki page with the primary key or returns <code>null</code> if it could not be found.
22620             *
22621             * @param pageId the primary key of the wiki page
22622             * @return the wiki page, or <code>null</code> if a wiki page with the primary key could not be found
22623             * @throws SystemException if a system exception occurred
22624             */
22625            @Override
22626            public WikiPage fetchByPrimaryKey(long pageId) throws SystemException {
22627                    return fetchByPrimaryKey((Serializable)pageId);
22628            }
22629    
22630            /**
22631             * Returns all the wiki pages.
22632             *
22633             * @return the wiki pages
22634             * @throws SystemException if a system exception occurred
22635             */
22636            @Override
22637            public List<WikiPage> findAll() throws SystemException {
22638                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
22639            }
22640    
22641            /**
22642             * Returns a range of all the wiki pages.
22643             *
22644             * <p>
22645             * 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.
22646             * </p>
22647             *
22648             * @param start the lower bound of the range of wiki pages
22649             * @param end the upper bound of the range of wiki pages (not inclusive)
22650             * @return the range of wiki pages
22651             * @throws SystemException if a system exception occurred
22652             */
22653            @Override
22654            public List<WikiPage> findAll(int start, int end) throws SystemException {
22655                    return findAll(start, end, null);
22656            }
22657    
22658            /**
22659             * Returns an ordered range of all the wiki pages.
22660             *
22661             * <p>
22662             * 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.
22663             * </p>
22664             *
22665             * @param start the lower bound of the range of wiki pages
22666             * @param end the upper bound of the range of wiki pages (not inclusive)
22667             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
22668             * @return the ordered range of wiki pages
22669             * @throws SystemException if a system exception occurred
22670             */
22671            @Override
22672            public List<WikiPage> findAll(int start, int end,
22673                    OrderByComparator orderByComparator) throws SystemException {
22674                    boolean pagination = true;
22675                    FinderPath finderPath = null;
22676                    Object[] finderArgs = null;
22677    
22678                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
22679                                    (orderByComparator == null)) {
22680                            pagination = false;
22681                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
22682                            finderArgs = FINDER_ARGS_EMPTY;
22683                    }
22684                    else {
22685                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
22686                            finderArgs = new Object[] { start, end, orderByComparator };
22687                    }
22688    
22689                    List<WikiPage> list = (List<WikiPage>)FinderCacheUtil.getResult(finderPath,
22690                                    finderArgs, this);
22691    
22692                    if (list == null) {
22693                            StringBundler query = null;
22694                            String sql = null;
22695    
22696                            if (orderByComparator != null) {
22697                                    query = new StringBundler(2 +
22698                                                    (orderByComparator.getOrderByFields().length * 3));
22699    
22700                                    query.append(_SQL_SELECT_WIKIPAGE);
22701    
22702                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
22703                                            orderByComparator);
22704    
22705                                    sql = query.toString();
22706                            }
22707                            else {
22708                                    sql = _SQL_SELECT_WIKIPAGE;
22709    
22710                                    if (pagination) {
22711                                            sql = sql.concat(WikiPageModelImpl.ORDER_BY_JPQL);
22712                                    }
22713                            }
22714    
22715                            Session session = null;
22716    
22717                            try {
22718                                    session = openSession();
22719    
22720                                    Query q = session.createQuery(sql);
22721    
22722                                    if (!pagination) {
22723                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
22724                                                            start, end, false);
22725    
22726                                            Collections.sort(list);
22727    
22728                                            list = new UnmodifiableList<WikiPage>(list);
22729                                    }
22730                                    else {
22731                                            list = (List<WikiPage>)QueryUtil.list(q, getDialect(),
22732                                                            start, end);
22733                                    }
22734    
22735                                    cacheResult(list);
22736    
22737                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
22738                            }
22739                            catch (Exception e) {
22740                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
22741    
22742                                    throw processException(e);
22743                            }
22744                            finally {
22745                                    closeSession(session);
22746                            }
22747                    }
22748    
22749                    return list;
22750            }
22751    
22752            /**
22753             * Removes all the wiki pages from the database.
22754             *
22755             * @throws SystemException if a system exception occurred
22756             */
22757            @Override
22758            public void removeAll() throws SystemException {
22759                    for (WikiPage wikiPage : findAll()) {
22760                            remove(wikiPage);
22761                    }
22762            }
22763    
22764            /**
22765             * Returns the number of wiki pages.
22766             *
22767             * @return the number of wiki pages
22768             * @throws SystemException if a system exception occurred
22769             */
22770            @Override
22771            public int countAll() throws SystemException {
22772                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
22773                                    FINDER_ARGS_EMPTY, this);
22774    
22775                    if (count == null) {
22776                            Session session = null;
22777    
22778                            try {
22779                                    session = openSession();
22780    
22781                                    Query q = session.createQuery(_SQL_COUNT_WIKIPAGE);
22782    
22783                                    count = (Long)q.uniqueResult();
22784    
22785                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
22786                                            FINDER_ARGS_EMPTY, count);
22787                            }
22788                            catch (Exception e) {
22789                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
22790                                            FINDER_ARGS_EMPTY);
22791    
22792                                    throw processException(e);
22793                            }
22794                            finally {
22795                                    closeSession(session);
22796                            }
22797                    }
22798    
22799                    return count.intValue();
22800            }
22801    
22802            @Override
22803            protected Set<String> getBadColumnNames() {
22804                    return _badColumnNames;
22805            }
22806    
22807            /**
22808             * Initializes the wiki page persistence.
22809             */
22810            public void afterPropertiesSet() {
22811                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
22812                                            com.liferay.portal.util.PropsUtil.get(
22813                                                    "value.object.listener.com.liferay.portlet.wiki.model.WikiPage")));
22814    
22815                    if (listenerClassNames.length > 0) {
22816                            try {
22817                                    List<ModelListener<WikiPage>> listenersList = new ArrayList<ModelListener<WikiPage>>();
22818    
22819                                    for (String listenerClassName : listenerClassNames) {
22820                                            listenersList.add((ModelListener<WikiPage>)InstanceFactory.newInstance(
22821                                                            getClassLoader(), listenerClassName));
22822                                    }
22823    
22824                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
22825                            }
22826                            catch (Exception e) {
22827                                    _log.error(e);
22828                            }
22829                    }
22830            }
22831    
22832            public void destroy() {
22833                    EntityCacheUtil.removeCache(WikiPageImpl.class.getName());
22834                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
22835                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
22836                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
22837            }
22838    
22839            private static final String _SQL_SELECT_WIKIPAGE = "SELECT wikiPage FROM WikiPage wikiPage";
22840            private static final String _SQL_SELECT_WIKIPAGE_WHERE = "SELECT wikiPage FROM WikiPage wikiPage WHERE ";
22841            private static final String _SQL_COUNT_WIKIPAGE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage";
22842            private static final String _SQL_COUNT_WIKIPAGE_WHERE = "SELECT COUNT(wikiPage) FROM WikiPage wikiPage WHERE ";
22843            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "wikiPage.resourcePrimKey";
22844            private static final String _FILTER_SQL_SELECT_WIKIPAGE_WHERE = "SELECT DISTINCT {wikiPage.*} FROM WikiPage wikiPage WHERE ";
22845            private static final String _FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_1 =
22846                    "SELECT {WikiPage.*} FROM (SELECT DISTINCT wikiPage.pageId FROM WikiPage wikiPage WHERE ";
22847            private static final String _FILTER_SQL_SELECT_WIKIPAGE_NO_INLINE_DISTINCT_WHERE_2 =
22848                    ") TEMP_TABLE INNER JOIN WikiPage ON TEMP_TABLE.pageId = WikiPage.pageId";
22849            private static final String _FILTER_SQL_COUNT_WIKIPAGE_WHERE = "SELECT COUNT(DISTINCT wikiPage.pageId) AS COUNT_VALUE FROM WikiPage wikiPage WHERE ";
22850            private static final String _FILTER_ENTITY_ALIAS = "wikiPage";
22851            private static final String _FILTER_ENTITY_TABLE = "WikiPage";
22852            private static final String _ORDER_BY_ENTITY_ALIAS = "wikiPage.";
22853            private static final String _ORDER_BY_ENTITY_TABLE = "WikiPage.";
22854            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WikiPage exists with the primary key ";
22855            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WikiPage exists with the key {";
22856            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
22857            private static Log _log = LogFactoryUtil.getLog(WikiPagePersistenceImpl.class);
22858            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
22859                                    "uuid"
22860                            });
22861            private static WikiPage _nullWikiPage = new WikiPageImpl() {
22862                            @Override
22863                            public Object clone() {
22864                                    return this;
22865                            }
22866    
22867                            @Override
22868                            public CacheModel<WikiPage> toCacheModel() {
22869                                    return _nullWikiPageCacheModel;
22870                            }
22871                    };
22872    
22873            private static CacheModel<WikiPage> _nullWikiPageCacheModel = new CacheModel<WikiPage>() {
22874                            @Override
22875                            public WikiPage toEntityModel() {
22876                                    return _nullWikiPage;
22877                            }
22878                    };
22879    }